akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int size = sc.nextInt();
		sc.nextLine();
		char[] arr = sc.nextLine().toCharArray();
		int count = 0;
		char temp = arr[0];
		for(int i = 1;i<size;i++) {
			if(arr[i]!=temp) {
				count++;
				temp = arr[i];
			}
		}
		System.out.println(count+1);

	}

}


Measured memory_bytes: 27780
#include<stdio.h>
int main()
{
    int i,s,h,c,d,k,j,l,n;
int card[4][13]={0};
    char a,b;
    scanf("%d",&l);
    while(l--)
    {
getchar();
        scanf("%c",&a);
        scanf("%d",&n);
        if(a=='S')
        {
            card[0][n-1]=1;

        };
        if(a=='H')
        {

            card[1][n-1]=1;

        };
        if(a=='C')
        {


            card[2][n-1]=1;

        };
        if(a=='D')
        {

            card[3][n-1]=1;

        };

    }
for(i=0;i<4;i++)
{
    if(i==0)b='S';
    if(i==1)b='H';
    if(i==2)b='C';
    if(i==3)b='D';
    for( j=0;j<13;j++)
    {
        if(card[i][j]==0)
      {
          printf("%c %d\n",b,j+1);
      }
    }

}
}



Measured memory_bytes: 2040
A = [list(map(int, input().split())) for _ in range(3)]
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
flag = False
if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0 or A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
  flag = True
  
for i in range(3):
  tate = True
  yoko = True
  for j in range(3):
    if A[i][j] != 0:
      yoko = False
    if A[j][i] != 0:
      tate = False
  flag = flag or tate or yoko
print("Yes" if flag else "No")

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+2;
int sum[N],sum1[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s,t;
	int q,i,j,k,l;
	cin>>s>>t>>q;
	s=' '+s;
	t=' '+t;
	for(i=1;i<s.size();i++){
		sum[i]=sum[i-1]+(int)(s[i]-'A'+1);
	}
	for(i=1;i<t.size();i++){
		sum1[i]=sum1[i-1]+(int)(t[i]-'A'+1);
	}
	while(q--){
		cin>>i>>j>>k>>l;
		if((sum[j]-sum[i-1])%3==(sum1[l]-sum1[k-1])%3){
			cout<<"YES\n";
		}
		else{
			cout<<"NO\n";
		}
	}
}

Measured memory_bytes: 1644
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
a.sort(reverse=True)
b = list(set(a))
b.sort(reverse=True)
c = [1 for _ in range(len(b))]
j = 0
for i in range(n - 1):
    if a[i] == a[i + 1]:
        c[j] += 1
    else:
        j += 1
ans = []
for i in range(len(b)):
    if c[i] >= 2:
        ans.append(b[i])
    if c[i] >= 4:
        ans.append(b[i])
if len(ans) >= 2:
    print(ans[0] * ans[1])
else:
    print(0)

Measured memory_bytes: 16572
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  map<int,int> m;
  rep(i,N){
    int a;
    cin >> a;
    m[a]++;
  }
  vector<int> ret(N+1,0);
  ret[1] = N;

  int M = m.size();
  REP(i,M+1,ret.size()) ret[i] = 0;

  queue<pair<int,int>> que;
  FOR(it,m){
    que.push(make_pair(it->first,it->second));
  }
  vector<int> w;
  while(true){
    queue<pair<int,int>> tmp;
    int cnt = 0;
    rep(i,M){
      if(que.empty()) break;
      pair<int,int> t = que.front(); que.pop();
      cnt++;
      t.second--;
      if(t.second > 0) tmp.push(t);
    }

    w.push_back(cnt);
    if(tmp.empty()) break;
    swap(que,tmp);
  }

  int j = 0;
  int stock = 0;
  for(int i=M; i>1; i--){
    while(j<w.size()){
      if(w[j] + stock >= i){
        stock -= i - w[j];
        j++;
      }else{
        break;
      }
    }
    while(stock >= i){
      stock -= i;
      j++;
    }
    stock += j;
    ret[i] = j;
  }

  REP(i,1,N+1){
    cout << ret[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 17920
#include<stdio.h>
#include<string.h>
int main(void)
{
	int  sx, sy, x1, y1, x2, y2, count1 = 0, count2 = 0, i, n, t;
	scanf("%d%d%d%d", &x1, &y1, &x2, &y2);

	sx = x2 - x1; sy = y2 - y1;

	
	for (i = 0; i < sy; i++)
	{
		printf("U");
		count1++;
	}
	for (i = 0; i < sx; i++)
	{
		printf("R");
		count2++;
	}
	i = 0;
	while (count1 != i)
	{
		printf("D");
		i++;
	}
	i = 0;
	while (count2 != i)
	{
		printf("L");
		i++;
	}


	printf("L");

	for (i = 0; i < sy + 1; i++)
	{
		printf("U");
	}
	for (i = 0; i < sx + 1; i++)
	{
		printf("R");
	}
	printf("D");


	printf("R");
	i = 0;
	while (sy + 1 != i)
	{
		printf("D");
		i++;
	}
	i = 0;
	while (sx + 1 != i)
	{
		printf("L");
		i++;
	}
	printf("U");



return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}


int main() {
	int a, b; cin >> a;
	if (a < 1200) cout << "ABC";
	else if (a < 2800) cout << "ARC";
	else cout << "AGC";

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

template<uint32_t mod>
struct ModInt{
    uint32_t a;
    ModInt& s(uint32_t vv){
        a=vv<mod?vv:vv-mod;
        return *this;
    }
 
    ModInt(int64_t x=0){s(x%mod+mod);}
 
    ModInt& operator+=(const ModInt &x){return s(a+x.a);}
    ModInt& operator-=(const ModInt &x){return s(a+mod-x.a);}
    ModInt& operator*=(const ModInt &x){
        a=uint64_t(a)*x.a%mod;
        return *this;
    }
    ModInt& operator/=(const ModInt &x){
        *this*=x.inv();
        return *this;
    }
 
    ModInt operator+(const ModInt &x)const{return ModInt(*this)+=x;}
    ModInt operator-(const ModInt &x)const{return ModInt(*this)-=x;}
    ModInt operator*(const ModInt &x)const{return ModInt(*this)*=x;}
    ModInt operator/(const ModInt &x)const{return ModInt(*this)/=x;}
    bool operator==(const ModInt &x)const{return a==x.a;}
    bool operator!=(const ModInt &x)const{return a!=x.a;}
    bool operator<(const ModInt &x)const{return a<x.a;}
 
    ModInt operator-()const{return ModInt()-*this;}
    ModInt pow(int64_t n)const{
        ModInt res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
 
    ModInt inv()const{return pow(mod-2);}
};
 
template<uint32_t mod>
istream& operator>>(istream& in,ModInt<mod>& a){
    return (in>>a.a);
}
template<uint32_t mod>
ostream& operator<<(ostream& out,const ModInt<mod>& a){
    return (out<<a.a);
}
using mint=ModInt<MOD>;

int main(void)
{
    int N;
    cin >> N;
    vector<int> C(N);
    for (int i = 0; i < N; i++) {
        cin >> C[i];
    }
    vector<int> c(1, C[0]);
    REP(i, N-1){
        if(C[i] != C[i+1]) c.pb(C[i+1]);
    }

    int n = c.size();

    vector<mint> dp(n+1);
    dp[0] = 1;
    map<int, mint> sm;

    REP(i, n){
        dp[i+1] = sm[c[i]] + dp[i];
        // sm[c[i]] += dp[i];
        sm[c[i]] = dp[i+1];
    }
    pr(dp[n]);
}

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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> hs(h, 0), ws(w, 0);
    set<P> s;
    rep(i, n) {
        int r, c;
        cin >> r >> c;
        r--; c--;
        hs[r]++;
        ws[c]++;
        s.emplace(r, c);
    }

    int mh = 0, mw = 0;
    rep(i, h) mh = max(mh, hs[i]);
    rep(i, w) mw = max(mw, ws[i]);
    vector<int> is, js;
    rep(i, h) if (mh == hs[i]) is.push_back(i);
    rep(i, w) if (mw == ws[i]) js.push_back(i);
    for (int i : is) for (int j : js) {
        if (s.count(P(i, j))) continue;
        cout << mh + mw << endl;
        return 0;
    }
    cout << mh + mw - 1 << endl;
    return 0;
}


Measured memory_bytes: 23872
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<array>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


template <typename T>
bool chmax(T & a, const T & b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <typename T>
bool chmin(T & a, const T & b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}


#define ARRAY_MAX 100005
const int INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

int dx4[4] = { 1,0,0,-1 };
int dy4[4] = { 0,1,-1,0 };
int dx2[2] = { 1,0 };
int dy2[2] = { 0,1 };

/******************************************************************************************/
typedef tuple<int,int,int> tpl;

template <typename T> bool next_combination(const T first, const T last, int k) {
    const T subset = first + k;
    // empty container | k = 0 | k == n 
    if (first == last || first == subset || last == subset) {
        return false;
    }
    T src = subset;
    while (first != src) {
        src--;
        if (*src < *(last - 1)) {
            T dest = subset;
            while (*src >= *dest) {
                dest++;
            }
            iter_swap(src, dest);
            rotate(src + 1, dest + 1, last);
            rotate(subset, subset + (last - dest) - 1, last);
            return true;
        }
    }
    // restore
    rotate(first, subset, last);
    return false;
}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	string s;
    cin >> s;
	int n=s.size()+1;
	vector<ll> v(n,0);
	for(int i = 0;i < n-1;i++){
		if(s[i]=='<'){
            chmax(v[i+1],v[i]+1);
        }
    }
	for(int i = n-1;i >= 0;i--){
        if(s[i]=='>'){
            chmax(v[i],v[i+1]+1);
        }
    }

    ll ans = 0;
    for(int i = 0;i < n;i++){
        ans += v[i];
    }
    cout << ans << endl;

	return 0;
}






Measured memory_bytes: 4764
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace C_ABC154
{
    class MainClass
    {

        static long[] n,s;

        public static void Main(string[] args)
        {

            n = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);
            s = Array.ConvertAll(ReadLine().Split().ToArray(), long.Parse);

            var pf = s.ToList();
            var pfgrp = pf.GroupBy(a => a);
            if(pf.Count()==pfgrp.Count()){
                WriteLine("YES");
            }else{
                WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 53060
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    int ans = 0;
    repf(i,1,n+1) {
        string s = to_string(i);
        if (s.size()%2==1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    intl a[n-1];
    cin(i,a);
    intl b[n];
    m0(b);
    rep(i,n-1)b[a[i]-1]++;
    rep(i,n){
        cout << b[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 6728
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  lint n; cin >> n;
  V<> a(3); for (auto&& e : a) cin >> e;
  V<> b(3); for (auto&& e : b) cin >> e;
  for (int _ = 0; _ < 2; ++_) {
    V<lint> dp(n + 1);
    iota(begin(dp), end(dp), 0);
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < 3; ++j) {
        if (i + a[j] <= n) dp[i + a[j]] = max(dp[i + a[j]], dp[i] + b[j]);
      }
    }
    n = dp[n];
    swap(a, b);
  }
  cout << n << '\n';
}

Measured memory_bytes: 195584
#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<cmath>
#include<climits>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
    int f=1,x=0;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    return x*f;
}
#define MAXN 1000
#define INF 0x3f3f3f3f
int n,len,x[MAXN+5],y[MAXN+5],d[35];
void Print(int X,int Y){//贪心策略
	for(int i=1;i<=len;i++){
		if(abs(X)>abs(Y)){
			if(X>0) putchar('R'),X-=d[i];
			else putchar('L'),X+=d[i];
		}
		else{
			if(Y>0) putchar('U'),Y-=d[i];
			else putchar('D'),Y+=d[i];
		}
	}
	puts("");
	return ;
}
int main(){
	bool f[2]={0};
	n=read();
	for(int i=1;i<=n;i++)
		x[i]=read(),y[i]=read(),f[(x[i]+y[i])%2]=1;
	if(f[0]&&f[1]){
		puts("-1");
		return 0;
	}
	for(int i=30;i+1;i--)
		d[++len]=(1<<i);
	if(f[0]) d[++len]=1;
	printf("%d\n",len);
	for(int i=1;i<len;i++)
		printf("%d ",d[i]);
	printf("%d\n",d[len]);
	for(int i=1;i<=n;i++)
		Print(x[i],y[i]);
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
int log_p_MAX = 32;
int main()
{
  int n,i;
  int s[log_p_MAX];
  cin >> n;
  s[0]=0;
  for(i=0;n!=0;i++){
    s[i]=abs(n%2);
    n=(n-s[i])/(-2);
  }
  i=max(i-1,0);
  for(;i>=0;i--)
    cout << s[i];
  cout << endl;
  return 0;
}

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

int main(){
    long long r,g,b,n;
    cin>>r>>g>>b>>n;
    long long ans=0;
    
    for(int i=0;i*r<=n;i++)for(int j=0;j*g<=n;j++){
        int k=n-i*r-j*g;
        if(k<0 || k%b) continue;
        ans++;
        //cerr<<ans<<" "<<i<<" "<<j<<" "<<k<<endl;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100

void visit(int);
void vi(int);

int n,d[N+1],cnt=0,adj[N+1][N+1],count;

int main()
{
  int i,j,u,k,v;

  scanf("%d",&n);

  for(i = 0; i <= n; i++){
    d[i] = 99;
    for(j = 0; j <= n; j++){
      adj[i][j] = 0;
    }
  }
  
  for(i = 0; i < n; i++){
    scanf("%d %d",&u,&k);
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      adj[u][v] = 1;
    }
  }
  visit(1);

  for(i = 1; i <= n; i++){
    if(d[i] == 99)d[i] = -1;
    printf("%d %d\n",i,d[i]);
  }

  return 0;
}
    
void visit(int u){
  int i;
  
  d[u] = cnt;

  while(1){
    if(u == n+1)break;
  //for(i = 1; i <= n; i++){
  //if(adj[u][i] == 1){
  //if(d[i] > cnt){
  //cnt++;
  //visit(i);
  //cnt--;
    for(i = 1; i <= n; i++){
      if(adj[u][i] == 1){
	if(d[i] > cnt+1){
	  d[i] = cnt+1;
	  count = d[i];
	  vi(i);
	}
      }
    }
    u++;
    cnt = d[u];
    if(d[u] ==99){
      while(1){
	u++;
	if(u == n+1)break;
	if(d[u] < 99){
	  cnt = d[u];
	  break;
	}
      }
    }
  }
  
}

void vi(int u){
  int i;
  for(i = 1; i <= n; i++){
    if(adj[u][i] == 1){
      if(d[i] > count+1)
	d[i] = count+1;
    }
  }
}



Measured memory_bytes: 2148
from operator import itemgetter

N = int(input())
W = [list(map(int,input().split())) for i in range(N)]
W.sort(key=itemgetter(1))
time = W[0][0]
if time > W[0][1]:
    print('No')
    exit()
else:
    for i in range(1, N):
        w = W[i]
        time = time + w[0]
        if time > w[1]:
            print('No')
            exit()
print('Yes')


Measured memory_bytes: 53732
#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() {
  int n, x, t;
  cin >> n >> x >> t;
  int cnt = (n - 1) / x;
  cout << (cnt + 1) * t << endl;
  return 0;
}


Measured memory_bytes: 3628
/**
 *    author:  tourist
 *    created: 20.11.2019 13:37:49       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<vector<int>> b(h, vector<int>(w));
  int ptr = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      while (a[ptr] == 0) ++ptr;
      --a[ptr];
      b[i][i % 2 == 0 ? j : w - 1 - j] = ptr + 1;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) cout << b[i][j] << " ";
    cout << '\n';
  }
  return 0;
}


Measured memory_bytes: 384
// Problem : B - Judge Status Summary
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Delete the dynamically allocated memory

#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define pb              push_back
#define pr              pair<long long,long long>
#define mp(a,b)         make_pair(a,b)
#define vr              vector<long long>
#define mod1            1000000007
#define mod2            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define fill(a,b)       memset(a, b, sizeof(a))
#define mk(arr,n,type)  type *arr=new type[n];
#define ll              long long
#define ld	            long double
#define w(x)            int x; cin>>x; while(x--)
ll power(ll base, ll exp) {
    ll res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base);
       base=(base*base);
       exp/=2;
    }
    return res;
}
int main()
{
	ll n;
	cin>>n;
	ll ac=0;
	ll wa=0;
	ll tle=0;
	ll re=0;
	for(ll i=0;i<n;i++){
		string s;
		cin>>s;
		if(s.compare("AC")==0){
			ac++;
		}else if(s.compare("WA")==0){
			wa++;
		}else if(s.compare("TLE")==0){
			tle++;
		}else if(s.compare("RE")==0){
			re++;
		}
		}
		cout<<"AC x "<<ac<<"\n";
		cout<<"WA x "<<wa<<"\n";
		cout<<"TLE x "<<tle<<"\n";
		cout<<"RE x "<<re<<"\n";
	return 0;
	}

Measured memory_bytes: 3632
string1 = input()
string2 = input()

n, m = len(string1), len(string2)
best = float("inf")
for i in range(n - m + 1):
  current = string1[i:i+m]
  differences = 0
  for i in range(m):
    if current[i] != string2[i]:
      differences += 1
  best = min(differences, best)

if best == float("inf"):
  print(0)
else:
  print(best)

Measured memory_bytes: 9028
// rand_09.txt, rand_10.txt, rand_24.txt, rand_37.txt
// rand_13.txt, rand_14.txt, rand_25.txt, rand_26.txt の WA回避のためロジック修正.
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){

    // 1. 入力情報.
    int N, A = 0, B = 0, AB = 0, ans = 0;
    scanf("%d", &N);
    rep(i, N){
        char c[22];
        scanf("%s", c);
        int l = strlen(c);
        rep(j, l - 1) if(c[j] == 'A' && c[j + 1] == 'B') ans++;
        
        // 'A' で 終わる 文字列 の 個数.
        if(c[l - 1] == 'A' && c[0] != 'B') A++;
        
        // 'B' から 始まる 文字列 の 個数.
        if(c[l - 1] != 'A' && c[0] == 'B') B++;
        
        // 'A' で 終わり, 'B' から 始まる 文字列 の 個数.
        if(c[l - 1] == 'A' && c[0] == 'B') AB++;
    }
    
    // 2. 文字列 "AB" の 個数 を カウント.
    if(A > B)  ans += B + AB;
    if(A < B)  ans += A + AB;
    if(A == B) ans += A + AB - 1 * (AB > 0 && A == 0);
    // printf("A=%d B=%d AB=%d\n", A, B, AB);
    
    // 3. 出力.
    printf("%d\n", ans);
    return 0;
    
}

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

using namespace std;

int main() {
	int n; cin >> n;
	string s; cin >> s;
	char last = s[0];
	int cnt = 0;
	vector <int> vec;
	for (auto c: s) {
		if (c == last) {
			cnt++;
		} else {
			vec.push_back(cnt);
			cnt = 1;
			last = c;
		}
	}

	vec.push_back(cnt);
	cout << vec.size() << endl;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
const int N=2e5+7;
int a[N];
int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int n; cin>>n;
	int cnt=0;
	int ans=0;
	for(int i=1; i<=n; i++) {
		cin>>a[i];
	}

	int j=1;
	while(j<=n) {
		if(a[j]==(cnt+1)) {
			cnt++;
		}
		else{
			ans++;
		}
		j++;
	}
	if(ans==n) {
		cout<< -1<<endl;
	}
	else{
		cout<<ans<<endl;
	}

	return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PGC
{
	class Program
	{
		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());
			var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

			var count = 0;
			for (int i = 0; i < N; i++)
			{
				var minIndex = i;
				for (int j = i; j < N; j++)
				{
					if (A[j] < A[minIndex])
					{
						minIndex = j;
					}
				}

				if (i != minIndex)
				{
					var tmp = A[i];
					A[i] = A[minIndex];
					A[minIndex] = tmp;
					count++;
				}
			}

			System.Console.WriteLine(string.Join(" ", A));
			System.Console.WriteLine(count);
		}
	}
}



Measured memory_bytes: 18264
N=gets.to_i

ret = []
if N.even?
    n = N+1
else
    n = N
end

1.upto(N) do |i|
    (i+1).upto(N) do |j|
        ret << [i,j] if i + j != n
    end
end

puts ret.length
puts ret.map {|a| a.join(' ')}

Measured memory_bytes: 14928
#include <iostream>
using namespace std;
int main(void){
    
    int counter = 0;
    string s;
    
    cin >> s;
    
    for(int i = 0; i < 3; i++){
        
        if(s[i] == '1') counter++;
        
    }
    
    cout << counter << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
from sys import stdin
import heapq
n, m = map(int, stdin.readline().rstrip().split())
ary = list(map(int, stdin.readline().rstrip().split()))

def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)


def _heappop_max(heap):
    """Maxheap version of a heappop."""
    lastelt = heap.pop()    # raises appropriate IndexError if heap is empty
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt


heapq._heapify_max(ary)

for i in range(m):
    temp = _heappop_max(ary) // 2
    _heappush_max(ary, temp)

res = sum([heapq.heappop(ary) for _ in range(n)])
print(res)

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

int main(){
    int n,k;
    cin>>n>>k;
    int h[n];
    int sum=0;
    for(int i=0;i<n;i++) cin>>h[i];
    for(int i=0;i<n;i++) {
        if (h[i] >= k) sum++;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    int day,month,days;
    while(1){
        scanf("%d %d",&month ,&day);
        
        if(month==0&&day==0){
            break;
        }if(month==1){
            days=day;
        }if(month==2){
            days=31+day;
        }if(month==3){
            days=31+29+day;
        }if(month==4){
            days=31+29+31+day;
        }if(month==5){
            days=31+29+31+30+day;
        }if(month==6){
            days=31+29+31+30+31+day;
        }if(month==7){
            days=31+29+31+30+31+30+day;
        }if(month==8){
            days=31+29+31+30+31+30+31+day;
        }if(month==9){
            days=31+29+31+30+31+30+31+31+day;
        }if(month==10){
            days=31+29+31+30+31+30+31+31+30+day;
        }if(month==11){
            days=31+29+31+30+31+30+31+31+30+31+day;
        }if(month==12){
            days=31+29+31+30+31+30+31+31+30+31+30+day;
        }if(days%7==1){
            printf("Thursday\n");
        }if(days%7==2){
            printf("Friday\n");
        }if(days%7==3){
            printf("Saturday\n");
        }if(days%7==4){
            printf("Sunday\n");
        }if(days%7==5){
            printf("Monday\n");
        }if(days%7==6){
            printf("Tuesday\n");
        }if(days%7==0){
            printf("Wednesday\n");
        }
        
        
    }
    
    
}



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

typedef long long LL;

const LL MOD = 1e9+7;

inline LL dmod(LL x){
	return x%MOD;
}

int n,c;

LL pang[405][405];
LL ps[405][405];

void pre(){
	for(int i=0;i<=400;i++) pang[i][0] = 1LL;
	for(int i=1;i<=400;i++){
		for(int j=1;j<=400;j++){
			pang[i][j] = dmod(pang[i][j-1]*(LL)i);
		}
	}
	for(int i=0;i<=400;i++) ps[0][i] = pang[0][i];
	for(int i=1;i<=400;i++){
		for(int j=0;j<=400;j++){
			ps[i][j] = dmod(ps[i-1][j] + pang[i][j]);
		}
	}
}

//int n,c;
int A[405],B[405];

LL memo[405][405];

LL dp(int id, int sisa){
	if(id > n){
		if(sisa == 0) return 1LL;
		else return 0LL;
	}
	LL &ret = memo[id][sisa];
	if(ret!=-1) return ret;
	ret = 0LL;
	for(int i=0;i<=sisa;i++){
		ret = dmod(ret+dmod(dp(id+1,sisa-i)*dmod(ps[B[id]][i] - ps[A[id]][i]+MOD)));
	}
	return ret;
}

int main(){
	pre();
//	for(int i=0;i<=5;i++){
//		for(int j=0;j<=5;j++){
//			cout << ps[i][j] << " ";
//		}
//		cout << endl;
//	}
	memset(memo,-1,sizeof(memo));
	cin >> n >> c;
	for(int i=1;i<=n;i++){
		cin >> A[i];
		A[i]--;
	}
	for(int i=1;i<=n;i++){
		cin >> B[i];
	}
	LL ans = dp(1,c);
	cout << ans << endl;
	return 0;
}

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

int main(){
    string s,t;
    cin >> s >> s >> t;
    cout << "A" << s[0] << "C" << endl;
}

Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]



s = input()

h = {}

alp = "abcdefghijklmnopqrstuvwxyz"

for i in alp:
    h[i] = 0

for i in s:
    h[i] += 1

#print(h)
for k,v in h.items():
    if (v == 0):
        print(k)
        exit()

print("None")



Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 5;

long long k;
long long ans;

int main() {
    cin >> k;

    for(int a = 1; a <= k; a++) {
        for(int b = 1; b <= k; b++) {
            for(int c = 1; c <= k; c++) {
                ans += __gcd(a, __gcd(b, c));
            }
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3676
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int main()
{
  char x;
  cin>>x;
  if(x <= 'z' && x>= 'a')cout<<"a";
  else cout<<"A";
}

Measured memory_bytes: 3628
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int H,W;
char C[51][51];
int main() {
	cin>>H>>W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin>>C[i][j];
		}
	}
	int S[51][51]={};
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
				if(C[i][j+1]=='#')S[i][j]++;
				if(C[i][j-1]=='#')S[i][j]++;
				if(C[i+1][j]=='#')S[i][j]++;
				if(C[i+1][j+1]=='#')S[i][j]++;
				if(C[i+1][j-1]=='#')S[i][j]++;
				if(C[i-1][j]=='#')S[i][j]++;
				if(C[i-1][j+1]=='#')S[i][j]++;
				if(C[i-1][j-1]=='#')S[i][j]++;
		}
	}

	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(C[i][j]=='.')cout<<S[i][j];
			if(C[i][j]=='#')cout<<'#';
		}
		cout<<endl;
	}

	return 0;
}


Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <utility>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int n;
    string s,t;
    cin >> n;
    cout << 0 << endl;
    cin >> s;
    if(s == "Vacant"){
        return 0;
    }
    cout << n-1 << endl;
    cin >> t;
    if(t == "Vacant"){
        return 0;
    }
    int l = 0,r = n-1;
    rep(hoge,18){
        int mid = (l+r)/2;
        cout << mid << endl;
        string m;
        cin >> m;
        if(m=="Vacant"){
            return 0;
        }
        if((m == s and (mid-l)%2) or (m!=s and (mid-l)%2==0)){
            r = mid;
            t = m;
        }else{
            l = mid;
            s = m;
        }
    }
}

Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll n,ans=0;
bool f[10000010]={};
vector<ll> pri;


int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	ll i,j;
	for(i=2;i<=1e6;++i){
		if(!f[i]){
			pri.push_back(i);
			for(j=2;j*i<=1e6;++j)
				f[i*j]=1;
		}
	}
	i=0;
	while(!(n==1||i>=pri.size())){
		if(n%pri[i]!=0){
			++i;
			continue;
		}
			
		for(j=pri[i];n%j==0;j*=pri[i]){
			n/=j;
			++ans;
		}
		while(n%pri[i]==0)
			n/=pri[i];
		++i;
		//cout<<n<<" "<<ans<<endl;
	}
	if(n!=1)
		++ans;
	cout<<ans;
	
	return 0;
}
//997764507

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


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

    ll ans=0;
    ll n;
    cin>>n;
    ll t=0;
    while(ans<n){
        t++;
        ans+=t;
    }
    int k=ans-n;
    for(int i=1;i<=t;i++){
        if(i!=k) cout<<i<<endl;
    }
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define inv(n, a) for(int i = 0; i < n; i++) cin >> a[i]
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
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; }
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

int main() {
    // int n; cin >> n;
    // int a;   
    // map<ll, ll> m;
    // int ans = 0;
    // for(int i = 1; i <= n; i++){
    //     cin >> a;
    //     ll l = i - a;
    //     ll r = i + a;
    //     ans += m[l];
    //     m[r]++;
    // }
    // cout << ans << endl;
    int n;
    cin>>n;
    map<ll, ll> am;
    ll hi;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        cin>>hi;
        ans+=am[i-hi];
        am[hi+i]+=1;
    }
    printf("%lli\n",ans);
    return 0;
}


Measured memory_bytes: 26292
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextLong();
        }
        Arrays.sort(a);
        double answer = a[0];
        for (int i = 0; i < N; i++) {
            answer = (answer + (double) a[i]) / 2;
        }
        System.out.println(String.format("%.9f", answer));
    }
}


Measured memory_bytes: 24916
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
int mod = 1000000007;

int main()
{
    IOS
    int t = 1;
    //cin >> t;
    while (t--)
    {
        int N;
        cin >> N;
        if (N % 1000 == 0)
            cout << 0;
        else
            cout << 1000 * (N / 1000 + 1) - N;
    }
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
vector<int> prime;
void seive(int x){
    vector<bool> isprime(x,true);
    for(int p=2;p*p<=x;p++){
        if(isprime[p]){
            for(int i=p*p;i<=x;i+=p) isprime[i]=false;
        }
    }
    for(int i=2;i<=x;i++) prime.push_back(i);
}
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res;
}
/*------------------------------------------------------------
------------------------------------------------------------*/
int main(void){
    ll n,k;
    boost;
    cin>>n>>k;
    for(int i=k-(n-1);i<=(k+(n-1));i++) cout<<i<<" ";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
def f(n, x):
    if n % x == 0:
        return (n // x * 2 - 1) * x
    else:
        return (n // x * 2) * x + f(x, n % x)
n, x = map(int,input().split())
ans = n + f(n - x, x)
print(ans)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int bit[114514][40], kbit[40];
ll dp[50][2];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	ll k, a;
	cin>>n>>k;
	REP(i, n){
		cin>>a;
		int cnt=0;
		while(a>0){
			bit[i][cnt++]=a&1;
			a/=2;
		}
	}
	int kcnt=0;
	while(k>0){
		kbit[kcnt++]=k&1;
		k/=2;
	}
	REP(i, 50){
		dp[i][0]=dp[i][1]=-1;
	}
	dp[40][0]=0;
	ll beki=1ll<<40;
	FORR(i, 0, 40){
		beki>>=1;
		int cnt=0;
		REP(j, n){
			if(bit[j][i]){
				++cnt;
			}
		}
		if(dp[i+1][1]>=0){
			dp[i][1]=dp[i+1][1]+beki*max(cnt, n-cnt);
		}
		if(kbit[i]){
			CHMAX(dp[i][1], dp[i+1][0]+beki*cnt);
			dp[i][0]=dp[i+1][0]+beki*(n-cnt);
		}
		else{
			dp[i][0]=dp[i+1][0]+beki*cnt;
		}
	}
	cout<<max(dp[0][0], dp[0][1])<<'\n';
	return 0;
}


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

int main() {
  int r, D, x;

  cin >> r >> D >> x;

  int ans = x;

  rep(i, 10) {
    ans = r * ans - D;
    cout << ans << endl;
  }

  return 0;

}

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

int main(){
    int A;
    int B;
    int C=0;

    cin >> A;
    cin >> B;

    if (A >= 13) {
        cout << B << endl;
    }
    else if (A >= 6 && A <= 12) {
        cout << int(B/2) << endl;
    }
    else if (A <= 5) {
        cout << C << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  char s[3];
  int days = 0;
  int max = 0;

  for(int i = 0; i < 3; i++){
      scanf("%c", &s[i]);
      if(s[i] == 'R'){
          days++;
          if(max < days){
              max = days;
          }
      } else {
          days--;
          if(days < 0){
              days = 0;
          }
      }
  }

  printf("%d", max);

  return 0;
}

Measured memory_bytes: 2092
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
// URLD
double dx[4]={0,1,-1,0};
double dy[4]={1,0,0,-1};
long double eps = 1e-6;
long double pi = acos(-1);

// LCA
// verify: https://atcoder.jp/contests/abc014/submissions/9535352
vector<vector<array<int,3>>> v(200010);
bool used[200010];
int depth[200010];
int par[200010][20];
int dist[200020];


// 根からの深さと1つ上の親を求める. initの中で使う
void dfs(int p,int d){
    used[p] = 1;
    depth[p] = d;
    for(auto i:v[p]){
        if(!used[i[0]]){
            dist[i[0]] = dist[p] + i[2];
            dfs(i[0],d+1);
            par[i[0]][0] = p;
        }
    }
}

// init(n, root) でダブリングテーブルを作製する, nは頂点数
void init(int n,int root=0){
    for(int i=0;i<n;i++){
        used[i]=false;
        for(int j=0;j<20;j++){
            par[i][j] = -1;
        }
    }
    dfs(root,0);
    for(int j=1;j<20;j++){
        for(int i=0;i<n;i++){
            if(par[i][j-1] == -1) continue;
            par[i][j] = par[par[i][j-1]][j-1];
        }
    }
}

//頂点aのd個上の親を求める
ll get_nyaa(ll a,ll d){
    for(ll i=19;i>=0;i--){
        if(d & (1<<i)) a = par[a][i];
    }
    return a;
}

// a,bのLCAを求める
int lca(int a,int b){
    if(depth[a] < depth[b]) swap(a,b);
    int dif = depth[a] - depth[b];
    for(int i=19;i>=0;i--){
        if(dif & (1<<i)) a = par[a][i];
    }
    if(a==b) return a;
    for(int i=19;i>=0;i--){
        if(par[a][i]!=par[b][i]){
            a = par[a][i], b = par[b][i];
        }
    }
    return par[a][0];
}

int cnt[200020];
int cd[200020];
map<int,pair<int,int>> totori[200020];
void dfs2(int p,int pre){
    for(auto &i:totori[p]){
        i.second.first = cd[i.first];
        i.second.second = cnt[i.first];
    }
    for(auto i:v[p]){
        if(i[0] != pre){
            cd[i[1]] += i[2];
            cnt[i[1]]++;
            dfs2(i[0],p);
            cd[i[1]] -= i[2];
            cnt[i[1]]--;
        }
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n,q;
    cin>>n>>q;

    for(int i=1;i<n;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        a--,b--,c--;
        v[a].push_back({b,c,d});
        v[b].push_back({a,c,d});
    }
    init(n,0);

    array<int,4> qu[q];
    for(int i=0;i<q;i++){
        int a,b,c,d;
        cin>>c>>d>>a>>b;
        a--,b--,c--;
        qu[i] = {a,b,c,d};
        totori[a][c]={0,0};
        totori[b][c]={0,0};
        totori[lca(a,b)][c]={0,0};
    }
    dfs2(0,-1);
    for(int i=0;i<q;i++){
        int a = qu[i][0], b = qu[i][1];
        int c = qu[i][2], d = qu[i][3];
        int l = lca(a,b);
        ll ans = (ll)(dist[a] + dist[b] - 2*dist[l]);
        ll mi = (ll)(totori[a][c].first + totori[b][c].first - 2*totori[l][c].first);
        ll p = (ll)(totori[a][c].second + totori[b][c].second - 2*totori[l][c].second)*d;
        //cerr << ans << " " << mi << " " <<p << endl;
        ans += p - mi;
        cout << ans << '\n';
    }

}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int n, m;
	cin >> n >> m;
	
	vector< vector< int > > dst(n, vector< int >(n, 1 << 29));
	for_(i,0,n) dst[i][i] = 0;
	
	struct Edge { int u, v, c; };
	vector< Edge > edges;
	for_(i,0,m) {
		int u, v, c;
		cin >> u >> v >> c;
		--u; --v;
		edges.push_back(Edge{u, v, c});
		dst[u][v] = dst[v][u] = c;
	}
	
	for_(k,0,n) for_(i,0,n) for_(j,0,n) dst[i][j] = min(dst[i][j], dst[i][k] + dst[k][j]);
	
	int ans = 0;
	for (Edge e : edges) {
		bool used = false;
		for_(i,0,n) for_(j,0,n) used |= (dst[i][j] == dst[i][e.u] + dst[e.v][j] + e.c);	
		if (!used) ++ans;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
//LIFE IS NOT A PROBLEM TO BE SOLVED
 
#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define F first
#define S second
#define pb push_back
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugV(v, n) { rep( i, 0, n ) { if(i) printf(" "); printf("%d", v[i]); } printf("\n"); }
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) { if(j) printf(" "); printf("%d", mat[i][j]); } printf("\n"); }
 
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> ii;
	

bool isPrime(int n){
	if(n<=1) return false;
	if(n==2) return true;
	int f = sqrt(n);
	rep(i, 2, f+1) if(n%i==0) return false;
	return true;
}


int main(){
	
	ll N; cin >> N;
	
	if(N&1){
		cout << 0 << '\n';
		return 0;
	}
	
	ull pot = 5, ans = 0;
	while(pot<=N){
		ans += (N/pot)/2;
		pot*=5;
	}
	
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
ans = [0] * M
cnt=0
for i in range(N):
    A = list(map(int,input().split()))
    for j in range(1,A[0]+1):
         ans[A[j]-1] +=1
for i in range(M):
    if ans[i] == N:
        cnt +=1
print(cnt)


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

int main() {
  ll x;
  cin >> x;
  ll k = 0, tmp = 0;
  while (tmp < x) tmp += (++k);
  cout << k << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  rep(i, N)
  {
    int t;
    cin >> t;
    a[i] = t - 1;
  }

  int ans = 0;
  rep(i, N)
  {
    if (a[a[i]] == i)
    {
      ans++;
    }
  }

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

Measured memory_bytes: 1024
n = int(input())
string = input()
red = 0
gre = 0
blu = 0
for i in range(n):
    if(string[i] == 'R'):
        red+=1
    elif(string[i] == 'G'):
        gre += 1
    else:
        blu += 1
sum = red * gre * blu
for i in range(n):
    if(i > n - i - 1):
        num = n - i - 1
    else:
        num = i
    for l in range(1,num + 1):
        if(string[i - l] != string[i] and string[i - l] != string[i + l] and string[i + l] != string[i]):
            sum -= 1
print(sum)


Measured memory_bytes: 9220