akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
const int MOD = 1000000007,MAX = 510000;
long int pow107 = (int)pow(10, 9) + 7,llimit = LONG_MAX,fac[MAX], finv[MAX], inv[MAX];
int ilimit = INT_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 int COM(long int n,long int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//階乗factorial
//コンビネーションFunc2
//コンビネーションCOMinit(),COM(n,m)

int main(){
    int n , m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

int main() {
  while( true ) {
    int n, m;
    string input;
    cin >> n;
    if ( n == 0 ) break;
    cin >> m >> input;
    int sum = 0;
    int token_size = -1;
    char before = 'A'; //random
    for ( char ch : input ) {
      if ( ch == 'I' ) {
	if ( before == 'O' ) {
	  token_size++;
	} else {
	  sum += max( 0, token_size - n + 1 );
	  token_size = 0;
	}
      } else {
	if ( before == 'O' ) {
	  sum += max( 0, token_size - n + 1 );
	  token_size = -1;
	}
      }
      before = ch;
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 2108
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

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

#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define vi vector<int>
#define vb vector<bool>
#define vll vector<ll>
#define vii vector<pii>
#define vvi vector<vector<int>>
#define vvii vector<vector<pii>>
#define vvll vector<vector<ll>>
#define umap unordered_map
#define uset unordered_set
#ifdef LOCAL
#define debug(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define debugrep(i, a, b) for (int i = a; i < b; i++)
#define check(...) assert(__VA_ARGS__)
#else
#define debug(fmt, ...)
#define debugrep(i, a, b)
#define check(...)
#endif

const int INF = INT_MAX / 2;

int n, m, x;
vi c;
vvi a;

int dfs(int which, vi &level, int finished) {
    if (which >= n) {
        if (finished == m) {
            return 0;
        } else {
            return INF;
        }
    }
    int ans = dfs(which + 1, level, finished);
    rep(i, 0, m) {
        if (level[i] < x && level[i] + a[which][i] >= x) {
            finished++;
        }
        level[i] += a[which][i];
    }
    ans = min(ans, c[which] + dfs(which + 1, level, finished));
    rep(i, 0, m) {
        level[i] -= a[which][i];
    }
    return ans;
}

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

    cin >> n >> m >> x;
    c = vi(n);
    a = vvi(n, vi(m));
    rep(i, 0, n) {
        cin >> c[i];
        rep(j, 0, m) {
            cin >> a[i][j];
        }
    }
    auto levels = vi(m, 0);
    int ans = dfs(0, levels, 0);
    cout << (ans == INF ? -1 : ans);
}


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

char M[1000][1000];
int d[1000][1000];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
int H, W;
const int INF = 1001001001;
queue<pair<int, int> > Q;
int ans = 0;

void bfs(){
    while(!Q.empty()){
        pair<int, int> p = Q.front(); Q.pop();
        int i = p.first;
        int j = p.second;
        rep(k, 4){
            int yn = i+dy[k];
            int xn = j+dx[k];
            if(yn >= 0 && yn < H && xn >= 0 && xn < W){
                if(M[yn][xn] == '#'){
                    continue;
                } else if(d[yn][xn] == INF){
                    Q.push(make_pair(yn, xn));
                    d[yn][xn] = d[i][j] + 1;
                    ans = max(ans, d[yn][xn]);
                }
            }
        }
    }

    return;
}

int main() {
    cin >> H >> W;
    rep(i, H){
        rep(j, W){
            cin >> M[i][j];
            d[i][j] = INF;
            if(M[i][j] == '#'){
                Q.push(make_pair(i, j));
                d[i][j] = 0;
            }
        }
    }

    bfs();

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 16316
import heapq

heap = []
N, K = [int(i) for i in input().split()]
for _ in range(N):
    a, b = [int(i) for i in input().split()]
    heapq.heappush(heap, (a, b))

k = 0
for _ in range(N):
    a, b = heapq.heappop(heap)
    if k + b < K:
        k += b
    else:
        print(a)
        break


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

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> D(10);
  int d;
  for (int i = 0; i < K; i++)
  {
    cin >> d;
    D[d] = 1;
  }

  for (;; N++)
  {
    int c = N;
    while (c && !D[c % 10])
      c /= 10;

    if (c == 0)
      break;
  }
  cout << N << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
class UnionFind {
private:
    vector<int> par;
    vector<int> sizes;
public:
    UnionFind(int n): par(n), sizes(n, 1) {
        for (int i = 0; i < n; i++) par[i] = i;
    }
    ~UnionFind() = default;
    int find(int x) {
        return x == par[x] ? x : find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (sizes[x] < sizes[y]) swap(x, y);
        par[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return sizes[find(x)];
    }
};
int main() {
    int n, q;
    cin >> n >> q;
    UnionFind uf(n);
    for (int i = 0; i < q; i++) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) uf.unite(u, v);
        else if (t == 1) cout << uf.same(u, v) << endl;
    }
}


Measured memory_bytes: 4736
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        Task task = new Task();
        task.solve(sc, out);
        out.flush();
        sc.close();
    }
    static class Task{
        public void solve(Scanner sc, PrintWriter out){
            int first = nint(sc);
            int last = nint(sc);
            int count=0;
            for (int i = first; i <= last; i++){
                String num = String.valueOf(i);
                int strLength = num.length();
                boolean circle = true;
                for (int j=0; j<strLength/2; j++){
                    if (num.charAt(j) != num.charAt(strLength-j-1)){
                        circle = false;
                    }
                }
                if (circle){
                    count++;
                }
            }
            out.println(count);
        }
    }

    static int nint(Scanner sc){
        return Integer.parseInt(sc.next());
    }
    static long nlong(Scanner sc){
        return Long.parseLong(sc.next());
    }
    static double ndouble(Scanner sc){
        return Double.parseDouble(sc.next());
    }
    static float nfloat(Scanner sc){
        return Float.parseFloat(sc.next());
    }
    static String nstr(Scanner sc){
        return  String.valueOf(sc.next());
    }
    static long[] longLine(Scanner sc, int size){
        long[] lLine = new long[size];
        for (int i = 0; i < size; i++) {
            lLine[i] = nlong(sc);
        }
        return lLine;
    }
    static int[] intLine(Scanner sc, int size){
        int[] iLine = new int[size];
        for (int i = 0; i < size; i++) {
            iLine[i] = nint(sc);
        }
        return iLine;
    }
    static String[] strLine(Scanner sc, int size){
        String[] strLine = new String[size];
        for (int i = 0; i < size; i++) {
            strLine[i] = nstr(sc);
        }
        return strLine;
    }
}

Measured memory_bytes: 27168
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

const ll INF = 1LL << 60;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> S(A);
    for (auto& s : S) {
        cin >> s;
    }
    vector<ll> T(B);
    for (auto& t : T) {
        cin >> t;
    }
    ll X;
    rep(_, 0, Q) {
        cin >> X;
        int idx1 = lower_bound(all(S), X) - S.begin();
        int idx2 = lower_bound(all(T), X) - T.begin();
        vector<ll> candidate1, candidate2;
        rep(i, -1, 2) {
            if (idx1 + i >= 0 && idx1 + i < A) {
                candidate1.push_back(idx1 + i);
            }
            if (idx2 + i >= 0 && idx2 + i < B) {
                candidate2.push_back(idx2 + i);
            }
        }
        ll ans = INF;
        for (auto& i : candidate1) for (auto& j : candidate2) {
            chmin(ans, abs(X - S[i]) + abs(S[i] - T[j]));
            chmin(ans, abs(X - T[j]) + abs(S[i] - T[j]));
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

using ll = long long;

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

    int x, max_p = 1;

    cin >> x;
    for (int b = 2; b * b <= x; ++b) {
        int tmp_b = b;
        while (b * tmp_b <= x) tmp_b *= b;
        max_p = max(max_p, tmp_b);
    }

    cout << max_p << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a,c;
	char b;
	scanf("%d",&a);
	while(1){
		scanf("%c",&b);
		if(b=='+'){
			scanf("%d",&c);
			a+=c;
		}
		if(b=='-'){
			scanf("%d",&c);
			a-=c;
		}
		if(b=='*'){
			scanf("%d",&c);
			a=a*c;
		}
		if(b=='/'){
			scanf("%d",&c);
			a=a/c;
		}
		if(b=='='){
			printf("%d\n",a);
			
				return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#define mod 998244353
#define max(a,b) ((a)>(b)?(a):(b))
struct interval{
    int l,r;
}a[200003];
long long f[200003]={0,1},s[200003]={0,1};
int n,k;
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=k;i++) scanf("%d%d",&a[i].l,&a[i].r);
    for(int i=2;i<=n;i++){
        for(int j=1;j<=k;j++){
            if(i>a[j].l) f[i]=(f[i]+(s[i-a[j].l]-s[max(i-a[j].r-1,0)])%mod)%mod;
        }
        s[i]=(s[i-1]+f[i])%mod;
    }
    printf("%lld\n",(f[n]+mod)%mod);
    return 0;
}

Measured memory_bytes: 4828
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define ns first
#define ew second

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int N = 4;

string rank = "23456789TJQKA";

int main(void){
    for(char tarSuit; cin >> tarSuit, tarSuit != '#';){
        pii res = mp(0, 0);
        int winner = 0;

        vector<vs> in(13, vs(N));
        rep(i, N){
            rep(j, 13){
                cin >> in[j][i];
            }
        }

        rep(i, 13){
            int maxr = 0;

            vs cards = in[i];
            char tableSuit = cards[winner].at(1);

            rep(j, N){
                string card = cards[j];

                char suit = card.at(1);
                int r = rank.find(card.at(0));

                if(suit == tarSuit) r += 26;
                else if(suit == tableSuit) r += 13;

                if(maxr < r){
                    maxr = r;
                    winner = j;
                }
            }

            if(winner % 2 == 0) res.ns++;
            else res.ew++;
        }

        if(res.ns < res.ew) cout << "EW " << res.ew - 6 << endl;
        else                cout << "NS " << res.ns - 6 << endl;
    }

	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;

int main(){
    int n, W;
    cin >> n >> W;
    vector<long long> w(n), v(n);
    for (int i = 0; i < n; i++) cin >> w[i] >> v[i];

    long long sum_value = 0;
    for (int x : v) sum_value += x;
    //vector<long long> dp(sum_value + 1,INF);
    //long long dp[n][sum_value + 1];
    //for (int i = 0; i < n; i++) for (int j = 0; j <= sum_value; j++) dp[i][j] = INF;
    //for (int i = 0; i <= sum_value; i++) dp[0][i] = 0;
    //dp[0][0] = 0;
    //dp[0][v[0]] = w[0];
    vector<long long> dp(sum_value + 1, INF);
    dp[0] = 0;

    for (int i = 0; i < n; i++){
        for (int j = sum_value - v[i]; j >= 0; j--){
                /*
            dp[i][j] = min(dp[i][j], dp[i -1][j]);
            if (j - v[i] >= 0)
                dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
            */
             dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
        }
    }
    //cout << dp[1][6] << endl;
    for (int i = sum_value; i >= 0; i--) //cout << dp[n - 1][i] << " ";
    if (dp[i] <= W) {
        cout << i << " ";
        break;
    }

}


Measured memory_bytes: 1024
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            bool Ans = true;

            var N = int.Parse(System.Console.ReadLine());

            var Word = new string[N + 1];
            var Wordlength = new int[N + 1];
            var WordF = new string[N + 1];
            var WordE = new string[N + 1];

            for (int h = 1; h <= N; h++)
            {

                Word[h] = Console.ReadLine();
                Wordlength[h] = Word[h].Length;
                WordF[h] = Word[h].Substring(0, 1);
                WordE[h] = Word[h].Substring(Wordlength[h] - 1);

                if (h >= 2)
                {
                    if (WordE[h - 1] != WordF[h])
                    {
                        Ans = false;
                    }
                }
            }

            for (int i = 1; i <= N; i++)
            {
                for (int j = 1; j <= N; j++)
                {
                    if (i != j)
                    {
                        if (Word[i] == Word[j])
                        {
                            Ans = false;

                        }
                    }
                }
            }

            if (Ans == true)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

int main() {
  vector<vector<int>> A(3, vector<int>(3));
  for (int i=0; i<3; i++) {
    for (int j=0; j<3; j++) cin >> A.at(i).at(j);
  }
  int N;
  cin >> N;
  vector<int> b(N);
  for (int i=0; i<N; i++) cin >> b.at(i);
  bool same1_1=false, same1_2=false, same1_3=false, same2_1=false, same2_2=false, same2_3=false, same3_1=false, same3_2=false, same3_3=false;
  for (int i=0; i<N; i++) {
    if ((!same1_1)&&b.at(i)==A.at(0).at(0)) same1_1 = true;
    else if ((!same1_2)&&b.at(i)==A.at(0).at(1)) same1_2 = true;
    else if ((!same1_3)&&b.at(i)==A.at(0).at(2)) same1_3 = true;
    else if ((!same2_1)&&b.at(i)==A.at(1).at(0)) same2_1 = true;
    else if ((!same2_2)&&b.at(i)==A.at(1).at(1)) same2_2 = true;
    else if ((!same2_3)&&b.at(i)==A.at(1).at(2)) same2_3 = true;
    else if ((!same3_1)&&b.at(i)==A.at(2).at(0)) same3_1 = true;
    else if ((!same3_2)&&b.at(i)==A.at(2).at(1)) same3_2 = true;
    else if ((!same3_3)&&b.at(i)==A.at(2).at(2)) same3_3 = true;
  }
  bool bingo = false;
  if (same1_1&&same1_2&&same1_3) bingo = true;
  else if (same2_1&&same2_2&&same2_3) bingo = true;
  else if (same3_1&&same3_2&&same3_3) bingo = true;
  else if (same1_1&&same2_1&&same3_1) bingo = true;
  else if (same1_2&&same2_2&&same3_2) bingo = true;
  else if (same1_3&&same2_3&&same3_3) bingo = true;
  else if (same1_1&&same2_2&&same3_3) bingo = true;
  else if (same1_3&&same2_2&&same3_1) bingo = true;
  if (bingo) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
a = 0
for x in range(1, N+1,2):
    b = 0
    for i in range(1, x+1):
        if x%i == 0:
            b += 1
        else:
            pass
    if b == 8:
        a += 1
    else:
        pass
print(a)

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

int main(int argc, char *argv[]) {
  int x, a;
  cin >> x >> a;
  
  if (x < a) {
    cout << 0 << endl;
  } else {
    cout << 10 << endl;
  }
  
  return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
#if DEBUG
            ReadLine();
#endif
        }

        void Solve(ConsoleInput cin)
        {
            int c = (int)cin.Read[0];
            c++;

            Console.WriteLine((char)c);
        }

        class Magic
        {
            public int damage { get; set; }
            public int mp { get; set; }
        }
        class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;

            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }

            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }

            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

Measured memory_bytes: 13268
//
//  main.cpp
//  ProgrammingContestChallengeBook2
//
//  Created by Hisaki Kobayashi on 2020/04/04.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string>
#include <bits/stdc++.h>
#include <stdlib.h>
//#include "mylibrary.hpp"



using namespace std;

int main(){
    int N;
    int i;
    vector<int> A;
    cin >> N;
    for(i=0;i<N;i++){
        int temp; cin >> temp;
        A.push_back(temp);
    }
    
    bool ANS=true;
    for(i=0;i<N;i++){
        if(A.at(i)%2==1) continue;
        if(A.at(i)%2==0){
            if(A.at(i)%3==0 || A.at(i)%5==0){
                continue;
            }else{
                ANS = false;
                break;
            }
        }
    }
    if(ANS){
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }
    return 0;
 
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    if len(s) < 26:
        for c in string.ascii_lowercase:
            if c not in s:
                return s + c
    if s == ''.join([c for c in string.ascii_lowercase][::-1]):
        return -1
    for i in range(25,-1,-1):
        c = s[i]
        if max([_ for _ in s[i:]]) == c:
            continue
        t = [_ for _ in s[i:]]
        t.sort()
        ci = t.index(c)
        return s[:i] + t[ci+1]


print(main())




Measured memory_bytes: 6476
import java.util.*;

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

        String n = sc.next();
        int len = n.length();

        String[] arr = new String[len];
        for (int i=0; i<len; i++) arr[i] = n.substring(i, i+1);

        long[][] dp = new long[len+1][2];
        dp[0][0] = 0;
        dp[0][1] = 1;
        
        for (int i=1; i<len+1; i++){
            int tmp = Integer.parseInt(arr[i-1]);

            dp[i][0] = Math.min(dp[i-1][0]+tmp, dp[i-1][1]+10-tmp);
            dp[i][1] = Math.min(dp[i-1][0]+tmp+1, dp[i-1][1]+9-tmp);
        }

        System.out.println(dp[len][0]);
    }
}


Measured memory_bytes: 163868
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <cmath>
#include <climits>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)

int main() {
	double dp[1<<12][12];
	double calc[16][32];
	rep(i,16) {
		rep2(j,i,32) {
			calc[i][j] = sqrt(j*j-i*i);
		}
	}
	int len, tmp;
	string s;
	while(getline(cin, s)) {
		stringstream ss(s);		
		vector<int> v;
		ss >> len;
		while(ss >> tmp) v.push_back(tmp);
		int n = v.size();
		rep(i,1<<12) {
			rep(j,12) {
				dp[i][j] = INT_MAX;
			}
		}
		rep(i,n) {
			dp[1<<i][i] = v[i];
		}
		rep(i,(1<<n)) {
			rep(j,n) {
				if(!(i&(1<<j))) continue;
				rep(k,n) {
					if(i&(1<<k)) continue;
					int a = abs(v[k]-v[j]);
					dp[i|1<<k][k] = min(dp[i|1<<k][k], dp[i][j]+calc[a][v[k]+v[j]]);
				}
			}
		}
		bool f = 1;
		rep(i,n) {
			if(dp[(1<<n)-1][i] + v[i] <= len) {
				cout << "OK" << endl;
				f = 0;
				break;
			}
		}
		if(f) cout << "NA" << endl;
	}	
	return 0;
}

Measured memory_bytes: 1624
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
static string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
static int v = int.Parse(input[0]);
static int e = int.Parse(input[1]);
static List<int>[] nextList = new List<int>[v];
static bool[] checkedVertex = new bool[v];//頂点を確認済みか？
static int timer = 0;
static int[] prenum = new int[v];
static int[] lowest = new int[v];
static int[] parent = new int[v];
static List<int> answers = new List<int>();

	static void Main()
	{
    for(long i = 0; i < v; i++) nextList[i] = new List<int>();//リストの宣言
  
    for(int i = 0; i < e; i++)
    {
      string[] inputa = Console.ReadLine().Split(' ');
      int a = int.Parse(inputa[0]);
      int b = int.Parse(inputa[1]);
      nextList[a].Add(b);
      nextList[b].Add(a);
    }
    ArticulationPoints();
	}

  static void ArticulationPoints()//関節点を求める
  {
    for(int i = 0; i < v; i++) checkedVertex[i] = false;
    timer = 1;
    DFS(0,-1);//深さ優先探索

    int np = 0;
    for(int i = 1; i < v; i++)
    {
      if(parent[i] == 0) np++;
      else if(prenum[parent[i]] <= lowest[i]) answers.Add(parent[i]);
    }
    if(np > 1) answers.Add(0);

    var memo = answers.Distinct().ToArray();
    Array.Sort(memo);//ソートして重複を除く
    
    var answerText = new StringBuilder();//解答の出力
    for(int i = 0; i < memo.Length; i++)
    {
      answerText.AppendLine(memo[i].ToString());
    }
    Console.Write(answerText);
  }

  static void DFS(int current, int prev)
  {
    prenum[current] = timer;
    lowest[current] = timer;
    timer++;

    checkedVertex[current] = true;
    int nextVertex = 0;

    for(int i = 0; i < nextList[current].Count(); i++)
    {
      nextVertex = nextList[current][i];
      if(!checkedVertex[nextVertex])
      {
        parent[nextVertex] = current;
        DFS(nextVertex, current);
        lowest[current] = Math.Min(lowest[current], lowest[nextVertex]);
      }else if(nextVertex != prev)
      {
        lowest[current] = Math.Min(lowest[current], prenum[nextVertex]);
      }
    }
  }
  
}


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

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

#define ll long long int
#define mp make_pair
#define pb push_back
#define MOD 1000000007

bool isvowel(char c)
{
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        return true;
        return false;
}
ll isprime(ll n)
{
    ll ans=1;
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            ans = i;
    }
    return ans;
}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    if(b==1)
        return a%m;
    ll temp=power(a,b/2,m);
    if(b%2==0)
        return ((temp%m)*(temp%m))%m;
    else
        return ((((temp%m)*(temp%m))%m)*a%m)%m;
}

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

ll c(ll n, ll k)
{
    ll C[n + 1][k + 1];
    ll i, j;

    for (i = 0; i <= n; i++)
    {
        for (j = 0; j <= min(i, k); j++)
        {

            if (j == 0 || j == i)
                C[i][j] = 1;

            else
                C[i][j] = (C[i - 1][j - 1]%MOD +
                          C[i - 1][j])%MOD;
        }
    }
    return C[n][k]%MOD;
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {

        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;


        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;

    return x;
}
ll func(ll n)
{
    ll ans=0;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            if(i/10==0)
                ans+=1+func(i)*func(n/i);
            else
                ans+=func(i)*func(n/i);
        }
    }
    return ans;
}
ll dp[2001][2001];
ll check(vector<pair<ll,ll> >v,ll l,ll r,ll i)
{ 
   //cout<<l<<" "<<r<<endl;
   if(l>r)
    return 0; 
   if(dp[l][r]!=-1)
    return dp[l][r]; 
   ll ans=0;
   ll p1=v[i].first;
   ll p2=v[i].second;
   ans=max(p1*(p2-l)+check(v,l+1,r,i+1),p1*(r-p2)+check(v,l,r-1,i+1));
   return dp[l][r]=ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    //freopen("1.txt","rt",stdin);
    //freopen("output.txt","wwt",stdout);

    ll t;
    t=1;
    //cin>>t;
    //ll t1=0;
    while(t--)
    {
      ll n,x,y;
      cin>>n>>x>>y;
      map<ll,ll>m;
      for(ll i=1;i<n;i++)
      {
          for(ll j=i+1;j<=n;j++)
          {
              //cout<<i<<" "<<j<<" ";
              ll p=min(j-i,abs(j-y)+abs(x-i)+1);
              //cout<<p<<endl;
              m[p]++;
          }
      }
      for(ll i=1;i<n;i++)
       cout<<m[i]<<endl;
    }
}


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

using namespace std;

//#define FILE_IO

typedef pair<int, int> pii;

const int mod = 1e9 + 7;

int N;
pii cpy[200005];
int lft[200005], rgt[200005];
int dp[200005], sum[200005];

int power(int x, int y)
{
    if(y <= 0)  return 1;
    int ans = power( (1LL * x * x) % mod, y >> 1 );
    if(y & 1) ans = (1LL * ans * x) % mod;
    return ans;
}

class Normalizator
{
public:
    map<int, int> mp;
    vector<int> ord;

    void add(int x) { if(mp.count(x)) return; mp[x]; ord.push_back(x); }
    void normalize()
    {
        sort(ord.begin(), ord.end());
        for(int i = 0; i < ord.size(); i++)
            mp[ ord[i] ] = i + 1;
    }
    int get(int x) { return mp[x]; }
}nrm;

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d", &N);
    for(int i = 1; i <= N; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        cpy[i] = {x, y};
        nrm.add(y);
    }
    nrm.normalize();
    sort(cpy + 1, cpy + N + 1);
    for(int i = 1; i <= N; i++)
        cpy[i].second = nrm.get(cpy[i].second);

    int mx = 0;
    for(int i = 1; i <= N; i++)
    {
        int y = cpy[i].second;
        mx = max(mx, y);
        rgt[i] = mx;
    }
    int mn = 1 << 30;
    for(int i = N; i >= 1; i--)
    {
        int y = cpy[i].second;
        mn = min(mn, y);
        lft[i] = mn;
    }

    dp[0] = 1;
    int ans = 0;
    int j = 1;
    for(int i = 1; i <= N; i++)
    {
        while(rgt[j] + 1 < lft[i])
            j++;

        dp[i] = (sum[i - 1] - sum[j - 1] + mod) % mod;
        if(lft[i] == 1) (dp[i] += 1) %= mod;
        if(rgt[i] == N) (ans += dp[i]) %= mod;

        sum[i] = (sum[i - 1] + dp[i]) % mod;
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 15092
import sys
read = sys.stdin.buffer.read
readlines = sys.stdin.buffer.readlines
input = sys.stdin.buffer.readline
H, W, K = map(int, input().split())
B = {}

for _ in range(K):
    r, c, v = map(int, input().split())
    B[(r-1,c-1)] = v

dp = [[0]*(W+1) for _ in range(4)]
 
for i in range(H):
    for j in range(W):
        if (i, j) in B:
            v = B[(i, j)]
            dp[0][j+1] = max(dp[0][j], dp[0][j+1], dp[1][j+1], dp[2][j+1], dp[3][j+1])
            dp[1][j+1] = max(dp[1][j], dp[0][j+1]+v)
            dp[2][j+1] = max(dp[2][j], dp[1][j]+v)
            dp[3][j+1] = max(dp[3][j], dp[2][j]+v)
        else:
            dp[0][j+1] = max(dp[0][j], dp[0][j+1], dp[1][j+1], dp[2][j+1], dp[3][j+1])
            dp[1][j+1] = dp[1][j]
            dp[2][j+1] = dp[2][j]
            dp[3][j+1] = dp[3][j]
print(max(dp[i][-1] for i in range(4)))

Measured memory_bytes: 110536
from bisect import bisect_right

def getINearests(ss, ts):
    iNearests = [-1] * len(ss)
    for iS, s in enumerate(ss):
        iT = bisect_right(ts, s)
        if iT == len(ts):
            iNearests[iS] = iT-1
        elif iT == 0:
            iNearests[iS] = 0
        else:
            d1 = abs(s - ts[iT-1])
            d2 = abs(s - ts[iT])
            if d1 <= d2:
                iNearests[iS] = iT-1
            else:
                iNearests[iS] = iT
    return iNearests


A, B, Q = map(int, input().split())
ss = [int(input()) for _ in range(A)]
ts = [int(input()) for _ in range(B)]
xs = [int(input()) for _ in range(Q)]

iTNearests = getINearests(ss, ts)
iSNearests = getINearests(ts, ss)

anss = [0] * Q
for iX, x in enumerate(xs):
    ans = float('inf')

    # 初手: 神社
    iS = bisect_right(ss, x)
    if iS > 0:
        cost = abs(x - ss[iS-1])
        cost += abs(ss[iS-1] - ts[iTNearests[iS-1]])
        ans = min(ans, cost)
    if iS < A:
        cost = abs(x - ss[iS])
        cost += abs(ss[iS] - ts[iTNearests[iS]])
        ans = min(ans, cost)

    # 初手: 寺
    iT = bisect_right(ts, x)
    if iT > 0:
        cost = abs(x - ts[iT-1])
        cost += abs(ts[iT-1] - ss[iSNearests[iT-1]])
        ans = min(ans, cost)
    if iT < B:
        cost = abs(x - ts[iT])
        cost += abs(ts[iT] - ss[iSNearests[iT]])
        ans = min(ans, cost)

    anss[iX] = ans

print('\n'.join(map(str, anss)))


Measured memory_bytes: 35028
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
const int mod= 1e+9+7;

int main() {
    ll N,M; cin>>N>>M;
    string S,T; cin>>S>>T;
    ll lcm=N/__gcd(N,M)*M;
    ll g=__gcd(N,M);

    /*vector<char>s(lcm,' ');
    vector<char>t(lcm,' ');
    ll cnts=0,cntt=0;
    rep(i,lcm){
        if(i%(lcm/N)==0&&cnts<=N-1){
            s[i]=S[cnts];
            cnts++;
        }
        if(i%(lcm/M)==0&&cntt<=M-1){
            t[i]=T[cntt];
            cntt++;
        }
         if(s[i]!=' '&&t[i]!=' '){
            if(s[i]!=t[i]){
                cout<<-1<<endl;
                return 0;
            }
        }
        if(cnts>=N&&cntt>=M)break;

    }
    cout<<lcm<<endl;*/
    for(int i=0,j=0;j<M;i+=N/g,j+=M/g){
        if(S[i]!=T[j]){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<lcm<<endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

ll M = 1000000007;

ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/2);
	ret *= ret; ret %= M;
	if(k%2 == 1){ ret *= x; ret %= M; }
	return ret;
}

ll inv(ll x){
	return modpow(x,M-2);
}

ll c[2][200010];
void mkseq(int t,ll x){
	c[t][0] = 1;
	for(int i = 0 ; i < x ; i ++){
		c[t][i+1] = c[t][i] * (x-i); c[t][i+1] %= M;
		c[t][i+1] *= inv(i+1); c[t][i+1] %= M;
	}
}

int main(){
	ll h,w,a,b;
	cin >> h >> w >> a >> b;
	
	mkseq(0,h-a+b-1);
	mkseq(1,w+a-b-1);
	
	ll ret = 0;
	int x = h-a , y = b+1;
	while(x > 0 && y <= w){
		ret += c[0][x-1]*c[1][h-x];
		ret %= M;
		x --;
		y ++;
	}
	
	cout << ret << endl;
}



Measured memory_bytes: 1792
module subprogram
	implicit none
contains
	subroutine heapsort(n,array)
	integer,intent(in) :: n
	integer(8),intent(inout) :: array(1:n)
  
	integer ::i,k,j,l
	double precision :: t
  
	if(n.le.0)then
		write(6,*)"Error, at heapsort"; stop
	endif
	if(n.eq.1)return

	l=n/2+1
	k=n
	do while(k.ne.1)
		if(l.gt.1)then
			l=l-1
			t=array(L)
		else
			t=array(k)
			array(k)=array(1)
			k=k-1
			if(k.eq.1) then
			array(1)=t
			exit
			endif
		endif
		i=l
		j=l+l
		do while(j.le.k)
			if(j.lt.k)then
			if(array(j).lt.array(j+1))j=j+1
			endif
			if (t.lt.array(j))then
			array(i)=array(j)
			i=j
			j=j+j
			else
			j=k+1
			endif
		enddo
		array(i)=t
	enddo
	return
	end subroutine heapsort
end module subprogram


program main
	use subprogram
	implicit none
	integer N, M, i, j, xfugo(1:8), yfugo(1:8), zfugo(1:8)
	integer(8) Sans(1:8)
	integer(8), allocatable :: x(:), y(:), z(:), S(:)
	read(*, *) N, M
	allocate(x(1: N))
	allocate(y(1: N))
	allocate(z(1: N))
	allocate(S(1: N))
	do i = 1, N
		read(*, *) x(i), y(i), z(i)
	end do
	Sans(1:8) = 0
	xfugo(1) = 1; yfugo(1) = 1; zfugo(1) = 1
	xfugo(2) = -1; yfugo(2) = 1; zfugo(2) = 1
	xfugo(3) = 1; yfugo(3) = -1; zfugo(3) = 1
	xfugo(4) = 1; yfugo(4) = 1; zfugo(4) = -1
	xfugo(5) = -1; yfugo(5) = -1; zfugo(5) = 1
	xfugo(6) = -1; yfugo(6) = 1; zfugo(6) = -1
	xfugo(7) = 1; yfugo(7) = -1; zfugo(7) = -1
	xfugo(8) = -1; yfugo(8) = -1; zfugo(8) = -1
	do i = 1, 8
		do j = 1, N
			S(j) = xfugo(i) * x(j)  +  yfugo(i) * y(j)  +  zfugo(i) * z(j)
		end do
		call heapsort(N,S)
		S = S(N:1:-1)
		do j = 1, M
			Sans(i) = Sans(i) + S(j)
		end do
	end do
	write(*, *) maxval(Sans)
end program main

Measured memory_bytes: 768
#include<stdio.h>

int main(){
    int a,b,c=0;
    scanf("%d %d",&a,&b);
    if(a==b)c=a+b;
    else if(a>b)c=a+(a-1);
    else c=b+(b-1);
    printf("%d\n",c);
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    string s;
    cin>>s;
    ll w;
    cin>>w;
    string x;
    rep(i,s.size()){
        if(i%w==0){
            x += s[i];
        }
    }
    ll ans=0;
    cout<<x<<endl;
    return  0;
}


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

int main(){
    int n;
    cin>>n;
    string name[n];
    int point[n], id[n];
    for(int i=0;i<n;i++)	id[i] = i+1;
    for(int i=0;i<n;i++)	cin>>name[i]>>point[i];
    for(int i=0;i<n-1;i++){
    	for(int j=i+1;j<n;j++){
    		int k = name[i].compare(name[j]);
			if(k>0 || (k==0 && point[i]<point[j])){
				string temp = name[i];
				name[i] = name[j];
				name[j] = temp;
				int tempP = point[i];
				point[i] = point[j];
				point[j] = tempP;
				int tempID = id[i];
				id[i] = id[j];
				id[j] = tempID;
			}
    	}
    }
    for(int i=0;i<n;i++)	cout<<id[i]<<endl;
}

Measured memory_bytes: 256
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t;
int cev;
string s;
vector<int> v;

int main(void){
	scanf("%d",&n);
	FOR{
		scanf("%d",&a[i]);
	}
	for(int i=2;i<n;i++){
		if(a[i]!=max(a[i],max(a[i-1],a[i+1])) && a[i]!=min(a[i],min(a[i-1],a[i+1])))cev++;
	}
	printf("%d\n",cev);
	return 0;
}


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

void Main() {
	using pip = pair<int, pair<int, int>>;
	int N;
	cin >> N;
	queue<pair<int, pair<int, int>>> plan;

	for (int i = 0; i < N; i++) {
		int t, x, y;
		cin >> t >> x >> y;
		plan.push(make_pair(t, make_pair(x, y)));
	}

	pip prev = make_pair(0, make_pair(0, 0));
	string ret = "Yes";
	for (int i = 0; i < N; i++) {
		pip now = plan.front();
		plan.pop();
		int dif_x = abs(now.second.first - prev.second.first);
		int dif_y = abs(now.second.second - prev.second.second);
		int dif_t = abs(now.first - prev.first);
		if (dif_t >= (dif_x + dif_y) && (dif_t % 2) == ((dif_x + dif_y) % 2)) {
			prev = now;
			continue;
		}
		else {
			ret = "No";
			break;
		}
	}
	cout << ret << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Main();
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#include <algorithm>
#include <memory>
#define ll long long
#define ull unsigned long long
#define uint unsigned
#define l_double long double
#define PB push_back
#define EB emplace_back
#define gcd __gcd
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PIE (3.1415926535897932384626433832795)
#define MOD 1'00'00'00'007
#define TEST uint _ {}; cin >> _; while (_--)
using namespace std;
ull lcm (ull a, ull b) { return ((a*b)/gcd(a, b)); }
ull countDigits(const ull &N) { return (floor(log10(N)) + 1); }
bool isPowOfTwo(ull const &N) { return (N && (!(N&(N-1)))); }
// ----------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<boolalpha<<fixed<<setprecision(3);
    // --------------------------------------

    int p {}, n {};
    cin >> p >> n;
    vector<int> arr (n);
    for (auto &val: arr) cin >> val;
    arr.EB(p + arr.at(0));

    int ans {INT_MAX};
    for (int i {}; i < n; ++i) {
        // cout<<"TEST: "<<p - (arr.at(i+1) - arr.at(i))<<endl;
        ans = min(ans, p - (arr.at(i+1) - arr.at(i)));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(void){
    int N, a;
    scanf("%d", &N);
    a = N/100;
    if(N<=100*a+10*a+a) printf("%d\n", 100*a+10*a+a);
    else printf("%d\n", 100*(1+a)+10*(1+a)+a+1);
    return 0;
}


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

int main() {
  ll n, k;
  ll p[5005], c[5005] = {};
  cin >> n >> k;
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> c[i];

  if (k < n) {
    ll ans = (ll)-1e15;
    for (ll start = 0; start < n; start++) {
      ll now = start;
      ll score = 0;
      for (ll i = 0; i < k; i++) {
        score += c[p[now] - 1];
        now = p[now] - 1;
        ans = max(ans, score);
      }
    }
    cout << ans << endl;
    return 0;
  }

  ll ans = (ll)-1e15;
  for (ll start = 0; start < n; start++) {
    ll now = start;
    ll loopsum = 0;
    ll loopcount = 0;
    for (ll i = 0; i < n; i++) {
      loopsum += c[p[now] - 1];
      now = p[now] - 1;
      ans = max(ans, loopsum);
      loopcount++;
      if (now == start) {
        break;
      }
    }
    ll score = loopsum * (k / loopcount - 1);
    ll newk = k % loopcount + loopcount;
    if (k / loopcount > 1) {
      ans = max(ans, score);
    }
    for (ll i = 0; i < newk; i++) {
      score += c[p[now] - 1];
      now = p[now] - 1;
      ans = max(ans, score);
    }
  }
  cout << ans << endl;
  return 0;
}

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

class Cmondai
{
    struct Connection
    {
        public List<int> list;
        public Connection(int index)
        {
            list = new List<int>();
        }
    }

    static void Main()
    {
        var nm = Console.ReadLine().Split(' ').Select(x=>Int32.Parse(x)).ToArray();
        var N = nm[0];
        var M = nm[1];
        var a = new int[M];
        var b = new int[M];
        for (int i=0;i<M;++i)
        {
            var ab = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
            a[i] = ab[0];
            b[i] = ab[1];
        }

        var ans = 0L;
        for (int i = 0; i < M; ++i)
        {
            var connection = new Connection[N];
            for (int j = 0; j < N; ++j) connection[j] = new Connection(j);
            for (int j = 0; j < M; ++j)
            {
                if (i == j) continue;
                connection[a[j]-1].list.Add(b[j]-1);
                connection[b[j] - 1].list.Add(a[j] - 1);
            }
            var hashSet = new HashSet<int>();
            Dfs(hashSet, connection, i == 0 ? 1 : 0);
            if (hashSet.Count() != N) ans++;
        }
        Console.WriteLine(ans);
    }
    static void Dfs(HashSet<int> hashSet,Connection[] connection,int index)
    {
        hashSet.Add(index);
        foreach (var l in connection[index].list)
        {
            if (!hashSet.Contains(l)) Dfs(hashSet,connection,l);
        }
    }
}

Measured memory_bytes: 13524
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

using namespace std;

int main(){
    string S;
    cin >> S;

    cout << S.substr(0,3) << endl;
    return 0;
}

Measured memory_bytes: 3624
X, K, D = map(int, input().split())
count = abs(int(X / D))#移動回数内で中央をまたげるか
if D > abs(X):
    if K % 2 == 1:
        last_place = abs(abs(X) - D)#Kが奇数の場合(済)
    else:
        last_place = abs(X)#(済)
else:
    if count <= K:#移動回数内で中央をまたげる場合
        if (K - count) % 2 == 1:#移動後残り移動回数が奇数の場合(済)
            last_place = abs(abs(X) - (count + 1) * D)
        else:
            last_place = abs(abs(X) - count * D)#(済)
    else:#(済)
        last_place = abs(abs(X) - D * K)
print(last_place)

Measured memory_bytes: 61680