akhauriyash/Code-Regression huggingface dataset:
def convolve(a, b):
    def fft(f):
        d = n // 2
        v = w
        while d >= 1:
            u = 1
            for i in range(d):
                for j in range(i, n, 2*d):
                    f[j], f[j+d] = (f[j] + f[j+d]) % p, u * (f[j] - f[j+d]) % p
                u = u * v % p
            v = v * v % p
            d //= 2
 
    def ifft(f):
        d = 1
        while d < n:
            v = pow(invw, n // (2 * d), p)
            u = 1
            for i in range(d):
                for j in range(i, n, 2*d):
                    f[j+d] *= u
                    f[j], f[j+d] = (f[j] + f[j+d]) % p, (f[j] - f[j+d]) % p
                u = u * v % p
            d *= 2
 
    p, g = (33 << 66) + 1, 5
    n0, n1 = len(a), len(b)
    n = 1 << (max(n0, n1) - 1).bit_length() + 1
    a = a + [0] * (n-n0)
    b = b + [0] * (n-n1)
    w = pow(g, (p - 1) // n, p)
    invw = pow(w, p-2, p)
    fft(a), fft(b)
    for i in range(n):
        a[i] = a[i] * b[i] % p
    ifft(a)
    invn = pow(n, p - 2, p)
    return [a[i] * invn % p % P for i in range(n0 + n1 - 1)]

def grow(d, v, h):
    h += [0] * d
    f = [(-1 if (i+d) % 2 else 1) * fainv[i] * fainv[d-i] % P * h[i] % P for i in range(d+1)]
    
    for idx, a in enumerate([d+1, d * fa[v-1] * fainv[v] % P, (d * fa[v-1] * fainv[v] + d + 1) % P]):
        g = [pow(a - d + i - 1, P-2, P) if i else 0 for i in range(2*d+2)]
        fg = convolve(f, g)
        p = 1
        for i in range(d+1):
            p = p * (a-i) % P
        for i in range(d+1):
            fg[d+i+1] = fg[d+i+1] * p % P
            p = p * (a+i+1) % P * pow(a-d+i, P-2, P) % P
        if idx == 1:
            for i in range(d+1):
                h[i] = h[i] * fg[d+i+1] % P
        elif idx == 0:
            for i in range(d):
                h[i+d+1] = fg[d+i+1]
        elif idx == 2:
            for i in range(d):
                h[i+d+1] = h[i+d+1] * fg[d+i+1] % P
    return h

# Create a table of the factorial of the first v+2 multiples of v, i.e., [0!, v!, 2v!, ..., (v(v+1))!]
def create_table(v):
    s = 1
    X = [1, v+1]
    while s < v:
        X = grow(s, v, X)
        s *= 2
    table = [1]
    for x in X:
        table.append(table[-1] * x % P)
    return table

def fact(i, table):
    a = table[i//v]
    for j in range(i//v*v+1, i+1):
        a = a * j % P
    return a

P = 10**9+7
v = 1 << 11
fa = [1] * (2*v+2)
fainv = [1] * (2*v+2)
for i in range(2*v+1):
    fa[i+1] = fa[i] * (i+1) % P
fainv[-1] = pow(fa[-1], P-2, P)
for i in range(2*v+1)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % P

T = create_table(v)

f = lambda a, b: fact(a+b+2, T) * pow(fact(a+1, T) * fact(b+1, T), P-2, P) % P
r1, c1, r2, c2 = map(int, input().split())
print((f(r2, c2) - f(r2, c1-1) - f(r1-1, c2) + f(r1-1, c1-1)) % P)

Measured memory_bytes: 81372
#include<stdio.h>

int main(void){
    int N=0,K=0;
    char S[51];
    scanf("%d %d",&N,&K);
    K-=1;
    scanf("%s",S);
    if(S[K]=='A'){
        S[K]='a';
    }
    if(S[K]=='B'){
        S[K]='b';
    }
    if(S[K]=='C'){
        S[K]='c';
    }
    printf("%s\n",S);

    return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
int32_t main(){
    
    int n;
    cin >> n;
    for(int i=1;i <= 9;i++){
        if(n%i == 0 && n/i >= 1 && n/i <= 9){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No\n";
}



Measured memory_bytes: 3604
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	r := nextInt()
	fmt.Printf("%d", r * r)
}


Measured memory_bytes: 640
const main = input => {
  const [A, B, C, K] = input.flat().map(Number)

  if (K <= A) return [[K]]

  if (K <= A + B) return [[A]]

  return [[A - (K - (A + B))]]
}

const wrapper = data => {
  const input = data.split('\n').map(line => line.split(' '))
  const output = main(input)
  console.log(output.map(line => line.join(' ')).join('\n'))
}

wrapper(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 29892
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int main(){
    int n,p,a;
    cin>>n>>p;
    for(int i=0;i<n;i++){
      cin>>a;
      if(a%2){cout<<(long)powl(2,n-1)<<endl;return 0;}
    }
    cout<<(p?0:(long)powl(2,n))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
int dp[100005][2];
int main(){
    ios::sync_with_stdio(false);
    cin>>s;
    memset(dp,0x3f, sizeof(dp));
    dp[0][0]=0;dp[0][1]=1;
    for(int i=1;i<s.length();i++){
        if(s[i]==s[i-1])dp[i][1]=min(dp[i][1],dp[i-1][0]+1),dp[i][0]=min(dp[i][0],dp[i-1][1]);
        else dp[i][0]=min(dp[i-1][0],dp[i][0]),dp[i][1]=min(dp[i-1][1]+1,dp[i][1]);
    }
    int n = s.length()-1;
    cout<<min(dp[n][0],dp[n][1]);
}



Measured memory_bytes: 1232
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

int main(void) {
	// in
	int h, w;
	std::cin >> h >> w;
	std::vector<std::string> s(h);
	for(int i = 0; i < h; ++i) std::cin >> s[i];

	// decode into 2d vector
	std::vector<std::vector<int>> n_h(h);
	std::vector<std::vector<int>> n_w(w);
	std::vector<std::vector<bool>> is_wall(h);
	for(int i_h = 0; i_h < h; ++i_h) {
		is_wall[i_h].resize(w);
		n_h[i_h].resize(w);
		for(int i_w = 0; i_w < w; ++i_w) {
			is_wall[i_h][i_w] = (s[i_h][i_w] == '#' ? true : false);
		}
	}
	for(int i_w = 0; i_w < w; ++i_w) {
		n_w[i_w].resize(h);
	}
	
	// h
	for(int i_h = 0; i_h < h; ++i_h) {
		int i_l = 0;
		while(i_l < w) {
			int i_r = i_l;
			while(i_r < w && is_wall[i_h][i_r] == false) ++i_r;
			for(int i_w = i_l; i_w < i_r; ++i_w) n_h[i_h][i_w] = i_r - i_l;
			i_l = i_r + 1;
		}
	}
	// w
	for(int i_w = 0; i_w < w; ++i_w) {
		int i_l = 0;
		while(i_l < h) {
			int i_r = i_l;
			while(i_r < h && is_wall[i_r][i_w] == false) ++i_r;
			for(int i_h = i_l; i_h < i_r; ++i_h) n_w[i_w][i_h] = i_r - i_l;
			i_l = i_r + 1;
		}
	}

	// sum
	int n_hw_max = 0;
	for(int i_h = 0; i_h < h; ++i_h) {
		for(int i_w = 0; i_w < w; ++i_w) {
			int n_hw = n_h[i_h][i_w] + n_w[i_w][i_h] - 1;
			n_hw_max = std::max(n_hw, n_hw_max);
		}
	}

	std::cout << n_hw_max << std::endl;

	return 0;
}


Measured memory_bytes: 36352
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,cnt=0,len=0;
int head[200005],a[200005],dp[200005],lis[200005];

struct edge
{
	int next;
	int to;
}e[500005];

inline void add_edge(int u,int v)
{
	cnt++;
	e[cnt].to=v;
	e[cnt].next=head[u];
	head[u]=cnt;
}

inline void dfs(int now,int fath)
{
	int last=0,pos=0,flag=0;
	if (a[now]>lis[len])
	{
		last=0,pos=len+1,flag=1;
		len++;
		lis[len]=a[now];
		dp[now]=len;
	}
	else
	{
		int p=lower_bound(lis+1,lis+len+1,a[now])-lis;
		last=lis[p];
		pos=p; 
		lis[p]=a[now];
		dp[now]=max(dp[fath],p);
	}
	for (int i=head[now];i;i=e[i].next)
	{
		if (e[i].to!=fath)  dfs(e[i].to,now);
	}
	lis[pos]=last;
	if (flag==1)  len--;
}

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++)  cin>>a[i];
	for (int i=1;i<n;i++)
	{
		int u,v;
		cin>>u>>v;
		add_edge(u,v);
		add_edge(v,u);
	}
	dfs(1,0);
	
	for (int i=1;i<=n;i++)  cout<<dp[i]<<endl;
	cout<<endl;
	
	return 0;
}

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

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

  while (N--) {
    int num_size;
    string num1, num2;
    cin >> num1 >> num2;

    reverse(num1.begin(), num1.end());
    reverse(num2.begin(), num2.end());

    num_size = max(num1.size(), num2.size());
    if (num_size > 80) {
      cout << "overflow" << endl;
      continue;
    }
    if (num1.size() > num2.size()) {
      int diff = num1.size() - num2.size();
      while (diff--) {
        num2 += '0';
      }
    } else {
      int diff = num2.size() - num1.size();
      while (diff--) {
        num1 += '0';
      }
    }

    string sum;
    bool flag = false;
    for (int i = 0; i < num_size; i++) {
      int n1 = num1[i] - '0';
      int n2 = num2[i] - '0';
      int tmp = n1 + n2;
      if (flag) {
        tmp++;
        flag = false;
      }
      if (tmp >= 10) {
        tmp %= 10;
        flag = true;
      }
      sum += tmp + '0';
    }
    if (flag) {
      sum += '1';
    }

    if (sum.size() > 80) {
      cout << "overflow" << endl;
      continue;
    }
    
    reverse(sum.begin(), sum.end());
    cout << sum << endl;

  }

  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) (1e9 + 7);
//const ll MOD = 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);
    ll a, b;
    while (cin >> a >> b) {
        ll g = __gcd(a, b);
        cout << g << " " << a / g * b << endl;
    }
    return 0;
}




Measured memory_bytes: 3176
module Main where--

valid i j k x = 500 * i + 100 * j + 50 * k == x

main :: IO ()
main = do
        a <- readLn
        b <- readLn
        c <- readLn
        x <- readLn
        putStrLn $ show $ length [(i, j, k) | i <- [0 .. a],
                           j <- [0 .. b],
                           k <- [0 .. c],
                           valid i j k x]


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

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

ll mod = 1000000007;

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

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

  int n;
  cin >> n;
  vll a(n);
  rep(i,n)cin >> a[i];

  bool zero = false;
  rep(i,n){
    if(a[i] == 0)zero = true;
  }
  if(zero)cout << 0 << endl;
  else{
    ll ret = 1;
    rep(i,n){
      ll mx = 1000000000000000000 / ret;
      if(mx < a[i]){
        ret = -1;break;
      }
      ret *= a[i];
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 3996
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main()
{
    int N; cin >> N;
    string S; cin >> S;
    long long ans = 0;
    vector< vector<int> > cnt(N, vector<int>(3, 0));
    for (int i = 0; i < N-1; i++) {
        if (S[i] == 'R') {
            cnt[i][0] += 1;
        } else if (S[i] == 'G') {
            cnt[i][1] += 1;
        } else {
            cnt[i][2] += 1;
        }
        for (int j = 0; j < 3; j++) {
            cnt[i+1][j] += cnt[i][j];
        }
    }
    int flg;
    for (int i = 2; i < N; i++) {
        for (int j = 1; j < i; j++) {
            if (S[i] == 'R' && S[j] == 'G') {
                // if (2*j-i >= 0 && S[2*j-i] == 'B') {
                //     flg = 1;

                // else 
                ans += cnt[j-1][2]-(2*j-i >= 0 && S[2*j-i] == 'B');
            } 
            else if (S[i] == 'R' && S[j] == 'B') {
                ans += cnt[j-1][1]-(2*j-i >= 0 && S[2*j-i] == 'G');
            }
            else if (S[i] == 'G' && S[j] == 'R') {
                ans += cnt[j-1][2]-(2*j-i >= 0 && S[2*j-i] == 'B');
            }
            else if (S[i] == 'G' && S[j] == 'B') {
                ans += cnt[j-1][0]-(2*j-i >= 0 && S[2*j-i] == 'R');
            }
            else if (S[i] == 'B' && S[j] == 'R') {
                ans += cnt[j-1][1]-(2*j-i >= 0 && S[2*j-i] == 'G');
            }
            else if (S[i] == 'B' && S[j] == 'G') {
                ans += cnt[j-1][0]-(2*j-i >= 0 && S[2*j-i] == 'R');
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long LL;
int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
const int N = 200001;
int read() {
	int s = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * f;
}
void put(int x) {
	if(x < 0) x = -x, putchar('-');
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

int A[N], B[N];

int main() {
	int n = read();
	LL ans = 0, zz = 1e9 + 1;
	int cc = 0;
	for(int i = 1; i <= n; i++) {
		A[i] = read(), B[i] = read();
		if(A[i] == B[i]) cc++;
		ans += B[i];
		if(A[i] > B[i]) zz = _min(zz, B[i]);
	} if(zz == 1e9 + 1 || ans == 0) ans = 0;
	else ans = ans - zz;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,ans=1<<28,a1,b1;
int main(){
	cin>>a>>b;
	a1=a%2019;
	b1=b%2019;
	if(a!=b&&a1>=b1) b1+=2019; 
	if(a/673<b/673&&a/3<b/3) {
		puts("0");
		return 0;
	}
	for(ll i=a1;i<=b1;i++)
		for(ll j=i+1;j<=b1;j++){
			ans=min(ans,i*j%2019);
		}
	printf("%lld",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	sort(a.begin(),a.end());
	if(a.at(n-1)-a.at(0)>1) cout << "No" << endl;
	else{
		if(a.at(n-1)-a.at(0)==0){
			if(a.at(0)*2<=n || a.at(0)==n-1) cout << "Yes" << endl;
			else cout << "No" << endl;
		}
		else{
			int cnt=0;
			rep(i,n) if(a.at(i)==a.at(0)) cnt++;
			if(cnt<a.at(n-1) && 2*(a.at(n-1)-cnt)<=n-cnt) cout << "Yes" << endl;
			else cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 640
n, k = map(int, input().split())

to = [0]
to += list(map(int, input().split()))

passed = [0] * (n + 1)

circle = [1]
st = -1
while True:
  nx = to[circle[-1]]
  if passed[nx] == 1:
    st = nx
    break
  circle.append(nx)
  passed[nx] = 1
  

l1 = circle.index(st)
l2 = len(circle) - l1

if k < l1:
  print(circle[k])
elif k < l1 + l2:
  print(circle[k])
else:
  div = (k - l1) % l2
  print(circle[l1+div])

Measured memory_bytes: 32376
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)
using namespace std;
using ll = long long;
using ii = pair<int,int>;

constexpr int MAXN = 55;

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  string s; cin >> s;
  cout << s[0] << s[1] << s[2] << '\n';
  return 0;
}


Measured memory_bytes: 3648
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;

#define MAX_N 100000000
#define INF 1000000000000

int main(){
  string s;
  cin >> s;
  int n;
  n = s.length();
  int d[n+1];
  for(int i=0;i<n+1;i++) d[i] = 0;
  d[0] = 0;
  d[1] = 1;
  if(s[0] == s[1]) d[2] = 1;
  else d[2] = 2;

  for(int i=3;i<n+1;i++){
    if(s[i-2] != s[i-1]){
      d[i] = d[i-1] + 1;
    }
    else{
      d[i] = d[i-3] + 2;
    }
  }
  cout << d[n] << endl;

  return 0;
}


Measured memory_bytes: 1412
#include<iostream>
using namespace std;
int n,o,a,b,c,p;
string s;
main()
{
    cin>>n;
    while(cin>>s)
    {
        o=p=a=b=c=0;
        do{
            if(s=="OUT")o++;
            else if(s=="HIT")
            {
                if(c)p++,c=0;
                if(b)b=0,c=1;
                if(a)a=0,b=1;
                a=1;
            }
            else
            {
                p+=a+b+c+1;a=b=c=0;
            }
        }while(o<3&&cin>>s);
        cout<<p<<endl;
    }
}


Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()
#define MP make_pair
#define F first
#define S second

int main() {
	int n, c[114] = {},b2 = 0,b4 = 0,b14 = 0,b24 = 0,b74 = 0;
	cin >> n;
	FOR(i,2, n + 1) {
		int a = i;
		FOR(j, 2, INF) {
			if (a == 1) break;
			else {
				REP(k, INF) {
					if (a% j == 0) {
						c[j]++;
						a /= j;
					}
					else break;
				}
			}
		}
	}
	REPO(i, 110) {
		if (c[i] >= 74)b74++;
		if (c[i] >= 24)b24++;
		if (c[i] >= 14)b14++;
		if (c[i] >= 4)b4++;
		if (c[i] >= 2)b2++;
	}
	cout << b74 + b24 * (b2 - 1) + b14 * (b4 - 1) + b4 * (b4 - 1) * (b2 - 2) / 2<< endl;
}


Measured memory_bytes: 256
while True:
    try:
        x = list(map(int,input().split()))
    except:
        break
    y = list(map(int,input().split()))
    h, b = 0, 0
    for i in range(4):
        if x[i] == y[i]:
            h += 1
        elif y[i] in x:
            b += 1
    print(h, b)

Measured memory_bytes: 7588
// Problem : A - Sheep and Wolves
// Contest : AtCoder - AtCoder Beginner Contest 164
// URL : https://atcoder.jp/contests/abc164/tasks/abc164_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
/* Author:bhagatsunny96
         JGEC
	   template__
	lets_code_it_ */
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long int 
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define test long long int t; cin>>t; while(t-->0)
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(long long int i=0;i<n;i++)
#define loopr(n) for(long long int i=n-1;i>=0;i--)
#define lrp(a,b) for(long long int i=a;i<=b;i++)
#define lrn(a,b) for(long long int i=b;i>=a;i--)
#define endl '\n'
#define ivec vector<ll>
#define ivecp vector<pair<ll,ll>>
#define imap map<ll,ll>
#define uimap unordered_map<ll,ll>
#define iset set<ll>
#define cvec vector<char>
#define civecp vector<pair<char,ll>>
#define cimap map<char,ll>
#define ucimap unordered_map<char,ll>
#define cset set<char>
using namespace std;
ll gcd(ll a, ll b)
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);
}
ll lcm(ll a, ll b)  
 {  
    return (a*b)/__gcd(a, b);  
 }
 ll power(ll x, unsigned ll y) 
 { 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
 }
 bool isPrime(ll num)
 {
    bool flag=true;
    for(ll i =2;i<=num/2;i++) 
    {
       if(num%i==0) 
       {
          flag=false;
          break;
       }
    }
    return flag;
}
bool isPalin(ll num)
{
    bool flag=false;
    ll digit,rev=0,n=num;
    do
     {
         digit = num % 10;
         rev = (rev * 10) + digit;
         num = num / 10;
     } while (num != 0);
     if(rev==n)
     flag=true;
     return flag;
}
ll sumofdigits(ll n)
{
    ll c=0;
    while(n>0)
    {
        c++;
        n/=10;
    }
    return c;
}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b) 
{ 
    return (a.first > b.first); 
}
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
string sortString(string &str) 
{ 
   sort(str.begin(), str.end()); 
   return str;
} 
void countSort(ll arr[], ll n, ll exp) 
{ 
	ll output[n];
	ll i, count[10] = {0}; 
	for (i = 0; i < n; i++) 
		count[ (arr[i]/exp)%10 ]++; 
	for (i = 1; i < 10; i++) 
		count[i] += count[i - 1]; 
	for (i = n - 1; i >= 0; i--) 
	{ 
		output[count[ (arr[i]/exp)%10 ] - 1] = arr[i]; 
		count[ (arr[i]/exp)%10 ]--; 
	} 
	for (i = 0; i < n; i++) 
		arr[i] = output[i]; 
} 
void radixsort(ll arr[], ll n) 
{
    ll mx = arr[0]; 
	for (ll i = 1; i < n; i++) 
		if (arr[i] > mx) 
			mx = arr[i];
	ll m =mx;
	for (ll exp = 1; m/exp > 0; exp *= 10) 
		countSort(arr, n, exp); 
} 
void print(ll arr[], ll n) 
{ 
    for (ll i = 0; i < n; i++) 
        cout << arr[i] << " "; 
}
int main()
{
	fIO
	ll w,s;
	cin>>s>>w;
	if(w>=s)
	cout<<"unsafe"<<endl;
	else
	cout<<"safe"<<endl;
	return 0;
}


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

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/


  char a;

  cin>>a;

  if(a=='A'){
    cout<<'T'<<endl;
  }else if(a=='T'){
    cout<<'A'<<endl;
  }else if(a=='C'){
    cout<<'G'<<endl;
  }else if(a=='G'){
    cout<<'C'<<endl;
  }
  
  return 0;

}


Measured memory_bytes: 256
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions

import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    s = list(input())
    t = list(input())

    s_ord = [ord(i) for i in s]
    t_ord = [ord(i) for i in t]
    s_ord.sort()
    t_ord.sort(reverse=True)

    for i in range(min(len(s), len(t))):
        if s_ord[i] < t_ord[i]:
            print("Yes")
            exit(0)
        elif s_ord[i] > t_ord[i]:
            print("No")
            exit(0)

    if len(s) >= len(t):
        print("No")
    else:
        print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 5036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

int main(void){
    int n;
    cin >> n;
    int plus=0;
    int minus=0;
    int M=0;
    int Midx, midx;
    int m=0;
    vector<int> a(n);
    rep(i,n){
        int tmp;
        cin >> tmp;
        a[i] = tmp;
        if(tmp > 0){
            plus++;
            if(tmp > M){
                M=tmp;
                Midx=i+1;
            }
        }
        else if(tmp < 0){
            minus++;
            if(tmp < m){
                m=tmp;
                midx=i+1;
            }
        }
    }
    if(plus == 0 && minus == 0){
        cout << 0 << endl;
    }else if(minus == 0){
        cout << n-1 << endl;
        rep(i,n-1){
            cout << i+1 << ' ' << i+2 << endl;
        }
    }else if(plus == 0){
        cout << n-1 << endl;
        rep(i,n-1){
            cout << n-i << ' ' << n-i-1 << endl;
        }
    }else{
        if(M+m >= 0){
            cout << minus + n - 1 << endl;
            rep(i,n){
                if(a[i] < 0){
                    cout << Midx << ' ' << i+1 << endl;
                }
            }
            rep(i,n-1){
                cout << i+1 << ' ' << i+2 << endl;
            }
        }else{
            cout << plus + n -1 << endl;
            rep(i,n){
                if(a[i] > 0){
                    cout << midx << ' ' << i+1 << endl;
                }
            }
            rep(i,n-1){
                cout << n-i << ' ' << n-i-1 << endl;
            }
        }
    }
}


Measured memory_bytes: 256
// #includes {{{
#ifdef MY_DEBUG
#include "header/header.hpp"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

template<class T>
T inf(){
	return numeric_limits<T>::has_infinity?numeric_limits<T>::infinity():(numeric_limits<T>::max()/2);
}

typedef pair<int,int> pii;

#ifdef MY_DEBUG
#include"print.hpp"
#include"debug.hpp"
#endif
// }}}

int main(){
	int N, M;
	cin>>N>>M;
	vector<pii> v;
	int Lmax = -inf<int>(), Rmin = inf<int>();
	REP(i,M){
		int L, R;
		cin>>L>>R;
		L--;
		Lmax = max(Lmax, L);
		Rmin = min(Rmin, R);
	}
	if(Rmin - Lmax >= 0)cout<<Rmin - Lmax<<endl;
	else cout<<0<<endl;
}


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

count = 0


for a in range(0, A+1, 1):
    for b in range(0, B+1, 1):
        for c in range(0, C+1, 1):
            if (a*500+100*b+50*c)==X:
                count = count + 1

print(count)

    


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int num_comp = 0;
const int MAX = 500000;
int L[MAX/2 + 2];
int R[MAX/2 + 2];
const int SENTINEL = 2000000000;


// Merge
void Merge(int A[], int left, int mid, int right)
{
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++)
		L[i] = A[left + i];
	for (int i = 0; i < n2; i++)
		R[i] = A[mid + i];
	L[n1] = SENTINEL;
	R[n2] = SENTINEL;

	int i = 0;
	int j = 0;
	for (int k = left; k < right; k++) {
		num_comp++;
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
		}
		else {
			A[k] = R[j];
			j++;
		}
	}
}

// Merge sort
void Mergesort(int A[], int left, int right)
{
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		Mergesort(A, left, mid);
		Mergesort(A, mid, right);
		Merge(A, left, mid, right);	
	}

}

// MAIN FUNCTION
int main(int argc, char** argv)
{
	// Input
	int A[MAX];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> A[i];

	// Merge sort
	Mergesort(A, 0, n);

	// Print all elements
	for (int i = 0; i < n; i++) {
		if (i)
			cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << num_comp << endl;

	return 0;
}

Measured memory_bytes: 6972
H,W = map(int,input().split())
C = [list(map(int,input().split())) for i in range(10)]
A = [list(map(int,input().split())) for i in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j], C[i][k] + C[k][j])
ans = 0
for row in A:
    for a in row:
        if a < 0: continue
        ans += C[a][1]
print(ans)

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

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

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//library----------------------------------------------

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

const int NMAX = 25;
bool flag;
using Graph = vector<vector<int>>;

int main(){
    CIN(N,M);
    Graph G(N+1);
    rep(i,M){
        int a,b;
        cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    RepS(i,1,N){
        printf("%d\n",G[i].size());
    }
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    S=input()
    s=S[0]
    if(s=='S'):
        print("Cloudy")
    elif(s=='C'):
        print("Rainy")
    else:
        print("Sunny")
resolve()

Measured memory_bytes: 38256
import heapq
n, m = map(int, input().split())
a = list(map(lambda x: -int(x), input().split()))
heapq.heapify(a)
for _ in range(m):
  t = (-heapq.heappop(a)) // 2
  heapq.heappush(a, -t)
print(-sum(a))


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

typedef long long ll;

struct info {
    int y;
    int input;
    int p;
};

bool cmp_input(const info &a, const info &b)
{
    return a.input < b.input;
}
bool cmp_y(const info &a, const info &b)
{
    return a.y < b.y;
}

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> P(M),Y(M);
    vector<info> a(M);
    vector<string> ans;
    for(int i=0; i<M; i++){
        cin >> P[i] >> Y[i];
    }
    
    for(int i=0; i<M; i++){
        a[i].y = Y[i];
        a[i].input = i;
        a[i].p = P[i];
    }
    
    sort(a.begin(),a.end(),cmp_y);
    vector<int> cnt(N+1,1);
    for(int i=0; i<a.size(); i++){
        a[i].y = cnt[a[i].p];
        cnt[a[i].p]++;
    }
    
    sort(a.begin(),a.end(),cmp_input);
    
    for (auto itr : a)
    {
        //cout << itr.input <<" "<< itr.p <<" "<< itr.y << endl;
        string ps,ys;
        ps = to_string(itr.p);
        while(ps.size()<6){
            ps.insert(ps.begin(),'0');
        }
        ys = to_string(itr.y);
        while(ys.size()<6){
            ys.insert(ys.begin(),'0');
        }
        cout << ps+ys << endl;
    }
    
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define maxn 200005
#define MOD 998244353
#define INF 10000000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

void solve(){
    ll n, x, y;
    cin >> n >> x >> y;
    ll dis[n];
    memset(dis, 0, sizeof(dis));

    for(ll i = 2; i <= n; i++){
        for(ll j = 1; j <= i-1; j++){
            ll d = min(i-j, abs(y-i)+1+abs(x-j));
            dis[d]++;
        }
    }
    for(ll i = 1; i <= n-1; i++)
        cout << dis[i] << "\n";

}

int main()
{
    fast();
    int t= 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n; // # of judges; 3 <= n && n <= 100
  int input, input2, score, max_score, min_score;
  int i;

  while (1) {
    scanf("%d", &n);
    if (n == 0) break;

    // scanf the first two value for temporaly max(min) value
    scanf("%d", &input);
    scanf("%d", &input2);
    if (input < input2) {
      min_score = input;
      max_score = input2;
    } else {
      min_score = input2;
      max_score = input;
    }

    score = 0;

    // score = sum - (min + max)
    for (i=0; i<n-2; i++) {
      scanf("%d", &input);
      if (input > max_score) {
        score += max_score;
        max_score = input;
      } else if (input < min_score) {
        score += min_score;
        min_score = input;
      } else {
        score += input;
      }
    }
    
    printf("%d\n", score / (n-2));
  }

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0;i<n;i++){
        cin >> a[i];
    }
    sort(all(a));
    int ans = 0;
    for(int i = 0;i<k;i++){
        ans += a[i];
    }
    cout  << ans << endl;

}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  string s;
  cin >> s;
  string a = "";
  for (auto e : s) {
    if (e != 'x')
      a += e;
  }
  if (!a.size()) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, a.size()/2) {
    if (a[i] != a[a.size()-1-i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = 0, l = 0, r = s.size()-1;
  while (l < r) {
    if (s[l] != s[r]) {
      ans++;
      if (s[l] == 'x')
        l++;
      else
        r--;
    } else {
      l++;
      r--;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		while(sc.hasNextLine()){
			String str=sc.nextLine();

			boolean isFirst=true;
			for(int i=0;i<str.length();i++){
				while(i<str.length() &&
						(' '==str.charAt(i)||'.'==str.charAt(i)||','==str.charAt(i)))i++;
				int s=i;
				while(i<str.length() &&!(' '==str.charAt(i)||'.'==str.charAt(i)||','==str.charAt(i)))i++;
				int e=i;
				if(3<=e-s && e-s<=6){
					pr((isFirst?"":" ")+str.substring(s,e));
					isFirst=false;
				}
			}
			ln();
		}
	}

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

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

class P {
	double x;
	double y;

	P(double _x, double _y) {
		x = _x;
		y = _y;
	}

	public static final P Xunit = new P(1, 0);
	public static final P Yunit = new P(0, 1);

	public static double dot(P a, P b) {
		return a.x * b.x + a.y * b.y;
	}

	public static double cross(P a, P b) {
		return a.x * b.y - a.y * b.x;
	}

	public static boolean isParallel(P a1, P a2, P b1, P b2) {
		return Math.abs(cross(a2.s(a1), b2.s(b1))) < Double.MIN_NORMAL;
	}

	public static boolean isVertical(P a1, P a2, P b1, P b2) {
		return Math.abs(dot(a2.s(a1), b2.s(b1))) < Double.MIN_NORMAL;
	}

	public P a(P a) {
		return new P(x + a.x, y + a.y);
	}

	public P s(P a) {
		return new P(x - a.x, y - a.y);
	}

	public double norm() {
		return Math.sqrt(x * x + y * y);
	}

	public double arg() {
		double s = Math.acos(x / norm());
		return y > 0 ? s : 2 * Math.PI - s;
	}

	public P rotate(double t) {
		return new P(Math.cos(t) * this.x - Math.sin(t) * this.y, Math.sin(t)
				* this.x + Math.cos(t) * this.y);
	}

	public static int ccw(P a, P b, P c) {
		if (P.cross(b.s(a), c.s(a)) > Double.MIN_NORMAL) {
			return 1;
		}
		if (cross(b.s(a), c.s(a)) < -Double.MIN_NORMAL) {
			return -1;
		}
		if (dot(b, c) < -Double.MIN_NORMAL)
			return 2;
		if (b.norm() < c.norm() - Double.MIN_NORMAL)
			return -2;
		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof P) {
			P p = (P) obj;
			return x == p.x && y == p.y;
		}
		return false;
	}

	public String toString() {
		return "(" + x + "," + y + ")";
	}
}

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

ll choose2(ll n) {
  return n*(n-1)/2;
}

int main() {
  int n;
  cin >> n;
  
  vector<int> A(n);
  map<int, int> m;
  rep (i,n) {
    cin >> A.at(i);
    m[A.at(i)] += 1;
  }
  
  ll sum = 0;
  for (auto p : m) {
    auto k = p.first;
    auto v = p.second;
    sum += choose2(v);
  }
  
  rep(i, n) {
    cout << sum - (m.at(A.at(i)) - 1) << endl;
  }
  return 0;
}


Measured memory_bytes: 8320
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n;
	vector<int> ds;

	scanf("%d", &n);
	ds.resize(n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &ds[i]);
	}

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

	int mid = n / 2;

	int a = ds[mid - 1];
	int b = ds[mid];

	printf("%d\n", b - a);

	return 0;
}


Measured memory_bytes: 640
{-# LANGUAGE BangPatterns #-}

import           Control.Monad
import qualified Data.ByteString.Char8 as B
import           Data.Char
import           Data.List
import           Data.Ratio

main :: IO ()
main = do
    n <- readLn
    tas <- replicateM n (map read . words <$> getLine)
    print $ solve tas

readInts :: IO [Int]
readInts = unfoldr (B.readInt . B.dropWhile isSpace) <$> B.getLine

solve :: [[Int]] -> Int
solve = go 0 0

go :: Int -> Int -> [[Int]] -> Int
go !n !m []          = n + m
go !n !m ([t,a]:tas) = go (t * k) (a * k) tas
    where 
        k = ceiling (n % t) `max` ceiling (m % a) `max` 1

Measured memory_bytes: 1532
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


H, W = zz()
board = []
for h in range(H):
    board.append(list(input()))
board = np.array(board)
ans1 = []
for h in range(H):
    if ('#' in board[h]):
        ans1.append(board[h])
ans2 = []
board = np.array(ans1)
for w in range(W):
    if ('#' in board[:, w]):
        ans2.append(board[:, w])
ans2 = np.array(ans2).T

for line in ans2:
    print(*line, sep='')


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

int main()
{
  int N=0,count1=0,count2=0,anser;
  char S[1000002];
  scanf("%s",S);
  
  N=strlen(S);
  
  for(int i=0;i<N;i++){
    
     if((i%2)==0){
       if(S[i]=='1'){
         count1++;
       }
     }else{
       if(S[i]=='0'){
         count1++;
       }
     }
    
    if((i%2)==0){
       if(S[i]=='0'){
         count2++;
       }
     }else{
       if(S[i]=='1'){
         count2++;
       }
     }
    
  }
  
  //printf("%d %d\n",count1,count2);
  
  if(count1>count2){
    anser=count2;
  }else{
    anser=count1;
  }
  
  printf("%d\n",anser);
  
  return 0;
}

Measured memory_bytes: 384
#include <cstdio>

int main(int argc, char const* argv[])
{
	int n;
	scanf("%d", &n);
	int *a = new int[n];
	for(int i = 0; i < n; i++){
			scanf("%d", a+i);
	}
	for(int i = n-1; i > 0; i--){
			printf("%d ", a[i]);
	}
	printf("%d\n", a[0]);
	return 0;
}



Measured memory_bytes: 2740
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define int               long long
#define fr                first
#define sc                second
#define vc                vector
#define endl              '\n'
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define LSB(i)            ((i)&-(i))

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e5 + 5;
int dp[N];
int a[N];
int n;

int dynamic(int pos)
{
    if (pos > n)
        return INT_MAX;
    if (pos == n)
        return 0;
    if (dp[pos] != -1)
        return dp[pos];
    int ans;
    ans = min(dynamic(pos + 1) + abs(a[pos + 1] - a[pos]), dynamic(pos + 2) + abs(a[pos + 2] - a[pos]));
    dp[pos] = ans;
    return ans;
}

void solve()
{
    cin >> n;
    for (int i = 1 ; i <= n; i++)
        cin >> a[i];
    mem1(dp);
    cout << dynamic(1);
}
signed main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin>>t;
    while (t--) solve();
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<queue>
#define N 10
typedef long long ll;
using namespace std;
int a[N][N];
int main()
{
    int x,y;
    cin>>x;
    cin>>y;
    int yu=x%500;
    if (yu>y)
       cout << "No" << endl;
    else
       cout << "Yes" << endl;
    return 0;
}


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

typedef long long ll;

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

    ll sum[n+1];
    sum[0] = 0;

    for(int i = 1; i <= n; i++){
        cin >> sum[i];
        sum[i] += sum[i-1];
    }

    ll ans = LLONG_MAX;
    for(int i = 1; i < n; i++){
        ll a = sum[i] - sum[0];
        ll b = sum[n] - sum[i];
        ans = min(ans, abs(a-b));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string n;
    cin>>n;

        if(n[0]=='7'||n[1]=='7'||n[2]=='7')
        {
            cout<<"Yes"<<endl;
            return 0;
        }

    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ll aaa = 1000000000000000;
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
struct edge { int to; ll cost; };
ll d[2][100000];
vector<edge> G[100000];
int main(){
	int n, m; cin >> n >> m;
	rep(i, m) {
		int u, v; cin >> u >> v; u--; v--;
		ll s; cin >> s;
		G[u].push_back({ v,s });
		G[v].push_back({ u,s });
	}
	rep(i, 2) {
		rep(j, n) {
			d[i][j] = INF;
		}
	}
	d[0][0] = 0;
	queue<P> q;
	q.push({ 0,0 });
	bool f = true;
	while (!q.empty()) {
		P now = q.front(); q.pop();
		int b = now.first; int v = now.second;
		int len = G[v].size();
		rep(i, len) {
			int ne = G[v][i].to;
			ll obj = G[v][i].cost;
			if (d[1-b][ne] == INF) {
				d[1 - b][ne] = obj - d[b][v];
				q.push({ 1 - b,ne });
			}
			else {
				if (d[1 - b][ne] != obj - d[b][v]) {
					f = false; break;
				}
			}
		}
		if (!f)break;
	}
	if (!f)cout << 0 << endl;
	else if (d[1][0] < INF) {
		if (d[1][0] > 0 && d[1][0] % (ll)2 == 0) {
			ll z = d[1][0] / (ll)2;
			ll mi1 = INF;
			rep(i, n) {
				mi1 = min(mi1, d[0][i]);
			}
			ll mi2 = INF;
			rep(i, n) {
				mi2 = min(mi2, d[1][i]);
			}
			mi1 = -mi1 + (ll)1; mi2--;
			if (mi2 >= z && z >= mi1) {
				cout << 1 << endl;
			}
			else {
				cout << 0 << endl;
			}
		}
		else {
			cout << 0 << endl;
		}
	}
	else {
		ll mi1 = INF;
		rep(i,n){
			mi1= min(mi1, d[0][i]);
		}
		ll mi2 = INF;
		rep(i, n) {
			mi2 = min(mi2, d[1][i]);
		}
		mi1 = -mi1 + (ll)1; mi2--;
		if (mi2 - mi1 < 0)cout << 0 << endl;
		else {
			cout << mi2 - mi1 + (ll)1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 9856
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,M; cin>>N>>M;
  vii A(N);
  vi B(N);
  rep(i,0,M){
    int X,Y; cin>>X>>Y;
    A[X-1].pb(Y-1);
    B[Y-1]++;
  }
  stack<int> Q;
  rep(i,0,N){
    if(B[i]==0) Q.push(i);
  }
  vi C;
  while(Q.size()>0){
    int X=Q.top(); Q.pop();
    C.pb(X);
    rep(i,0,A[X].size()){
      int Y=A[X][i];
      B[Y]--;
      if(B[Y]==0) Q.push(Y);
    }
  }
  vi dp(N);
  rep(i,0,N){
    rep(j,0,A[C[i]].size()){
      dp[A[C[i]][j]]=max(dp[A[C[i]][j]],dp[C[i]]+1);
    }
  }
  int ans=0;
  rep(i,0,N) ans=max(ans,dp[i]);
  cout<<ans<<endl;
  }


Measured memory_bytes: 8180
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 100100;

int n, tag[MAXN];

char s[MAXN];

void put() {
	puts("-1");
	exit(0);
}

void ispis() {
	REP(i, n) (tag[i]) ? printf("S") : printf("W");
	puts("");
	exit(0);
}

bool pretp(int x, int y) {
	memset(tag, 0, sizeof tag);

	tag[0] = x;
	tag[1] = y;
	FOR(i, 1, n) {
		if (s[i] == 'o' && tag[i]) tag[i + 1] = tag[i - 1];
		if (s[i] == 'o' && !tag[i]) tag[i + 1] = !tag[i - 1];
		if (s[i] == 'x' && tag[i]) tag[i + 1] = !tag[i - 1];
		if (s[i] == 'x' && !tag[i]) tag[i + 1] = tag[i - 1];
	}

	if (s[n - 1] == 'o' && tag[n - 1] && tag[0] != tag[n - 2]) return 0;
	if (s[n - 1] == 'o' && !tag[n - 1] && tag[0] == tag[n - 2]) return 0;
	if (s[n - 1] == 'x' && tag[n - 1] && tag[0] == tag[n - 2]) return 0;
	if (s[n - 1] == 'x' && !tag[n - 1] && tag[0] != tag[n - 2]) return 0;

	if (s[0] == 'o' && tag[0] && tag[1] != tag[n - 1]) return 0;
	if (s[0] == 'o' && !tag[0] && tag[1] == tag[n - 1]) return 0;
	if (s[0] == 'x' && tag[0] && tag[1] == tag[n - 1]) return 0;
	if (s[0] == 'x' && !tag[0] && tag[1] != tag[n - 1]) return 0;
	ispis();
	return 1;
}

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

	pretp(0, 0);
	pretp(0, 1);
	pretp(1, 0);
	pretp(1, 1);
	put();

	return 0;
}

Measured memory_bytes: 768