akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <math.h>
const double EPS = 1e-9;
using namespace std;
class vector {
public:
	double x, y;
	vector(double a, double  b) {
		x = a;
		y = b;
	};
	/*vector operator * (const vector &v)const {
		return vector(x*v.x, y* v.y);
	}
	vector operator - (vector v) {
		return vector(x - v.x, y - v.y);
	}*/
};
inline double dot(vector v1, vector v2) {
	return v1.x*v2.x + v1.y*v2.y;
}
inline double para(vector v1, vector v2) {
	return sqrt(v1.x*v1.x + v1.y*v1.y)*sqrt(v2.x*v2.x + v2.y*v2.y);
}
int main() {
	double n, x1, x2, x3, x4, y1, y2, y3, y4;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		vector v1(x2 - x1, y2 - y1);
		vector v2(x4 - x3, y4 - y3);
		double ans = dot(v1, v2);
		if (ans == 0) cout << 1 << endl;
		else if (fabs(ans - para(v1, v2)) < EPS || fabs(2*ans - fabs(ans - para(v1, v2))) < EPS || fabs((-2) * ans - fabs(ans - para(v1, v2))) < EPS) cout << 2 << endl;
		else cout << 0 << endl;
	}
	return 0;
}

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

int main(){
  int N,M;
  cin>>N>>M;
  
  vector<int> H(N);
  
  rep(i,N){
    cin>>H[i];
  }
  
  vector<vector<int>> G(N);
  
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  vector<bool> peek(N,true);
  //int c=G.size();
  //cout<<c<<endl;
  
  for(int i=0;i<N;i++){
    
    if(peek[i]==true){
      int c=G[i].size();
      //printf("%d\n",c);
      for(int j=0;j<c;j++){
        int ans=0;
        int height=H[i];
        
        if(height>H[G[i][j]]){
          
          peek[G[i][j]]=false;
        }else{
          peek[i]=false;
        }
      }
    }
  }
  int ans=0;
  for(int i=0;i<N;i++){
    if(peek[i]==true)ans++;
  }
  
  
  cout<<ans<<endl;
  


}

Measured memory_bytes: 8736
x=y=z=-1
N,Y=map(int, input().split())

for i in range(N+1):
    if i*10000>Y:
        continue
    for j in range(N+1):
        if i*10000+j*5000>Y:
            continue
        elif (N-i-j)*1000+j*5000+i*10000==Y:
            x=i
            y=j
            z=N-j-i
            break

print(x,y,z)


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

signed main() {
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(a,b) << " " << max(0, a+b-n) << '\n';
}

Measured memory_bytes: 3524
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2) {
		return -1;
	}
	else if (*(long *)n1 < *(long *)n2) {
		return 1;
	}
	else {
		return 0;
	}
}

int cmpnum2(const void * n1, const void * n2) {
	if (labs(*(long *)n1) > labs(*(long *)n2)) {
		return 1;
	}
	else if (labs(*(long *)n1) < labs(*(long *)n2)) {
		return -1;
	}
	else {
		return 0;
	}
}

int main(void) {

  long n,k;
  scanf("%ld %ld", &n, &k);
  long a[n];
  long plus = 0, zero = 0, minus = 0;
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
    if (a[i] > 0) {
      plus++;
    } else if (a[i] == 0) {
      zero++;
    } else {
      minus++;
    }
  }
  qsort(a, n, sizeof(long), cmpnum);
  long mod = pow(10,9)+7;
  int flag = 0;
  long pairs = minus/2;
  if (k/2 < pairs) {
    pairs = k/2;
  }
  if (plus+pairs*2 >= k) {
    flag = 1;
  } else if (zero == 0) {
    flag = -1;
  }
  long ans;
  long p_cur,m_cur,left,p_left,m_left;
  long tmp1,tmp2;
  if (flag == 1) {
    ans = 1;
    p_cur = 0;
    m_cur = n-1;
    left = k;
    p_left = plus;
    m_left = minus/2*2;
    if (k%2 == 1) {
      ans = a[0];
      p_cur++;
      left--;
      p_left--;
    }
    while (left > 0) {
      if (p_left == 0) {
        ans *= -a[m_cur];
        ans %= mod;
        ans *= -a[m_cur-1];
        ans %= mod;
        left -= 2;
        m_cur -= 2;
      } else if (m_left == 0) {
        ans *= a[p_cur];
        ans %= mod;
        ans *= a[p_cur+1];
        ans %= mod;
        left -= 2;
        p_cur += 2;
      } else {
        tmp1 = a[p_cur]*a[p_cur+1];
        tmp2 = (-a[m_cur])*(-a[m_cur-1]);
        if (tmp1 >= tmp2) {
          ans *= a[p_cur];
          ans %= mod;
          ans *= a[p_cur+1];
          ans %= mod;
          left -= 2;
          p_cur += 2;
        } else {
          ans *= -a[m_cur];
          ans %= mod;
          ans *= -a[m_cur-1];
          ans %= mod;
          left -= 2;
          m_cur -= 2;
        }
      }
    }
    printf("%ld\n", ans);
  } else if (flag == -1) {
    qsort(a, n, sizeof(long), cmpnum2);
    ans = 1;
    for (long i = 0; i < k; i++) {
      ans *= (mod+a[i]);
      ans %= mod;
    }
    printf("%ld\n", ans);
  } else {
    printf("0\n");
  }

  return 0;
}

Measured memory_bytes: 4784
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)

n= int(input())
ans = 0
for i in range(1, n+1):
  for j in range(1, n+1):
    for k in range(1, n+1):
      ans += gcd(i, j, k)
print(ans)

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


int main()
{
	long long  n,a,b,c;
	cin>>n;
	for(int a=1;a<=3500;a++)
	{
		for(int b=1;b<=3500;b++){
		long long x=n*a*b;
		long long y=4*a*b-n*(b+a);
			if(y>0 && x%y==0){
				cout<<a<<" "<<b<<" "<<x/y<<endl;
				return 0;
			}
		}
	}
		
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <stdlib.h>
#include <ctime>
using namespace std;
typedef long long ll;

//ifstream fin("input.txt");
//ofstream fout("output.txt");
ll gds(ll x,ll y){
    if(y == 0) return x;
    if(x%y==0) return y;
    else return gds(y,x%y);
}

ll prime[100000];
ll sz;

ll a[100000];
int main(){
    //ios_base::sync_with_stdio(false);
    //cout<<fixed<<setprecision(20);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int a=0;
    for(int i=0;i<n;i++) if(s[i] == '#') a++;
    int b=0;
    int ans=a;
    for(int i=0;i<n;i++){
        int locans=(n-i)-(a-b)+b;
        if(locans<ans) ans=locans;
        if(s[i] == '#') b++;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    char c;
    cin>>c;
    if(c>='a' && c<='z')
    cout<<"a"<<endl;
    else
    cout<<"A"<<endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
ll a[20][20];
ll dp[MAXN];
ll val[MAXN];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("../IO/int.txt","r",stdin);
        freopen("../IO/out.txt","w",stdout);
    #endif

    cin>>n;

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin>>a[i][j];
        }
    }
    int mx = (1<<n);
    for(int i = 1; i < mx; i++) dp[i] = -INF;
    for(int i = 0; i < mx; i++){
        int mask = i;
        for(int j = 0; j < n; j++){
            if((mask & (1<<j))){
                val[mask] = val[mask ^ (1<<j)];
                for(int k = 0; k < n; k++){
                    if((mask & (1<<k))){
                        val[mask] += a[j][k];
                    }
                }
                break;
            }
        }
    }
    dp[0] = 0;
    for (int m=0; m < mx; ++m){
        for(int s=m; s; s=(s-1)&m){
            dp[m] = max(val[s] + val[m^s], max(dp[m], dp[s] + dp[m ^ s]));
        }
    }


    cout<<dp[mx - 1]<<endl;
    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for(int i = (int)m; i < (int)n; i++)

string AL = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int N;
string S;

int main() {
    cin >> N;
    cin >> S;
    REP(i, S.size()) {
        int num = ((S[i] - 'A') + N) % AL.size();
        cout << AL[num];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RF(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {F(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {F(i, 0, a.size()) cout<<a[i]<<" ";}
/*----------------------------------------------------------------------*/

const int N = 405;
ll arr[N],dp[N][N];

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin>>n;

    F(i, 0, N) {
    	F(j, 0, N) {
    		dp[i][j] = LONG_LONG_MAX;
    	}
    }

    F(i, 0, n) {
    	cin>>arr[i];
    	dp[i][i] = 0;
    	if(i) arr[i] += arr[i-1];
    }

    RF(i, n-2, 0) {
    	F(j, i+1, n) {
    		F(k, i, j) {
    			ll val = dp[i][k] + dp[k+1][j] + arr[j];
    			if(i) val -= arr[i-1];
    			dp[i][j] = min(dp[i][j], val);
    		}
    	}
    }

    cout<<dp[0][n-1];

    return 0;
}/*

*/


Measured memory_bytes: 1536
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <string>

using namespace std;

int main()
{
    int N, A, B;
    if (scanf("%d%d%d", &N, &A, &B) < 3) return 0;

    printf("%s\n", (B - (A + 1)) % 2 == 0 ? "Borys" : "Alice");

    return 0;
}


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

void Main() {
    // input
    int a, b;
    cin >> a >> b;

    string ans;
    // process
    if (a < b) {
        for (int i = 0; i < b; i++) {
            ans += to_string(a);
        }
    } else {
        for (int i = 0; i < a; i++) {
            ans += to_string(b);
        }
    }


    // output
    cout << ans << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3676
s = input()
ans = 0
# 2019までの余りの分布
U = [0 for i in range(2019)]
mod = 2019
sum_i_to_n = 0
for i in range(len(s)-1, -1, -1):
    # 後ろから見てく
    sum_i_to_n += int(s[i]) * pow(10, len(s)-i-1, mod)
    sum_i_to_n %= mod
    if sum_i_to_n % mod == 0:
        # 2019で割り切れたら
        ans += 1
    # 1817181712114と81712114はあまりが同じ。
    # 二つの差の1817100000000は2019の倍数よって18171も2019の倍数
    ans += U[sum_i_to_n]
    U[sum_i_to_n] += 1

print(ans)


Measured memory_bytes: 9288
n = int(input())
A = list(map(int, input().split()))
B = A[::-1]

mod_n = 10**9+7

cum_A = [0]
for i in range(n-1):
  cum_A.append(cum_A[i]+B[i])
  
ans = 0
cum_B = cum_A[::-1]
for i in range(n-1):
  ans += A[i]*cum_B[i]%mod_n
  
print(ans%mod_n)

Measured memory_bytes: 31768
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
double X[1010], Y[1010], R[1010];
double E[1010][1010];
double D[1010];
bool used[1010];

double dist(double x1, double y1, double x2, double y2) {
	double x = x1 - x2, y = y1 - y2;
	return sqrt(x * x + y * y);
}

void solve() {
	cin >> X[0] >> Y[0] >> X[1] >> Y[1];
	R[0] = R[1] = 0;
	cin >> N;
	rep(i, 2, N + 2) cin >> X[i] >> Y[i] >> R[i];
	N += 2;
	rep(i, 0, N) 
		rep(j, 0, N) 
			E[i][j] = max(0.0, dist(X[i], Y[i], X[j], Y[j]) - R[i] - R[j]);

	// rep(i, 0, N)
	// 	rep(j, 0, N) debug(i, j, E[i][j]);

	fill(D, D + N, linf);
	D[0] = 0;
	while(true) {
		int v = -1;
		rep(i, 0, N) if(!used[i] && (v == -1 || D[i] < D[v])) v = i;
		if(v == -1) break;
		used[v] = true;
		rep(i, 0, N) MIN(D[i], D[v] + E[i][v]);
	}
	cout << D[1] << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 8192
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<ctype.h>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<math.h>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<stdio.h>
#include<stdlib.h>
#include<streambuf>
#include<string.h>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
using namespace std;
typedef long long ll;
struct edg{
	int w;
	int u,v;
	int nud;
	edg(int _a=0,int _b=0,int _c=0,int _d=0){
		w=_a;
		u=_b;
		v=_c;
		nud=_d;
	}
	bool operator <(const edg &a)const{
		if (w!=a.w) return w<a.w;
		if (u!=a.u) return u<a.u;
		if (v!=a.v) return v<a.v;
		return nud<a.nud;
	}
};
int fa[200010];
int rnk[200010];
int get(int i){
	return fa[i]==i?i:fa[i]=get(fa[i]);
}
bool sameset(int i,int j){
	return get(i)==get(j);
}
void unite(int i,int j){
	i=get(i);
	j=get(j);
	if (rnk[i]<rnk[j]){
		fa[i]=j;
		return;
	}
	if (rnk[i]>rnk[j]){
		fa[j]=i;
		return;
	}
	fa[j]=i;
	++rnk[i];
}
int main(void){
	int n,q;
	scanf("%d%d",&n,&q);
	priority_queue<edg> pq;
	for (int i=1;i<=q;++i){
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		pq.push(edg(-w,u,v,0));
		pq.push(edg(-w-1,v,u==n-1?0:u+1,0));
	}
	for (int i=0;i<n;++i){
		fa[i]=i;
	}
	ll res=0;
	int hve=0;
	edg t;
	while(hve<n-1){
		t=pq.top();
		pq.pop();
		if (sameset(t.u,t.v)){
			if (t.nud==10) continue;
			pq.push(edg(t.w-2,t.u==n-1?0:t.u+1,t.v==n-1?0:t.v+1,t.nud+1));
			continue;
		}
		res+=-t.w;
		++hve;
		unite(t.u,t.v);
		pq.push(edg(t.w-2,t.u==n-1?0:t.u+1,t.v==n-1?0:t.v+1,0));
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 10604
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

void solve()
{
	int n,k;
	cin>>n>>k;
	map<int,int> m;
	for (int i = 0; i < k; ++i)
	{
		/* code */
		int d;
		cin>>d;
		for(int j = 0; j < d; j++)
		{
			int l;
			cin>>l;
			m[l]++;
		}
	}
	cout<<n-m.size()<<endl;
}

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

Measured memory_bytes: 3632
N = int(input())
S = input()

L, R = [0] * 10, [0] * 10

L[int(S[0])] += 1
for s in S[2:]:
    R[int(s)] += 1

memo = set()
for i, s in enumerate(S[1:-1], 1):
    for l, v in enumerate(L):
        if v <= 0:
            continue
        for r, v in enumerate(R):
            if v <= 0:
                continue
            memo.add(str(l) + s + str(r))
    L[int(s)] += 1
    R[int(S[i + 1])] -= 1

print(len(memo))


Measured memory_bytes: 43484
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll r, d, x;
    cin >> r >> d >> x;
    for (int i = 0; i < 10; i++)
    {
        x = r * x - d;
        cout << x << endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265359
using namespace std;


//const string k = "enterstringtobechecked";

const int K = 1e6 + 10;
bool seen[K];

int main()
{
    SYNC
   // clock_t tStart = clock();
    //freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    ll n; in(n);
    string s; in(s);
    vl w,r;
    l(i,0,n)
    {
        if(s[i]=='W')
            w.pb(i);
        else
            r.pb(i);
    }
    if(w.size()==0 || r.size()==0)
    {
        o(0)<<endl;
        return 0;
    }
    ll p=r.size()-1,q=0;
    ll count=0;
    while(q<r.size() && p>=0 && r[p]>w[q])
    {
        count++;
        q++;
        p--;
    }
    o(count)<<endl;






    //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);   
}


Measured memory_bytes: 5772
#include<bits/stdc++.h>
#define LL long long
#define MAXN 50005
#define INF (1<<25)
#define P int(998244353)
using namespace std;

LL n,s;


bool chk(LL b){
	LL res = 0;
	LL x = n;
	while(x){
		res += x%b;
		x /= b;
	}
	return (s==res);
}

bool chk(LL b, LL x, LL y){
	return x>=0 && y>=0 && y<b && x<b;
}

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

	if(n==s){
		cout<<n+1<<endl;
		return 0;
	} 
	
	LL ans = 1e18;
	for(LL b=2;b*b<=n;b++){
		if(chk(b)){
			ans = b;
			break;
		}
	}

	/*
	bx + y = n
	x + y = s
	(b-1)*x = n-s
	*/

	if(ans==1e18 && n-s<=0){
		cout<<"-1"<<endl;
		return 0;
	}
	
	LL b,y;
	for(LL x=1;x*x<=n-s;x++){
		if((n-s)%x==0){
			
			b = (n-s)/x + 1;
			y = s - x;
			if(chk(b,x,y)){
				
				ans = min(ans, b);
			}
			
			//
			b = x + 1;
			y = s - (n-s)/(b-1);
			if(chk(b,s-y,y)){
				ans = min(ans, b);
			}
		}
	}
	
	if(ans==1e18){
		if(s==1) ans = n;
		else ans = -1;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 384
//minmaxsum.cpp
#include <bits/stdc++.h>
using namespace std;
int main (){
  int n, min, max;
  double sum;
  cin >> n ;
  int arr[n];
  for (int i=0; i < n; i++){
    cin >> arr[i];
  };
  min = arr[0]; max = arr[0]; sum = arr[0];
  for (int i=1; i < n ; i++){
    if (min > arr[i]) min = arr[i];
    if (max < arr[i]) max = arr[i];
    sum += arr[i];
  };
  cout << fixed << setprecision(0) << min << " " << max << " " << sum << endl;
}




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

int main(void){
    long n, m;
    long cnt = 0;
    
    cin >> n >> m;
    
    if(2 * n >= m){
        cnt += m / 2;
        cout << cnt << endl;
    }
    else{
        cnt += n;
        m -= 2 * n;
        cnt += m / 4;
        cout << cnt << endl;
    }
    
    return 0;
}

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

int main()
{
 	int a;
  cin >> a;
  string s;
  int counter=0;
  for(int i=1;i<=a;i++)
  {
    s=to_string(i);
   	if( s.length() %2 ==1)
    {
     counter++; 
    }
  }
  cout << counter << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int MAXN = 1000000;

int C(int n, int m) {
	if( m == 0 ) return 1;
	if( (n & 1) < (m & 1) ) return 0;
	return C(n / 2, m / 2);
}
int abs(int x) {
	return x >= 0 ? x : -x;
}

int N; char s[MAXN + 5];
int a[MAXN + 5];
int main() {
	scanf("%d%s", &N, s);
	bool flag = false;
	for(int i=1;i<N;i++) {
		a[i] = abs(s[i - 1] - s[i]);
		if( a[i] == 1 ) flag = true;
	}
	if( flag ) {
		int ans = 0;
		for(int i=1;i<N;i++)
			if( C(N - 2, i - 1) && a[i] == 1 ) ans ^= 1;
		printf("%d\n", ans);
	}
	else {
		int ans = 0;
		for(int i=1;i<N;i++)
			if( C(N - 2, i - 1) && a[i] == 2 ) ans ^= 1;
		printf("%d\n", ans*2);
	}
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define OUT(x) cout << (x) << endl;
#define ALL(v) v.begin(), v.end()
#define REP(i, n) for (int i=0; i<(int)(n); ++i)


int main() {
    int K, S;
    cin >> K >> S;
   int count = 0;
   for(int x=0; x<=K; x++){
      for(int y=0; y<=K; y++){
           int z = S - x - y;
           if(0 <=z && z <= K){
               count++;
           }
       }
   }
   OUT(count);
}

Measured memory_bytes: 256
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

struct Elem {
    int x, y, col;
    bool operator<(const Elem &e) const {
        return x < e.x;
    }
};

signed main() {
    int N; cin >> N;
    vector<Elem> es;
    for(int i=0; i<2*N; i++) {
        int x, y; cin >> x >> y;
        es.push_back(Elem{x, y, i < N});
    }

    sort(es.begin(), es.end());
    set<int> S;
    int ans = 0;
    for(int i=0; i<2*N; i++) {
        if(es[i].col == 1) S.insert(es[i].y);
        else {
            int target = es[i].y;
            auto it = S.upper_bound(target);
            if(it == S.begin()) continue;
            it--;
            S.erase(*it);
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  while (n > 0) {
    n /= k;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N,n,v,w,i,t,m,*p;main(W){for(;scanf("%d",&W),W;){int c[1001]={0};for(scanf("%d",&n);n--;)for(scanf("%d,%d",&v,&w),m=i=W+1,p=c;i--;*p++-*c||m--)i>=w&&*p<(t=p[w]+v)&&(*p=t);printf("Case %d:\n%d\n%d\n",++N,*c,m);}return 0;}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main(){
    ll N,M,sum=0,K=0;cin>>N>>M;
    vector<ll> A;
    ll V;
    rep(i,N){
        cin >> V;
        A.push_back(V);
    }
    sort(ALL(A));
    reverse(ALL(A));
    while(1){
        ll key=A[0];
        rep(i,N){
            if(K>=M){
                rep(i,N){
                    sum+=A[i];
                }
                cout << sum <<endl;
                return 0;
            }
            if(A[i]>=key/2){
                A[i]/=2;
                K++;
            }
        }
        sort(ALL(A));
        reverse(ALL(A));
    }
}


Measured memory_bytes: 1400
N = int(input())
from itertools import product

count_dic = {i: 0 for i in range(1, N+1)}
def func(x, y, z):
    return x**2 + y**2 + z**2 + x*y + y*z + z*x

for x, y, z in list(product(range(1, 101), repeat=3)):
    res = func(x, y, z)
    if res > N:
        continue
    count_dic[res] += 1

for i in range(1, N+1):
    print(count_dic[i])

Measured memory_bytes: 154312
#include <iostream>
#include <math.h>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;
#define n_max 1000

int SumDigits(int n)
{
    int sum = 0;

    while(n > 0) {
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

int main()
{
    int N;

    cin >> N;
    
    if((N % SumDigits(N)) == 0) {
        puts("Yes");
    } else {
        puts("No");
    }

    return 0;
}


Measured memory_bytes: 256
#Coding:Utf-8

S = list(map(int, input()))
N=len(S)
count=0


def rev(x):
    if x==0:
        return 1
    else:
        return 0


if N==1:
    print(0)
    exit()

for i in range(N-1):
    if S[i]==S[i+1]:
        S[i+1]=rev(S[i+1])
        count+=1
print(count)


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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> v(h);
	REP(i, h) {
		cin >> v[i];
	}
	vector <int> dx = { 1,-1,0,0,1,1,-1,-1 };
	vector<int> dy = { 0,0,1,-1,1,-1,1,-1 };
	REP(i, h) {
		REP(j, w) {
			int res = 0;
			if (v[i][j] == '.') {
				REP(k, 8) {
					if (i + dx[k] >= 0 && i + dx[k] < h){
						if (j + dy[k] >= 0 && j + dy[k] < w) {
							if (v[i + dx[k]][j + dy[k]] == '#'){
								res++;
							}
						}
					}
				}
				cout << res;
			}
			else {
				cout << v[i][j];
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int pop();
void push(int);
int stack[1000];
int num=0;
void push(int j){
  stack[num++]=j;
}
int pop(){
  if(num<=0) return 0;
  return stack[--num];
}

int main(){
  int i,j,k=0,Ans,a,b;
  char s[100];
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      a=pop();
      b=pop();
      Ans=a+b;
      push(Ans);
    }
    else if(s[0]=='-'){
      a=pop();
      b=pop();
      Ans=b-a;
      push(Ans);
      
    }
    else if(s[0]=='*'){
      a=pop();
      b=pop();
      Ans=a*b;
      push(Ans);
      
    }
    else {
      j=atoi(s);    
      push(j);
    }
  }
  Ans=pop();
  printf("%d\n",Ans);
  return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

struct UnionFind {
    /* N: 0-indexed array size */
    vector<int> par;
    vector<int> _size;
    
    UnionFind(int N) : par(N), _size(N) {
        rep(i, N) par[i] = i;
        rep(i, N) _size[i] = 1;
    }
    
    int root(int x) {
        if (par[x]==x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx==ry) return;
        if (_size[rx] <= _size[ry]) swap(rx, ry);
        _size[rx] += _size[ry];
        par[ry] = rx;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return _size[root(x)];
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m, k; cin >> n >> m >> k;
    UnionFind tree(n);
    vector<set<int>> adj(n);
    rep(i, m) {
        int a, b; cin >> a >> b;
        a--; b--;
        tree.unite(a, b);
        adj[a].insert(b);
        adj[b].insert(a);
    }
    rep(i, k) {
        int c, d; cin >> c >> d;
        c--; d--;
        if (tree.same(c, d)) {
            adj[c].insert(d);
            adj[d].insert(c);
        }
    }
    rep(i, n) {
        cout << tree.size(i) - adj[i].size() - 1 << " ";
    }
    cout << endl;
    return 0;
}

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

int main(){
   int a, b;
   cin>>a>>b;
   cout << a*b << endl;
   return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
    string n;
    cin>>n;
    int x=0;
    for(int i=0;i<n.size();i++)x+=n[i]-'0';
    if(x%9)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;

void print(){ std::cout << std::endl; }
template<typename H> void print(H&& head){ std::cout << head << std::endl; }
template<typename H, typename... T> void print(H&& head, T&&... tail){
  std::cout << head << " ", print(std::forward<T>(tail)...);
}

void solve()
{
  std::string S, T;
  std::cin >> S >> T;

  T.pop_back();

  print(S == T ? "Yes" : "No");
  return;
}

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

  solve();
  return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG=20;

int n, m, k, u, v, x, y, t, a, b, ans;
string s;

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>s;
	if (n&1) kill("No")
	for (int i=0; i<n/2; i++) if (s[i]!=s[i+n/2]) kill("No")
	kill("Yes")
	
	
	return 0;
}


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

// # DEFINES # //
#define ll long long
#define M (ll)1e9+7
#define EPS 1e-9

using namespace std;

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

int gcdArray(vector<int> arr) {
    int result = arr[0];
    size_t n = arr.size();

    for(int i = 1; i < n; i++) {
        result = gcd(result, arr[i]);
        if(result == 1)
            return 1;
        
    }
    return result;
}

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

    ll int n;
    
    cin >> n;

    ll int sum = 0;
    for(int i = 1; i <= n; i++) {
        if(i % 3 != 0 && i % 5 != 0)
            sum += i;

    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(4, 0);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s[0] == 'A')
            a[0]++;
        else if (s[0] == 'W')
            a[1]++;
        else if (s[0] == 'T')
            a[2]++;
        else if (s[0] == 'R')
            a[3]++;
    }
    cout << "AC x " << a[0] << endl;
    cout << "WA x " << a[1] << endl;
    cout << "TLE x " << a[2] << endl;
    cout << "RE x " << a[3] << endl;
    return 0;
}

Measured memory_bytes: 3640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func solve(n int, a []int) string {
	m := map[int]int{}
	for _, v := range a {
		m[v]++
	}

	if m[0] == n {
		return "Yes"
	}
	if n%3 != 0 {
		return "No"
	}

	if len(m) == 2 {
		if m[0] == (n / 3) {
			return "Yes"
		} else {
			return "No"
		}
	}

	if len(m) == 3 {
		nums := make([]int, 0, 3)
		cnts := make([]int, 0, 3)
		for k, v := range m {
			nums = append(nums, k)
			cnts = append(cnts, v)
		}
		if cnts[0] != cnts[1] || cnts[0] != cnts[2] {
			return "No"
		}
		if nums[0]^nums[1] == nums[2] {
			return "Yes"
		}
	}

	return "No"
}

func main() {
	n, _ := strconv.Atoi(input())
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(input())
	}
	fmt.Println(solve(n, a))
}


Measured memory_bytes: 7680
t1, t2 = gets.split.map(&:to_i)
a1, a2 = gets.split.map(&:to_i)
b1, b2 = gets.split.map(&:to_i)
x1 = (a1 - b1) * t1
x2 = (a2 - b2) * t2
if (x1 > 0) ^ (x2 > 0) then
  x1, x2 = -x1, -x2 if x1 < 0
  sub = -(x1 + x2)
  if sub == 0 then
    puts "infinity"
  elsif sub < 0
    puts 0
  else
    ans = (x1 / sub) * 2
    ans += (x1 % sub == 0) ? 0 : 1
    puts ans
  end
else
  puts 0
end

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF   = LL(1e18) + 1;
#define pow10(n) int(1e##n + n)

void solve()
{
    int N, R;
    cin >> N >> R;
    if (N >= 10)
    {
        cout << R << endl;
    }
    else
    {
        cout << R + 100 * (10 - N) << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
import itertools

n,a,b,c=(input().split())
n,a,b,c=int(n),int(a),int(b),int(c)
l=[int(input()) for i in range(n)]
#print(n,a,b,c,l)

ansans=float('inf')
ans=float('inf')

mylist=list(itertools.product(range(4),repeat=n))
#print(len(mylist))
#mylist=[1,2,2,2,3]
for j in range(len(mylist)):
    x,y,z=0,0,0
    for i in range(n):
        if mylist[j][i]==1:
            x+=l[i]
        elif mylist[j][i]==2:
            y+=l[i]
        elif mylist[j][i]==3:
            z+=l[i]
        
    if mylist[j].count(1)>0 and mylist[j].count(2)>0 and mylist[j].count(3) > 0:
        ans=0
        ans+=abs(a-x)+abs(b-y)+abs(c-z)
        compo=0
        for i in range(1,4):
            compo+=mylist[j].count(i)-1
        ans+=10*compo

    if ans < ansans:
        ansans = ans

print(ansans)

Measured memory_bytes: 10916
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int H,W,D;cin >> H >> W >> D;
    vector<vector<int>> A(H+1,vector<int>(W+1,0));
    vector<pair<int,pair<int,int>>> B(H*W+1);
    rep(i,H)rep(j,W){
        cin >> A[i+1][j+1];
        B[A[i+1][j+1]] = {A[i+1][j+1],{i+1,j+1}};
    }
    sort(all(B));   // index順に並べる
    int Q;cin >> Q;
    vector<pair<int,int>> lr(Q);
    rep(i,Q)cin >> lr[i].F >> lr[i].S;

    vector<LL> rui(H*W+1,0);    // i番目がRとなるときの絶対値の累積和
    for(int i = 1;i <= H*W;++i){
        if(i + D <= H*W){
            rui[i + D] = rui[i] + abs(B[i+D].S.F - B[i].S.F) + abs(B[i+D].S.S - B[i].S.S);
        }
    }

    vector<int> ans(Q);
    rep(i,Q){
        ans[i] = rui[lr[i].S] - rui[lr[i].F];
    }
    rep(i,Q)cout << ans[i] << endl;
}


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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n,dem=0;

int main()
{
    cin>>n;
    for (int i=1;i<=n;++i)
    {
        int x;
        cin>>x;
        dem+=(x%2 && i%2);
    }
    cout<<dem;
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <string>
#include <vector>

using namespace std;

int main(){

	int n, q, cnt;
	int max=0;
	vector<int> x, l, r;
	string s, che;

	cin>> n >> q;
	cin>> s;

	x.resize(s.size()-1);
	l.resize(q);
	r.resize(q);

	for(int i=0;i<q;i++) cin>> l[i] >> r[i];

	for(int i=0;i<s.size()-1;i++){
		che=s.substr(i, 2);
		if(che=="AC"){
			x[i]=1;
			max++;
		}else{
			x[i]=0;
			//if(che.substr(1, 1)!="A") i++;
		}
	}

	/*for(int i=0;i<x.size();i++) cout<< x[i];
	cout<< endl;*/

	for(int i=0;i<q;i++){
		cnt=0;

		if(r[i]-l[i]>50000){
			cnt=max;
			for(int j=0;j<l[i]-1;j++) cnt-=x[j];
			for(int j=r[i]-1;j<x.size();j++) cnt-=x[j];
		}else{
			for(int j=l[i]-1;j<r[i]-1;j++){
				cnt+=x[j];
				//cout<< x[j];
			}
		}

		cout<< cnt << endl;
	}

}

Measured memory_bytes: 2176
#include <iostream>
#include <cmath>
#include <utility>

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
#define mp make_pair
#define x first
#define y second

int main () {
	int n;
	cin>>n;
	if(n%10==2 or n%10==4 or n%10==5 or n%10==7 or n%10==9) cout<<"hon";
	else if(n%10==3) cout<<"bon";
	else cout<<"pon";



return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc169/abc169_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  vector<unsigned long long> c(N);
  rep(i, N) {
    cin >> c[i];
    if (c[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  unsigned long long ans = 1;
  rep(i, N) {
    unsigned long long bef = ans;
    ans *= c[i];
    if (ans > 1000000000000000000 || ans / c[i] != bef) {
      cout << -1 << endl;
      return 0;
    }
  }


  cout << ans << endl;
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll a, b, c; cin >> a >> b >> c;
    (c >= a && c <= b) ? Yes() : No();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main() {
	
	ll N,W;
	cin>>N>>W;
	vector<ll> w(N),v(N);
	for(ll i=0;i<N;i++)
	{
	    cin>>w[i]>>v[i];
	}
	vector<vector<ll>> dp(N+1,vector<ll>(W+1));
	for(ll i=0;i<=W;i++)
	{
	    dp[0][i]=0;
	}
	
	for(ll i=0;i<=N;i++)
	{
	    for(ll j=0;j<=W;j++)
	    {
	        if(i==0||j==0)
	        {
	            dp[i][j]=0;
	        }
	        else if(j<w[i-1])
	        {
	            dp[i][j]=dp[i-1][j];
	        }
	        else
	        {
	            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
	        }
	    }
	}
	cout<<dp[N][W]<<endl;
   return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
int MAX_INT = 1e9;
int N,A,B,C;
int l[1000];
int dfs(int cur,int a,int b,int c) {
  if(cur==N) return (min(a,min(b,c))>0)?abs(a-A)+abs(b-B)+abs(c-C)-30:MAX_INT;
  return min(min(dfs(cur+1,a,b,c),dfs(cur+1,a+l[cur],b,c)+10),min(dfs(cur+1,a,b+l[cur],c)+10,dfs(cur+1,a,b,c+l[cur])+10));
}

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

  cin >> N >> A >> B >> C;
  for(int i = 0; i < N; i++) cin >> l[i];
  cout << dfs(0, 0, 0, 0) << endl;
  return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

int main(){
	string END="END OF INPUT";
	string s;
	while(getline(cin,s)){
		if(s.substr(0,12)==END){
			// cout<<0<<endl;
			break;
		}
		s=" "+s+" ";
		int n=s.size();
		rep(i,n){
			// if(i) cout<<" ";
			if(i==n-1){
				break;
			}
			if(s[i]==' '){
				// cout<<"i = "<<i<<endl;
				int cnt=0;
				reep(j,i+1,n){
					if(s[j]==' '){
						i=j-1;
						break;
					}
					else{
						// cout<<j<<" "<<s[j]<<endl;
						cnt++;
					}
				}
				cout<<cnt;
			}
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1196
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int x, a;
	cin >> x >> a;
	if(x < a) cout << 0 << endl;
	else cout << 10 << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = lc()
t = lc()

ans = "z"*50

match = False
for i in range(len(s)-1,-1,-1):
    if s[i] == '?' or s[i] == t[0]:
        for j, sij in enumerate(s[i:i+len(t)]):

            if sij != '?' and sij != t[j]:
                break

            if j == len(t)-1:
                match = True
                s[i:i+len(t)] = t[:]
    
    if match:
        break
                
if not match:
    print("UNRESTORABLE")
    
else:
    for i in range(len(s)):
        if s[i] == '?':
            s[i] = 'a'
            
    print("".join(s))

Measured memory_bytes: 3064