akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[101010],B[101010],C[101010];
vector<pair<double,double>> P;

template<class V, int ME> class BIT {
public:
	V bit[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { e++; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
};

BIT<int,17> bt;
ll hoge(double v) {
	ZERO(bt.bit);
	vector<pair<double,int>> V;
	int i;
	
	FOR(i,N) V.push_back({v*P[i].first+P[i].second,i});
	sort(ALL(V));
	ll ret=0;
	
	FORR(c,V) {
		ret+=bt(c.second);
		bt.add(c.second,1);
	}
	return ret;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>A[i]>>B[i]>>C[i];
	
	FOR(i,2) {
		P.clear();
		FOR(j,N) {
			if(i==0) P.push_back({-1.0*A[j]/B[j],1.0*C[j]/B[j]});
			else P.push_back({-1.0*B[j]/A[j],1.0*C[j]/A[j]});
		}
		sort(ALL(P));
		
		double L=-1e9,R=1e9;
		FOR(j,100) {
			double M=(L+R)/2.0;
			if(hoge(M)<(1LL*N*(N-1)/2+1)/2) L=M;
			else R=M;
		}
		
		_P("%.12lf%c",L,(i==0)?' ':'\n');
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3600
max2 = lambda x,y: x if x > y else y
min2 = lambda x,y: x if x < y else y

import sys
from itertools import count
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


MOVES = [
    ((1, 0), [(2,-1),(2,0),(2,1),(2,2),(1,1)]),
    ((-1, 0),[(-2,-1),(-2,0),(-2,1),(-2,-2),(-1,-1)]),
    ((0, 1), [(1,2),(0,2),(-1,2),(-2,2),(-1,1)]),
    ((0, -1), [(1,-2),(0,-2),(-1,-2),(2,-2),(1,-1)]),
    ]

CONVERTED_MOVES = None

def solve(dist, start, goal):
    q = [start]
    cnt = 0
    while q:
        nq = []
        while q:
            x = q.pop()
            if x == goal:
                return cnt
            if dist[x] < cnt:
                continue
            for d,l in CONVERTED_MOVES:
                nx = x+d
                if dist[nx] > cnt:
                    dist[nx] = cnt
                    q.append(nx)
                if dist[nx] < 0:
                    for t in l:
                        p = x+t
                        if dist[p] > cnt+1:
                            dist[p] = cnt+1
                            nq.append(p)
        q = nq
        cnt += 1

    return -1




if __name__ == '__main__':
    H,W = map(int,readline().split())
    start = tuple(map(lambda i:int(i)+1,readline().split()))
    goal = tuple(map(lambda i:int(i)+1,readline().split()))

    H += 4
    W += 4

    dist = [-1]*(W*H)

    start = start[0]*W+start[1]
    goal = goal[0]*W+goal[1]

    for t,s in zip(count(2*W,W),read().split()):
        for i,c in zip(count(t+2),s.decode()):
            if c == '.':
                dist[i] = 10**7

    convert = lambda x,y: x*W+y
    CONVERTED_MOVES = []
    for d,l in MOVES:
        d = convert(*d)
        l = [convert(*d) for d in l]
        CONVERTED_MOVES.append((d,l))

    # print(CONVERTED_MOVES)

    print(solve(dist,start,goal))

Measured memory_bytes: 82392
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

double temp(int t, int h) {
    double s = t-h*0.006;
    return s;
}

int main() {
    int n,t,a;
    cin >> n >> t >> a;
    vector<int> H(n);
    vector<tuple<double,int>> diff(n);
    rep(i,n) {
        cin >> H[i];
    }
    rep(i,n) {
        double aa = a-temp(t,H[i]);
        if (aa<0) aa=-aa;
        diff[i] = tie(aa,i);
    }
    sort(all(diff));
    cout<<get<1>(diff.at(0))+1<<"\n";
}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#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 pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

ll combination(ll n, ll r)
{
	ll retval = 1;
	if ( r * 2 > n ) r = n - r;
	FORR(i,n,n-r+1)retval *= i;
	FOR(i,2,r+1)retval /= i;
	return retval;
}

int main()
{
	int n,p;
	cin >> n >> p;
	int oddCnt,evenCnt;
	oddCnt = evenCnt = 0;
	FOR(i,0,n){
		int a;
		cin >> a;
		if(a % 2 == 1){
			oddCnt++;
		}else{
			evenCnt++;
		}
	}
	ll ans = 1;
	FOR(i,0,evenCnt)ans *= 2;
	if(p == 0){
		ll a = 0;
		for(int i = 0; i <= oddCnt; i+=2){
			a += combination(oddCnt,i);
		}
		ans *= a;
	}else{
		ll a = 0;
		for(int i = 1; i <= oddCnt; i+=2){
			a += combination(oddCnt,i);
		}
		ans *= a;
	}
	ANS(ans);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();

		int[] x = new int[N+1];
		int[] y = new int[M+1];

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

		int minY = 100;
		int maxX = -100;
		x[N] = X;
		y[M] = Y;
		
		for(int i = 0; i <= N; i++) {
			maxX = Math.max(maxX, x[i]);
		}
		for(int i = 0; i <= M; i++) {
			minY = Math.min(minY, y[i]);
		}
		
		if(maxX < minY) {
			System.out.println("No War");
		}else {
			System.out.println("War");
		}
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;

const int MAXN = 100100;
int A[MAXN];

ll calc(int start, int N) {
	if (start == 0) return 1ll<<55;
	ll sum = start;
	ll ret = 0;
	for (int i = 1; i < N; i++) {
		ll old = sum;
		sum += A[i];
		if (old > 0 && sum >= 0) {
			ret += sum+1;
			sum = -1;
		} else if (old < 0 && sum <= 0) {
			ret += -sum+1;
			sum = 1;
		}
	}
	return ret;
}

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> A[i];
	ll ans = 1ll<<55;
	ans = calc(A[0], N);
	ans = min(ans, calc(1, N) + abs(A[0]-1));
	ans = min(ans, calc(-1, N) + abs(A[0]+1));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
N = int(input())
S = str(input())
R = S.count('R')
G = S.count('G')
B = S.count('B')

allpattern = R*G*B
counter = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        k = j-i
        
        if k+j <= N-1:
            if S[i] != S[j] and S[j] != S[j+k] and S[j+k] != S[i]:
                counter += 1
            

print(allpattern-counter)      

Measured memory_bytes: 68152
n, money = map(int, input().split())

flg = False
for i in range(n+1):
  for j in range(n+1-i):
    #print(10000*i + 5000*j + (n-i-j)*1000)
    if (10000*i + 5000*j + (n-i-j)*1000) == money:
      flg = True
      break
  if flg:
    break
if flg:
  print('{} {} {}'.format(i,j,n-(i+j)))
else:
  print('{} {} {}'.format(-1,-1,-1))

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			long[] t = new long[n], a = new long[n];
			for (int i = 0; i < n; i++) {
				t[i] = in.nextLong();
				a[i] = in.nextLong();
			}

			long nt = t[0], na = a[0];
			for (int i = 1; i < n; i++) {
				if (t[i-1]<=t[i] && a[i-1]<=a[i]) {
					nt = t[i];
					na = a[i];
				} else if (t[i-1]>t[i] && a[i-1]>a[i]) {
					long mul, mul1, mul2;
					if (t[i-1]%t[i]==0) {
						mul1 = t[i-1]/t[i];
					} else {
						mul1 = (t[i-1]/t[i])+1;
					}

					if (a[i-1]%a[i]==0) {
						mul2 = a[i-1]/a[i];
					} else {
						mul2 = (a[i-1]/a[i])+1;
					}

					mul = Math.max(mul1, mul2);
					t[i] *= mul;
					a[i] *= mul;

				} else if (t[i-1]>t[i]) {
					long mul = 1;
					if (t[i-1]%t[i]==0) {
						mul = t[i-1]/t[i];
					} else {
						mul = (t[i-1]/t[i])+1;
					}
					t[i] *= mul;
					a[i] *= mul;

				} else if (a[i-1]>a[i]) {
					long mul = 1;
					if (a[i-1]%a[i]==0) {
						mul = a[i-1]/a[i];
					} else {
						mul = (a[i-1]/a[i])+1;
					}
					t[i] *= mul;
					a[i] *= mul;
				}
//				out.println(t[i] + " " + a[i]);
			}

			out.println(t[n-1]+a[n-1]);

		}

	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

int main(){
    int n;
    cin >> n;
    string s;
    map<string, int> cnt;
    char temp[10];
    ll res = 0;
    for(int i = 0; i < n; ++i){
        cin >> s;
        for(int j = 0; j < 10; ++j){
            temp[j] = s[j];
        }
        sort(temp, temp+10);
        for(int j = 0; j < 10; ++j){
            s[j] = temp[j];
        }
        
        if(cnt.find(s) == cnt.end()){
            cnt[s] = 0;
        }
        else{
            cnt[s]++;
            res += cnt[s];
        }
    }
    
    cout << res << endl;
}

Measured memory_bytes: 11136
using System;
using System.Collections.Generic;
using System.Linq;
class b{
  public static void Main(){
    long n = long.Parse(Console.ReadLine());
    long[] num = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
    Array.Sort(num);
    long max = (long)Math.Pow(10,18);
    long ans = 1;
    for(long i=0; i<n; i++){
      if((double)max/num[i] < (double)ans){
        ans = -1;
        break;
      }
      ans *= num[i];
      if(ans > max){
        ans = -1;
        break;
      }
    }
    Console.WriteLine(ans);
  }
}


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

#define pb push_back
#define S second
#define F first
#define sz size()
#define eps 0.000001
#define oo 2000000007
#define endl '\n'
#define bg begin()
#define nd end()
#define up upper_bound
#define lw lower_bound
#define debug(x) #x << " = " << x << "; "
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define MOD 1000000007
const int N = 50; //Maximo size de la matriz

struct matrix {
    int m[N][N], r, c;

    matrix(int _r = N, int _c = N, bool iden = false) {
        r = _r; c = _c;
        memset(m, 0, sizeof(m));
        if (iden) while (_c--) m[_c][_c] = 1;
    }

    matrix operator * (const matrix &B) {
        matrix C(r, B.c);
        for(int i = 0; i < r; i++)
            for(int k = 0; k < c; k++) if (m[i][k])
                for(int j = 0; j < B.c; j++)
                    C.m[i][j] = (1ll*C.m[i][j] + 1ll*m[i][k]*B.m[k][j]) % MOD;
        return C;
    }
};

matrix pow(matrix A, ll e) {
    matrix ANS(A.r, A.c, true);
    while (e) {
        if (e&1) ANS = ANS * A;
        A = A * A;
        e >>= 1;
    }
    return ANS;
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n; ll k;
	cin >> n >> k;
	matrix mat;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> mat.m[i][j];
		}
	}
	ll ans = 0;
	mat = pow(mat, k);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			ans = (ans + mat.m[i][j]%MOD)%MOD;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);


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

  int n;
  cin >> n;
  map<string, vector<pair<int, int>>> mp;
  rep(i, n) {
    string c;
    int s;
    cin >> c >> s;
    mp[c].emplace_back(s, i+1);
  }

  for (auto& p : mp) {
    vector<pair<int, int>>& pp = p.second;
    sort(ALL(pp), greater<pair<int, int>>());
    for (auto& x : pp) {
      cout << x.second << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE 10
#define PI 3.141592653589793

using namespace std;
typedef long long ll;

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

	int N;
	int i,j;
	int tmp;
	int answer=0;
	int counter=0;
	string S;
	vector<int> given;

	cin >> S;

	if(S=="ABC") cout << "ARC" << endl;
	else cout << "ABC" << endl;

	return 0;
}



Measured memory_bytes: 3576
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}


signed main()
{
    string S, T;cin >> S >> T;
    int n = S.size(), m = T.size();
    int ans = 1e9;
    for (int i = 0; i < n; ++i) {
        int cnt = 0;
        if (i + m - 1 >= n) break;
        for (int j = 0; j < m; ++j) {
            if (S[i + j] != T[j]) cnt++;
        }

        chmin(ans, cnt);
    }

    cout << ans << endl;
}


Measured memory_bytes: 3596
import itertools
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A,B = IL()

if B%A == 0:
    print(A+B)
else:
    print(B-A)

Measured memory_bytes: 21028
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, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        k: i64,
        s: i64
    }
    let mut ans = 0;
    for i in max(0, s - 2 * k)..min(k, s) + 1 {
        ans += min(k, s - i) - max(0, s - k - i) + 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
const ll mod = 1e9+7;
const ll nax = 1e5+7;
const ll INF = 1e18;

ll n,dp[nax],a[nax];

int main(){
//	freopen("input.inp","r",stdin);
//	freopen("output.out","w",stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin>>n;
	for (ll i=1;i<=n;++i) cin>>a[i];
	
	for (ll i=2;i<=n;++i) dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),((i>2)? dp[i-2]+abs(a[i]-a[i-2]) : INF));
	
	cout<<dp[n]<<"\n";
}

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

namespace myApp
{
    class Program
    {
        public class Pair<T, U> {
            public Pair() {
            }

            public Pair(T first, U second) {
                this.First = first;
                this.Second = second;
            }

            public T First { get; set; }
            public U Second { get; set; }
        };
        static void Main(string[] args)
        {
            // 総面積
            var area = 0;

            // ＼ならば、その位置を表すiをスタックに積む
            // /ならば、対応する＼の位置を取り出し距離を総面積に加算する
            Stack<int>  S1 = new Stack<int>();

            // 水たまりの左の＼の位置と、面積のペアを積む
            // leftとiで挟まれる水たまりは取り出し、面積を合計してまた積む
            Stack<Pair<int, int>> S2 = new Stack<Pair<int, int>>();
            var line = Console.ReadLine().ToCharArray();
            for (int i = 0; i < line.Length; i++) {
                if (line[i] == '\\') {
                    S1.Push(i);
                } else if (line[i] == '/' && S1.Count > 0) {
                    int left = S1.Pop();
                    area += i - left;

                    int a = i - left;
                    while (S2.Count > 0 && S2.Peek().First > left) {
                        // leftより大きい、つまり内側
                        a += S2.Pop().Second;
                    }
                    S2.Push(new Pair<int, int>(left, a));
                }
            }

            // 総面積を出力する
            Console.WriteLine(area);

            // 水たまりの数とそれぞれの面積
            var ans = new List<int>();
            while (S2.Count > 0) {
                ans.Add(S2.Pop().Second);
            }
            ans.Reverse();
            Console.Write(ans.Count);
            for (int i = 0; i < ans.Count; i++) {
                Console.Write(" " + ans[i]);
            }
            Console.WriteLine();
        }
    }
}



Measured memory_bytes: 18380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N; cin >> N;
    string S; cin >> S;
    vector<set<int>> a(26);
    for (int i = 0; i < N; i++) {
        a[S[i] - 'a'].insert(i);
    }
    int l, r; char c;
    int q;
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> q;
        if(q == 1){
            cin >> l >> c; l--;
            a[S[l] - 'a'].erase(l);
            a[c - 'a'].insert(l);
            S[l] = c;
        }
        else{
            cin >> l >> r; l--; r--;
            int tmp = 0;
            for (int j = 0; j < 26; j++) {
                if(a[j].upper_bound(r) != a[j].lower_bound(l)){
                    tmp++;
                }
            }
            printf("%d\n", tmp);
        }
    }



}

Measured memory_bytes: 27256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mood) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mood;
		}
		x = x * x % mood;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n;
P a[100010];
int cnt;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(a, a + n);
	for (int i = 0; i < n; i++) {
		if (abs(i - a[i].second) % 2)cnt++;
	}
	cout << cnt / 2 << endl;
}

Measured memory_bytes: 1920
#include "omp.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <vector>
#include <cassert>
#include <fstream>
#include <algorithm>
#include <list>
#include <random>
#include <ctime>
#include <random>
#include <bitset>
#include <unordered_set>
#include <cassert>
#include <list>


using namespace std;

typedef long long ll;
typedef long double ld;


const int sze = 1e5 + 10;
const ll MOD1 = 1e9 + 7;

ll fact[sze];


inline ll MOD(ll v)
{
	return v % MOD1;
}


ll bin_pow(ll v, int pow)
{
	ll res = 1;

	while (pow)
	{
		if (pow & 1)
			res = MOD(res * v);

		pow >>= 1;

		v = MOD(v * v);
	}

	return res;
}


ll A(ll n, ll k)
{
	return MOD(fact[n] * bin_pow(fact[n - k], MOD1 - 2));
}


ll C(ll n, ll k)
{
	return MOD(fact[n] * bin_pow(MOD(fact[n - k] * fact[k]), MOD1 - 2));
}


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

	int n;
	cin >> n;
	string s;
	cin >> s;

	int lw = 0, le = 0, rw = 0, re = 0;
	for (int i = 0; i < n; ++i)
		if (s[i] == 'W')
			rw++;
		else
			re++;

	int ans = n;

	for (int i = 0; i < n; ++i)
	{
		if (s[i] == 'W')
			rw--;
		else
			re--;

		if (s[i] == 'W')
			ans = min(ans, re + lw);
		else
			ans = min(ans, re + lw);
	
		if (s[i] == 'W')
			lw++;
		else
			le++;
	}

	cout << ans;

	return 0;
}

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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> v(3),init(3);
	for (int i=0; i<n; ++i){
		for (int& k:init) cin >> k;
		init[0] += max(v[1],v[2]);
		init[1] += max(v[0],v[2]);
		init[2] += max(v[1],v[0]);
		v=init;
	}
	cout << max(v[0],max(v[1],v[2]));
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
struct p
{
    int x;
    long long val;
}a[100009];
int cmp(p a,p b)
{
    return a.val>b.val;
}
int main()
{
    int n,m;
    long long b[100009],sum=0;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&b[i]);
        sum+=b[i];
    }
    sort(b,b+n);
    for(int i=0;i<m;i++)
        scanf("%d%lld",&a[i].x,&a[i].val);
    sort(a,a+m,cmp);
    int i=0,j=0,tmp;
    while(1)
    {
        tmp=0;
        if(a[j].val<=b[i])
            break;
        while(b[i]<a[j].val&&tmp<a[j].x&&i<n)
        {
            tmp++;
            sum+=a[j].val-b[i];
            i++;
        }
        j++;
        if(i==n||j==m)
            break;
    }
    printf("%lld",sum);
    return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int ans = 753;
    for(int i=0;i<s.size()-2;i++){
        int val = (int)(s[i]-'0')*100 + (int)(s[i+1]-'0')*10 + (int)(s[i+2]-'0');
        ans = min(ans,abs(753-val));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
w,h,n = gets.chomp.split.map(&:to_i)
max_x = 0
min_x = w
max_y = 0
min_y = h

for i in 0..n-1
  x,y,a = gets.chomp.split.map(&:to_i)
  if a==1
    if max_x < x
      max_x = x
    end
  elsif a==2
    if min_x > x
      min_x = x
    end
  elsif a==3
   
    if max_y < y
      max_y = y
    end
  else
 if min_y > y
      min_y = y
    end
  end
end


ans = [(min_x-max_x),0].max * [(min_y-max_y),0].max
puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr
#define INT_MAX_HALF (INT_MAX / 2)

typedef long long ll;

using namespace std;
//using namespace boost::multiprec

ll gcd(ll a, ll b){

    if(a < b) return gcd(b, a);

    if(a % b == 0){
        return b;
    }else{
        return gcd(b, a % b);
    }
}

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

int main(){

    int n;
    cin >> n;

    //cerr << n << endl;

    ll ans = 1;

    //cerr << ans << endl;

    rep(i,n){
        ll tmp;
        cin >> tmp;

        ans = lcm(ans, tmp);

        //cerr << ans << endl;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9+21;
const long long LINF = (long long) 1e18;
const long double PI = 2 * acos((long double)0);
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
#define Mahmud main()
#define endl "\n"
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define alla(arr,n) arr,arr+n
#define sz(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define pb push_back
///Debug
#define dbg1(x) std::cerr<<#x<<"="<<(x)<<endl;
#define dbg2(x,y) std::cerr<<#x<<"="<<(x)<<','<<#y<<"="<<(y)<<endl;
#define dbg3(x,y,z) std::cerr<<#x<<"="<<(x)<<','<<#y<<"="<<(y)<<','<<#z<<"="<<(z)<<endl;
#define dbgArr(arr,n) cerr<<#arr<<"=["; printArray(arr,n,0,93); cerr<<endl;
///traversing
#define rep(n) for(int i=0;i<n;++i)
#define trv(i,t) for(__typeof(t.begin()) i=t.begin();i!=t.end();++i)
///necessary functions
inline ll Int()
{
    ll _x=0,_tmp=1;
    char _tc=getchar();
    while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
    if( _tc == '-' ) _tc=getchar(), _tmp = -1;
    while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
    return _x*_tmp;
}
inline long double Double()
{
    long double d;
    scanf("%Lf",&d);
    return d;
}
ll lcm(ll a,ll b)
{
    return a/__gcd(a,b)*b;
}
int ton(string x)
{
    int y;
    std::istringstream ss(x);
    ss >> y;
    return y;
}
template<typename T>
string tostring(T x)
{
    ostringstream ss;
    ss << x ;
    return ss.str();
}

///Current Code vars
#define N 100010
long long n,k,c,d;
int arr[N+1],brr[N+1];
///Current Code functions

string s;

bool chk()
{
    char c = s[0];
    for(int i=0;i<sz(s);++i)
    {
        if(c != s[i]) return false;
    }
    return true;
}

void solve()
{
    cin>>s;
    int ans=1e9;
    for(int i=0;i<sz(s);++i)
    {
        arr[s[i]-'a']++;
    }

    string pp = s,ss=s;
    for(int j=0;j<sz(pp);++j)
    {
        char to = pp[j];
        s = ss;
        int p = 0;
        while(!chk())
        {
            n = sz(s);
            p++;
            for(int i=0;i<n-1;++i)
            {
                if(s[i] != to && i+1<n && s[i+1]==to)
                {
                    s[i] = to;
                }
            }
            s = s.substr(0,n-1);
            //dbg2(s,p);
        }
        ans = min(ans,p);
    }
    cout<<ans<<endl;
}

int Mahmud
{
    // ios_base::sync_with_stdio(0); //cin.tie(0);
  //#ifdef _LOCAL_
    //freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
  //while(1)
    solve();
  //#ifdef _LOCAL_
    //printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
  //#endif
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

int func(){
    stack<vector<int>> st;
    st.push(vector<int>(1, 0));
    string str;
    cin>>str;
    int num = -1;
    foreach(i, str){
        if(i=='['){
            st.push(vector<int>());
        }else if(i==']'){
            if(num>=0){
                st.pop();
                st.top().push_back((num+1)/2);
                num=-1;
                continue;
            }
            vector<int> line = st.top();
            st.pop();
            sort(ALL(line));
            int num = 0;
            REP(j, (line.size()+1)/2){
                num+=line[j];
            }
            st.top().push_back(num);
            num=-1;
        }else{
            if(num<0)num=0;
            num=num*10+i-'0';
        }
    }
    return st.top().back();
}

int main(){
    int n;
    cin >> n;
    REP(i, n){
        cout << func() << endl;
    }
    return 0;
}




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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second


int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    while(k > 0 && b <= a){
        b *= 2;
        k--;
    }
    while(k > 0 && c <= b){
        c *= 2;
        k--;
    }
    if(a < b && b < c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, h, w;
    cin >> n >> h >> w;
    cout << (n - h + 1) * (n - w + 1) << endl;
    return 0;
}

Measured memory_bytes: 256
/*
  D - An Ordinary Game
  <http://abc048.contest.atcoder.jp/tasks/arc064_b>
  [Tips]
  ・strlen：文字列の長さを返す。'\0'は含まない。
*/

#include <stdio.h>
#include <string.h>

int main(int argc, char const *argv[]) {

  char s[100000];
  int len;

  scanf("%s", s);
  len = strlen(s);

  if( (len % 2) == 0 ){ // if "len" is an even number
    if( s[0] == s[len-1] ){ // if top character and end character are equal
      printf("First\n");
    }else{ // if top character and end character are not equal
      printf("Second\n");
    }
  }else{ // if "len" is an odd number
    if( s[0] == s[len-1] ){ // if top character and end character are equal
      printf("Second\n");
    }else{ // if top character and end character are not equal
      printf("First\n");
    }
  }

  return 0;
}


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

int main() {
  string s;
  cin >> s;
  if(s == "SUN") cout << 7 << endl;
  else if(s == "MON") cout << 6 << endl;
  else if(s == "TUE") cout << 5 << endl;
  else if(s == "WED") cout << 4 << endl;
  else if(s == "THU") cout << 3 << endl;
  else if(s == "FRI") cout << 2 << endl;
  else if(s == "SAT") cout << 1 << endl;
  return 0;
}

Measured memory_bytes: 3628
#pragma optimize("unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// #include <ext/pb_ds/assoc_container.hpp>
// typedef tree<int,null_type,less<int>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define Max(a,b,c) max(a,max(b,c))
#define Min(a,b,c) min(a,min(b,c))
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define pc(x)  __builtin_popcount (x)
#define vl vector< ll >
#define sorts(v) sort(v.begin(),v.end())
#define sortg(v) sort(v.begin(),v.end(),greater<ll>())
#define ss second
#define ff first
#define ll long long
#define ld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1e18)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 1000000007
#define mem(x,y) memset(x,y,sizeof(x))
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define gcd __gcd
#define primeDEN 727999983
#define nx_pe next_permutation(s.begin(),s.end())
#define cl cout<<"\n"
#define sp(x) setprecision(x)
const ll N=1e5+5;
vector<ll>v[N];
ll dp[N][2];
bool vis[N];
ll n;

void dfs(ll u)
{
    vis[u]=1;
    for(ll x:v[u])
    {
        if(vis[x])continue;
        dfs(x);
        dp[u][0]=(dp[u][0]%mod*(dp[x][0]%mod+dp[x][1]%mod+mod)%mod)%mod;
        dp[u][1]=(dp[u][1]%mod*((dp[x][0]%mod+mod)%mod)%mod);
    }
}


void solve()
{
   cin>>n;
   rep(i,n-1)
   {
       ll x,y;
       cin>>x>>y;
       v[x].pb(y);
       v[y].pb(x);
   }
   if(n==1)
   {
       cout<<2<<"\n";
       return ;
   }
   f(i,1,n+1)
   {
       
       {
           dp[i][0]=1;
           dp[i][1]=1;
       }
   }
   dfs(1);
//    f(i,1,n+1)
//    {
//        cout<<i<<"    "<<dp[i][0]<<' '<<dp[i][1]<<"\n";
//    }
   cout<<(dp[1][0]%mod+dp[1][1]%mod+mod)%mod<<"\n";
}


    
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("ouput.txt", "w", stdout) ;
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    std::ios::sync_with_stdio(false);
    ll te=1;
    // cin>>te;
    while(te--){
        solve();
    }
    
}


Measured memory_bytes: 16352
void main() {
    int[] tmp = readln.split.to!(int[]);
    int w = tmp[0], a = tmp[1], b = tmp[2];
    writeln(abs(b-a) > w ? abs(b-a) - w : 0);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

public class Main {
	
	public static void main(String[] args) {
		// 入力
		final int a, b, c;
		try(Scanner scan = new Scanner(System.in)) {
			a = scan.nextInt();	// 2≤A，B，C≤10^9
			b = scan.nextInt();
			c = scan.nextInt();
		}
		
		long result;
		// 偶数の辺があれば、そこで2等分できる。
		if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
			result = 0;
		} else {
			int[] edges = {a, b, c};
			// 短い辺2つの積 * 1(残りの辺も奇数)
			Arrays.sort(edges);
			result = (long) edges[0] * edges[1];
		}
		
		// 出力
		try (PrintWriter out = new PrintWriter(System.out)) {
			out.println(result);
		}

	}

}

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

int n;
string s;
char ans[100001];

int main(){
	cin >> n >> s;
	
	bool b = 0;
	char c[2] = {'S', 'W'};
	for(int j = 0; j < 4; j++){
		if(b) break;
		for(int i = 0; i < n; i++){
			ans[i] = '*';
		}
		
		ans[0] = c[j/2]; ans[1] = c[j%2];
		
		for(int i = 0; i < n; i++){
			int l = i-1, r = i+1;
			if(i == 0) {l = r; r = n-1;}
			if(i == n-1) r = 0;
			if(s[i] == 'o' && ans[i] == 'S' || s[i] == 'x' && ans[i] == 'W'){
				if(ans[r] == '*') ans[r] = ans[l];
				else if(ans[r] == ans[l]){
					b = 1;
				}
				else {b = 0; break;}
			}
			else{
				if(ans[r] == '*'){
					if(ans[l] == 'S') ans[r] = 'W';
					else ans[r] = 'S';
				}
				else if(ans[r] != ans[l]){
					b = 1;
				}
				else {b = 0; break;}
			}
		}
	}
	
	if(b){
		for(int i = 0; i < n; i++){
			cout << ans[i];
		}
		cout << endl;
	}
	else cout << -1 << endl;
	
	return 0;
}

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

int main(){
	int n,i,ans = 1;
	char tmp;
	cin >> n;
	string s;
	cin >> s;
	tmp = s[0];
	for(i = 1; i < n; i++){
		if(s[i] != tmp){
			ans++;
		}
		tmp = s[i];
	}

	cout << ans;
	return 0;
}


Measured memory_bytes: 512
# undo が出来るゲームは全て2手だけ見ればよい
ops = ["+", "*", "-", "&", "^", "|"]
numbers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]


def check(x):
    # +*
    op = 0
    for c in x:
        if c in ops:
            op += 1
            if op >= 2:
                return None
        else:
            op = 0
    # +...
    for op in ops:
        if x.startswith(op):
            return None
        if ("(" + op) in x:
            return None
    # 0がないか
    zero_ok = False
    for c in x:
        if not zero_ok and c == "0":
            return None
        if c in ops:
            zero_ok = False
        elif c in numbers:
            zero_ok = True
        else:  # ( )
            zero_ok = False
    try:
        val = int(eval(x))
        return val
    except:
        return None


def get_nexts(x):
    # 削除
    result = []
    for i in range(len(x)):
        y = x[:i] + x[i + 1:]
        val = check(y)
        if val != None:
            result.append((val, y))
    # 追加
    for i in range(len(x) + 1):
        add_list = numbers + ops
        for s in add_list:
            y = x[:i] + s + x[i:]
            val = check(y)
            if val != None:
                result.append((val, y))
    return result


while True:
    n, x = input().split(" ")
    n = int(n)
    if n == 0:
        quit()
    nexts = get_nexts(x)
    if n % 2 == 1:
        nexts.sort(key=lambda a: - a[0])
        print(nexts[0][0])
        continue
    minvals = []
    for (val, y) in nexts:
        nextss = get_nexts(y)
        nextss.sort(key=lambda a: a[0])
        minvals.append(nextss[0][0])
    print(max(minvals))



Measured memory_bytes: 5616
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <utility>
#define DIVCEIL(A,B) ((A+(B-1))/B)
#define LL long long
#define sgn(a) ((a>0)-(a<0))
using namespace std;


void solve(long long N, long long C, std::vector<long long> s, std::vector<long long> t, std::vector<long long> c){
    multiset<pair<LL, LL>> events;
    map<LL, LL> cs;

    for(LL i=0; i<N; i++){
        events.insert(make_pair(s[i], -c[i]));
        events.insert(make_pair(t[i], c[i]));
    }
    LL ans=0;
    for(auto kv: events){
        auto op = sgn(kv.second);
        auto channel = op*kv.second;
        if(op==1){
            cs[channel]--;
            if(!cs[channel])cs.erase(channel);
        }
        else cs[channel]++;
        ans = max(ans, (LL)cs.size());
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long C;
    scanf("%lld",&C);
    std::vector<long long> s(N);
    std::vector<long long> t(N);
    std::vector<long long> c(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&s[i]);
        scanf("%lld",&t[i]);
        scanf("%lld",&c[i]);
    }
    solve(N, C, std::move(s), std::move(t), std::move(c));
    return 0;
}


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

int main() {
    string s;
    cin>>s;
    ll count[3]={0,0,0},nowh=1;
    for (int i = 0; i < s.length(); ++i) {
        string now=s.substr(i,1);
        if(now=="A"){
            count[0]+=nowh;
        }
        if(now=="B"){
            count[1]+=count[0];
        }
        if(now=="C"){
            count[2]+=count[1];
        }
        if(now=="?") {
            count[2]=count[2]*3+count[1];
            count[1]=count[1]*3+count[0];
            count[0]=count[0]*3+nowh;
            nowh*=3;
        }
        count[0]%=Mod;
        count[1]%=Mod;
        count[2]%=Mod;
        nowh%=Mod;
        //cout<<count[0]<<" "<<count[1]<<" "<<count[2]<<" "<<nowh<<endl;
    }
    cout<<count[2];
    return 0;
}


Measured memory_bytes: 512
def s(n,m):
  f = 1
  for i in range(1,n+1):f*=i;f%=m
  return f
N,M=map(int,input().split());m=10**9+7
print(s(N,m)*s(M,m)*(2-(N+M)%2)%m if abs(N-M) < 2 else 0)

Measured memory_bytes: 62924
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
typedef struct pp
{   char x[50];
    int t,R;
}S;
S s[105];
bool cmp(S a,S b)
{   if(a.R==b.R)return strcmp(a.x,b.x);
    return a.R>b.R;
}
int main()
{   int i,j,T,n,a=0,b=0;char x[200];
    scanf("%s",x);
    for(i=0;i<strlen(x);i++)
    {   if((i+1)%2==1)
        {   if(x[i]=='L')a=1;
        }
        if((i+1)%2==0)
        {   if(x[i]=='R')b=1;
        }
    }
    if(a==1||b==1)printf("No\n");
    else printf("Yes\n");
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
bool betemp(string sleft, string sright, int left, int right){
  if(sleft==sright){
    return (right-left)%2 == 1;
  }else{
    return (right-left)%2 == 0;
  }
}
void solve(int N){
  string vct = "Vacant";
  string sleft, sright, str;
  int left=0, right=N/2;
  cout << left << endl;
  cin >> sleft;
  if(sleft==vct) return ;
  cout << right << endl;
  cin >> sright;
  if(sright==vct) return ;
  if(!betemp(sleft, sright, left, right)){
    swap(sleft, sright), left = right, right = N;
  }
  while(left+1<right){
    int mid = (left+right)/2;
    cout << mid << endl;
    cin >> str;
    if(str==vct) return;
    if(betemp(sleft, str, left, mid)){
      sright = str, right = mid;
    }else{
      left = mid, sleft = str;
    }
  }
}
int main(){
  int N;
  while(cin>>N) solve(N);
  return 0;
}


Measured memory_bytes: 852
N = int(input())
p = list(map(int,input().split()))
pn = []
count = 0
for i in range(N-1):
    if i+1 == p[i]:
        p[i],p[i+1] = p[i+1],p[i]
        count += 1
if p[-1] == N:
    count += 1
print(count)

Measured memory_bytes: 14008