akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n;
long long k,a[100010];
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;++i){
        scanf("%lld",a+i);
	}
	for(int i=1;i<n;++i){
	    if(a[i]+a[i+1]>=k){
	        puts("Possible");
	        for(int j=1;j<i;++j)printf("%d\n",j);
	        for(int j=n-1;j>=i;--j)printf("%d\n",j);
			return 0;
		}
	}
	puts("Impossible");
}

Measured memory_bytes: 1536
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

set<ll>s;
ll ans(0);
//素因数分解　
//pair<ll,ll>型
//auto pf=prime_factorize(ll N);で呼ぶ
//for(auto p:pf){}で探す

vector<pair<ll, ll>>prime_factorize(ll n) {
	vector<pair<ll, ll>>res;
	for (ll p = 2; p * p <= n; ++p) {
		if (n % p != 0)continue;
		int num = 0;
		while (n % p == 0) {
			++num;
			n /= p;
		}
		res.push_back(make_pair(p, num));
		if (s.count(p))ans++;
		else s.insert(p);
	}
	if (n != 1) {
		res.push_back(make_pair(n, 1));
		if (s.count(n))ans++;
		else s.insert(n);
	}
	return res;
}

int main() {
	ll x, y;
	cin >> x >> y;
	
	auto pf=prime_factorize(x);
	auto pf2=prime_factorize(y);
	cout << ans + 1;
	return 0;
}

Measured memory_bytes: 3592
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.buffer.readline

    class Bit:
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)

        def sum(self, i):
            s = 0
            while i > 0:
                s += self.tree[i]
                i -= i & -i
            return s

        def add(self, i, x):
            while i <= self.size:
                self.tree[i] += x
                i += i & -i

        def lower_bound(self, w):
            if w <= 0:
                return 0
            x = 0
            k = 1 << (self.size.bit_length() - 1)
            while k:
                if x + k <= self.size and self.tree[x + k] < w:
                    w -= self.tree[x + k]
                    x += k
                k >>= 1
            return x + 1

    N, Q = map(int, input().split())
    C = list(map(int, input().split()))
    query = []
    for q in range(Q):
        query.append(list(map(int, input().split())))
        query[-1].append(q)
    query.sort(key=lambda x: x[1])

    last = [0] * (N+1)
    for i, c in enumerate(C):
        if i > query[0][1]-1:
            break
        last[c] = i+1

    bit = Bit(N)
    for i in range(1, N+1):
        if last[i]:
            bit.add(last[i], 1)
    r_prev = query[0][1]
    ans = [0] * Q
    for l, r, q in query:
        if r > r_prev:
            for i in range(r_prev+1, r+1):
                j = last[C[i-1]]
                if j:
                    bit.add(j, -1)
                last[C[i-1]] = i
                bit.add(i, 1)
            r_prev = r
        ans[q] = bit.sum(r) - bit.sum(l-1)

    for a in ans:
        print(a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 179852
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
using namespace std;

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


void solve(){

   
    int n , x, t;
    cin>>n>>x>>t;

    int ans = 0;

    int cnt = 0;
    while(cnt < n) {
        cnt += x;
        ans += t;
    }

    cout<<ans<<endl;


    


}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3648
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for i in range(A+1):
    if i*500 > X:
        continue
    for j in range(B+1):
        if i*500 + j*100 > X:
            continue
        for k in range(C+1):
            if i*500 + j*100 + k*50 == X:
                ans += 1
                
print(ans)

Measured memory_bytes: 39664
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int main(void) {
    string S;
    cin>>S;
    
    Int ans = 0;
    Int counter = 0;
    for(int i = 0;i <S.size();i++) {
        if(S[i] == 'A') {
            counter++;
        } else if(i > 0 && (S[i] == 'B' && S[i+1] == 'C')) {
            ans += counter;
            i++;
        } else {
            counter = 0;
        }
    }

    cout<<ans<<endl;

    return 0;
}





Measured memory_bytes: 640
#include<iostream>

using namespace std;

int N;
int A[210]={0};

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

    int counter=0;

    while(true){
        bool cannot=false;
        for(int i=0; i<N; ++i){
            if(A[i]%2!=0) cannot=true;
        }

        if(cannot==true) break;
        
        for(int i=0; i<N; ++i) A[i]/=2;
        counter++;
    }

    cout << counter << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
using namespace std;
ll ans;
signed main(){
	ios_base::sync_with_stdio(0);
	int n;
	cin>>n;
	vector<int> l(n);
	for(int i=0;i<n;i++) cin>>l[i];
	sort(all(l));
	for(int i=0;i+2<n;i++){
		for(int j=i+1;j+1<n;j++){
			int a=l[i],b=l[j];
			ans+=lower_bound(all(l),a+b)-l.begin()-1-j;
		}
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3656
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        // int[] a = new int[N];
        int x=0;
        int y=0;
        int z=0;
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();
            if (a == 1) {
                x++;
            } else if(a == 2) {
                y++;
            } else if(a == 3) {
                z++;
            }
        }
        double[][][] dp = new double[N+6][N+6][N+6];

        LinkedList<State> queue = new LinkedList<>();
        queue.offerLast(new State(0,0,0));
        int[][][] inDegree = new int[N+6][N+6][N+6];
        for(int i = 0; i < N+6; i++) {
            for(int j = 0; j < N+6; j++) {
                for (int k = 0; k < N+6; k++) {
                    inDegree[i][j][k] = calcInDegree(i, j, k);
                }
            }
        }

        while(queue.size() > 0) {
            State v = queue.pollFirst();
            int s = v.sum();
            if (s != 0) {
                dp[v.x][v.y][v.z] += ((double) N)/s;
            }
            if(s < N) {
                dp[v.x + 1][v.y][v.z] += (dp[v.x][v.y][v.z] * (v.x + 1))/(s + 1);
                if(--inDegree[v.x+1][v.y][v.z] == 0) {
                    queue.offerLast(new State(v.x+1,v.y,v.z));
                }
            }
            if(v.x > 0) {
                dp[v.x-1][v.y+1][v.z] += (dp[v.x][v.y][v.z] * (v.y + 1))/s;
                if(--inDegree[v.x-1][v.y+1][v.z] == 0) {
                    queue.offerLast(new State(v.x-1,v.y+1,v.z));
                }
            }
            if (v.y > 0) {
                dp[v.x][v.y - 1][v.z + 1] += (dp[v.x][v.y][v.z] * (v.z + 1)) / s;
                if (--inDegree[v.x][v.y - 1][v.z + 1] == 0) {
                    queue.offerLast(new State(v.x, v.y - 1, v.z + 1));
                }
            }
            if (v.x > N+3) break;
        }

        double ans = dp[x][y][z];
        System.out.println(ans);
    }
    public static int calcInDegree(int x, int y, int z) {
        int ans = 0;
        ans += x > 0 ? 1 : 0;
        ans += y > 0 ? 1 : 0;
        ans += z > 0 ? 1 : 0;
        return ans;
    }
    public static class State {
        public int x;
        public int y;
        public int z;

        public State(int x, int y, int z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        public int sum(){
            return this.x + this.y + this.z;
        }
    }
}

Measured memory_bytes: 704016
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
int n;
  cin>>n;
  vector<int> vec(n);
  for(int i=0;i<n;i++)cin>>vec[i];
  int a_max=max(vec[0],vec[1]),a_second=min(vec[0],vec[1]);
  for(int i=2;i<n;i++){
  if(vec[i] >= a_max){
  a_second=a_max;
    a_max=vec[i];
    
  
  }
  else if(vec[i] >= a_second)a_second=vec[i];
    else continue;
  
  }
    for(int i=1;i<n+1;i++){
    if(vec[i-1] == a_max)cout << a_second <<endl;
      else cout << a_max <<endl;
      
    }
  
  
}

Measured memory_bytes: 4004
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);  
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
 
template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind(){double x; scanf("%lf",&x);return x;}

///*....Bitmask....*///
int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

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

///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;


int main()
{
    int t=1,te=0;
    //Int(t);
    while(t--){
        int k;
        Int(k);

        int x=0;
        for(int i=1;i<=1e7;++i){
            x= x*10 + 7;
            if(x>=k){
                if(x%k==0){
                    printf("%d\n", i);
                    return 0;
                }
                x=x%k;
            }
        }
        printf("-1\n");

        //printf("Case %d: ",++te);
    }
    return 0;
}






Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

constexpr ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    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 {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

class combination{
private:
    vector<mint> fact,inv,finv;
public:
    combination(int N){
        fact = inv = finv = vector<mint>(N+1);
        fact[0] = fact[1] = 1;
        inv[0] = inv[1] = 1;
        finv[0] = finv[1] = 1;
        for(ll i=2;i<=N;i++){
            fact[i] = fact[i-1]*i;
            inv[i] = (mint) mod - inv[mod%i]*(mod/i);
            finv[i] = finv[i-1]*inv[i];
        }
    }
    mint f(int i){
        return fact[i];
    }
    mint comb(int n,int k){
        if(n<k) return 0;
        if(n<0 || k<0) return 0;
        return fact[n]*finv[k]*finv[n-k];
    }
    mint hcomb(int n,int k){
        if(n==0 && k==0) return 1;
        return comb(n+k-1,k);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    vec<ll> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    combination comb(N);
    mint ans = 0;
    for(int i=K-1;i<N;i++){
        if(i<K-1) continue;
        mint val = A[i];
        ans += val*comb.comb(i,K-1);
    }
    for(int i=0;i<N-K+1;i++){
        mint val = A[i];
        ans -= val*comb.comb(N-i-1,K-1);
    }
    cout << ans.x << endl;
}

Measured memory_bytes: 3456
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef uint B;

#define mask 0x07

#define get(d,i) (((d) >> ((i)*3)) & mask)

#define set(d,i,n) {d &= ~(mask << ((i)*3)); d |= (n << (3*(i)));}

#define get2(d,x,y) get(d, x+y*4)

#define set2(d,x,y,n) set(d, x+y*4, n)

#define ABS(x) ((x)<0?-(x):(x))

//struct B { char b[2][4]; };

int py[8] = { 0,0,0,0,1,1,1,1 };
int px[8] = { 0,1,2,3,0,1,2,3 };

int manhattan(B b){
  int ret = 0;
  REP(y,2) REP(x,4)
    ret = ret + ABS(py[get2(b,x,y)]-y) + ABS(px[get2(b,x,y)]-x);
  return ret;
}

//bool operator < (const B &a, const B &b) { return true; }
static inline B swap(B b, int p1, int p2){
  int d1 = get(b, p1);
  int d2 = get(b, p2);
  set(b, p1, d2);
  set(b, p2, d1);
  return b;
}

static inline B swap2(B b, int x1, int y1, int x2, int y2){
  return swap(b, x1+y1*4, x2+y2*4);
}

B q[1<<24];
int flag[1<<24];

int main(){
  int tmp;
  B ans = 0; REP(i,8) set(ans,i,i);
  memset(flag, 0, sizeof(flag));

  int head = 0;
  int tail = 0;
  q[tail++] = ans;
  flag[ans] = 1;

  while(head != tail){
    B bb = q[head++];
    int nn = flag[bb];

    REP(y,2) REP(x,4){
      if(get2(bb,x,y) == 0){
        if(y == 0){
          B bbb = swap2(bb,x,y,x,y+1);
          if(flag[bbb] == 0){
            flag[bbb] = nn + 1;
            q[tail] = bbb;
            tail = (tail + 1) % (1<<24);
          }
        }else{
          B bbb = swap2(bb,x,y,x,y-1);
          if(!flag[bbb]){
            flag[bbb] = nn + 1;
            q[tail] = bbb;
            tail = (tail + 1) % (1<<24);
          }
        }
        if(x != 0){
          B bbb = swap2(bb,x,y,x-1,y);
          if(!flag[bbb]){
            flag[bbb] = nn + 1;
            q[tail] = bbb;
            tail = (tail + 1) % (1<<24);
          }
        }
        if(x != 3){
          B bbb = swap2(bb,x,y,x+1,y);
          if(!flag[bbb]){
            flag[bbb] = nn + 1;
            q[tail] = bbb;
            tail = (tail + 1) % (1<<24);
          }
        }
      }
    }
  }
  while(~scanf("%d",&tmp)){
    B b = 0;
    set(b,0,tmp);
    REP(i,7){
      scanf("%d",&tmp);
      set(b,i+1,tmp);
    }
    printf("%d\n",flag[b]-1);
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main()
{
	int n, a[100];
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) 
	{
		scanf("%d", &a[i]);
	}
	for (int i = n - 1; i >= 0; --i) 
	{
		printf("%d", a[i]);
		if (i != 0) 
		{
			printf(" ");
		}
		else 
		{
			printf("\n");
		}
	}

	return 0;
}


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

int f(int n) {
	int ret = 0;
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			if (i * i == n) ret++;
			else ret += 2;
		}
	}
	return ret;
}

int main() {
	int n;
	cin >> n;
	ll ans = 0;
	for (int i = 1; i < n; i++) {
		ans += f(i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main() {
    ll n;
    cin >> n;
    string str;
    cin >> str;
    vector<ll> modsPlus(200001, 1);
    vector<ll> modsMinus(200001, 1);
    ll sumPlus = 0;
    ll sumMinus = 0;
    ll bitNum = 0;
    rep(i, n){
        if(str[i] == '1') bitNum++;
    }
    for(int i=1; i<=200000; i++){
        modsPlus[i] = modsPlus[i-1]*2;
        modsPlus[i] %= (bitNum+1);
        modsMinus[i] = modsMinus[i-1]*2;
        if(bitNum != 1) modsMinus[i] %= (bitNum-1);
    }
    for(int i=n-1; i>=0; i--){
        if(str[i]=='1'){
            sumPlus += modsPlus[n-1-i];
            sumPlus %= (bitNum+1);
            sumMinus += modsMinus[n-1-i];
            if(bitNum != 1) sumMinus %= (bitNum-1);
        }
    }
  
    for(int i=0; i<n; i++){
        if(str[i] == '1'){
            if(bitNum == 1){
              cout << 0 << endl;
            }else{
                ll tmp = sumMinus+(bitNum-1)-modsMinus[n-1-i];
                tmp %= (bitNum-1);
                ll cnt = 1;
                int one = 0;
                ll copy = tmp;
                while(copy > 0){
                    if(copy%2==1) one++;
                    copy /= 2;
                }
                while(tmp != 0){
                    tmp %= one;
                    one = 0;
                    ll copy = tmp;
                    while(copy > 0){
                        if(copy%2==1) one++;
                        copy /= 2;
                    }
                    cnt++;
                }
                cout << cnt << endl;
            }
        }else{
            ll tmp = sumPlus+modsPlus[n-1-i];
            tmp %= (bitNum+1);
            ll cnt = 1;
            int one = 0;
            ll copy = tmp;
            while(copy > 0){
                if(copy%2==1) one++;
                copy /= 2;
            }
            while(tmp != 0){
                tmp %= one;
                one = 0;
                ll copy = tmp;
                while(copy > 0){
                    if(copy%2==1) one++;
                    copy /= 2;
                }
                cnt++;
            }
            cout << cnt << endl;
        }
    }
    return 0;
}

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

int main(){
    
    int n,m;
    cin >> n >> m;

    int data[n][m];
    int data2[m];
    int sum;
    //data2[m];

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> data[i][j];
        }
        
    }
    for (int i = 0; i < m; i++)
    {
        int tmp;
        cin >> data2[i];
    }
    for (int i = 0; i < n; i++)
    {
        sum = 0;
        for (int j = 0; j < m; j++)
        {
            sum += data[i][j]*data2[j];
        }
        
        cout << sum << endl;
    }
    
        
    

    return(0);
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;


int main(){
	int n,m;cin>>n>>m;
	map<int,int>mp;
	int cnt=0;
	int penalty=0;
	rep(i,m){
		int p;string s;cin>>p>>s;
		if(s=="AC"){
			if(mp[p]!=-1){
				penalty+=mp[p];
				cnt++;
				mp[p]=-1;
			}
		}
		else{
			if(mp[p]!=-1){
				mp[p]++;
			}
		}
	}
	cout<<cnt<<' '<<penalty<<endl;
}

Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
#include<set>
using namespace std;

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

int main()
{
    int m; cin >> m;
    while(m--)
    {
        string s, s1, s2, con;
        cin >> s;
        set<string> sum;
        int l = s.size();
        for(int i = 1; i < l;i++)
        {
            s1 = s.substr(0, i);
            s2 = s.substr(i, l - i);
            
            con = s1 + s2; sum.insert(con);
            con = s2 + s1; sum.insert(con);
            
            reverse(all(s1)); 
            con = s1 + s2; sum.insert(con);
            con = s2 + s1; sum.insert(con);
            
            reverse(all(s1)); reverse(all(s2));
            con = s1 + s2; sum.insert(con);
            con = s2 + s1; sum.insert(con);
            reverse(all(s1));
            con = s1 + s2; sum.insert(con);
            con = s2 + s1; sum.insert(con);
        }
        cout << sum.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 1296
#include "bits/stdc++.h"
using namespace std;

int main(){

	string S;
	int N,K;

	cin >> N;
	cin >> S;
	cin >> K;
	char moji = S[K-1];
	for (int i = 0 ; i < N ; i++){
		
		if (S[i]!=moji){
			S[i]='*';
		}
	}

	cout << S <<endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	while(n=in()){
		vector<pint> vp(n);
		int i;
		int f,s1,s2;
		int d;
		int score;
		for(i=0;i<n;i++){
			f=1;
			d=0;
			score=0;
			cin>>vp[i].second;
			while(f<10){
				cin>>s1;
				if(d==3){
					score+=s1*3;
				}else if(d==0){
					score+=s1;
				}else{
					score+=s1*2;
				}
				d/=2;
				if(s1==10){
					d|=2;
				}else{
					cin>>s2;
					if(d==0){
						score+=s2;
					}else{
						score+=s2*2;
					}
					d=0;
					if(s1+s2==10)d=1;
				}
				f++;
			}
			cin>>s1;
			if(d==3){
				score+=s1*3;
			}else if(d==0){
				score+=s1;
			}else{
				score+=s1*2;
			}
			d/=2;
			cin>>s2;
			if(d==0){
				score+=s2;
			}else{
				score+=s2*2;
			}
			if(s1+s2>=10){
				score+=in();
			}
			vp[i].first=score;
		}
		while(!vp.empty()){
			int r=0;
			for(i=1;i<vp.size();i++){
				if(vp[r].first<vp[i].first||vp[r].first==vp[i].first&&vp[r].second>vp[i].second)
					r=i;
			}
			cout<<vp[r].second<<" "<<vp[r].first<<endl;
			vp[r]=vp[vp.size()-1];
			vp.pop_back();
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,k;
  cin>>n>>k;
  vector<bitset<5000>> fwd(1);
  vector<bitset<5000>> bwd(1);
  fwd.front().set(0);
  bwd.front().set(0);
  vecint a(n);
  for(auto&& e:a)cin>>e;
  REP(i,n) {
    auto nxt = fwd.back() | (fwd.back() << min(a[i], k));
    fwd.push_back(nxt);
  }
  REP(ri,n) {
    int i = n-ri-1;
    auto nxt = bwd.back() | (bwd.back() << min(a[i], k));
    bwd.push_back(nxt);
  }
  reverse(ALL(bwd));
  int cnt = 0;
  REP(i,n) {
    vecint psum(k+1);
    REP(j,k) {
      psum[j+1] = psum[j] + fwd[i][j];
    }
    bool need = false;
    REP(j,k) {
      if (bwd[i+1][j] && psum[k-j] - psum[max(0, k-j-a[i])] > 0) need = true;
    }
    if (!need) ++cnt;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 14124
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define N 300005
#define vi vector<int>
#define all(v) v.begin(),v.end()

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   int a[n];
   for(int i=0;i<n;i++)
    cin>>a[i];
   sort(a,a+n);
   cout<<a[n/2]-a[n/2 -1]<<endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

long double a, b;
main(){
    scanf("%Lf%Lf", &a, &b);
    printf("%.Lf\n", floorl(a*b));
    return 0;
}

Measured memory_bytes: 1756
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1000000007;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecb vector<bool>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, size_t second_itr) {
	std::string tmp;
	for (size_t i = first_itr; i < second_itr + 1; i++) {
		tmp.push_back(str.at(i));
	}
	return tmp;
}


int main() {
	int n; cin >> n;
	if (n < 1000) {
		cout << "ABC" << endl;
	}
	else {
		cout << "ABD" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;           
typedef pair<int,int> P;

int main(){
	int n,a=0,b=0,i,j,ans=0,t=0;
	priority_queue<P,vector<P>,greater<P>> q;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a>>b;
		q.push(P(b,a));
	}
	for(i=0;i<n;i++){
		P a=q.top();
		t+=a.second;
		if(t>a.first)ans=1;
		q.pop();
	}
	if(ans==0){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
}

Measured memory_bytes: 2420
#include<iostream>

#define lli long long int

lli N,C;
lli imos[30][101010];

using namespace std;

#define REP(i,n) for(lli i=0;i<n;i++)

int main(){

	cin>>N>>C;
	REP(i,N){
		lli a,b,c;
		cin>>a>>b>>c;
		a--;
		c--;
		imos[c][a]++;
		imos[c][b]--;
	}

	REP(c,C)for(lli i=1;i<101010;i++){
		imos[c][i]+=imos[c][i-1];
	}
	REP(c,C)for(lli i=0;i<101010;i++){
		if(imos[c][i])imos[c][i]=1;
	}

	lli ans = 0;
	REP(i,101010){
		lli cnt=0;
		REP(c,C)cnt+=imos[c][i];
		ans=max(ans,cnt);
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 23936
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
	char name[100];
	int t;
}P;

P Q[LEN];
int head , tail , n;

void enqueue(P x){
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

P dequeue() {
	P x = Q[head];
	head = (head+1) % LEN;
	return x;
}

int min(int a, int b){ return a < b ? a : b;}

int main(void)
{
	int elaps = 0, c;
	int i , q;
	P u;
	scanf("%d %d", &n, &q);
	for( i = 1; i <= n; i++)
	{
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].t);
	}
	head = 1;
	tail = n + 1;
	while(head != tail){
		u = dequeue();
		c = min(q,u.t);
		u.t -= c;
		elaps += c;
		if(u.t > 0)enqueue(u);
		else{
			printf("%s %d\n",u.name,elaps);
		}
	}
	return 0;
}


Measured memory_bytes: 11884
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

vector<vector<int>> grid_bfs(const vector<string> &S, int sh, int sw) {
    const int delta_h[4] = {0, 1, 0, -1}, delta_w[4] = {1, 0, -1, 0};
    const char wall = '#'; // change yourself
    int H = S.size(), W = S.at(0).size();
    vector<vector<int>> dist(H, vector<int>(W, -1)); dist[sh][sw] = 0;
    vector<vector<bool>> seen(H, vector<bool>(W, false));
    queue<pair<int, int>> que; que.emplace(sh, sw);
    while (!que.empty()) {
        int h, w; tie(h, w) = que.front(); que.pop();
        if (seen[h][w]) { continue; }
        int d = dist[h][w] + 1; seen[h][w] = true;
        for (int i = 0; i < 4; i++) {
            int nh = h + delta_h[i], nw = w + delta_w[i];
            if (nh < 0 || H <= nh || nw < 0 || W <= nw) continue;
            if (S[nh][nw] == wall || seen[nh][nw]) continue;
            dist[nh][nw] = d; que.emplace(nh, nw);
        }
    }
    return dist;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; i++) cin >> S[i];
    
    auto longest_path = [=] (vector<vector<int>> G) {
        int longest = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (G[i][j] > longest) longest = G[i][j];
            }
        }
        return longest;
    };
    
    int ans = 0;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) {
        if (S[i][j] == '#') continue;
        int res = longest_path(grid_bfs(S, i, j));
        chmax(ans, res);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
double res=0;

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		double x;
		cin>>x>>s;
		if(s=="JPY") res+=x;
		else res+=x*380000;
	}
	cout<<syosu(9)<<res<<endl;
}

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

typedef long long int lli;

const lli maxn = 305;

lli A[maxn][maxn];

int main(void)
{
	lli n, res = 0;
	scanf("%lld", &n);
	for(lli i = 0;i < n;i++)
	{
		for(lli j = 0;j < n;j++) scanf("%lld", &A[i][j]);
	}

	for(lli i = 0;i < n;i++)
	{
		for(lli j = i+1;j < n;j++)
		{
			bool cando = 1;
			for(lli k = 0;k < n;k++)
			{
				if(k == i || k == j) continue;
				if(A[i][j] > A[i][k]+A[k][j])
				{
					printf("-1\n");
					exit(0);
				}
				if(A[i][j] == A[i][k]+A[k][j]) cando = 0;
			}
			res += lli(cando)*A[i][j];
		}
	}
	printf("%lld\n", res);
}

Measured memory_bytes: 896
use std::io::*;
use std::str::FromStr;

fn main() {
    let mut s: Vec<char> = read::<String>().chars().collect();
    let mut k: usize = read();
    let mut pos = 0;
    while k > 0 {
        if pos == s.len() - 1 {
            k %= 26;
            let po = ((s[pos] as u8) + (k as u8) - ('a' as u8)) % 26;
            s[pos] = (('a' as u8) + po) as char;
            break;
        } else if s[pos] == 'a' {
            pos += 1;
            continue;
        } else {
            let a = (('z' as u8) - (s[pos] as u8) + 1) as usize;
            if k >= a {
                k -= a;
                s[pos] = 'a';
            } else {
                pos += 1;
            }
        }
    }
    for i in &s {
        print!("{}", *i);
    }
    println!();
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 4352
#include "iostream"
using namespace std;

int main(){
    //a,b.c作成
    char a[5-1],b[5-1],c[5-1];
    scanf("%s\n%s\n%s",a,b,c);
    //012で出力.
    printf("%c%c%c\n",a[0-0],b[1-0],c[2-0]);
    //a,b,cの出力が終わったのであとはreturnをする.
    return 0;
}


Measured memory_bytes: 256
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) ((int)(x).size())
#define MEMSET(c, v) memset((c), v, sizeof(c))

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

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1e9;
// const ll INF = 1e15;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


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


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

  int A, B, C, D;
  cin >> A >> B >> C >> D;

  cout << max(0, min(B, D) - max(A, C)) << endl;
  return 0;
}

Measured memory_bytes: 256
N, D = map(int, input().split())
day = 0
day10 = 0
ans =0
for j in range(4, N+1):
    for i in range(22, D+1):
        day = i % 10
        day10 = i//10
        if day >= 2 and day10 >=2:
          if j == day * day10:
              ans += 1

print(ans)

Measured memory_bytes: 3060
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

n, x0 = list(map(int, input().split()))
x = list(map(int, input().split()))

xx0 = [abs(xi-x0) for xi in x ]

y = xx0[0]
for yi in xx0:
    y = gcd(y, yi)
    
print(y)

Measured memory_bytes: 14252
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please



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


	string S, T;
	cin >> S >> T;

	int N = S.size();

	int kotae = 0;
	rep(i, N) if (S[i] != T[i]) kotae++;

	co(kotae);


	Would you please return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s,t;
  cin >> s >> t;
  
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  
  reverse(t.begin(), t.end());
  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int Stop[100];
int Si=0;

int pop(){
  return Stop[--Si];
}

void push(int x){
  Stop[Si++]=x;
}

int main()
{
  char S[5],top,s;
  int a,b,i,Slen;
  
  while((scanf("%s",S))!=EOF){
    if('0'<=S[0] && S[0]<='9') push(atoi(S));
    else{
      a=pop();
      b=pop();
      if(S[0]=='+') push(b+a);
      else if(S[0]=='-') push(b-a);
      else if(S[0]=='*') push(b*a);
    }
  }
  printf("%d\n",pop());
  
  return 0;
}

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

using namespace std;

#define LL           long long
#define ULL          long long unsigned
#define LD           long double
#define ff              first
#define ss              second
#define FOR(i,n)     for(int i=0;i<n;i++)
#define FLR(i,n)     for(LL i=0;i<n;i++)
#define RFOR(i,n)    for(int i=n-1;i>=0;i--)
#define RFLR(i,n)    for(LL i=n-1;i>=0;i--)
#define rep(i,a,b)   for(int i=a;i<=b;i++)
#define repl(i,a,b)  for(LL i=a;i<=b;i++)
#define fast         ios_base::sync_with_stdio(0);cin.tie(0);
#define all(a)       a.begin(),a.end()
#define ABS(x)       ((x)<0?-(x):(x))
#define NL           "\n"
#define pb           push_back
#define mk              make_pair
#define pi           acos(-1.0)
#define prec(n)      fixed << setprecision(n)
#define sq(a)          (a)*(a)
#define asi          cout<<"check"<<" ";
#define all_set(arr,val) memset(arr,val,sizeof(arr))

int main()
{
    fast;
    int i,j,k,n,kount1=0,kount2=0,kount3=0,kount4=0,ans;
    string s;
    cin>>s;
    n=s.size();
    FOR(i,n){
        if(i%2==0){
            if(s[i]=='0')kount1++;
            else kount3++;
        }
        else{
            if(s[i]=='0')kount2++;
            else kount4++;
        }
    }
    ans=min(kount3+kount2,kount1+kount4);
    cout<<ans;


}


Measured memory_bytes: 3760
import qualified Data.Sequence as S
import Data.Bool
 
main = do
  getLine
  as <- S.fromList . map read . words <$> getLine
  let o = S.length $ S.filter odd as
  let f = S.length $ S.filter (\x -> x `mod` 4 == 0) as
  let t = bool 0 1 $ length as > o + f
  putStr . bool "No" "Yes" $ f + 2 > o + t

Measured memory_bytes: 59772
#include <algorithm>
#include <cstdio>

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

using namespace std;

const int INF=1<<29;

int main(){
	int n,m,a[1000],b[1000],c[1000];
	scanf("%d%d",&n,&m);
	rep(i,m) scanf("%d%d%d",&a[i],&b[i],&c[i]), a[i]--, b[i]--;

	int d[100][100];
	rep(u,n) rep(v,n) d[u][v]=d[v][u]=(u==v?0:INF);
	rep(i,m) d[a[i]][b[i]]=d[b[i]][a[i]]=c[i];

	rep(k,n) rep(i,n) rep(j,n) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);

	int ans=0;
	rep(i,m) if(c[i]>d[a[i]][b[i]]) ans++;
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 256
A=[list(map(int,input().split())) for i in range(3)]
AB=[[0 for i in range(3)] for j in range(3)]
N=int(input())
for i in range(N):
    x=int(input())
    for j in range(3):
        for k in range(3):
            if A[j][k]==x:
                AB[j][k]=1
c=1
for i in range(3):
    if AB[i][0]*AB[i][1]*AB[i][2]==1:
        c=0
        break
    if AB[0][i]*AB[1][i]*AB[2][i]==1:
        c=0
        break
    if AB[0][0]*AB[1][1]*AB[2][2]==1:
        c=0
        break
    if AB[0][2]*AB[1][1]*AB[2][0]==1:
        c=0
        break
        

if c==1:
    print("No")
else:
  	print("Yes")

Measured memory_bytes: 38384
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    d1 = defaultdict(int)
    d2 = defaultdict(int)

    for i, a in enumerate(A):
        d1[a + i] += 1
        d2[i - a] += 1

    ans = 0
    for val in d1:
        ans += d1[val] * d2[val]
    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 163784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

string s;
int dp[2][11];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> s, s != "0") {
    fill_n((int*)dp, 2 * 11, 0);
    int sz = s.size(), ans = 0;
    for (int i = 0; i < sz; i++) {
      for (int j = 0; j < 11; j++) {
        if (dp[0][j] == 0) continue;
        dp[1][(j * 10 + (s[i] - '0')) % 11] += dp[0][j];
      }
      if (s[i] != '0') dp[1][s[i] - '0']++;
      ans += dp[1][0];
      swap(dp[0], dp[1]);
      fill_n((int*)dp[1], 11, 0);
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3288
//#pragma GCC optimize(3)
#pragma comment(linker,"/stack:16777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	if(n==m)puts("Yes");
	else puts("No");
	return 0;
}

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

#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}

int main(void){
    int n;
    cin>>n;
    vector<int> l(n);
    rep(i,0,n){
        cin>>l[i];
    }
    sort(l.begin(),l.end());
    ll ans=0;
    rep(a,0,n){
        rep(b,a+1,n){
            int k=lower_bound(l.begin(),l.end(),l[a]+l[b])-l.begin();

            ans+=max(k-(b+1),0);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256