akhauriyash/Code-Regression huggingface dataset:
N = int(input())
S = []
for i in range(N):
    S.append(input())

D = {}
for s in S[0]:
    if s not in D:
        D[s] = 0
    D[s] += 1

for s in S:
    d = {}
    for i in s:
        if i not in d.keys():
            d[i] = 0
        d[i] += 1

    for k,v in d.items():
        if k not in D.keys():
            continue
        if D[k] > d[k]:
            D[k] = d[k]

    for k in D.keys():
        if k not in d.keys():
            D[k] = 0

keys =sorted(D)
ans = ""
for k in keys:
    if D[k] != 0:
        for v in range(D[k]):
            ans += k
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
typedef long long ll;
using namespace std;
const int mod = 1e9+7;
int main() {
    int n; cin >> n;
    vector<int> t(n); repeat (i,n) cin >> t[i];
    vector<int> a(n); repeat (i,n) cin >> a[i];
    vector<bool> fixed(n);
    fixed[0] = fixed[n-1] = true;
    repeat (i,n-1) if (t[i] < t[i+1]) fixed[i+1] = true;
    repeat (i,n-1) if (a[i] > a[i+1]) fixed[i  ] = true;
    ll acc = 1;
    repeat (i,n) if (not fixed[i]) acc = acc * min(t[i], a[i]) % mod;
    int highest = *whole(max_element, a);
    if (highest != t[n-1]) {
        acc = 0;
    } else {
        int i = whole(find, t, highest) - t.begin();
        int j = n - (find(a.rbegin(), a.rend(), highest) - a.rbegin()) - 1;
        if (j < i) acc = 0;
    }
    cout << acc << endl;
    return 0;
}


Measured memory_bytes: 1024
import sys, math, collections, heapq, itertools
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    file = sys.stdin.readline #single: int(file()), line: map(int, file().split())
    INF = 10 ** 25
    mod = 7 + 10 ** 9
    L = file()
    length = len(L)
    DP = [[0, 0] for i in range(length-1)]
    DP[0][0] = 2
    DP[0][1] = 1
    for i in range(1, length-1):
        if L[i] == "1":
            DP[i][0] = (DP[i-1][0] * 2) % mod
            DP[i][1] = (DP[i-1][0] + DP[i-1][1] * 3) % mod
        else:
            DP[i][0] = DP[i-1][0]
            DP[i][1] = (DP[i-1][1] * 3) % mod
    print(sum(DP[length - 2]) % mod)

    return 0
  
if __name__ == "__main__":
    solve()

Measured memory_bytes: 20020
#include<bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
	int x=0,p=1;char c=getchar();
	while (c<=32)c=getchar();
	if(c==45)p=-p,c=getchar();
	while (c>32)x=x*10+c-48,c=getchar();
	return x*p;
}
using namespace std;
//ruogu
int n,m,dp[(1<<12)+10];
//
int main(){
	n=getint();m=getint();
	rep(i,1<<n)dp[i]=INF;dp[0]=0;
	rep(ii,m){
		int a=getint(),b=getint();
		int mask=0;
		rep(j,b){
			int x=getint()-1;
			mask|=(1<<x);
		}
		rep(i,1<<n)dp[i|mask]=min(dp[i|mask],dp[i]+a);
	}
	if(dp[(1<<n)-1]==INF)dp[(1<<n)-1]=-1;
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}


Measured memory_bytes: 256
N,Y = map(int,input().split())

for i in range(N+1):
  for j in range(N+1-i):
    if 10000*i + 5000*j + 1000*(N-i-j) == Y:
      print(i, j, N-i-j)
      exit()
print(-1, -1, -1)

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

using namespace std;

const int N = 25;

int n;
int h[N], dp[N];
	
int main() {

	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> h[i];
	}
	int ans = 0;
	for (int i = 1; i <= n; i ++) {
		bool flag = true;
		for (int j = 1; j < i; j ++) {
			if (h[j] > h[i]) {
				flag = false;
				break;
			}
		}
		if (flag) ans ++;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
A, B, C, K = [int(i) for i in input().split()]

#%%
if K - A <= 0:
    print(K)
elif K - A - B <= 0:
    print(A)
elif K - A - B - C <= 0:
    print(A - (K - A - B))
else:
    print(A - C)


Measured memory_bytes: 9172
#include<iostream>
#include<algorithm>

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int sq[201];
  for(int i = 0; i <= 200; ++i) sq[i] = i*i;
  int N; std::cin >> N;
  for(int n = 1; n <= N; ++n) {
    int ans = 0;
    for(int x = 1; x*x+x+x+3 <= n; ++x) {
      for(int y = 1; x*x+y*y+1+x*y+x+y <= n; ++y) {
        int b = x+y;
        int c = x*y+x*x+y*y-n;
        int D = b*b-4*c;
        if(D < 0) break;
        int rD = std::lower_bound(sq, sq+201, D) - sq;
        if(rD*rD != D) continue;
        if((rD-b)%2==0) ++ans;
      }
    }
    std::cout << ans << "\n";
  }
  return 0;
}


Measured memory_bytes: 3540
n, k = [int(e) for e in input().split()]
h = [int(e) for e in input().split()]
cost = [0] * n
cost[1] = abs(h[1] - h[0])
for i in range(1, n):
  cost[i] = min(abs(h[i] - h[j]) + cost[j] for j in range(max(0, i - k), i))
print(cost[n - 1])


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

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 

void solve(){
    int n;
    cin >> n;
    vector<int>a(n+1);
    vector<int>b(n);
    for(int i=0;i<n+1;i++)cin >> a[i];
    for(int i=0;i<n;i++)cin >> b[i];
    int x=0;
    llint ans=0;
    for(int i=0;i<n;i++){
        x=min(a[i],b[i]);
        b[i]-=x;
        ans+=x;
        x=min(a[i+1],b[i]);
        a[i+1]-=x;
        ans+=x;
    }
    cout << ans << endl;
}

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


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

int main()
{
  for(int i=0;i<3;i++)
  {
    char a;
    cin>>a;
    if(a=='7')
    {
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}

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

using namespace std;
long long ll;

vector<int> sieve(int n) {
  vector<bool> is_prime(n, true);
  is_prime[0] = false;
  is_prime[1] = false;
  vector<int> primes;
  for (int i = 2; i * i <= n; ++i) {
    if (is_prime[i]) {
      primes.push_back(i);
      for (int j = i * i; j <= n; j += i) is_prime[j] = false;
    }
  }
  return primes;
}

set<int> primeFactorize(int n, vector<int> &primes) {
  set<int> res;
  int m = primes.size();
  for (int i = 0; i < m; ++i) {
    if (primes[i] > n) break;
    while (n % primes[i] == 0) {
      n /= primes[i];
      res.insert(primes[i]);
    }
  }
  if (n > 1) {
    res.insert(n);
  }
  return res;
}

bool check(vector<set<int> > x) {
  set<int> st = x[0];
  for (int i = 1; i < x.size(); ++i) {
    set<int> e = x[i];
    size_t n = st.size();
    size_t m = e.size();
    st.insert(e.begin(), e.end());
    if (st.size() < n + m)
      return false;
  }
  return true;
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}

int main() {
  vector<int> primes = sieve(1e6 + 1);
  int n;
  cin >> n;

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

  vector<set<int> > a_primes(n);
  for (int i = 0; i < n; ++i) {
    a_primes[i] = primeFactorize(a[i], primes);
  }

  if (check(a_primes)) {
    puts("pairwise coprime");
    return 0;
  }

  int g = a[0];
  for (int i = 1; i < n; ++i) {
    g = gcd(g, a[i]);
  }
  if (g == 1) {
    puts("setwise coprime");
  } else {
    puts("not coprime");
  }
  return 0;
}



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

using namespace std;

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

  for(int i=0;i<n;i++){
    printf("Case %d:\n", i+1);

    int k;
    char s[256];
    scanf("%d", &k);

    for(int j=0;j<10;j++){
      k *= k;
      sprintf(s, "%08d", k);
      int l = strlen(s);
      string sn(s);
      k = atoi(sn.substr(l-6, 4).c_str());
      printf("%d\n", k);
    }
  }
}

Measured memory_bytes: 0
#include<cstdio>
int n, a[200];
int main() {
    scanf ("%d\n", &n);
   
    int cmin=100;
    for (int i=0;i<n;i++) {
        int a;
        scanf("%d", &a);
        int c=0;
        while (a%2==0) {
            a/=2;
            c++;
        }  
    if (c<cmin) cmin=c;
    }    
    
    printf("%d\n", cmin);
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	int n;
	int[][] mat;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			n = sc.nextInt();
			if(n == 0) break;
			
			ArrayList<String> strs = new ArrayList<String>();
			for(int i=0;i<n;i++) {
				String str = sc.next();
				boolean flg = true;
				for(Iterator<String> it=strs.iterator();it.hasNext();) {
					String tmp = (String)it.next();
					if(tmp.indexOf(str) >= 0) { flg = false; break; }
					if(str.indexOf(tmp) >= 0) it.remove();
				}
				if(flg) strs.add(str);
			}
			
			String[] words = strs.toArray(new String[]{});
			n = words.length;
			mat = new int[n][n];
			
			for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(i!=j) {
				int l1 = words[i].length(), l2 = words[j].length();
				for(int k=0;k<l1;k++) if(l1-k <= l2 && words[i].endsWith(words[j].substring(0, l1-k))) {
					mat[i][j] = l1-k;
					break;
				}
			}
//			debug(words);
//			debug(mat);
			int len = 0;
			for(String w: words) len += w.length();
			int max = 0;
			mem = new int[n][1<<n]; for(int[] a: mem) fill(a, -1);
			for(int i=0;i<n;i++) max = max(max, solve(i, 1<<i));
//			debug(len, max);
			System.out.println(len - max);
		}
	}
	
	int[][] mem;
	int solve(int p, int S) {
		if(mem[p][S] >= 0) return mem[p][S];
		int max = 0;
		
		for(int i=0;i<n;i++) if( ((S>>i)&1) == 0 ) {
			max = max(max, solve(i, S|(1<<i)) + mat[p][i]);
		}
		return mem[p][S] = max;
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 58912
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007
#define endl "\n"
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    int n, m;
    cin>>n>>m;
    vi a(n);
    double tot=0;
    REP(i,0,n){
        cin>>a[i];
        tot+=a[i];
    }
    tot=(tot*1.0)/(4.0*m);
    int ct=0;
    REP(i,0,n){
        if(a[i]<tot){
            // tot++;
            ct++;
        }
    }
    ct=n-ct;

    if(ct>=m){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = "." + input() + "#"
B = [0]*(N+2)
W = [0]*(N+2)
b = 0
for k in range(N+2):
    if S[k] == "#":
        b += 1
    B[k] = b
w = 0
for k in range(N+1,-1,-1):
    if S[k] == ".":
        w += 1
    W[k] = w
ans = 10**10
for k in range(N+1):
    ans = min(ans,B[k]+W[k+1])
print(ans)


Measured memory_bytes: 73048
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        long[][] cnt = new long[10][10];
        for (int i = 1; i <= n; i++) {
            cnt[Character.getNumericValue(String.valueOf(i).charAt(0))][Character.getNumericValue(String.valueOf(i).charAt(String.valueOf(i).length() - 1))]++;
        }
        long ans = 0;
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                ans += cnt[i][j] * cnt[j][i];
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 42352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#ifdef LOCAL
#define debug(x) cerr << '[' << #x << " = " << (x) << "]\n"
#else
#define debug(x)
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;cin>>n;
	vector<int>v(n),dp(n,1e9);
	rep(i,0,n)cin>>v[i];
	dp[0]=0;
	rep(i,1,n){
		if(i-1>=0)dp[i]=min(dp[i],abs(v[i]-v[i-1])+dp[i-1]);
		if(i-2>=0)dp[i]=min(dp[i],abs(v[i]-v[i-2])+dp[i-2]);
	}
	cout<<dp[n-1]<<'\n';
}

Measured memory_bytes: 3992
n = gets.chomp.to_i
S = gets.chomp.split(" ").map(&:to_i)
q = gets.chomp.to_i
T = gets.chomp.split(" ").map(&:to_i)
#sortS = S.sort{|a, b| a <=> b}

count = 0

T.each do |t|
  left = 0
  # rightはn-1ではなくnにしてる
  right = n
  while left < right
    middle = (right+left) / 2
    if t == S[middle]
      count += 1
      break
    elsif S[middle] < t
      left = middle + 1
    else t < S[middle]
      #初期値のleft、right間の幅の定義と合わせるために、ここでは-1をしない
      right = middle 
    end
  end
end

puts count



Measured memory_bytes: 15652
#include <bits/stdc++.h>
using namespace std;
#define REP(i, t) for(int i = 0; i < t; i++)
#define INF (1 << 30)

int main()
{
    int X;
    cin >> X;
    if (X == 3 || X == 5 || X == 7)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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

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

	n -= k;
	int ans = 1;
	ans += (n + k - 2) / (k - 1);
	cout << ans << endl;




	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a[100000];
int mi = 1;
int ans;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < mi)continue;
		if (a[i] == mi)mi++;
		else ans += (a[i] - 1) / mi;
		if (mi == 1)mi++;
	}
	cout << ans << endl;
}

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

#define rep(i,n) for(int i = 0;i < n;++i)
#define rep2(i,n,m) for(int i = n;i < m;++i)
#define all(v) v.begin(),v.end()

using namespace std;
using ll = long long;


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

    int n,m=0;
    string s;

    cin >> n >> s;
    rep(i,n-2){
        if(s.at(i)=='A'&& s.at(i+1)=='B'&&s.at(i+2)=='C'){
            m++;
        }
    }
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = [int(input()) for _ in range(N)]
from collections import Counter

c = Counter(As)
ans = 0
for i, cnt in c.most_common():
    if cnt%2==0:
        continue
    else:
        ans += 1

print(ans)

Measured memory_bytes: 26160
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	if(a>b) swap(a,b);
	if(a<0&&b>0)
	{
		cout<<"Zero\n";
		return 0;
	}
	if(a==0||b==0)
	{
		cout<<"Zero\n";
		return 0;
	}
	if(a>0)
	{
		cout<<"Positive\n";
		return 0;
	}
	if(b<0)
	{
		if((b-a+1)%2)
			cout<<"Negative\n";
		else cout<<"Positive\n";
	}
	return 0;
}

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

int main(){
   int K;
   int A, B;
   cin >> K;
   cin >> A >> B;
   bool flag = false;
   for (int i=A; i<=B; i++){
      if (i % K == 0){
         flag = true;
      }
   }
   if (flag){
      cout << "OK" << endl;
   } else{
      cout << "NG" << endl;
   }
}



Measured memory_bytes: 3624
n,m,X,Y = map(int,input().split())
x = list(map(int,input().split()))
x = sorted(x)
y = list(map(int,input().split()))
y = sorted(y)
a = max(X,x[-1])
b = min(Y,y[0])
if a<b:
        print("No War")
else:
        print("War")

Measured memory_bytes: 3064
n = gets.strip.to_i
uvw = readlines.map {|line| line.strip.split.map(&:to_i) }

graph = Array.new(n+1) { [] }
uvw.each do|u, v, w|
  graph[u] << [v, w]
  graph[v] << [u, w]
end

q = [[1, 0]]
dist = [nil, 0]
until q.empty?
  from, from_cost = q.shift
  graph[from].each do |to, to_cost|
    next if dist[to]
    current_cost = from_cost+to_cost
    dist[to] = current_cost
    q.push << [to, current_cost]
  end
end

#puts (1..n).map {|e| dist[e] }
puts (1..n).map {|e| dist[e].even? ? 0 : 1 }


Measured memory_bytes: 38892
#include<cstdio>
#include<algorithm>
int main() {
	int n, d[100], i;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &d[i]);
	}
	std::sort(d, d + n);
	int ans = 1;
	for (i = 1; i < n; i++) {
		if (d[i - 1] < d[i]) {
			ans++;
		}
	}
	printf("%d", ans);
	return 0;
}

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

using namespace std;

int main() {
    string s;
    getline(cin, s);
    
    int blue = 0, red = 0;
    for(int i = 0; i < (int)s.size(); i++)
    {
        if (s[i] == '0')
        {
            red++;
        } else {
            blue++;
        }
    }       

    cout << min(red, blue) * 2;
}


Measured memory_bytes: 512
Scanf.scanf "%d" @@ fun n ->
  Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0))
  |> Array.fold_left (fun (s, l) x ->
      let c = if x = 0 then 0 else l + x mod 2 in
      s + x/2 + c/2, c mod 2) (0, 0)
  |> fst |> Printf.printf "%d\n"

Measured memory_bytes: 5376
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int n;
const int maxn = 205;

int x[maxn],y[maxn];

long long ans[maxn];

const int mod = 998244353;

int qpow(int x,int n){
	int ret = 1;
	while(n > 0){
		if(n & 1){
			ret = 1LL * ret * x % mod;
		}
		x = 1LL * x * x % mod;
		n >>= 1;
	}
	return ret;
}

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

int main(){
	cin >> n;
	for(int i = 1;i <= n;i++){
		scanf("%d%d",x + i,y + i);
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++) if(j != i){
			int num = 2;
			for(int k = 1;k <= n;k++) if(k != i && k != j){
				if((x[k] - x[i]) * (y[j] - y[i]) - (x[j] - x[i]) * (y[k] - y[i]) == 0) num++;	
			}
			upd(ans[num],(qpow(2,num) - 1 - num + mod) % mod);
		}
	}
	long long res = 0;
	upd(res,qpow(2,n));
	upd(res,-n-1);
	for(int i = 1;i <= n;i++){
		int tmp = ans[i] * qpow(i,mod - 2) % mod * qpow(i - 1,mod - 2) % mod;
		upd(res,-tmp);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
start_A, end_B = map(long, raw_input().split())

result = 0
if start_A == end_B:
  result = start_A
else:
  num_count = end_B - start_A + 1
  if start_A % 2 == 0:
    num_pair = num_count // 2
    if num_count % 2 == 0:
      result = num_pair % 2
    else:
      result = (num_pair % 2) ^ end_B
  else:
    num_pair = (num_count - 1) // 2
    if (num_count - 1) % 2 == 0:
      result = start_A ^ (num_pair % 2)       
    else:
      result = start_A ^ (num_pair % 2) ^ end_B

print result

Measured memory_bytes: 2692
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    String s = Integer.toString(a) + Integer.toString(b);
    int i = Integer.parseInt(s);
    double result = (int)Math.sqrt(i);
    if(result*result == i){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


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

int main() {
    int H, W;
    
    while(true) {
        cin >> H >> W;

        if(H == 0 && W == 0) { break; }

        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                cout << "#";
            }
            cout << "\n";
        }
        cout << endl;
    }    

    return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE

map< int, int > prime_factor(int n) {
  map< int, int > ret;
  for(int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
bool dist(vector<int>& A ,vector<int> &B)
{
  int D = 0;
  for (int i = 0; i < A.size(); i++)
  {
    D += (A[i] - B[i])* (A[i] - B[i]);
  }
  auto pf = prime_factor(D);
  bool check = 1;
  for (auto &&i : pf)
  {
    if(i.second%2 == 1)check = 0;
  }
  return check;
}
void solve (void)
{
  int N;cin>>N;
  int D;cin>>D;
  vector<vector<int> > vv (N,vector<int>(D,0));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < D; j++)
    {
      cin>>vv[i][j];
    }
  }
  int cnt = 0;
  for (int i = 0; i < N; i++)
  {
    for (int j = i+1; j < N; j++)
    {
      if(dist(vv[i],vv[j]))cnt++;
    }
    
  }
  cout<<cnt<<endl;
  
  

  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> l(q); vector<int> r(q);
    REP(i,q) cin >> l[i] >> r[i];
    vector<int> ans(n, 0);
    int cnt = 0;
    REP(i,n-1) {
        if (s[i] == 'A' && s[i+1] == 'C') {
            ans[i+1] = ans[i]+1;
        } else {
            ans[i+1] = ans[i];
        }
    }
    //REP(i,n) cout << "ans : " << ans[i] << endl;
    REP(i,q) {
        cout << ans[r[i]-1]-ans[l[i]-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 2176
using System;
using System.Collections.Generic;
using System.Linq;

namespace _032_Ball
{
	class Program
	{
		static void Main ( string[] args )
		{
			int dataCount = int.Parse (Console.ReadLine ());

			for (int lp = 0; lp < dataCount; lp++)
			{
				int[] ballNumber = Console.ReadLine ().Split (' ').Select (int.Parse).ToArray ();

				Stack<int> cylinderA = new Stack<int> (ballNumber.Length);
				Stack<int> cylinderB = new Stack<int> (ballNumber.Length);

				bool isAccept = true;

				cylinderA.Push (0);
				cylinderB.Push (0);

				for (int index = 0; index < ballNumber.Length; index++)
				{
					int item = ballNumber[index];

					//A < B
					if (cylinderA.Peek () < cylinderB.Peek ())
					{
						//B???A???not
						//B
						if (cylinderB.Peek () < item)
						{
							cylinderB.Push (item);
						}
						//A
						else if (cylinderA.Peek () < item)
						{
							cylinderA.Push (item);
						}
						//can not
						else
						{
							isAccept = false;
							break;
						}
					}
					//A > B
					else
					{
						//A???B???not
						//A
						if (cylinderA.Peek () < item)
						{
							cylinderA.Push (item);
						}
						//B
						else if (cylinderB.Peek () < item)
						{
							cylinderB.Push (item);
						}
						//can not
						else
						{
							isAccept = false;
							break;
						}
					}
				}

				if (isAccept)
					Console.WriteLine ("YES");
				else
					Console.WriteLine ("NO");
			}
		}
	}
}

Measured memory_bytes: 10168
o=input()
e=input()
a=[]
i=0
while 1:
    #print(i)
    if i%2==0:
        a.append(o[i//2])
    else:
        a.append(e[i//2])
    i+=1
    if len(o)+len(e)==i:
        a="".join(a)
        print(a)
        exit()

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

#define ll long long
#define ar array

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

	string u, s, t; 
	int a, b; 
	cin >> s >> t >> a >> b >> u;
	if(s==u)
		--a;
	else
		--b;
	cout << a << " " << b;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define up(a,b) (((a)%(b)==0)?((a)/(b)):((a)/(b))+1)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) (a>b)?(a>c)?a:c:(b>c)?b:c
#define min3(a,b,c) (a<b)?(a<c)?a:c:(b<c)?b:c
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;
 
ll mymod(ll a, ll b)
{
	return (a%b + b)%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b, a%b);
}
bool prime[3001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=3000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=3000; i += p) 
                prime[i] = false; 
        } 
    } 
}
ll powe[20];
void power()
{
	powe[0]=1;
	REP(i,1,20)
	{
		powe[i]=(powe[i-1]*10)%num;
        if(powe[i]<0)
        powe[i]+=num;
	}
}
struct edge
{
	ll src;
	ll to;
	ll val;
	ll index;
};
struct node
{
	vll adj;
	ll parent;
	ll time;
	ll ex_time;
	ll indegree;
};

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,m;
	cin>>n>>m;
	cout<<min(mymod(n,m), -1 *(mymod(n,m)-m));
	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long
#define tc(t)  int t; cin>>t; while(t--)
#define f(n)    for(int i=0;i<n;i++)
#define endl   "\n"
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

 int apple,peice;
 cin>>apple>>peice;
 int answer=apple*3+ peice;
 cout<<answer/2<<endl;
 

}

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


using namespace std;

int main() {
	int a;
	int num[200];

	cin >> a;

	for (int i = 0; i < a; i++) cin >> num[i];

	int n = 0;

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

		if (num[i] % 2 != 0)break;
		else num[i] = num[i] / 2;

		if (i == (a - 1)) {
			n++;
			i = 0;
		}

	}

	cout << n << endl;
	return 0;
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  int l=0,r=n;
  rep(i,m){
      int s,t;
      cin>>s>>t;
      l=max(l,s);
      r=min(t,r);
  }
  if(r>=l)cout<<r-l+1<<endl;
  else cout<<0<<endl;
  return 0;
  }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forab(i, a, b) for(int i=(a);i<(b);++i)
#define foreach(i, n) for (__typeof(n.begin()) i = n.begin(); i != n.end(); ++i)
#define sqr(x) ((x)*(x))
#define clr(a, b) memset(a, b, sizeof(a))
#define MP make_pair
#define PB push_back
#define SZ(a) ((int)a.size())
#define all(a) (a).begin(),(a).end()
#define inf 0x3f3f3f3f
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
const double eps = 1e-8;
int dcmp(double x) { if (x < -eps) return -1; else return x > eps;}
#define se(x) cout<<#x<<" = "<<x<<endl

#ifdef CHEN_PC
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...)
#endif

const int N = 100010;
const int mod = 1000000007; // 10^9+7
int n;
int a[N];

struct mint {
	ll x;
	mint():x(0){}
	mint(ll x):x((x%mod+mod)%mod){}
	mint& fix() { x = (x%mod+mod)%mod; return *this;}
	mint operator-() const { return mint(0) - *this;}
	mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
	mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
	mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
	mint operator+(const mint& a)const{ return mint(*this) += a;}
	mint operator-(const mint& a)const{ return mint(*this) -= a;}
	mint operator*(const mint& a)const{ return mint(*this) *= a;}
	bool operator<(const mint& a)const{ return x < a.x;}
	bool operator==(const mint& a)const{ return x == a.x;}
	mint pow(ll n) const {
		mint x = *this, r = 1;
		while (n) {
			if (n & 1) r *= x;
			x *= x;
			n >>= 1;
		}
		return r;
	}
	mint inv() const { return (*this).pow(mod - 2); }
	mint operator/(const mint& a)const{ return *this * a.inv(); }
	mint& operator/=(const mint& a){ return *this = *this / a; }
};

mint val[N];
mint sum[N];

int solve() {
	mint v = 1;
	forab (i, 1, n+1) {
		v *= i;
	}
	sum[0] = 0;
	forab (i, 1, n+1) {
		val[i] = v / i;
		sum[i] = sum[i - 1] + val[i];
	}

	mint ans;
	forab (i, 1, n+1) {
		ans += (sum[i] + sum[n + 1 - i] - sum[1]) * a[i];
	}

	return (int)ans.fix().x;
}

int main(int argc, char *argv[]) {
#ifdef CHEN_PC
	freopen("B.in", "r", stdin);
#endif

	while (scanf("%d", &n) != EOF) {
		forn (i, n) {
			scanf("%d", a + i + 1);
		}
		int ret = solve();
		printf("%d\n", ret);
	}
	return 0;
}



Measured memory_bytes: 2176
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, functools, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ; count = 0; pro = 1

n=int(input())
count=0
# @functools.lru_cache(maxsize=None)
memo=[0]*(n+1)
memo[0]=0
def func(n):
    if memo[n] or n==0:return memo[n]
    # print(n)
    # global count
    # count+=1
    # if count%10==0:print(count)
    if n==0:
        return 0
    re=func(n-1)+1
    k=s=1
    while 9**s<=n:
        re=min(re,func(n-9**s)+1)
        s+=1
    while 6**k<=n:
        re=min(re,func(n-6**k)+1)
        k+=1
    re=min(re,func(n-1)+1)
    memo[n]=re
    return re
    
print(func(n))
# print(memo)



Measured memory_bytes: 90228
n = int(input())
if n%10 == 2 or n%10 == 4 or n%10 == 5 or n%10 == 7 or n%10 == 9:
  print("hon")
elif n%10 == 0 or n%10 == 1 or n%10 == 6 or n%10 == 8:
  print("pon")
else:
  print("bon")

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
struct edge{
	int a,b;
	ll c;
	int id;
	edge(int x,int y,int z,int w):a(x),b(y),c(z),id(w){}
};
bool comp(const edge& x, const edge& y){
	return x.c<y.c;
}
int par[100000];
int find(int x){
	if(x==par[x]) return x;
	return par[x]=find(par[x]);
}
bool same(int x,int y){
	return find(x)==find(y);
}
void unite(int x,int y){
	par[find(x)]=find(y);
}

int N,M;
ll sum=0;
int o[100000];
set<P> st[100000];		//st[v] P(es[id].c,id)
vector<P> G[100000];
vector<int> oG[100000];
vector<edge> es;
ll ans[200000];
void dfs(int v,int p,int btw){
//	for(P pu:G[v]) if(pu.fs!=p) dfs(pu.fs,v,pu.sc);
	for(int i:oG[v]){
		st[v].insert(P(es[i].c,i));
	}
	int id=v;
	for(P u_:G[v]) if(u_.fs!=p){
		int u=o[u_.fs];
		if(st[id].size()<st[u].size()) swap(id,u);
		for(P pi:st[u]){
			if(st[id].find(pi)!=st[id].end()) st[id].erase(pi);
			else st[id].insert(pi);
		}
	}
	o[v]=id;
	if(v==0) return;
	if(st[id].empty()){
		ans[es[btw].id]=-1;
/*		show(v);
		show(p);
		show(id);
		assert(0);*/
	}else{
		ans[es[btw].id]=sum-es[btw].c+(*st[id].begin()).fs;
	}
}
int main(){
	cin>>N>>M;
	rep(i,N) par[i]=i;
	rep(i,M){
		int a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		es.pb(edge(a,b,c,i));
	}
	sort(all(es),comp);
	int cnt=0;
	rep(i,M){
		edge e=es[i];
		if(same(e.a,e.b)){
			oG[e.a].pb(i);
			oG[e.b].pb(i);
			ans[e.id]=-2;
		}else{
			unite(e.a,e.b);
			sum+=e.c;
			cnt++;
			G[e.a].pb(P(e.b,i));
			G[e.b].pb(P(e.a,i));
		}
	}
	rep(i,M) if(ans[i]==-2) ans[i]=sum;
	if(cnt!=N-1){
		rep(i,M) puts("-1");
		return 0;
	}
	int pa[100000]={};
	queue<int> que;
	que.push(0);
	pa[0]=-1;
	vector<int> a,b,c;
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(P p:G[v]){
			if(p.fs==pa[v]) continue;
			a.pb(p.fs),b.pb(v),c.pb(p.sc);
			pa[p.fs]=v;
			que.push(p.fs);
		}
	}
	int K=a.size();
	rep(i,K) dfs(a[K-1-i],b[K-1-i],c[K-1-i]);
	rep(i,M) cout<<ans[i]<<endl;
}

Measured memory_bytes: 65108
#include <iostream>

using namespace std;

int main() {
	int n, q;
	while (cin >> n >> q) {
		if (n == 0 && q == 0) {
			break;
		}
		int hyou[101] = {0};
		for (int i = 0; i < n; i++) {
			int k;
			cin >> k;
			for (int j = 0; j < k; j++) {
				int a;
				cin >> a;
				hyou[a]++;
			}
		}
		int max = 0;
		int data = 0;
		for (int i = 0; i < 101; i++) {
			if (hyou[i] >= q) {
				if (hyou[i] > max) {
					max = hyou[i];
					data = i;
				}
			}
		}
		cout << data << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int n, m;
  cin >> n >> m;
  ivec a(n);
  ll sum = 0;
  REP(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  sort(RALL(a));
  int s = (sum + (m * 4 - 1)) / (4 * m);
  REP(i, m) {
    if (a[i] < s) {
      print("No");
      return 0;
    }
  }
  print("Yes");
  return 0;
}

Measured memory_bytes: 256
n = int(input())
s = [ input() * 2 for _ in range(n)]

ans = 0
for k in range(n):
    check = 1
    for i in range(n-1):
        for j in range(i+1,n):
            if(s[i][j+k] != s[j][i+k]):
                check = 0
                break
        if(check==0):
            break
    ans += check * n

print(ans)

Measured memory_bytes: 73952
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, ans;
bool ok[100005];
vector<int> p;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n;
    p.resize(n);
    erep(i, 1, n) {
        cin >> p[i];
        if (p[i] != i) ok[i] = true;
        else ok[i] = false;
    }
    rep(i, 1, n) {
        if (!ok[i]) {
            ans++;
            ok[i] = ok[i+1] = true;
        }
    }
    if (!ok[n]) ans++;
    printf("%d\n", ans);
    return 0;
}


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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... Args> void rd(Args&... args) {((cin >> args), ...);}
template<typename... Args> void write(Args... args) { ((cout << args << " "), ...); cout<<endl;}

const int N=1e5+5;
int h[N];
vector<int> G[N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin>>n>>m;
    int ans=0;
    for1(i,n) cin>>h[i];
    forn(i,m){
        int x,y;
        cin>>x>>y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    for1(i,n){
        int flag=1;
        for(auto it:G[i]) if(h[it]>=h[i]){
            flag=0;
            break;
        }
        ans+=flag;
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 9176
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	String S = sc.next();
    	boolean key = true;
    	for (int i = 0; i < S.length(); i++) {
    		if (i == A) {
    			if (S.charAt(i) != '-') {
    				key = false;
    			}
    		} else {
    			if (!S.substring(i, i+1).matches("[0-9]")) {
    				key = false;
    			}
    		}
    	}
    	System.out.println(key ? "Yes" : "No");
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back  
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll    

const int N = 2e5 + 10;
int cnt_operations = 0;
char type[N];
int X[N], Y[N], Z[N];

void get_pl(int a, int b, int c) {
  type[cnt_operations] = '+';
  X[cnt_operations] = a;
  Y[cnt_operations] = b;
  Z[cnt_operations] = c;
  cnt_operations++;
}

void get_ls(int a, int b, int c) {
  type[cnt_operations] = '<';
  X[cnt_operations] = a;
  Y[cnt_operations] = b;
  Z[cnt_operations] = c;
  cnt_operations++; 
}

void out() {
  cout << cnt_operations << '\n';
  for (int i = 0; i < cnt_operations; i++) {
    cout << type[i] << ' ' << X[i] << ' ' << Y[i] << ' ' << Z[i] << '\n';
  }
}

const int BITS = 30;

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); 
  cout.tie(0);
  int A = 0, B = 1, res = 2, one = 3;
  get_pl(A, B, one);
  get_ls(228, one, one);
  get_pl(A, one, A);
  get_pl(B, one, B);
  //now we have 1 at one
  int ptr = 4;
  vector<int> bits_A(BITS), pows_A(BITS), bits_B(BITS), pows_B(BITS);
  for (int i = 0; i < BITS; i++) {
    bits_A[i] = ptr++;
  }
  for (int i = 0; i < BITS; i++) {
    pows_A[i] = ptr++;
  }   
  for (int i = 0; i < BITS; i++) {
    bits_B[i] = ptr++;
  }
  for (int i = 0; i < BITS; i++) {
    pows_B[i] = ptr++;
  }
  for (int i = BITS - 1; i >= 0; i--) {
    int cpos = bits_A[i];
    get_pl(one, res, cpos);
    for (int j = 0; j < i; j++) {
      get_pl(cpos, cpos, cpos);
    }
    for (int j = i + 1; j < BITS; j++) {
      get_pl(cpos, pows_A[j], cpos);
    }
    get_ls(cpos, A, cpos);
    get_pl(cpos, res, pows_A[i]);
    for (int j = 0; j < i; j++) {
      get_pl(pows_A[i], pows_A[i], pows_A[i]);
    }
  }
  for (int i = BITS - 1; i >= 0; i--) {
    int cpos = bits_B[i];
    get_pl(one, res, cpos);
    for (int j = 0; j < i; j++) {
      get_pl(cpos, cpos, cpos);
    }
    for (int j = i + 1; j < BITS; j++) {
      get_pl(cpos, pows_B[j], cpos);
    }
    get_ls(cpos, B, cpos);
    get_pl(cpos, res, pows_B[i]);
    for (int j = 0; j < i; j++) {
      get_pl(pows_B[i], pows_B[i], pows_B[i]);
    }
  }
  vector<vector<int>> mult_pows(BITS, vector<int>(BITS));
  for (int i = 0; i < BITS; i++) {
    for (int j = 0; j < BITS; j++) {
      mult_pows[i][j] = ptr++;
      get_pl(bits_A[i], bits_B[j], mult_pows[i][j]);
      get_ls(one, mult_pows[i][j], mult_pows[i][j]);
      for (int k = 0; k < i + j; k++) {
        get_pl(mult_pows[i][j], mult_pows[i][j], mult_pows[i][j]);
      }
      get_pl(res, mult_pows[i][j], res);
    }
  }
  out();

}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

ll dp[MX], h[MX];

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int N,K; cin >> N >> K;

    F0R(i,N) cin >> h[i];

    memset(dp,63,sizeof dp);

    dp[0] = 0;
    FOR(x,1,N) {
        FOR(k,1,K+1) {
            dp[x] = min(dp[x],(x-k >= 0) ? dp[x-k]+abs(h[x]-h[x-k]) : INF);
        }
    }

    cout << dp[N-1] << "\n";

}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define F first
#define S second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const int X=2e5+9;
const ll inf=(1ll<<60);
const ll mod=1e9+7;
ll w,a,b;
int main(){
    scanf("%lld%lld%lld",&w,&a,&b);
    if(a==b){
        puts("0");
        return 0;
    }
    if(a>b)swap(a,b);
    a+=w;cout<<max(0ll,b-a)<<endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

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

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n, x;
    cin >> n >> x;
    vector<int> s(n);
    rep(i, n) cin >> s[i];
    sort(ALL(s), greater<int>());

    auto dp = initVec2<int>(n + 1, x + 1);
    dp[0][x] = 1;
    rep(i, n){
        for(int j = 0; j <= x; j++){
            dp[i+1][j%s[i]] += dp[i][j];
            dp[i+1][j%s[i]] %= MOD;
            dp[i+1][j] += dp[i][j] * (n - 1 - i) % MOD;
            dp[i+1][j] %= MOD;
        }
    }

    int ans = 0;
    rep(i, x + 1){
        ans += dp[n][i] * i % MOD;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 158592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N; cin >>N;
  int count=0;
  int countA=0;
  int countB=0;
  int countAB=0;
  for(int i=0;i<N;i++){
    string A;
    cin>>A;
    int kazu=A.size();
    if(A[0]=='B'&&A[kazu-1]=='A'){
      countAB++;
    }else if(A[kazu-1]=='A'){
      countB++;
    }else if(A[0]=='B'){
      countA++;
    }
    for(int j=0;j<kazu-1;j++)if(A[j]=='A'&&A[j+1]=='B')count++;
  }
  int kotae=0;
  if(countAB==0){
    kotae=min(countA,countB);
  }else{
    if(countA+countB==0){
      kotae=countAB-1;
    }else{
      kotae=countAB+min(countA,countB);
    }
  }
  kotae+=count;
  cout <<kotae<<endl;
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int ali = b-a;
  int bob = d-c;
  int ans = 0;
  if(a <= c && b <= d) ans = b-c;
  if(ali > bob) ans = bob;
  if(ali < bob) ans = ali;
  if(a >= c && b >= d) ans = d-a;
  if(a > d || b < c) ans = 0;
  cout << ans << endl;
  return 0;
}

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

int64_t Luca(int N){
    if(N==0)
      return 2;
    else if(N==1)
      return 1;
    else
      return Luca(N-1)+Luca(N-2);
}

int main() {
  int N;
  cin >> N;
  int64_t Luca=1;
  int64_t count1=1;
  if(N==1)
    cout << Luca << endl;
  else{
    int64_t count2=2;
  for(int i=1; i<N; i++){
    Luca+=count2;
    count2=count1;
    count1=Luca;
  }
  cout << Luca << endl;
  }
}

Measured memory_bytes: 256