akhauriyash/Code-Regression huggingface dataset:
n,m,d=map(int,input().split())
mp=[input() for _ in range(n)]
t='.'*d
cnt=0
for i in range(n):
    for j in range(m):
        if j<=m-d and mp[i][j:j+d]==t:
            cnt+=1
        if i<=n-d:
            ns=''
            for l in range(d):
                ns+=mp[i+l][j]
                if ns==t:
                    cnt+=1
print(cnt)


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

int main(){
	int n;
	cin>>n;
	char c[n];
	for(int i=0;i<n;i++){
		cin>>c[i];
		if(c[i]=='Y'){
			cout<<"Four";
			return 0;
		}
	}
	cout<<"Three";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
 
int main(){
    int N;
    cin >> N;
    vector<int> vec(N);

    for(int i=0;i<N;i++){
        cin >> vec.at(i);
    }

    int b=1;
    for(int i=0;i<N;i++){
        /*
        for(int x: vec){
            cout << x;
        }
        cout << endl;
        */

        b = vec.at(b-1);
        // cout << "b=" << b << endl;
       
        if(b == 2){
            cout << i+1;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0; 
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define hii cout << "hii" << endl
#define int ll
#define endl '\n'
#define all(s) s.begin(), s.end()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

const int N = 5e5 + 5;
const int MAX = 250000 + 5;
const int M = 3e5;
const int mod = 998244353;
const int MOD = 998244353;
const int INF = 1e15;
const int LG = 21;

int arr[N];

void solve()
{
	map<int, int> cnt;
	int n;
	cin >> n;
	int x;
	cin >> x;
	swap(x, n);
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
		cnt[arr[i]]++;
	}
	int diff = mod;
	int ans = mod;
	for(int i = -1000; i <= 1000; i++)
	{
		if(cnt[i]) continue;
		int temp = abs(i - x);
		if(temp < diff)
		{
			diff = temp;
			ans = i;
		}
	}
	cout << ans << endl;
}
 
int32_t main() 
{	
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define ITR(x, c) for(__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans = 0;
int main() {
    char X;
    cin>>X;
    cout<<char(X+1)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int asumisu(int mizuhasu) {
	int kugyu = 0;
	while (mizuhasu > 0) {
		kugyu += mizuhasu % 10;
		mizuhasu /= 10;
	}
	return kugyu;
}

int main(void) {
	int N;
	if (scanf("%d", &N) != 1) return 1;
	puts(N % asumisu(N) == 0 ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EMP emplace
#define EMPB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

const int MAX_N = 1000010;
vector<int> prime;
bool is_prime[MAX_N];

int sieve(int n) {
  for (int i = 0; i <= n; i++) is_prime[i] = true;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime.push_back(i);
      for (int j = i*i; j <= n; j += i) is_prime[j] = false;
    }
  }
  return prime.size();
}

int Q;
int l[100010], r[100010];
int cum[100010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  sieve(100010);
  for (int i = 3; i < 100010; i += 2) {
    if (is_prime[i] && is_prime[(i+1)/2]) cum[i]++;
  }
  REP(i, 100009) cum[i+1] += cum[i];
  cin >> Q;
  REP(i, Q) {
    cin >> l[i] >> r[i];
    cout << cum[r[i]] - cum[l[i]-1] << endl;
  }

  return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    double r,S,l,pai;
    scanf("%lf",&r);
    pai=3.141592653589;
    l=2*pai*r;
    S=pai*r*r;
    printf("%.8f %.8f",S,l);
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3316
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
//#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
string s1,s2;
int dp[1000][1000];
int main()
{
	cin>>s1>>s2;
	rep(i,s1.size()){
		rep(j,s2.size()){
			dp[i][j]=1000000;
		}
	}
	if(s1[0]==s2[0]) dp[0][0]=0;
	else dp[0][0]=1;
	rep1(i,s1.size()-1){
		dp[i][0]=dp[i-1][0]+1;
		if(s1[i]==s2[0]){
			dp[i][0]=i;
		}
	}
	rep1(j,s2.size()-1){
		dp[0][j]=dp[0][j-1]+1;
		if(s1[0]==s2[j]){
			dp[0][j]=j;
		}
	}
	rep1(i,s1.size()-1){
		rep1(j,s2.size()-1){
			dp[i][j]=min(dp[i-1][j-1], min(dp[i-1][j],dp[i][j-1]) ) +1;
			if(s1[i]==s2[j]) dp[i][j]=min(dp[i][j],dp[i-1][j-1]);
		}
	}
	cout<<dp[s1.size()-1][s2.size()-1]<<endl;
}


Measured memory_bytes: 7100
#include <boost/multiprecision/cpp_int.hpp>
#include <iostream>

int main() {
  using namespace std;
  namespace mp = boost::multiprecision;
  // 任意長整数型
  using Bint = mp::cpp_int;

  Bint UB = pow(Bint(10), 80);
  int n;
  cin >> n;
  while (n--) {
      Bint a, b;
      cin >> a >> b;
      Bint c = a + b;
      if (a >= UB || b >= UB || c >= UB) {
          cout << "overflow";
      } else {
          cout << c;
      }
      cout << endl;
  }
}



Measured memory_bytes: 3084
#include <stdio.h>

int main(){
	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	int sum = 0;

	for (int i=1; i<=n; i++){
		int c = 0;
		int temp = i;
		for (int j=0; j<5;j ++){
			c += temp % 10;
			temp /= 10;
		}
		if (c >= a && c <= b){
			sum += i;
		}
	}

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

	return 0;
}


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

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int sum = 0;
	int n_1 = 0, n_2 = 0, n_3 = 0, n_4 = 0, n_5 = 0, n_sum = 0;
	for (int i = 0; i <= n; ++i) {
		n_1 = i % 10;
		n_2 = (i / 10) % 10;
		n_3 = (i / 100) % 10;
		n_4 = (i / 1000) % 10;
		n_5 = (i / 10000) % 10;
		n_sum = n_1 + n_2 + n_3 + n_4 + n_5;
		if (a <= n_sum && n_sum <= b) {
			sum += i;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] L = new int[N];

		for (int i=0; i < N; i++){
			L[i] = sc.nextInt();
		}

		Arrays.sort(L);
		int ans=0;
		for (int i=0; i < N - 2; i++){
			for (int j=i+1; j < N-1; j++){
				int minus = L[j] - L[i];
				int plus = L[i] + L[j];
				for (int k=j+1; k < N; k++){
					if (L[k] >= plus){
						break;
					}
					ans++;
				}
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 26256
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

const ll MOD=998244353;
int main(){
    int N;
    cin>>N;
    vector<int> cnt(N);
    for(int i=0;i<N;i++){
        int d;
        cin>>d;
        if(i==0 && d!=0){
            cout<<0<<endl;
            return 0;
        }
        if(i!=0 && d==0){
            cout<<0<<endl;
            return 0;
        }
        cnt[d]++;
    }
    // cerr<<cnt[0]<<endl;
    ll res=1;
    for(int i=1;i<cnt.size();i++){
        if(cnt[i]==0) continue;
        // cerr<<"#"<<i<<" "<<cnt[i-1]<<endl;
        for(int j=0;j<cnt[i];j++) res=res*cnt[i-1]%MOD;
    }
    cout<<res<<endl;
    
    
    return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int> pos(n + 1, -1);
    for (int i = 1; i <= n; i++) {
        int a; cin >> a;
        pos[a] = i;
    }
    vector<int> pr(n + 2), ne(n + 2);
    for (int i = 0; i <= n + 1; i++) {
        pr[i] = i - 1, ne[i] = i + 1;
    }
    long long ans = 0;
    for (int a = n; a >= 1; a--) {
        int i = pos[a];
        ans += 1LL * a * (i - pr[i]) * (ne[i] - i);
        pr[ne[i]] = pr[i];
        ne[pr[i]] = ne[i];
    }
    cout << ans << endl;
    return 0;
}

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



int main() {
  string S;
  cin >> S;
  bool flag = false;
  for(int i = 0;i<S.size()-1;i++){
      if(S[i] == 'A' && S[i+1] == 'C'){
          flag = true;
          break;
      }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};


int main(){
    string S,T; cin >> S >> T;
    vector<int> s(26,-1);
    vector<int> t(26,-1);
    for(int i=0;i<S.length();i++){ //文字列すべてを探索
        if(s[S[i]-'a']==-1 && t[T[i]-'a']==-1){//まだ出てきていない
            s[S[i]-'a'] = T[i]; //交換する
            t[T[i]-'a'] = S[i]; //交換する
        }else{ //すでにどこかしらと交換している
            if(s[S[i]-'a']!=T[i] || t[T[i]-'a']!=S[i]){ //交換先が異なっている
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

double probability_heads[3003][3003];
int main()
{
    int no_of_coins;
    cin >> no_of_coins;
	double probability[no_of_coins];
    for(int i = 1; i <= no_of_coins; i++)
        cin >> probability[i];

    memset(probability_heads, 0, sizeof(probability_heads));
    probability_heads[0][0] = 1;

    for(int i = 1; i <= no_of_coins; i++)
    {
        double head_event = probability[i], tail_event = 1 - probability[i];

        probability_heads[0][i] = tail_event*probability_heads[0][i - 1];

        for(int heads = 1; heads <= i; heads++)
        {
            probability_heads[heads][i] = head_event*probability_heads[heads - 1][i - 1] + tail_event*probability_heads[heads][i - 1];
        }
    }

    double answer = 0;
    for(int i = no_of_coins/2 + 1; i <= no_of_coins; i++)
        answer += probability_heads[i][no_of_coins];

    cout << setprecision(9) << answer;
    return 0;
}

Measured memory_bytes: 74220
#include <stdio.h>
#define k_max 2000001
int size=0;
int que[k_max];
#define swap(a,b){int temp=que[a]; que[a]=que[b]; que[b]=temp;}

int max_index(int ,int );
void insert(int);
int extract();

int main(){
  char ope[10];
  int i,j,k;
  
  while(1){
    scanf("%s",ope);
    if(ope[0]=='i'){
      scanf("%d",&k);
      insert(k);
    }
    if(ope[0]=='e'){
      if(ope[1]=='x')
	printf("%d\n",extract());
      if(ope[1]=='n') break;
    }
  }
  return 0;
}


int max_index(int a,int b){
  if(que[a]>que[b]) return a;
  else return b;
}

void insert(int k){
  int i;
  
  size++;
  que[size]=k;
  i=size;
  
  while(que[i]>que[i/2] && i>1){
    swap(i,i/2);
    i=i/2;
  }
}

int extract(){
  int key=que[1];
  int i, node_max;
  
  que[1]=que[size];
  size--;
  i=1;
  
  while(i*2 <= size ){
    if(i*2+1 <= size)
      node_max=max_index(i*2,i*2+1);
    else node_max=i*2;
    if(max_index(node_max,i)==node_max){swap(node_max,i);i=node_max;}
    else break;    
  }
  return key;
}





Measured memory_bytes: 5696
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
 ll n; cin>>n;
  vector<pair<ll,ll>>v;
  rep(i,n){
  ll t; cin>>t;
    v.push_back(pair<ll,ll>(t,i+1));
  }
    sort(all(v));
    for(pair<ll,ll>x:v){
    if(x.first==n) cout<<x.second<<endl;
     else  cout<<x.second<<" ";
      
    }
  
  
  
}

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

int c1[26], c2[26];
vector< int > a, b;

int main(){
	string s, t; cin >> s >> t;
	for(int i = 0; i < s.size(); ++i) c1[s[i] - 'a']++;
	for(int i = 0; i < t.size(); ++i) c2[t[i] - 'a']++;
	for(int i = 0; i < 26; ++i){
		if(c1[i]) a.push_back(c1[i]);
		if(c2[i]) b.push_back(c2[i]);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	if(a.size() != b.size()) return cout << "No\n" , 0;
	
	bool ok = 1;
	for(int i = 0; i < a.size(); ++i) if(a[i] != b[i]){
		ok = 0;
		break;
	}
	cout << (ok ? "Yes" : "No") << "\n";
	return 0;
}

Measured memory_bytes: 776
n = int(input())
a = list(map(int, input().split()))
ruiseki = [0]*(n+1)

for i in range(n):
    ruiseki[i+1] = ruiseki[i] + a[i]

ans = 0
memo = {}
for i in range(n + 1):
    if ruiseki[i] not in memo:
        memo[ruiseki[i]] = 1
    else:
        ans += memo[ruiseki[i]]
        memo[ruiseki[i]] += 1

print(ans)

Measured memory_bytes: 41400
from typing import List


def rec(i: int, tmp_sum: int, A_list: List[int], sum_list: List[bool]):
    if tmp_sum > 2000:
        return
    elif i == len(A_list):
        sum_list[tmp_sum] = True
        return

    rec(i + 1, tmp_sum + A_list[i], A_list, sum_list)
    rec(i + 1, tmp_sum, A_list, sum_list)


def main():
    n = int(input())
    A_list = list(map(int, input().split()))
    q = int(input())
    m_list = list(map(int, input().split()))

    sum_list = [False for _ in range(2001)]

    rec(0, 0, A_list, sum_list)

    for m in m_list:
        if sum_list[m]:
            print("yes")
        else:
            print("no")


if __name__ == "__main__":
    main()



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

int main() {
  int n;
  cin >> n;
  if(n / 1000 == 0) cout << "ABC" << endl;
  else cout << "ABD" << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
         
        #define x first
        #define y second
         
        using namespace std;
         
        typedef long long ll;
        typedef long double ld;
        typedef vector<int> vi;
        typedef vector<vi> vvi;
        typedef pair<int,int> ii;
        typedef pair<ll,ll> pll;
         
        int N,M;
        //set<ii> al[100000];
        int dist[100000];
        queue<int> q;
        //set<int> vis;
    vi tounset;
         
        vector<pair<ii,int>> al[100000];
         
        bool vis[100000];
        void dfs(int i,int k,int di) {
        	if (vis[i]) return;
        	vis[i]=1;
    tounset.push_back(i);
        	if (dist[i]==INT_MAX) {
        		dist[i]=di;
        		q.push(i);
        	}
        	//auto U=upper_bound(al[i].begin(),al[i].end(),ii{k,INT_MAX});
        	int ct=lower_bound(al[i].begin(),al[i].end(),pair<ii,int>({k,0},0))-al[i].begin();
        		for (;ct<al[i].size() && al[i][ct].x.x==k;ct++) {
        		//	it!=al[i].end() && it->x.x==k;it++) {
        	//for (auto it=lower_bound(al[i].begin(),al[i].end(),ii{k,0});it!=U;) {
        		int j=al[i][ct].x.y;
        		//cout << al[i].size() << endl;;
        		//al[i].erase(prev(++it));
        		//cout << al[i].size();
        		//cout << "ho" << endl;
        		al[i][ct].y=1;
        		dfs(j,k,di);
        		//cout << "hi" << endl;
        	}
        	//vis[i]=0;
        }
         
        int main() {
        	ios::sync_with_stdio(0);
        	cin >> N >> M;
        	fill(dist+1,dist+N,INT_MAX);
        	for (int c=0;c<M;c++) {
        		int i,j,k;
        		cin >> i >> j >> k;
        		i--;j--;
        		al[i].push_back({{k,j},0});
        		al[j].push_back({{k,i},0});
        	}
         
        	for (int i=0;i<N;i++) sort(al[i].begin(),al[i].end());
         
        	q.push(0);
        	while (!q.empty()) {
        		int i=q.front();q.pop();
        		//while (!al[i].empty()) {
        			//cout << "Helle" << endl;
        			for (int c=0;c<al[i].size();c++) if (al[i][c].y==0)
        				{dfs(i,al[i][c].x.x,dist[i]+1);
    while (!tounset.empty()) {
       vis[tounset.back()]=0;
    tounset.pop_back();
    }}
        			//vis.clear();
        		//}
        	}
         
        	if (dist[N-1]==INT_MAX) cout << -1 << endl;
        	else cout << dist[N-1] << endl;
        }

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

int main() {
  int N,P,W,G,Y;
  cin >> N;
  P=0;
  W=0;
  G=0;
  Y=0;
  
  for (int i=0 ; i < N ; i++ ){
    string x;
    cin >> x;
    if (x == "P") P += 1;
    else if (x == "W") W += 1;
    else if (x == "G") G += 1;
    else if (x == "Y") Y += 1;
  }
  
  if(P != 0 && W != 0 && G != 0 &&Y != 0)
    cout << "Four"<<endl;
  else cout << "Three"<< endl;
 
}



Measured memory_bytes: 256
"use strict";
function Main(input) {
    let lines = input.split("\n");
    let nk = lines.shift().split(/\s/).map((v) => v - 0);
    let N = nk[0], K = nk[1];
    let S = lines.shift().trim();
    let Nums = [];
    let now = 1;
    let cnt = 0;
    for (let i = 0; i < N; i++) {
        if (S.charAt(i) == now) cnt++;
        else {
            Nums.push(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if (cnt != 0) Nums.push(cnt);
    if (Nums.length % 2 == 0) Nums.push(0);
    let Add = 2 * K + 1;
    let ans = 0;
//累積和を作る
    let sum = new Array(Nums.length - 1);
    sum[0] = 0;
    for (let i = 0; i < Nums.length; i++) {
        sum[i + 1] = sum[i] + Nums[i];
    }
    for (let i = 0; i < Nums.length; i += 2) {
        let left = i;
        let right = Math.min(i + Add, Nums.length);
        let tmp = sum[right] - sum[left];
        ans = Math.max(tmp, ans);
    }
    console.log(ans);
}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

class SCC {
	public:
	static const int MV = 10000;
	vector<vector<int> > grp; int NV,cmp[MV];
	vector<int> E[MV], RE[MV], NUM; int vis[MV];
	void init(int NV) { this->NV=NV; for(int i=0;i<MV;i++) { E[i].clear(); RE[i].clear();}}
	void add(int x,int y) { E[x].push_back(y); RE[y].push_back(x); }
	void dfs(int cu) { vis[cu]=1; for(int i=0;i<E[cu].size();i++) if(!vis[E[cu][i]]) dfs(E[cu][i]); NUM.push_back(cu); }
	void revdfs(int cu, int ind) {vis[cu]=1; cmp[cu]=ind; grp[ind].push_back(cu);
		for(int i=0;i<RE[cu].size();++i) if(!vis[RE[cu][i]]) revdfs(RE[cu][i],ind);}
	void scc() {
		int c=0; grp.clear(); grp.resize(MV); NUM.clear();
		memset(vis,0,sizeof(vis)); for(int i=0;i<NV;i++) if(!vis[i]) dfs(i);
		memset(vis,0,sizeof(vis)); for(int i=NUM.size()-1;i>=0;i--) if(!vis[NUM[i]])
			{ grp[c].clear(); revdfs(NUM[i],c); sort(grp[c].begin(),grp[c].end()); c++;}
		grp.resize(c);
	}
};

int n, m, a, b, q;
SCC s;

int main() {
	cin >> n >> m;
	s.init(n);
	for (int i = 0; i < m; ++i) {
		cin >> a >> b;
		s.add(a,b);
	}
	s.scc();
	cin >> q;
	while (q--) {
		cin >> a >> b;
		cout << (s.cmp[a]==s.cmp[b]) << endl;
	}
}


Measured memory_bytes: 4672
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)

	r := nextInt()

	fmt.Println(3 * r * r)
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void)
{
    int r, g, b, k;
    int s = 0;
   
    cin >> r >> g >> b;
    cin >> k;

    for (int i = 0; i <= k; i++)
    {
        if (g <= r)
        {
            g = g * 2;
            s += 1;
            // printf("r=%d,g=%d,b=%d\n", r, g, b);
            // printf("s=%d\n", s);
        }
    }

    for (int i = s + 1; i <= k; i++)
    {
        if (b <= g)
        {
            b = b * 2;
            // printf("r=%d,g=%d,b=%d\n", r, g, b);
            
        }
    }

    if (b > g && g > r)
    {
        printf("Yes");
        // printf("Yes r=%d,g=%d,b=%d\n", r, g, b);
    }
    else
    {
        printf("No");
        //printf("No r=%d,g=%d,b=%d\n", r, g, b);
    }
}


Measured memory_bytes: 3652
k = gets.chomp.to_i
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

puts a[k-1]

Measured memory_bytes: 1788
#include<iostream>

using namespace std;

int p,n[6],u[6];

int dfs(int r,int c){
  int cc[]={1,5,10,50,100,500};
  if(c>=0){
    int ans=1<<30;
    for(int i=0;i<2;i++){
      u[c]=min(n[c],r/cc[c]+i);
      ans=min(ans,dfs(max(0,r-u[c]*cc[c]),c-1)+u[c]);
    }
    return ans;
  }else{
    int ch=-p;
    for(int i=0;i<6;i++){
      ch+=cc[i]*u[i];
    }
    int r=0;
    for(int i=5;i>=0;i--){
      r+=ch/cc[i];
      ch%=cc[i];
    }
    return r;
  }
}

int main(){
  while(cin>>p>>n[0]>>n[1]>>n[2]>>n[3]>>n[4]>>n[5],p){
    cout<<dfs(p,5)<<endl;
  }
  return 0;
}

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

int main()
{
	int q;
	scanf("%d", &q);
	set<int> st;
	while (q--) {
		int com, x;
		scanf("%d%d", &com, &x);
		if (com == 0) {
			st.insert(x);
			printf("%d\n", st.size());
		}
		else if (com == 1) {
			puts(st.count(x) ? "1" : "0");
		}
		else if (com == 2) {
			st.erase(x);
		}
		else {
			int L = x, R;
			scanf("%d", &R);
			auto it = st.lower_bound(L);
			while (it != st.end() && *it <= R) {
				printf("%d\n", *it); ++it;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 12532
#include <iostream>
#include <cstdio>
#include <vector>
#include <math.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())

const int MOD = 1000000007;
const int INF = INT_MAX;


int main(){

    int a, b;
    cin >> a >> b;

    if (a <= 8 && b <= 8) cout << "Yay!" << endl;
    else cout << ":(" << endl;

    return 0;
}





//              g++ -std=c++1z

Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;
int main(void) {
    
    int n;
    cin>>n;
    int s[100];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }


    sort(s,s+n);
    
    int sum=0;
    for(int i=0;i<n;i++){
        sum+=s[i];
    }
    int SUM=sum;

    for(int i=n-1;i>=0;i--){
        sum=SUM;
        if(sum%10==0){
            sum -=s[n-1-i];
            if(sum%10!=0){
                cout<<sum<<endl;
                return 0;
            }
        }else{
            cout<<sum<<endl;
            return 0;
        }
    }
    if(sum%10==0)cout<<"0"<<endl;
    else    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	if((a*b)%2 == 0) {
		System.out.println("Even");
	}
	else {
		System.out.println("Odd");
	}
	}

}


Measured memory_bytes: 24148
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int c[22], b[22], a[22][22];
int main()
{
	int n, m, x;
	cin >> n >> m >> x;
	for(int i = 1; i <= n; i ++)
	{
		cin >> c[i];
		for(int j = 1; j <= m; j ++)
			cin >> a[i][j];
	}
	int ans = 1e9;
	for(int i = 0; i < (1 << n); i ++)
	{
		int s = 0;
		for(int j = 1; j <= m; j ++)
			b[j] = 0;
		for(int j = 0; j < n; j ++)
		{
			if((1 << j) & i)
			{
				s += c[j+1];	
				for(int k = 1; k <= m; k ++)
					b[k] += a[j+1][k];
			}
		}
		int ok = 0;
		for(int j = 1; j <= m; j ++)
		{
			if(b[j] < x)
			{
				ok = 1;
				break;
			}
		}
		if(!ok)
		{
			ans = min(ans, s);
		}
	}
	if(ans > 1e8)
		ans = -1;
	cout << ans;



	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#define fi first
#define se second
using namespace std;
const int maxn = 1e5 + 100;
typedef pair<int, int> PII;
bool cmp(const PII &A, const PII &B){
    return A.fi - A.se < B.fi - B.se;
}
PII a[maxn];
set<int> S[3];
map<int, int> H[3];
int ssz[3], sz[3];
long long ans = 0, temp, ans1[maxn], ans2[maxn];
void Erase(int x, int ty){
    if(H[ty][x] == 1) S[ty].erase(x);
    H[ty][x]--;
    ans -= x;
    ssz[ty]--;
}
void Insert(int x, int ty){
    if(H[ty][x] == 0) S[ty].insert(x);
    H[ty][x]++;
    ans += x;
    ssz[ty]++;
}

void S_Insert(int x, int ty){
    if(ssz[ty] == sz[ty]){
        int y = *S[ty].begin();
        if(y > x) return;
        Erase(y, ty);
    }
    Insert(x, ty);
}

int main()
{
    int X, Y, Z, x, y, z;
    cin>>X>>Y>>Z;
    int n = X+Y+Z;
    for(int i = 1; i <= n; i++){
        scanf("%d %d %d", &x, &y, &z);
        x -= z;
        y -= z;
        ans += z;
        a[i].fi = x;
        a[i].se = y;
    }
    temp = ans;
    ans = 0;
    sort(a+1, a+1+n, cmp);
    sz[1] = Y; sz[0] = X;
    for(int i = 1; i <= Y; i++) S_Insert(a[i].se, 1);
    ans1[Y] = ans;
    for(int i = Y+1; i <= n-X; i++){
        S_Insert(a[i].se, 1);
        ans1[i] = ans;
    }
    ans = 0;
    for(int i = n; i >= n-X+1; i--) S_Insert(a[i].fi, 0);
    ans2[n-X+1] = ans;
    for(int i = n-X; i >= Y+1; i--){
        S_Insert(a[i].fi, 0);
        ans2[i] = ans;
    }
    ans = -1e18;
    //for(int i = 1; i <= n; i++) cout<<a[i].fi<<" "<<a[i].se<<endl; cout<<endl;
    //cout<<temp<<endl;
    //for(int i = 1; i <= n; i++) cout<<ans1[i]<<" ";cout<<endl;
    //for(int i = 1; i <= n; i++) cout<<ans2[i]<<" ";cout<<endl;
    for(int i = Y; i <= n-X; i++) ans = max(ans, ans1[i]+ans2[i+1]);
    cout<<ans+temp<<endl;
    return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int H, N;
    cin >> H >> N;
    vector<int> dp(H + 1, INF);
    dp[0] = 0;
    for(int i = 0; i < N; ++i){
        int A, B;
        cin >> A >> B;
        for(int j = 0; j <= H; ++j){
            if(dp[j] == INF)    continue;
            chmin(dp[min(H, j + A)], dp[j] + B);
        }
    }
    cout << dp[H] << endl;
}

Measured memory_bytes: 3648
n,a,b = gets.split.map &:to_i

if n == 1
  puts a == b ? 1 : 0
elsif n == 2
  puts a <= b ? 1 : 0
elsif a > b
  puts 0
else
  puts b * (n - 2) - a * (n - 2) + 1
end



Measured memory_bytes: 1788
using System;
using System.Linq;

class AIDU0021
    {
        public static void Main(){
            decimal[] vertices = new decimal[8], VAB = new decimal[2], VCD = new decimal[2];
            int N=int.Parse(Console.ReadLine()),i=0;
            string s;
            
            bool[] result=new bool[N];
            for (int l = 0; l<N; l++) {
                s=Console.ReadLine();
                vertices=s.Split(' ').Select(decimal.Parse).ToArray();
                for (i = 0; i<2; i++) {
                    VAB[i]=vertices[i+2]-vertices[i];
                    VCD[i]=vertices[i+6]-vertices[i+4];
                }
                result[l]= VAB[0]*VCD[1]-VAB[1]*VCD[0]==0; //#687744
            }
            for (i = 0; i<N; i++) {
                Console.WriteLine(result[i] ? "YES" : "NO");
            }
        }
    }

Measured memory_bytes: 9584
use std::io;
use std::collections::VecDeque;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let row: usize = s.trim().parse().unwrap_or(0);
    s.clear();
    let mut array = VecDeque::with_capacity(row);

    for _ in 0..row {
        io::stdin().read_line(&mut s).ok();
        let v: Vec<isize> = s.trim().split_whitespace()
        .map(|e| e.parse().unwrap_or(0)).collect();

        match v[0] {
            0 => {
                if v[1] == 0 {
                    array.push_front(v[2]);
                } else {
                    array.push_back(v[2]);
                }
            },
            1 => {
                println!("{}", array[v[1] as usize]);
            },
            2 => {
                if v[1] == 0 {
                    array.pop_front();
                } else {
                    array.pop_back();
                }
            },
            _ => println!("error 0 or 1 or 2"),
        }
        s.clear();
    }
}


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

int main() {
  int n, m; cin >> n >> m;
  vector<int> foods(m);
  for (int i = 0; i < n; i++) {
    int k; cin >> k;
    for (int j = 0; j < k; j++) {
      int a; cin >> a;
      foods.at(a - 1)++;
    }
  }
  int ans = 0;
  for (auto e : foods) if (e == n) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main(){
    ll N;
    cin >> N;
    vll A(N);
    rep(i,N) cin >> A[i];
    sort(A.begin(),A.end(),greater<ll>());
    ll ans = 0;
    ll pos = 0;
    bool state = true;
    for (size_t i = 0; i < N-1; i++)
    {
        if(state){
            ans += A[pos];
            pos++;
            state = false;
        }
        else
        {
            ans += A[pos];
            state = true;
        }
        
    }
    cout << ans << endl;
    
}

int main(int argc, char const *argv[])
{
    Main();
    return 0;
}

void yesno(bool state){
    if(state)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 4792
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; // 998'244'353LL
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

#include <boost/multiprecision/cpp_int.hpp>
namespace boost_multiprecision = boost::multiprecision;
#define lll boost_multiprecision::cpp_int

int N;
lll ans = 1;
bool flg = false;

signed main(){
    cin >> N;
    rep(i, N){
        lll tmp;
        cin >> tmp;
        if(tmp == 0){
            cout << 0 << endl;
            return 0;
        }
        ans *= tmp;
        if(ans > 1'000'000'000'000'000'000LL){
            flg = true;
            ans = 1;
        }
    }
    if(flg) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3684
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    int[] inputArray;

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int input = sc.nextInt();
int n = 1;
        while(true){
if (n > input) {
n/=2;
break;}

n*=2;
}

if (input == 1) System.out.println(1);
else System.out.println(n);
    }

}


Measured memory_bytes: 21844
n,x = [int(x) for x in input().split()]
a =[int(x) for x in input().split()]
ans = 0
for i in range(n-1):
  b = a[i]+a[i+1]
  if x<b:
    c = b-x
    if c<a[i+1]:
      a[i+1] = a[i+1]-c
      ans+=c
    else:
      a[i+1]=0
      ans+=c
print(ans)

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
using ll = long long;
using ld = long double;
using str = string;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vs = vector<str>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

// Constant variables
const ld PI = (acos(-1));
const ll MOD = 1000000007;

// I/O Asynchronizing
struct __io_async{
    __io_async(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

int main() {
    str s;
    cin >> s;
    int cnt = 0;
    REP(i, s.length() / 2) {
        if(s[i] != s[s.length() - i - 1]) cnt++;
    }
    cout << cnt << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
ll n;
ll po[10];
ll has(vector<ll> a){
	ll x=1,res=0;
	rep(i,n){
		res+=a[i]*x;
		x*=10;
	}
	return res;
}
vector<ll> unzip(ll key){
	vector<ll> a;
	rep(i,n){
		a.push_back(key%10);
		key/=10;
	}
	return a;
}

class HALF{
public:
unordered_set<ll> vis;
unordered_map<ll,ll> dist;
queue<P> Q;
void solve(ll key,ll cost){
	dist[key]=cost;
	vector<ll> a=unzip(key);
	for(int j=0;j+1<n;j++){
		vector<ll> b=a;
		ll score=key;
		for(int i=0;0<=j-i&&j+1+i<n;i++){
			score-=b[j-i]*po[j-i];
			score-=b[j+1+i]*po[j+1+i];
			swap(b[j-i],b[j+1+i]);
			score+=b[j-i]*po[j-i];
			score+=b[j+1+i]*po[j+1+i];
			if(cost<4&&!vis.count(score)){
				Q.push(make_pair(score,cost+1));
				vis.insert(score);
			}
		}
	}
	for(int j=1;j<n-1;j++){
		vector<ll> b=a;
		ll score=key;
		for(int i=1;0<=j-i&&j+i<n;i++){
			score-=b[j-i]*po[j-i];
			score-=b[j+i]*po[j+i];
			swap(b[j-i],b[j+i]);
			score+=b[j-i]*po[j-i];
			score+=b[j+i]*po[j+i];
			if(cost<4&&!vis.count(score)){
				Q.push(make_pair(score,cost+1));
				vis.insert(score);
			}
		}
	}
}
void main(vector<ll> a){
	vis.insert(has(a));
	Q.push(make_pair(has(a),0));
	while(!Q.empty()){
		ll key=Q.front().first,cost=Q.front().second;
		Q.pop();
		solve(key,cost);
	}
}
};
HALF s,t;
int main(){
	po[0]=1;
	for(int i=1;i<10;i++)po[i]=po[i-1]*10;
	vector<ll> a;
	cin>>n;
	rep(i,n)a.push_back(i);
	s.main(a);
	rep(i,n){
		ll x; cin>>x; x--;
		a[i]=x;
	}
	t.main(a);
	ll ans=n-1;
	for(auto u:s.vis){
		if(t.vis.count(u)){
			chmin(ans,s.dist[u]+t.dist[u]);
		}
	}
	cout<<ans<<endl;
}




Measured memory_bytes: 43828
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000;
const int MOD = (int)1e9 + 7;
template <class T>
inline T in()
{
    T x;
    cin >> x;
    return x;
}

signed main()
{
    int n = in<int>();
    cout << (n - 2) * 180 << "\n";
}

Measured memory_bytes: 256
N = int(input())
S = []
for i in range(N):
    s = input()
    S.append(s)
M = int(input())
T = []
for i in range(M):
    t = input()
    T.append(t)

ans = 0
for s in S:
    ans = max(ans,S.count(s)-T.count(s))
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int N = scan.nextInt();
      	int K = scan.nextInt();
      	int nokori = N - K ;
      	if(K == 1) {
        	System.out.print(0);
        }
      	else {
      	System.out.print(nokori);
        }
    }

}

Measured memory_bytes: 22228
N = gets.to_i
xy = N.times.map { gets.split.map(&:to_i) }

sum = 0
count = 0
(0..(N-1)).to_a.permutation do |p|
  (N - 1).times do |i|
    sum += Math.sqrt((xy[p[i]][0] - xy[p[i + 1]][0]) ** 2 + (xy[p[i]][1] - xy[p[i + 1]][1]) ** 2)
  end
  count += 1
end
puts sum / count

Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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


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

    ll n; cin >> n;
    ll MIN = 1000000000000001;
    rep (i, 5) {
        ll a; cin >> a;
        MIN = min(MIN, a);
    }
    ll ans = ((n  + (MIN - 1)) / MIN) + 4;

    COUT(ans);
}


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s: Vec<char> = iterator.next().unwrap().chars().collect();

    let mut sum: Vec<usize> = vec![0; s.len() + 1];
    for i in 1..(s.len() + 1) {
        sum[i] = sum[i - 1] + i;
    }

    let mut parts: Vec<String> = Vec::new();
    let mut part = String::new();
    let mut prev: char = ' ';
    for &c in &s {
        if c != prev {
            if prev != ' ' {
                parts.push(part.clone());
            }
            part = String::new();
        }
        part.push(c);
        prev = c;
    }
    parts.push(part);

    let mut ans = 0;
    for i in 0..parts.len() {
        let part = &parts[i];
        if part.starts_with('<') {
            ans += sum[part.len()];
        } else {
            if i == 0 {
                ans += sum[part.len()];
            } else if part.len() <= parts[i - 1].len() {
                ans += sum[part.len() - 1];
            } else {
                ans -= parts[i - 1].len();
                ans += sum[part.len()];
            }
        }
    }
    return ans.to_string();
}


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

using namespace std;

typedef long long ll;

#define MOD (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()

ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll c(ll a,ll b)
{
  if(a==0)return b==0?1:0;

if(b>a)return 0;

  ll val=1;
ll fac=1;
for(int i=1;i<=b;i++)fac*=i;
for(int i=a;i>=a-b+1;i--)val*=i;

  return val/fac;

}

ll f(ll n)
{
  ll ans=1LL;
  while(ans<=n)ans<<=1;

return ans;
}

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


ll n,a,b;
cin>>n>>a>>b;

if(a==b)
{
  cout<<1<<"\n";
}
else if(a>b||n==1)
{
  cout<<0<<"\n";

}

else 
{
  ll ans=(n-2)*(b-a)+1;
  cout<<ans<<"\n";
}


return 0;

}


Measured memory_bytes: 256
n, l = gets.chomp.split(' ').map(&:to_i)

min_abs = Float::INFINITY
min_val = 0
expected = 0
(1..n).each do |i|
  a = i + l - 1
  if a.abs < min_abs
    min_abs = a.abs
    min_val = a
  end
  expected += a
end

res = expected - min_val

puts res

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    vector<int> a(3);
    cin >> a.at(0) >> a.at(1) >> a.at(2);
    sort(a.begin(), a.end());
    if (a[0] + a[1] == a[2]) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


Measured memory_bytes: 256