akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
typedef long long LL;
int main(){
    int k,a,b;
    scanf("%d %d %d",&k,&a,&b);
    if(b>a+2){
        if(k+1<=a){
            printf("%d\n",k+1);
        }
        else{
            k-=a-1;
            LL res=a;
            res+=(LL)k/2*(b-a);
            res+=k%2;
            printf("%lld\n",res);
        }
    }
    else{
        printf("%d\n",k+1);
    }
}

Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<usize>();
    let (n, m) = (line[0], line[1]);

    let a = read_as_vec::<usize>();

    if a.iter().sum::<usize>() > n{
        println!("-1");
    }else{
        println!("{}", n- a.iter().sum::<usize>());
    }
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
string s[51]={ "KIHBR","AKIHBR","KIHABR","KIHBAR","KIHBRA","AKIHABR","AKIHBAR","AKIHBRA","KIHABAR","KIHABRA","KIHBARA","AKIHABAR","AKIHABRA","AKIHBARA","KIHABARA","AKIHABARA"};
string x;
int main(){
	cin>>x;
	for (int i=0;i<50;i++) if (s[i]==x){
		cout<<"YES";
		return 0;
	}
	cout<<"NO";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
n,k = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
s = [0]
for i in range(len(a)):
    s.append(s[-1]+a[i])
for i in range(len(s)):
    s[i] = (s[i] - i) % k
# print(s)
d = {0:1}
ans = 0
for j in range(1,n+1):
    if s[j] in d:
        d[s[j]] += 1
    else:
        d[s[j]] = 1
    if j >= k:
        d[s[j-k]] -= 1
    ans += d[s[j]] - 1
    # print(d)
    # print(ans)
print(ans)

Measured memory_bytes: 111448
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long li;

li a, b, c, x, y, ans;

int main(void) {
  scanf("%lld%lld%lld%lld%lld", &a, &b, &c, &x, &y);
  ans = x * a + y * b;
  for (int i = 1; i <= x || i <= y; ++i) {
    li cntx = max(0LL, x - i);
    li cnty = max(0LL, y - i);
    ans = min(ans, cntx * a + cnty * b + c * 2 * i);
  }
  printf("%lld\n", ans);
  
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();

		String sa = "";
		String sb = "";

		for (int i = 0; i < a; i++) {
			sb += b;
		}

		for (int i = 0; i < b; i++) {
			sa += a;
		}
		String res = sa.compareTo(sb) > 0 ? sb : sa;
		System.out.println(res);
	}
}

Measured memory_bytes: 21588
n, m = map(int,input().split())
a, b = map(int,input().split())
cnt = 0
for i in range(1, m):
  l, r = map(int,input().split())
  if (l > b and r > b) or (l < a and r < a):
    print(0)
    exit()
  if a<=l<=b:
    a = l
  if r <= b:
    b = r
print(b-a+1)


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	char c; cin >> c;
	if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') cout << "vowel" << endl;
	else cout << "consonant" << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramA
    {
        static void Main()
        {
            int a = NextInt, b = NextInt, c = NextInt;
            System.Console.WriteLine(a * b / 2);
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 13268
fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextInt()
        val a = sc.longList()
        // +-+-+-
        var p = 0L
        var m = 0L
        var tmpP = 0L
        var tmpM = 0L
        for (i in 0 until n) {
            tmpP += a[i]
            tmpM += a[i]
            if (i % 2 == 0) {
                // +
                if (tmpP <= 0) {
                    p += -tmpP + 1
                    tmpP = 1
                }

                if (tmpM >= 0) {
                    m += tmpM + 1
                    tmpM = -1
                }
            } else {
                // -
                if (tmpP >= 0) {
                    p += tmpP + 1
                    tmpP = -1
                }

                if (tmpM <= 0) {
                    m += -tmpM + 1
                    tmpM = 1
                }
            }
        }

        println(Math.min(p,m))
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        while (l.size <= ptr) {
            l = readLine()!!.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        return readLine()!!.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


Measured memory_bytes: 53016
#include <stdio.h>

int main(){ 
	long long l,r,f,s,i,j;
	scanf("%lld %lld",&l,&r);
	for(i = l;i <= r;i++){
		if(i % 2019 == 0){
			printf("0");
			return 0;
		}
	}
	f = l * r % 2019;
	for(i = l;i < r;i++){
		for(j = i + 1;j <= r;j++){
			s = i * j % 2019;
			if(s < f) f = s;
			if(f==1) break;
		}
	}
	printf("%lld",f);
	return 0;
}

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

typedef long long ll;
typedef long double ld;
// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// use merge(all(vec1), all(vec2), vec3.begin()) to merge 2 vectors, use vec3.resize(vec1.size() + vec2.size()) first
// ll pos = partition_point(all(vec), pred) - vec.begin(); bool pred(ll a){return a<3};
// print number in binary -> cout << bitset<20>(n);

int main(){
	cin.tie(0);cin.sync_with_stdio(0);
	int n,res=0;cin>>n;
	for(int i=0;i<n;++i){
		int num;cin>>num;if(!(i%2)&&num%2)++res;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 3632
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextssort(n,a){return a?cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>b-a):cin.slice(cid,cid+=n).map(a=>+a).sort((a,b)=>a-b);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var mod = 1e9+7;
function mul(){for(var a=arguments,r=a[0],i=a.length;--i;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i])%mod;return r;}
var fac=[],finv=[],invs=[],pow2=[];
function fset(n){
  fac.length=n+1,fac[0]=fac[1]=1;
  for(var i=2;i<=n;)fac[i]=mul(fac[i-1],i++);
  finv.length=n+1,finv[0]=finv[1]=1,finv[n]=inv(fac[n]);
  for(i=n;2<i;)finv[i-1]=mul(finv[i],i--);
  //invs.length=n+1,invs[0]=invs[1]=1;
  //for(i=2;i<=n;)invs[i]=mul(fac[i-1],finv[i++]);
  //pow2.length=n+1,pow2[0]=1;
  //for(i=1;i<=n;i++)pow2[i]=pow2[i-1]*2%mod;
}
function inv(b){for(var a=mod,u=0,v=1,t;b;v=t)t=a/b|0,a-=t*b,u-=t*v,t=a,a=b,b=t,t=u,u=v;u%=mod;return u<0?u+mod:u;}
function pow(a,n){for(var r=1;n;a=mul(a,a),n>>=1)if(n&1)r=mul(a,r);return r;}
function ncr(n,r){return mul(fac[n],finv[r],finv[n-r]);}
function npr(n,r){return mul(fac[n],finv[n-r]);}
function mput(n){return (n%mod+mod)%mod;}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var a = nexts(n);
  var ans = a.reduce((a,b)=>a+b);
  ans %= mod;
  ans = mul(ans,ans);
  for(var i = 0; i < n; i++){
    ans -= mul(a[i],a[i]);
  }
  return mul(mput(ans),inv(2));
}

Measured memory_bytes: 58828
#!/usr/bin/env python3

N, M = map(int, input().split())
A = [list(input().split()) for i in range(M)]

if N == 1:
    for i in range(0, 10):
        while all(str(i)[int(A[j][0])-1] == A[j][1] for j in range(M)):
            print(i)
            exit()

if N == 2:
    for i in range(10, 100):
        while all(str(i)[int(A[j][0])-1] == A[j][1] for j in range(M)):
            print(i)
            exit()

if N == 3:
    for i in range(100, 1000):
        while all(str(i)[int(A[j][0])-1] == A[j][1] for j in range(M)):
            print(i)
            exit()

print(-1)

Measured memory_bytes: 3064
/*
ID: arthurc4
TASK: test
LANG: C++11
*/

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <stack>
#include <deque>

using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++)

#define REPb(j, d, c) \
for (int j = int(d); j >= int(c); j--)

#define pb \
push_back

#define ff \
first

#define ss \
second

ll h[100001];
ll dp[100001];

int main()
{
	//ifstream cin("input.txt");
	//ifstream cin("test.in");
	//ofstream cout("test.out");

	ll n, k;
	cin >> n >> k;

	REP(i,1,n)
	{
		ll h_i;
		cin >> h_i;
		h[i]=h_i;
		dp[i]=1000000000;
	}

	dp[1]=0;

	REP(i,2,n)
	{
		REP(j,max(i-k,ll(1)),i-1)
		{
			dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}

	cout << dp[n] << endl;

	return 0;
}

Measured memory_bytes: 1792
const main = input => {
  const N = parseInt(input.trim())
  let ans = 0
  for (let i = 1; i <= N; i++) {
    if (i.toString().length % 2 !== 0) {
      ans++
    }
  }

  console.log(ans)
}
// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 34932
import math
a,b,h,m=map(int,input().split())
h=h/12*360 + m/60*30
m=m/60*360
c = h-m
c = min(360-c,c)*math.pi/180
x = (a**2+b**2-2*a*b*math.cos(c))**(0.5)
print("{:.20f}".format(x))


Measured memory_bytes: 9500
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
bool isDigit(char c){return '0' <= c && c <= '9';}
template<typename T> void remove(std::vector<T>& vector, unsigned int index){vector.erase(vector.begin() + index);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed main(){
    SPEED;
    int a,b,c;
    cin >> a >> b >> c;
    int ans;
    if(c<a-b)ans = 0;
    else ans = c-a+b;
    cout << ans << endl;
}


Measured memory_bytes: 256
// abc163_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;

    vector<int> A(N);
    REP(i, N-1){
        int a; cin >> a; a--;
        A[a]++;
    }
    REP(i, N){
        print(A[i]);
    }


    return 0;
}


Measured memory_bytes: 3972
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>

using namespace std;



int main() {
	int n;
	cin >> n;
	map<char, int>w;
	for (char j = 'a'; j <= 'z'; j++) {
		w[j] =99999;
	}

	for (int i = 0; i < n; i++) {
		string p;
		cin >> p;
		map<char, int>z;

		for (int j = 0; j < p.size(); j++) {
			z[p[j]]++;

		}
		for (char j = 'a'; j <= 'z'; j++) {
			w[j] = min(w[j], z[j]);
		}

	}
	for (char j = 'a'; j <= 'z'; j++) {
		for (int i = 0; i < w[j]; i++)cout << j ;
	}
	
	cout << endl;

	return 0;
	
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n, i;
	
	while (1){
		
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		i = 0;
		while (1){
			
			if (n == 1){
				break;
			}
			
			if (n % 2 == 0){
				n /= 2;
				i++;
			}
			else {
				n = n * 3 + 1;
				i++;
			}
		
		}
		printf("%d\n", i);
	}
	
	return (0);
}

Measured memory_bytes: 600
#include<iostream>
#include<functional>
#include<vector>
#include<queue>
#include<utility>
#include<cstring>
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int, int> PII;
typedef vector<PII> VP;
typedef VP::iterator VPI;

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

int r;
int w[2], h[2], x[2], y[2];
int room[2][500][500];

VP level[2];
bool though[2][500][500];
int main()
{
  while(cin >> r && r){

    memset(though, false, sizeof though);
    level[0].clear();
    level[1].clear();

    //part1
    for(int i = 0; i < 2; i++){
      cin >> w[i] >> h[i] >> x[i] >> y[i];
      for(int j = 0; j < h[i]; j++){
	for(int k = 0; k < w[i]; k++){
	  cin >> room[i][j][k];
	}
      }
    }

    //part2
    for(int i = 0; i < 2; i++){
      priority_queue<PII, vector<PII>, greater<PII> > search;
      search.push(MP(1, (y[i] - 1) * 10000 + (x[i] - 1)));
      though[i][y[i] - 1][x[i] - 1] = true;
      
      int counter = 0, lv = 0;
      while(!search.empty()){
	PII now = search.top();
	search.pop();

	if(now.first > lv){
	  level[i].PB(MP(counter, lv));
	  lv = now.first;
	}
	counter++;
	for(int j = 0; j < 4; j++){
	  int nexty = now.second / 10000 + dy[j];
	  int nextx = now.second % 10000 + dx[j];

	  if(0 <= nexty && nexty < h[i] && 0 <= nextx && nextx < w[i] && !though[i][nexty][nextx]){
	    though[i][nexty][nextx] = true;
	    search.push(MP(room[i][nexty][nextx], nexty * 10000 + nextx));
	  }
	}
      }
      level[i].PB(MP(counter, lv));
    }

    //part3
    int ans = 2e9;
    for(int i = 0; i < level[0].size(); i++){
      VPI pr = lower_bound(level[1].begin(), level[1].end(), MP(r - level[0][i].first, 0));
      if(pr != level[1].end())
	ans = min(ans, level[0][i].second + pr->second);
    }

    cout << ans << endl;
  }
  return 0;
}

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

int main(){
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >> ty;
  int x=tx-sx,y=ty-sy;
  cout << string(x,'R')<<string(y,'U')<<string(x,'L')<<string(y+1,'D')<<
    string(x+1,'R')<<string(y+1,'U') << 'L'<< 'U'<<string(x+1,'L')<<string(y+1,'D')<<'R'<<endl;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,a,sum,ans;

signed main() {
    cin >> n;
    rep(i,n) {
        cin >> a;
        sum += a;
        if (!a) ans += sum/2, sum=0;
    }
    ans += sum/2;
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;

long long sum(long long n){
    return (n*(n+1))/2;
}
int main(){
    int N, K; cin >> N >> K;
    long long ans = 0;
    for (int i = K; i <= N+1; i++){
        ans += sum(N+1) - sum(N-i+1) - sum(i) + 1;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
//#include <string>
#include <string.h>
#include <algorithm>

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
 
typedef long long ll;
typedef char str255[256];

#define BIG_PRIME 1'000'000'007
#define BP_remainder(x) ((x) % BIG_PRIME)

const int INF = 1 << 30;
const int INF_NEG = INF * -1;
const ll INF_LONG = 1LL << 62;
const ll INF_LONG_NEG = INF_LONG * -1;

int main()
{
    char S[55]; cin >> S;
    int lenS = strlen(S);
    
    bool used[260]; rep(i, 260) used[i] = false;

    rep(i, lenS){
        int code = S[i];
        if (used[code]){
            puts("-1"); return 0;
        }
        used[code] = true;
    }

    if (lenS < 26){  // 使われていない文字がある場合は一番小さい文字を追加
        for (char c = 'a'; c <= 'z'; ++c){
            if(!used[c]){
                S[lenS] = c;
                S[lenS + 1] = '\0';
                cout << S << endl;
                return 0;
            }
        }
    } else { // 既に全ての文字が使われている場合
        used[S[25]] = false;
        for (int ptr = 24; ptr >= 0; --ptr){
            char deleteChar = S[ptr];
            used[deleteChar] = false;
            for (char c = deleteChar + 1; c <= 'z'; ++c){
                if (!used[c]){
                    S[ptr] = c;
                    S[ptr + 1] = '\0';
                    cout << S << endl;
                    return 0;
                }
            }
        }
        puts("-1"); // 新たに多彩な単語が作れなかった場合
    }

    return 0;
}


Measured memory_bytes: 256
// Ho-kago Tea Time

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MOD = (int) 924844033;

inline int fpm(int x, int y)
{
	int res = 1;
	for(; y; y >>= 1, x = (LL) x * x % MOD) if(y & 1) res = (LL) res * x % MOD;
	return res;
}

inline int inv(int x) { assert(x); return fpm(x, MOD - 2); }

namespace MATH
{
	const int n = (int) 2e3;

	int fac[n + 5];

	inline void init()
	{
		fac[0] = 1;
		for(int i = 1; i <= n; ++i) fac[i] = (LL) fac[i - 1] * i % MOD;
	}
}
using MATH::fac;

const int MAXN = (int) 4e3;

int n, k;

inline void input()
{
	n = read<int>(), k = read<int>();
}

inline void solve()
{
	static int ban[MAXN + 5];

	int N = 0;
	for(int i = 1; i <= k; ++i)
	{
		int len = 0;
		for(int j = i; j <= n; j += k) ++len;

		N += len, ban[N] = 1;
		N += len, ban[N] = 1;
	}

	static int f[MAXN  + 5][MAXN + 5][2];

	f[0][0][0] = 1;
	for(int i = 0; i < N; ++i) for(int j = 0; j <= i; ++j) for(int p = 0; p < 2; ++p) if(f[i][j][p])
		for(int q = 0; q < 2; ++q) if(!(p & q) && !(ban[i + 1] & q))
			(f[i + 1][j + q][q] += f[i][j][p]) %= MOD;

	int ans = 0;
	for(int i = 0; i <= n; ++i) (ans += (LL) (i & 1 ? -1 : +1) * f[N][i][0] % MOD * fac[n - i] % MOD) %= MOD;
	printf("%d\n", (ans + MOD) % MOD);
}

int main()
{
#ifdef K_ON // K-ON!
	freopen("D.in", "r", stdin);
	freopen("D.out", "w", stdout);
#endif

	MATH::init();
	input();
	solve();

	return 0;
}



Measured memory_bytes: 123520
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef unsigned long long ll;
struct node{
    ll id;
    node* parent;
    node* marked_parent;
    ll h;
    vector<node*> child;
};
int main(){
   // freopen("/Users/shitian/Downloads/1.txt","r",stdin);
    int n,q,p;
    while(cin>>n>>q,n){
        vector<node*>vec;
        vector<int>marked(n,0);
        for(int i=0;i<n;i++){
            node* t=new node;
            vec.push_back(t);
        }
        node* no=vec[0];
        no->id=1;
        no->parent=no;
        no->h=1;
        no->marked_parent=vec[0];
        marked[0]=1;
        for(int i=2;i<=n;i++){
            cin>>p;
            node* no=vec[i-1];
            no->id=i;
            no->parent=vec[p-1];
            no->h=no->parent->h+1;
            no->marked_parent=vec[0];
            vec[p-1]->child.push_back(no);
        }
        ll ans=0;
        for(int i=0;i<q;i++){
            
            char que;int num;
            cin>>que>>num;
            if(que=='M'){
                marked[num-1]=1;
                node* mp=vec[num-1];
                queue<node*>que;
                que.push(mp);
                while(!que.empty()){
                    node* now=que.front();
                    que.pop();
                   // cout<<"now->id-1       "<<now->id-1<<endl;
                    if(marked[now->id-1]==1&&now->id!=num){
                        continue;
                    }
                    now->marked_parent=mp;
                   // cout<<"now-id: "<<now->id<<"     mp->id: "<<mp->id<<endl;
                    for(int i=0;i<now->child.size();i++){
                        que.push(now->child[i]);
                    }
                }
            }
            else{
                ans+=vec[num-1]->marked_parent->id;
            }
        }
        cout<<ans<<endl;;
        vec.clear();
        marked.clear();
    }
}

Measured memory_bytes: 42080
#include<stdio.h>
int main(void) {
	int s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,sum=0,i=0;
	scanf("%d%d%d%d%d%d%d%d%d%d", &s1, &s2, &s3, &s4, &s5, &s6, &s7, &s8, &s9, &s10);
	sum = s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10;
	printf("%d", sum);
	printf("\n");
	return 0;
}


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

typedef struct data
{
	int ord;
	int idx;
} stu;

int q_cmp(const void *a, const void *b)
{
	return ((stu *)a)->ord - ((stu * )b)->ord;
}

int main()
{
	int n;
	cin >> n;
	stu list[n];
	rep(i, n)
	{
		cin >> list[i].ord;
		list[i].idx = i;
	}
	int size = sizeof(list) / sizeof(stu);
	qsort(list, size, sizeof(stu), q_cmp);
	rep(i, n)
	{
		cout << list[i].idx+1 << " ";
	}
	return (0);
}

Measured memory_bytes: 1788
/*
	0228:Seven Segment
*/
#include	<iostream>
#include	<string>

using namespace std;

const string segNums[10] = {
	"0111111", "0000110", "1011011", "1001111", "1100110",
	"1101101", "1111101", "0100111", "1111111", "1101111"
};

int main(void) {
	int n;
	while(1) {
		cin >> n;
		if(n == -1) { break; }
		string seg = "0000000";
		for(int i = 0; i < n; i++) {
			int sn;
			
			cin >> sn;
			for(int t = 0; t < 7; t++) {
				if(seg[t] == segNums[sn][t]) {
					cout << '0';
				} else {
					cout << '1';
				}
			}
			cout << endl;
			seg = segNums[sn];
		}
	}
}

Measured memory_bytes: 1200
#include <stdio.h>
#include <math.h>
int main(void){
  long int n,k,h[100101],dp[100101];
  dp[0]=0;
  scanf("%ld%ld",&n,&k);
  int i,j;
  for(i=0;i<n;i++){
    scanf("%ld",&h[i]);
  }
  for(i=1;i<100101;i++) dp[i]=1E9;
  
  for(i=0;i<n;i++){
    for(j=1;j<=k;j++){
      dp[i+j]=fmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
    }
  }
  printf("%ld",dp[n-1]);
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  
  int sum = 0;
  
  for (int i = 0; i < S.size(); i++) {
    sum += S[i] - '0';
  }
  
  if (sum % 9) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3748
import java.util.*

fun main(args: Array<String>) = abc158d()

fun abc158d() {
    val s = readLine()!!
    val q = readLine()!!.toInt()

    val deque = ArrayDeque(s.toList())
    var reversed = false

    for (i in 1..q) {
        val t = readLine()!!.split(' ')
        when (t[0].toInt()) {
            1 -> reversed = !reversed
            else -> {
                val f = t[1].toInt()
                val c = t[2][0]
                if ((f == 1) == !reversed) deque.addFirst(c) else deque.addLast(c)
            }
        }
    }

    val answer = (if (reversed) deque.reversed() else deque).joinToString("")

    println(answer)
}


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

int n,k;
int d[10];
bool ok(int x){
    bool okk=true;
    while(x){
        int m=x%10;
        rep(i,k){
            if(m==d[i])okk=false;
        }
        x/=10;
    }
    return okk;
}

signed main(){
    cin>>n>>k;
    rep(i,k)cin>>d[i];
    while(!ok(n))n++;
    cout<<n<<endl;
}

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;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<P> p(n);
    rep(i, n) cin >> p[i].first >> p[i].second;
    vector<bool> zoro(n, false);
    rep(i, n) {
        if (p[i].first == p[i].second) zoro[i] = true;
    }
    for (int i = 2; i < n; i++) {
        if (zoro[i] && zoro[i-1] && zoro[i-2]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3628
def main():
    N=int(input())
    S=input()
    ans=S.count('R')*S.count('G')*S.count('B')
    for i in range(N):
        for d in range(N):
            j = i+d
            k = j+d
            if k >= N:
                break
            if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
                ans-=1
    print(ans)
main()


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

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < 3; i++) {
    if (s[i] == '1')
      s[i] = '9';
    else if (s[i] == '9')
      s[i] = '1';
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
  	cin >> n;
  	int a[n];
  	for(int i = 0 ; i < n ; i++)
    {
		cin >> a[i];
    }
  	int ans = 0;
  	for(int i = 1; i < n - 1 ; i++){
		if( a[i] < a[i+1] && a[i] > a[i - 1] || (a[i] < a[i - 1] && a[i] > a[i + 1]))
          	ans++;
    }
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

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

    
    vector<int> count(101000);
    rep(i,n){
        int a;
        cin >> a;
        count[a]++;
    }

    int ans = 0;
    if(n > 2)for(int i = 0; i <= 100000; ++i) ans = max(ans,count[i] + count[i + 1] + count[i + 2]);
    else ans = *max_element(count.begin(),count.end());
    print(ans);
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  int N;
  vector<vector<int>> memo{};
  Tmp(int N): N(N){};
  void rec(vector<int>& vc, int n) {
    if (n == N+1) {
      memo.push_back(vc);
      return;
    }
    int inf = 1;
    if (!vc.empty()) {
      auto max = *boost::max_element(vc);
      inf = std::min(max+1, n) + 1;
    }
    for (int i = 0; i < inf; ++i) {
      vc.push_back(i);
      rec(vc, n+1);
      vc.pop_back();
    }
  }
};

void solve(void)
{
  int N; cin >> N;
  Tmp t(N);
  vector<int> tmp{};
  t.rec(tmp, 1);
  for (const auto& m : t.memo) {
    std::string s;
    for (const auto& k : m) {
      s += ('a' + k);
    }
    cout << s << CRLF;
  }
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 9776
import java.io.PrintWriter
import java.util.*

val pw = PrintWriter(System.out)
val sc = Scanner(System.`in`)

fun main(args: Array<String>) {
    val n = sc.nextInt()
    val a = Array(n){sc.nextInt()}.toList()
    val q = sc.nextInt()
    val m = Array(q){sc.nextInt()}.toList()
    abc000a(n,a,q,m)
}

fun abc000a(n:Int, a:List<Int>, q:Int, m:List<Int>) {
    fun solve (i:Int, l:Int): Boolean {
        if (l==0) return true
        if (i >= n) return false
        return solve(i+1, l) || solve(i+1, l-a[i])
    }

    for(j in 0 until q){
        if(solve(0, m[j])) println("yes") else println("no")
    }
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextListOfString() = next().split(" ")
fun nextListOfInt() = nextListOfString().map { it.toInt() }
fun nextListOfLong() = nextListOfString().map { it.toLong() }
fun nextListOfDouble() = nextListOfString().map { it.toDouble() }




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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  ll n;
  cin >> n;
  cout << n * (n - 1) / 2 << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 256
import sys
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, sqrt, cos, sin, pi
from operator import itemgetter
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]

N = ri()
A = sorted(ri_())
B = sorted(ri_())
C = sorted(ri_())
ans = 0
for i in range(N):
    ans += bisect_left(A, B[i]) * (N - bisect_right(C, B[i]))
print(ans)

Measured memory_bytes: 118932
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((a<b)&&(b<c)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}



Measured memory_bytes: 3084
#pragma GCC target ("avx2") 
#pragma GCC optimization ("O3") 
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define fast_az_fuk ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long 
#define int ll 
#define ull unsigned ll
#define ld long double 
#define pb push_back 
#define pf push_front
#define dll deque<ll> 
#define vll vector<ll> 
#define pll pair<ll,ll> 
#define mapll map<ll,ll>
#define endl "\n" 
#define all(v) v.begin(),v.end() 
#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;
void swap(auto*,auto*);
int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast_az_fuk
    ll n; cin>>n;
    ll c=0; std::vector<pll> v;
    for(ll i=0;i<n;i++){
        ll a,b; cin>>a>>b; v.pb({a,b});
    }
    bool flag=0;
    for(ll i=0;i<n;i++){
        if(c>0&&v[i].first!=v[i].second) {c=0; continue;}
        if(v[i].first==v[i].second) c++;
        if(c==3) {flag=1; break;}
    }
    if(flag) cout<<"Yes"; else cout<<"No";
    return 0;
}
void swap(auto &a,auto &b)
{
    auto temp=a; a=b; b=temp;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n;
	std::set<std::vector<int>> st;
	for(int i = 0; i < n; i++) {
		std::vector<int> vec(3);
		for(int j = 0; j < 3; j++) cin >> vec[j];
		sort(begin(vec), end(vec));
		
		st.insert(vec);
	}
	
	cout << n - st.size() << endl;
	return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
const long long MAXN = 1e6+5;
long long fact[MAXN];
long long dp[1005][1005];
long long inv[MAXN];
long long factinv[MAXN];
long long powe(long long x,long long y){
    long long z = 1;
   
    while(y>0){
        if(y%2 == 1){
            z*=x;
            z%=MOD;
        }
        x=x*x;
        x%=MOD;
        y/=2;
    }
    
    return z%MOD;
}
long long C(long long n,long long k){
    //cout<<(1LL*fact[k]*fact[n-k])%MOD<<endl;
    if (k < 0 || n < k) return 0;
    return ((1LL*(1LL*fact[n]*factinv[k])%MOD)*factinv[n-k])%MOD;
}
int main() {
    long long n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    fact[0] = 1;
    fact[1] = 1;
    inv[1] = 1;
    factinv[0] = 1;
    factinv[1] = 1;
    for(long long i=2;i<=n;i++){
        fact[i] = fact[i-1]*i;
        fact[i]%=MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        inv[i]%=MOD;
        factinv[i] = factinv[i-1]*inv[i];
        factinv[i]%=MOD;
    }
    dp[a-1][0] = 1;
    
    for(long long i=a;i<=b;i++){
        for(long long j=0;j<=n;j++){
            dp[i][j] = dp[i-1][j];
            for(long long k=c;k<=d;k++){
                if(j<(i*k)){
                    break;
                }
                
                long long val = 1LL*dp[i-1][j-(1LL*i*k)]*C(j,1LL*i*k);
                
                val%=MOD;
                 val*=1LL*fact[k*i];
               
                val%=MOD;
                
                val*=1LL*((powe(factinv[i],k)%MOD)*factinv[k])%MOD;
                val%=MOD;
                
                dp[i][j] += val;
                dp[i][j]%=MOD;
                
               
               
                
            }
           // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
        }
    }
    cout<<dp[b][n]<<endl;
}

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

int main()
{
	double a,b,c,d,e,f;
	double x,y;
	while(cin>>a>>b>>c>>d>>e>>f)
	{
		y=(c*d-a*f)/(b*d-a*e);
		x=(c-(b*y))/a;
		printf("%.3f %.3f\n",x,y);
	}
	return 0;
}


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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n;
    cin >>n;
    vector<int>a;
    vector<int>dif;

    for (int i = 0; i < n; i++){
        int ai;
        cin>>ai;

        if(i!=0 && ai ==a.back())continue;
        a.eb(ai);

        int s=a.size();
        if(s>1){
            if(a[s-2] < a[s-1])dif.eb(1);
            else dif.eb(-1);
        }
    }

    /*

    bool skip=false;
    for (int i = 1; i < n-1; i++){
        if(!skip && dif[i-1]!=dif[i]){
            ++ans;
            skip=true;
            continue;
        }
        skip=false;
    }
    if(skip)++ans;

    */

    int i=0,l=a.size();
    while (i<l){
        ans++;

        if(i<l-1 && a[i]<a[i+1])while (a[i] < a[i+1] && i<n-1)i++;
        else while (a[i] > a[i+1] && i<n-1)i++;

        ++i;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define MAX_N 100000
using namespace std;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n;
vector <int> v;
char s[MAX_N+5];
int main() {
	scanf("%s", s+1);
	n = (int)strlen(s+1);
	if (s[1] == '0') return puts("-1"), 0;
	if (s[n] == '1') return puts("-1"), 0;
	for (int i = 1; i <= n/2; i++)
		if (s[i] ^ s[n-i]) return puts("-1"), 0;
	v.push_back(1);
	for (int i = 2; i < n; i++)
		if (s[i] == '0') v.push_back(i);
		else {
			for (int j : v)
				printf("%d %d\n", j, i);
			v.clear(), v.push_back(i);
		}
	for (int i : v)
		printf("%d %d\n", i, n);
	return 0;
}

Measured memory_bytes: 2040
from collections import defaultdict

N = int(input())

top_end = defaultdict(int)

ans = 0
for i in range(1, N + 1):
    stri = str(i)
    ans += top_end[(stri[-1], stri[0])] * 2
    top_end[(stri[0], stri[-1])] += 1
    if stri[0] == stri[-1]:
        ans += 1

print(ans)

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

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

constexpr ll INF = 1e15;

constexpr ll mod = 1e9 + 7;

template<typename T>
void cmpmax(T& reference, T value) {
	reference = max(reference, value);
}

template<typename T>
void cmpmin(T& reference, T value) {
	reference = min(reference, value);
}

int main() {
	int n;
	cin >> n;
	vector<int> as(n);
	vector<int> counts(4, 0);
	rep(i, n) {
		cin >> as[i];
		counts[as[i]]++;
	}

	vector<vector<vector<double>>> dp(n + 1, vector<vector<double>>(n + 1, vector<double>(n+1, -1)));
	
	//dp[i][j][k]...1枚の皿がi個、2枚の皿がj個、3枚の皿がk個のときに、必要な手数の期待値
	//dp[i][j][k] = (n-i-j-k) / n * dp[i][j][k] + i / n * dp[i-1][j][k] + j / n * dp[i+1][j-1][k] + k / n * dp[i][j+1][k-1] + 1
	//(i+j+k)/n * dp[i][j][k] = i / n * dp[i-1][j][k] + j / n * dp[i+1][j-1][k] + k / n * dp[i][j+1][k-1] + 1

	dp[0][0][0] = 0;
	const double dn = n;
	rep(k, counts[3] + 1) {
		rep(j, n + 1) {
			rep(i, n + 1) {
				if (i == 0 && j == 0 && k == 0) continue;
				double right = dn;
				if (i > 0) right += i * dp[i - 1][j][k];
				if (j > 0 && i < n) right += j * dp[i + 1][j - 1][k];
				if (k > 0 && j < n) right += k * dp[i][j + 1][k - 1];
				right *= 1.0 / (i + j + k);
				dp[i][j][k] = right;
			}
		}
	}
	cout << setprecision(10) << dp[counts[1]][counts[2]][counts[3]] << endl;
	return 0;
}


Measured memory_bytes: 216832
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e9
#define N 600010
using namespace std;

main(){
    int h,w;
    cin>>h>>w;
    int a[600][600];
    rep(i,h)rep(j,w)cin>>a[i][j];
    int b[600][600];
    rep(i,h)rep(j,w)b[i][j]=a[i][j];
    int count=0;
    rep(i,h)rep(j,w){
        if(j!=w-1){
            if(b[i][j]%2){
                count++;
                b[i][j+1]++;
            }
        }
        else if(b[i][j]%2&&i!=h-1){
            count++;
            b[i+1][j]++;
        }
    }
    cout<<count<<endl;
    rep(i,h)rep(j,w){
        if(j!=w-1){
            if(a[i][j]%2){
                printf("%d %d %d %d\n",i+1,j+1,i+1,j+2);
                a[i][j+1]++;
            }
        }
        else if(a[i][j]%2&&i!=h-1){
            printf("%d %d %d %d\n",i+1,j+1,i+2,j+1);
            a[i+1][j]++;
        }
    }
    return 0;
}


Measured memory_bytes: 4736
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

vector<int> Z_algorithm(string S) {
	int c = 0, n = S.length();
	vector<int> Z(n, 0);
	for (int i = 1; i < n; i++) {
		int l = i - c;
		if (i + Z[l] < c + Z[c]) {
			Z[i] = Z[l];
		}
		else {
			int j = max(0, c + Z[c] - i);
			while (i + j < n && S[j] == S[i + j])j++;
			Z[i] = j;
			c = i;
		}
	}

	Z[0] = n;
	return Z;
}


int main() {
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	for (int beg = 0; beg < N - 1; beg++) {
		string tmp = S.substr(beg);
		auto ret = Z_algorithm(tmp);
		for (int j = 1; j < ret.size(); j++) {
			if (ret[j] <= j)ans = max(ans, ret[j]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    k = int(readline())
    a, b = list(map(int, readline().split()))
    for i in range(a, b + 1):
        if i % k == 0:
            print("OK")
            exit()
    print("NG")


if __name__ == '__main__':
    solve()


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

public class Main {

  void solve(InputReader in, PrintWriter out) {
    int n = in.nextInt();
    int k = in.nextInt();
    int[] arr = new int[n];
    for (int i = 0; i < n; ++i)
      arr[i] = in.nextInt();
    boolean[] wins = new boolean[k + 1];
    for (int i = 1; i <= k; ++i) {
      for (int move : arr) {
        if (i - move >= 0) {
          wins[i] |= !wins[i - move];
        }
      }
    }
    out.println(wins[k] ? "First" : "Second");
  }

  public static void main(String[] args) throws Exception {
    InputReader in = new InputReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    Main solver = new Main();
    solver.solve(in, out);
    out.close();
  }

  static class InputReader {
    BufferedReader in;
    StringTokenizer st;

    public InputReader(InputStream is) {
      in = new BufferedReader(new InputStreamReader(is));
    }

    public String next() {
      try {
        while (st == null || !st.hasMoreTokens()) {
          st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }

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

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


Measured memory_bytes: 25044