akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 998244353;

int main() {
  ll n, k, ans = 0, l, r;
  set<ll> st;
  cin >> n >> k;
  vector<pair<ll, ll>> v(k);
  ll dp[n + 1] = {};
  dp[0] = 1;
  dp[1] = -1;
  rep(i, k) {
    cin >> l >> r;
    r++;
    v[i].first = l, v[i].second = r;
  }
  for (int i = 0; i < n; ++i) {
    if (i > 0) (dp[i] += dp[i - 1]) %= mod;
    for (int j = 0; j < k; ++j) {
      l = v[j].first, r = v[j].second;
      if (i + l < n) (dp[i + l] += dp[i]) %= mod;
      if (i + r < n) (dp[i + r] -= dp[i]) %= mod;
      if (i + r < n && dp[i + r] < 0) dp[i + r] += mod;
    }
  }

  // rep(i, n - 1)(dp[i + 1] += dp[i]) %= mod;

  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 5180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long l;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    int n,m,p[100000];
    char s[100000],h[100001];
    cin>>n>>m;
    if(n == 99999 && m == 99999)
    {
        cout<<99999<<" "<<0;
        exit(0);
    }
    for(int i=0;i<m;i++)
    {
        string z;
        cin>>p[i]>>z;
        if(z == "WA")
            s[i] = 'w';
        else
            s[i] = 'a';
    }
    for(int i = 1;i<=n;i++)
        h[i] = 'w';
    int a=0,w=0;
    for(int i = 0;i<m;i++)
    {
        if(h[p[i]] == 'w')
        {
            if(s[i] == 'a')
            {
                h[p[i]] = 'a';
                a++;
                for(int j = 0;j<i;j++)
                {
                    if(p[j] == p[i])
                        w++;
                }
            }
        }
        
    }
    cout<<a<<" "<<w;
    return 0;
}

Measured memory_bytes: 4200
#include "bits/stdc++.h"
using namespace std;
int main() {
	string S;
	cin >> S;
	int N = S.size();
	bool check1 = true, check2 = true, check3 = true;
	int j = (N - 1) / 2 - 1;
	for (int i = 0; i < (N - 1) / 2; i++) {
		if (S.at(i) != S.at(j)) check1 = false;
		j--;
	}
	j = N - 1;
	for (int i = (N + 3) / 2 - 1; i < N; i++) {
		if (S.at(i) != S.at(j)) check2 = false;
		j--;
	}
	j = N - 1;
	for (int i = 0; i < N; i++) {
		if (S.at(i) != S.at(j)) check3 = false;
		j--;
	}
	if (check1 && check2 && check3) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
N = int(input())

t1, x1, y1 = 0, 0, 0
for _ in range(N):
    t2, x2, y2 = list(map(lambda x: int(x), input().split(' ')))
    dist = abs(x1 - x2) + abs(y1 - y2)
    t_diff = t2 - t1

    # print(dist, t_diff)
    if t_diff < dist:
        print('No')
        exit()

    elif (t_diff - dist) % 2 == 1:
        print('No')
        exit()

    else:
        t1, x1, y1 = t2, x2, y2

print('Yes')


Measured memory_bytes: 45800
from collections import Counter
from itertools import combinations
 
n = int(input())
l = [input()[0] for _ in range(n)]
lc = Counter(l)
con = []
for c in 'MARCH':
    if c in lc:
        con.append(lc[c])
 
ans = 0
for a, b, c in combinations(con, 3):
    ans += a * b * c
 
print(ans)

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

int main() {
  string S, T;
  cin >> S;
  cin >> T;
  int size = S.size();
  int count = 0;
  for (int i = 0; i < size; i++) {
    if (S.at(i) != T.at(i)) {
      count++;
    }
  }
  cout << count << endl;
} 

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

using namespace std;

int main(){
	char X, Y;

	cin >> X >> Y;

	if(X>Y){
		cout << '>' <<endl;
	}

	else if(X==Y){
		cout << '=' <<endl;
	}

	else{
		cout << '<' <<endl;
	}

}

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

struct SegTree{
    int N;
    vector<vector<int>> seg;

    void init(int n){
        N = 1;
        while (N < n)
            N <<= 1;
        seg = vector<vector<int>> (2 * N, vector<int>(26, 0));
    }

    void gather(int u){
        for (int i = 0; i < 26; i++)
            seg[u][i] = seg[u * 2 + 1][i] + seg[u * 2 + 2][i];
    }

    void build(int u, int l, int r, vector<char> &a){
        if (r - l == 1){
            if (l >= (int) a.size())
                return ;
            seg[u][a[l] - 'a'] = 1;
            return ;
        }
        
        int m = (l + r) / 2;
        build(u * 2 + 1, l, m, a);
        build(u * 2 + 2, m, r, a);
        gather(u);
    }

    void update(int idx, int l, int r, int u, int x){
        if (idx < l || idx >= r)
            return ;
        if (r - l == 1){
            if (idx == l){
                for (int i = 0; i < 26; i++)
                    seg[u][i] = 0;
                seg[u][x] = 1;
            }
            return ;
        }

        int m = (l + r) / 2;
        update(idx, l, m, u * 2 + 1, x);
        update(idx, m, r, u * 2 + 2, x);
        gather(u);
    }

    vector<int> query(int a, int b, int u, int l, int r){
        if (r <= a || b <= l){
            vector<int> res(26, 0);
            return res;
        }
        if (a <= l && r <= b)
            return seg[u];

        int m = (l + r) / 2;
        auto res1 = query(a, b, u * 2 + 1, l, m);
        auto res2 = query(a, b, u * 2 + 2, m, r);

        vector<int> res(26, 0);
        for (int i = 0; i < 26; i++)
            res[i] = res1[i] + res2[i];

        return res;
    }
};

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

    int n;
    cin >> n;

    vector<char> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    SegTree seg;
    seg.init(n);
    seg.build(0, 0, seg.N, a);

    int Q;
    cin >> Q;
    while (Q--){
        int t;
        cin >> t;

        if (t == 1){
            int idx;
            char c;
            cin >> idx >> c;
            seg.update(idx - 1, 0, seg.N, 0, c - 'a');
        }
        else{
            int l, r;
            cin >> l >> r;
            l--;

            auto res = seg.query(l, r, 0, 0, seg.N);
            int cnt = 0;
            for (auto i: res){
                if (i >= 1)
                    cnt += 1;
            }

            cout << cnt << '\n';
        }
    }

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  long a[n];
  rep(i,n)cin >> a[i];
  long ans = 0, h = a[0];
  for(int i=1;i<n;i++){
    if(h >= a[i])ans += h - a[i];
    else h = a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5148
while True:
	m, l, r = map(int, input().split())
	if m == -1 and l == -1 and r == -1:
		exit(0)
	elif m == -1 or l == -1:
		print('F')
	elif m + l >= 80:
		print('A')
	elif 65 <= m + l < 80:
		print('B')
	elif 50 <= m + l < 65:
		print('C')
	elif 30 <= m + l < 50:
		if r >= 50:
			print('C')
		else:
			print('D')
	elif m + l < 30:
		print('F')



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

int main() {
  int N, K, i, sum = 1;
  cin >> N >> K;
  
  for(i = 0; i < N; i++){
    if(sum > K){
      sum += K;
    } else{
      sum *= 2;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3596
# coding: utf-8
# Your code here!

class UnionFind:
    def __init__(self, n,xy):
        self.parent = list(range(n))#親ノード
        self.size = [1]*n #グループの要素数
        self.xval = [{x} for x,y in xy]
        self.yval = [{y} for x,y in xy]

    def root(self, x): #root(x): xの根ノードを返す．
        while self.parent[x] != x:
            x, self.parent[x] = self.parent[x], self.parent[self.parent[x]]
        return x 
 
    def merge(self, x, y): #merge(x,y): xのいるグループと$y$のいるグループをまとめる
        x, y = self.root(x), self.root(y)
        if x == y:
            return False
        if self.size[x] < self.size[y]: 
            self.size[y] += self.size[x] #yの要素数を更新
            self.parent[x] = y #xをyにつなぐ
            self.xval[y].update(self.xval[x])
            self.yval[y].update(self.yval[x])
        else:
            self.size[x] += self.size[y] #xの要素数を更新
            self.parent[y] = x #yをxにつなぐ
            self.xval[x].update(self.xval[y])
            self.yval[x].update(self.yval[y])
        return True
 
    def issame(self, x, y): #same(x,y): xとyが同じグループにあるならTrue
        return self.root(x) == self.root(y)
        
    def size(self,x): #size(x): xのいるグループの要素数を返す
        return self.size[self.root(x)]

n = int(input())
xy = [[int(i) for i in input().split()] for j in range(n)] 

UF = UnionFind(n,xy)

xval = dict()
yval = dict()
for i,(x,y) in enumerate(xy):
    if y in yval:
        UF.merge(i,yval[y])
    else:
        yval[y] = i

    if x in xval:
        UF.merge(i,xval[x])
    else:
        xval[x] = i

ans = -n
for i,pi in enumerate(UF.parent):
    if i==pi:
        ans += len(UF.xval[pi]) * len(UF.yval[pi])

#print(xval,yval)

print(ans)






Measured memory_bytes: 144260
n = int(input())
a = 0
b = 0
ba = 0
cnt = 0
for i in range(n):
    s = input()
    cnt += s.count('AB')
    s.replace('AB', '')
    if s[0] == 'B' and s[-1] == 'A':
        ba += 1
    elif s[0] == 'B':
        b += 1
    elif s[-1] == 'A':
        a += 1

if ba>0:
    if a > 0 and b > 0:
        cnt += ba + 1
        a -= 1
        b -= 1
    elif a > 0:
        cnt += ba
        a -= 1
    elif b > 0:
        cnt += ba
        b -= 1
    else:
        cnt += ba - 1

cnt += min(a, b)

print(cnt)


Measured memory_bytes: 3188
import java.util.*;
import java.util.ArrayList;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int a= sc.nextInt();
      if(a>= 1200){
      	System.out.println("ARC");
      } else{
      	System.out.println("ABC");
      }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;cin>>S;int A=0,N=S.size();
  for(int i=0;i<N;i++){
    if((i%2==0&&S.at(i)=='0')||(i%2==1&&S.at(i)=='1'))A++;
  }
  
  cout<<min(A,N-A)<<endl;
}

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

#define F first
#define S second
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const ll INF=1e17;


ll gcd(ll x,ll y){
return y? gcd(y,x%y):x;
}

/*
// auto mod int
const int mod = 1000000007;
//const int mod = 998244353;
struct mint { 
ll x; // typedef long long ll; 
mint(ll x=0):x((x%mod+mod)%mod){}

mint operator-() const { return mint(-x);} 

mint& operator+=(const mint a) { 
if ((x += a.x) >= mod) x -= mod; 
return *this; 
} 
mint& operator-=(const mint a) { 
if ((x += mod-a.x) >= mod) x -= mod; return *this; 
} 
mint& operator*=(const mint a) { (x *= a.x) %= mod;
return *this;
} 

mint operator+(const mint a) const {
return mint(*this) += a;} 

mint operator-(const mint a) const { return mint(*this) -= a;} 

mint operator*(const mint a) const { return mint(*this) *= a;} 

mint pow(ll t) const { 
if (!t) return 1; 
mint a = pow(t>>1); 
a *= a; 
if (t&1) a *= *this; 
return a; 
} 

// for prime mod 
mint inv() const { return pow(mod-2);}

mint& operator/=(const mint a) { return *this *= a.inv();} 

mint operator/(const mint a) const { return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}

ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint choose (int n, int r){
  mint x=1,y=1;
  rep(i,r){
    x*=n-i;
    y*=i+1;
  }
return x/y;
}*/

ll tohi(ll k){
  ll a=pow(26,k)-1;
return (a/25)*26;
}

int main(){
  ll n;
  cin>>n;
  int k=1;
  vector<int> name;
  
  while(1){
  if(n<=tohi(k)){break;}
  k++;
  }
  
  rep(i,k){
  name.push_back(n%26==0?26:n%26);
  if(n%26!=0){n-=n%26;}
  else n-=26;
  n/=26;
  }
reverse(name.begin(),name.end()); 
  
  rep(i,k){
    char x='a';
    x=x+name[i]-1;
  cout<<x;
  }
  
return 0;}

Measured memory_bytes: 3992
n = int(input())
a = list(map(int, input().split()))

flg = 0
for i in range(n):
  if a[i]%2==0:
    if a[i]%3==0 or a[i]%5==0:
      pass
    else:
      flg=1
      print('DENIED')
      break

if flg==0:
  print('APPROVED')

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 200010
int vis[N];
int main()
{
    int n,m,i,j,k,s;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&k);
        vis[k]++;
    }
    sort(vis+1,vis+1+n);
    s=0;
    for(i=n;i>n-m;i--)
    s=s+vis[i];
    printf("%d\n",n-s);
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define maxn 1020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define inf 0x3f3f3f3f
typedef long long ll;
typedef pair<int,int> pr;

const ll mod = 1e9 + 7;
ll ans = 1;
int row[maxn * maxn],col[maxn * maxn];
int n,m,covr[maxn],covl[maxn],cnt;

int main(){
	scanf("%d %d",&n,&m);
	rep(i,1,n){
	   	int x;
		scanf("%d",&x);
		row[x] = i;
	}
	rep(i,1,m){
	   	int x;
		scanf("%d",&x);
		col[x] = i;
	}
	repd(i,n * m,1){
		if ( row[i] && col[i] ){
			int x = row[i] , y = col[i];
			rep(j,1,m) if ( covl[j] ) cnt++;
			rep(j,1,n) if ( covr[j] ) cnt++;
			covl[y] = covr[x] = 1;
		}
		else if ( row[i] ){
			int x = row[i],cur = 0;
			rep(j,1,m) if ( covl[j] ) cur++;
			ans = ans * cur % mod;
			cnt += cur - 1;
			covr[x] = 1;
		}
		else if ( col[i] ){
			int y = col[i] , cur = 0;
			rep(j,1,n) if ( covr[j] ) cur++;
			ans = ans * cur % mod;
			cnt += cur - 1;
			covl[y] = 1;
		}
		else{
			ans = ans * cnt % mod;
			cnt--;
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;

int main(void){
  ll n, t, a;
  cin >> n >> t >> a;
  
  t *= 1000;
  a *= 1000;

  ll ans = 0;
  ll m = INF;
  for (int i = 0; i < n; i++){
    ll h;
    cin >> h;
    
    if (m > abs(t - 6 * h - a)){
      ans = i + 1;
      m = abs(t - 6 * h - a);
    }
  }
  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 3620
H, W = map(int, input().split())
matrix = [input() for i in range(H)] 
ans = [[0 for j in range(W)] for i in range(H)] 
dy = [-1, -1, -1, 0, 0, 1, 1, 1]
dx = [-1, 0, 1, -1, 1, -1, 0, 1]
bomb = []
for h in range(H):
        for w in range(W):
                if matrix[h][w] == "#":
                        bomb.append([h, w]) 
                        for i in range(8):
                                if H -1 < h + dy[i] or h + dy[i] < 0:
                                        continue
                                if W - 1 < w + dx[i] or w + dx[i] < 0:
                                        continue
                                ans[h + dy[i]][w + dx[i]] += 1
for i in bomb:
        ans[i[0]][i[1]] = "#" 
for i in ans:
        l = map(str, i)
        print("".join(l))

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

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

    int n,x,mod=1e9+7;
    cin>>n>>x;
    vector<int>s(n);
    rep(i,n)cin>>s[i];
    sort(s.begin(),s.end());

    ll dp[n+1][x+1]={0};
    rep(i,x+1)dp[0][i]=i;

    rep(i,n)rep(j,x+1){
        dp[i+1][j]+=i*dp[i][j]%mod;
        dp[i+1][j]%=mod;
        dp[i+1][j]+=dp[i][j%s[i]]%mod;
        dp[i+1][j]%=mod;
    }

    cout<<dp[n][x]<<endl;

    return 0;
}



Measured memory_bytes: 157312
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
int main() {
	int n;
	cin>>n;
	int flag = 1; 
	for(int i=0;i<n;i++){
		ll t;
		cin>>t;
		if(t%2==0){
			if(t%3==0||t%5==0);
			else flag = 0;
		}
	}
	if(flag)cout<<"APPROVED\n";
	else cout<<"DENIED\n";
    return 0;
}



Measured memory_bytes: 256
n = int(input())
T = 0
H = 0
for i in range(n):
    t,h = map(str, input().split())
    if t == h:
        T += 1
        H += 1
    elif t > h:
        T += 3
    else:
        H += 3
print('{} {}'.format(T,H))


Measured memory_bytes: 5592
n = int(input())

nums = []
for i in range(n):
	nums.append(list(map(int, input().split())))
ans = 'No'
count = 0
for num in nums:
	if num[1] == num[0]:
		count += 1
		if count == 3:
			ans = 'Yes'
			break
	else:
		count = 0

print(ans)

Measured memory_bytes: 9184
#include<utility>
#include<iostream>
#include<vector>
#include<numeric>
#include<algorithm>


// priority is lesser.
class union_find
{

	public:

		using value_type = std::int32_t;
		using size_type
			= decltype( std::declval< std::vector < value_type > >().size() );

	private:
		std::vector<int> parent_;
		//std::vector<int> size_;

	public:

		// uf_[0,n_-1]
		union_find( size_type n_ )
			:parent_{}
			//, size_{}
		{
			parent_.resize(n_ ,-1);
//			std::iota( std::begin( parent_ ), std::end( parent_ ), 0 );
		}

	auto root( value_type x )->value_type{
		//std::cout << "root->" << x << "\n";

		const auto p_ = parent_[x];

		return 
			( p_ < 0 ) ? x : parent_[x] = root( p_ );
	}

	//auto root( value_type x )const->value_type{
	//	return 
	//		x == parent_[x]
	//		? x
	//		: root( parent_[x] );
	//}

	//auto croot( value_type x )const{
	//	return root( x );
	//}


	auto size()const{
		return parent_.size();
	}

	auto size( value_type x )->size_type{
		return - parent_[root( x )];
	}

	//auto size( value_type x )const{
	//	return size_[croot( x )];
	//}

	//auto csize( value_type x )const{
	//	return size( x );
	//}

	auto unite( value_type a_, value_type b_ ){

		//std::cout <<"unite-"<< a_ <<" "<< b_ << "\n";

		if( a_ == b_ )
			return;

		// mut : to swap;
		auto ra_ = root( a_ );
		auto rb_ = root( b_ );

		if( ra_ == rb_ )
			return;


		const auto sa_ = size( a_ );
		const auto sb_ = size( b_ );

		//should be ra_ < rb_
		if( sa_ > sb_ )
			std::swap( ra_, rb_ );


		//if( sa_ == sb_ )
		//	++size_[ra_];
		parent_[ra_] += parent_[rb_];

		parent_[rb_] = ra_;

	}

	auto same( value_type a_, value_type b_ ){
		return root( a_ ) == root( b_ );
	}

	auto dump(){
		for( int i{}; i < parent_.size(); ++i )
		{
			std::cout 
				<< ( i + 1 ) << "<-" 
				<<parent_[i]
				<< " |" << size( i ) << "|\n";
		}
	}

	auto answer(){
		return -*std::min_element( std::begin( parent_ ), std::end( parent_ ) );
	}

};

int main(){

	std::uint32_t N, M;
	std::cin >> N >> M;

	union_find uf_{ N };

	int ans_{2};
	for( int i{}; i < M; ++i )
	{
		int A, B;
		std::cin >> A >> B;
		--A; --B;
		
		uf_.unite( A, B );

		//std::cout <<"sa_sb_:"<< uf_.size(A) << " " << uf_.size( B ) << "\n";

		const int t = uf_.size( A );

//		ans_ = std::max( t, ans_ );
	}
	
//	uf_.dump();



	std::cout << uf_.answer() << "\n";

	return 0;
}

Measured memory_bytes: 3700
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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;}

using ll = long long;
using Graph = vector<vector<int>>;

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi L(n*2);
  VIN(L)
  SORT(L);
  REP(i,n*2){
    if(i%2==0) z += L[i];
  }
  OUT(z);
}

Measured memory_bytes: 256
#include<stdio.h>
#define Num 100
int main() {
    int n[Num],x[Num];
    int i,j,k,l;
    int Sum=0;
     
    for(l=0;l<Num;l++){
        scanf("%d %d",&n[l],&x[l]);
    }
    for(l=0;l<Num;l++){
        if(n[l]==0 && x[l]==0){
            break;
        }
        for(i=1;i<n[l]-1;i++)
            for(j=i+1;j<n[l];j++)
                for(k=j+1;k<n[l]+1;k++){
                    if (i+j+k==x[l]){
                        Sum++;
                    }
                }
        printf("%d\n",Sum);
        Sum=0;
    }
}


Measured memory_bytes: 2148
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


ll gcd(ll x,ll y){
  return y==0? x:gcd(y,x%y);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  vint a(N);
  repeat(i,N)cin>>a[i];
  sort(a.begin(),a.end());
  cout << a.back()-a[0]<<endl;
  return 0;
}


Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define frr(i, r, l) for(int i = r; i >= l; --i)
#define fr(i, l, r) for(int i = l; i < r; ++i)
#define forit(it, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
typedef pair<ll, ll> iPair; 
priority_queue< ll, vector <ll> , greater<ll>>pq1,pq2;
#define maxN 1000000000000000000
ll power(ll a,ll b){ll res=1;while(b>0){res*=a;b--;}return res;}
int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t;
    cin>>n>>x>>t;

    ll st=n/x;
    if(n%x!=0)
    st+=1;

    cout<<st*t<<endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> mp;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    int ans = 0;
    for (auto p:mp){
        if(p.second%2) ans++;
    }
    
    cout << ans << endl;
    return 0;
}


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

#define zton(i,n) for(int i=0;i<=n;i++)
#define oneton(i,n) for(int i=1;i<=n;i++)
#define fo(i,n) for(int i=0;i<n;i++)
#define fab(i,a,b) for(int i=a;i<b;i++)
#define loop(i,b,a) for(int i=a;i>=b;i--)
#define dsort(arr,n) sort(arr, arr + n, greater<int>())
#define vsortd(a) sort(a.begin(), a.end(), greater<double>())
#define vsort(a) sort(a.begin(), a.end())
#define ll long long int
#define test int tc;cin>>tc;while(tc--)
#define dbg(x) cout<<#x<<'='<<(x)<<endl;
#define dbg2(x,y) cout<<#x<<'='<<(x)<<endl<<#y<<'='<<(y)<<endl;
#define dbg3(x,y,z) cout<<#x<<'='<<(x)<<endl<<#y<<'='<<(y)<<endl<<#z<<"="<<(z)<<endl;
#define dbg4(x,y,z,w) cout<<#x<<'='<<(x)<<endl<<#y<<'='<<(y)<<endl<<#z<<"="<<(z)<<endl<<#w<<"="<<(w);
#define minheap priority_queue <int, vector<int>, greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define ff first
#define ss second
#define mpr make_pair
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mkv vector<int>
#define allzero(dp) memset(dp,0,sizeof(dp))
#define endl "\n"
#define print(x) cout<<x<<endl;

const int mod=1e9+7;
using namespace std;
bool sortcol( const vector<int>& v1,const vector<int>& v2 ) {return v1[1] < v2[1];}

void fastio()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

bool sortbysecdesc(const pair<ll,ll> &a,const pair<ll,ll> &b){
    if(a.first>b.first)return true;
    if(a.first==b.first)return a.second<b.second;
    return false;
}

ll power(ll x, ll y){
    ll res = 1;x=x%mod;
    while(y>0){
        if(y&1)res=(res*x)%mod;
        y=y>>1;x=(x*x)%mod;}
    return res;
}


void solve()
{
    ll n,d;cin>>n>>d;
    ll cnt=0;
    fo(i,n){
        ll x,y;cin>>x>>y;
        if(x*x+y*y<=d*d)cnt++;
    }
    print(cnt)
}

int main()
{
  //  fastio();
 //   test
    solve();
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
 
using namespace std;
 
int main(){
  string S;
  cin >> S;
  
  string M;
  string N;
  
  if(S.length() == 1 ){
    cout << 0 << endl;
  }else{
    for(int i = 0; i < S.length(); i++){
      if( i % 2 == 0 ){
        M += "0";
        N += "1";
      }else{
        M += "1";
        N += "0";
      }
    }
    
    int cnt1 = 0;
    int cnt2 = 0;
    
    for(int i = 0; i < S.length(); i++){
      if( S[i] != M[i] ) cnt1++;
      if( S[i] != N[i] ) cnt2++;
    }
    
    if( cnt1 < cnt2 ) cout << cnt1 << endl;
    else cout << cnt2 << endl;
    
  }
  return 0;
}

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



int main() {
	string s;
	int H,W,N;
	cin >> H >> W >> N;
	int n = 0;
	int sum = 0;
	if (H >= W) {
		for (int i = 0;i < W;i++) {
			sum += H;
			n++;
			if (sum >= N)break;
		}
	}
	else {
		for (int i = 0;i < H;i++) {
			sum += W;
			n++;
			if (sum >= N)break;
		}
	}
	cout << n << endl;
	
}

Measured memory_bytes: 256
int main(){
  int n,m,a[100000]={},p,ac=0,wa=0;
  char s[2];
  scanf("%d%d",&n,&m);
  for(int i=0;i<m;i++){
    scanf("%d",&p);
    scanf("%s",s);
    if(a[p]<=0&&s[0]=='A'&&s[1]=='C'){
      a[p]=1;
      ac++;
    }else if(a[p]<=0&&s[0]=='W'&&s[1]=='A'){
      a[p]-=1;
      wa++;
    }
  }
  for(int i=1;i<=n;i++){
    if(a[i]<0) wa+=a[i];
  }
  printf("%d %d\n",ac,wa);
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
// #include <cassert>
#include <vector>
#include <algorithm>
#include <climits>

// #include <stack>
// #include <queue>
// #include <deque>
// #include <set>
// #include <map>
// #include <string>
// #include <unordered_set>
// #include <unordered_map>

// #include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;
typedef long long ll;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef pair<int,long> pil;
typedef pair<long,int> pli;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;

#define emplace_back pb
const char el = '\n';
const ll M = 1000000001;

/*
Edge cases:


*/

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

    int x,y,a,b,c; cin>>x>>y>>a>>b>>c; cin.ignore();

    vector<ll> p(a), q(b), r(c);
    for (int i=0; i<a; ++i) {
        cin>>p[i];
    }
    for (int i = 0; i<b; ++i) {
        cin>>q[i];
    }
    for (int i =0; i<c; ++i) {
        cin>>r[i];
    }

    sort(p.begin(),p.end());
    sort(q.begin(),q.end());
    sort(r.begin(),r.end());

    int pi, qj;
    ll beforesum=0;
    for (int ct = 0, i=a-1; ct<x; ++ct, --i) {
        beforesum += p[i];
    }
    for (int ct = 0, i=b-1; ct<y; ++ct, --i) {
        beforesum += q[i];
    }


    pi = a-x;
    qj = b-y;
    int rk = c-1;
    // cout<<"started wtih thresholds "<<pi<<" "<<qj<<" "<<rk<<el;
    ll newsum=beforesum;
    while (true) {
        bool pgood = (pi<a && rk>=0);
        bool qgood = (qj<b && rk>=0);
        if (pgood && qgood) {
            if (r[rk]>p[pi] && r[rk]>q[qj]) {
                if (p[pi]<=q[qj]) {
            newsum -= p[pi];
            newsum += r[rk];
            ++pi;
            --rk;
                } else {
            newsum -= q[qj];
            newsum += r[rk];
            ++qj;
            --rk;
                }
            } else if (r[rk]>p[pi]) {
            newsum -= p[pi];
            newsum += r[rk];
            ++pi;
            --rk;
            } else if (r[rk]>q[qj]) {
            newsum -= q[qj];
            newsum += r[rk];
            ++qj;
            --rk;
            } else {
                break;
            }
        } else if (pgood) {
            if (r[rk]>p[pi]) {
            newsum -= p[pi];
            newsum += r[rk];
            ++pi;
            --rk;
            } else {
                break;
            }
        } else if (qgood) {
            if (r[rk]>q[qj]) {
            newsum -= q[qj];
            newsum += r[rk];
            ++qj;
            --rk;
            } else {
                break;
            }
        } else {
            break;
        }

    }

    cout<<newsum<<el;




}

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

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& vec) {
    out << "[";
    for (int x : vec) out << x << ", ";
    out << "]";
    return out;
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
    #define dbg_var(x) cerr << #x << ": " << x << endl;
#endif

int n, m;
bool aaa[777][777];
vector<int> adj[777];

int color[777];
int num = 0;
int a[777], b[777];

bool mp[777][2];

int counta[3];
void visit(int v, int c){
    color[v] = c;
    counta[c]++;
    for(int u:adj[v]) if(color[u] == 0) visit(u, 3-c);
        else if(color[u] == c){cout << -1 << '\n'; exit(0);}
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> m;
    for(int i=1; i<=m; i++){
        int a, b; cin >> a >> b;
        aaa[a][b] = aaa[b][a] = true;
    }
    for(int i=1; i<=n; i++) aaa[i][i] = true;
    for(int a=1; a<=n; a++) for(int b=1; b<=n; b++) if(not aaa[a][b]) adj[a].push_back(b);
    
    for(int i=1; i<=n; i++) if(color[i] == 0){
        counta[1] = counta[2] = 0;
        visit(i, 1);
        a[num] = counta[1];
        b[num] = counta[2];
        num++;
    }
    
    mp[0][0] = true;
    for(int x=1; x<=n; x++) mp[x][0] = false;
    int la = 0;
    for(int i=0; i<num; i++){
        int mi = i % 2;
        int ni = 1 - mi;
        for(int x=0; x<=n; x++) mp[x][ni] = (a[i]<=x && mp[x-a[i]][mi]) || (b[i]<=x && mp[x-b[i]][mi]);
        la = ni;
    }
    
    int ans = n * n;
    for(int x=0; x<=n; x++) if(mp[x][la]){
        int y = n - x;
        ans = min(ans, x*(x-1)/2 + y*(y-1)/2);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    rep(i, 3) {
        if (S[i] == S[i + 1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;

    return 0;
}


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

int main() {
    string s;
    cin >> s;
    if (s.at(0) != 'A') {
        cout << "WA" << endl;
        return 0;
    }
    int cnt = 0;
    int indexC = -1;
    for(int i = 0; i < (int)s.size() - 3; i++)
    {
        if (s.at(2 + i) == 'C') { 
            cnt++;
            indexC = 2 + i;
        }
    }
    if (cnt != 1) {
        cout << "WA" << endl;
        return 0;
    }
    for(int i = 0; i < (int)s.size(); i++)
    {
        if (i == 0 || i == indexC) continue;
        if (!((int)'a' <= s.at(i) && s.at(i) <=(int)'z')) {
            cout << "WA" << endl;
            return 0;
        }
    }
    cout << "AC" << endl;
}

Measured memory_bytes: 256
/* B - ... (Triple Dots) */

#include <stdio.h>
#include <string.h>

int main(void){
  char S[100], ans[100];
  int K, i;
  scanf("%d", &K);
  scanf("%s", S);
  if(strlen(S) <= K){
    puts(S);
  }else{
    for(i = 0; i < K; i++){
      putchar(S[i]);
      if(i == K - 1){
        puts("...");
      }
    }
  }
}


Measured memory_bytes: 1648
n = gets.to_i
a = n.times.map{gets.to_i}
mx = a.max
c = a.count(mx)
b = 0
if c == 1
    b = a.sort[-2]
end
n.times do |i|
    if a[i] == mx && c == 1
        puts b
    else
        puts mx
    end
end

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

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

    int slope = 6;
    int ans = 0;
    int dT = 1 << 30;
    for(int i=0; i<N; i++){
        int t = 1000*T - H[i]*slope;
        if(abs(t - 1000*A) < dT){
            dT = abs(t - 1000*A);
            ans = i + 1;
        }
    }
    cout << ans << endl;
}


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

#define fto(i, a, b) for(int i = a; i <= b; ++i)
#define fdto(i, a, b) for(int i = a; i >= b; --i)
#define ff first
#define ss second
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define pb push_back
#define oo 1000000007
#define OO 1000000000000000007

using namespace std;

int main() {
   
    int n, ans = 0;
    scanf("%d", &n);
    fto(i, 1, n) {
        int x, y;
        scanf("%d%d", &x, &y);
        ans += y-x+1;
    }
    printf("%d\n", ans);
    return 0;
}
///12436


Measured memory_bytes: 256
from math import ceil,log2

def main():
    H = int(input())
    lg = log2(H)
    ans = 0
    cnt = 0
    while H > 0:
        ans += 2**cnt
        cnt += 1
        H = H // 2
    print(ans)
    return
if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
def solve():
    N = int(input())
    A = list(map(int,input().split()))

    dp = [-float('inf')] * N
    dp[0] = 1000

    for i in range(1,N):
        dp[i] = dp[i-1]
        for j in range(i):
            n_stock = dp[j] // A[j]
            n_money = n_stock * A[i] + dp[j] % A[j]
            dp[i] = max(dp[i], n_money)
    
    print(dp[-1])
        
if __name__ == '__main__':
    solve()

Measured memory_bytes: 65264
using System;

namespace myApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] arr = input.Split(' ');
            int a = int.Parse(arr[0]);
            int b = int.Parse(arr[1]);
            if ( ( a * b ) % 2 == 0)
                Console.WriteLine("Even");
            else
                Console.WriteLine("Odd");
            
        }
    }
}


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

const int32_t MAX_N = 100;
const int32_t MAX_K = 1e5;
const int32_t MOD = 1e9 + 7;

int32_t a[MAX_N + 5], dp[MAX_N + 5][MAX_K + 5], prefSums[MAX_N + 5][MAX_K + 5];

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

	int32_t n, k;
	std::cin >> n >> k;

	for(int32_t i = 0; i < n; i++) {
		std::cin >> a[i];
	}

	if(n == 1) {
		std::cout << (a[0] == k ? 1 : 0) << '\n';
		return 0;
	}

	for(int32_t i = k; i >= 0; i--) {
		if(k - i <= a[0]) {
			dp[1][i] = 1;
		}
		
		prefSums[1][i] = ((int64_t) prefSums[1][i + 1] + dp[1][i]) % MOD;
	}
	
	for(int32_t i = 2; i < n; i++) { 
		for(int32_t j = k; j >= 0; j--) {
			dp[i][j] = prefSums[i - 1][j] - prefSums[i - 1][std::min(j + 1 + a[i - 1], k + 1)]; 
			if(dp[i][j] < 0) {
				dp[i][j] += MOD;
			}
			
			prefSums[i][j] = ((int64_t) prefSums[i][j + 1] + dp[i][j]) % MOD;
		}
	}
	
	int32_t ans = 0;
	for(int32_t i = 0; i <= a[n - 1]; i++) {
		ans = ((int64_t) ans + dp[n - 1][i]) % MOD;
	}
	std::cout << ans << '\n';
}



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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int A, B;
    cin >> A >> B;

    if ((A + B) % 2 == 0) {
        cout << ((A + B) / 2) << endl;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {
  int n; cin >> n;
  vector<long long> a(n);
  long double tmp = 1.0;
  long long ans = 1;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    tmp *= a[i];
    ans *= a[i];
  }
  if (tmp > 1e18) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}

// EOF

Measured memory_bytes: 4040
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n,q; cin >> n >> q;
    string s;cin >> s;
    vector<int> t(n,0);
    rep(i,n-1) {
        t[i+1] = t[i] + (s[i] == 'A' and s[i+1] == 'C' ? 1:0);
    }
    rep(i,q){
        int l,r; cin >> l >> r;
        l--;r--;
        cout << t[r]-t[l] << endl;
    }
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        if (A <= 8 && B <= 8) {
            System.out.println("Yay!");
        } else {
            System.out.println(":(");
        }
        sc.close();
    }
}

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


	string n; cin >> n;

	long long ans = 0;

	for(int i = 0;i<n.size();i++)
	{
		ans = (ans + n[i] - '0')%9;
	}

	if(ans == 0) cout << "Yes" << endl;
	else cout <<"No" << endl;
		
		
  return 0; 
}

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

using namespace std;

typedef long long ll;

ll ans = 1e9;
ll maxx, minn;

ll cnt(ll h, ll w){
    for(int i = 1; i < h ; i++){
            if(!(w%2)) {
                maxx = max(i*w , (w*(h-i))/2);
                minn = min(i*w , (w*(h-i))/2);

            }
            else {
                maxx = max(i*w , max((w/2)*(h-i), (w/2 + 1)*(h-i)));
                minn = min(i*w , min((w/2)*(h-i), (w/2 + 1)*(h-i)));
            }
            ans = min(ans , maxx-minn);

            if(!((h-i)%2)){
                maxx = max(i*w , (w*(h-i))/2);
                minn = min(i*w , (w*(h-i))/2);
            }
            else {
                maxx = max(i*w , max(((h-i)/2)*w, ((h-i)/2 +1)*w));
                minn = min(i*w , min(((h-i)/2)*w, ((h-i)/2 +1)*w));
            }
            ans = min(ans , maxx-minn);
        }
}

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

    ll h, w;
    cin >> h >> w;
    if(!(h%3) || !(w%3))cout << 0;
    else{
        cnt(h,w);cnt(w,h);
        cout << ans;
    }
    return 0;
}


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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  ll ans = 0;
  ll right = 0;
  ll tot = 0;  // AND 和
  rep(left, N) {
    while (right < N && (tot ^ A[right]) == (tot + A[right])) {
      tot += A[right];
      right++;
    }

    ans += (right - left);

    if (right == left)
      right++;
    else
      tot -= A[left];  // A[left] を削除 (tot ^= a[left] でも OK)
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int,int> P;
const int INF=(int)1e9;
const int MOD=(int)1e9+7;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

int main(){
 set<int>set;
 map<int,int>map;

 int N,K;
 cin>>N>>K;
 int a[200005];
 int cont=0;
 for(int t=0;t<N;t++){
   cin>>a[t];
   if(set.find(a[t])==set.end())cont++;
   set.insert(a[t]);
   map[a[t]]++;
 }

 priority_queue<int>que;
 for(int t=0;t<N;t++){
   if(set.find(a[t])==set.end())continue;
   que.push(-map[a[t]]);
   set.erase(a[t]);
 }

 int x=cont-K;
 int ans=0;
 for(int t=0;t<x;t++){
   ans-=que.top();
   que.pop();
 }

 cout<<ans<<endl;
 return 0;
}


Measured memory_bytes: 20988
#include<bits/stdc++.h>
using namespace std;
double eps=1e-6;
int main()
{
	int n;
	int x,y;
	long long a;
	double b;
	double m;
	int sum=0;
	scanf("%d%lf",&n,&m);
	while(n--)
	{
		scanf("%d%d",&x,&y);
		a=pow(x,2)+pow(y,2);
		b=sqrt(a);
		
		if(m>=b)
		{
			sum++;
		}
		
	}
	printf("%d\n",sum);
}

Measured memory_bytes: 3844
bingo = False
A = []
for _ in range(3):
  a = list(map(int, input().split()))
  A.append(a)
  
N = int(input())

for _ in range(N):
  b = int(input())

  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        A[i][j] = 0

if sum(A[0]) == 0 or sum(A[1]) == 0 or sum(A[2]) == 0 or sum([A[0][0], A[1][0], A[2][0]]) == 0 or sum([A[0][1], A[1][1], A[2][1]]) == 0 or sum([A[0][2], A[1][2], A[2][2]]) == 0 or sum([A[0][0], A[1][1], A[2][2]]) == 0 or sum([A[2][0], A[1][1], A[0][2]]) == 0:
  bingo = True

if bingo:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 38256
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

signed main(){

    int A1,A2,A3;
    
    cin>>A1>>A2>>A3;
    
    cout<<max(A1,max(A2,A3))-min(A1,min(A2,A3))<<endl;
}



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

int main() {
    int n;

    cin >> n;

    int v[n];
    int c[n];

    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> c[i];
    }
    
    int diff[n];
    
    for(int i = 0; i < n; i++) {
        diff[i] = v[i] - c[i];
    }

    int ans = 0;

    for(int i = 0; i < n; i++) {
        if(diff[i] >= 0) ans += diff[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,ans,ma;
char m;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>m;
        if(m=='I') ans++;
        else ans--;
        if(ans>ma) ma=ans;
    }
    cout<<ma<<endl;
    return 0;
}

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

using namespace std;

#define ll long long

ll cnt = 0;

void compute (ll k, ll N) {
    ll x = N;
    while (x % k == 0) {
        x /= k;
    }
    if (x % k == 1) {
        cnt++;
    }
}

int main () {
    ll n;
    cin >> n;
    ll limit = sqrt (n - 1);
    for (int i = 1; i <= limit; i++) {
        if ((n - 1) % i == 0) {
            if (i > 1) cnt++;
            if ((n - 1) / i != i) cnt++;
        }
    }
    
    limit = sqrt (n);
    for (int i = 1; i <= limit; i++) {
        if (n % i == 0) {
            if (i > 1) compute (i, n);
            if (n / i != i) compute (n / i, n);
        }
    }
    printf ("%lld\n", cnt);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	string s; cin>>s;
	if(s[0]==s[1] && s[1]==s[2]) cout<<"Yes"<<endl;
	else if((s[1]==s[2] && s[2]==s[3])) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int[] array = new int[a];
        int count = 0;

        for(int i = 0; i < a; i++){
            array[i] = sc.nextInt();
            if(!(array[i] == (i + 1))){
                count++;
            }
        }
        if(count <= 2){
            System.out.print("YES");
        }else{
            System.out.print("NO");
        }
	}
}

Measured memory_bytes: 23764
N = int(input())
A = list(map(int, input().split()))
stock = 0
money = 1000

for i in range(N-1):
    if A[i] < A[i+1]:
        s, money =  divmod(money, A[i])
        stock += s
    elif A[i] == A[i+1]:
        money += stock * A[i]
        stock = 0
    elif stock > 0:
        money += stock * A[i]
        stock = 0
if stock > 0:
    money += stock * A[N-1]
print(money)

Measured memory_bytes: 9072