akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
char s[N];
int ans[N];
int nx[4] = {1, 1, 0, 0};
int ny[4] = {1, 0, 0, 1};

bool check(int a, int b, int n)
{
    ans[0] = a; ans[1] = b;
    for(int i = 1; i < n - 1; i++)
    {
        if(s[i] == 'o')
        {
            if(ans[i]) ans[i + 1] = ans[i - 1];
            else ans[i + 1] = !ans[i - 1];
        }
        else
        {
            if(ans[i]) ans[i + 1] = !ans[i - 1];
            else ans[i + 1] = ans[i - 1];
        }
    }
    if(s[0] == 'o')
    {
        if(ans[0])
        {
            if(ans[1] != ans[n - 1]) return false;
        }
        else if(ans[1] == ans[n - 1]) return false;
    }
    else
    {
        if(ans[0])
        {
            if(ans[1] == ans[n - 1]) return false;
        }
        else if(ans[1] != ans[n - 1]) return false;
    }
    if(s[n - 1] == 'o')
    {
        if(ans[n - 1])
        {
            if(ans[0] != ans[n - 2]) return false;
        }
        else if(ans[0] == ans[n - 2]) return false;
    }
    else
    {
        if(ans[n - 1])
        {
            if(ans[0] == ans[n - 2]) return false;
        }
        else if(ans[0] != ans[n - 2]) return false;
    }
    return true;
}


int main()
{
    int n;
    scanf("%d %s", &n, s);
    for(int i = 0; i < 4; i++)
    {
        if(check(nx[i], ny[i], n))
        {
            for(int i = 0; i < n; i++)
            {
                if(ans[i]) printf("S");
                else printf("W");
            }
            printf("\n");
            exit(0);
        }
    }
    puts("-1");
    return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>


int main (int argc, char const *argv[])
{
    int64_t K, A, B;
    int64_t i, ans = 0;

    scanf("%"PRId64"%"PRId64"%"PRId64, &K, &A, &B);

    if (A >= (B - 1)) {
        printf("%"PRId64"\n", 1 + K);
        return 0;
    }

    ans = A + (K - (A - 1)) / 2 * (B - A) + (K - (A - 1)) % 2;

    printf("%"PRId64"\n", ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
//get the biggest element.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

int main() {
  int n;
  cin >> n;
  map<ll, ll> mi;
  vector<ll> a(n);
  rep (i, n) {
    int x;
    cin >> x;
    a[i] = x;
    ++mi[x];
  }

  ll tmp = 0;
  for (auto v : mi) {
    ll x = v.second;
    tmp += x * (x - 1) / 2;
  }

  for (int i = 0; i < n; i++) {
    ll x = mi[a[i]];
    cout << tmp - (x * (x - 1) / 2) + ((x - 1) * (x - 2) / 2) << endl;
  }

  return 0;
}


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

int h,w ,K;
char grid[11][1010];
int tmpg[11][1010];
int main(){
    
    cin>>h>>w>>K;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>grid[i][j];
        }
    }
   
   int cnt=1<<30,tmp=0,x[11],chk,lst;
   for(int i=(1<<(h-1)); i<(1<<h);i++){
        tmp=0;
        for(int j=0;j<(h-1);j++)
            tmp+=(!!(i&(1<<j)));
        for(int j=0;j<w;j++){
            lst=0;
            for(int k=0;k<h;k++){
                tmpg[k][j]=0;
                if(i&(1<<k)){
                    for(int l=lst;l<=k;l++){
                        tmpg[k][j]+=(grid[l][j]-'0');
                    }
                    if(tmpg[k][j]>K){
                        tmp = 1<<30;
                        break;
                    }
                    lst=k+1;
                }
            }
            if(tmp==(1<<30))
                break;
        }
        if(tmp==(1<<30))
            continue;
        
        for(int k=0;k<h;++k)x[k]=0;

        for(int j=0;j<w;j++){
            for(int k=0;k<h;k++){
                if(i&(1<<k)){
                    x[k]+=tmpg[k][j];
                    if(x[k]>K){
                        tmp++;
                        for(int l=0;l<h;l++)
                            x[l]=tmpg[l][j];
                        break;
                    }
                }
            }
        }
        cnt= min(tmp,cnt);

   }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
rule = (2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1)
a, b = map(int, input().split())
if rule.index(a) > rule.index(b):
    print("Alice")
elif rule.index(b) > rule.index(a):
    print("Bob")
else:
    print("Draw")


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

using namespace std;

long long n, a, b;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n >> a >> b;

    long long g = n / (a + b);
    long long c = n % (a + b);
    long long ans = g * a;
    if(c <= a){
        ans += c;
    } else {
        ans += a;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
/*    Don’t Quit
    
    When things go wrong as they sometimes will;
        When the road you’re trudging seems all uphill;
            When the funds are low, and the debts are high;
                And you want to smile, but you have to sigh;
                    When care is pressing you down a bit
                        Rest if you must, but don’t you quit.
*/
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=2e5+5;
int gcd(int n,int m)
{
    if(n==0)
        return m;
    else
        return gcd(m%n,n);
}
vector<int>vp[N];
int a[N];
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    cout<<(n*(n-1))/2<<endl;

        
}


Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>

using namespace std;

int n;

long long int d[100000];

long long int wa[200000];

bool func(long long int l)
{
	for(int i = 0; i < n; i++)
	{
		int now = i;
		for(int j = 0; j < 2; j++)
		{
			long long int nl;
			if(now == 0)
			{
				nl = 0;
			}
			else
			{
				nl = wa[now - 1];
			}
			if(wa[i + n - 1] - nl < l)
			{
				goto aa;
			}
			int s = now - 1;
			int b = i + n - 1;
			while(s < b - 1)
			{
				int m = (s + b) / 2;
				if(wa[m] - nl >= l)
				{
					b = m;
				}
				else
				{
					s = m;
				}
			}
			now = b + 1;
			//printf("%d %d\n",i,now);
		}
		if(wa[i + n - 1] - wa[now - 1] < l)
		{
			goto aa;
		}
		return true;
aa:
		int q = 0;
	}
	return false;
}

int main()
{
	scanf("%d",&n);
	long long int now = 0;
	for(int i = 0; i < n; i++)
	{
		long long int w;
		scanf("%lld",&w);
		d[i] = w;
		now += w;
		wa[i] = now;
	}
	for(int i = 0; i < n; i++)
	{
		now += d[i];
		wa[i + n] = now;
	}
	long long int s = 1;
	long long int b = 1000000000000000;
	while(s < b - 1)
	{
		long long int m = (s + b) / 2;
		if(func(m))
		{
			s = m;
		}
		else
		{
			b = m;
		}
	}
	printf("%lld\n",s);
	return 0;
}

Measured memory_bytes: 3536
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vector<long double> A(N);
  REP(i, N) cin >> A[i];
  long double po = 0;
  REP(i, N) po += (long double)1 / A[i];
  cout << SP(20) << (long double)1 / po << endl;

  return 0;
}


Measured memory_bytes: 888
A = int(input())
B = int(input())
C = int(input())
X = int(input())
list = []
for j in range(A+1):
    for k in range(B+1):
        for l in range(C+1):
            TOTAL = j * 500 + k * 100 + l * 50
            list.append(TOTAL)
if X in list:
    print(list.count(X))
else:
    print(0)

Measured memory_bytes: 8276
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
    if(A<=C && C<=B){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
    return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N;
int A[100100];
// [0, i]まで, [N-1, i]まで
int B[100100], C[100100];

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

    std::cin >> N;

    for(int i=1;i<=N;++i){
        std::cin >> A[i];
    }

    for(int i=1;i<=N+1;++i){
        B[i] = B[i-1] + abs(A[i] - A[i-1]);
    }

    for(int i=N;i>=0;--i){
        C[i] = C[i+1] + abs(A[i] - A[i+1]);
    }

    for(int i=1;i<=N;++i){
        int res = B[i-1] + abs(A[i-1] - A[i+1]) + C[i+1];
        std::cout << res << std::endl;
    }
}


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

using namespace std;
typedef long long ll;

int main() {
    ll n, m, l;
    cin >> n >> m >> l;
    vector<vector<ll> > a(n, vector<ll>(m));
    vector<vector<ll> > b(m, vector<ll>(l));
    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    for (ll j = 0; j < m; j++) {
        for (ll k = 0; k < l; k++) {
            cin >> b[j][k];
        }
    }
    for (ll i = 0; i < n; i++) {
        for (ll k = 0; k < l - 1; k++) {
            ll ans = 0;
            for (ll j = 0; j < m; j++) {
                ans += a[i][j] * b[j][k];
            }
            cout << ans << " ";
        }
        ll ans = 0;
        for (ll j = 0; j < m; j++) {
            ans += a[i][j] * b[j][l - 1];
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3280
#include <iostream>
using namespace std;
const int MAX = 2000002;
bool c[MAX+1];

int main(){
  int n,a,b;

  while(cin >> n >> a >> b , n+a+b){
    int cnt = 0;
    for(int i = 0 ; i <= n ; i++) c[i] = false;
    c[0] = true;
    
    for(int i = 0 ; i <= n ; i++){
      if(c[i]&&(i+a <= n||i+b <= n)){
	c[i+a] = true; c[i+b] = true;
      }
    }
    for(int i = 1 ; i  <= n ; i++) 
      if(!c[i]) cnt++;

    cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 2136
#include <iostream>
using namespace std;
 
int main() {
	int n;
	cin>>n;
	string s;
	cin>>s;
	int k;
	cin>>k;
	char ch=s[k-1];
	string ans="";
	for(int i=0;i<s.size();i++)
		if(s[i]!=ch)
			ans+='*';
		else
			ans+=s[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <map>


using namespace std;



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

char e[555];


int main(){
	int i;
	signed char a,b,c;
	bool f;
	
	while(true){
		scanf("%s",e);
		if(e[0]=='#')break;
		i=0;
		f=false;
		while(e[i]!=0){
			i++;// (
			if(e[i] == '~'){
				a=-e[++i];
				
				//printf("!%c,",-a);
			}else{
				a=e[i];
				
				//printf(" %c,",a);
			}
			
			i+=2;// &
			if(e[i] == '~'){
				b=-e[++i];
				
				//printf("!%c,",-b);
			}else{
				b=e[i];
				
				//printf(" %c,",b);
			}
			
			i+=2;// &
			if(e[i] == '~'){
				c=-e[++i];
				
				//printf("!%c\n",-c);
			}else{
				c=e[i];
				
				//printf(" %c,\n",c);
			}
			
			if(a==-b || a==-c || b == -c){
			}else{
				f=true;break;
			}
			
			i+=2;
			if(e[i]==0)break;
			i++;
		}
		
		if(f)puts("yes");
		else puts("no");
		
	
	}
	
}

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

void solve(){
    
    int n,k;
    cin>>n>>k;


    vector<int> w(n);
    vector<int> v(n);

    for(int i=0; i<n; i++){
        cin>>w[i]>>v[i];
    }
    
    vector<vector<long long>> dp(n+1,vector<long long>(k+1,0));

    long long ma = 0;    

    for(int i=1 ; i<=n; i++){
    
        for(int j=1; j<=k; j++){
            
            if(j-w[i-1] >= 0){
                dp[i][j] = max(dp[i-1][j] , dp[i-1][j-w[i-1]]+v[i-1]);
                ma = max(ma, dp[i][j]);
            }
            else{
                dp[i][j] = dp[i-1][j];
            }
            
        }
        
    }
    


    
    cout<<ma<<endl;
    
return;

}
int main() {
	// your code goes here
        solve();
    
    return 0;
}




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



int main(){
int x,a,b;
cin >> x >>a >>b;
int ans = (x-a)%b;
cout << ans << endl;
}

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

ll n, m, q, a[55], b[55], c[55], d[55], p[55], res;

void go (int i, int j) {
	if (i == n) {
		ll t = 0;

		forn (k, q)
			if (p[b[k]] - p[a[k]] == c[k])
				t += d[k];
		
		res = max(res, t);
		return;
	}

	for (int k = j; k <= m; k++) {
		p[i] = k;
		go(i + 1, k);
	}
}

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

	cin >> n >> m >> q;

	forn (i, q) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--, b[i]--;
	}

	go(0, 1);

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3644
fun main(args: Array<String>) {
    val line = readLine()!!.trim()
    var (n, m) = line.split(" ").map {it.toLong()}
    val line2 = readLine()!!.trim()
    var ary = line2.split(" ").map {it.toLong()}.slice(0..n.toInt()-1)

    val totalVote: Long = ary.sum()
    val threshold: Double = totalVote / (4 * m.toDouble())

    val b = ary.filter {it >= threshold}.size >= m

    if (b) {
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 37992
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	char s[15];
	int sum=0,sum1=0,sum2=0,sl;
	scanf("%s",s);
	if(s[0]=='A')
	{
		for(int i=0;i<strlen(s);i++)
		{
			if(s[i]>='A'&&s[i]<='Z')
			sum++;		
		}
		for(int i=2;i<strlen(s)-1;i++)
		{
			if(s[i]=='C')
			sum1++;		
		}
		if(sum==2&&sum1==1)
		{
			printf("AC");
		}
		else
			printf("WA");
	}
	else
	{
		printf("WA");
	}
	
}

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

char field[30][30];
int res;
int w, h;
constexpr int dd[] = {0, 1, 0, -1, 0};

void dfs(int y, int x) {
  res++;
  field[y][x] = 'x';
  for (int i = 0; i < 4; ++i) {
    int ny = dd[i] + y, nx = dd[i + 1] + x;
    if (0 <= ny && ny < h && 0 <= nx && nx < w) {
      if (field[ny][nx] == '.') {
        dfs(ny, nx);
      }
    }
  }
}

int main() {
  while (cin >> w >> h, w || h) {
    int sy, sx;
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> field[i][j];
        if (field[i][j] == '@') {
          sy = i;
          sx = j;
          field[i][j] = '.';
        }
      }
    }
    res = 0;
    dfs(sy, sx);
    cout << res << endl;
  }
}

Measured memory_bytes: 3004
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

N = int(input())
S = [list(input()) for _ in range(N)]
INF = 10**12
dist = [[INF]*N for _ in range(N)]
edge = [[] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i==j:
            dist[i][j] = 0
        if S[i][j]=='1':
            edge[i].append(j)
            dist[i][j] = 1

def WarshallFloyd(d, N):
    #d[i][j]: iからjへの最短距離（隣接行列）
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

d = WarshallFloyd(dist, N)
def dfs(v, c):
    colors[v] = c
    for nv in edge[v]:
        if colors[nv] == c:
            return False
        if colors[nv] == -1:
            if not dfs(nv, c^1):
                return False
    return True

colors = [-1]*N
if not dfs(0,0):
    print(-1)
    exit()

ans = 0
for e in d:
    ans = max(ans, max(e))
print(ans+1)




Measured memory_bytes: 42224
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    vector<int> x(3);
    cin >> x[0] >> x[1] >> x[2];
    sort(x.begin(), x.end());

    int ans = 0;
    int add1 = (x[1] - x[0]) % 2;
    x[1] += add1;
    x[2] += add1;
    ans += add1;
    ans += (x[1] - x[0]) / 2;
    ans += x[2] - x[1];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
A,B,C=[],[],[]
for i in range(n):
  a,b,c=map(int,input().split())
  A.append(a)
  B.append(b)
  C.append(c)
DP=[[0 for i in range(3)] for j in range(n)]
DP[0]=[A[0],B[0],C[0]]
for i in range(1,n):
  DP[i][0]=max(DP[i-1][1],DP[i-1][2])+A[i]
  DP[i][1]=max(DP[i-1][0],DP[i-1][2])+B[i]
  DP[i][2]=max(DP[i-1][0],DP[i-1][1])+C[i]
print(max(DP[n-1][i] for i in range(3)))

Measured memory_bytes: 36236
import fractions
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

ma = 0
mod2count = -1
for i in range(n):
    if mod2count == -1:
        mod2count = bin(a[i])[2:][::-1].find('1')
    if mod2count != bin(a[i])[2:][::-1].find('1'):
        print(0)
        exit()
    a[i] = a[i] // 2
    if a[i] > ma:
        ma = a[i]

l = a[0]
for i in range(1, n):
    l = lcm(l, a[i])

tmp = m // l
if tmp % 2 == 0:
    print(tmp // 2)
else:
    print(tmp // 2 + 1)



Measured memory_bytes: 16280
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

typedef long long ll;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e5 + 10, INF = 1e9 * 1000;

vector<ll> pr;
int cmp[SIZE][26][26];

struct node {
	node* ns[26];
	int cnt = 0, sub = 0;
};

node* rt = new node();

void add(string& s, node* v, int ind) {
	if (ind == s.size()) {
		v->cnt++;
		v->sub++;
		return;
	}
	ll ch = s[ind] - 'a';
	if (v->ns[ch] != 0) {
		add(s, v->ns[ch], ind + 1);
	}
	else {
		node* u = new node();
		v->ns[ch] = u;
		add(s, v->ns[ch], ind + 1);
	}
	
	v->sub = v->cnt;
	for (int i = 0; i < 26; i++) {
		if (v->ns[i]) {
			v->sub += v->ns[i]->sub;
		}
	}
}

void cnt_pr(string& s, node* v, int ind, int i) {
	if (ind == s.size()) {
		return;
	}
	else {
		pr[i] += v->cnt;
		
		ll k = s[ind] - 'a';
		for (int j = 0; j < 26; j++) {
			if (k != j) {
				if (v->ns[j]) cmp[i][j][k] += (v->ns[j]->sub);
			}
		}
		
		cnt_pr(s, v->ns[k], ind + 1, i);
	}
}

int main() {
	fastInp;

	ll n;
	cin >> n;

	pr.resize(n);
	vector<string> vec;
	
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		vec.push_back(s);
		add(s, rt, 0);
	}

	for (int i = 0; i < n; i++) {
		string s = vec[i];
		cnt_pr(s, rt, 0, i);
	}
	ll q;
	cin >> q;

	while (q--) {
		ll k;
		cin >> k;
		string p;
		cin >> p;

		k--;
		ll ans = pr[k];
		for (int i = 0; i < 26; i++) {
			for (int j = i + 1; j < 26; j++) {
				ans += cmp[k][p[i] - 'a'][p[j] - 'a'];
			}
		}

		cout << ans + 1 << "\n";
	}

	return 0;
}


Measured memory_bytes: 296892
str = gets.chomp
q = gets.to_i
v = []

q.times do
  c = gets.split
  command = c[0]
  a = c[1].to_i
  b = c[2].to_i

  if command == 'print'
    v << str[a..b]
  elsif command == 'reverse'
    tmp = str[a..b].reverse
    str[a..b] = tmp
  else
    str[a..b] = c[3]
  end
end

v.each do |i|
  puts i
end



Measured memory_bytes: 6916
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; 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);
    int N;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    int count[9] = {};
    rep(i, N) {
        rep(j, 8) {
            if(a[i] >= j*400 && a[i] < (j+1)*400 ) {
                count[j]++;
            } else if ( a[i] >= 3200) {
                count[8]++;
            }
        }
    }
    int ans = 0;
    rep(i ,8) {
        if(count[i] > 0) ans++;
    }
    cout << max(1,ans) << " " << ans+count[8]/8;

    return 0;
}


Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '{';
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i];
    if (i != vec.size() - 1) os << ',';
  }
  os << '}';
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
// constant
constexpr int INF = std::numeric_limits<int>::max() / 2;  // 1.073741823e9
constexpr int64 INF64 = std::numeric_limits<int64>::max() / 2;  // 4.611686018427387903e18
constexpr int MOD = 1000000007;

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

  int n; cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
  }

  int ans = 0;

  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      ans += d[i] * d[j];
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;cin >> n;vector<long long>a(n);
  long long l1 = 0,l2 = 0;
  for(int i = 0;i < n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  for(int i = n-1;i >= 1;i--){
    if(a[i] == a[i-1]){
      if(l1 == 0){
        l1 = a[i];
        i--;
      }
      else{
        l2 = a[i];
        cout << l1*l2 << endl;
        return 0;
      }
    }
  }
  cout << 0 << endl;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	if (a + b >= c) wrln("Yes");
	else wrln("No");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

vector<vi> G;

int dp[100100];

int rec(int v){
  if(dp[v] != -1) return dp[v];

  int res = 0;
  for(auto nv: G[v]){
    maxs(res,rec(nv)+1);
  }
  dp[v] = res;
  return res;
}

int main() {
  int n,m;
  cin >> n >> m;
  G.assign(n,vi());

  rep(i,m){
    int x,y;
    cin >> x >> y;
    x--;y--;
    G[x].push_back(y);
  }

  rep(i,100100) dp[i] = -1;

  int ans = 0;
  rep(i,n) maxs(ans,rec(i));

  cout<<ans<<endl;
  return 0;


  return 0;
}

Measured memory_bytes: 8192
function main(input) {
  input=input.trim();
  const N = parseInt(input.split(" ")[0], 10);
  const arrA = input.split('\n')[1].split(' ').map((n) => parseInt(n, 10));
  arrA.sort(function(a,b){
    if( a < b ) return 1;
    if( a > b ) return -1;
    return 0;
  });

  var A=0
  var B=0
  for(var i=0; i<Math.floor(N/2)+Math.floor(N%2); i++){
    A+=arrA[2*i]
  }
  for(var i=0; i<Math.floor(N/2); i++){
    B+=arrA[2*i+1]
  }
  console.log(A-B);

}



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


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

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; cin>>N;
	vector<int> p(N+1);
	for (int i=1; i<=N; i++)
		cin>>p[i];
	int ret=0;
	for (int i=1; i<N; i++) {
		if(p[i]!=i)
			continue;
		swap(p[i],p[i+1]);
		ret++;
	}
	if(p[N]==N)
		swap(p[N],p[N-1]), ret++;
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#define N 110
#define LL long long
using namespace std;
int n,m;
LL w[N],v[N],dp[100010];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		cin>>w[i]>>v[i];
	memset(dp,128/3,sizeof(dp));
	dp[0]=0;
	for(int i=1;i<=n;i++)
		for(int j=100000;j>=v[i];j--)
			dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
	LL ans=0;
	for(int i=0;i<=100000;i++)
		if(dp[i]<=(LL)m) ans=(LL)i;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<51)
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double
#define all(c) (c).begin(),(c).end()
#define N 100500

int dp[N][3];
int a[N][3];
int n;
int rec(int i,int ch)
{

    if(i == n)
        return 0;
    if(dp[i][ch] == -1)
    {
        int ans = 0;
        for(int c =0 ;c<3;c++)
        {
            if(ch == c)
                continue;
            ans = max(ans,a[i][c] + rec(i+1,c));
        }
        dp[i][ch] = ans;
        return ans;
    }
    else
        return dp[i][ch];
}
int32_t main()
{                
    IOS;
    
   
    memset(dp,-1,sizeof(dp));
    cin>>n;
   
    for(int i = 0;i  < n;i++)
    {
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    cout<<max(rec(0,0),max(rec(0,1),rec(0,2)));
    return 0;

}

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

int main() {
  int a, b;
  cin >> a >> b;
  if (a==0) cout << "IMPOSSIBLE";
  else if (b==0) cout << "IMPOSSIBLE";
  else {
    if ((a+b)%2==1) cout << "IMPOSSIBLE";
    else cout << (a+b)/2;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

vector<long long> divisor(long long n) {
    vector<long long> res;
    for (int i = 1; (long long)i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    sort(begin(res), end(res));
    return res;
}

signed main() {
    int n, k;
    cin >> n >> k;
    int sum = 0;
    int a[n];
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    auto D = divisor(sum);
    reverse(ALL(D));
    for (int d : D) {
        int r[n];
        rep(i, n) {
            r[i] = a[i] % d;
        }
        sort(r, r + n);
        int rr[n];
        rep(i, n) {
            rr[i] = d - r[i];
        }
        int sumrr[n + 1] = {};
        rep(i, n) {
            sumrr[i + 1] = sumrr[i] + rr[i];
        }
        int sumr = 0;
        rep(i, n) {
            sumr += r[i];
            if (sumr == sumrr[n] - sumrr[i + 1]) break;
        }
        if (sumr <= k) {
            cout << d << endl;
            return 0;
        }
    }
    return 0;
}

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

if N % 2 == 1:
    print("No")
else:
    correct = 0
    
    for i in range(N//2):
        if S[i] == S[i + N//2]:
            correct += 1
            
    if correct == N//2:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    long long k;
    cin>>k;
    cout<<50<<endl;
    long long a=k/50;
    long long ans[50];
    REP(i,50)ans[i]=49+a;
    long long b=k%50;
    REP(i,b){
        REP(j,50){
            if(ans[j]+50<=10000000000001000){
                ans[j]+=50;
                REP(k,50)if(j!=k)ans[k]--;
                break;
            }
        }
    }
    REP(i,50)cout<<ans[i]<<" ";cout<<endl;
}

Measured memory_bytes: 256
S = input()
ans = 0
i = 0
for i in range(len(S)):
    for j in range(i,len(S)):
        if S[j]=='A' or S[j]=='G' or S[j]=='T' or S[j]=='C':
            ans = max(ans,j-i+1) 
        else:
            break
print(ans)
# print(S)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll a; ll b;
    cin >> a >> b;
    ll bai = a*b;
    while (true){
        ll new_a = min(a, b);
        ll new_b = max(a, b);
        new_b %= new_a;
        if (new_b == 0){
            cout << bai / new_a << endl;
            return 0;
        }
        a = new_a;
        b = new_b;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main(){
   std::string S;
   std::cin >> S;

   long long count = 0;
   long long n = 0;
   for(int i=0; i<S.size(); ++i){
      if(S[i]=='W'){
	count += n;
      }else{
	 ++n;
      }
   }
   std::cout << count << std::endl;
   return 0;
}


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

int main(){

	int W, H, x, y, z;
	cin >> W >> H >> x >> y >> z;

	if(x - z < 0 || x + z > W || y - z < 0 || y + z > H ){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}

return 0;
}

Measured memory_bytes: 1156
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int a[3];
    while(cin>>a[0]>>a[1]>>a[2])
    {
      
      sort(a,a + 3);
      if(a[0] == 5 && a[1] == 5 && a[2] == 7)
 
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }


}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repc(i, a, b) for (int i = a; i <= (int)(b); i++)
#define ll long long
#define vec vector
#define pb push_back
#define ft first
#define sd second
#define all(vec) vec.begin(), vec.end()

typedef pair<int, int> P;

const int MOD = 1e9 + 7;
const int INF = 1001001001;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};

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

int main(){
  int n, wmax;
  cin >> n >> wmax;
  vec<int> w(n), v(n);
  rep(i, n) cin >> w[i] >> v[i];
  ll dp[n+1][100001];
  rep(i, n+1){
    rep(j, 100001){
      dp[i][j] = INF;
    }
  }

  dp[0][0] = 0;

  repc(i, 1, n){
    repc(j, 0, 100000){
      if(j-v[i-1] >= 0) dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]]+w[i-1]);
      else dp[i][j] = dp[i-1][j];
    }
  }
  
  int ans = 100000;
  while(dp[n][ans]>wmax) ans--;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 82532
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define endl '\n'
using namespace std;
const int N = 1e5 + 5;

int n, m, a[N], label[N], base[N], temp[N];
ll k;
ll x[N], d[N], ans[N];

void by_p()
{
    for(int i = 1; i <= m; i++)
        swap(label[a[i]], label[a[i] + 1]);
}

void by_itself()
{
    for(int i = 1; i <= n; i++)
        temp[i] = label[label[i]];
    for(int i = 1; i <= n; i++)
        label[i] = temp[i];
}

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

    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> x[i];
        d[i] = x[i] - x[i - 1];
        label[i] = i;
        base[i] = i;
    }

    cin >> m >> k;
    for(int i = 1; i <= m; i++)
    {
        cin >> a[i];
        swap(base[a[i]], base[a[i] + 1]);
    }

    vector <int> b;
    while(k)
    {
        b.pb(k & 1);
        k /= 2;
    }
    reverse(b.begin(), b.end());
    for(int x: b)
    {
        by_itself();
        if(x)
            by_p();
    }

    for(int i = 1; i <= n; i++)
        ans[i] = d[label[i]];

    for(int i = 1; i <= n; i++)
        ans[i] = ans[i] + ans[i - 1];

    for(int i = 1; i <= n; i++)
        cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 5248
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
using ll = long long;
using namespace std;

int main()
{
	ll N;
	ll count = 0;
	cin >> N;
	vector<ll> A(N);
	ll max = 0;
	vector<ll> dis(N,0);
	for (ll i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (ll k = 1; k <= N; k++) {
		if (max < A[k-1]) {
			max = A[k-1];
		}
		dis[k-1] = max - A[k-1];
		count = count + dis[k - 1];
	}
	cout << count << endl;
}



Measured memory_bytes: 5928
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define space " "
#define MOD (long long) 1000000007
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename T> void __f(const char* variable_name, T&& value){cout << variable_name << ": " << value << endl;}
template <typename T1, typename... T2> void __f(const char* names, T1&& arg1, T2&&... args){const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << ": " << arg1 << " |";__f(comma + 1, args...);}

const ll N = 5e5 + 5;
ll *v;
ll n;

void solve(){
    cin >> n;
    ll sum = 0;
    for(ll i = 1; i <= n; i++)
        if(i % 3 != 0 && i % 5 != 0)
            sum += i;
    cout << sum << endl;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll t = 1;
    // cout << "\n\nBLAH BLAH BLAH\n\n";
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
n = int(input())
count = 0
ans = 0
j = 1

for i in range(1, n+1, 2):
    while j <= i:
        if i % j == 0:
            count += 1
        j += 1
    if count == 8:
        ans += 1
    count = 0
    j = 1
            
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
typedef long long ll;
int main(){
    ll N,A,B;
    cin>>N>>A>>B;
    ll count=0;
    ll C=N/(A+B);
    ll D=N%(A+B);
    count+=C*A;
    if(D>A){
        count+=A;
    }else{
        count+=D;
    }
    cout<<count<<endl;
    

    return 0;
}

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


int t1,ans;
long long t;

int x,p,d1,r,m,d,b,k2,cch,f2,q,z,i,l,k,f,y;
long long int n;


string j;
int o;

int main() {
//cin>>t;

//	while(t--)
//	{
	    cin>>x>>y;
	    n=0;
	    //cout<<x<<" "<<y<<"\n";
	    for(i=x;i<=y;i++)
	    {
	        f=1;
	       // cout<<i<<"\n";
	        j=to_string(i);
	       // cout<<j<<"--\n";
	        l=j.size();
	        for(k=0;k<l;k++)
	        {
	            if(j[k]!=j[l-k-1])
	            {
	                f=0;
	                break;
	            }
	        }
	        if(f)
	        {n++;
	        //cout<<i<<"=\n";
	            
	        }
	    }
	   cout<<n<<"\n";
	 
   
//	}
	
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline

H, W = map(int, readline().split())
S = [list(input()) for i in range(H)]


def bfs(grid, start):
    distance = [[0] * W for _ in range(H)]
    queue = deque([start])
    visited = [[False] * W for _ in range(H)]
    visited[start[0]][start[1]] = True
    while queue:
        x, y = queue.popleft()

        for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y + j, x + i
            if 0 <= new_y < W and 0 <= new_x < H:
                if grid[new_x][new_y] == '.' and not visited[new_x][new_y]:
                    distance[new_x][new_y] = distance[x][y] + 1
                    visited[new_x][new_y] = True
                    queue.append((new_x, new_y))
    return distance


answer = 0
limit = H - 1 + W - 1
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue

        cnt = 0
        for dx, dy in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = dy + j, dx + i
            if 0 <= new_y < W and 0 <= new_x < H:
                if S[new_x][new_y] == '.':
                    cnt += 1

        if cnt > 2:
            continue

        tmp = max(map(max, bfs(S, (i, j))))
        if tmp > answer:
            answer = tmp
        if answer == limit:
            print(answer)
            exit()

print(answer)


Measured memory_bytes: 3316
a = input().strip().split(' ')
player = [int(a[1]) - int(a[2])] * int(a[0])
for i in range(int(a[2])):
    t = int(input())
    player[t - 1] += 1
for i in range(int(a[0])):
    if player[i] > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 6596
from collections import Counter
n=int(input())
s=[input() for _ in range(n)]
sc=[Counter(s[i]) for i in range(n)]
alp="abcdefghijklmnopqrstuvwxyz"
alpm=[100 for _ in range(len(alp))]
ansl=[]
for q, i in enumerate(alp):
	for j in range(n):
		alpm[q] = min(alpm[q], sc[j][i])
for q in range(len(alp)):
	ansl.append(alp[q]*alpm[q])
print("".join(ansl))

Measured memory_bytes: 3436
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;

int main(){

    int n;
    double s[1000];

    while(1){
        cin >> n;
        if(n==0) break;

        double a;
        double S=0;
        double m=0;

        for(int i=0; i<n; i++){
            cin >> s[i];
            m += s[i];
            
        }
        m = m/n;//平均

        for(int j=0; j<n; j++){
            S += pow(s[j]-m, 2);
        }
        a = sqrt(S/n);
        printf("%lf\n", a);
    }

    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
ll n,W;
ll w[105],v[105];
ll dp[105][105][305];
ll ans;
int main(void){
    cin>>n>>W;
    for(int i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<=n*3;j++){
            dp[1][i][j]=v[0];
        }
    }
    for(int i=2;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=0;k<=3*n;k++){
                if(w[i-1]==w[0]){
                    dp[i][j][k]=max(dp[i-1][j][k],dp[i-1][j-1][k]+v[i-1]);
                }else if(w[i-1]==w[0]+1){
                    if(k>=1){
                        dp[i][j][k]=max(dp[i-1][j][k],dp[i-1][j-1][k-1]+v[i-1]);
                    }else{
                        dp[i][j][k]=dp[i-1][j][k];
                    }
                }else if(w[i-1]==w[0]+2){
                    if(k>=2){
                        dp[i][j][k]=max(dp[i-1][j][k],dp[i-1][j-1][k-2]+v[i-1]);
                    }else{
                        dp[i][j][k]=dp[i-1][j][k];
                    }
                }else if(w[i-1]==w[0]+3){
                    if(k>=3){
                        dp[i][j][k]=max(dp[i-1][j][k],dp[i-1][j-1][k-3]+v[i-1]);
                    }else{
                        dp[i][j][k]=dp[i-1][j][k];
                    }
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<=3*n;j++){
            if(w[0]*i+j<=W){
                ans=max(ans,dp[n][i][j]);
            }
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 27764
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	while (b > 0) {
		if (b & 1) {res = (res * a); b--;}
		a = (a * a);
		b >>= 1;
	}
	return res;
}
ll n;
ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}


int main() {
	ll ww;
	cin>>n>>ww;
	vl v(n),w(n);
	for(ll i=0;i<n;i++)
		cin>>w[i]>>v[i];
	ll vmax=0;
	for(ll i=0;i<n;i++)
		vmax+=v[i];
	vector < vector <ll> > dp (n+1,vector <ll> (vmax+1,1000000000));
	// dp[i][j]=min weight with total value j upto i th element
	// 
	for(ll i=0;i<n;i++){
		for(ll j=0;j<=vmax;j++){
			if(j==0){
				dp[i][j]=0;
				continue;
			}
			if(i==0){
				dp[i][j]=v[i]>=j?w[i]:1000000000;
				continue;
			}
			if(v[i]<=j)
				dp[i][j]=min(dp[i-1][j],w[i]+dp[i-1][j-v[i]]);
			else
				dp[i][j]=min(dp[i-1][j],w[i]);
		}
	}
	ll ans=0;
	for(ll i=0;i<=vmax;i++){
		if(dp[n-1][i]<=ww)
			ans=i;
	}
	cout<<ans<<"\n";
}


Measured memory_bytes: 83068
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>

int main(void) {
    int n;
    std::scanf("%d", &n);
    int cnt[100010] = {};
    for (int i = 0; i < n; i++) {
        int a;
        std::scanf("%d", &a);
        cnt[a - 1]++;
        cnt[a]++;
        cnt[a + 1]++;
    }
    int ans = -1;
    for (int i = 0; i < 100010; i++) {
        ans = std::max(cnt[i], ans);
    }
    std::printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 640