akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<cmath>
#include<vector>
#include<map>
#include<sstream>
#include<deque>
#include<iomanip>
#include<algorithm>
#include<set>
#include<queue>
#include<bitset>
#include<stack>
#include<unordered_set>
#include<cstring>
#include<list>
using namespace std;
//	int x=atoi(s.c_str()); s_to_in;
int dx[] = { -1,0,0,1 };
int dy[] = { 0,1,-1 ,0 };
#define endl '\n'
long long mo = 1e9;
const long double P = 3.141592653589793238L;
void trust_yourself()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
long long gcd(long long x, long long y)
{
	if (x == 0)
		return y;
	return gcd(y%x, x);
}
long long fast_power(long long x, long long y, long long mo)
{
	long long p = 1;
	while (y)
	{
		if (y & 1)
			p = (p*x) % mo;
		y = (y >> 1); //y/=2
		x = (x*x) % mo;
	}

	return p;
}
long long convert_to_num(string x) {
	long long  num = 0;
	for (int i = 0; i < x.size(); i++) {
		num *= 2;
		num += x[i] - '0';
	}
	return num;
}

long long com(long long n, long long r) {
	long long p = 1, p1 = 1;
	for (long long i = r + 1; i <= n; i++) {
		p = p * i;
		p /= p1;
		p1++;
	}
	return p;
}


int main()
{
	trust_yourself();
	//freopen("hussien.in", "r", stdin);
	long long n, p, p1;
	cin >> n;
	for (int i = 0; i <= 3000; i++)
	{
		p = pow(i, 5);
		for (int j = 0; j <= 3000; j++) {
			p1 = pow(j, 5);
			if (p - p1 == n) {
				cout << i << " " << j;
				return 0;
			}
			else if (p1 - p == n) {
				cout << j << " " << i;
				return 0;
			}
			else if (p + p1 == n) {
				cout << i << " " << -1 * j;
				return 0;
			}
			else if (p1 + p == n) {
				cout << j << " " << -1 * i;
				return 0;
			}
		}
	}

	return 0;

}


Measured memory_bytes: 4156
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	vector<pair<int, int> > order(n);
	int x;
	for (int i = 0; i < n; ++i) {
		cin >> x;
		order[i] = {x, i + 1};
	}

	sort(order.begin(), order.end());
	for (int i = 0; i < n; ++i) {
		cout << order[i].second << " ";
	}

	cout << "\n";

	return 0;

}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;

#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(ll i = a; i<=b; ++i)
#define NFOR(i,a,b) for(ll i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const ll N = 5e5 + 10;
inline ll add(ll x,ll y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline ll mul(ll x,ll y){
  x = (1LL * x * y) % mod;
  return x;
}

int main()
{   
    ll n,k;
    cin >> n >> k;
    ll a[n+1];
    FOR(i,1,n)cin >> a[i];
    ll dp[n+1] = {0};
    dp[1] = 0;
    dp[2] = abs(a[2]-a[1]);
    FOR(i,3,n){
        dp[i] = INF;
        FOR(j,1,k)
        if(i-j>=1)
        dp[i] = min(dp[i],dp[i-j] + abs(a[i]-a[i-j]));
    }
    cout << dp[n];

    return 0;
}

Measured memory_bytes: 1792
from collections import deque
s = deque(input())
q = int(input())
rev = False
for _ in range(q):
    inp = [x for x in input().split()]
    if inp[0] == "1":
        rev = not rev
    else:
        if inp[1] == "1":
            if rev:
                s.append(inp[2])
            else:
                s.appendleft(inp[2])
        else:
            if rev:
                s.appendleft(inp[2])
            else:
                s.append(inp[2])

if rev:
    s.reverse()
    print("".join(s))
else:
    print("".join(s))

Measured memory_bytes: 8436
type intseq = Cons of int * (int -> intseq) ;; (* 整数の無限列 *)

let rec is_divisible lst x = (* リストのいずれかの要素でxが割り切れるかどうかチェックする. *)
  let max = float_of_int x |> sqrt |> int_of_float in (* チェックする最大値 *)
  match lst with
    [] -> false 
  | p::ps when p > max -> false
  | p::ps -> if x mod p = 0 then true
             else is_divisible ps x ;;

let rec prime_seq primes x =    (* 素数の無限列. primesはアキュムレータであり, 素数のリスト *)
  if is_divisible primes (x+1) then prime_seq primes (x+1)
  else Cons(x+1, prime_seq (primes @ [x+1])) ;;

let is_prime x =                (* xが素数かどうかチェックする *)
  let max = float_of_int x |> sqrt |> int_of_float in
  let rec is_p p_seq =            (* xが素数の数列で割り切れるかチェックする *)
    let Cons(n, f) = p_seq in
    if n > max then true
    else if x mod n = 0 then false
    else is_p (f n)
  in
  is_p (prime_seq [] 1) ;;

let () =
  let open Scanf in
  let m = scanf "%d\n" (fun x -> x) in
  let as_ = Array.init m (fun _ -> scanf "%d\n" (fun x -> if is_prime x then 1 else 0)) in
  Array.fold_left (+) 0 as_
  |> Printf.printf "%d\n" ;;


Measured memory_bytes: 5036
#include<stdio.h>
int main()
{
  int i,n,r[200000],max,min;

  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&r[i]);
  
  min = r[0];
  max = r[1]-r[0];
  for(i=1; i<n; i++) {
    if(max < r[i]-min) max = r[i] - min;
    if(min > r[i]) min = r[i];
  }

  printf("%d\n",max);
  
  return 0;
}

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

int main(){
  long long a,b;
  cin >> a >> b;
  string ans;
  if(a*b<=0) ans = "Zero";
  else if(a>0 && b>0) ans = "Positive";
  else{
    long long sub = b-a;
    if(sub%2==0) ans = "Negative";
    else ans = "Positive";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/*
 * aoj/dpl_5_a/main.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/* Mod */
#define MOD 1000000007
template <class T> void madd(T &a, T b){ if((a+=b)>=MOD) a-=MOD; }
template <class T> void msub(T &a, T b){ if((a+=MOD-b)>=MOD) a-=MOD; }


struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%MOD+MOD)%MOD; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  mint& operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
ostream & operator << (ostream & out, mint const & v) {
  out << v.x;
  return out;
}

int N, K;
void solve() {
  cin >> N >> K;
  mint m = 1;
  loop(n,0,N) {
    m *= K;
  }
  cout << m << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}



Measured memory_bytes: 3108
s = input()
if s[0] != "A":
    print("WA")
elif s[2:-1].count("C") != 1:
    print("WA")
else:
    flag = True
    s = s.replace("A", "").replace("C", "")
    if s.islower() != True:
        print("WA")
    else:
        print("AC")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
inline int read () {
	int num = 0;
	char c = ' ';
	bool flag = true;
	for (;c > '9' || c < '0';c = getchar())
		if (c == '-')
			flag = false;
	for (;c >= '0' && c <= '9';num = (num << 1) + (num << 3) + c - 48, c = getchar());
	return flag ? num : -num;
}
int main () {
	int n = read (), T = read ();
	int ans = 0, now = 0x7fffffff;
	for (int i = 1; i <= n;i ++) {
		int c = read ();
		int t = read ();
		if (t <= T)
			now = min (now ,c);
	}
	if (now != 0x7fffffff)
		cout << now << endl;
	else cout << "TLE\n";
	return 0;
}

Measured memory_bytes: 256
"use strict";
const Main = (input) => {
	let xs = input.trim().split(' ').map(v=>parseInt(v,10));
    let ans0 = xs[0];
    let ans1 = xs[1];

    if(xs[0] == 1){
    	ans0 = xs[0] + 13;
    }
   
    if(xs[1] == 1){
        ans1 = xs[1] + 13;
    }       
     
    if(ans0 == ans1){
        console.log('Draw');
    }else if(ans0 > ans1){
        console.log('Alice');
    }else{
    	console.log('Bob');
    }
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
s = input()
def solve(s):
    n = len(s)
    for i in range(1,n):
        if s[i-1] == s[i]:
            print(i,i+1)
            return
    for i in range(2,n):
        if s[i-2] == s[i]:
            print(i-1,i+1)
            return
    print(-1,-1)
    return
solve(s)

Measured memory_bytes: 39524
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
ll n,m;
struct node{
	int x,h;
}a[maxn];
bool cmp(node p1,node p2){
	return p1.x<p2.x;
}
ll add[maxn];
int main() {
	ll N,D,A;
	cin>>n>>D>>A;
	for(int i=1;i<=n;i++)
		cin>>a[i].x>>a[i].h;
	sort(a+1,a+1+n,cmp);
	ll ans = 0;
	ll cnt = 0;
	for(ll i=1;i<=n;i++){
		cnt-=add[i];
		a[i].h-=cnt;
		if(a[i].h>0){
			ll sum = (a[i].h+A-1)/A;
			ans+=sum;
			sum*=A;
			cnt+=sum;
			int ed = i;
			int l = i+1,r = n;
			while(l<=r){
				int mid = (l+r)>>1;
				if(a[mid].x>(a[i].x+2*D)){
					ed = mid;
					r = mid-1;
				}
				else {
					l = mid+1;
				}
			}
			add[ed]+=sum;
			
		}
	}
	cout<<ans<<endl;
    return 0;
}



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

int main() {
  int h,w;
  cin >> h >> w;
  vector<int>data(26,0);
  for(int i = 0;i < h;i++){
    string s;
    cin >> s;
    for(int j = 0;j < w;j++){
      data[s[j]-'a']++;
    }
  }
  int fc = 0,tc = 0,oc = 0;
  for(int i = 0;i < 26;i++){
    if(data[i]%2 == 1){
      oc++;
      data[i]--;
    }
    if(data[i]%4 == 0){
      fc += data[i]/4;
    }
    else{
      fc += data[i]/4;
      tc ++;
    }
  }
  if(fc >= (w/2)*(h/2)){
    tc += (fc-(w/2)*(h/2))*2;
    fc = (w/2)*(h/2);
  }
  else{
    cout << "No" << endl;
    return 0;
  }
  bool judge = false;
  if(w%2 == 0 && h%2 == 0){
    if(oc == 0 && tc == 0) judge = true;
  }
  else if(w%2 == 1 && h%2 == 0){
    if(oc == 0 && tc == h/2) judge = true;
  }
  else if(w%2 == 0 && h%2 == 1){
    if(oc == 0 && tc == w/2) judge = true;
  }
  else{
    if(oc == 1 && tc == w/2+h/2) judge = true;
  }
  if(judge) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

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

    vector<int> sums(1000);
    sums[0] = 0;
    REP(i, 999) {
        sums[i + 1] = sums[i] + i + 1;
    }

    REP(i, 1000) {
        if (sums[i] - A == sums[i + 1] - B) {
            cout << sums[i] - A << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve();
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve()
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int n = int.Parse(Console.ReadLine());

			List<int> list = new List<int>();
			list.Add(1);
			for (int i = 6; i <= n; i *= 6) {
				list.Add(i);
			}
			for (int i = 9; i <= n; i *= 9) {
				list.Add(i);
			}
			//System.Diagnostics.Debug.WriteLine(string.Join(" ", list.OrderBy(p => p)));

			// 100000
			int[] dp = new int[n + 2];
			for (int i = 1; i < dp.Length; i++) {
				dp[i] = n;
			}
			for (int i = 1; i <= n; i++) {
				foreach (var j in list) {
					if (i - j >= 0) {
						dp[i] = Math.Min(dp[i], dp[i - j] + 1);
					}
				}
			}
			//System.Diagnostics.Debug.WriteLine(string.Join(" ", dp));
			Console.WriteLine(dp[n]);
		}
	}
}


Measured memory_bytes: 28184
$eye_data = [[0, 0, 0, 0], [0, 0, 0, 0]]

def check(vision, lr)
  case
  when 1.1 <= vision
    $eye_data[lr][0] += 1
  when 0.6 <= vision
    $eye_data[lr][1] += 1
  when 0.2 <= vision
    $eye_data[lr][2] += 1
  else
    $eye_data[lr][3] += 1
  end
end

readlines.each do |line|
  l, r = line.chomp.split.map(&:to_f)
  check(l, 0)
  check(r, 1)
end

0.upto(3) do |i|
  puts "#{$eye_data[0][i]} #{$eye_data[1][i]}"
end

Measured memory_bytes: 6108
main = do
  getLine -- n
  co <- getContents
  let ss = map read $ lines co
  let ans = compute ss
  print ans

{-
基本的に全ての点数をとりたい。
しかし結果が10の倍数だと表示されない。
だから極力小さい点数の問題だけを落とす。
しかしそのとき10の倍数の問題は落としても効果がないので、
そうでない最小のものを選ぶ。
-}

compute :: [Int] -> Int
compute ss
  | isOK sum0 = sum0
  | null oks  = 0
  | otherwise = sum0 - minimum oks
  where
    sum0 = sum ss
    oks = filter isOK ss

isOK :: Int -> Bool
isOK n = 0 /= n `mod` 10


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

int main()
{
  int n, m=0, i, j, a[10000];

  scanf("%d", &n);

  for(i=0; i<n; i++)
    {
      scanf("%d", &a[i]);
    }
  for(i=0; i<n; i++)
    {
      if(a[i]%2 == 0)
	{
	  if(a[i] == 2) m++;
	  continue;
	}

      j = 3;
      while(j <= sqrt(a[i]))
	{
	  if(a[i]%j == 0)
	    {
	      m--;
	      break;
	    }
	  j += 2;
	}
      m++;
    }

  printf("%d\n", m);
  return 0;
}

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

int main() {
  int n,l;cin>>n>>l;
  int cnt=0;
  for(int i=1;i<=n;i++){
    int a=i+l-1;
    cnt+=a;
  }
  int ans=1e9;
   for(int i=1;i<=n;i++){
    int a=i+l-1;
     int t=cnt-a;
       if(abs(cnt-t)<abs(ans-cnt))ans=t;
   }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ABC
{
    class ABC173B
    {
        const string FILE = "/tmp/data.txt";

        static void Main(string[] args)
        {
#if DEBUG
            Console.SetIn(new StreamReader(FILE));
#endif
            Dictionary<string, int> dic = new Dictionary<string, int>();
            dic["AC"] = 0;
            dic["WA"] = 0;
            dic["TLE"] = 0;
            dic["RE"] = 0;

            var N = RI();
            for (int i = 0; i < N; ++i)
            {
                string line = Console.ReadLine();
                dic[line] += 1;
            }
            Console.WriteLine("AC x " + dic["AC"]);
            Console.WriteLine("WA x " + dic["WA"]);
            Console.WriteLine("TLE x " + dic["TLE"]);
            Console.WriteLine("RE x " + dic["RE"]);


#if DEBUG
            Console.WriteLine("*** end ***");
            Console.SetIn(Console.In);
            Console.ReadKey();
            Console.WriteLine();
#endif
        }

        static int RI()
        {
            return int.Parse(Console.ReadLine());
        }

        static int[] RIa(int n)
        {
            string[] sa = Console.ReadLine().Split(' ');
            int[] la = new int[n];
            for (int i = 0; i < n; ++i)
            {
                la[i] = int.Parse(sa[i]);
            }
            return la;
        }
    }
}


Measured memory_bytes: 30996
N = int(input())
c = list(input())

l = 0
r = N - 1
ans = 0
while True:
    while l < N and c[l] == 'R':
        l += 1
    while r >= 0 and c[r] == 'W':
        r -= 1
    if r < l:
        break
    c[r], c[l] = c[l], c[r]
    ans += 1

print(ans)

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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

//---------------------------------------------------------------
// 
//---------------------------------------------------------------

int D;
int64 G;
int p[10], c[10];		// 各点数の問題数とボーナス点

int count(int i=0, int cnt=0, int64 total=0, int v=-1) {
//    cout << "i = " << i << "  cnt = " << cnt << "  total = " << total << "  v = " << v << endl;
	if(i >= D) {
		if(total >= G)	{
//		    cout << "ret 1 : " << cnt << endl;
		    return cnt;
		}
		if(v >= 0) {
			int n = (G - total + (100 * (v+1)) - 1) / (100 * (v+1));
			if(n > p[v]) {
//    		    cout << "ret 2 : " << "n = " << n << " > " << p[v] << endl;
			    return INF;
			} else {
//    		    cout << "ret 3 : " << (cnt + n) << endl;
			    return (cnt + n);
			}
		} else {
//		    cout << "ret 4 : " << INF << endl;
		    return INF;
		}
	}
	
	int ans1 = count(i+1, cnt, total, i);
    int ans2 = count(i+1, (cnt + p[i]), total + ((i+1) * 100 * p[i] + c[i]), v);
    return min(ans1, ans2);
}

signed main(){
	cin >> D >> G;
	REP(i, 0, D)	cin >> p[i] >> c[i];
	
	cout << count() << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	static int[] memo=new int[100];
	static int fib(int n) {
		if (memo[n]!=0) return memo[n];
		if (n==0||n==1) return memo[n]=1;
		return (memo[n-1]=fib(n-1))+(memo[n-2]=fib(n-2));
	}
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		System.out.println(fib(scan.nextInt()));
	}

}

Measured memory_bytes: 26348
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
int C[200000];
int pv[200000];
ll dp[200000];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> C[i];
		C[i]--;
	}
	vector<int> v;
	int now = 0;
	while (now < N) {
		int nxt = now + 1;
		while (nxt < N) {
			if (C[now] != C[nxt]) break;
			nxt++;
		}
		v.push_back(C[now]);
		now = nxt;
	}
	memset(pv, -1, sizeof(pv));
	pv[v[0]] = 0;
	dp[0] = 1;
	for (int i = 1; i < v.size(); i++) {
		dp[i] = dp[i - 1];
		if (pv[v[i]] != -1) (dp[i] += dp[pv[v[i]]]) %= MOD;
		pv[v[i]] = i;
	}
	cout << dp[v.size() - 1] << endl;
 }

Measured memory_bytes: 4340
from collections import deque

N = int(input())
ab = [list(map(int, input().split())) for i in range(N-1)]
tree = [list() for _ in range(N+1)]
color = [0] * (N-1)

for i, (a, b) in enumerate(ab):
    tree[a].append((b, i))

q = deque([(1, 0)]) # パス先, パスの色でキューに追加
while q:
    v, pc = q.popleft()
    nc = 0 # 使用する色
    for nv, edge in tree[v]: # nv=パス先 edge=abでの順番
        nc += 1
        if nc == pc: # 渡ってきたパスの色と同じなら+1した色にする
            nc += 1
        color[edge] = nc # 使用する色を答えのリストに格納
        q.append((nv, nc))

print(max(color))
print(*color, sep="\n")

Measured memory_bytes: 82392
#include <stdio.h>

#define WIDTH 6
#define HEIGHT 12

enum { YET, ALREADY };

int del( void );
int search( int, int );
int search_body( int, int, char );
void fall( void );

typedef struct {
	char color;
	int state;
} FIELD;

FIELD field[ WIDTH + 2 ][ HEIGHT + 2 ] = {};
const int dx[ 4 ] = { -1, 0, 1, 0 }, dy[ 4 ] = { 0, -1, 0, 1 };

int stack[ WIDTH * HEIGHT ], sp;

int main( void ) {
	int n, x, y, chain;

	for ( scanf( "%d", &n ); n--; printf( "%d\n", chain ) ) {
		for ( y = 1; y <= HEIGHT; y++ )
			for ( x = 1; x <= WIDTH; x++ ) {
				scanf( " %c", &field[ x ][ y ].color );
				field[ x ][ y ].state = YET;
			}

		for ( chain = 0; del(); chain++ )
			fall();
	}

	return 0;
}

int del( void ) {
	int x, y, del = 0;

	for ( y = 1; y <= HEIGHT; y++ )
		for ( x = 1; x <= WIDTH; x++ )
			if ( field[ x ][ y ].color != '.' && field[ x ][ y ].color != 'O' && field[ x ][ y ].state == YET ) {
				sp = 0;
				if ( search( x, y ) >= 4 ) {
					while ( sp-- )
						field[ stack[ sp ] / ( HEIGHT + 2 ) ][ stack[ sp ] % ( HEIGHT + 2 ) ].color = '.';

					del++;
				}
			}

	return del;
}

int search( int x, int y ) {
	return search_body( x, y, field[ x ][ y ].color );
}

int search_body( int x, int y, char color ) {
	int i, sum;

	stack[ sp++ ] = x * ( HEIGHT + 2 ) + y;
	field[ x ][ y ].state = ALREADY;

	sum = 0;
	for ( i = 4; i--;  ) {
		int nx = x + dx[ i ], ny = y + dy[ i ];

		if ( field[ nx ][ ny ].state == YET )
			if ( field[ nx ][ ny ].color == color )
				sum += search_body( nx, ny, color );
			else if ( field[ nx ][ ny ].color == 'O' )
				stack[ sp++ ] = nx * ( HEIGHT + 2 ) + ny;
	}

	return sum + 1;
}

void fall( void ) {
	int x, y;

	for ( x = 1; x <= WIDTH; x++ ) {
		int cnt = 0;

		for ( y = HEIGHT; y; y-- )
			if ( field[ x ][ y ].color == '.' )
				cnt++;
			else {
				field[ x ][ y + cnt ].color = field[ x ][ y ].color;
				field[ x ][ y + cnt ].state = YET;
			}

		for ( y = cnt; y; y-- )
			field[ x ][ y ].color = '.';
	}
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=1e5+10;
const int mod=0;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,l,t,x[N],w[N];
ll sum=0;
int main() {
    cin>>n>>l>>t;
    for(int i=1;i<=n;i++) x[i]=gi(),w[i]=gi();
    for(int i=1;i<=n;i++) {
        if(w[i]==2) w[i]=-1;
        int p=x[i]+w[i]*t;
        if(p>0) sum+=p/l;
        else if(p<0) sum+=(p+1)/l-1;
        x[i]=(p%l+l)%l;
    }
    sort(x+1,x+n+1);
    sum=(sum%n+n)%n;
    for(int i=sum+1;i<=n;i++) printf("%d\n",x[i]);
    for(int i=1;i<=sum;i++) printf("%d\n",x[i]);
    return 0;
}


Measured memory_bytes: 1920
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){ 
    int n; cin >> n;
    vector<ll> A(n), S(n+1);
    map<ll, int> mp; mp[0]++;
    rep(i, n){
        cin >> A[i];
        S[i+1] = S[i] + A[i];
        mp[S[i+1]]++;
    }
    ll res = 0;
    for(auto m: mp){
        ll val = m.second;
        res += val * (val-1) / 2;
    }
    cout << res << ln;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=10005;
char ch[N],mn='z';
int f[N],mx;
int main(){
	int n=read(),k=read()-1;
	scanf("%s",ch+1);
	For(i,n+1,2*n)mn=min(mn,ch[i]=ch[n-(i-n)+1]);
	For(i,1,2*n)mx=max(mx,f[i]=ch[i]==mn?f[i-1]+1:0);
	string ans;ans.resize(n);
	For(i,0,n-1)ans[i]=ch[i+1];
	For(i,n,2*n)if(f[i]==mx){
		string zs; zs.resize(n);
		if(k>=15||(f[i]<<k)>=n){
			For(j,0,n-1)zs[j]=mn; ans=zs;
		}else{
			For(j,0,n-(f[i]<<k)-1)zs[j]=ch[i-f[i]-(n-(f[i]<<k))+j+1];
			//cout<<i<<" "<<f[i]<<" "<<i-f[i]-(n-(f[i]<<k))+1<<endl;
			For(j,n-(f[i]<<k),n-1)zs[j]=mn;
			reverse(zs.begin(),zs.end());
			ans=min(ans,zs);
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=1e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
}
int n,m;
int x[N];
void input()
{
	n=read<int>(),m=read<int>();
	For(i,1,m)x[i]=read<int>();
}
const int mo=1e9+7;
struct Matrix
{
	int a[3][3];
	Matrix(){memset(a,0,sizeof a);}
	void init(){For(i,0,2)a[i][i]=1;}
	Matrix operator * (const Matrix &b)const
	{
		Matrix h;
		ll val=0;
		For(i,0,2)For(j,0,2)
		{
			val=0;
			For(k,0,2)val+=1ll*a[i][k]*b.a[k][j];
			h.a[i][j]=val%mo;
		}
		return h;
	}
	Matrix operator ^ (int y)const
	{
		Matrix res,x=*this;
		res.init();
		for(;y;x=x*x,y>>=1)if(y&1)res=res*x;
		return res;
	}
	void out()
	{
		For(i,0,2)For(j,0,2)write(a[i][j],j==2?'\n':' ');
		puts("");
	}
}trans0,trans1,ans;
int A[3][3]={{1,2,1},{0,1,1},{1,2,2}},B[3][3]={{1,2,1},{0,1,1},{0,0,1}};
void work()
{
	ans.a[0][0]=1;
	memcpy(trans0.a,A,sizeof A);
	memcpy(trans1.a,B,sizeof B);
//	trans0.out();
	int last=0;
	For(i,1,m)
	{
		ans=ans*(trans0^(x[i]-last));
		last=x[i]+1;
		ans=ans*trans1;
	}
	ans=ans*(trans0^(n-last));
	write(ans.a[0][2],'\n');
}
int main()
{
	input();
	work();
	return 0;
}



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


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

#define MAX 1000000

vector<int> prime;
bool is_prime[MAX+1];

void Sieve() {
  
  for(int i=0; i<=MAX; i++) {
    is_prime[i] = true;
  }
  
  is_prime[0] = is_prime[1] = false;
  
  for(int i=2; i<=MAX; i++) {
    if(is_prime[i]) {
      prime.push_back( i );
      for(int j=2*i; j<=MAX; j+=i) is_prime[j] = false;
    }
  }
}

int main() {
  
  Sieve();
  
  int n;
  while(cin >> n) {
    int temp = n;
    while(n--) {
      if( is_prime[n] ) {
	cout << n << " ";
	break;
      }
    }

    while(temp++) {
      if( is_prime[temp] ) {
	cout << temp << endl;
	break;
      }
    }
  }
  
  return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

void solve(int h, int w) {
  vector<string> key(h); rep(i, h) std::cin >> key[i];
  string in; std::cin >> in;
  map<char, int> cp;
  rep(i, h) rep(j, w) {
    cp[key[i][j]] = i*w+j;
  }
  int x = 0, y = 0;
  ll ans = 0;
  for (auto &c : in) {
    int nx = cp[c] % w, ny = cp[c] / w;
    int dx = abs(nx - x), dy = abs(ny - y);
    ans += dx + dy + 1;
    x = nx, y = ny;
  }
  std::cout << ans << "\n";
}

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

  while (1) {
    int h, w; std::cin >> h >> w;
    if (h == 0 && w == 0) break;
    solve(h, w);
  }
}



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

using namespace std;

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

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define contains(i, c) ((c).find(i) != (c).end())

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++)
#define repa(i, a, b) for(int i = (a); i < (b); i++)
#define repd(i, n) for(int i = (n)-1; i >= 0; i--)

#define TRACE(x...) x
#define watch(x) TRACE(cerr << #x" = " << x << endl)
#define watch_all(x) TRACE(cerr << #x" = "; for(auto __i : x) cerr << __i << " "; cerr << endl)

//=========================

void run_test() {
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	cout << h2 * 60 + m2 - h1 * 60 - m1 - k << endl;
}

//=========================

ifstream infile;
clock_t start__;
void open_func();
void close_func();

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	open_func();
	//int t = 1, _t; cin >> _t; while(t <= _t) { cout << "Case #" << t++ << ": "; run_test(); }
	//int t; cin >> t; while(t--) run_test();
	run_test();
	close_func();
	return 0;	
}

void open_func() {
	//infile = ifstream("input.in"); if(infile.good()) cin.rdbuf(infile.rdbuf());
	start__ = clock();
	cerr << "---" << endl;
}

void close_func() {
	clock_t elapsed = clock()-start__;
	cerr << "---" << endl << "(time " << fixed << setprecision(2) << elapsed * (1.0/CLOCKS_PER_SEC) << "s)" << endl;	
	//if(infile.good()) infile.close();
}


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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

void solve() {
  int N;
  bool unique = true;
  cin >> N;
  vector<int> a(N);
  REP(i, N) { cin >> a[i]; }
  sort(ALL(a));
  REP(i, N - 1) {
    if (a[i] == a[i + 1]) {
      unique = false;
      break;
    }
  }
  cout << (unique ? "YES" : "NO") << endl;
}

signed main() {
  solve();

  return 0;
}

Measured memory_bytes: 1024
A = [list(map(int,input().split())) for _ in range(3)]
N = int(input())

bingo = [[0 for _ in range(3)] for _ in range(3)]

for _ in range(N):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        bingo[i][j] = 1
        
check = False

for i in range(3):
  if 0 not in bingo[i]:
    check = True
  
for j in range(3):
  if bingo[0][j] + bingo[1][j] + bingo[2][j] == 3:
    check = True
    
if bingo[0][0] + bingo[1][1] + bingo[2][2] == 3:
  check = True

if bingo[0][2] + bingo[1][1] + bingo[2][0] == 3:
  check = True
  
print("Yes" if check else "No")

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define double long double
#define rep(i, n) for (int i = 0; i < n; i++)
#include <math.h> /* M_PI */
#define INF 2147483647

int main()
{
    ll p = 0;
    ll k = 0;
    ll h = 0;
    cin >> k;
    ll j = 0;
    int flag = 0;
    while (1)
    {
        ll data = h * 10 + 7;
        if ((h = data % k) == 0)
        {
            cout << j + 1 << endl;
            flag = 1;
            break;
        }
        j += 1;
        if (j >= 100000000)
        {
            break;
        }
    }
    if (flag == 0)
    {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 3584
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
P = []
N.times do |i|
  P[i] = get_int
end

P.sort!.reverse!
max = P.first
rest = P[1..]

puts (max / 2) + rest.sum


Measured memory_bytes: 14400
// AGC013A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) cin >> A[i];
	int count = 0;
	for (int i = 0; i < N; i++) {
		while (i + 1 < N && A[i] == A[i + 1]) ++i;

		if (i + 1 < N && A[i] > A[i + 1]) 
		{
			while (i + 1 < N && A[i] >= A[i + 1]) ++i;
		}
		else {
			while (i + 1 < N && A[i] <= A[i + 1]) ++i;
		}
		count++;
	}


	cout << count << endl;
	return 0;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!=',')
        {
            cout<<s[i];
        }
        else
        {
            cout<<" ";
        }
    }
}


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

struct RollingHash {
    const int base1 = 1007, base2 = 2009;
    const int mod1 = 1e9 + 7, mod2 = 1e9 + 9;
    vector<ll> hash1, hash2, power1, power2;

    RollingHash(string& S) {
        int n = S.size();
        hash1.assign(n + 1, 0);
        hash2.assign(n + 1, 0);
        power1.assign(n + 1, 1);
        power2.assign(n + 1, 1);
        for(int i = 0; i < n; i++) {
            hash1[i + 1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i + 1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i + 1] = power1[i] * base1 % mod1;
            power2[i + 1] = power2[i] * base2 % mod2;
        }
    }

    // [l, r)
    pair<ll, ll> get(int l, int r) const {
        ll res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        ll res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

    int getLCP(int a, int b) const {
        int len = min((int)hash1.size() - a, (int)hash1.size() - b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a + mid) != get(b, b + mid)) high = mid;
            else low = mid;
        }
        return low;
    }
};

int main() {
    int n;
    string s;
    cin >> n >> s;
    RollingHash rh(s);
    auto ok = [&](int x) -> bool {
        map<pair<int, int>, int> mp;
        for(int i = 0; i + x <= n; i++) {
            auto p = rh.get(i, i + x);
            if(mp.count(p)) {
                if(i - mp[p] >= x) return true;
            }
            else mp[p] = i;
        }
        return false;
    };
    int l = 0, r = n / 2 + 1;
    while(r - l > 1) {
        int mid = (r + l) / 2;
        if(ok(mid)) l = mid;
        else r = mid;
    }
    cout << l << endl;
}

Measured memory_bytes: 4048
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N;

	public void solve() {

		StringBuilder sb = new StringBuilder();
		String S;
		N = nextInt();
		for(int i = 0;i < N;i++){
			sb.append(nextInt());
		}

		S = sb.toString();

		for(int i = 0;i < (int)1e6 + 1;i++){
			if(S.indexOf(String.valueOf(i)) == -1){
				out.println(i);
				break;
			}
		}
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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

Measured memory_bytes: 25084
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <climits>
#include <ctype.h>
using namespace std;

#define PI acos(-1.0)
#define EPS 1e-8
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

template <class L, class R> ostream &operator <<(ostream &os, pair<L, R> P){
    return os << "(" << P.fi << "," << P.se << ")";
}
template <class T> ostream &operator <<(ostream &os, vector<T> V){
    os << "["; for (auto vv: V) os << vv << ","; return os << "]";
}

struct Matrix {
    vvi data;
    int r, c;
    Matrix(int row, int col, bool identity = false) : r(row), c(col) {
        data.assign(row, vector<int>(col, 0));
        if (identity) {
            for (int i = 0; i < r; ++i) {
                data[i][i] = 1;
            }
        }
    }
    Matrix operator * (Matrix& other) {
        int m = r, n = c, p = other.c;
        Matrix res(m, p);
        for (int i = 0; i < m; ++i) {
            for (int j = 0; j < p; ++j) {
                for (int k = 0; k < n; ++k) {
                    res.data[i][j] += data[i][k] * other.data[k][j];
                }
            }
        }
        return res;
    }
};

// 扩展欧几里得算法 res[1] * a + res[2] * b = res[0] = gcd(a, b)
vector<int> extendGcd(int a, int b) {
    if (b == 0) {
        return {a, 1, 0};
    } else {
        vector<int> tmp = extendGcd(b, a % b);
        return {tmp[0], tmp[2], tmp[1] - (a / b) * tmp[2]};
    }
}

// 矩阵快速幂
Matrix matrix_power(Matrix base, ll exp) {
    int n = base.r;
    Matrix res(n, n, true);
    while (exp) {
        if (exp & 1) {
            res = res * base;
        }
        base = base * base;
        exp >>= 1;
    }
    return res;
}

// 带模快速幂
template <typename T>
T power_mod(T base, int exp, int mod = MOD) {
    T res = 1;
    while (exp) {
        if (exp & 1) res = res * base % mod;
        base = base * base % mod;
        exp >>= 1;
    }
    return res;
}

// 快速幂
template <typename T>
T power(T base, int exp) {
    T res = 1;
    while (exp) {
        if (exp & 1) res *= base;
        base *= base;
        exp >>= 1;
    }
    return res;
}

// 求逆元
ll inv(ll a) {
    return power_mod(a, MOD - 2);
}

/******************************** template ********************************/
#define N 100010
int n, a, b;

int main() {
    cin >> n >> a >> b;
    if ((b - a) % 2 == 0) {
        cout << "Alice";
    } else {
        cout << "Borys";
    }

    return 0;
}


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


int main(void){
   int64_t X;
   cin >> X;
   
   int64_t a,b,ans;
   a=X/500;
   b=(X%500)/5;
   ans=1000*a+5*b;
   
   cout << ans << endl;
   
   

}




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

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define int long long 
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
using namespace std;
signed main()
{
    fast;
   	map<string,int> mp;
   	int n;
   	cin>>n;
   	while(n--){
   		string s;
   		cin>>s;
   		mp[s]++;
   	}
   	vector<string> ans;
   	int mx = 0;
   	for(auto it:mp){
   		mx = max(mx,it.second);
   	}
   	for(auto it:mp){
   		if(it.second == mx){
   			ans.pb(it.first);
   		}
   	}
   	sort(all(ans));
   	for(auto it:ans)
   		cout<<it<<"\n";
}   

Measured memory_bytes: 25584
#include<bits/stdc++.h>
using namespace std;
int const MAXN=2100;
bool t[MAXN][MAXN];
int up[MAXN][MAXN], down[MAXN][MAXN], ri[MAXN][MAXN], le[MAXN][MAXN];
int r, c;
int main(){
	cin>>r>>c;
	char ch;
	for(int i=0;i<r;i++)
		for(int j=0;j<c;j++){
			cin>>ch;
			t[i][j]=(ch=='.'?true:false);
		}
	for(int i=0;i<r;i++)
		for(int j=0;j<c;j++){
			if(!t[i][j]) continue;
			if(i!=0 && t[i-1][j])
				up[i][j]=up[i-1][j]+1;
			if(j!=0 && t[i][j-1])
				le[i][j]=le[i][j-1]+1;
		}
	for(int i=r-1;i>=0;i--)
		for(int j=c-1;j>=0;j--){
			if(!t[i][j]) continue;
			if(i!=r-1 && t[i+1][j])
				down[i][j]=down[i+1][j]+1;
			if(j!=c-1 && t[i][j+1])
				ri[i][j]=ri[i][j+1]+1;
		}
	int res=0;
	for(int i=0;i<r;i++)
		for(int j=0;j<c;j++)
			if(t[i][j])
				res=max(res,1+up[i][j]+down[i][j]+ri[i][j]+le[i][j]);
	cout<<res;
}

Measured memory_bytes: 73216
sx, sy, tx, ty = map(int, input().split())
nsx, nsy = sx, sy
while nsy < ty:
    nsy += 1
    print("U", end = "")
while nsx <= tx:
    nsx += 1
    print("R", end = "")
while nsy >= sy:
    nsy -= 1
    print("D", end="")
while nsx > sx:
    nsx -= 1
    print("L", end = "")
nsy += 1
print("U", end = "")
nsx -= 1
print("L", end = "")
while nsy <= ty:
    nsy += 1
    print("U", end = "")
while nsx < tx:
    nsx += 1
    print("R", end = "")
while nsy > sy:
    nsy -= 1
    print("D", end="")
while nsx > sx:
    nsx -= 1
    print("L", end = "")

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

int counter = 0;
int N;

void test( long long  x )
{
    if( x > N ) return;

    string s = to_string( x );
    if( s.find("7") != string::npos && s.find("5") != string::npos && 
        s.find("3") != string::npos  ) counter++;

    test( x * 10 + 7 );
    test( x * 10 + 5 );
    test( x * 10 + 3 );
}

int main() 
{
    cin >> N;

    test( 0 );
    cout << counter << endl;
  }

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
double last[1120];
int x[110];
int l[110];
int f[110];
int d[110];
int u[110];
int p[1120];
double q[110];
int v[110];
int main(){
	int a,b,c;
	while(scanf("%d%d%d",&a,&b,&c),a){
		for(int i=0;i<=c+b+2;i++)p[i]=-1;
		for(int i=0;i<a;i++){
			scanf("%d%d%d%d%d",x+i,l+i,f+i,d+i,u+i);
			if(!u[i]){
				swap(f[i],d[i]);
			}
			p[x[i]]=i;
		}
		for(int i=0;i<a;i++)q[i]=-999999999;
		for(int i=0;i<=c+b+2;i++)last[i]=-999999999;
		for(int i=0;i<a;i++){
			if(u[i]==1)q[i]=-(double)l[i]/d[i];
		}
	//	for(int i=0;i<a;i++)printf("%f\n",q[i]);
		for(int i=0;i<b;i++)scanf("%d",v+i);
		for(int i=0;i<b;i++){
		
			double now=0;
			for(int j=0;j<=c+b;j++){
				if(j==0){
					now=(double)i/v[i];
				}else now+=1.0/v[i];
				now=max(now,last[j+1]);
				
				last[j]=now;
				if(~p[j]){
					int at=p[j];
					now=max(now,q[at]+(double)l[at]/f[at]+(double)l[at]/d[at]);
					q[at]=now;
					now+=(double)l[at]/d[at];
				}
			//	printf("%d %d: %f\n",i,j,now);
			}
		}
		printf("%.12f\n",last[c]);
	}
}

Measured memory_bytes: 1084