akhauriyash/Code-Regression huggingface dataset:
def osilate(seq):
    flag = 1
    acc = 0
    ans = 0
    #while loop O(n)
    for i in range(len(seq)):
        a = seq[i]
        acc += a
        flag = i%2

        if flag == 0:
            if acc <= 0:
                ans += 1-acc
                acc = 1
        if flag == 1:
            if acc >= 0:
                ans += 1+acc
                acc = -1
        #print(seq, acc, acc)
        flag = flag * (-1)
    return ans

n = int(input()) #(1)
seq = [int(i) for i in input().split()] #O(N)

seq_rev = [-i for i in seq]  # O(N)
print(min(osilate(seq),osilate(seq_rev))) #O(2N)


Measured memory_bytes: 14468
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#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++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int d, n; cin >> d >> n;
    if(d == 0) {
        cout << (n != 100 ? n : 101) << endl;
    } else if(d == 1) {
        cout << (n != 100 ? n * 100 : 10100) << endl;
    } else {
        cout << (n != 100 ? n * 10000 : 1010000) << endl;
    }
}

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

Measured memory_bytes: 3648
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
 
template <typename T>
void ivec(vector<T> &v, ll N){
    REP(i,0,N){ T x; cin >> x; v.push_back(x); }
}

int main(){
    ll N, K;
    cin >> N >> K;

    ll s = 0;
    vector<ll> ls(1,0);
    REP(i,0,N){
        ll p;
        cin >> p;
        s+=p+1;
        ls.push_back(s);
    }

    ll ret = 0;
    REP(i,0,N-K+1){
        ret = max(ret, ls[i+K]-ls[i]);
    }

    cout << fixed << setprecision(10) << (double)ret / 2.0 << endl;
    return 0;
}

Measured memory_bytes: 2420
def solve(N, A):
    c = 0
    z = 0
    if A[0] != 0:
        return -1
    for i in range(1, N):
        if A[i] == 0:
            z = 0
            c+=A[i-1]
        elif A[i-1] < A[i] - 1:
            return -1
        elif A[i] <= i - z:
            if A[i] != A[i-1]+1:
                c += A[i-1]
        else:
            return -1
        #print("A[%d]=%d, c=%d" % (i, A[i], c))
    c += A[-1]
    return c

def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = [0]*N
    for i in range(N):
        A[i] = int(input())
    print(solve(N, A))

main()


Measured memory_bytes: 10868
import bisect
n= int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
ans = 0
for i in range(n):
    x = bisect.bisect_left(a,b[i])
    y = bisect.bisect_right(c,b[i])
    ans += x*(n-y)
print(ans)


Measured memory_bytes: 23360
#include <stdio.h>
int main(void){
    int b,r,g,c,s,t;
    while(scanf("%d%d%d%d%d%d",&b,&r,&g,&c,&s,&t) , t != 0){
        printf("%d\n",b * 95 + r * 63 + g * 7 + c * 2 + s * 3 - t * 3 + 100);
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

#define EPS 1e-14
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define INFLL (ll)1e18 //Long long infinity
#define INF (int)1e9 //Int infinity
#define MX 100005

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vd> vvd;
typedef vector<string> vstr;

#define us unordered_set
#define um unordered_map
#define bs bitset

#define RANGE(i,a,b,d) for (int i=min((int)a,(int)b); i<max((int)a,(int)b); i+=d)
#define RRANGE(i,a,b,d) for (int i=max((int)a,(int)b); i>min((int)a,(int)b); i+=d)
#define FOR(i,a,b) RANGE(i,a,b,1)
#define RFOR(i,a,b) RRANGE(i,a,b,-1)
#define REP(i,s) FOR(i,0,s)
#define RREP(i,s) RFOR(i,s-1,-1)
#define FORIT(it,l) for (auto it = l.begin(); it != l.end(); it++)
#define EACH(x,v) for (auto &x : v)

#define sz(x) (int)(x).size()
#define len(x) (int)sizeof(x)/sizeof(*x)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define contains(m,x) (m.find(x) != m.end()) // check if an element in a map
#define isIn(S, s) (S.find(s) != string::npos) // check if substring

#define pv(v) EACH(x, v) cout << x << " "; cout << endl; // print vector/array
#define pvv(vv) EACH(xx, vv){pv(xx);} // print 2-d vector/2-d array
#define pm(m) EACH(x, m) cout << x.F << ":" << x.S << " "; cout << endl; //print map/lookup table

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

namespace std{
  // Used for hashing pair
  template <> struct hash<pi>{
    size_t operator()(const pi&x)const{
      ll P=38923, Q=109797901;
      return (size_t)((x.F*P+x.S)%Q);
    }
  };
};

// This is min queue
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
void print(T t){
  cout << t << endl;
}

//Python style printing
template<typename T, typename... Args>
void print(T t, Args... args){
  cout << t << " ";
  print(args...);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k, x;
  cin >> k >> x;
  FOR(i, x-k+1, x+k) cout << i << " \n"[i==x+k-1];
  return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)

c=0
for i in range(M):
    if A[i]<sum(A)/(4*M):c+=1
    else:c+=0
if c==0:print('Yes')
else:print('No')
  

Measured memory_bytes: 2940
#include <stdio.h>

int main(void)
{
	char board[16];
	
	while (scanf("%s", board) != EOF){
		char win = 's';
		int i, j;
		
		for (i = 0; i < 3; i++){
			if (board[i * 3] == board[i * 3 + 1] && board[i * 3] == board[i * 3 + 2]){
				win = board[i * 3];
			}
			if (board[i] == board[i + 3] && board[i] == board[i + 6]){
				win = board[i];
			}
			if (win != 's'){
				break;
			}
		}
		if (board[4] != 's'){
			if (board[0] == board[4] && board[4] == board[8]){
				win = board[4];
			}
			if (board[2] == board[4] && board[4] == board[6]){
				win = board[4];
			}
		}
		printf("%c\n", win == 's' ? 'd' : win);
	}
	
	return 0;
}

Measured memory_bytes: 540
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}
signed main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	int h=0;
	while(1){
		int co=0,g=0;
		int ma=1;
		rep(i,n)if(in[i]-1){
			if(in[i]%2)cmax(ma,in[i]);
			co+=in[i]%2==0,in[i]-=in[i]%2,g=gcd(g,in[i]);
		}
		if(g)rep(i,n)in[i]/=g;
		if(co%2){
			if(h)cout<<"Second"<<endl;
			else cout<<"First"<<endl;
			return 0;
		}else{
			if(n-co-1||ma==1){
				if(!h)cout<<"Second"<<endl;
				else cout<<"First"<<endl;
				return 0;
			}
		}
		h^=1;
	}
}












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

int main() {
    vector<int> a(5);
    rep(i,5) cin >> a[i];
    ll ans = 999999999;
    do{
        ll t = 0;
        rep(i,5){
            t = (t+9)/10*10;
            t+=a[i];
        }
        ans = min(ans, t);

    }while(next_permutation(all(a)));
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/


int main(){
    string s; cin >> s;
    int n = s.size();
    vector<int> count(3, 0);
    rep(i, n){
        if(s[i] == 'a')count[0]++;
        else if(s[i] == 'b')count[1]++;
        else if(s[i] == 'c')count[2]++;
    }
    sort(count.begin(), count.end());
    if(count[2] - count[0] <= 1){
        cout << "YES" << endl;
    }else cout << "NO" << endl;
}

Measured memory_bytes: 512
import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main(args: Array<String>) {
  val (a, b, h, m) = readDs()
  val sa = (h + m / 60) * 30
  val sb = m * 6
  var d = abs(sa - sb)
  if (180.0 < d) d = 360.0 - d
  val x = sqrt(a * a + b * b - 2 * a * b * cos(d * PI / 180))
  println("%.10f".format(x))
}


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

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

  if(A >= 13)
    cout << B << endl;
  else if(A >= 6 && A <= 12)
    cout << B/2 << endl;
  else
    cout << 0 << endl;

  return 0;
}

Measured memory_bytes: 256
//2018-03-25
//LZYeah
//
#include<bits/stdc++.h>
#define ll long long
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define Forr(i,a,b) for(register int i=a;i>=b;i--)
using namespace std;
inline void File()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
inline void read(int &x)
{
	int p=1;
	x=0;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)){x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
	x*=p;
}
#define N (100+10)
int a,b,n,m;
char c[N][N];
int main()
{
//	File();
	read(a),read(b);
	For(i,1,50)For(j,1,100)c[i][j]='#';
	For(i,51,100)For(j,1,100)c[i][j]='.';
	a--,b--;
	n=2,m=2;
	while(a)
	{
		c[n][m]='.';
		m+=2;
		a--;
		if(m>100){n+=2;m=2;}
	}
	n=52,m=2;
	while(b)
	{
		c[n][m]='#';
		m+=2;
		b--;
		if(m>100){n+=2;m=2;}
	}
	cout<<100<<' '<<100<<endl;
	For(i,1,100){For(j,1,100)printf("%c",c[i][j]);puts("");}
	return 0;
}


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

#define llu             unsigned long long int
#define ll              long long int
#define f0(i, n)        for( i = 0 ; i <  n ; i++ )
#define f1(i, n)        for( i = 1 ; i <= n ; i++ )
#define ff(i, m, n)     for( i = m ; i <= n ; i++ )
#define sp(i)           fixed << setprecision( i )
#define pb              push_back
#define pf              push_front
#define nl              cout<<"\n";

///ELIN75ELIN75ELIN75ELIN75ELIN75ELIN75ELIN75ELIN75ELIN75
///                    ELIN(K-5)
///ELIN47ELIN47ELIN47ELIN47ELIN47ELIN47ELIN47ELIN47ELIN47

int main()
{
    ll a,b,c;
    cin>>a>>b;
    c=a%b;
    if(c==0)
    {
        cout<<0<<endl;
    }
    else if(c<=b/2)
    {

        cout<<c<<endl;
    }
    else
    {
        cout<<b-c<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a < b){
     printf("a < b\n");
    }
    else if(a > b){
     printf("a > b\n",a,b);
    }
    else{ 
     printf("a == b\n",a,b);
    }
    return 0;
}



Measured memory_bytes: 2112
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL d,g;
    cin >> d >> g;
    vector<LL> p(d+1),c(d+1);
    for(int i = 0; i < d; i++){
        cin >> p[i] >> c[i];
    }

    LL min = 100*10;

    for(int i = 0; i < 1 << d; i++){
        LL x = 0;
        LL num = 0;
        for(int j = 0; j < d; j++){
            if(((1 << j) & i) == (1 << j)){
                num += p[j];
                x += p[j]*(j+1)*100 + c[j];
            }
        }
        if(x >= g){
            if(min > num){
                min = num;
            }
        }else{
            LL ind = -1;
            for(int k = d-1; k >= 0; k--){
                if(((1 << k) & i) != (1 << k)){
                    ind = k;
                    break;
                }
            }
            if(ind >= 0){
                for(int k = 0; k < p[ind]; k++){
                    if(x+k*(ind+1)*100 >= g){
                        if(min > num + k){
                            min = num + k;;
                        }
                    }
                }
            }
        }
    }
    
    cout << min << endl;

    return 0;
}

Measured memory_bytes: 256
# include<bits/stdc++.h>
 
using namespace std;
 
# define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;
 
# define S second
# define F first
# define kill(x) return(cout << x << endl, 0LL)
# define debug(x) cerr<< #x << " = " << x << endl
# define ddebug(x, y) cerr<< #x << " = " << x  << ", " << #y << " = " << y << endl
# define tdebug(x, y, z) cerr<< #x << " = " << x  << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)
# define MP make_pair
# define uop(x, y) pii(min(x, y), max(x, y))

multiset <int> ms;

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	int n;
	cin >> n;

	int x = 0;
	for (int i = 0; i < n; i ++)
	{
		int a;
		cin >> a;
		smax(x, a);
		ms.insert(a);
	}

	for (int i = 0; i < 2; i ++)
		if (ms.find(x) == ms.end())
			kill("Impossible");
		else
			ms.erase(ms.find(x));

	
	for (int i = 1; i <= x - 1; i ++)
	{
		int a = max(i, x - i);
		if (ms.find(a) == ms.end())
			kill("Impossible");
		else
			ms.erase(ms.find(a));
	}


	for (int a : ms)
		if (a < (x + 1) / 2 + 1)
			kill("Impossible");

	cout << "Possible" << endl;

	return 0;
}
 



Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define INF 1<<20
int main() {
	int N, W;
	cin >> N >> W;
	
	int v[N+1], w[N+1];
	for (int i=1; i<=N; i++) {
		cin >> v[i] >> w[i];
	}
	
	int d[N+1][W+1]={};
	for (int i=1; i<=N; i++) {
		for (int j=w[i]; j<=W; j++) {
			d[i-1][j]=max(d[i-1][j], d[i-1][j-w[i]]+v[i]);
		}
		for (int j=0; j<=W; j++) {
			if (j>=w[i]) {
				d[i][j]=max(d[i-1][j], d[i-1][j-w[i]]+v[i]);
			} else {
				d[i][j]=d[i-1][j];
			}
		}
	}
	cout << d[N][W] << endl;
}


Measured memory_bytes: 7032
def main():
  n=int(input())
  v=list(map(int,input().split()))
  w=sorted(v)

  a=(w[0]+w[1])/2
  for i in range(2,n):
    a=max(a,a/2+w[i]/2)
  print(a)
  
if __name__=="__main__":
  main()

Measured memory_bytes: 3060
// In the name of Allah the most Merciful.

#include<bits/stdc++.h>
using namespace std;

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

    if(a==b)cout << "Draw" << endl;
    else if(a==1||b==1){

        if(a==1)cout << "Alice" << endl;
        else cout << "Bob" << endl;
    }

    else{

        if(a>b)cout << "Alice" << endl;
        else cout << "Bob" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException e){
			e.printStackTrace();
		}
	}

	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		List<Integer> Ans = new ArrayList<Integer>();
		String line;

		while((line = in.readLine()) != null){
			int nTube = Integer.parseInt(line);

			if(nTube==0) break;

			Tube[] tubes = new Tube[nTube];
			for(int n=0; n<nTube; n++){
				line = in.readLine();
				String[] dst = line.split(" ");
				int x = Integer.parseInt(dst[0]);
				int y = Integer.parseInt(dst[1]);
				int r = Integer.parseInt(dst[2]);
				tubes[n] = new Tube(x, y, r);
			}

			line = in.readLine();
			int nSet = Integer.parseInt(line);
			for(int n=0; n<nSet; n++){
				line = in.readLine();
				String[] dst = line.split(" ");
				double x1 = Double.parseDouble(dst[0]);
				double y1 = Double.parseDouble(dst[1]);
				double x2 = Double.parseDouble(dst[2]);
				double y2 = Double.parseDouble(dst[3]);

				int hide = 0;
				for(int m=0; m<tubes.length; m++){
					double a, b, c, d, e1, e2, x0, min, max;
					if(x1 != x2){
						double p = (y1 - y2) / (x1 - x2);
						double q = y1 - p * x1;
						a = p * p + 1.0;
						b = 2.0 * p * (q - tubes[m].y) - 2.0 * tubes[m].x;
						c = Math.pow(tubes[m].x, 2.0) + Math.pow(q - tubes[m].y, 2.0) - Math.pow(tubes[m].r, 2.0);
						d = b * b - 4.0 * a * c;
						e1 = a * x1 * x1 + b * x1 + c;
						e2 = a * x2 * x2 + b * x2 + c;
						x0 = - b / (2.0 * a);
						min = Math.min(x1, x2);
						max = Math.max(x1, x2);
					}
					else{
						a = 1.0;
						b = -2.0 * tubes[m].y;
						c = Math.pow(tubes[m].y, 2.0) + Math.pow(x1 - tubes[m].x, 2.0) - Math.pow(tubes[m].r, 2.0);
						d = b * b - 4.0 * a * c;
						e1 = a * y1 * y1 + b * y1 + c;
						e2 = a * y2 * y2 + b * y2 + c;
						x0 = - b / (2.0 * a);
						min = Math.min(y1, y2);
						max = Math.max(y1, y2);
					}

					if(x0 >= min && x0 <= max){
						if(d*e1 >= 0 || d*e2 >= 0){
							Ans.add(1);
							hide = 1;
							break;
						}
					}
					else{
						if(e1 * e2 <= 0){
							Ans.add(1);
							hide = 1;
							break;
						}
					}
				}

				if(hide == 0){
					Ans.add(-1);
				}
			}
		}

		for(int n=0; n<Ans.size(); n++){
			int i = Ans.get(n);
			if(i==1){
				System.out.println("Safe");
			}else{
				System.out.println("Danger");
			}
		}
	}
}

class Tube{
	double x;
	double y;
	double r;

	public Tube(int x, int y, int r){
		this.x = (double)x;
		this.y = (double)y;
		this.r = (double)r;
	}
}

Measured memory_bytes: 12000
#include <stdio.h>

int pay;
int coin[4];

int main(void){
	scanf("%d", &pay);
	scanf("%d %d %d %d", &coin[0],&coin[1],&coin[2],&coin[3]);
	while(1){
		
		int all = 10*coin[0] + 50*coin[1] + 100*coin[2] + 500*coin[3];
		int charge = all - pay;

		int ret[4];
		ret[3] = (int)(charge / 500);
		charge -= 500*ret[3];
		ret[2] = (int)(charge / 100);
		charge -= 100*ret[2];
		ret[1] = (int)(charge / 50);
		charge -= 50*ret[1];
		ret[0] = (int)(charge / 10);

		for(int i=0; i<4; i++){
			coin[i] = coin[i] - ret[i];
		}

		if(coin[0] > 0) printf("10 %d\n", coin[0]);
		if(coin[1] > 0) printf("50 %d\n", coin[1]);
		if(coin[2] > 0) printf("100 %d\n", coin[2]);
		if(coin[3] > 0) printf("500 %d\n", coin[3]);

		scanf("%d", &pay);
		if(pay == 0) break;
		scanf("%d %d %d %d", &coin[0],&coin[1],&coin[2],&coin[3]);
		puts("");
	}

	return 0;
}

Measured memory_bytes: 1040
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    vector<ll>h(n);
    REP(i,n)cin>>h[i];
    vector<ll>dp(n);
    dp[0]=0;
    dp[1]=llabs(h[0]-h[1]);
    REP(i,n-2){
        dp[i+2] = min(dp[i+1]+llabs(h[i+2]-h[i+1]),dp[i]+llabs(h[i+2]-h[i]));
    }
    cout<< dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
import itertools

def main():
    n = int(input())
    c = 0
    for m in gen():
        if m > n:
            break

        if is_753(m):
            c += 1

    print(c)

def is_753(n):
    s = str(n)
    if '3' in s and '5' in s and '7' in s:
        return True
    else:
        return False

def gen():
    for i in itertools.count(1):
        for x in gen_1(i):
            yield x

def gen_1(num_digits):
    if num_digits == 1:
        yield 3
        yield 5
        yield 7
    else:
        for sub in gen_1(num_digits - 1):
            yield sub * 10 + 3
            yield sub * 10 + 5
            yield sub * 10 + 7

main()


Measured memory_bytes: 3064
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))

    A.sort()
    ans = 1
    S = sum(A)
    for i in reversed(range(N-1)):
        S -= A[i+1]
        if A[i+1] <= 2*S:
            ans += 1
        else:
            break
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14276
let readIntArray () =
    stdin.ReadLine().Split(" ") |> Array.map int

readIntArray ()
|> fun [| n; _ |] ->
    readIntArray ()
    |> Array.reduce (+)
    |> (-) n
    |> fun x -> if x < 0 then -1 else x
    |> printfn "%d"


Measured memory_bytes: 31012
def main():
    s = list(input())
    s_len = len(s)
    if s[0] != "A":
        print("WA")
        return
    elif s[1] == "C":
        print("WA")
        return
    elif s[s_len-1] == "C":
        print("WA")
        return
    c_counter = 0

    for i in range(2, s_len - 1):
        if(s[i] == "C"):
            if(c_counter == 1):
                print("WA")
                return
            c_counter += 1
    for i in range(s_len):
        if(s[i].isupper()):
            if(s[i] != "A" and s[i] != "C"):
                print("WA")
                return
    if(c_counter == 0):
        print("WA")
        return

    print("AC")
main()


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

int main() {
    const int big = 1'000'000'007;

    int N;
    cin >> N;
    vector<int> as(N);
    for (int i=0; i<N; ++i) cin >> as[i];

    int ans {0};
    int x {0};
    for (int i=0; i<N; ++i) {
        ans = (ans + (ll)as[i] * x) % big;
        x = (x + as[i]) % big;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3944
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (long long i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long A, B, C, D; cin >> A >> B >> C >> D;

    long long bc = B/C, bd = B/D;
    long long g = __gcd(C, D);
    long long bu = B / ((C*D)/g);
    long long ac = (A-1)/C, ad = (A-1)/D;
    long long au = (A-1) / ((C*D)/g);

    long long l = B - bc - bd + bu;
    long long r = (A-1) - ac - ad + au;

    cout << l - r << endl;
}

Measured memory_bytes: 256
class UnionFind
  def initialize(n)
    @n = n
    @parent = Array.new(n){|i|i}
    @rank = Array.new(n, 0)
  end

  def find(x)
    if @parent[x] == x
      return x
    else
      return @parent[x] = find(@parent[x])
    end 
  end

  def unite(x, y)
    x = find(x)
    y = find(y)
    return if x == y
    if @rank[x] < @rank[y]
      @parent[x] = y
    else
      @parent[y] = x
      @rank[x] += 1 if @rank[x] == @rank[y]
    end
  end

  def same?(x, y)
    find(x) == find(y)
  end
end

n,m=gets.split.map(&:to_i)
perm=gets.split.map{|n|n.to_i-1}

uf=UnionFind.new(n)
m.times{
  x,y=gets.split.map(&:to_i)
  x-=1;y-=1
  uf.unite(x,y)
}

ans=0
n.times{|i|ans+=1 if uf.same?(i,perm[i])}
puts ans


Measured memory_bytes: 12292
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i,n) for(int i=(int)(n);i>=0;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------
 
signed main() {
		string s;
		cin >> s;
    int from0=0, from1=0;
    for (auto i=0; i<s.size(); i++) {
      if ((s[i]-'0') == i % 2) {
        from0++;
      } else {
        from1++;
      }
    }
    cout << min(from0, from1) << endl;
    return 0;
}


Measured memory_bytes: 512
n=int(input())
A=tuple(map(int,input().split()))
B=[0]*n
for i in reversed(range(n//2,n)):
    B[i]=A[i]
for i in reversed(range(n//2)):
    k=i+1
    l=n//k
    tmp=0
    for j in range(2,l+1):
        idx=k*j-1
        tmp+=B[idx]
    B[i]=(tmp%2-A[i])%2
s=0
Ans=[]
for i,b in enumerate(B):
    if b:
        s+=1
        Ans.append(i+1)
print(s)
print(*Ans)

Measured memory_bytes: 70236
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
typedef modint<MOD> m;
#pragma endregion

int main() {
  string s;
  cin >> s;
  rep(i, s.size()) cout << "x";
}



Measured memory_bytes: 256
ticket = input()

ans = 0
if int(ticket[0]) + int(ticket[1]) + int(ticket[2]) + int(ticket[3]) == 7:
    print(ticket[0] + '+' + ticket[1] + '+' + ticket[2] + '+' + ticket[3] + '=7')
elif int(ticket[0]) + int(ticket[1]) + int(ticket[2]) - int(ticket[3]) == 7:
    print(ticket[0] + '+' + ticket[1] + '+' + ticket[2] + '-' + ticket[3] + '=7')
elif int(ticket[0]) + int(ticket[1]) - int(ticket[2]) + int(ticket[3]) == 7:
    print(ticket[0] + '+' + ticket[1] + '-' + ticket[2] + '+' + ticket[3] + '=7')
elif int(ticket[0]) + int(ticket[1]) - int(ticket[2]) - int(ticket[3]) == 7:
    print(ticket[0] + '+' + ticket[1] + '-' + ticket[2] + '-' + ticket[3] + '=7')
elif int(ticket[0]) - int(ticket[1]) + int(ticket[2]) + int(ticket[3]) == 7:
    print(ticket[0] + '-' + ticket[1] + '+' + ticket[2] + '+' + ticket[3] + '=7')
elif int(ticket[0]) - int(ticket[1]) + int(ticket[2]) - int(ticket[3]) == 7:
    print(ticket[0] + '-' + ticket[1] + '+' + ticket[2] + '-' + ticket[3] + '=7')
elif int(ticket[0]) - int(ticket[1]) - int(ticket[2]) + int(ticket[3]) == 7:
    print(ticket[0] + '-' + ticket[1] + '-' + ticket[2] + '+' + ticket[3] + '=7')
elif int(ticket[0]) - int(ticket[1]) - int(ticket[2]) - int(ticket[3]) == 7:
    print(ticket[0] + '-' + ticket[1] + '-' + ticket[2] + '-' + ticket[3] + '=7')


Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <fstream>
#include <iomanip>
//#include <unordered_map>
using namespace std;
#define dbg(x) cerr << #x " = " << x << endl;
typedef pair<int, int> P;
typedef long long ll;
#define FIN freopen("in.txt", "r", stdin);

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string a, b, c;
    cin >> a >> b >> c;
    cout << a[0] << b[0] << c[0] << endl;
}

Measured memory_bytes: 384
Q, H, S, D = map(int, input().split())
N = int(input())
A = [Q * 8, H * 4, S * 2, D]
B = [Q * 4, H * 2, S]
Ans = 0

cnt = N // 2
N = N % 2
Ans = Ans + min(A) * cnt
Ans = Ans + min(B) * N
print(Ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;   
const int inf = (int) 1e9+7;
map<int,int> m;
int main(){
	fastIO;
	int p1=0;         
	string s;
	cin>>s;
	for(int i=0;i<(int)s.size();i++){
		if(s[i] == 'A'){
			p1=i;
			break;
		}
	}
	for(int i=(int)s.size()-1;i>=0;i--){
		if(s[i] == 'Z'){
			p1=i-p1+1;
			break;
		}
	}
	cout<<p1<<'\n';
	return 0;
}

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

int main()
{
	int n, k;
	std::cin >> n >> k;
	
	int x;
	int a, b;
	int d = 0;
	for (int i = 0; i < n; i++) {
		std::cin >> x;
		a = x * 2;
		b = (k - x) * 2;
		d += std::min(a, b);
	}
	
	std::cout << d << std::endl;
	
	return 0;
}


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

int main()
{
    int a, b, c;
    cin >> a;
    cin >> b;
    c = a + b;
    if (c % 2 == 0)
    {
        c = c / 2;
    }
    else
    {
        c = c / 2 + 1;
    }

    std::cout << c << std::endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		int x = (X - a) % b;
		System.out.println(x);

	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	string s,t;
	cin>>s>>t;
	ll cnt=0;
	for(ll i=0;i<3;i++)
	{
		if(s[i]==t[i])
		++cnt;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

	int x,y,i,t;
	int a[10000];
	i = 0;
	t = 0;
	y = 0;
	

	while(1){

		scanf("%d",&a[y]);
		
		x = a[y];

		y += 1;

		if(x == 0){

			break;

		}
		

	}

	while(i < y){

		if(a[t] == 0){
			break;
		}

		printf("Case %d: %d\n",t+1,a[t]);
		
		t += 1;
		i += 1;


	}

}

Measured memory_bytes: 1068
#include<bits/stdc++.h>
#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
#define ff first
#define ss second
/*----------------------------------------------------------------------*/

const int N = 2e5+5;
int arr[N],vals[N],a=0;
vi ans;

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; cin>>n; memset(vals, 0, sizeof(vals));
    FOR(i, 1, n+1) cin>>arr[i];
    RFOR(i, n, 1) {
    	int cnt = 0;
    	for (int k = 2*i; k <= n; k+=i)
    	{
    		cnt += vals[k];
    	}
    	cnt %= 2;
    	if(cnt != arr[i]) {
    		vals[i] = 1;
			a++;    		
    		ans.push_back(i);
    	}
    }
    cout<<a<<endl;
    FOR(i, 0, ans.size()) {
    	cout<<ans[i]<<" ";
    }

    return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#define int long long
using namespace std;
int keta(int n){
    int res = 0;
    while(n>0){
        res++;
        n /= 10;
    }
    return res;
}
signed main(){
    int n; cin >> n;
    int res = 1 << 22;
    for(int a=1; a<(int) 1 + sqrt(n); ++a){
        if(n%a==0){
            int b = n / a;
            res = min(res, max(keta(b) , keta(a)));
        }
    }    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
mod = 10**9+7

#[[素因数,数]]を出力
def fctr1(n): 
    f=[]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            f.append([i,c])
            c=0
    if n!=1:
        f.append([n,1])
    return f

fact = [1]
fact_inv = [1]
for i in range(10**6):
    new_fact = fact[-1]*(i+1)%mod
    fact.append(new_fact)
    fact_inv.append(pow(new_fact,mod-2,mod))


def mod_comb_k(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

p = fctr1(m)
res = 1

for e,num in p:
    res = res*mod_comb_k(num+n-1,n-1,mod)%mod

print(res)


Measured memory_bytes: 108312
def sigma(x, d):
    if d == 1:
        return x * (x + 1) // 2
    if d == 2:
        return x * (x + 1) * (2 * x + 1) // 6


def calc(x):
    return -sigma(x, 2) + (n + 1) * sigma(x, 1) + x


# N+1個の数からK個の数を選ぶとき、その和としてあり得る数は-K^2+(N+1)K+1個

n, k = map(int, (input().split()))
p = 10 ** 9 + 7

print((calc(n + 1) - calc(k - 1)) % p)

Measured memory_bytes: 9192
#include<iostream>
using namespace std;
double t[4]={0.2,0.6,1.1,9999999.9};
double a,b;
int ans[4][2];
int main(){
  for(int i=0;i<4;i++)for(int j=0;j<2;j++)ans[i][j]=0;
  while(cin>>a>>b){
    for(int i=0;i<4;i++){
      if(a<t[i]){
	ans[3-i][0]++;
	break;
      }
    }
    for(int i=0;i<4;i++){
      if(b<t[i]){
	ans[3-i][1]++;
	break;
      }
    }
  }
  for(int i=0;i<4;i++){
    cout<<ans[i][0]<<' '<<ans[i][1]<<endl;
  }
  return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
ll qpow(ll a,ll x){
    ll res = 1;
    while (x){
        if(x&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        x/=2;
    }
    return res;
}
ll n,a[2005],k;
ll las[2005],all[2005];
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(a[j]<a[i]){
                all[i]++;
                if(j>i){
                    las[i]++;
                }
            }
        }
    }
    ll ans = 0;
    for(int i=1;i<=n;i++){
        ans+=((k-1)*all[i]%mod+las[i]+las[i])*k%mod*qpow(2,mod-2)%mod;
        ans%=mod;
    }
    cout<<ans<<endl;
}


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

int main() {
    string s;
    int cnt = 0;
    cin >> s;
    for (unsigned int i = 0; i < s.size() / 2; i++) {
        if(s.at(i) != s.at(s.size() - 1 - i)){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ll n,cnt=0;
    cin>>n;
    vector<ll>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
for(int i=1;i<n-1;i++)
    if(v[i-1]>v[i] ^ v[i+1]>v[i])
{
    cnt++;
}
cout<<cnt<<endl;
return 0;
}



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

int main(){
  long long N,X,M; cin >> N >> X >> M;
  vector<long long> A(M);
  vector<int> R(M,-1);
  int start=-1,last=-1;
  for(int i=0; i<M; i++){
    if(i==0){
      A[i]=X;
      R[X]=i;
    }else{
      A[i]=(A[i-1]*A[i-1])%M;
      if(R[A[i]]<0){
        R[A[i]]=i;
      }else{
        start=R[A[i]];
        last=i;
        break;
      }
    }
  }
  if(start<0){
    start=R[(A[M-1]*A[M-1])%M];
    last=M;
  }
  long long sum=0;
  for(int i=0; i<start; i++){
    sum+=A[i];
  }
  long long loopsum=0;
  for(int i=start; i<last; i++){
    loopsum+=A[i];
  }
  sum+=((N-start)/(last-start))*loopsum;
  int residue=(N-start)%(last-start);
  for(int i=start; i<start+residue; i++){
    sum+=A[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 4572
import scala.io.StdIn.{readLine,readInt}
import scala.math.BigDecimal

object Main {
    def round(x:Double) = BigDecimal(x).setScale(3,BigDecimal.RoundingMode.HALF_UP).toDouble 

    def main(args:Array[String]) = {
        val n = readInt
         for(i <- 0 until n) {
            val m = readLine.split(" ").map(_.toDouble)
            val (x12,y12,x13,y13) = (m(0)-m(2),m(1)-m(3),m(0)-m(4),m(1)-m(5))
            val (xx1,yy1,xx2,yy2,xx3,yy3) = (m(0)*m(0),m(1)*m(1),m(2)*m(2),m(3)*m(3),m(4)*m(4),m(5)*m(5))
            val g = 2*(x12*y13 - y12*x13)
            val x = (y13*(xx1 - xx2 + yy1 - yy2) - y12*(xx1 - xx3 + yy1 - yy3))/g
            val y = (x12*(xx1 - xx3 + yy1 - yy3) - x13*(xx1 - xx2 + yy1 - yy2))/g

            printf("%.3f %.3f %.3f\n",round(x),round(y),round(Math.sqrt((x-m(0))*(x-m(0))+(y-m(1))*(y-m(1)))))
        }
    }
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

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

int main(){
  int h, w, k; cin >> h >> w >> k;
  char a[310][310] = {};
  int v[310][310] = {};
  {
    int cnt = 0;
    for(int i = 0; i < h; ++i){
      for(int j = 0; j < w; ++j){
	cin >> a[i][j];
	if(a[i][j] == '#'){
	  cnt++;
	  v[i][j] = cnt;
	}
      }
    }
  }
  for(int i = 0; i < h; ++i){
    for(int j = 1; j < w; ++j){
      if(v[i][j] == 0 && v[i][j-1] != 0) v[i][j] = v[i][j-1];
    }
  }
  for(int i = 0; i < h; ++i){
    for(int j = w-2; j >= 0; --j){
      if(v[i][j] == 0 && v[i][j+1] != 0) v[i][j] = v[i][j+1];
    }
  }
  for(int i = 1; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(v[i][j] == 0 && v[i-1][j] != 0) v[i][j] = v[i-1][j];
    }
  }
  for(int i = h-2; i >= 0; --i){
    for(int j = 0; j < w; ++j){
      if(v[i][j] == 0 && v[i+1][j] != 0) v[i][j] = v[i+1][j];
    }
  }
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(j!=0)cout << ' ';
      cout << v[i][j];
    }
    cout << endl;
  }
  return 0;  
}


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

ll solve(ll a[],ll n)
{
  ll dp[n+1][n+1];
  for(ll s = 0; s<n; s++)
  {
    for(ll i = 1,j = i+s; i<=n && j<=n; i++,j++)
    {
        if(i==j)
            dp[i][j] = a[i];
        else if(j==i+1)
            dp[i][j] = max(a[i],a[i+1]);
        else
        {
            ll t1=0,t2=0,t3=0;
            if(i+2<=j)
            {
                t1=dp[i+2][j];
                t2=dp[i+1][j-1];
                t3=dp[i][j-2];
            }
            dp[i][j] = max((a[i]+min(t1,t2)),(a[j]+min(t2,t3)));
        }
    }
  }
  return dp[1][n];
}

int main()
{
    ll n;
    ll sum = 0;
    cin>>n;
    ll a[n+1];
    for(ll i = 1 ;i<=n; i++)
    {
        cin>>a[i]; 
        sum+=a[i];
    }
    ll x = solve(a,n);
    ll y = sum-x;
    cout<<x-y;
    return 0;
}

Measured memory_bytes: 49776
#![allow(non_snake_case, unused_imports)]
 
// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }
 
// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};
 
// Functions
 
// Main
fn main(){
    input!{
        N: usize,
        K: usize,
        D: [String; K],
    }
    for i in N..100000{
        if i.to_string().chars().all(|x| !D.contains(&x.to_string())){
            println!("{}", i);
            return;
        }
    }
}


Measured memory_bytes: 4352
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
const long double eps = 1e-12;
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); ++i) {
		if (i % 2 == 0) {
			if (s[i] == 'L') {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if (s[i] == 'R') {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 760