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

using namespace std;
int n,i,a,b,c,nr;
long long sum;
int main()
{
    cin>>a;
    for (i=1;i<=a;i++)
    {
        b=i;
            nr=0;
        while (b)
        {
            nr++;
            b=b/10;
        }
        if (nr%2==1)
        {
            c++;
        }
    }
    cout<<c;
}


Measured memory_bytes: 256
from math import atan2,pi
a,b,x = map(int,input().split())

h = 2*x/(a*b)
ans1 = atan2(b, h)

y = b-x/(a*a)

if b-2*y <= 0:
    print(ans1/pi*180)
else:
    ans2 = atan2(y, a/2)
    print(ans2/pi*180)

Measured memory_bytes: 3060
def main():
    n, m = map(int, input().split())
    p = [0] + list(map(int, input().split()))
    cnt = 0
    global parent
    parent = list(range(n+1))
    for _ in range(m):
        x, y = map(int, input().split())
        unite(x, y)
    for i in range(1, n+1):
        if same(i, p[i]):
            cnt += 1
    print(cnt)

def root(x):
    if parent[x] == x:
        return x
    parent[x] = root(parent[x])
    return parent[x]

def unite(x, y):
    root_x = root(x)
    if root_x != root(y):
        parent[root_x] = y

def same(x, y):
    return root(x) == root(y)

if __name__ == "__main__":
    main()

Measured memory_bytes: 121708
K, A, B = [int(elem) for elem in input().split()]

if B - A <= 2:
    print(K + 1)
else:
    first_num_exchanges = A + 1
    rest_num_exchanges = K - first_num_exchanges
    gain_per_two_manipulation = B - A
    num_cookies = rest_num_exchanges // 2 * gain_per_two_manipulation + B
    if rest_num_exchanges % 2 == 1:
        num_cookies += 1
    print(num_cookies)


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

int main()
{
	double a,b,c,d,e,f;
	while(cin>>a>>b>>c>>d>>e>>f){
		printf("%.3f ",(c-b*(f-d*c/a)/(e-d*b/a))/a);
		printf("%.3f\n",(f-d*c/a)/(e-d*b/a));
	}
	return 0;
}

Measured memory_bytes: 0
Q = int(input())
A = []
B = []
for i in range(Q):
    in1, in2 = list(map(int,input().split()))
    A.append(in1)
    B.append(in2)
    
def sieve(N):
    p = 0
    prime = []
    is_prime = [1 for _ in range(N + 1)]
    is_prime[0], is_prime[1] = 0, 0
    for i in range(2, N + 1):
        if is_prime[i]:
            p += 1
            temp = i
            prime.append(i)
            while(temp <= N):
                is_prime[temp] = 0
                temp += i
            is_prime[i] = 1
    return is_prime

p_list = sieve(10 ** 5 + 10)
acc = [0, 0]
for i in range(3, 10 ** 5 + 1, 2):
    if p_list[i] and p_list[(i + 1) // 2]:
        acc.append(acc[-1] + 1)
    else:
        acc.append(acc[-1])
for i in range(Q):
    print(acc[(B[i] + 1) // 2] - acc[(A[i] + 1) // 2 - 1])

Measured memory_bytes: 94928
N=int(input())
res = 0

def trans753(i):
    dict753=['0','3','5','7']
    num753=""
    while i>0:
        num753+=dict753[i%4]
        i//=4
    return int(num753[::-1])

def verify753(i):
    if '0' in str(i):
        return False
    flag = [False for i in range(10)]
    while i>0:
        flag[i%10]=True
        i//=10
    return flag[7] and flag[5] and flag[3]

for i in range(1,4**10):
    num753 = trans753(i)
    if num753>N:
        break
    if verify753(num753):
        res+=1

print(res)


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


int main(){
  string s;
  cin >> s;
  int n = s.size();
  REP(bit,1<<(n-1)) {
    int check=s[0]-'0';
    string ans;
    ans.push_back(s[0]);
    REP(i,n-1) {
      if (bit&(1<<i)) {
	check += s[i+1] - '0';
	ans.push_back('+');
	ans.push_back(s[i+1]);
      }
      else {
	check -= s[i+1] - '0';
	ans.push_back('-');
	ans.push_back(s[i+1]);
      }
    }
    if (check == 7) {
      cout << ans << "=7" << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
#define pb push_back
#define mp make_pair
#define INF (ll)(1e18)
#define inf 0x7fffffff
#define inff 100000
#define ff first
#define ss second
#define sz(x) ((int) (x).size())
#define fast cin.sync_with_stdio(0);cin.tie(0)
#define rep(i,N) for(int i = 0;i < N;i++)
#define frep(i,a,b) for(int i = a;i <= b;i++)
#define pii pair<int , int>
#define pll pair<ll , ll>
#define vii vector<int>
#define vpii vector< pii >
#define fill(A,v) memset(A,v,sizeof(A))
#define setbits(x) __builtin_popcountll(x)
#define print(A,j,k) for(int ii=j;ii<k;ii++)cout<<A[ii]<<" ";cout<<"\n"
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
#define SQRT 350
#define CASES int t;cin>>t;while(t--)
#define FILE freopen("inp.txt" , "r" , stdin);
#define ld long double

const int MOD = 1e9 + 7;
const int N = 1e6 + 5;

string xs;

ll value(string s) {
	ll v = 0 , ans = 0;
	for(auto c : s) {
		if (c == '+') {
			ans += v;
			v = 0;
		}
		else {
			v = v * 10LL + (c - '0');
		}
	}
	ans += v;
	return ans;
}

ll solve(int index , string s) {
	
	if (index >= xs.size())
		return value(s);

	//do not add + sign here
	s.pb(xs[index]);
	ll ans = solve(index + 1 , s);

	s.erase(s.end() - 1);
	//add plus sign
	if (s.size() > 0) {
		char last = s[s.size() - 1];
		if (last != '+') {
			s.pb('+');
			ans += solve(index , s);
		}
	}
	return ans;
}

int main(int argc, char const *argv[])
{
	
	fast;

	cin >> xs;

	int n = xs.size();

	//dp[i][j] denote all possible sums from s[i..n]
	//j denotes if

	cout << solve(0 , "") << '\n';

	return 0;
}

Measured memory_bytes: 256
N = int(input())
B = [int(i) for i in input().split()]
total_A = 0
total_A += B[0]
for i in range(1,N-1):
    Ai = min(B[i-1],B[i])
    total_A += Ai
total_A += B[N-2]
print(total_A)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,cnt=1,maxv=1;
vector<P>z;
vector<P>vec;
signed main(){
    cin>>n;
    rep(i,n){
        int x,y;
        cin>>x>>y;
        z.push_back(make_pair(x,y));
    }
    sort(z.begin(),z.end());
    rep(i,n-1){
        for(int j=i+1;j<n;j++){
            int p=z[j].F-z[i].F,q=z[j].S-z[i].S;
            if(p<0){
                p*=-1;
                q*=-1;
            }
            vec.push_back(make_pair(p,q));
        }
    }
    sort(vec.begin(),vec.end());
    rep(i,n*(n-1)/2){
        if(i!=0&&vec[i]==vec[i-1])cnt++;
        else cnt=1;
        maxv=max(maxv,cnt);
    }
    if(n==1)cout<<1<<endl;
    else cout<<n-maxv<<endl;
    return 0;
}



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

minimum = N * 100

def kakuiNoWa(x:int):
    digits = []
    for i in range(5):
        digits.append(int(str(int(x / (10 ** i)))[-1]))
    return sum(digits)

for i in range(1, int(N / 2) + 1):
    result = kakuiNoWa(i) + kakuiNoWa(N-i)
    minimum = min(minimum, result)

print(minimum)


Measured memory_bytes: 3060
n=int(input())
happy=[list(map(int, input().split())) for i in range(n)]
dp=[[0 for j in range(3)] for i in range(n+1)]

for i in range(1,n+1):
  for place in range(3):
    for placeY in range(3):
      if place==placeY:
        continue
      dp[i][place]=max(dp[i][place],
                       dp[i-1][placeY]+happy[i-1][place])
      
ans=0
for place in range(3):
  ans=max(ans,dp[n][place])
print(ans)

Measured memory_bytes: 47348
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int x, y;
    cin >> x >> y;
    if (x % y == 0)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << x << endl;
    }
    return 0;
}

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



int main()
{
    int N, Q;
    std::cin >> N >> Q;

    std::string S;
    std::cin >> S;

    std::vector<int> l;
    std::vector<int> r;

    for(int i =0; i < Q; ++i){
        int a,b;
        std::cin >> a >> b;
        l.push_back(a-1);
        r.push_back(b-1);
    }
    std::vector<int> ac_index;
    ac_index.push_back(0);
    for(int i= 1; i < N+1; ++i){
        if(S[i-1] == 'A' && S[i] == 'C'){
                ac_index.push_back(ac_index[ac_index.size()-1]+1);
        }
        else{
            ac_index.push_back(ac_index[ac_index.size()-1]);
        }        
    }

    for(int i = 0; i < Q; ++i){
        int count = 0;

        std::cout << ac_index[r[i]] - ac_index[l[i]] << std::endl;
    }
    
     

    return 0;
}




Measured memory_bytes: 2356
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	bool S[14] = {}, D[14] = {}, H[14] = {}, C[14] = {};
	string card;
	int num;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> card >> num;
		if (card == "S") {
			S[num] = true;
		}
		if (card == "D") {
			D[num] = true;
		}
		if (card == "H") {
			H[num] = true;
		}
		if (card == "C") {
			C[num] = true;
		}
	}
	for (int i = 1; i < 14; i++) {
		if (S[i] == false) {
			cout << "S " << i << endl;
		}
	}
	for (int i = 1; i < 14; i++) {
		if (H[i] == false) {
			cout << "H " << i << endl;
		}
	}
	for (int i = 1; i < 14; i++) {
		if (C[i] == false) {
			cout << "C " << i << endl;
		}
	}
	for (int i = 1; i < 14; i++) {
		if (D[i] == false) {
			cout << "D " << i << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<string>
#include<set>
#include<map>
#include<bitset>
#define UP(i,l,h) for(int i=l;i<h;i++)
#define DOWN(i,h,l) for(int i=h-1;i>=l;i--)
#define W(a) while(a)
#define INF 0x3f3f3f3f
#define LL long long
#define MAXN 8200
#define EPS 1e-10
#define MOD 100000000

using namespace std;
vector<int> nodes[200010];
int step=0;
int n,m;

bool dfs(int x){
    if(x==n)
        return true;
    if(step==2)
        return false;
    int sz=nodes[x].size();
    UP(i,0,sz){
        step++;
        if(dfs(nodes[x][i])){
            return true;
        }
        step--;
    }
    return false;
}

int main(){

    scanf("%d%d",&n,&m);
    UP(i,0,m){
        int x,y;
        scanf("%d%d",&x,&y);
        nodes[x].push_back(y);
        nodes[y].push_back(x);
    }
    if(dfs(1)){
        puts("POSSIBLE");
    }else{
        puts("IMPOSSIBLE");
    }
}


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

using namespace std;

const int MOD = 1E9 + 7;
const int MAXN = 2E5;
int c[MAXN + 1];
int pre[MAXN + 1];
int dp[MAXN + 1];

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> c[i];
    }
    dp[0] = dp[1] = 1;
    pre[c[1]] = 1;
    for (int i = 2; i <= n; i++)
    {
        dp[i] = dp[i - 1];
        if (c[i] != c[i - 1])
        {
            dp[i] = (dp[i] + pre[c[i]]) % MOD;
            pre[c[i]] = (pre[c[i]] + dp[i - 1]) % MOD;
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 2560
/******************************************
* AUTHOR : Ashish Joshi* 
* INSTITUTION : NIT Hamirpur *
******************************************/
#include <bits/stdc++.h>
using namespace std;

#define N 100005
#define MOD 1000000007
#define PI 3.141592653589793

#define dd double
#define loop(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define set(b,i) (b|(1<<i))
#define unset(b,i) (b&!(1<<i))
#define cbit(b,i) bool(b&(1<<i))

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;
typedef vector<vector<ll> > vvll;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//ios_base& scientific (ios_base& str);
string s;
cin>>s;
int n=s.length();
int f=1;
for(int i=0;i<n;i++)
{
	if(s[i]!=s[n-1-i]){
		f=0;break;
	}
}
for(int i=0;i<(n-1)/2;i++){
	if(s[i]!=s[(n-1)/2-1-i])
		f=0;
}
for(int i=(n+1)/2;i<n;i++){
	if(s[i]!=s[n-i-1])
		f=0;
}
if(f)cout<<"Yes\n";
else cout<<"No\n";
return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
    h,n=map(int,input().split())
    lis=np.array([list(map(int,input().split())) for _ in range(n)])
    a_max=np.max(lis[:,0])
    dp=np.zeros(h+a_max+1,int)
    for i in range(a_max+1,a_max+h+1):
        dp[i]=np.min(dp[i-lis[:,0]]+lis[:,1])
    print(dp[a_max+h])

if __name__=='__main__':
    main()

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

int main(){
    long long N, K, ans;
    cin >> N >> K;
    ans=0;
    for (int b = K+1; b<=N; b++){
        ans += N/b*(b-K);
        ans += max(N%b-K+1,0LL);
    }
    if (K == 0) ans-=N;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    long long int a[4];
    long long int ans = (long long int)-1000000000000000003;
    int i, ii;
    scanf("%lld%lld%lld%lld", a, &a[1], &a[2], &a[3]);
    for (i = 0; i < 2; i++)
        for (ii = 2; ii < 4; ii++)
            if (ans < a[i] * a[ii])
                ans = a[i] * a[ii];
    printf("%lld", ans);
}

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;


int main() {

    int N;

    cin >> N;

    map<string, int> m;

    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        m[s] += 1;
    }

    int M;
    cin >> M;

    for (int i = 0; i < M; i++) {
        string s;
        cin >> s;
        m[s] -= 1;
    }

    int maxV = -101;

    for (auto const &x : m) {

        maxV = max(maxV, x.second);

    }

    cout << max(maxV, 0) << "\n";

    return 0;

}

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

using namespace std;
int a[4][4];
int check(int i)
{
    int b1 = a[0][0] - i , b2 = a[0][1] - i,b3= a[0][2] - i;
    int a2 = a[1][0]-b1 ,  a3 = a[2][0]-b1 ;
    if(a2+b2==a[1][1]&& a2 + b3 == a[1][2] && a3+b2 == a[2][1] && a3+b3 == a[2][2])
    {
        return 1 ;
    }
    return 0 ;
}
int main()
{

    for(int i = 0 ; i< 3; i++)
        for(int j = 0 ; j < 3;j++)
        cin>>a[i][j];

            if(check(0)) {
                cout<<"Yes"<< endl;
                return 0;
            }

    puts("No");
    return 0;
}

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

using std::min;
using std::max;
using std::pair; 
using std::make_pair; 

typedef long long LL;
const int N=5e5+10;

int n,l,t[N];
LL v[N];
double sum[N],f[N];

void Init() {
	scanf("%d%d",&n,&l);
	for (int i=1;i<=n;++i) scanf("%d%lld",&t[i],&v[i]);
}

pair<int,double>que[N];
void Solve() {
	int nowv=0; double sum=0;
	int h=1,ti=0;
	for (int i=1;i<=n;++i) {
		nowv+=v[i]; sum+=1.0*v[i]*t[i]/l;
		while (h<=ti && nowv>l) {
			int del=min(nowv-l,que[h].first);
			nowv-=del; sum-=1.0*que[h].second*del/l;
			if (que[h].first==del) ++h;else que[h].first-=del; 
		}
		printf("%.7f\n",sum);
		int _v=v[i];double _t=t[i];
		while (h<=ti && que[ti].second>=_t) {
			_t=(que[ti].first*que[ti].second+_v*_t)/(_v+que[ti].first);
			_v=que[ti].first+_v;
			--ti; 
		}
		que[++ti]=make_pair(_v,_t); 
	}
}

int main() {
	Init();
	Solve();
	return 0;
} 

Measured memory_bytes: 24320
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
  int n,p[100],q[100];
  cin >> n;
  
  for(int i = 0; i < n; i++) 
    cin >> p[i];
  
  for(int i = 0; i < n; i++)
    q[i] = p[i];

  sort(p,p+n);
  int num = 0;
  for(int i = 0; i < n; i++) {
    p[i] -= q[i];
    if(p[i] < 0) num++;
  }
  if(num > 1)
    cout << "NO" << endl;
  else cout << "YES" << endl;
  
}

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

main()
{
    unsigned long long int n,a,b,x,y;
    cin>>n>>a>>b;
    x=b-a;
    if(a!=1 && b!=n)
    {
        if((b-a)%2==0)
        {
            cout<<x/2<<endl;
        }
        else
        {
            x=a-1;
            y=n-b;
            if(y<x)
            {
                cout<<y+1+(n-(a+y+1))/2<<endl;
            }
            else
            {
                cout<<x+1+((b-x-1)-1)/2<<endl;
            }
        }
    }
    else if(a==1 && b!=n)
    {
        if((b-a)%2==0)
        {
            cout<<x/2<<endl;
        }
        else
        {
            cout<<(((b-1)-a)/2)+1<<endl;
        }
    }
    else if(a!=1 && b==n)
    {
         if((b-a)%2==0)
        {
            cout<<x/2<<endl;
        }
        else
        {
            cout<<((n-(a+1))/2)+1<<endl;
        }
    }
    else
    {
         if((b-a)%2==0)
        {
            cout<<x/2<<endl;
        }
        else
        {
            cout<<(((n-1)-a)/2)+1<<endl;
        }
    }
}

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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 1e5 + 7;

int n;
int x;
int y;
int res[N];
vector<pair<int, int>> g[N];
void dfs(int v, int p, int col){
    int c = 1;
    for(auto to: g[v]){
        if(to.first == p){
            continue;
        }
        if(col == c){
            c ++;
        }
        res[to.se] = c;
        dfs(to.first, v, c);
        c ++;
    }
}
int main()
{
    #ifdef FILEs
        freopen("input.txt", "r", stdin);
        /// freopen("output.txt", "w", stdout);
    #endif

    scanf("%d", &n);
    for(int i = 1; i < n; i ++){
        scanf("%d %d", &x, &y);
        g[x].push_back({y, i});
        g[y].push_back({x, i});
    }
    dfs(1, -1, -1);
    printf("%d\n", *max_element(res + 1, res + n));
    for(int i = 1; i < n; i ++){
        printf("%d\n", res[i]);
    }
}


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

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

    char l=s.at(11);

    for(int i=11; i>4; i--){
        s.at(i)=s.at(i-1);
    }

    s.at(4)=' ';

    cout << s << l << endl;
}

Measured memory_bytes: 256
N, L = list(map(int, input().split()))

apple_pie = 0
for i in range(1, N+1):
    apple_pie += L + i - 1

ab = []
for k in range(1, N+1):
    ab.append(abs(L + k - 1))

print(apple_pie - (L + ab.index(min(ab))  ))

Measured memory_bytes: 3060
#include <iostream>
#include <array>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;


int main()
{
	ll N, x;
	cin >> N >> x;
	vector<ll> A;
	for (size_t i = 0; i < N; i++)
	{
		int a;
		cin >> a;
		A.push_back(a);
	}
	ll sum = 0;
	for (auto a : A) {
		sum += a;
	}
	int index = 0;
	while (index+1<A.size())
	{
		if (A[index] + A[index + 1] <= x) {
			index++;
			continue;
		}
		int subrange = A[index] + A[index + 1] - x;
		A[index + 1] -= subrange;
		if (A[index + 1] < 0) {
			A[index] += A[index + 1];
			A[index + 1] = 0;
		}
	}
	for (auto a : A) {
		sum -= a;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a>=1&&a<=9&&b>=1&&b<=9)
	{
		cout<<a*b<<endl;
	}
	else
	{
		cout<<-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	Scanner sc=new Scanner(System.in);

    	int N=sc.nextInt();

    	int cntE=0;
    	int cntO=0;

    	for(int i=0;i<N;i++) {

    		int A=sc.nextInt();

    		if(A%2==0) {
    			cntE++;
    		}else {
    			cntO++;
    		}

    	}

    	int result=(int)Math.pow(3,N)-(int)Math.pow(2,cntE);

    	System.out.println(result);

    }

}



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

int main(){
	string t1("HIT"), t2("OUT"), t3("HOMERUN");
	int n;
	cin >> n;
	string s;
	for(int i = 0; i < n; i++){
		int out = 0;
		int count = 0;
		int point = 0;
		while(out != 3){
			cin >> s;
			if(s == t2){
				out++;
			}else if(s == t3){
				point += count + 1;
				count = 0;
			}else if(s == t1){
				if(count == 3) point++;
				else count++;
			}
		}
		cout << point << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
      // 準備するよ！
      long mod = 1_000_000_000 + 7;

      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long[] a = new long[n];
      for(int i=0; i<n; ++i) a[i] = sc.nextLong();

      // 解くよ！
      long ruiseki = 0;
      long ans = 0;
      for(int i=0; i<n; ++i) {
        ans     = (ans + a[i] * ruiseki) % mod;
        ruiseki = (a[i] + ruiseki) % mod;
      }

      System.out.println(ans);

    }
}

Measured memory_bytes: 62888
#include <iostream>
#include <utility>

using namespace std;

int search(int K, int S, int X, int Y)
{
  int Z = S - X - Y;
  return (Z >= 0 and Z <= K) ? 1 : 0;
}

int search(int K, int S, int X)
{
  int sum = 0;
  for (int Y = 0; Y <= min(K, S - X); ++Y)
    sum += search(K, S, X, Y);
  return sum;
}

int search(int K, int S)
{
  int sum = 0;
  for (int X = 0; X <= K; ++X)
    sum += search(K, S, X);
  return sum;
}


int main()
{
  int K, S;
  cin >> K >> S;
  cout << search(K, S) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define N 300010
using namespace std;
int to[8][2]={2,1,
			  3,5,
			  4,7,
			  6,1,
			  2,2,
			  5,5,
			  3,3,
			  2,1};
char s[N];
int f[N][8];
const int p=1e9+7;
int main()
{
	scanf("%s",s);
	int n=strlen(s);
	f[n][1]=f[n][5]=1;
	for(int i=n-1;i>=0;i--)
		for(int j=0;j<8;j++)
		{
			if(s[i]!='1') f[i][j]+=f[i+1][to[j][0]];
			if(s[i]!='0') f[i][j]+=f[i+1][to[j][1]];
			f[i][j]%=p;
		}
	printf("%d",f[0][0]);
	return 0;
} 

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

using namespace std;
using ll = long long;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()

#define READ(x) (cin >> (x))

#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))

int main() {
    // get values from input
    int X, Y, Z;
    cin >> X >> Y >> Z;
    // main procedure

    // output
    cout << Z << " " << X << " " <<  Y << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
    int N,M,X,Y;

    cin >> N >> M >> X >> Y;

    int xm = -100;
    int ym = 100;

    for(int i = 0; i < N; i++){
        int x;
        cin >> x;

        xm = max(x,xm);
    }

    for(int i = 0; i < M; i++){
        int y;
        cin >> y;

        ym = min(y,ym);
    }

    int Z = min(Y, ym);

    if(xm + 1 > Z || X + 1 > Z){
        cout << "War" << endl;

        return 0;
    }

    cout << "No War" << endl;
    

    return 0;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}



int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	ll n, lv[5];
	cin >>n;
	rep(i, 5) cin >>lv[i];
	VL hep(6); hep[0] =n;
	ll zx0, zx1, zx2;
	rep(i, 1000){
		repr(j, 4, 0){
			ll mn = min(hep[j], lv[j]);
			hep[j] -=mn; hep[j+1] += mn; 
		}
		if(hep[5] ==n){
			cout << i + 1<<"\n"; return 0;
		}
		if(i==999) zx0 = hep[5];
		if(i==998) zx1 = hep[5];
		if(i==997) zx2 = hep[5];
	}
	
	ll df = max(zx0 - zx1, zx1 - zx2);
	ll su = (n - zx0 + df -1)/ df;
	cout << 1000 + su <<"\n";
	return 0;
}


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

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin>>N;

	cout<<N*N*N<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int sum(int n);

int main()
{
	int n, a, b;
	int ans = 0;
	int sumn;

	scanf("%d %d %d", &n, &a, &b);

	for (int i = 1; i <= n; i++) {
		sumn = sum(i);

		if (sumn >= a && sumn <= b) {
			ans = ans + i;
		}
	}

	printf("%d\n", ans);

	return 0;
}

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

	while (n) {
		res = res + n % 10;
		n = n / 10;
	}

	return res;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

int main(){
  int A,B,C;
  cin >> A >> B;
  if(A<=8 && B <=8){
    cout << "Yay!";
  }else{
    cout<< ":(";
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int k = in.nextInt();
			long[] an = in.nextLongArray(k);

			long min = 0;
			long max = 100000000000000000L;

			long left = 0, right = max;
			long mid = (left + right) / 2;

			long v = 0;
			while (left < right) {
				v = g(mid, an);
				if (v >= 2) {
					right = mid;
				} else {
					left = mid + 1;
				}
				mid = (left + right) / 2;
			}
			if (g(mid, an) != 2) {
				out.println(-1);
				return;
			}
			min = mid;

			left = 0;
			right = max;
			mid = (left + right) / 2;

			while (left < right) {
				v = g(mid, an);
				if (v <= 2) {
					left = mid;
				} else {
					right = mid - 1;
				}
				mid = (left + right) / 2;
				if (right == (left + 1)){
					mid++;
				}
			}
			if (g(mid, an) != 2) {
				out.println(-1);
				return;
			}
			max = mid;

			out.println(min + " " + max);


		}

		static long g(long x, long[] an) {
			for (int i = 0; i < an.length; i++) {
				x = f(x, an[i]);
			}
			return x;
		}

		static long f(long x, long p) {
			return x - x % p;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


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

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			int a = gcd(i,j);
			for (int k = 1; k <= n; k++)
			{
				ans += gcd(a,k);
			}
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Atcoderrrrrrr
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int length = S.Length;

            int ans = 1001;
            for (int i = 0; i < length - 2; i++)
            {
                string rawX = S.Substring(i, 3);
                int X = int.Parse(rawX);

                int maybeans = Math.Abs(X - 753);
                if (maybeans < ans)
                {
                    ans = maybeans;
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
a=int(input())
b=int(input())
c=int(input())
x=int(input())
res=0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            tmp=i*500+j*100+k*50
            if tmp==x:
                res+=1
print(res)

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

int main(){
  string S;
  cin >> S;
  int N = S.size();
  vector<char> X(N), A(N), B(N);
  
  int a = 0,b = 0;
  for(int i = 0; i < N ; i++){
    if(i %2 == 0){
      A[i] = '0'; 
      B[i] = '1';
    } else {
      A[i] = '1';
      B[i] = '0';
    }
    X[i] = S[i];
    
    if(A[i] != X[i]){
      a += 1;
    }
    if(B[i] != X[i]){
      b += 1;
    }
    
  }
  
  cout << min(a,b) << endl;
}

Measured memory_bytes: 640
//
// Created by 永徳泰明 on 2019-01-20.
//

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;
#define dump(x)  cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define fill(x, y) memset(x,y,sizeof(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 999999999;

void readFromInputFile() {
#ifdef LOCAL
    static std::ifstream in("/Users/hoo/CLionProjects/for_atcoder/input");
    std::cin.rdbuf(in.rdbuf());
#endif
}
int N;

void plus_h(int i, int num, vector<int> &h) {
    h[i] += num;
    if (i < N-1 && h[i] - num == h[i+1]) {
        plus_h(i+1, num, h);
    }
}

int main() {
    readFromInputFile();
    cin>>N;
    vector<int> h;
    set<int, greater<> > k;
    rep(i,N){
        int t;
        cin>>t;
        h.push_back(t);
        k.insert(t);
    }

    int count = 0;
    while(k.size() != 1) {
        int max = *k.begin();

        rep(i,N){
            if(h[i]==max){
                plus_h(i, -1, h);
                count += 1;
                k.insert(max-1);
                k.erase(max);
            }
        }
    }
    cout<<count+*k.begin()<<endl;

    return 0;
}


Measured memory_bytes: 256
entierAConvertir = int(input())
baseArrivee= 26 
sortie = []
while entierAConvertir>0:
  reste = entierAConvertir % baseArrivee
  if reste==0:
    reste = 26
  sortie.append(reste)
  entierAConvertir-=reste
  entierAConvertir = (entierAConvertir//baseArrivee)
for i in range(len(sortie)):
  print(chr(sortie[len(sortie)-1-i]+ord('a')-1),end="")

Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, x;
  double a1, b1, d;
  cin >> a >> b;
  a1 = a;
  b1 = b;
  c = (a+b)/2;
  d = (a1+b1)/2-c;
  x = c + 2*d;
  cout << x << endl;
}

Measured memory_bytes: 3576
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func strintToInt(s string) int {
	i, _ := strconv.Atoi(s)
	return i
}

func main() {
	s := ""
	fmt.Scan(&s)
	N := strintToInt(s)
	sum := 0
	for _, digit := range strings.Split(s, "") {
		sum += strintToInt(digit)
	}
	if N%sum == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

const ll p = 7LL + 1e9;

ll mod_exp(ll a, ll b)
{
    if(b==0LL) return 1LL;
    
    ll ans = mod_exp(a,ll(b/2LL));
    ans*=ans;
    ans%=p;
    
    if(b%2LL==1LL) ans*=a;
    ans%=p;
    
    return ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif
	
	// cout << mod_exp(10,100) << endl;
	
	int n,k;
	cin>>n>>k;
	
	ll ans=0LL;
	
	for(int i=k; i<=n+1; i++)
	{
	    ans += ll(n-i+2) + ll(i-1)*ll(n-i+1);
	    ans %= p;
	}
	
	cout << ans << "\n";
}

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

int main()
{
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    char n = 'A' - 'a';
    char a, b, c;
    a = (char)(s1.at(0) + n);
    b = (char)(s2.at(0) + n);
    c = (char)(s3.at(0) + n);

    cout << a<<b<<c << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

ll n, k;

int main() {
    cin >> n >> k;
    ll ans = 0;
    for(ll b = 1; b <= n; ++b) {
        ll sub = max(b-k, 0LL);
        ll sum = (n/b)*sub;
        ll rest = n - (n/b)*b;
        sum += max(0LL, rest-k+1);
        ans += sum;
    }
    if(k == 0) cout << ans-n << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    int K,  A, B;
    cin >> K >> A >> B;
    int temp = A / K;
    if ((double)temp == (double) A / K){
        if(K * temp >= A && K * temp <= B) cout << "OK" << endl;
        else cout << "NG" << endl;
    }else{
        if(K * (temp + 1) >= A && K *(temp + 1) <= B) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
}


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

int main(){
    int n;
    ll lim, w1, maxv = 0;
    cin >> n >> lim;
    vector<ll> vec[4], vsum[4];
    rep(i, n){
        ll ww, vv;
        cin >> ww >> vv;
        if(i == 0) w1 = ww;
        vec[ww - w1].push_back(vv);
    }
    rep(i, 4){
        sort(vec[i].begin(), vec[i].end());
        reverse(vec[i].begin(), vec[i].end());
    }
    rep(i, 4){
        vsum[i].push_back(0);
        rep(j, vec[i].size())
            vsum[i].push_back(vsum[i][j] + vec[i][j]);
    }
    
    rep(x, vec[0].size()+1)
        rep(y, vec[1].size()+1)
            rep(z, vec[2].size()+1)
                rep(w, vec[3].size()+1){
                    if(x*w1 + y*(w1+1) + z*(w1+2) + w*(w1+3) > lim)
                        continue;
                    maxv = max(maxv,
                        vsum[0][x] + vsum[1][y]
                        + vsum[2][z] + vsum[3][w]);
                }
    
    cout << maxv << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdlib.h>
#include<stdio.h>

int Max(int c, int d)
{
    return c>d?c:d;
}

int main()
{
    int n, a, b, c, d;
    scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
    char s[n+1];
    int flag = 0;
    
    scanf("%s", s);

    for(int i = a - 1 ; i < Max(c, d); i++){
        if(s[i] == '#' && s[i+1] == '#'){
            printf("No");
            return 0;
        }
    }

    if(c > d){
        for(int i = b-2; i < d - 1; i++){
            if(s[i] == '.' && s[i+1] == '.' && s[i+2] == '.'){
                flag = 1;
            }
        }
        if(flag == 0){
            printf("No");
            return 0;
        }                    
    }
    
    
               
    printf("Yes");    
    return 0;
}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int array[] = new int[3];
        array[0] = sc.nextInt();
        array[1] = sc.nextInt();
        array[2] = sc.nextInt();
        Arrays.sort(array);
        System.out.println(array[0]+" "+array[1]+" "+array[2]);
    }
}


Measured memory_bytes: 26144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

set<vector<int>> choice;
void dfs(vector<int> &A)
{
  vector<int> temp = A;
  SORT(temp);
  choice.insert(temp);

  // 数列の長さが N に達したら打ち切り
  if (A.size() == 6)
    return;

  for (int v = 0; v < 6; ++v)
  {
    bool is_ok = true;
    rep(i, A.size())
    {
      if (A[i] == v)
      {
        is_ok = false;
      }
    }

    if (!is_ok)
      continue;
    A.push_back(v);
    dfs(A);
    A.pop_back();
  }
}

int K;
bool ok(vector<int> h, vector<int> w, vector<string> c)
{
  rep(ih, h.size())
  {
    rep(i, c[0].size())
    {
      if (h[ih] >= c.size())
        return false;
      c[h[ih]][i] = 'r';
    }
  }

  rep(iw, w.size())
  {
    rep(i, c.size())
    {
      if (w[iw] >= c[0].size())
        return false;
      c[i][w[iw]] = 'r';
    }
  }
  int count = 0;
  rep(H, c.size()) rep(W, c[0].size())
  {
    if (c[H][W] == '#')
      count++;
  }

  if (count == K)
  {
    /*
    rep(i, h.size())
    {
      cout << h[i] << " ";
    }
    cout << endl;
    rep(i, w.size())
    {
      cout << w[i] << " ";
    }
    cout << endl;

    rep(i, c.size())
    {
      cout << c[i] << endl;
    }
    cout << endl;
    */
    return true;
  }

  return false;
}

int main()
{
  int H, W;
  cin >> H >> W >> K;
  vector<string> c(H);
  rep(i, H)
  {
    cin >> c[i];
  }
  int ans = 0;
  vector<int> a;
  dfs(a);
  for (vector<int> h : choice)
  {
    for (vector<int> w : choice)
    {
      if (ok(h, w, c))
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#入力
input = input()

text = ''

#操作
for i in range(len(input)):
   if input[i] == '0':
      text = text + '0'
   elif input[i] == '1':
      text = text + '1'
   elif input[i] == 'B':
      if text != '':
         text = text[:-1]

#出力
print(text)

Measured memory_bytes: 8980
#include<stdio.h>
int power(int x, int y)
{
	int power = 1;
	for (int i = 0; i < y; i++) {
		power *= x;
	}
	return power;
}
int main(void)
{
	int X, max = 0;
	scanf("%d", &X);
	for (int i = 1; i <= X; i++) {
		for (int j = 9; j >= 2; j--) {
			if (power(i, j) <= X) {
				if (power(i, j) >= max) {
					max = power(i, j);
				}
			}
		}
	}
	printf("%d", max);
	return 0;
}

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

int main(){
    int n,t;cin >> n >> t;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> lmin(n),rmax(n);
    int mini = 1e9;
    rep(i,n){
        mini = min(mini,a[i]);
        lmin[i] = mini;
    }
    int mx = 0;
    rep(i,n){
        mx = max(mx,a[n-1-i]);
        rmax[n-1-i] = mx;
    }
    int d = 0;
    int left;
    int cnt = 0;
    rep(i,n-1){
        if(d < rmax[i+1]-lmin[i]){
            cnt = 1;
            left = lmin[i];
            d = rmax[i+1]-lmin[i];
        }else if(d == rmax[i+1]-lmin[i] && lmin[i] != left) {
            cnt++;
            left = lmin[i];
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1408
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define f first
#define s second
#define y1 yasfasf
#define kz ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILE "substring"
#define fr freopen(FILE".in", "r", stdin); freopen(FILE".out", "w", stdout);
using namespace std;
typedef pair <int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef struct node* treap;

const int N = 3e5 + 11, inf = 1e9;
const ll linf = 1e18, mod = 1e9 + 7;

int n, a[N], ans;

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i){
		int x;
		scanf("%d", &x);
		a[x]++;
	}
	for(int i = 1; i <= 100000; ++i)
		ans = max(ans, a[i - 1] + a[i] + a[i + 1]);
	cout << ans;	
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
double eps = 1e-8;
double PI = acos(-1);
double equals(double a, double b){
  return (-eps<a-b&&a-b<eps);
}
 
double dot(P a,P b){
  return real(b*conj(a));
}
double cross(P a,P b){
  return imag(b*conj(a));
}
struct C{
  P p;
  double r;
  C(){}
  C(P p,double r) : p(p),r(r) {}
};
 
int ccw( P p, P a, P b ){
  a -= p;
  b -= p;
  if( cross( a, b ) > eps ) return 1; //ue
  if( cross( a, b ) < -eps ) return -1; //shita
  if( dot( a, b ) < -eps ) return 2;
  if( norm(b) - norm(a) > eps ) return -2;
  return 0;
}
 
int isIntersect(C a,C b){
  double x=a.p.real()-b.p.real();
  double y=a.p.imag()-b.p.imag();
  double s=a.r+b.r;
  double d=x*x+y*y;
  s *= s;
  if( equals(d, s))return 1;
  if(d>s)return 0;
  double r = abs(a.r-b.r);
  r *= r;
  if(equals(d, r))return -1;
  if(d > r)return 2;
  return -2;
}
 
vector<P> getCrossP(C c1,C c2){
  vector<P> v;
  int cp=isIntersect(c1,c2);
  if(cp==0||cp==-2)return v;
   
  double ll = norm(c1.p-c2.p);
  double A=(c1.r*c1.r-c2.r*c2.r + ll ) / (2.0*ll);
  P base = c2.p - c1.p;
  if(abs(cp)==1){
    v.push_back(c1.p+A*base);
  }else{
    P n(-base.imag(),base.real());
    n /= abs(n);
    double h=sqrt(abs( c1.r*c1.r - A*A*ll ));
    v.push_back(c1.p + A*base + h*n);
    v.push_back(c1.p + A*base - h*n);
  }
  return v;
}
 
int n;
C t[105];
typedef pair<double,double> Pair;
 
double solve(int id){
  P op=t[id].p;
 
  vector<Pair> vec;
  for(int i=0;i<n;i++){
    if(i==id)continue;
    vector<P> k=getCrossP(t[i],t[id]);
    if(k.size()<2)continue;
    P sp=k[0],tp=k[1];
    if( ccw(op, t[i].p, sp) == 1 ){
      swap(sp,tp);
    }
    double sarg=arg(sp-op);
    if(sarg<0)sarg+=2.0*PI;
 
    double targ=arg(tp-op);
    if(targ<0)targ+=2.0*PI;
    //    if( id == 0 )cout<<sarg/PI<<' '<<targ/PI<<'!'<<endl;
 
    if(sarg<targ){
      vec.push_back( Pair( sarg,targ  ) );
    }else{
      vec.push_back( Pair( 0 , targ ) );
      vec.push_back( Pair( sarg , 2.0*PI ) );
    }
 
  }
  sort(vec.begin(),vec.end());
  int size=vec.size();
  double sum=0;
  for(int i=0;i<size;i++){
    Pair e=vec[i];
    if(i+1==size ||  e.second < vec[i+1].first){
      sum+=(e.second-e.first);
    }else{
      vec[i+1].first=min(vec[i+1].first, e.first);
      vec[i+1].second=max(vec[i+1].second, e.second);
    }
  }
 
  return (2.0*PI-sum)*t[id].r;
}
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      double x,y,r;
      cin>>x>>y>>r;
      t[i]=C( P(x,y) , r );
 
      for(int j=0;j<i;j++){
        assert( t[i].r!=t[j].r || t[i].p!=t[j].p);
      }
    }
     
    double ans=0;
    for(int i=0;i<n;i++){
      bool flg=false;
      for(int j=0;j<n;j++){
        if(i==j)continue;
        if( isIntersect(t[i],t[j]) < 0 && t[i].r < t[j].r){
          flg=true;
        }
      }
      if(flg)continue;
      ans+=solve(i);
    }
    printf("%.10f\n",ans);
  }  
  return 0;
}

Measured memory_bytes: 1328
#include<cctype>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;int n,m,li,ri,l,r;
LL s[100010];
inline LL read()
{
	char c;LL d=1,f=0;
	while(c=getchar(),!isdigit(c)) if(c=='-') d=-1;f=(f<<3)+(f<<1)+c-48;
	while(c=getchar(),isdigit(c)) f=(f<<3)+(f<<1)+c-48;
	return d*f;
}
signed main()
{
	n=read();m=read();
	for(register int i=1;i<=n;i++)
	{
		li=read();ri=read();
		s[li]++;s[ri+1]--;
		li--;
		for(l=1;l<=li;l=r+1)
		{
			r=min(li/(li/l),ri/(ri/l));
			if(li/l!=ri/l) s[l]++,s[r+1]--;
		}
	}
	for(register int i=1;i<=m;i++)
	{
		s[i]+=s[i-1];
		printf("%lld\n",s[i]);
	}
}

Measured memory_bytes: 2356
n,a,b=map(int,input().split())
s=input()
w=a+b
a=""
for i in range(len(s)):
  if w<1:
    a+="N"
  elif s[i]=="a":
    a+="Y"
    w-=1
  elif s[i]=="b" and b>0:
    a+="Y"
    b-=1
    w-=1
  else:
    a+="N"
for c in a:
  print(("No","Yes")[c=="Y"])


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

using namespace std;

int main() {
    int x, y;
    cin >> x >> y;
    // a + b = x, 2a + 4b = y;
    // 2 * (x - b) + 4b = y
    // 2x + 2b = y
    // (y - 2x) % 2 == 0;
    int b = (y - 2 * x) / 2;
    int a = x - b;
    if (a >= 0 && b >= 0 && (a + b) == x && (2 * a + 4 * b) == y)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <malloc.h>
#include <stack>
#include <cstring>
#include <string>
#include <set>
#include <unordered_map>
#define INT long long int
#define MOD 1000000007
#define oo 987654321
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    string a[110], b[110];
    int n, m;
    cin>>n>>m;
    for(int i = 0 ; i < n ; i++ ) cin>>a[i];
    for(int j = 0 ; j < m ; j++ ) cin>>b[j];
    for(int i = 0 ; i <= n-m ; i++ ) for(int j = 0 ; j <= n-m ; j++ )
    {
        int cnt = 0;
        for(int ii = i ; ii < i+m ; ii++ ) for(int jj = j ; jj < j+m ; jj++ )
        {
            if( a[ii][jj] == b[ii-i][jj-j] ) cnt++;
        }
        if( cnt == m*m )
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
int main(){
  char N[200001];
  scanf("%s", N);
 
  int S=0;
  int k=0;
  int L=strlen(N);
  
  while(k<L){
    S=S+N[k]-'0';
    k++;
  }
  
  if(S%9==0) printf("Yes\n");
  else printf("No\n");
  
  return 0;
}

Measured memory_bytes: 1816
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
less_x = 0
for i in range(m):
    if a[i] < x: less_x += 1
print(min(less_x,m - less_x))

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

signed main(void)
{
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.rbegin(), a.rend());
	cout << 10 * a[0] + a[1] + a[2] << endl;
	return 0;
}


Measured memory_bytes: 256