akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<vector>
#include<algorithm>
int main()
{
	int n,i,j,s,r;
	while(scanf("%d",&n),n)
	{
		std::vector<int>v[2];
		v[0].resize(n);v[1].resize(n);
		for(s=r=i=0;i<n;++i)scanf("%d",&v[0][i]);
		for(;;)
		{
			for(i=0;i<n;++i)v[!s][i]=std::count(v[s].begin(),v[s].end(),v[s][i]);
			if(v[!s]==v[s])break;
			++r;
			s=!s;
		}
		printf("%d\n",r);
		for(i=0;i<n;++i)printf("%d%c",v[0][i],i+1-n?' ':'\n');
	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors


r = make_divisors(n)

if len(r) % 2 == 1:
    a = r[len(r)//2]
    print((a-1)+(a-1))
else:
    a = int(len(r)/2)
    print((r[a-1]-1)+(r[a]-1))


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

const int maxn = 510;
const int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
int n, ans, p[250010], f[maxn][maxn], vis[maxn][maxn];
bool chk[maxn][maxn];
deque<pair<int, int>> Q;

int id(int x, int y) {
    return (x - 1) * n + y;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            f[i][j] = min({i - 1, j - 1, n - i, n - j});
            chk[i][j] = 1;
        }
    }
    for (int i = 1; i <= n * n; i++) {
        scanf("%d", &p[i]);
        int x = (p[i] - 1) / n + 1, y = p[i] - (x - 1) * n;
        ans += f[x][y], Q.push_back({x, y}), chk[x][y] = 0;
        while (!Q.empty()) {
            int x = Q.front().first, y = Q.front().second; Q.pop_front();
            if (vis[x][y] == i) continue;
            else vis[x][y] = i;
            for (int k = 0; k < 4; k++) {
                int nx = x + dx[k], ny = y + dy[k];
                if (nx < 1 || nx > n || ny < 1 || ny > n) continue;
                int nd = f[x][y] + chk[x][y];
                if (nd >= f[nx][ny]) continue;
                f[nx][ny] = nd;
                if (!chk[x][y]) Q.push_front({nx, ny});
                else Q.push_back({nx, ny});
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 7828
# ABC146 B - ROT N
N = int(input())
S = str(input())
s=''
alp = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
for i in range(len(S)):
    t =alp.index(S[i])+N
    if t>=26:
        t -=26
    s += alp[t]
print(s)

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

#define rep(i, n)     for(int i = 0;      i < int(n); ++i)
#define rep3(i, a, b) for(int i = int(a); i < int(b); ++i)
#define all(x)        (x).begin(),(x).end()
#define sz(x)         int(x.size())
#define mp            make_pair
#define pb            push_back


typedef long long ll;

using namespace std;

int main(){
  int H, W;
  cin >> H >> W;

  vector<string> grid;
  rep(h, H){
    string s;
    cin >> s;
    if(s.find("#") != string::npos){
      grid.pb(s);
    }
  }

  rep(w, sz(grid[0])){
    bool delete_flag = true;
    rep(h, sz(grid)){
      if(grid[h][w] == '#'){
        delete_flag = false;
        break;
      }
    }
    if(delete_flag){
      rep(h, sz(grid)){
        string s = grid[h];
        s.erase(w, 1);
        grid[h] = s;
      }
      w--;
    }
  }

  rep(h, sz(grid)){
    cout << grid[h] << endl;
  }


  return 0;
}


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


int main () {
  int A, B, score;
  cin >> A >> B;

  score = 0;
  for (int i = 0; i < 2; i++) {
    if (A <= B) {
      score += B;
      B--;
    } else {
      score += A;
      A--;
    }
  }
  cout << score << endl;
}


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

long long calc(long long s, long long t, long long x){
  if((x - t) * (x - s) > 0){
    return max(abs(x-s), abs(x-t));
  } else {
    return abs(t-s) + min(abs(x-s), abs(x-t));
  }
}

int main(){
  int a, b, q;
  cin >> a >> b >> q;
  vector<long long> s(a+2), t(b+2), x(q+2);
  for ( int i = 1; i <= a; i++) cin >> s[i];
  for ( int i = 1; i <= b; i++) cin >> t[i];
  for ( int i = 1; i <= q; i++) cin >> x[i];
  s[a+1] = t[b+1] = 100000000000000;
  s[0] = t[0] = -100000000000000;

  for ( int i = 1; i <= q; i++){
    int sidx = lower_bound(s.begin(), s.end()-1, x[i]) - s.begin();
    int tidx = lower_bound(t.begin(), t.end()-1, x[i]) - t.begin();
    vector <long long> v = {
    calc(s[sidx], t[tidx], x[i]),
    calc(s[sidx-1], t[tidx], x[i]),
    calc(s[sidx], t[tidx-1], x[i]),
    calc(s[sidx-1], t[tidx-1], x[i])
    };
    sort(v.begin(), v.end());
    cout << v[0] << endl;
  }


  return 0;
}

Measured memory_bytes: 3712
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ a, b, c ] <- readInts
	let
		d = min c $ a - b
	print $ c - d

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
#pragma region Macros
typedef long long ll;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};
#define LOCAL

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    cout << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<int> cnt(4,0);
    vector<string> T={"AC","WA","TLE","RE"};
    for (;N--;){
        string S; cin >> S;
        for (int j=0;j<4;++j){
            if (S==T[j]) ++cnt[j];
        }
    }
    for (int i=0;i<4;++i){
        cout << T[i] << " x " << cnt[i] << '\n';
    }
}

Measured memory_bytes: 3608
//https://atcoder.jp/contests/abc123/tasks/abc123_d
//解説みた
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int X, Y, Z, K;
    cin>>X>>Y>>Z>>K;
    long long *A = new long long[X];
    long long *B = new long long[Y];
    long long *C = new long long[Z];
    for(int i=0;i<X;i++)cin>>A[i];
    for(int i=0;i<Y;i++)cin>>B[i];
    for(int i=0;i<Z;i++)cin>>C[i];

    long long *AsB = new long long[X*Y];
    for(int i=0;i<X;i++){
        for(int j=0;j<Y;j++){
            AsB[i*(Y)+j]=A[i]+B[j];
        }
    }
    sort(AsB,AsB+X*Y);
    int k=K;
    if(K>X*Y)k=X*Y;
    long long *AsBsC =new long long[k*Z];
    for (int i = 0; i < k; i++)
    {
        for (int j = 0; j < Z; j++)
        {
            AsBsC[i*(Z)+j]=AsB[X*Y-i-1]+C[j];
            //cout<<AsBsC[i*(Z)+j]<<endl;
        }
        
    }
    sort(AsBsC,AsBsC+k*Z);
    for (int i = 0; i < K; i++)
    {
        cout<<AsBsC[k*Z-1-i]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 31616
#include <iostream>
#include<iomanip>
#include <cmath>
#include <climits>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <queue>
#include <tuple>
#include <map>
#include <list>
#include <string>
#include <numeric>
#include <utility>
#include <cfloat>
using namespace std;

//long long a[100000];
//long long b[100000];

using namespace std;
 
int A[200001];

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    A[N] = 0;

    long long tmp_sum = 0;
    long long tmp_xor = 0;
    long long ans = 0;
    int left = 0;
    int right = 0;
    while(left < N){
        while(right <= N && tmp_xor >= tmp_sum){
            tmp_sum += A[right];
            tmp_xor ^= A[right];
            right ++;
        }
        ans += (right - left - 1);
        tmp_sum -= A[left];
        tmp_xor ^= A[left];
        left++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a+b>c+d) {
    cout << "Left" << endl;
  }
  else if (a+b<c+d) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

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

using namespace std;

typedef long long ll;

int n;
int pay = 0;
int main()
{
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n;

    while (pay < n){
        pay += 1000;
    }

    cout << pay - n << endl;

    return 0;
}


Measured memory_bytes: 3660
a,b,k = map(int,input().split())
if b+1-a <= k*2:
    for i in range(a,b+1):
        print(i)
else:
    for j in range(a,a+k):
        print(j)
    for l in range(b-k+1,b+1):
        print(l)   


 


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

using namespace std;

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

	int n = a + b + c;
	int ans = 0;
	while (1) {
		if ((a & 1) || (b & 1) || (c & 1)) {
			break;
		}
		if (a == b && b == c) {
			ans = -1;
			break;
		}

		++ans;
		a = (n - a) / 2;
		b = (n - b) / 2;
		c = (n - c) / 2;
		n = a + b + c;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nm = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int n = nm[0];
            int m = nm[1];

            var lamps = new Lamp[m];
            for (int i = 0; i < m; i++)
            {
                string line = Console.ReadLine();
                int[] elems = line.Split(' ').Select(x => int.Parse(x)).ToArray();

                int k = elems[0];
                int[] switchNums = elems.Skip(1).ToArray();

                lamps[i] = new Lamp(switchNums);
            }

            var ps = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            var switches = new bool[(int)Math.Pow(2, n), n];

            for (int w = 0; w < switches.GetLength(1); w++)
            {
                switches[0, w] = false;
            }

            for (int h = 1; h < switches.GetLength(0); h++)
            {
                for (int w = 0; w < switches.GetLength(1); w++)
                {
                    switches[h, w] = switches[h - 1, w];
                }

                int i = 0;
                while (i < switches.GetLength(1))
                {
                    if (switches[h - 1, i])
                    {
                        switches[h, i] = false;
                        i++;
                    }
                    else
                    {
                        switches[h, i] = true;
                        break;
                    }
                }

            }

            int patternCount = 0;
            for (int i = 0; i < switches.GetLength(0); i++)
            {
                bool allLampOn = true;
                for (int lampIndex = 0; lampIndex < m; lampIndex++)
                {
                    var lamp = lamps[lampIndex];

                    int onCount = 0;
                    foreach (var switchNum in lamp.SwitchNumbers)
                    {
                        if (switches[i, switchNum - 1])
                        {
                            onCount++;
                        }
                    }

                    bool isLampOn = (onCount % 2) == ps[lampIndex];
                    if (!isLampOn)
                    {
                        allLampOn = false;
                        break;
                    }
                }

                if (allLampOn)
                {
                    patternCount++;
                }
            }

            Console.WriteLine(patternCount);
        }
    }

    class Lamp
    {
        public Lamp(int[] switchNumbers)
        {
            this.SwitchNumbers = switchNumbers;
        }

        public int[] SwitchNumbers { get; private set; }
    }
}


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

int N,count = 0;
bool judge = true;
vector<vector<int>> v(100010);
int visited[100010] = {0},col[100010] = {0};


bool dfs(int n){
	visited[n] = 1;
	bool j = true;
	if(n!=1 && v[n].size()==1) return true;
	for(int i=0;i<v[n].size();i++){
		int s = v[n][i];
		if(visited[s]==0 && dfs(s)){
			if(col[n]==0){
				col[n] = 1;
				count++;
				j = false;
			}else judge = false;
		}
	}
	return j;
}


int main(){
	cin >> N;
	int a,b;
	for(int i=0;i<N-1;i++){
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	if(N%2==1){
		cout << "First" << endl;
		return 0;
	}
	dfs(1);
/*	for(int i=1;i<=N;i++){
		cout << col[i] << (i!=N? " ":"\n");
	}
*/	cout << (!judge? "First":"Second") << endl;
}

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

int gcd(int a,int b){
	if(a < b) swap(a,b);
	if(!b) return a;
	return gcd(b,a % b);
}

int main(){
	int n,a[100000];
	bool turn = true;
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	while(1){
		int gu = 0,one = 0;
		for(int i = 0;i < n;i++){
			if(a[i] % 2 == 0) gu++;
			if(a[i] == 1) one++;
		}
		if(gu % 2){
			if(turn) cout << "First" << endl;
			else cout << "Second" << endl;
			break;
		}else if(n - gu != 1 || (n - gu == 1 && one)){
			if(!turn) cout << "First" << endl;
			else cout << "Second" << endl;
			break;
		}
		if(a[0] % 2 == 1) a[0]--;
		int g = a[0];
		for(int i = 1;i < n;i++){
			if(a[i] % 2 == 1) a[i]--;
			g = gcd(g,a[i]);
		}
		for(int i = 0;i < n;i++) a[i] /= g;
		turn = !turn;
	}
	return 0;
}

Measured memory_bytes: 640
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define e endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
map<ll,ll>check;
map<ll,ll>visit;
vector<ll>ans;

int main()
{
   ll n,i,j,cc=0,m;
   cin>>n>>m;
   ll ara[m];
   for(i=0;i<m;i++){
    cin>>ara[i];
    cc+=ara[i];
   }
   if(cc>n)cout<<-1<<endl;
   else cout<<n-cc<<endl;
return 0;
}


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

template <typename T>
struct flow_graph {
	
	struct edge {
		int from, to;
		T cap, f;
	};
	
	vector<edge> edges;
	vector<vector<int>> g;
	vector<int> level, iter;
	int n, st, fin;
	T flow;
	
	flow_graph(int n, int st, int fin) : n(n), st(st), fin(fin) {
		assert(0 <= st && st < n && 0 <= fin && fin < n && st != fin);
		g.resize(n);
		level.resize(n);
		iter.resize(n);
		flow = 0;
	}
	
	void clean_flow() {
		for (const edge &e : edges) {
			e.f = 0;
		}
		flow = 0;
	}
	
	void add(int from, int to, T cap = 1, T rev_cap = 0) {
		assert(0 <= from && from < n && 0 <= to && to < n);
		g[from].emplace_back(edges.size());
		edges.push_back({from, to, cap, 0});
		g[to].emplace_back(edges.size());
		edges.push_back({to, from, rev_cap, 0});
	}
	
	bool bfs() {
		fill(level.begin(), level.end(), -1);
		queue<int> q;
		level[st] = 0;
		q.emplace(st);
		while (!q.empty()) {
			int i = q.front();
			q.pop();
			for (int id : g[i]) {
				const edge &e = edges[id];
				if (0 < e.cap - e.f && level[e.to] < 0) {
					level[e.to] = level[i] + 1;
					q.emplace(e.to);
				}
			}
		}
		return 0 < level[fin];
	}
	
	T dfs(int now, T f = numeric_limits<T>::max()) {
		if (now == fin) {
			return f;
		}
		for (int &i = iter[now]; i < g[now].size(); i++) {
			int id = g[now][i];
			edge &e = edges[id];
			if (0 < e.cap - e.f && level[now] < level[e.to]) {
				T d = dfs(e.to, min(f, e.cap - e.f));
				if (0 < d) {
					e.f += d;
					edges[id ^ 1].f -= d;
					return d;
				}
			}
		}
		return 0;
	}
	
	T max_flow() {
		while (bfs()) {
			fill(iter.begin(), iter.end(), 0);
			for (T f = dfs(st); 0 < f; f = dfs(st)) {
				flow += f;
			}
		}
		return flow;
	}
};

int main() {
	int n;
	cin >> n;
	int64_t a[n];
	for (auto &i : a) {
		cin >> i;
	}
	int64_t maxi = 0;
	for (auto &i : a) {
		if (0 < i) {
			maxi += i;
		}
	}
	flow_graph<int64_t> g(n + 2, 0, n + 1);
	for (int i = 1; i <= n; i++) {
		if (0 <= a[i - 1]) {
			g.add(0, i, a[i - 1]);
			g.add(i, n + 1, 0);
		} else {
			g.add(0, i, 0);
			g.add(i, n + 1, -a[i - 1]);
		}
		for (int j = 2 * i; j <= n; j += i) {
			g.add(j, i, numeric_limits<int64_t>::max());
		}
	}
	cout << maxi - g.max_flow() << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

char arr[107][107];
int main(){
	Lancer();
	ll l = 0;
	string str;
	cin >> str;
	for (int i = 0; i < str.length(); i++){
		bool ch = true;
		for (int j = i + 1; j < str.length(); j++){
			if (str[i] == str[j]){
				ch = false;
				break;
			}
		}
		if (ch)
			l++;
	}
	if (l == str.length())
		cout << "yes";
	else
		cout << "no";
	//cout << endl;
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>

using namespace std;

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

string v;
ll n, k;

bool isfull(){
  for(int i = 1; i <= n; i++)
    if(v[1] != v[i])
      return 0;
  return 1;
}

int main()
{
  cin >> v >> k;
  n = v.size();
  v = '#' + v;

  if(isfull() == 1)
    cout << 1LL * n * k / 2;
  else{
    if(v[1] != v[n]){
      ll result = 0, sum = 0;
      for(int i = 1;i <= n; i++){
        if(v[i - 1] != v[i]) {
          result += sum / 2;
          sum = 1;
        } else
          sum++;
      }
      result += sum / 2;
      cout << k * result;
    } else {
      ll result = 0, sum = 0;
      ll x = 1, y = n;
      while(v[x] == v[x + 1])
        x++;
      while(v[y - 1] == v[y])
        y--;

      for(int i = x + 1;i < y; i++){
        if(v[i - 1] != v[i]) {
          result += sum / 2;
          sum = 1;
        } else
          sum++;
      }
      result += sum / 2;
      cout << k * result + x / 2 + (n - y + 1) / 2 + (k - 1) * ((x + (n - y + 1)) / 2);
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll                long long int
#define ld                long double
#define pb                push_back
#define mk                make_pair
#define in(i,a,n)         for(ll i=0;i<n;++i) cin>>a[i];
#define out(i,a,n)        for(ll i=0;i<n;++i) cout<<a[i]<<" ";
#define sz(c)             (ll)c.size()
#define all(c)            c.begin(), c.end()
#define rall(c)           c.rbegin(), c.rend()
#define loop(i,a,b)       for(ll i=a;i<b;i++)
#define rloop(i,a,b)      for(ll i=a;i>b;i--)
#define F                 first
#define S                 second
#define copy(a,b)         copy(all(a),back_inserter(b));
#define intersect(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
const ll N=300001;
const ll MOD = 1000 * 1000 * 1000 + 7;
ll mod(ll n) {
    return (n % MOD + MOD) % MOD;
}

void solve(){
    ld n, k, i, x, y;
    cin >> n;
    cout << setprecision(20) << (ld)((ld)(2) * (ld)((ld)22/(ld)7) * (ld)(n));
}

signed main(){
    //fin fout
    fast
    ll t=1; //cin>>t;
    while(t--) solve();
}  

Measured memory_bytes: 3804
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
using namespace std;
typedef long long LL;

const int Maxn = 200000;

int main(){
    LL k, a[Maxn];
    while(~scanf("%lld", &k)){
        for(int i = 1; i <= 50; i++) a[i] = k/50LL + i - 1;
        k %= 50;
        for(int i = 1; i*1LL <= k; i++){
            for(int j = 1; j <= 50; j++) a[j]--;
            a[i] += 51;
        }
        printf("50\n");
        for(int i = 1; i < 50; i++) printf("%lld ", a[i]);
        printf("%lld\n", a[50]);
    }
    return 0;
}

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

using namespace std;
const int _max = 2e6 + 10;
const int mod = 1e9 + 7;
typedef unsigned long long ll;

int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int count=0;
        for(int j1=1;j1<sqrt(i)+1;j1++){
            for(int j2=1;j2<sqrt(i)+1;j2++){
                for(int j3=1;j3<sqrt(i)+1;j3++){
                    if(j1*j1+j2*j2+j3*j3+j1*j2+j1*j3+j2*j3>i){
                        break;
                    }
                    if(j1*j1+j2*j2+j3*j3+j1*j2+j1*j3+j2*j3==i){
                        count++;
                    }
                }
            }
        }
        cout<<count<<endl;
    }
    return 0;
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
  int n;
  string s;
  int k;
  cin >> n >> s >> k;
  char c = s[k-1];
  rep(i,n) {
    if(s[i] == c) cout << s[i];
    else cout << '*';
  }
  cout << endl;
}

Measured memory_bytes: 3600
def resolve():
    '''
    code here
    '''
    N = int(input())

    num_lists = [[int(item) for item in input().split()] for _ in range(N)]

    res = 0

    for a, b in num_lists[::-1]:
        temp_mod = (a + res ) % b
        if temp_mod > 0:
            res += b - temp_mod

    print(res)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 26504
import java.util.Scanner;

public class Main {

	private static String TENKI[] = {"Sunny","Cloudy","Rainy"};

	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String S = sc.next();
		String ans = getAnswer(S) ;
		System.out.println(ans);
	}

	public String getAnswer(String S) {
		String ans = "" ;

		if(S.equals(TENKI[0])) {
			ans = TENKI[1] ;
		}else if(S.equals(TENKI[1])){
			ans = TENKI[2] ;
		}else if(S.equals(TENKI[2])){
			ans = TENKI[0] ;
		}
		return ans ;
	}


}


Measured memory_bytes: 22228
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
int main()
{
	char s[10];
	int ans[10] = { 0 }, fans[5] = { 0 };
	cin >> s;
	for (int i = 0; i < 10; i++) {
		if (s[i] == 'A')ans[i] = 1;
		if (s[i] == 'C')ans[i] = 1;
		if (s[i] == 'G')ans[i] = 1;
		if (s[i] == 'T')ans[i] = 1;
	}
	int count = 0;
	for (int i = 0; i < 10; i++) {
		fans[count] += ans[i];
		if (ans[i - 1] == 1) {
			if (ans[i] == 0) {
				count++;
			}
		}
	}
	sort(fans, fans + 5);
	cout << fans[4] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int INF = 100000000;
int h, w;
char a[100][101];
const int noans = 10000000;
const int S = 200;
const int T = 201;
const int maxsize = 100;

struct edge { int to, cap, rev; };

vector<edge> G[202];
bool used[202];
void add_edge (int from, int to, int cap) {
  G[from].push_back((edge){to, cap, (int)G[to].size()});
  G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}
int dfs(int v, int t, int f) {
  if (v == t) return f;
  used[v] = true;
  for (int i = 0; i < G[v].size(); i++) {
    edge &e = G[v][i];
    if (!used[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t) {
  int flow = 0;
  while (1) {
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if (f == 0) return flow;
    flow += f;
  }
}

int main() {
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) scanf("%s", a[i]);
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
    switch (a[i][j]) {
      case 'S':
        add_edge(S, i, noans);
        add_edge(i, S, noans);
        add_edge(S, j + maxsize, noans);
        add_edge(j + maxsize, S, noans);
        break;
      case 'T':
        add_edge(T, i, noans);
        add_edge(i, T, noans);
        add_edge(T, j + maxsize, noans);
        add_edge(j + maxsize, T, noans);
        break;
      case 'o':
        add_edge(i, j + maxsize, 1);
        add_edge(j + maxsize, i, 1);
        break;
    }
  }
  int ans = max_flow(S, T);
  if (ans >= noans) ans = -1;
  printf("%d\n", ans);
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int, int>
#define F first
#define S second
#define mp make_pair
#define um unordered_map
#define all(x) (x).begin(), (x).end() 
#define reps(i, j, k) for(auto i = j; i < k; ++i)
#define rep(i, j) reps(i, 0, j)
#define decs(i, j, k) for(auto i = j; i >= k; --i)
#define dec(i, j) decs(i, j, 0)
using namespace std;
int main()
{
	ll n; cin >> n;
	ll ans = numeric_limits<ll>::max();
	ll q, r, root = sqrt(n);
	reps(i, 1, root + 1)
	{
		q = n / i;
		r = n - q * i; 
		if(r == 0) 
			ans = min(ans, i - 1 + q - 1);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    string s;
    cin >> s;
    int a = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == 'o') a++;
    }
    cout << 700 + a * 100 << endl;
}

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

int main()
{
	int N;
	int a, x;
  
	cin >> N;
    x = N;
	for(int i=0;i<8;i++){
      a += x%10; 
      x /= 10;
	}
  if(N%a == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

}


Measured memory_bytes: 256
#include<cstdio>
#define MAX 10000
#define NIL -1

struct Node { int parent, left, right; };

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
  if ( u == NIL ) return;
  D[u] = d;
  setDepth(T[u].left, d + 1);
  setDepth(T[u].right, d + 1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if ( T[u].left != NIL)
    h1 = setHeight(T[u].left) + 1;
  if (T[u].right != NIL )
    h2 = setHeight(T[u].right) + 1;
  return H[u] = ( h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
  if ( T[u].parent == NIL) return NIL;
  if ( T[T[u].parent].left != u && T[T[u].parent].left != NIL )
    return T[T[u].parent].left;
  if ( T[T[u].parent].right != u && T[T[u].parent].right != NIL )
    return T[T[u].parent].right;
  return NIL;
}

void print(int u) {
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if ( T[u].left != NIL ) deg++;
  if ( T[u].right != NIL ) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if ( T[u].parent == NIL ) {
    printf("root\n");
  } else if ( T[u].left == NIL && T[u].right == NIL ) {
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}

int main() {
  int v, l ,r ,root = 0;
  scanf("%d", &n);

  for ( int i = 0; i < n; i++ ) T[i].parent = NIL;

  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &v, &l ,&r);
    T[v].left = l;
    T[v].right = r;
    if (l != NIL) T[l].parent = v;
    if (r != NIL) T[r].parent = v;
  }

  for ( int i = 0; i < n; i++) if ( T[i].parent == NIL) root = i;

  setDepth(root, 0);
  setHeight(root);

  for ( int i = 0; i < n; i++) print(i);

  return 0 ;
}



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

int main(void){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i, n){
        cin>>a[i];
    }
    rep(i, n) a[i]--;
    vector<int>idx(n);
    rep(i, n)idx[a[i]]=i;
    set<int>s;
    ll ans=0;
    for(int x=n-1;x>=0;x--){
        int i=idx[x];//xの場所
        ll c=0;
        s.insert(i);
        vector<int>l(2, -1);
        vector<int>r(2, n);
        set<int>::iterator it=s.find(i);
        rep(j, 2){
            if(it==s.begin()) break;
            --it;
            l[j]=*it;
        }
        it=s.find(i);
        rep(j, 2){
            ++it;
            if(it==s.end()) break;
            r[j]=*it;
        }

        vector<int>ls(2);
        ls[0]=i-l[0];
        ls[1]=l[0]-l[1];
        vector<int>rs(2);
        rs[0]=r[0]-i;
        rs[1]=r[1]-r[0];

        c=(ll)ls[0]*rs[1]+(ll)ls[1]*rs[0];

        ans+=c*(x+1);
    }
    cout<<ans<<endl;



}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

int main(){fastio
    
    ll n;cin>>n;
    string s;cin>>s;
    ll ans=0;
    rep(si,0,n-1){
        rep(sj,si+1,n-1){
            if(s[si]!=s[sj])continue;
            if(si>=1&&s[si-1]==s[sj-1])continue;
            rep(p,0,n){
                ll px=p+si;
                ll py=p+sj;
                if(px>=sj)break;
                if(py>=n)break;
                if(s[px]!=s[py])break;
                Max(ans,p+1);
            }
        }
    }
    cout<<ans<<endl;
    
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	ll N,a,b;
	cin>>N>>a>>b;
	ll nax = b*(N-1) + a;
	ll nin = a*(N-1) + b;
	cout<<max(0LL, nax-nin+1LL)<<endl;
	return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vec a(N);
    rep(i, N) cin >> a[i];
    ll res = INF;
    Rep1(i, -100, 100){
        ll tmp = 0;
        rep(j, N){
            tmp += (i - a[j])*(i - a[j]);
        }
        res = min(res, tmp);
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int a[1000005], b[1000005];
int judge(int n)
{
      if (a[n]>1)return 0;
      for (int i=2; i*i<=n; i++)
      {
           if (n%i==0)
           {
                 if (a[i]>=1)return 0;
                 int temp=n/i;
                 if (a[temp]>=1) return 0;
           }
      }
      return 1;
}
int main()
{
       ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
       int n;int ans=0;
       cin >> n ;
       for (int i=1; i<=n; i++)
       {
             cin >> b[i];
             if (b[i]==1) ans++;
             a[b[i]]++;
       }
       if (ans==1) cout << 1 << endl;
       else if (ans>1) cout << 0 << endl;
       else
       {
            for (int i=1; i<=n; i++)
             {
                   if (judge(b[i]))
                   {
                         ans++;
                   }
             }
             cout << ans << endl;
       }
	return 0;
}


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 100010
#define inf 1e9

int main()
{

    ll lfl = -1000000, rl = 1000000, n, k;
    cin >> k >> n;
    vector<ll> v1,v2;
    for(ll i = k-1; i >= 1; i--)
    {

        ll x = n-i;
        if(x >= lfl) v1.pb(x);
    }
    for(ll i = 1; i <= k-1; i++)
    {

        ll x = n+i;
        if(x <= rl) v2.pb(x);
    }
    if(v1.size()==k-1)
        for(ll i = 0; i < v1.size(); i++) cout << v1[i] << " ";
    cout << n << " ";
    if(v2.size() == k-1)
        for(ll i = 0; i < v2.size(); i++) cout << v2[i] << " ";
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

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

    var(int, N);
    vector<int> a(N);
    read(a);

    vector<int> freq(100010);
    for (int e : a) freq[e]++;

    i64 ans = 0;
    rep(i, 1, 100010 - 1) { chmax(ans, freq[i] + freq[i - 1] + freq[i + 1]); }

    print(ans);

    return 0;
}


Measured memory_bytes: 1024
n = int(input())
s = input()
pins = ['0' * (3-len(str(i))) + str(i) for i in range(1000)]
ans = 0
for p in pins:
    a, b, c, = p
    if a not in s:
        continue
    p1 = s.index(a)
    if b not in s[p1+1:]:
        continue
    p2 = s[p1+1:].index(b) + len(s[:p1+1])
    if c not in s[p2+1:]:
        continue
    ans += 1
print(ans)


Measured memory_bytes: 9284
a = list(map(int, input().split(' ')))
s, t = a[2], a[3]
mi = max(map(int, input().split(' ')))
ma = min(map(int, input().split(' ')))
if not mi < ma:
  print('War')
  exit()
for i in range(mi+1, ma+1):
  if s < i <= t:
    print('No War')
    exit()
print('War')

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for(int i = 0; i < N; i++)
		{
			list.add(sc.nextInt());
		}
		int max = list.stream().max((a, b) -> a.compareTo(b)).get();
		int min = list.stream().min((a, b) -> a.compareTo(b)).get();
		System.out.println(max - min);
	}

}


Measured memory_bytes: 27604
package main

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

func main() {
	nums := ReadString()
	n := make([]int, 4)
	for i := 0; i < 4; i++ {
		n[i] = int(nums[i] - '0')
	}
	for S := 0; S < 1<<3; S++ {
		v := n[0]
		ans := "" + string(nums[0])
		for i := 0; i < 3; i++ {
			if S>>i&1 == 1 {
				ans += "+"
				v += n[i+1]
			} else {
				ans += "-"
				v -= n[i+1]
			}
			ans += string(nums[i+1])
		}
		if v == 7 {
			ans += "=7"
			fmt.Println(ans)
			return
		}
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1844
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define eps (1e-8)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    int a,b;cin>>a>>b;
    if(a<=9 && a>=1 && b<=9 && b>=1){
        cout<<a*b;
    }else cout<<-1;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
X = [list(map(int,input().split())) for i in range(m)]
a_list = []
b_list = []
for i in range(m):
  if X[i][0] == 1:
    a_list.append(X[i][1])
  elif X[i][1] == n:
    b_list.append(X[i][0])
c_set = set(a_list) & set(b_list)
if len(c_set) ==0:
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	pair<double,double> xy[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>xy[i].first>>xy[i].second;
	}
	sort(xy, xy+n, [](const auto &p1, const auto &p2) {return atan2(p1.second, p1.first) < atan2(p2.second, p2.first);});
	double ans=.0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = i; j < i+n; ++j)
		{
			double xn=.0,yn=.0;
			for (int k = i; k <= j; ++k)
			{
				xn+=xy[k%n].first;
				yn+=xy[k%n].second;
			}
			ans=max(ans,sqrt((xn*xn+yn*yn)));
		}
	}
	printf("%.11f\n", ans);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <map>
#include <utility>
using namespace std;
#define rep(i, n) for (int i =0; i < (int)(n); i++)
typedef pair<int, string> P;

long long gcd(long long a, long long b) {
    return  b ? gcd(b, a % b) : a;
}

long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b;
}

long long f(long long x,long long c ,long long d) {
    long long res = x;
    res -= x / c;
    res -= x / d;
    res += x / lcm(c, d);
    return res;
}

int main() {
    long long a, b, c,d;
    cin >> a >> b>>c>>d;
    long long ans = 0;
    ans = f(b,c,d) - f(a - 1,c,d);

    cout << ans << endl;

}





Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  string s;
  cin >> s;
  bool flag = true;
  REP(i,s.size()) {
    if(i%2 == 0) {
      if (s[i] == 'L') flag = false;
    } else {
      if (s[i] == 'R') flag = false;
    }
  }
  if(flag) cout << "Yes" << endl;
  else  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
A = [int(input()) for i in range(m)]
B = [0 for i in range(10**5+10)]
for i in range(len(A)):
    B[A[i]] = 1

mod = 10**9 + 7

DP = [1,1]
if B[1] == 1:
    DP[1] = 0
for i in range(2,n+1):
    p1 = DP[i-2] % mod
    p2 = DP[i-1] % mod
    if B[i-2] == 1:
        p1 = 0
    if B[i-1] == 1:
        p2 = 0
    DP.append((p1+p2)%mod)
print(DP[n])

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

int bunkatu(long long A, long long B, long long C){

  long long rA, rB, rC;
  rA = A;
  rB = B;
  rC = C;

  long long cnt=0;

  while(1){

    if((rA % 2 == 1) || (rB % 2 == 1) || (rC % 2 == 1)){
      return cnt;
    }

    if( (A == B) && (B == C) ){
      return -1;
    }

    A /= 2;
    B /= 2;
    C /= 2;

    rA = B + C;
    rB = A + C;
    rC = A + C;

    cnt++;
  }
}



int main(){

  long long A, B, C;
  cin >> A >> B >> C;
  int cnt=0;
  cnt = bunkatu(A, B, C);

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256