akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vP c(N);
    rep(i,N){
        cin >> c[i].first;
        c[i].second=i;
    }
    sort(c.begin(),c.end());
    vl before(N,-1);
    rep(i,N){
        if(c[i].first==c[i+1].first){
            before[c[i+1].second]=c[i].second;
        }
    }
    ll dp[N];
    rep(i,N){
        dp[i]=0;
    }
    dp[0]=1;
    rep(i,N-1){
        dp[i+1]=dp[i];
        if(before[i+1]!=-1&&before[i+1]!=i){
            dp[i+1]+=dp[before[i+1]];
        }
        dp[i+1]%=MOD;
    }
    rep(i,N){
        cerr << i << ' ' << dp[i] << '\n';
    }
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 10012
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
a = nl()
ans = 0

def factorize2(n):
    a = 0
    while n % 2 == 0:
        a += 1
        n //= 2
    return a

for num in a:
    f = factorize2(num)
    if f > 0:
        ans += f

print(ans)

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

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

int N, K;
int A[200010];

signed main()
{
    cin >> N >> K;
    rep(i, N)cin >> A[i];

    sort(A, A + N);

    if(K == 0)
    {
        cout << A[N - 1] << endl;
        return 0;
    }

    int l = 1, r = 1001001001001001001;
    rep(i, 70)
    {
        int mid = (l + r) / 2;
        int cnt = 0;
        rep(j, N)
            cnt += (A[j] + mid - 1) / mid - 1;
        if(cnt <= K)r = mid;
        else l = mid;
    }

    cout << r << endl;

    return 0;
}


Measured memory_bytes: 5112
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
mod = 10 **9 + 7


# 階乗 & 逆元計算
factorial = [1]
inverse = [1]
for i in range(1, N+2):
    factorial.append(factorial[-1] * i % mod)
    inverse.append(pow(factorial[-1], mod-2, mod))


# 組み合わせ計算
def nCr(n, r):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % mod


X = Counter(A).most_common(1)[0][0]
X_index = []
for i, a in enumerate(A, start=1):
    if a == X:
        X_index.append(i)
L, R = X_index[0], X_index[1]

for k in range(1, N + 2):
    if k == 1:
        print(N)
    else:
        print((nCr(N + 1, k) - nCr(N - R + L, k - 1)) % mod)


Measured memory_bytes: 26432
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n;
    ll sum=0;
    cin>>n;
    vector<ll> v;
    map<ll,ll> m;
    for(ll i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        v.push_back(x);
       m[x]++;
    }
    
    map<ll,ll> :: iterator it=m.begin();
    while(it!=m.end())
    {
        ll r=it->second;
        sum=sum+((r-1)*r)/2;
        it++;
    }
    ll sum2=sum;
    for(ll i=0;i<n;i++)
    {
        ll z=v[i];
        ll q=m[z];
        sum2=sum-((q-1)*q)/2;
        q=q-1;
        sum2=sum2+((q-1)*q)/2;
        cout<<sum2<<"\n";
        sum2=sum;
    }
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int w;
  Vi s(2);
  cin >> w >> s[0] >> s[1];
  sort(ALL(s));
  cout << max(0LL,-s[0]-w+s[1]) << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  string s;
  cin>>s;
  
  int a=0;
  if(s[0]=='A') a++;
  int c=0;
  for(int i=2;i<s.size()-1;++i)
    if(s[i]=='C') c++;
  int b=0;
  rep(i,s.size()) if('A'<=s[i] && s[i]<='Z')
    b++;
  
  if(a==1 && c==1 && b==2) cout<<"AC"<<endl;
  else cout<<"WA"<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var nhw = IO.RSInt;
            var a = nhw[0];
            var b = nhw[1];
            var k = nhw[2];

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

                if (i % 2 == 0)
                {
                    if (a % 2 == 1) a--;
                    b += a / 2;
                    a /= 2;
                }
                else
                {
                    if (b % 2 == 1) b--;
                    a += b / 2;
                    b /= 2;
                }
            }
            IO.OutJoinSpace(new int[] { a, b });
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 19176
N = int(input())
A = list(map(int,input().split()))
cums = [0]
for a in A:
    cums.append(cums[-1] + a)
from collections import Counter
ctr = Counter(cums)
ans = 0
for v in ctr.values():
    ans += v*(v-1)//2
print(ans)

Measured memory_bytes: 41364
#include<iostream>
using namespace std;
int main() {
    int N,ans=0;
    cin >> N;
    int C[N],V[N],a[N];
    for (int i=0; i<N; i++) cin >> V[i];
    for (int i=0; i<N; i++) cin >> C[i];
    for (int i=0; i<N; i++) a[i] = V[i] - C[i];
    for (int i=0; i<N; i++) if (a[i] > 0) ans += a[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    set<int> st;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        st.insert(a);
    }
    cout << st.size() << endl;
}


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

int main(){
  int n,i,a,ma,mi;
  cin >> n;
  ma=1; mi=1000000000;
  for(i=0; i<n; i++){
    cin >> a;
    ma=max(ma,a);
    mi=min(mi,a);
  }
  cout << ma-mi << endl;
}

Measured memory_bytes: 256
N,C = map(int,input().split())
XV = [list(map(int,input().split())) for i in range(N)]

migiM = [0]
tmp = 0
for i in range(N):
    tmp =  tmp + XV[i][1]
    migiM.append(max(migiM[-1],tmp-XV[i][0]))

hidariM = [0]
tmp = 0
for i in range(N):
    tmp =  tmp + XV[N-i-1][1]
    hidariM.append(max(hidariM[-1],tmp-C+XV[N-i-1][0]))
    
ans = max(migiM[N],hidariM[N])
tmp = 0
for i in range(N):
    tmp = tmp + XV[i][1]
    if ans < tmp + hidariM[N-1-i] - 2*XV[i][0]:
        ans = tmp + hidariM[N-1-i] - 2*XV[i][0]
        
tmp = 0
for i in range(N):
    tmp = tmp + XV[N-1-i][1]
    if ans < tmp + migiM[N-1-i]  - 2*(C-XV[N-1-i][0]):
        ans = tmp + migiM[N-1-i] - 2*(C-XV[N-1-i][0])

#print(migiM,hidariM)
print(ans)

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

int main() {
  ll q,h,s,d;
  cin >> q >> h >> s >> d;

  ll n;
  cin >> n;

  ll q1,h1,s1,d1;
  q1 = q*4*n;
  h1 = h*2*n;
  s1 = s*n;

  d1 = (d*(n/2));
  if (n % 2 != 0) {
    if (q*4 < h*2 && q*4 < s) {
      d1 += q*4;
    }
    if (h*2 < q*4 && h*2 < s) {
      d1 += h*2;
    }
    if (s < h*2 && s < q*4) {
      d1 += s;
    }
  }

  ll m = d1;
  m = min(m, q1);
  m = min(m, s1);
  m = min(m, h1);
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
import math

def f(a, b, x):
    return math.floor(a * x / b) - a * math.floor(x / b)

a, b, n = map(int, input().split())

if n < b:
    print(math.floor(a * n / b))
    exit(0)
print(f(a, b, b - 1))


Measured memory_bytes: 9180
#include<iostream>
using namespace std;
int main(void)
{
  char a[9];
  while(cin>>a)
    {
      int x=0;
      for(int i=0;i<3;i++)
	{
	  
	  
	  if((a[i*3]=='o' && a[i*3+1]=='o' && a[i*3+2]=='o') || (a[i]=='o' && a[i+3]=='o' && a[i+6]=='o'))
	    {
	      cout<<'o'<<endl;
	      x++;
	      break;
	    }
	  else if((a[i*3]=='x' && a[i*3+1]=='x' && a[i*3+2]=='x') || (a[i]=='x' && a[i+3]=='x' && a[i+6]=='x'))
	    {
	      cout<<'x'<<endl;
	      x++;
	      break;
	    }
	  
	}
      if(a[0]=='o' && a[4]=='o' && a[8]=='o' || (a[2]=='o' && a[4]=='o' && a[6]=='o'))
	{
	  cout<<'o'<<endl;
	  x++;
	}
      if((a[0]=='x' && a[4]=='x' && a[8]=='x') || (a[2]=='x' && a[4]=='x' && a[6]=='x'))
	{
	  cout<<'x'<<endl;
	  x++;
	}
 if(x==0)cout<<'d'<<endl;
    }
  return 0;
}

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

int main(){
    int a,b;
    double t;
    cin>>a>>b>>t;
    
    for(int i=20;i>=0;--i){
        if(i*a <= t+0.5)
        return cout<<i*b,0;
    }
    
    return 0;
}

Measured memory_bytes: 256
s=input()
n=len(s)
i=1
for j in range(n):
    if s[-i:-i-5:-1]=="maerd":
        i+=5
 
    if s[-i:-i-5:-1]=="esare":
        i+=5

    if s[-i:-i-6:-1]=="resare":
        i+=6

    if s[-i:-i-7:-1]=="remaerd":
        i+=7

    if i==n+1:
        print("YES")
        break

if i != n+1:
    print("NO")

Measured memory_bytes: 44396
// ITP1_9_B Shuffle
import java.io.*;

class Main {

   public static void main(String[] args) {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      try {
         String cards = br.readLine();
         while (!(cards.equals("-"))) {
            int m = Integer.parseInt(br.readLine());
            for (int i = 0; i < m; i++) {
               int h = Integer.parseInt(br.readLine());
               String left = cards.substring(0, h);
               String right = cards.substring(h,cards.length());
               cards = right + left;
            }
            System.out.println(cards);
            cards = br.readLine();
         }
      }

      catch (Exception e) {
         System.err.println(e);
      }
   }
}

Measured memory_bytes: 17040
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		String T = sc.next();
		String ans = "";
		for (int i = 0; i < N; i++) {
			ans += S.charAt(i);
			ans += T.charAt(i);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
char S[200010];
int cnt=0,n,a[200010],b[200010];
bool fla=false;
int main()
{
	scanf("%s",S+1);
	int n=strlen(S+1);
	if (S[1]=='S') a[++cnt]=0;else a[++cnt]=1;
	b[cnt]=1;
	for (int i=2;i<=n;i++) 
		if (S[i]!=S[i-1]) {
			if (S[i]=='S') a[++cnt]=0;
			  else a[++cnt]=1;
			b[cnt]=1;
		}
		else b[cnt]++;
	int st=1;
	if (a[1]==1) st++; 
	for (int i=st;i<cnt;i++) {
		if (b[i]<=b[i+1]) {
			b[i+1]-=b[i];
			b[i]=0;
			i++;
		}
		else {
			b[i+1]=b[i]-b[i+1];
			a[i+1]=0;
			b[i]=0;
			b[i+2]+=b[i+1];b[i+1]=0;
			i++;
		}
	}
	int ans=0;
	for (int i=1;i<=cnt+1;i++)
	    ans+=b[i];
	cout<<ans;
	return 0;
}
/*
SSSTT
*/

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

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;

  int x[n];
  for (int i = n; i > 0; i--) {
    cin >> x[i - 1];
  }
  cout << x[0];
  for (int i = 1; i < n; i++) {
    cout << " " << x[i];
  }
  cout << endl;

  return 0;
}



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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

//typedef pair<int,int>			P;
typedef vector<int>				V;
typedef vector<V>				VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		40010

const ll LINF = (ll)1e18+7;		//
const int INF = 1e9+7;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//




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

	cout << (N*N*N) << endl;


	return 0;
}




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

using namespace std;

const long long INF = 1E18;
const int MAXN = 1E5;
const int MOD = 1E9 + 7;
vector<pair<int, int>> adjList[MAXN + 1];
int ways1[MAXN + 1];
int ways2[MAXN + 1];
long long dist1[MAXN + 1];
long long dist2[MAXN + 1];
int path1[MAXN + 1];
int path2[MAXN + 1];
bool visited1[MAXN + 1];

inline int add(int a, int b)
{
    if (a + b >= MOD)
        return a + b - MOD;
    return a + b;
}

void dijkstra(int s, int ways[MAXN + 1], long long dist[MAXN + 1], bool visited[MAXN + 1], int path[MAXN + 1])
{
    priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> pq;
    fill(dist, dist + MAXN + 1, INF);
    dist[s] = 0;
    ways[s] = 1;
    pq.push(make_pair(0LL, s));
    path[s] = -1;
    while (!pq.empty())
    {
        pair<long long, int> pr = pq.top();
        pq.pop();
        int v = pr.second;
        if (visited[v])
            continue;
        long long d = pr.first;
        visited[v] = true;
        for (pair<int, int> edge : adjList[v])
        {
            int adj = edge.first;
            int w = edge.second;
            if (!visited[adj])
            {
                if (d + w < dist[adj])
                {
                    path[adj] = v;
                    dist[adj] = d + w;
                    pq.push(make_pair(dist[adj], adj));
                }
            }
            else if (v != s)
            {
                if (dist[adj] + w == dist[v])
                {
                    ways[v] = add(ways[v], ways[adj]);
                }
            }
        }
    }
}

void process(int v, int u, int &exclude)
{
    int temp = (int) (((long long) ways1[v] * ways2[u]) % MOD);
    temp = (int) (((long long) temp * ways1[v]) % MOD);
    temp = (int) (((long long) temp * ways2[u]) % MOD);
    exclude = add(exclude, temp);
}

int main()
{
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    for (int i = 0; i < m; i++)
    {
        int u, v, d;
        cin >> u >> v >> d;
        adjList[u].push_back(make_pair(v, d));
        adjList[v].push_back(make_pair(u, d));
    }
    dijkstra(s, ways1, dist1, visited1, path1);
    fill(visited1, visited1 + MAXN + 1, false);
    dijkstra(t, ways2, dist2, visited1, path2);
    long long shortest = dist1[t];
    int exclude = 0;
    for (int i = 1; i <= n; i++)
    {
        if (dist1[i] + dist2[i] > shortest)
            continue;
        if (2 * dist1[i] == shortest)
        {
            process(i, i, exclude);
        }
        else
        {
            for (pair<int, int> edge : adjList[i])
            {
                int adj = edge.first;
                int w = edge.second;
                if (dist1[adj] + w + dist2[i] == shortest && 2 * dist1[i] > shortest && 2 * dist1[adj] < shortest)
                {
                    process(adj, i, exclude);
                }
            }
        }
    }
    int ans = (int) (((long long) ways1[t] * ways1[t]) % MOD);
    //(int) (((long long) cnt1 * cnt2) % MOD);
    ans = add(ans, MOD - exclude);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15700
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/*
??\????????????????????????????°?????????????????????????????£??????????????????????

insert str : ????????? str ??????????????????
find str : ????????? str ?????????????????´??? 'yes'??¨????????????????????´??? 'no'??¨???????????????

??\???

??????????????????????????° n
?????????????????????????¶???? n ?????? n

??¶?????????????????????????????????????????????????????¢??????????¨??????¨????????§?????????

??????

??? find ?????????????????????yes ????????? no ???????????????????????????????????????

??¶?´?

??????????????????????????????'A', 'C', 'G', 'T' ???????¨????????????????????§????????????????
1????????????????????????12
n???1,000,000
*/

public class Main {
    
    public static void main(String[] args) throws IOException {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//        insert????????\??????????????????????????¢?????????????????????a-t??????????????????????????????
        HashSet<String> dica = new HashSet<String>();
        HashSet<String> dicc = new HashSet<String>();
        HashSet<String> dicg = new HashSet<String>();
        HashSet<String> dict = new HashSet<String>();
//        ????????¨
        StringBuffer sb = new StringBuffer();
//        ??\????????°n?????\??????
        int n = Integer.parseInt(br.readLine());
//        ????´¢?????????????????£????????????????????????
        boolean ft;
        String[] tmp;
        
        for (int i = 0; i < n; i++) {
            tmp = br.readLine().split(" ");
            if (tmp[0].equals("insert")) {
                switch (tmp[1].charAt(0)) {
                    case 'A':
                        dica.add(tmp[1]);
                        break;
                    case 'C':
                        dicc.add(tmp[1]);
                        break;
                    case 'G':
                        dicg.add(tmp[1]);
                        break;
                    case 'T':
                        dict.add(tmp[1]);
                        break;
                }
            } else {
                ft = false;
                switch (tmp[1].charAt(0)) {
                    case 'A':
                        if (dica.contains(tmp[1])) ft = true;
                        break;
                    case 'C':
                        if (dicc.contains(tmp[1])) ft = true;
                        break;
                    case 'G':
                        if (dicg.contains(tmp[1])) ft = true;
                        break;
                    case 'T':
                        if (dict.contains(tmp[1])) ft = true;
                        break;
                }
                if (ft) {
                    sb.append("yes\n");
                } else {
                    sb.append("no\n");
                }
            }
        }
        
        sb.deleteCharAt(sb.lastIndexOf("\n"));
        System.out.println(sb.toString());
    }
}

Measured memory_bytes: 195392
import math

vals = []
for _ in range(5):
	vals.append( int(input()) )

amari = sorted([val % 10 for val in vals if val % 10 != 0])
rounded = [math.ceil(val/10)*10 for val in vals]


ret = sum(rounded)
if len(amari) > 0:
	ret += amari[0] - 10

print(ret)

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

class Bmondai
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var S = Console.ReadLine();
        var K = Int32.Parse(Console.ReadLine());
        var letter = S[K - 1];
        var ans = string.Empty;
        for (int i = 0; i < N;++i)
        {
            if (S[i] == letter) ans += S[i];
            else ans += '*';
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;

class Main {
    public static void main(String[] args) throws IOException {
	    	BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String str = reader.readLine();
            StringBuffer sb = new StringBuffer(str);
            System.out.println(sb.reverse());
    }
}

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

using namespace std;
const int IINF = INT_MAX;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000000000
int n;

int main(){
    double a,b,x;
	cin >> a >> b >> x;
	
	double s = x/a;
	double ans = 0;
	if(s >= a*b/2){
		double h = (a*b-s)*2/a;
		ans = atan2(h,a); 
	}else{
   		 double k = 2*s/b;
   		 ans = atan2(b,k);
    }
    double pai = acos(-1);
    cout << fixed <<  setprecision(7) << ans/(2*pai)*360 << endl; 
    return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF (int)1e9
#define MOD 0
//#define int ll
using namespace std;
typedef vector<int> vi;
 
int dp[101][4][4][4];
ll mod = (ll)1e9+7;

signed main(){
    int N;
    cin >> N;

    //長さ０の文字列は1である
    //０，１，２に関する制約しかないので、Sは333Sと考えても問題がない
    dp[0][3][3][3] = 1;
    
    //文字列の文字数
    rep(len,N) {
        //最後から1文字目の文字
        rep(c1,4) {
            //最後から2文字目の文字
            rep(c2,4) {
                //最後から3文字目の文字
                rep(c3,4){
                    //条件に当てはまるものがない場合はcontinue;
                    if(dp[len][c1][c2][c3] == 0) continue;

                    //新しく追加する文字
                    rep(a,4) {
                        //ダメな5つの条件をカットする
                        if( a == 2 && c1 == 1 && c2 == 0) continue;
                        if( a == 2 && c1 == 0 && c2 == 1) continue;
                        if( a == 1 && c1 == 2 && c2 == 0) continue;
                        if( a == 2 && c1 == 1 && c3 == 0) continue;
                        if( a == 2 && c2 == 1 && c3 == 0) continue;

                        //ダメな条件を抜けたら、aを足した文字列が作れる
                        //S = ........c3 c2 c1
                        //nextS = .......c2 c1 a

                        dp[len + 1][a][c1][c2] += dp[len][c1][c2][c3];
                        dp[len + 1][a][c1][c2] %= mod;
                    }
                }
            }
        }
    }

    int ans = 0;

    //最後から1文字目の文字
    rep(c1,4) {
        //最後から2文字目の文字
        rep(c2,4) {
            //最後から3文字目の文字
            rep(c3,4) {
                ans += dp[N][c1][c2][c3];
                ans %= mod;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define ff first
#define ss second
#define pri 1000000007 
using namespace std;

int main() {
	
	ll a,b;
	cin>>a>>b;
	if(a>=13){cout<<b<<endl;}
	else if(a>=6){cout<<b/2<<endl;}
	else{ cout<<0<<endl;}
	
	// your code goes here
	return 0;
}

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

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

int main() {
    int N;
    cin >> N;

    int ans = 0;

    if (N <= 9)
        ans = N;
    else if (N <= 99)
        ans = 9;
    else if (N <= 999)
        ans = 9 + (N - 100 + 1);
    else if (N <= 9999)
        ans = 909;
    else if (N <= 99999)
        ans = 909 + (N - 10000 + 1);
    else
        ans = 90909;
    cout << ans << endl;
}

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

int selection_sort(vector<int>& a){
    int count_swap{0};

    for (int i = 0; i < a.size(); i++){
        int minj{i};
        for (int j = i; j < a.size(); j++){
            if (a[minj] > a[j]){
                minj = j;
            };
        }
        if (minj != i){
            swap(a[minj], a[i]);
            count_swap += 1;
        };
    };
    return count_swap;
}

int main(){

    int N{0};
    cin >> N;
    //#unique_ptr<array<int, N>> a;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int count_swap{0};
    count_swap = selection_sort(a);
    for (int i = 0; i < N; i++) {
        if (i) cout << " ";
        cout << a[i];
    }
    cout << endl << count_swap << endl;
    return 0;
}



Measured memory_bytes: 3088
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll>pll;

int main() {
	int N, M, a[100001], b[100001], D[100001];
	cin >> N >> M;
	REP(i, N) {
		D[i] = N + 1;
	}
	REP(i, M) {
		cin >> a[i] >> b[i];
		D[a[i] - 1] = min(D[a[i] - 1], b[i] - 1);
	}


	int cnt = 0, k = N + 1;

	REP(i, N) {
		if (i >= k) {
			cnt++;
			k = D[i];
		}
		k = min(k, D[i]);
	}

	cout << cnt << endl;


	return 0;
}

Measured memory_bytes: 1408
#                         author:  kagemeka 
#                         created: 2019-11-06 16:18:30(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    n, *a = (int(x) for x in sys.stdin.read().split())
    a.sort(reverse=1)
    alice, bob = 0, 0
    for i in range(n):
        if i % 2 == 0:
            alice += a[i]
        else:
            bob += a[i]
    ans = alice - bob
    print(ans)


if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
import collections,itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
while 1:
    w,h = LI()
    if w==h==0:
        break
    ans = 0
    c = [LI() for _ in range(h)]
    seen = [[0]*w for _ in range(h)]
    stack = []
    dhdw = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]
    def dfs(H,W):
        seen[H][W] = 1
        stack.append([H,W])
        while stack:
            sh,sw = stack.pop()
            for dh,dw in dhdw:
                nh,nw = sh+dh,sw+dw
                if not(0<=nh<=h-1) or not(0<=nw<=w-1) or seen[nh][nw] or c[nh][nw]==0:
                    continue
                seen[nh][nw] = 1
                stack.append([nh,nw])
    for H,W in itertools.product(range(h),range(w)):
        if seen[H][W] or c[H][W]==0:
            continue
        ans += 1
        dfs(H,W)
    print(ans)



Measured memory_bytes: 6044
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

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

	N := getInt()
	m := make(map[int]int)
	sum := 0
	m[sum]++
	for i := 0; i < N; i++ {
		a := getInt()
		sum += a
		m[sum]++
	}

	ans := 0
	for _, v := range m {
		if v >= 2 {
			if v%2 == 0 {
				ans += v / 2 * (v - 1)
			} else {
				ans += v * ((v - 1) / 2)
			}
		}
	}

	out(ans)
}


Measured memory_bytes: 12672
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
int main()
{
	long long W, H, x, y;
	scanf("%lld%lld%lld%lld", &W, &H, &x, &y);
	if (W / 2 == x && W % 2 == 0 && H / 2 == y && H % 2 == 0) {
		printf("%f %d", (double)W * H / 2, 1);
	}
	else {
		printf("%f %d", (double)W * H / 2, 0);
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		if (n%2==0) {
			System.out.println(n/2);
		}else{
			System.out.println(n/2+1);
		}


	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k; vl p(3);
    cin>>n>>k>>p;
    string s;cin>>s;
    ll ans=0;
    rep(r,k){
        string t="";
        for(ll j=r;j<n;j+=k)t+=s[j];
        // dp[i][j]=i回目の結果で，ちょうどk回前にjを出した時の結果
        ll l=t.size();
        vvl dp(l+1, vl(3,0));
        rep(i,l){
            rep(j,3)rep(pre,3)if(pre!=j){
                chmax(dp[i+1][j], dp[i][pre]+("spr"s[j]==t[i]?p[j]:0));
            }
        }
        ans+=max(dp[l]);
    }
    puta(ans);

    return 0;
}

Measured memory_bytes: 5888
import java.util.ArrayDeque;
import java.util.Scanner;

public class Main {

	static char	s[];
	static char	t[];

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		s = in.next().toCharArray();
		t = in.next().toCharArray();
		in.close();

		int row = t.length;
		int col = s.length;
		int tb[][] = new int[row + 1][col + 1];
		for(int i = 0; i<=row; i++)tb[i][0] = 0;
		for(int i = 0; i<=col; i++)tb[0][i] = 0;

		for ( int r = 0; r < row; r++ ) {
			for ( int c = 0; c < col; c++ ) {
				if ( t[r] == s[c] ) {
					tb[r + 1][c + 1] = tb[r][c] + 1;
				} else {
					tb[r + 1][c + 1] = Math.max(tb[r + 1][c], tb[r][c + 1]);
				}
			}
		}

		int r = row;
		int c = col;
		ArrayDeque<Character> stack = new ArrayDeque<Character>();
		stack.add(' ');
		while ( tb[r][c] != 0 ) {

			// 左上に行けるとき
			if ( tb[r - 1][c - 1] == tb[r][c]) {
				r -= 1;
				c -= 1;
			} else
			// 上にだけ行けるとき
			if ( tb[r - 1][c] ==  tb[r][c]) {
				r -= 1;
			} else
			// 左にだけ行けるとき
			if ( tb[r][c - 1] == tb[r][c]) {
				c -= 1;
			} else
			// 行き止まり
			{
				stack.add((Character) s[c - 1]);
				r -= 1;
				c -= 1;
			}
		}
//		if ( stack.size() == 0 ) {
//			System.out.print("");
//			return;
//		}

		while ( stack.size() > 0 ) {
			System.out.print(stack.pollLast());
		}
	}
}


Measured memory_bytes: 83020
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <bitset>
#include <map>
#include <set>
#include <vector>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>

#define ll long long

using namespace std;

int v[88][88];
bitset<25600> dp[88][88];

int
main() {

  int h, w;
  cin>>h>>w;

  for (int i=0; i<h; i++)
    for (int j=0; j<w; j++)
      cin>>v[i][j];

  int temp;
  for (int i=0; i<h; i++)
    for (int j=0; j<w; j++) {
      cin>>temp;
      v[i][j] = abs(v[i][j] - temp);
    }

  dp[0][0][12800+v[0][0]] = 1;
  dp[0][0][12800-v[0][0]] = 1;
  for (int i=0; i<h; i++)
    for (int j=0; j<w; j++) {
      if (i + 1 < h) 
        dp[i+1][j] |= dp[i][j] << v[i+1][j] | dp[i][j] >> v[i+1][j];
      if (j + 1 < w)
        dp[i][j+1] |= dp[i][j] << v[i][j+1] | dp[i][j] >> v[i][j+1];
    }

  int ans = 0;
  while (!dp[h-1][w-1][12800+ans] && !dp[h-1][w-1][12800-ans])
    ans++;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 22656
def main():
    s = input()
    length = len(s)-1
    count = s.count('B')
    init = sum([i for i in range(len(s)) if s[i] == "B"])
    processed = sum(range(length-count+1, length+1))

    print(processed-init)


if __name__ == '__main__':
    main()


Measured memory_bytes: 52960
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <ll, int> P;
const ll MOD=1e9+7;
const int MAX_V=100000;
const ll INF=1e17;
struct edge {int to; ll cost;};
int V, M, S,T;
vector <edge> G[MAX_V];
ll d[2][MAX_V], n[2][MAX_V];
void dijkstra (int s, int k){
    priority_queue<P, vector<P>, greater<P>> que;
    auto itr=d[k];
    fill(itr,itr+V,INF);
    itr[s]=0;
    que.push(P(0,s));
    while (!que.empty()) {
        P p=que.top();  que.pop();
        int v=p.second;
        if (itr[v]<p.first) continue;
        rep(i,0,G[v].size()){
            edge e=G[v][i];
            if (itr[e.to]>itr[v]+e.cost){
                itr[e.to]=itr[v]+e.cost;
                que.push(P(itr[e.to], e.to));
            }
        }
    }
}

void dfs(int s, int k){
    priority_queue<P, vector<P>, greater<P>> que;
    auto dd=d[k];
    rep(i,0,V) que.push(P(dd[i], i));
    auto N=n[k];
    N[s]=1;
    while(!que.empty()){
        P p=que.top(); que.pop();
        int v=p.second;
        rep(i,0,G[v].size()){
            edge e=G[v][i];
            if (dd[e.to]==dd[v]+e.cost){
                N[e.to]+=N[v];
                N[e.to]%=MOD;
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>V>>M>>S>>T;
    S--; T--;
    rep(i,0,M){
        int u,v; ll D;
        cin>>u>>v>>D;
        u--; v--;
        G[u].pb(edge{v,D});
        G[v].pb(edge{u,D});
    }
    dijkstra(S,0); dijkstra(T, 1);
    dfs(S,0); dfs(T,1);
    ll D=d[0][T];
    ll ans=n[0][T]*n[0][T]%MOD;
    rep(i,0,V){
        if(d[0][i]*2==D&&d[1][i]*2==D){
            ans-=n[0][i]*n[0][i]%MOD*n[1][i]%MOD*n[1][i]%MOD;
            if(ans<0) ans+=MOD;
        }
    }
    rep(i,0,V){
        for(auto &e : G[i]){
            if(d[0][i]+e.cost+d[1][e.to]==D&&d[0][i]*2<D&&d[1][e.to]*2<D){
                ans-=n[0][i]*n[0][i]%MOD*n[1][e.to]%MOD*n[1][e.to]%MOD;
                if(ans<0) ans+=MOD;
            }
        }
    }
    cout <<ans<<"\n";
}

Measured memory_bytes: 20340
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -9223372036854775807
#define inf 9223372036854775807
#define f first
#define se second
#define mod 1000000007
#define mx 100001
using namespace std;
ll mi(ll n,ll m){ll pw=n%m;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans%mod;}
ll pw(ll a,ll n){ll pw=a%mod;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw%mod;pw = pw*pw%mod;ex>>=1;}return ans%mod;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
void show(ll x){cout<<x<<" ";}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define to_low(s) for_each(s.begin(), s.end(), [](char & c) {c = ::tolower(c);})
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mkp make_pair
//#define d double
void solve(){
	ll n;
	cin>>n;
	cout<<Ceil(n,2)<<endl;
	
	
	
 
 
}
int32_t main(){
FIO;
int t=1;
//cin>>t;
while(t--){
	solve();
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

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

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
const int MAXN = 200005;
using lint = long long;

int n, a[MAXN], b[MAXN];
queue<int> que;

int opable(int x){
	int l = (x + n - 1) % n;
	int r = (x + 1) % n;
	return max(0, b[x] - a[x]) / (b[l] + b[r]);
}

void solve(){
	scanf("%d",&n);
	for(int i=0; i<n; i++) scanf("%d",&a[i]);
	for(int i=0; i<n; i++) scanf("%d",&b[i]);
	for(int i=0; i<n; i++){
		if(opable(i)) que.push(i);
	}
	lint ans = 0;
	while(sz(que)){
		auto x = que.front(); que.pop();
		int l = (x + n - 1) % n, r = (x + 1) % n;
		ans += opable(x);
		b[x] -= (b[l] + b[r]) * opable(x);
		if(opable(l)) que.push(l);
		if(opable(r)) que.push(r);
	}
	for(int i=0; i<n; i++){
		if(a[i] != b[i]){
			puts("-1");
			return;
		}
	}
	cout << ans << endl;
}

int main(){
	solve();
}


Measured memory_bytes: 2176
_ = int(input())
H = list(map(int, input().split()))

max_count = 0
last = 10 ** 9
count = -1
for h in H:
  if h <= last:
    count += 1
  else:
    max_count = max(max_count, count)
    count = 0
  last = h

max_count = max(max_count, count)
print(max_count)


Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define mod 1000000007
#define int long long

int dp[3001][3001][2];

int game(int i, int j, int k, vector<int> &a) {
	int n = a.size();
	if (i >= n || j >= n || i < 0 || j < 0)return 0;
	if (i > j)return dp[i][j][k] = 0;
	if (dp[i][j][k] != -1)return dp[i][j][k];

	dp[i][j][0] = max(a[i] + game(i + 1, j, 1, a), a[j] + game(i, j - 1, 1, a));
	dp[i][j][1] = min(game(i + 1, j, 0, a), game(i, j - 1, 0, a));

	return dp[i][j][k];
}

void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	int i, j, k;
	for (i = 0; i < n; i++)cin >> a[i];
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			for (k = 0; k < 2; k++)dp[i][j][k] = -1;
		}
	}

	int sum = 0;
	for (i = 0; i < n; i++) {
		sum += a[i];
	}

	int x = game(0, n - 1, 0, a);
	int y = sum - x;
	cout << x - y << endl;

	return;
}

int32_t main() {

	std::ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	int t = 1;
	// cin >> t;
	while (t--)solve();
	return 0;
}

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

int main() {
    string s;ll k;cin >> s >> k;
    ll q=0;

    bool w=true;
    for(int i = 1; i < s.size(); i++) {
        if(s[i]!=s[0]) w=false;
    }
    if(w){
        ll z=s.size();
        cout << z*k/2 << endl;
        return 0;
    }
    ll a=1,b=1;
    if(s[0]==s[s.size()-1]){
        
        for(int i = 1; i < s.size(); i++) {
            if(s[i]!=s[0]) break;
            a++;
        }
        for(int i = s.size()-2; i >0; i--) {
            if(s[i]!=s[0]) break;
            b++;
        }
    }
    ll c=0,d=1;
    char x=s[0];
    for(int i = 1; i < s.size(); i++) {
        if(s[i]==s[i-1]) d++;
        else{
            d/=2;
            c+=d;
            x=s[i];
            d=1;
        }
    }
    d/=2;
    c+=d;

    if(s[0]==s[s.size()-1]){
        cout << c*k+(k-1)*((a+b)/2-a/2-b/2) << endl;
    }
    else{
        cout << c*k << endl;
    }


    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
typedef long long ll;
typedef pair<ll,ll> P;
#define N 100010
ll n,l[N];
P rui[N];
ll dat[N];
void add(ll i,ll x){
	i++;
	for(;i<N;i+=i&-i)dat[i]+=x;
}
ll sum(ll i){
	i++;
	ll res=0;
	for(;i>0;i-=i&-i)res+=dat[i];
	return res;
}
int main(){
	cin>>n;
	ll ru=0; rui[0]=make_pair(0,0);
	rep(i,n){
		ll p; cin>>p;
		ru+=p;
		rui[i+1]=make_pair(ru,i+1);
	}
	sort(rui,rui+n+1);
	rep(i,N)dat[i]=0;
	ll ans=0;
	rep(i,n+1){
		ans+=sum(n)-sum(rui[i].second-1);
		add(rui[i].second,+1);
	}
	rep(i,n){
		cin>>l[i];
		if(rui[i+1].first-rui[i].first<l[i])ans=-1;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 6200
N, K = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))

move_db = [[0] * N for _ in range(65)]
point_db = [[0] * N for _ in range(65)]
maxpoint_db = [[0] * N for _ in range(65)]

for i, (p, c) in enumerate(zip(P, C)):
    move_db[0][i] = p
    point_db[0][i] = c
    maxpoint_db[0][i] = c

for i in range(40):
    for j in range(N):
        move_db[i+1][j] = move_db[i][move_db[i][j]]
        point_db[i+1][j] = point_db[i][move_db[i][j]] + point_db[i][j]
        maxpoint_db[i+1][j] = max(maxpoint_db[i][j], point_db[i][j] + maxpoint_db[i][move_db[i][j]])

res = -10 ** 19
for i in range(N):
    tmp, now = 0, i
    for d in range(32):
        if K&(1<<d):
            res = max(res, tmp + maxpoint_db[d][now])
            tmp += point_db[d][now]
            now = move_db[d][now]

print(res)


Measured memory_bytes: 85752
H,W = map(int, input().split())
s = [[-1 if w == "#" else 9999 for w in input()] for h in range(H)]
black = sum([ sum([ 1 for w in range(W) if s[h][w] == -1]) for h in range(H)])

neighbors = [(-1, 0), (1, 0), (0, -1), (0, 1)]
s[0][0] = 1
check_list = [(0, 0)]
index = 0
while index < len(check_list):
    check = check_list[index]
    for neighbor in [(check[0] + neighbor[0], check[1] + neighbor[1]) for neighbor in neighbors]:
        if 0 <= neighbor[0] < H and 0 <= neighbor[1] < W and s[neighbor[0]][neighbor[1]] != -1:
            if s[neighbor[0]][neighbor[1]] > s[check[0]][check[1]] + 1:
                s[neighbor[0]][neighbor[1]] = s[check[0]][check[1]] + 1
                check_list.append(neighbor)
    index += 1

if s[H - 1][W - 1] == 9999:
    print(-1)
else:
    print(W*H - black - s[H - 1][W - 1])


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
long a[2200];
int main(){
  long n,z,w,i;
  cin>>n>>z>>w;
  for(i=0;i<n;i++)cin>>a[i];
  if(n==1)cout<<labs(a[n-1]-w);
  else cout<<max(labs(a[n-1]-a[n-2]),labs(a[n-1]-w));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
void solve()
{
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<c<<' '<<a<<' '<<b;
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
}

Measured memory_bytes: 256