akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <iostream> 
#include <iomanip>  
#include <string>
#include <sstream>  
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <cstring>
#include <cmath>
#include <cassert>


#define INF              (int)1000000007
#define EPS              1e-9
#define pb               push_back
#define mp               make_pair
#define all(c)           c.begin(), c.end()
#define forall(i,a,b)    for(int i=a;i<(b);++i)
#define trav(a,x)        for(auto & a: x)
#define in(a,b)          ((b).find(a) != (b).end())
#define sz(c)            (int)(c).size()
#define input(a)         for(auto & x : a) cin >> x;

using namespace std;

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

#ifdef DEBUG
#define trace(...)       __f(#__VA_ARGS__, __VA_ARGS__)
#define debug(args...)   {dbg,args; clog<<endl;}
#define print_( a )      for( auto & x : a ) clog << x << ' '; clog << '\n';
#define printPair_( a )  for( auto & x : a ) clog << '(' << x.first << ',' << x.second << ')' << ' '; clog << '\n';
#else
#define trace(...)       
#define debug(args...)            
#define print_( a )               
#define printPair_( a )           
#endif

struct debugger {
  template<typename T> debugger& operator , (const T& x) {    
    clog << x << " ";    return *this;    
  }
}dbg;

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " | ";
    __f(comma + 1, args...);
}

auto ____ =[]() { std::ios::sync_with_stdio(0); cin.tie(0); return nullptr; }();

int main( int argc, char * argv[] ){
  ll n, m; cin >> n >> m; 
  vector<ll> w(n), v(n), dp(100005, numeric_limits<ll>::max()); 
  forall(i,0,n) cin >> w[i] >> v[i];
  dp[0] = 0;
  forall(i,0,n){
    ll wei = w[i], val = v[i];
    for(ll j = 100005-val; j >= 0; --j){
      if( dp[j] == numeric_limits<ll>::max() ) continue;
      if( dp[j] + wei > m ) continue;
      debug("update dp[j+val]", j+val, dp[j]+wei);
      dp[j+val] = min(dp[j+val], dp[j] + wei);
    }
    trace(i, wei, val);
  }
  ll ans = 0;
  forall(i,0,100005){
    if( dp[i] <= m ) ans = i;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
S = input()
targetLst = ['A' , 'C', 'G', 'T']

ansLst = []

for i in range(len(S)):
    tmp = []
    for j in range(i, len(S)):
        if S[j] in targetLst:
            tmp.append(S[j])
        else:
            break
    ansLst.append(len(tmp))

ansLst.sort()
ansLst.reverse()

print(ansLst[0])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,x;
  	x=0;
	cin>>a>>b>>c;
	if(a==5){
		if(b==7&&c==5){
			cout<<"YES"<<endl;
          	x++;
		}
		if(b==5&&c==7){
			cout<<"YES"<<endl;
          	x++;
		}
		if (x==0){
			cout<<"NO"<<endl;
          	x++;
		}
	}
	if(a==7){
		if(b==5&&c==5){
			cout<<"YES"<<endl;
          	x++;
		}
		if(x==0){
			cout<<"NO"<<endl;
          	x++;
		}
	}
	else if (x==0){
		cout<<"NO"<<endl;
	}
}

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

int main(void)
{
    int a;
    cin >> a;
    a=a%1000;
    if(a==0)
    {
        cout << "0" << endl;
    }
    else
    {
        cout << 1000 - a%1000 << endl;
    }

    return 0;
}


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

int main() {
  int n,k;
  cin >> n >> k;
  int x;
  int ans = 0;
  for(int i=0; i<n; i++){
    cin >> x;
    ans += 2 * min(x,k-x);
  }
  cout << ans << endl;
}
    
    

Measured memory_bytes: 256
using System;

class Program {
    static void Main(string[] args) {

        string []nk = Console.ReadLine().Split(' ');
        string[] h = Console.ReadLine().Split(' ');

        int n = int.Parse(nk[0]);
        int k = int.Parse(nk[1]);

        int result = 0;

        for(int a = 0; a < n; a++) {
            int ha = int.Parse(h[a]);
            if (ha >= k) result++;
        }

        Console.WriteLine(result);
    }
}



Measured memory_bytes: 15584
K, N = map(int, input().split())
An = list(map(int, input().split()))

def distance(a1, a2):
  return abs(a1 - a2)

sum, max = 0, 0
for i in range(N):
  if (i + 1) < N:
    d = distance(An[i], An[i+1])
    sum += d
    if(d > max):
      max = d
  else:
    d = distance(An[i], K) + distance(0, An[0])
    sum += d
    if(d > max):
      max = d

print(sum - max)

Measured memory_bytes: 26444
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	int k = 2;
	while(true) {
		int m = k * (k - 1);
		if(m == 2 * n) break;
		else if(m > 2 * n) {
			cout << "No" << endl;
			return 0;
		}
		k++;
	}
	vector<vi> s(k, vi(k - 1));
	vi idx(k);
	int val = 1;
	rep(i, k - 1) for(int j = i + 1; j < k; j++) {
		s[i][idx[i]++] = val;
		s[j][idx[j]++] = val;
		val++;
	}
	cout << "Yes" << endl;
	cout << k << endl;
	rep(i, k) {
		cout << k - 1;
		rep(j, k - 1) cout << ' ' << s[i][j];
		cout << endl;
	}
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
long long sumright[200005];
long long sumleft[200005];

int main()
{
    long long n,i,j,mini=1e18;

    long long a[200005];
    scanf(" %lld",&n);
    for(i=1;i<=n;i++){
        scanf(" %lld",&a[i]);
        sumright[i]=sumright[i-1]+a[i];
    //    printf("\nsumright=%d\n",sumright[i]);
    }
    for(j=n;j>1;j--){
        sumleft[j]=sumleft[j+1]+a[j];
    //    printf("\nj=%d sumleft=%d sumright=%d %d\n",j,sumleft[j],sumright[j-1],abs(sumright[j-1]-sumleft[j]));
        if(mini>abs(sumright[j-1]-sumleft[j])){
            mini=abs(sumright[j-1]-sumleft[j]);
        }
    }
    printf("%lld\n",mini);
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>

using namespace std;

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

    string s;
    cin >> s;
    int n = s.size();
    if (n == 6 && s[2] == s[3] && s[4] == s[5]) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
 
using namespace std;
 
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	int n, l[3000];
	int cnt = 0;
	int i, j, k;
 
	cin >> n;
	for (i = 0; i < n; i++)
		cin >> l[i];
 
	sort(l, l + n);
 
	for (i = 0; i < n - 2; i++)
	{
		for (j = i + 1; j < n - 1; j++)
		{
			for (k = j + 1; k < n; k++)
			{
				if (l[i] < l[j] + l[k]&&l[k] < l[j] + l[i]&&l[j] < l[i] + l[k])
							cnt++;
			}
		}
	}
	cout << cnt << endl;
 
	return 0;
}

Measured memory_bytes: 256
import sys

A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

x = abs((A - B))
y = (V - W)

if y <= 0:
    print("NO")
    sys.exit()

z = x / y

if z <= T:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define vecsort(x) sort(x.begin(), x.end())
#define vecrsort(x) sort(x.rbegin(), x.rend())
#define massort(x, n) sort(x, x + n)
#define FOR(i, n) for(int i = 0; i < n; i ++)
using namespace std;
int max(int32_t a, int b){
   return max((int)a, b);
}
int max(vector<int> a){
   cout << *max_element(a.begin(), a.end());
}

const int INF = 1e18 + 7;
const int N = 1e5 + 2000;

int32_t main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   int n, W;
   cin >> n >> W;
   vector<int> dp(n*1000, INF);
   // dp[i] is minimum weight to get total value i
   vector<int> weight(n), value(n);
   int total_value = 0;
   for(int i = 0; i < n; i ++){
      cin >> weight[i] >> value[i];
      total_value += value[i];
   }
   dp[0] = 0;
   for(int i = 0; i < n; i ++){
      for(int j = total_value - value[i]; j >= 0; j --){
         dp[j + value[i]] = min(dp[j + value[i]], dp[j] + weight[i]);
      }
   }
   int ans = 0;
   for(int i = 0; i <= total_value; i ++){
      if(dp[i] <= W)
         ans = max(ans, i);
   }
   cout << ans;


}



Measured memory_bytes: 1024
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <climits>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template<typename T>
#define _HT template<typename H,typename... T>
_T _DEF(T,in,int c){T n{};int m{1};while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_SCAN(char &c){c=gcu();gcu();return c!=EOF;}
_T _SCAN(T &n){int c{gcu()};return c==EOF?false:(n=in<T>(c),true);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
_OUT(string s){for(char c:s)pcu(c);}
#endif
_OUT(const char *s){while(*s)pcu(*s++);}
_T _OUT(T n){static char b[20];char *p{b};T m=n<0?pcu('-'),-1:1;if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{int e,b{0},s{1};range(int _b,int _e,int _s):e(_e),b(_b),s(_s){}range(int _b,int _e):e(_e),b(_b){}range(int _e):e(_e){}
	struct it{int v,s;it(int _v,int _s):v(_v),s(_s){}operator int()const{return v;}operator int&(){return v;}int operator*()const{return v;}it& operator++(){v+=s;return *this;}};
	it begin(){return{b, s};}it end(){return{e,s};}};

template <typename T>
using V = vector<T>;

int main() {
	V<V<int>> a {{1, 1, 1}, {2, 1},{3}};
	V<int> t(3);
	for (int Q {in()}; Q; Q--) {
		for (int &i: t)
			i = in();
		int r {};
		for (auto &i: a) {
			range $(i.size());
			int m {INT_MAX};
			for (int j: $)
				m = min(m, t[j] / i[j]);
			for (int j: $)
				t[j] -= i[j] * m;
			r += m;
		}
		outl(r);
	}
}


Measured memory_bytes: 2708
import java.io.*;
import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n=scan.nextInt();
        long[] a = new long[n];
        for(int i=0;i<n;i++){a[i]=scan.nextLong();}

        int q=scan.nextInt();
        int ans=0;
        for(int i=0;i<q;i++){
            long t=scan.nextLong();
            if(check(a,t)){
                ans++;
            }
        }
        System.out.println(ans);
    }
    private static boolean check(long[]a,long t){
        int l=0,r=a.length-1;
        while(l<r){
            int mid=(l+r)/2;
            if(a[mid]<t){
                l=mid+1;
            }
            else{
                r=mid;
            }
        }
        if(a[r]==t)return true;
        else return false;
    }
}


Measured memory_bytes: 81004
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


int main() {
    int n; cin >> n;
    string s, t; cin >> s >> t;

    for (int i=0; i<n; i++) {
        cout << s[i];
        cout << t[i];
    }

    cout << endl;
    return 0;
}



Measured memory_bytes: 888
#include<cstdio>
const int MAXN = 1e3 + 5;
const int MAXM = 1e3 + 5;

int ans[MAXN][MAXM];

inline void print(int nn,int x)
{
	while(nn--) putchar(x+'0');
}

int main(void)
{
	int n,m,a,b;
	scanf("%d%d%d%d",&n,&m,&a,&b);
	
	for(int i=1; i<=b; ++i)
	{
		print(a,0);
		print(m-a,1);
		putchar('\n');
	}
	for(int i=b+1; i<=n; ++i)
	{
		print(a,1);
		print(m-a,0);
		putchar('\n');
	}
	return 0;
}

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

int main(void) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 7 && b == 5 && c == 5) {
        cout << "YES" << endl;
    } else if (a == 5 && b == 7 && c == 5) {
        cout << "YES" << endl;
    } else if (a == 5 && b == 5 && c == 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
 int A,B;
 cin>>A>>B;
 int cnt;
 for(int i=A;i<=B;i++){
  int i0=i/10000;
  int i1=(i-i0*10000)/1000;
  int i4=i%10;
  int i3=((i-i4)%100)/10;

  if(i0==i4&&i1==i3){
   cnt++;
  }
 }
 cout<<cnt<<endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1LL << 60;

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	int cnt[3] = {};
	ll ans = 1;
	for (int i = 0; i < S.size(); i++) {
		int c;
		if (S[i] == 'R') c = 0;
		else if (S[i] == 'G') c = 1;
		else c = 2;
		int r = 0;
		for (int i = 0; i < 3; i++) if (cnt[i] > cnt[c]) r++;
		vector<int> vec{ cnt[0],cnt[1],cnt[2] };
		sort(vec.begin(), vec.end(), greater<int>());
		if (r == 1) {
			(ans *= vec[0] - vec[1]) %= MOD;
		}
		else if (r == 2) {
			(ans *= vec[1] - vec[2]) %= MOD;
		}
		cnt[c]++;
	}
	for (int i = 1; i <= N; i++) (ans *= i) %= MOD;
	cout << ans << endl;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
int main(){
        int n; cin >> n;
        int ans = 0;
        for (int x = 0; x < n; ++x){
            int q; cin >> q;
            ans += q - 1;
        }
        cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
/*
AizuOnline A0103
Baseball Simulation
*/
#include <stdio.h>
#include <string.h>

main()
{

  int ining;
  int out;
  int runner;
  int point ;
  char bat[10];

  scanf("%d",&ining);
  while(ining)
  {   out = 0;
            runner = 0;
            point = 0;
        while(out < 3)
          {scanf("%s",bat);
            if (0 == strcmp("OUT",bat))
              out++;
            else if (0 == strcmp("HIT",bat))
              {if(runner == 3)
                point++;
               else    
                runner++;
              }
            else if(0 == strcmp("HOMERUN",bat))
              { point += (1+runner);
                runner = 0;
              }
          }
  
    printf("%d\n",point);
    ining--;
  }

  return(0);
}

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

#define reint register int
#define coint const int

using namespace std;

coint SIZE = 20 + 5;

int li[SIZE];

int main(void) {
    int n;
    scanf("%d", &n);
    for (reint i = 1; i <= n; ++i) scanf("%d", &li[i]);
    int ans = 0;
    for (reint i = 2; i < n; ++i)
        ans += ((li[i] > li[i - 1] && li[i] < li[i + 1])
                || (li[i] < li[i - 1] && li[i] > li[i + 1]));
    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-


import sys


def counting_sort(A, max_occurance):
    result = [0] * array_length
    count_list = [0] * max_occurance

    for j in range(array_length):
        count_list[A[j]] += 1
    # print('1', C[:array_length])

    for i in range(1, max_occurance):
        count_list[i] += count_list[i - 1]
    # print('2', C[:array_length])

    for m in array[::-1]:
        result[count_list[m] - 1] = m
        count_list[m] -= 1

    return result


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    array = list(map(int, _input[1].split()))
    assert len(array) == array_length
    max_elem = int(1e4)
    result = counting_sort(A=array, max_occurance=max_elem)
    print(*result)

Measured memory_bytes: 220976
#include <stdio.h>
int n,A[50];
int solve(int i, int j);
int main(){
    int q,r,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&r);
        if(solve(0,r)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}
int solve(int i, int j){
if(j==0)return 1;
    if(i>=n)return 0;
    int c=solve(i+1,j) || solve(i+1,j-A[i]);
    return c;
    }


Measured memory_bytes: 2104
#include <iostream>

int main()
{
    int n;
    std::cin>>n;
    switch(n%10)
    {
        case 3:
        std::cout<<"bon"<<std::endl;
        break;
        case 0:
        case 1:
        case 6:
        case 8:
        std::cout<<"pon"<<std::endl;
        break;
        default:
        std::cout<<"hon"<<std::endl;
        break;     
    }
}

Measured memory_bytes: 3624
# tokio marine 2020 C.Lamps
import copy
# N = int(input())
N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

for i in range(K):
    B = [0 for k in range(N)]
    for j in range(N):
        L = A[j]
        l = max(j-L, 0)
        r = min(j+L, N-1)
        B[l] += 1
        if r + 1 < N:
            B[r+1] -= 1
    for j in range(1, N):
        B[j] += B[j-1]
    A = copy.deepcopy(list(B))
    if len(set(A)) == 1 and A[0] == N:
        break
print(*A)


Measured memory_bytes: 180460
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;

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

const int MAX_N = 100010;

int par[MAX_N];
int Rank[MAX_N];
int cnt[MAX_N]; //cnt[i]:i番目が親だった時、そのグループに所属するメンバーの個数

void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		Rank[i] = 0;
		cnt[i] = 1;
	}
}

int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;

	if (Rank[x] < Rank[y]) {
		par[x] = y;
		cnt[y] += cnt[x];
	}
	else {
		par[y] = x;
		cnt[x] += cnt[y];
		if (Rank[x] == Rank[y]) Rank[x]++;
	}
}

bool same(int x, int y) {
	return find(x) == find(y);
}

ll Combi(ll n) {
	if (n < 2) return 0;
	return n*(n - 1) / 2;
}

int main(void) {
	int N, M; cin >> N >> M;
	ll d[MAX_N]; d[M] = 0;
	int a[MAX_N], b[MAX_N];
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i];
	}
	init(N);
	for (int i = M - 1; i >= 0; i--) {
		if (!same(a[i], b[i])) {
			int x = find(a[i]);
			int y = find(b[i]);
			d[i] = d[i + 1] + Combi(cnt[x] + cnt[y]) - Combi(cnt[x]) - Combi(cnt[y]);
			unite(a[i], b[i]);
		}
		else {
			d[i] = d[i + 1];
		}
	}
	for (int i = 1; i <= M; i++) {
		cout << Combi(N) - d[i] << endl;
	}

}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
const ll limit = 2e9;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
 
//const int mod = 998244353;
 
struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a); 
		b = find_set(b);	
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}	
};


//~ map<int,int> h;
//~ int dp[2007];
//~ vector <int> arraySort(vector <int> v) {
	//~ vector<int> ans;
	//~ for(int i = 1; i <= (int)v.size(); i++){
		//~ dp[i] = 1;
	//~ }
	
	//~ for(int i = 1; i <= (int)v.size(); i++){
		//~ for(int j = 1; j < i; j++){
			//~ if(v[j-1] <= v[i-1]){ 
				//~ if(dp[i] < dp[j] + 1){
					//~ dp[i] = dp[j] + 1;
					//~ h[i] = j;
				//~ }
				//~ else if(dp[i] == dp[j] + 1){					
					//~ int index = h[i];
					//~ int val = v[index-1];
					//~ if(v[j-1] < val){
						//~ h[i] = j;
					//~ }
				//~ }
			//~ }
		//~ }
	//~ }
	//~ int index, maxi = 0, minval = inf;
	//~ for(int i = 1; i <= (int)v.size(); i++){
		//~ if(maxi <= dp[i] ){
			//~ maxi = dp[i];
		//~ }
	//~ } 
	
	//~ for(int i = 1; i<= (int)v.size(); i++){
		//~ if(maxi == dp[i]){
			//~ if(minval > v[i-1]){
				//~ minval = v[i-1];
				//~ index = i;
			//~ }
		//~ }
	//~ }
	
	//~ cout<<minval<<" "<<index<<endl;
	
	//~ int next = index;
	
	//~ while(next){
		//~ cout<<next<<" ";
		//~ next = h[next];
	//~ }
	//~ return ans;
//~ }

int v[4];
int main(){
	string s;
	cin>> s;
	bool a = false, b = false;
	for(char c: s){
		if(c == 'A')
			a = true;
		if(c =='B')
			b = true;
	}
	
	if(a && b)
		cout<<"Yes";
	else
		cout<<"No";
		
	
	return 0;
}













Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
using namespace std;
using ll = long long;


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n+1),b(n);
    for(ll i=0;i<=n;i++)    cin >> a[i];
    for(ll i=0;i<n;i++) cin >> b[i];

    ll sum=0;
    for(ll i=0;i<n;i++){
        if(a[i]<=b[i]){
            sum+=a[i];
            b[i]-=a[i];
        }
        else{
            sum+=b[i];
            b[i] = 0;
        }

        if(a[i+1]<=b[i]){
            sum+=a[i+1];
            a[i+1]=0;
        }
        else{
            sum+=b[i];
            a[i+1]-=b[i];
        }
    }
    cout << sum;
}

Measured memory_bytes: 1792
import sys
from bisect import bisect_left as bi_l, bisect_right as bi_r

n = int(sys.stdin.readline().rstrip())
*a, = map(int, sys.stdin.readline().split())
*b, = map(int, sys.stdin.readline().split())
*c, = map(int, sys.stdin.readline().split())

def main():
    a.sort()
    b.sort()
    c.sort()
    res = 0
    for i in b:
        cnt_a = bi_l(a, i)
        cnt_c = n - bi_r(c, i)
        res += cnt_a * cnt_c
 
    return res
    
if __name__ == '__main__':
    ans = main()
    print(ans)

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

const int N = 4e5+7;
vector<int> adj1[N], adj2[N];

int sz = 0;
void build(int n, int d, vector<int> adj[]) {
    vector<pair<int, int>> v;

    for (int dx=0; dx*dx <= d; dx++) {
        int dy = sqrt(d-dx*dx);
        if (dx*dx+dy*dy != d)   continue;

        v.emplace_back(dx, dy);
        if (dx) v.emplace_back(-dx, dy);
        if (dy) v.emplace_back(dx, -dy);
        if (dx && dy) v.emplace_back(-dx, -dy);
    }

    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            for (auto pr: v) {
                int nx = i+pr.first;
                int ny = j+pr.second;
                if (0<=nx && nx<n && 0<=ny && ny<n) {
                    adj[i*n+j].push_back(nx*n+ny);
                    sz++;
                }
            }
        }
    }
}

bool bad[N];

int col[N];
int cnt[2];

void dfs(int u, vector<int> adj[]) {
    if (!bad[u])    cnt[col[u]]++;
    for (int v: adj[u]) {
        if (col[v] == -1)   {
            col[v] = !col[u];
            dfs(v, adj);
        }
    }
}

void bicolor(int n, vector<int> adj[]) {
    memset(col, -1, sizeof col);
    cnt[0] = cnt[1] = 0;

    for (int i=0; i<n*n; i++)
        if (col[i] == -1) {
            col[i] = 0;
            dfs(i, adj);
        }

    bool big = cnt[1] > cnt[0];
    for (int i=0; i<n*n; i++)
        if (col[i] != big)
            bad[i] = 1;
}

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

    int n, d1, d2;
    cin>>n>>d1>>d2;
    n*=2;

    build(n, d1, adj1);
    build(n, d2, adj2);

    bicolor(n, adj1);
    bicolor(n, adj2);

    vector<pair<int, int>> ans;
    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++)
            if (!bad[i*n+j])
                ans.push_back({i, j});

    for (int i=0; i<n*n/4; i++) cout<<ans[i].first<<" "<<ans[i].second<<"\n";
}


Measured memory_bytes: 114808
K,N = map(int,input().split())
A = [int(x) for x in input().split()]
Max = 0
for i in range(N):
  if i<N-1:
    Max = max(Max, A[i+1]-A[i])
  else:
    Max = max(Max, A[0]+K-A[i])
print(K-Max)
  

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

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

	int ans = 0;

	Rep(i, n + 1)
	{
		int x = i;
		int tmp = 0;

		while (x > 0) {
			tmp += x % 10;
			x = x / 10;
		}

		if (a <= tmp && tmp <= b) ans += i;
	}
	ANS(ans);
}

Measured memory_bytes: 256
#if defined(LOCAL)
#define PROBLEM_NAME "a"
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) (debug(x, #x))
#define I(x, ...) (x)
#define C(x...) CHECK(x)
#else
#define L(x, ...) (x)
#define I(x, ...) (x)
#define C(x, ...) ;
#endif
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <iostream>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <limits>
#include <numeric>

using namespace std;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ii = pair<int,int>; using lu = unsigned long long; using l = long long;
using vs = vector<string>; using vii = vector<ii>;
using vl = vector<l>; using vvl = vector<vl>; using vvvl = vector<vvl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<l>::max();
const double EPS = 1e-10; static constexpr auto PI = 3.1415926;
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(c) - 1; a >= l(b); a--)
#define VVL(x, a, b, i) vvl x(a, vl(b, l(i)));
#define VVVL(x, a, b, c, i) vvvl x(a, vvl(b, vl(c, l(i))));

const l MOD = e9 + 7; // end of template

void solve(istream& in, ostream& out) {
  l n; in >> n;
  vl v(n); F(i, 0, n) in >> v[i];
  l z = 0;
  F(i, 1, n) {
    if (v[i] == v[i - 1]) {
      z++;
      v[i] = -1;
    }
  }
  out << z << lf;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
  maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}


Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>a>>b>>c;
    rep(i,c+1){
        i+=(a-1);
        sum+=b;
    }
    sum-=b;
    cout<<sum<<endl;


    

    return 0;
}


Measured memory_bytes: 3612
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

a, b = MAP()

if a*b <= 0:
	print("Zero")
elif (b-a+1)%2 and b < 0 and a < 0:
	print("Negative")
else:
	print("Positive")

Measured memory_bytes: 5200
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())


//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	LL n, W; cin >> n >> W;

	vector<LL> v(n+1);
	vector<LL> w(n+1);

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

	vector<vector<LL>> dp(n + 1, vector<LL>(W + 1, -1));

	dp[0][0] = 0;
	
	for (int i = 1; i < n + 1; i++) {
		for (int j = 0; j < W + 1; j++) {


			dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			if (j - w[i] < 0)continue;
			if (dp[i - 1][j - w[i]] == -1)continue;

			dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
			
		}
	}

	LL ans = -1;
	for (int j = 0; j < W + 1; j++) {
		ans = max(ans, dp[n][j]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
int main() {
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<(abs(a-c)<=d||((abs(a-b)<=d)&&abs(b-c)<=d)?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
using namespace std;

using INT = long long;
using UINT = unsigned long long;

INT f(int s)
{
	return s % 2 == 0 ? s / 2 : 3 * s + 1;
}

int main()
{
	INT s;

	cin >> s;

	INT cnt = 1;

	vector<INT> db;

	while (1)
	{
		db.push_back(s);
		s = f(s);
		cnt++;
		for (auto a : db)
		{
			if (a == s)
			{
				cout << cnt << endl;
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
	int N, A, B, ans = 0;
	cin >> N >> A >> B;
	for(int i = 1; i <= N; i++) {
		int sum = 0;
		int tmp = i;
		while(tmp > 0){ 
			sum += (tmp % 10);
			tmp /= 10;
		}
		if (sum >= A && sum <= B){
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define PER(a,b,c) for(int a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
using namespace std;
const int MAXN=1e6+5;
int n,m,t;
int have[MAXN];
int main(){
    cin>>n>>t;
    REP(i,1,t){
        int tmp;
        cin>>tmp;
        REP(j,1,tmp){
            int a;
            cin>>a;
            have[a]=1;
        }
    }
    int ans=0;
    REP(i,1,n)if(!have[i])ans++;
    cout<<ans;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int A, B, C = ~(1<<31), Ma = (1<<16)-1;
int r() {
  A = 36969 * (A & Ma) + (A >> 16);
  B = 18000 * (B & Ma) + (B >> 16);
  return (C & ((A << 16) + B)) % 1000000;
}

ll M,N;
ll x[300001],y[300001],z[300001];
ll ord[300001],Y[300001],Z[300001];

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

  while(1){
    cin>>M>>N>>A>>B;
    if(M+N==0)break;
    rep(i,M){
      cin>>x[i]>>y[i]>>z[i];
      ord[i]=i;
    }
    rep(i,N){
      x[i+M]=r(); y[i+M]=r(); z[i+M]=r(); ord[i+M]=i+M;
    }
    N+=M;
    sort(ord,ord+N,[](const ll& a,const ll& b){
      if(x[a]==x[b]&&y[a]==y[b])return z[a] > z[b];
      else if(x[a]==x[b])return y[a] > y[b];
      else return x[a] < x[b];
    });
    rep(i,N){
      Y[i]=y[ord[i]];
      Z[i]=z[ord[i]];
    }

    vector<set<P> > st(N,set<P>());
    ll res=1;
    st[0].insert(P(Y[0],Z[0]));
    repl(i,1,N){
      ll lb=-1,ub=res;
      while(ub-lb>1){
        ll m=(lb+ub)/2;
        auto it=st[m].lower_bound(P(Y[i],-1));
        if(it!=st[m].begin()&&(--it)->se<Z[i])lb=m;
        else ub=m;
      }

      maxch(res,ub+1);

      auto it=st[ub].lower_bound(P(Y[i],-1));
      while(it!=st[ub].end()&&it->se>=Z[i])it=st[ub].erase(it);

      it=st[ub].lower_bound(P(Y[i],-1));
      if(st[ub].size()==0)st[ub].insert(P(Y[i],Z[i]));
      else if(it->fi!=Y[i]){
        st[ub].insert(P(Y[i],Z[i]));
      }
    }
    cout<<res<<endl;
  }

  return 0;
}



Measured memory_bytes: 37148
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int pt[123456], s, m, ans[123456], q[123456];
pair<int, int> p[123456];
void f() {
	for (int i = 1; i <= s; i++)pt[i] = i;
	return;
}
int root(int i) {
	if (pt[i] == i)return i;
	else return pt[i] = root(pt[i]);
}
void unite(int a, int b) {
	pt[root(b)] = root(a);
	root(b);
	return;
}
signed main() {
	cin >> s >> m;
	for (int i = 1; i <= s; i++)q[i] = 1;
	f();
	for (int i = 1; i <= m; i++)cin >> p[i].first >> p[i].second;
	for (int i = m; i > 0; i--) {
		if (i != m)ans[i] = ans[i + 1];
		else ans[i] = 0;
		if (root(p[i].first) != root(p[i].second)) {
			ans[i] += q[root(p[i].first)] * q[root(p[i].second)];
			q[root(p[i].first)] += q[root(p[i].second)];
			unite(p[i].first, p[i].second);
		}
	}
	for (int i = 2; i <= m + 1; i++)cout << s * (s - 1) / 2 - ans[i] << endl;
}

Measured memory_bytes: 5632
#include<stdio.h>
int n,k,i,m=1e9+7;
long a[200001]={},r=0;
int main(){
    scanf("%d%d",&n,&k);
    for(i=1;i<=n+1;i++)a[i]=(a[i-1]+i)%m;
    for(i=k;i<=n+1;i++)r=(r+(a[n]+1+m-a[n-i<0?0:n-i]-a[i-1]))%m;
    printf("%ld",r);
    return 0;
}

Measured memory_bytes: 3232
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
    
    int n,m,a,b,ans,er;
    
    cin >> n >> m;
    ans = m;
    er = m;
    for(int i=0;i<n;i++){
        cin >> a >> b;
        m += a-b;
        ans = max(ans,m);
        er = min(er,m);
    }
    
    cout << (er<0?0:ans) << endl;
    
    return(0);
}


Measured memory_bytes: 3076
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
string s;
int k;
int INFi=1000000000;
ll INFl=1000000000000000;

int main(){
    int N,M;cin>>N;
    map<string,int> mp;
    for(int i=0;i<N;i++){
        string s;cin>>s;
        mp[s]++;
    }
  cin>>M;
    for(int j=0;j<M;j++){
        string t;cin>>t;
        mp[t]--;
    }
    int ans=0;
    for(auto it=mp.begin();it!=mp.end();it++){
        ans=max(ans,it->second);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int ar[10000];
int n;
int i,j;

int min(int a,int b){
	if(a<=b)return a;
	else return b;
}

int calc(int s1,int s2,int color){
	int c=0;
	int os1=s1;
	int os2=s2;
	while(ar[s1]==color){
		c++;
		s1--;
		if(s1<0)break;
	}
	while(ar[s2]==color){
		c++;
		s2++;
		if(s2>n-1)break;
	}
	if(c<4)return os1+1+(n-os2);
	if(s1<0||s2>n-1||ar[s1]!=ar[s2])return s1+1+(n-s2);
	return calc(s1,s2,ar[s1]);
}

int main(){
	while(1){
		scanf("%d",&n);
		if(n==0)return 0;
		int ans=n;
		for(i=0;i<n;i++)scanf("%d",&ar[i]);
		for(i=0;i<n-1;i++){
			int oi1=ar[i+1];
			int oi2=ar[i];
			ar[i+1]=ar[i];
			ans=min(ans,calc(i,i+1,ar[i]));
			ar[i]=oi1;
			ar[i+1]=oi1;
			ans=min(ans,calc(i,i+1,ar[i+1]));
			ar[i]=oi2;
			ar[i+1]=oi1;
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=100010;
int a[N],b[N],lsta[N],lstb[N];
set<int>vis;
map<int,vector<int> >to;
inline bool valid(int x){
	set<int>::iterator it=vis.find(x);
	return it==vis.end();
}
void dfs(int x){
	if(!valid(x))return;
	vis.insert(x);
	map<int,vector<int> >::iterator it=to.find(x);
	if(it==to.end())return;
	for(int i=0,n=it->second.size();i<n;i++){
		dfs(it->second[i]);
	}
}
inline int Main(){
	int n=ni,xora=0,ans=0;
	for(int i=1;i<=n;i++){
		xora^=a[i]=lsta[i]=ni;
	}
	for(int i=1;i<=n;i++){
		b[i]=lstb[i]=ni;
		if(a[i]!=b[i]){
			ans++;
			to[b[i]].push_back(a[i]);
		}
	}
	lsta[n+1]=xora;
	sort(lsta+1,lsta+n+2);
	sort(lstb+1,lstb+n+1);
	for(int i=1,j=1;i<=n;i++,j++){
		for(;j<=n+1&&lsta[j]!=lstb[i];j++);
		if(j>n+1)return -1;
	}
	dfs(xora);
	for(int i=1;i<=n;i++){
		if(a[i]!=b[i]&&valid(b[i])){
			ans++,dfs(b[i]);
		}
	}
	return ans;
}
int main(){
	printf("%d\n",Main());
	return 0;
}

Measured memory_bytes: 22144
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll x , y;
 
int main() {
  cin >> x >> y;
  ll aw = 0;
  aw += (x<=1) ? 300000 : (x<=2) ? 200000 : (x<=3) ? 100000 : 0;
  aw += (y<=1) ? 300000 : (y<=2) ? 200000 : (y<=3) ? 100000 : 0;
  aw += (x*y<=1) ? 400000 : 0;
  cout << aw << endl;
}

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

string roop(string st)
{
    int a = st.size();
    char c = st[a - 1];
    for (int i = 0; i < a - 1; i++) {
        st[a - i - 1] = st[a - i - 2];
    }
    st[0] = c;

    return st;
}


int main()
{
    string s, t, kari;
    bool flag = false;
    cin >> s >> t;
    kari = roop(s);

    for (int i = 0; i < s.size(); i++) {
        if (t == kari) {
            cout << "Yes" << endl;
            return 0;
        }
        kari = roop(kari);
    }

    cout << "No" << endl;

    return 0;
}


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

struct Point { double x, y; };

struct Circle { Point center; double radius; };

double distance(const Point p, const Point q)
{
    const auto dx = p.x-q.x, dy = p.y-q.y;
    return sqrt(dx*dx + dy*dy);
}

double distance(const Circle a, const Circle b)
{
    const auto d = distance(a.center, b.center);
    return max(0.0, d - a.radius - b.radius);
}

int main()
{
    cout << setprecision(10) << fixed;

    Point start, finish;
    cin >> start.x >> start.y >> finish.x >> finish.y;

    int N; cin >> N;

    auto circles = vector<Circle>(N);
    for (auto& c : circles)
        cin >> c.center.x >> c.center.y >> c.radius;
    circles.push_back({start, 0});
    circles.push_back({finish, 0});

    const auto s = N, t = N+1;
    N += 2;

    auto distances = vector<double>(N, numeric_limits<double>::infinity());
    distances[s] = 0;

    auto candidates = vector<int>(N);
    iota(begin(candidates), end(candidates), 0);
    while (!candidates.empty())
    {
        const auto compare = [&](const int v, const int w) { return distances[v] < distances[w]; };
        const auto v = *min_element(begin(candidates), end(candidates), compare);
        candidates.erase(remove(begin(candidates), end(candidates), v), end(candidates));

        for (auto w = 0; w < N; w++)
            distances[w] = min(distances[w], distances[v] + distance(circles[v], circles[w]));
    }

    cout << distances[t] << endl;
}


Measured memory_bytes: 256
import numpy as np

N,D=map(int,input().split())
L=[]
for i in range(N):
	arr=input().split()
	L.append(arr)
grid=np.array(L,dtype=int)
O=np.zeros(2)
s=np.sum(np.square(grid-O),axis=1)
print(np.sum(s<=D*D))

Measured memory_bytes: 107884
#include<bits/stdc++.h>
using namespace std;
 int a[200010];
 int b[200010];
 int main(){
 int n;
 scanf("%d",&n);
 for(int i=2;i<=n;i++)scanf("%d",&a[i]);
 for(int i=2;i<=n;i++)b[a[i]]++;
 for(int i=1;i<=n;i++)printf("%d\n",b[i]);
return 0;
}


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

int main(){
	int n,k,r,s,p;
	long long ans=0;
	string t;
	cin>>n>>k>>r>>s>>p>>t;
	vector <char> bac;
	for(int i=0;i<n;i++){
		if(i<k){
			if(t[i]=='r'){
				bac.push_back('r');
				ans+=p;
			}else if(t[i]=='s'){
				bac.push_back('s');
				ans+=r;
			}else{
				bac.push_back('p');
				ans+=s;
			}
		}else{
			if(t[i]!=bac[i%k]){
				if(t[i]=='r'){
					bac[i%k]='r';
					ans+=p;
				}else if(t[i]=='s'){
					bac[i%k]='s';
					ans+=r;
				}else{
					bac[i%k]='p';
					ans+=s;
				}
			}else{
				bac[i%k]='x';
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int H[N];
  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  
  int answer = 0;
  int count = 0;
  for (int i = 0; i < N - 1; i++) {
    if (H[i] < H[i + 1]) {  // 移動不可
      if (answer < count) answer = count;
      count = 0;
    }
    else count++;
  }
  if (answer < count) answer = count;
  
  cout << answer << endl;
  return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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


ll N,K,S;

ll i, j;
int main(){
    scanf("%lld%lld%lld",&N,&K,&S);
    if(S<=2){
        fornum(i,0,K){
            printf("%lld ",S);
        }
        fornum(i,K,N){
            printf("%lld ", S + 1);
        }
    }else{
        fornum(i,0,K){
            printf("%lld ", S);
        }
        fornum(i,K,N){
            printf("%lld ", S - 1);
        }
    }
    return 0;
}

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

int main(){
	int k=0;
	int n;cin>>n;
	map<string,int> s;
	rep(i,n){
		string a; cin>>a;
		s[a]+=1;
		k=max(k,s[a]);
	}
	for( auto& p:s){
		if(p.second>=k){
			cout<<p.first<<endl;
		}
	}
}
		

Measured memory_bytes: 19220