akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = list(map(int,input().split()))
b = [a_ for a_ in a]

ans = 10**14
for a0 in [-1,a[0],1]:
    if a0 == 0:
        continue
    ans_ = abs(a[0]-a0)
    b[0] = a0
    sign = b[0] > 0
    for i in range(1,n):
        b[i] = a[i]+b[i-1]
        if sign:
            if b[i] >= 0:
                ans_ += b[i]+1
                b[i] = -1
        else:
            if b[i] <= 0:
                ans_ += 1-b[i]
                b[i] = 1
        sign = not sign
    ans = min(ans, ans_)
print(ans)


Measured memory_bytes: 14644
use std::collections::HashSet;

use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        h: [usize; n],
        ab: [[usize; 2]; m],
    }

    let mut good_observatories: HashSet<usize> = (1..(n + 1)).collect();

    for _ab in ab {
        if h[_ab[0] - 1] > h[_ab[1] - 1] {
            good_observatories.remove(&_ab[1]);
        } else if h[_ab[0] - 1] < h[_ab[1] - 1] {
            good_observatories.remove(&_ab[0]);
        } else {
            good_observatories.remove(&_ab[0]);
            good_observatories.remove(&_ab[1]);
        }
    }

    println!("{}", good_observatories.len());
}


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

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
	int N,K;
	cin>>N>>K;
	int H;
	int R=0;
	for(int i=0;i<N;i++){
		cin>>H;
		if(H>=K)R++;
	}
	cout<<R<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;
 
template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
 
const double PI = acos(-1.0);
const int INF = 1e9 + 47;
const LL LINF = 1LL * INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 998244353;
int mult(int a, int b)
{
	return a * (LL) b % MOD;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	VI d(n);
	VI cnt(n);
	FOR(i, 0, n)
	{
		cin >> d[i];
		cnt[d[i]]++;
	}
	int m = n;
	int ans = (d[0] == 0) * (cnt[0] == 1);
	m -= cnt[0];
	int ind = 1;
	while(m)
	{
		FOR(i, 0, cnt[ind])
			ans = mult(ans, cnt[ind - 1]);
		m -= cnt[ind];
		ind++;
	}
	cout << ans << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}
 


Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,p,x=0;cin>>N;
  for(int i=1;i<=N;i++){
    cin>>p;if(p!=i)x++;
  }
  if(x<3)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> B(N);
    for (int i=0; i<N-1; i++) cin >> B.at(i);
    B.at(N-1) = 1000000;
    int ans = B.at(0);
    for (int i=1; i<N; i++) {
        ans += min(B.at(i-1), B.at(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

// 愚直にやるとO(QN)の計算量になりTLE

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

    int N, Q;
    string S;
    cin >> N >> Q >> S;

    vector<int> ac_accum_list(N);
    {
        bool found_a = false;
        int ac_accum = 0;
        for (int i = 0; i < N; ++i) {
            if (S[i] == 'A') found_a = true;
            else {
                if (S[i] == 'C' && found_a) ++ac_accum;
                found_a = false;
            }
            ac_accum_list[i] = ac_accum; // ACのCのところで+1
        }
    }

    for (int i = 0; i < Q; ++i) {
        int l, r;
        cin >> l >> r;
        --l;
        --r;

        cout << ac_accum_list[r] - ac_accum_list[l] << "\n";
    }

    // TLE
    // for (int i = 0; i < Q; ++i) {
    //     int l, r;
    //     cin >> l >> r;
    //     --l;
    //     --r;

    //     bool found_a = false;
    //     int ans = 0;
    //     for (int j = l; j <= r; ++j) {
    //         if (S[j] == 'A') found_a = true;
    //         else {
    //             if (S[j] == 'C' && found_a) ++ans;
    //             found_a = false;
    //         }
    //     }

    //     cout << ans << "\n";
    // }

    cout << flush;
    return 0;
}


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

typedef long long ll;
ll MOD = 1000000007;

vector<vector<ll> > matmul(vector<vector<ll> >& A, vector<vector<ll> >& B) {
	int n = A.size();
	vector<vector<ll> > C(n, vector<ll>(n));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			for (int k = 0; k < n; k++)
				C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
	return C;
}

vector<vector<ll> > matpow(vector<vector<ll> > A, ll x) {
	int n = A.size();
	vector<vector<ll> > B(n, vector<ll>(n));
	for (int i = 0; i < n; i++) B[i][i] = 1;
	while (x > 0) {
		if (x % 2) B = matmul(B, A);
		x /= 2;
		A = matmul(A, A);
	}
	return B;
}

int main() {
	int N, K, C, T;
	cin >> N >> K >> C >> T;
	C--;
	vector<vector<ll> > A(N * 5, vector<ll>(N * 5));
	for (int i = 0; i < N * 4; i++)
		A[i + N][i] = 1;
	for (int k = 0; k < K; k++) {
		int a, b, t; cin >> a >> b >> t;
		a--;
		for (int x = 0; x < N; x++) {
			int y;
			if (x < b) y = x + a;
			else if (x < a + b) y = x - b;
			else y = x;
			A[y][(t - 1) * N + x]++;
		}
	}
	A = matpow(A, T);
	cout << A[C][0] << endl;
}

Measured memory_bytes: 4192
#include <bits/stdc++.h>
using namespace std;
#define sq(x) ((x)*(x))
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	vector<pair<int, int>> arr(n);
	vector<int> p(n);
	for(int i=0; i<n; i++) {
		p[i] = i;
		cin >> arr[i].first >> arr[i].second;
	}
	double sum = 0;
	int cnt = 0;
	do {
		double t = 0;
		for(int i=1; i<n; i++) {
			t += sqrt(sq(arr[p[i]].first-arr[p[i-1]].first) + sq(arr[p[i]].second-arr[p[i-1]].second));
		}
		sum += t;
		cnt++;
	} while(next_permutation(p.begin(), p.end()));
	printf("%.10f", sum/cnt);
}

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

typedef long long              ll;
typedef long double            ld;
typedef pair<int, int>         pi;
typedef vector<int>            vi;
typedef vector<pair<int, int>> vpi;

#define pb       push_back
#define all(x)   begin(x), end(x)
#define sz(x)    (int)(x).size()
#define ff       first
#define ss       second
#define mp       make_pair
#define lb       lower_bound
#define ub       upper_bound
#define tcase()  int t; cin >> t; while(t--)

const int MOD = 1e9 + 7; // 998244353;
const int MX  = 2e5 + 5;
const ll  INF = 1e18;
const ld  PI  = acos((ld) -1);

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main(){

    setIO();

    double a, b;
    cin >> a >> b;

    double i;

    for(i = 1; i <= 125001; i++){
        if(floor(i * 0.08) == a && floor(i / 10) == b) break;
    }

    if(i > 125000) cout << -1;
    else cout << i;
}


Measured memory_bytes: 3688
#include <iostream>

using namespace std;

int main(void)
{
    string S;
    bool ok = false;
    cin >> S;
    
    if (S[0] == S[1]) {
        if (S[0] == S[2]) {
        } else if (S[2] == S[3]) {
            ok = true;
        }
    } else if (S[0] == S[2]) {
        if (S[0] == S[1]) {
        } else if (S[1] == S[3]) {
            ok = true;
        }
    } else if (S[0] == S[3]) {
        if (S[0] == S[1]) {
        } else if (S[1] == S[2] ) {
            ok = true;
        }
    }
    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int k = s.size();
    vector<vector<int>> node(k, vector<int>(2, 0));
    for (int i = 0; i < k; i++) node[i][0]++;
    for (int i = 0; i < k; i++){
        if (s[i] == 'R'){
            if (i == k - 1) continue;
            node[i+1][1] += node[i][0];
            node[i+1][0] += node[i][1];
            node[i][0] = 0;
            node[i][1] = 0;
        }
    }
    for (int i = k - 1; i >= 0; i--){
        if (s[i] == 'L'){
            if (i == 0) continue;
            node[i-1][1] += node[i][0];
            node[i-1][0] += node[i][1];
            node[i][0] = 0;
            node[i][1] = 0;
        }
    }
    for (int i = 0; i < k; i++){
        if (i == 0) {
            if (s[1] == 'R') cout << node[0][0];
            else cout << node[0][0] + node[1][1];
        }
        else if (i == k - 1){
            if (s[k - 2] == 'L') cout << node[k - 1][0];
            else cout << node[k - 1][0] + node[k - 2][1];
        }
        else {
            if (s[i] == 'R'){
                if (s[i+1] == 'R') cout << node[i][0];
                else cout << node[i][0] + node[i+1][1];
            }
            else {
                if (s[i-1] == 'L') cout << node[i][0];
                else cout << node[i][0] + node[i-1][1];
            }
        }
        if (i == k - 1) cout << endl;
        else cout << " ";
    }
}

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

int main()
{
    int P, Q, R;

    cin >> P >> Q >> R;

    if (P + Q >= Q + R)
    {
        if (Q + R >= R + P)
            cout << R + P << endl;
        else
            cout << Q + R << endl;
    }
    else if (Q + R >= R + P)
    {
        if (R + P >= P + Q)
            cout << P + Q << endl;
        else
            cout << R + P << endl;
    }
    else if (R + P >= P + Q)
    {
        if (P + Q >= Q + R)
            cout << Q + R << endl;
        else
            cout << P + Q << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

bool ok(int x, vector<bool> f) {
  while(x) {
    if(f[x % 10])
      return false;
    x /= 10;
  }
  return true;
}

signed main() {
  int N, K, tmp;
  cin >> N >> K;
  vector<bool> f(10);

  REP(i, K) {
    cin >> tmp;
    f[tmp] = true;
  }

  while(!ok(N, f))
    N++;

  cout << N << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import deque


class Dinic(object):
    __slots__ = ["inf", "v_count", "edges", "iter", "level"]

    def __init__(self, v_count: int, edges: list):
        self.inf = 10**9
        self.v_count = v_count
        self.edges = [[] for _ in [0]*v_count]
        self.iter = [0]*v_count
        self.level = None
        self._create_graph(edges)

    def _create_graph(self, _edges):
        edges = self.edges
        for origin, dest, cap in _edges:
            edges[origin].append([dest, cap, len(edges[dest])])
            edges[dest].append([origin, 0, len(edges[origin])-1])

    def solve(self, source: int, sink: int):
        max_flow = 0

        while True:
            self.bfs(source)
            if self.level[sink] < 0:
                return max_flow

            self.iter = [0]*self.v_count
            flow = self.dfs(source, sink, self.inf)

            while flow > 0:
                max_flow += flow
                flow = self.dfs(source, sink, self.inf)

    def bfs(self, source: int):
        level, edges = [-1]*self.v_count, self.edges
        level[source] = 0
        dq = deque([source])
        popleft, append = dq.popleft, dq.append

        while dq:
            v = popleft()
            for dest, cap, _rev in edges[v]:
                if cap > 0 > level[dest]:
                    level[dest] = level[v] + 1
                    append(dest)

        self.level = level

    def dfs(self, source: int, sink: int, flow: int) -> int:
        if source == sink:
            return flow
        while self.iter[source] < len(self.edges[source]):
            dest, cap, rev = edge = self.edges[source][self.iter[source]]
            if cap > 0 and self.level[source] < self.level[dest]:
                flowed = self.dfs(dest, sink, flow if flow < cap else cap)
                if flowed > 0:
                    edge[1] -= flowed
                    self.edges[dest][rev][1] += flowed
                    return flowed
            self.iter[source] += 1

        return 0


if __name__ == "__main__":
    import sys
    X, Y, E = map(int, input().split())
    source, sink = X+Y, X+Y+1
    edges = [(source, i, 1) for i in range(X)] + [(X+i, sink, 1) for i in range(Y)]
    append = edges.append
    for x, y in (map(int, l.split()) for l in sys.stdin):
        append((x, X+y, 1))
    dinic = Dinic(X+Y+2, edges)
    print(dinic.solve(source, sink))


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

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

using namespace std;


int n;

ll solve0(vector<ll> a){
    ll cnt = 0;
    if(a[0] <= 0){
        cnt += abs(a[0])+1;
        a[0] += abs(a[0])+1;
    }

    vector<ll> sum(n, 0);
    sum[0] = a[0];
    rep(i, n-1) sum[i+1] = a[i+1] + sum[i];
    
    bool plus = (0 < sum[0])? true:false;
    ll d = 0;
    for(ll i= 1; i < n; i++){
        sum[i] += d;
        if(plus){
            if(0 <= sum[i]){
                ll diff = sum[i]+1;
                a[i] -= diff;
                d -= diff;
                //for(ll j = i; j < n; j++)   sum[j] -= diff;
                cnt += diff;
            }
        }
        else{
            if(sum[i] <= 0){
                ll diff = -sum[i]+1;
                a[i] += diff;
                d += diff;
                //for(ll j = i; j < n; j++)   sum[j] += diff;
                cnt += diff;
            }
        }
        plus = !plus;
    }

    return cnt;
}

ll solve1(vector<ll> a){
    ll cnt = 0;
    if(0 <= a[0]){
        cnt += abs(a[0])+1;
        a[0] -= abs(a[0])+1;
    }

    vector<ll> sum(n, 0);
    sum[0] = a[0];
    rep(i, n-1) sum[i+1] = a[i+1] + sum[i];
    
    bool plus = (0 < sum[0])? true:false;
    ll d = 0;
    for(ll i= 1; i < n; i++){
        sum[i] += d;
        if(plus){
            if(0 <= sum[i]){
                ll diff = sum[i]+1;
                a[i] -= diff;
                d -= diff;
                //for(ll j = i; j < n; j++)   sum[j] -= diff;
                cnt += diff;
            }
        }
        else{
            if(sum[i] <= 0){
                ll diff = -sum[i]+1;
                a[i] += diff;
                d += diff;
                //for(ll j = i; j < n; j++)   sum[j] += diff;
                cnt += diff;
            }
        }
        plus = !plus;
    }

    return cnt;
}

int main(){
    cin >> n;
    vector<ll> a(n);
    rep(i, n)   cin >> a[i];


    cout << min(solve0(a), solve1(a)) << endl;

    return 0;
}


Measured memory_bytes: 3440
#include<iostream>
#include<string>

using namespace std;

int main(){

    int a, b;
    string op;

    while(1){

        cin >> a >> op >> b;
    
        if(op == "+"){
            cout << a + b << endl;
        }else if(op == "-"){
            cout << a - b << endl;
        }else if(op == "*"){
            cout << a * b << endl;
        }else if(op == "/"){
            cout << a / b << endl;
        }else{
            break;
        }
        
    }

    return 0;

}


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

int main() {
  int n;
  cin >> n;
  long long a[n];
  for (int i=0; i<n; i++)
    cin >> a[i];

  long long ans = 0ll;
  for (int i=1; i<n; i++) {
    if (a[i-1] > a[i]) {
      ans += a[i-1] - a[i];
      a[i] = a[i-1];
    }
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5200
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int>v[100005];
int c[2][100005];
int cnt1,cnt2;
void bfs(int sk,int color){
	for(int i=1;i<=n;i++) c[color][i]=-1;
	queue<int>q;
	q.push(sk);
	c[color][sk]=0;
	while(!q.empty()){
		int k=q.front();
		q.pop();
		for(int i=0;i<v[k].size();i++){
			int x=v[k][i];
			if(c[color][x]!=-1) continue;
			c[color][x]=c[color][k]+1;
			q.push(x);
		}
	}
}
int main(){
	cin>>n;
	for(int i=1;i<=n-1;i++){
		int u,w;
		cin>>u>>w;
		v[u].push_back(w);
		v[w].push_back(u);
	}
	bfs(1,0);
	bfs(n,1);
	for(int i=1;i<=n;i++)
		if(c[0][i]<=c[1][i]) cnt1++;
		else cnt2++;
	if(cnt2>=cnt1) cout<<"Snuke"<<endl;
	else cout<<"Fennec"<<endl;
	return 0;
}

Measured memory_bytes: 6656
import scala.io.StdIn.{readLine,readInt}

object Main extends App {
  val seq1 = for(i<-1 to 9) yield List(i,i,i)
  val seq2 = for(i<-1 to 7) yield List(i,i+1,i+2)

  def check(m:List[Int], count:Int,u:Int,v:Int):Boolean =
    if(m.length != count) false
    else if(count==2) m(0)==m(1)
    else (u to 8).exists( i=> check(m diff seq1(i),count-3,i+1,v)) || (v to 6).exists(i=> check(m diff seq2(i),count-3,u,i))

  Iterator.continually(readLine).takeWhile ( _!=null ).foreach { line =>
    val l = line.map(_.asDigit).toList
    val m = (1 to 9).filter { i=> if(l.count( _==i ) >= 4) false else check(i::l,14,0,0) }
    if(m.length>0) println(m.mkString(" ")) else println(0)
  }
}

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

int main() {
	int n,a,b; cin >> n >> a >> b;
	string s; cin >> s;

	int A=0,B=0;	
	for(int i=0;i<s.size();++i){
		switch(s[i]){
			case 'a':
			if(A+B<a+b){
				++A;
				cout << "Yes" << endl;
			}else{
				cout << "No" << endl;
			}
			break;
			case 'b':
			if(A+B<a+b && B<b){
				++B;
				cout << "Yes" << endl;
			}else{
				cout << "No" << endl;
			}
			break;
			case 'c':
			cout << "No" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 896
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

N = int(input())
G = [list(map(lambda x: int(x)-1, input().split()))[2:] for _ in range(N)]
D = [-1]*N
D2 = [-1]*N
def dfs(cur, now):
    if D[cur] != -1: return now
    now += 1
    D[cur] = now
    for nex in G[cur]:
        now = dfs(nex,now)
    now += 1
    D2[cur] = now
    return now
now = 0
for i in range(N):
    now = dfs(i,now)
for i in range(N):
    print(i+1,D[i],D2[i])



Measured memory_bytes: 5668
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=1; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n; cin >> n;
    ll cnt = 0;
    map<ll, ll> mp;
    rep(i,101){
        rep(j,101){
            rep(k,101){
                ll tmp = i*i + j*j + k*k + i*j + j*k + k*i;
                mp[tmp]++;
            }
        }
    }

    for(int i=1; i<=n; i++){
        cout << mp[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 5976
#include <iostream>
using namespace std;
int main()
{
	int a,b,c,i,count=0;
	cin>>a>>b>>c;
	for (i = a; i <=b ; i++)
	{
		if(c%i==0)
			count++;
	}
	cout<<count<<endl;
	return 0;
}


Measured memory_bytes: 3104
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#define mp make_pair
#define pb push_back
using namespace std;

namespace Header_Template {
  typedef long long li;
  template<class T>inline void read(T &x) {
    x = 0;
    T tmp = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') tmp = -1, c = getchar();
    while (c >= '0' && c <= '9')
      x = (x << 1) + (x << 3) + c - '0', c = getchar();
    x *= tmp;
  
  }
  template<class T>inline void Max(T &x, T y) {
    if (y > x) x = y;
  
  }
  template<class T>inline void Min(T &x, T y) {
    if (y < x) x = y;
  
  }

}
using namespace Header_Template;

const int N = 2e5 + 10;
int n, k, cnt[N];

int main(void) {
  read(n), read(k);
  for (int i = 1; i <= n; ++i)
    ++cnt[i % k];
  li ans = 1LL * cnt[0] * (cnt[0] - 1) * (cnt[0] - 2);
  ans += 1LL * cnt[0] * (cnt[0] - 1) * 3 + cnt[0];
  if (k % 2 == 0) {
    int x = k >> 1;
    ans += 1LL * cnt[x] * (cnt[x] - 1) * (cnt[x] - 2);
    ans += 1LL * cnt[x] * (cnt[x] - 1) * 3 + cnt[x];
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 512
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;


int main() {
	ll n;
	cin >> n;
	deque<ll> a;
	bool even;
	if(n % 2 == 0)even = true;
	else even = false;
	for(ll i = 0; i < n; i++) {
		ll x;
		cin >> x;
		if (even) {
			if (i % 2 == 0) a.push_back(x);
			else a.push_front(x);
		}
		else {
			if (i % 2 == 0) a.push_front(x);
			else a.push_back(x);
		}
		
	}
	rep(i, n) {
		cout << a[i] << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3840
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<vector>
using namespace std;

int main(void) {
	int x;
	cin >> x;
	if (x < 1200) {
		cout << "ABC";
	}
	else {
		cout << "ARC";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n)                     \
    rep(i, n) { cout << a[i] << ' '; } \
    cout << endl
#define show2(a, n, m)                        \
    rep(i, n)                                 \
    {                                         \
        rep(j, m) { cout << a[i][j] << ' '; } \
        cout << endl;                         \
    }
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

struct mint {
	ll x;
	mint(ll x=0):x((x%MOD+MOD)%MOD){}
	mint operator-() const { return mint(-x);}
	mint& operator+=(const mint a) {if ((x+=a.x)>=MOD) x-=MOD; return *this;}
	mint& operator-=(const mint a) {if ((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
	mint& operator*=(const mint a) {(x*=a.x)%=MOD; return *this;}
	mint operator+(const mint a) const {mint res(*this); return res+=a;}
	mint operator-(const mint a) const {mint res(*this); return res-=a;}
	mint operator*(const mint a) const {mint res(*this); return res*=a;}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if (t&1) a *= *this;
 		return a;
	}

	// For prime mod.
	// Do not use if MOD is not prime number !!
	mint inv() const { return pow(MOD-2);}
	mint& operator/=(const mint a) { return (*this) *= a.inv();}
	mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

typedef vector<mint> vm; 

int main()
{
    //	cout << fixed << setprecision(15);
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i, n) cin >> a[i];

    if(k == 0) {
        cout << 1 << endl;
        return 0;
    }

    vector<vm> dp(n + 1, vm(k + 1));
    rep(i, k + 1) dp[0][i] = 1;
    rep(i, n) {
        rep(j, k + 1) {
            dp[i + 1][j] = dp[i][j];
            if(j - a[i] >= 1) dp[i + 1][j] -= dp[i][j - a[i] - 1];
        }
        rep(j, k) dp[i + 1][j + 1] += dp[i + 1][j];
    }
    mint ans = dp[n][k] - dp[n][k - 1];
    cout << ans.x << endl;
}


Measured memory_bytes: 80256
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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        a:i64,
        s:String,
    }
    println!("{}",if a < 3200 { "red" } else { &s });
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

const int N=200005;
const int P=998244353;

struct num{
	int val,cnt;
	inline num(){}
	inline num(int _x,int _y){
		val=_x;
		cnt=_y;
	}
}c[N];

int n,m;
int a[N],s1[N],s2[N];
long long ans;

inline bool check(int l,int r){
	if((s1[r]-s1[l-1])==(s2[r]^s2[l-1])) return true;
	return false;
}

void init(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) s1[i]=s1[i-1]+a[i];
	for(int i=1;i<=n;i++) s2[i]=s2[i-1]^a[i];
	/*
	for(int i=1;i<=n;i++){
		if(a[i]==0){
			cnt++;
			continue;
		}
		c[++m]=num(a[i],cnt+1);
		cnt=0;
	}
	if(m==0){
		printf("%lld\n",(long long)n*(n+1)/2);
		return ;
	}
	for(int l=1;l<=m;l++){
		int r=l;
		int cur=c[l].val,siz=c[l].cnt;
		while((cur^c[r+1].val)==(cur+c[r+1].val) && r<=m) r++,siz+=c[r].cnt;
		ans+=siz;
	}
	printf("%lld\n",ans);
	*/
	for(int i=1;i<=n;i++){
		int l=i,r=n;
		while(r>l){
			int mid=(l+r+1)>>1;
			if(check(i,mid)==true) l=mid;
			else r=mid-1;
		}
		ans+=(r-i+1);
	}
	printf("%lld\n",ans);
}

int main(){
	init();
	return 0;
}

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

int main() {
  int n;
  cin>>n;
  map<int,int> A;
  bool ans=true;
  rep(i,n){
    int a;
    cin>>a;
    A[a]++;
    if(A[a]>1){
      ans=false;
      break;
    }
  }
  if(ans) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 9600
#include<stdio.h>
#include<string.h>

int main(){
  char a[128];
  
  scanf("%s",a);
  if(strcmp(a,"Sunny")==0)printf("Cloudy");
  else if(strcmp(a,"Cloudy")==0)printf("Rainy");
  else if(strcmp(a,"Rainy")==0)printf("Sunny");
    

  return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=pair<ll,ll>;
const ll MOD=1e9+7;//998244353;
const int MAX=1e5;
const ll INF=(1ll<<62)-1;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    int sum(int x){
        int ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
};
signed main(){
    int N,K; cin>>N>>K;
    vi dp(N+1);
    rep(i,0,N){
        int X; cin>>X;
        dp[i+1]=dp[i]+X;
    }
    REP(i,0,N) dp[N-i]+=K*i;
    ll ans=0;
    vector<pii> Data(N+1);
    REP(i,0,N) Data[i]=std::mp(dp[i],i);
    sort(ALL(Data));
    int memo=1;
    REP(i,0,N){
        int point=Data[i].second;
        if(i>0&&Data[i].first>Data[i-1].first) memo++;
        dp[point]=memo;
    }
    Binary_indexed_tree BIT(N+1);
    REP(i,0,N){
        ans+=BIT.sum(dp[i]);
        BIT.add(dp[i],1);
    }
    cout<<ans<<endl;
}
 

Measured memory_bytes: 6528
ab = []
for i in range(3):
    ab.append([int(v) for v in input().split()])

city_cnt = {i: 0 for i in range(1, 5)}
for a, b in ab:
    city_cnt[a] += 1
    city_cnt[b] += 1

if max(city_cnt.values()) == 3:
    print('NO')
else:
    print('YES')


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

using namespace std;

/********************************************************************************************************/

int n;
vector<int> v[100010];
int colr[100010];   //the color of each cell
int bl,wh;    //Fennec -> black , Snuke -> wh
int ok;

/***************************DFS()****************************/

void DFS(int x,int pre,int cl,int &tot)    //int &tot -> change tot while dfs()
{
	tot++;
	for(int i=0;i<v[x].size();i++)
		if(v[x][i]!=pre&&colr[v[x][i]]!=-cl)DFS(v[x][i],x,cl,tot);
}

void dfs(int x,int pre,int s,int &ok)
{
	if(x==n)
	{
		ok=s;
		return;
	}
	
	for(int i=0;i<v[x].size();i++)
	{
		if(ok)break;
		if(v[x][i]!=pre)dfs(v[x][i],x,s+1,ok);
	}
	
	if(ok)
	{
		if(x!=1&&s<=ok/2)colr[x]=1;
		if(x!=n&&s>ok/2)colr[x]=-1;
	}
	
	return;
}

/******************************************main*************************************************/

int main()
{
	/*********cin*********/
	
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		v[x].push_back(y);
		v[y].push_back(x);
	}
	
	/*****************clear***************/
	
	colr[1]=1;  //black
	colr[n]=-1;   //white
	//index from 1
	
	/***************do dfs in main()******************/
	
	dfs(1,-1000000007,0,ok);
	DFS(1,-1000000007,1,bl);
	DFS(n,-1000000007,-1,wh);
	
	/************************************************end****************************************/
	
	//judge who do more selections
	
	if(bl>wh)puts("Fennec");
	else puts("Snuke");
	
	return 0;
}

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

#define LL long long

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    int l, r; cin >> l >> r;
    if(r - l >= 2025) return cout << 0, 0;
    vector<int> v;
    int ans = 1e9;
    for(int i = l; i <= r; i++) v.push_back(i % 2019);
        
    for(int i = 0; i < v.size(); i++) {
        for(int j = i + 1; j < v.size(); j++) {
            ans = min(ans, (v[i] * v[j]) % 2019);
        }
    }
    cout << ans;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    string S;
    cin >> N >> S;
    reverse(all(S));
    vl A1(N), A2(N);

    ll V = 0, cnt = count(all(S), '1');
    ll c1 = cnt + 1, c2 = cnt - 1, s1 = 1, s2 = 1, sum1 = 0, sum2 = 0;
    rep(i, N){
        A1[i] = s1;
        (s1 *= 2) %= c1;
        if (S[i] == '1') (sum1 += A1[i]) %= c1;
        if(c2 > 0){
            A2[i] = s2;
            (s2 *= 2) %= c2;
            if (S[i] == '1') (sum2 += A2[i]) %= c2;
        }
    }

    vl ans(N);
    
    rep(i, N){
        ll tmp = 0;
        if(S[i]=='0'){
            tmp = sum1;
            (tmp += A1[i]) %= c1;
            ans[i] = 1;

            while(tmp){
                tmp = tmp % __builtin_popcount(tmp);
                ans[i]++;
            }
        }
        else{
            if (c2 <= 0) continue;
            tmp = sum2;
            (tmp += c2 - A2[i]) %= c2;
            ans[i] = 1;
            
            while(tmp){
                tmp = tmp % __builtin_popcount(tmp);
                ans[i]++;
            }
        }
    }

    reverse(all(ans));
    rep(i, N){
        cout << ans[i] << '\n';
    }
}

Measured memory_bytes: 8360
//                               //
    // author : samars_diary //
    // 17-09-2020 │ 17:10:23 //
//                               //

#include <iostream>
#include <cmath>
using namespace std;

void solve(){
    long long int a;
    cin>>a;
    int val(7%a);
    for(int i=1; i<10000000; i++){
        if(val==0){
            cout<<i;
            return;
        }
        val=(val*10+7)%a;
    }
    cout<<-1;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);

    //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    //#endif

    int t = 1;
    while(t--){
        solve();
    }

    return 0;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const int INF = 1 << 25;
const LL MOD = 1000000007LL;
using namespace std;
typedef pair<int, int> P;
int p[100000];
int main() {
	int N;
	cin >> N;
	rep(i, N) cin >> p[i], p[i]--;
	int ans = 0;
	for (int i = 0; i + 1 < N; i++) {
		if (p[i] == i) swap(p[i], p[i + 1]), ans++;
	}
	if (p[N - 1] == N - 1) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef long double     ld;
typedef string          str;
#define all(x)			(x).begin(),(x).end()
#define Sort(x)			sort(all(x))
#define A               first
#define B               second
#define sep             ' '
#define endl            '\n'
#define fast_io         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int MAX1 = 5e5 + 7;

ll a, b, c, T, d, e, l, r, x, y, z, mid, cnt, flag, mod = 1e9+7;
vector <ll> vec;

int main(){
	cin >> a;
	cout << 1.0*(a%2+a/2)/a;
    return 0;
}
/*                          now or never                         */

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

int main(void){
    long n;
    scanf("%ld",&n);
    long a[n+1],tmp[n+1];
    for(long i=0;i<=n;i++){
        a[i]=0;
    }
    for(long i=1;i<n;i++){
        scanf("%ld",&tmp[i]);
        a[tmp[i]]+=1;
    }
    for(long i=1;i<=n;i++){
        printf("%ld\n",a[i]);
    }
    return 0;
}

Measured memory_bytes: 4856
N = int(input().strip())
Q = [list(map(int, input().strip().split(' '))) for _ in range(N)]

def make_primeset(N):
  prime_set = {2,3}
  for i in range(5,N+1):
    prime_flag = True
    for j in prime_set:
      if i % j == 0:
        prime_flag = False
        break
    if prime_flag:
      prime_set.add(i)
  return prime_set

max_i = max(q[1] for q in Q)
prime_set = make_primeset(max_i)

# 累積和
cusum = [0]*(max_i+1)

now = 0
for i in range(1,max_i+1,2):
  if i in prime_set and (i+1)//2 in prime_set:
    now += 1
  cusum[i] = now

for l,r in Q:
  if l == 1:
    print(cusum[r])
  else:
    print(cusum[r]-cusum[l-2])

Measured memory_bytes: 69592
N,A,B=map(int,input().split())
C=A+B
D=N//C
count=D*A
N=N-C*D
while N>0:
    N=N-A
    if N>0:
        count=count+A
    elif N<=0:
        count=count+(A+N)
        break
    N=N-B
    if N<=0:
        break
    else:
        pass
print(count)

Measured memory_bytes: 3064
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pf push_front
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int mp[10000][10000]={};

signed main(){
  int n,u,k;
  cin>>n;
  int ad_m[100][100]={};
  rep(i,n){
    cin>>u>>k;
    rep(j,k){
      int v;
      cin>>v;
      v--;
      ad_m[i][v]+=1;
    }
  }
  rep(i,n){
    rep(j,n){
      cout<<ad_m[i][j];
      if(j<n-1)cout<<' ';
    }
    cout<<endl;
  }


  return 0;

}

Measured memory_bytes: 3160
#include<stdio.h>
int main()
{
	char S[10];
	scanf("%s", S);
	if (S[0] == 'S') {
		printf("Cloudy");
		return 0;
	}
	if (S[0] == 'C') {
		printf("Rainy");
		return 0;
	}
	printf("Sunny");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a<=12 && a>=6)
	  cout<<b/2;
	else
	  if(a>=13)
	    cout<<b;
      else
        cout<<0;
    return 0;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var shop = new int[n];
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var wk = Array.ConvertAll(line, int.Parse);
            shop[i] = Convert.ToInt32(string.Join("", wk), 2);
        }
        var p = new long[n, 11];
        for (int i = 0; i < n; i++)
        {
            string[] line2 = Console.ReadLine().Trim().Split(' ');
            for (int j = 0; j < 11; j++) p[i, j] = long.Parse(line2[j]);
        }
        var pmax = -999999999999999999L;
        for (int i = 1; i <= 1023; i++)
        {
            var psum = p[0, countBit(i & shop[0])];
            for (int j = 1; j < n; j++)
                psum += p[j, countBit(i & shop[j])];
            pmax = Math.Max(pmax, psum);
        }
        Console.WriteLine(pmax);
    }
    public static int countBit(int bits)
    {
        bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
        bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
        bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
        bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
        return (bits & 0x0000ffff) + (bits >> 16 & 0x0000ffff);
    }
}

Measured memory_bytes: 13632
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()


int main(){
    int N;
    cin >> N;
    bool flag = false;
    for(int a = 1; a <= 9; a++){
        for(int b = 1; b <= 9; b++){
            if(a * b == N) flag = true;
        }
    }
    if(flag) puts("Yes");
    else puts("No");
}


Measured memory_bytes: 3612
s = input()
N = len(s)
#連続
res = ""
ind = -1
eind = -1
c = 0
for i in range(N):
  if c == 0:
    if s[i] != res:
      res = s[i]
      ind = i
    else:
      c = 1
  elif c == 1:
    if s[i] != res:
      eind = i
      break
if eind == -1:
  if ind == N-1:
    ind = -1
  else:
    eind = N-1
#一個飛ばし
if ind == -1 and eind == -1:
  ind = -1
  eind = -1
  for i in range(N):
    if i+2 < N:
      if s[i] == s[i+2]:
        ind = i
        eind = i+2
        break  
if ind != -1 and eind != -1:           
  ind += 1
  eind += 1
print(ind,eind)      

Measured memory_bytes: 3188
def main():
    n, m = map(int, input().split())
    xs = list(map(int, input().split()))
    if n >= m:
        print(0)
        exit()
    xs = sorted(xs)
    diff_xs = sorted([xs[i+1] - xs[i] for i in range(m-1)])
    ans = sum(diff_xs[:m-n])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 20416
S = input()
a = int(S[:2])
b = int(S[2:])

ym = False
my = False
if a >= 0 and b>0 and b <= 12:
  ym = True
if b >= 0 and a>0 and a <= 12:
  my = True

if ym and my:
  print("AMBIGUOUS")
elif ym and not(my):
  print('YYMM')
elif not(ym) and my:
  print('MMYY')
else:
  print('NA')


Measured memory_bytes: 3060
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<pair<int, int>>qs;
		for (int i = 0; i < N; ++i) {
			int m, a, b; cin >> m >> a >> b;
			qs.push_back(make_pair(a, m));
			qs.push_back(make_pair(b, -m));
		}
		sort(qs.begin(), qs.end());
		int nw = 0;
		bool ok = true;
		for (int i = 0; i < qs.size(); ++i) {
			nw += qs[i].second;
			if (nw > 150)ok = false;
		}
		if (ok) {
			cout << "OK" << endl;
		}
		else {
			cout << "NG" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3088
while
  a =gets.split.map(&:to_i)
  if a[0]==0&&a[1]==0
    break
  end
  if a[0]>a[1]
    temp=a[0]
    a[0]=a[1]
    a[1]=temp
  end
  b=a.join(" ")
    puts b
end

Measured memory_bytes: 8920
#include <iostream>
using namespace std;
int main(){
  int a;cin>>a;
  a=a%10;
  if(a==3){
    cout << "bon"<<endl;
  }else{
    if(a==0||a==1||a==6||a==8){
      cout << "pon"<<endl;
    }else{
      cout << "hon"<<endl;
    }
  }
}

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

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

int main() {
    while (true) {
        vector<int> imos(24 * 60 * 60+1, 0);
        int n;
        cin>>n;
        if (n==0)
            break;
        rep(i,n){
            int h,m,s;
            char c;
            cin>>h>>c>>m>>c>>s;
            imos[h*60*60+m*60+s]++;
            cin>>h>>c>>m>>c>>s;
            imos[h*60*60+m*60+s]--;
        }

        rep(i,24*60*60){
            imos[i+1]+=imos[i];
        }
        int ans=-1;
        rep(i,24*60*60){
            ans=max(ans,imos[i]);
        }
        cout<<ans<<endl;

    }
    return 0;


}


Measured memory_bytes: 3432
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
using namespace std;
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define MEM(x,a) memset((x),a,sizeof((x)))
#define F first
#define S second
#define imx INT_MAX
#define inI(x) scanf("%d",&x)
#define inI2(x,y) scanf("%d %d",&x,&y)
#define inI3(x,y,z) scanf("%d %d %d",&x,&y,&z)
const long long MOD = (long long)(1e9+7);
const long long MMX = (long long)(1e18);
typedef long long LL;
char c[105][105];
bool p=false,ll=false;
int a,b,aa,bb,mid,k,ri=2,rj=2;
int main()
{
    scanf("%d %d",&a,&b);
    if(b==1&&a!=1)ll=true;
    for(int i=1;i<=99;i++)
    {
        for(int j=1;j<=99;j++)
        {
            c[i][j]='.';
        }
    }
    a--;
    b--;
    k=3;
    while(b--)
    {
        c[ri][rj]='#';
        rj+=k;
        if(rj>99)rj=98,ri+=3,k*=-1;
        if(rj<1)rj=2,ri+=3,k*=-1;
    }
    if(a==0)c[99][99]='#',p=true;
    while(a--)
    {
        c[ri+1][rj+1]='#';
        c[ri+1][rj-1]='#';
        c[ri-1][rj+1]='#';
        c[ri-1][rj-1]='#';
        c[ri+1][rj]='#';
        c[ri-1][rj]='#';
        c[ri][rj-1]='#';
        c[ri][rj+1]='#';
        rj+=k;
        if(rj>99)rj=98,ri+=3,k*=-1;
        if(rj<1)rj=2,ri+=3,k*=-1;
    }
    if(!p)
    {
        while(1)
        {
            c[ri+1][rj+1]='#';
            c[ri+1][rj-1]='#';
            c[ri-1][rj+1]='#';
            c[ri-1][rj-1]='#';
            c[ri+1][rj]='#';
            c[ri-1][rj]='#';
            c[ri][rj-1]='#';
            c[ri][rj+1]='#';
            c[ri][rj]='#';
            if(ri==98&&rj==98)break;
            rj+=k;
            if(rj>99)rj=98,ri+=3,k*=-1;
            if(rj<1)rj=2,ri+=3,k*=-1;
        }
    }
    if(ll)c[99][99]='.';
    printf("99 99\n");
    for(int i=1;i<=99;i++)
    {
        for(int j=1;j<=99;j++)
        {
            printf("%c",c[i][j]);
        }
        printf("\n");
    }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll H, W;
	cin >> H >> W;
	bool s[H][W];
	REP(i, H)REP(j, W){
		char tmp;
		cin >> tmp;
		s[i][j] = (tmp=='.'?false:true);
	}

	bool visited[H][W];
	REP(i, H)REP(j, W) visited[i][j] = false;
	queue< pair<pll, ll> > qu;
	qu.push({{0, 0},0});
	vector<pll> move{{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

	ll goal_dist;
	while(1){
		if(qu.empty()){
			cout << -1 << endl;
			return 0;
		}
		auto now = qu.front();qu.pop();
		pll now_grid = now.first;
		ll now_dist = now.second;
		if(now_grid.first == H-1 && now_grid.second == W-1){
			goal_dist = now_dist;
			break;
		}
		if(visited[now_grid.first][now_grid.second]) continue;
		visited[now_grid.first][now_grid.second] = true;

		REP(i, 4){
			pll next_grid = {now_grid.first + move[i].first, now_grid.second + move[i].second};
			if(next_grid.first < 0 || next_grid.first > H-1) continue;
			if(next_grid.second < 0 || next_grid.second > W-1) continue;
			if(!visited[next_grid.first][next_grid.second] && !s[next_grid.first][next_grid.second]){
				ll next_dist = now_dist + 1;
				qu.push({next_grid, next_dist});
			}
		}
	}

	ll sum = 0;
	REP(i, H)REP(j, W) sum += s[i][j];
	cout << H*W - sum - goal_dist - 1 << endl;

    return 0;
}

Measured memory_bytes: 256