akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

void Output(string s) {
  cout << s << endl;
  exit(0);
}

int DFS(int v, int ignoreVertex, const vector<vector<int>>& g, vector<bool>& used) {
  if (used[v]) return 0;
  used[v] = true;
  int result = 1;
  for (int to : g[v]) {
    if (to == ignoreVertex) continue;
    result += DFS(to, ignoreVertex, g, used);
  }
  return result;
}

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  vector<int> deg(n);
  vector<vector<int>> g(n);
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    deg[a[i]]++;
    deg[b[i]]++;
    g[a[i]].push_back(b[i]);
    g[b[i]].push_back(a[i]);
  }

  int num = 0;
  int vertex = 0;
  for (int i = 0; i < n; ++i) {
    if (deg[i] % 2 == 1) {
      Output("No");
    }
    if (deg[i] > 2) {
      num++;
      vertex = i;
    }
  }

  if (num > 2) {
    Output("Yes");
  }

  if (num == 0) {
    Output("No");
  }

  if (num == 1) {
    if (deg[vertex] == 4) {
      Output("No");
    }
    Output("Yes");
  }
  
  int start = 0;
  if (vertex == start) {
    start++;
  }

  vector<bool> used(n);
  int visited = DFS(start, vertex, g, used);

  if (visited == n - 1) {
    Output("No");
  }

  Output("Yes");

  return 0;
}


Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  map<string, ll> mp1;
  rep(i, n) {
    string s;
    cin >> s;
    mp1[s]++;
  }
  map<ll, vs> mp2;
  for(auto v : mp1) {
    string s = v.first;
    ll k = v.second;
    mp2[k].push_back(s);
  }
  vs s = (*mp2.rbegin()).second;
  sort(all(s));
  for(auto v : s) cout << v << '\n';
}

Measured memory_bytes: 31364
'use strict'

function main(input) {

    input = input.split(/\n/)
    const n = ~~input[0]

    //スペース区切りで配列化、数値化、重複削除、並べ替え
    let houses = input[1].split(' ').map(v => ~~v).filter((v, i, self) => {
        return self.indexOf(v) === i
    }).sort((a, b) => a - b)

    const ans = houses[houses.length-1] - houses[0]

    console.log(ans)


}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7500
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

W, H, N = MAP()
 
dict = defaultdict(int)
dict[1] = 0
dict[2] = W
dict[3] = 0
dict[4] = H
 
for _ in range(N):
	x, y, a = MAP()
	if a == 1:
		dict[1] = max(x, dict[1])
	elif a == 2:
		dict[2] = min(x, dict[2])
	elif a == 3:
		dict[3] = max(y, dict[3])
	elif a == 4:
		dict[4] = min(y, dict[4])
 
if dict[2]-dict[1] < 0 or dict[4]-dict[3] < 0:
	print(0)
else:
	print(max(0, (dict[2]-dict[1])*(dict[4]-dict[3])))

Measured memory_bytes: 5196
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const int MOD = 1e9 +7;

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

int main(){
    int N;
    ll a[100010];
    bool flag=false;
    cin >>N;
    rep(i,N) cin >>a[i];
    ll ans =gcd(a[0],a[1]);
    rep(i,N){
        ans =gcd(ans,a[i]);
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = sum(A)

for i in range(N):
    
    if A[i] >= B[i]:
        A[i] -= B[i]
    
    else:
        A[i + 1] -= abs(A[i] - B[i])
        A[i + 1] *= int(A[i + 1] > 0)
        A[i] = 0 

print(ans - sum(A))

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int N;
	cin >> N;

	ll INF = 1e15;
	ll a[N+2];
	a[0] = INF;
	rep(i, N) cin >> a[i+1];
	a[N+1] = INF;

	ll s[N+2	];
	s[0] = 0;
	rep(i, N) s[i+1] = s[i] + a[i+1];
	s[N+1] = s[N];

	ll dp[N+1][N+1];
	rep(i, N+1) rep(j, N+1) dp[i][j] = ((i == j) ? 0 : INF);

	for(int w = 1; w <= N; w++){
		for(int l = 1; l+w <= N; l++){
			for(int k = 0; k <= w-1; k++){
				int r = l+w;
				dp[l][r] = min(dp[l][r], dp[l][l+k] + dp[l+k+1][r] + s[r] - s[l-1]);
			}
		}
	}

	cout << dp[1][N] << endl;
}


Measured memory_bytes: 1536
// DPかと構えるもべつにそんなことはない K個前をみて同じだったら+0点
package main
import "fmt"
func main(){
	var N, K int
	var R, S, P int
	var T string
	fmt.Scan(&N, &K, &R, &S, &P, &T)
	TT := make([]string, N)
	ans := 0
	for i, c := range []rune(T){
		TT[i] = string(c)
	}
	for i:=K; i<N; i++{
		if TT[i-K] == TT[i]{
			TT[i] = "死"
		}
	}
	for _, c := range TT{
		switch c{
		case "r":
			ans += P
		case "p":
			ans += S
		case "s":
			ans += R
		}
	}
	
	fmt.Println(ans)
}

Measured memory_bytes: 4516
import sys

N, L = map(int, input().split())
a = list(map(int, input().split()))

for i in range(N-1):
    if(a[i]+a[i+1] >= L):
        idx = i
        break
else:
    print("Impossible")
    sys.exit()
    
print("Possible")

for i in range(1, i+1):
    print(i)
    
for i in range(N-1, i, -1):
    print(i)

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int x, y, z;
  x = 0;
  y = 0;
  z = 0;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    if (num <= a) {
      x++;
    } else if (num >= b + 1) {
      z++;
    } else {
      y++;
    }
  }
  if (x <= y) {
    if (x <= z) {
      cout << x << endl;
    } else if (x > z) {
      cout << z << endl;
    }
  } else if (x > y) {
    if (y <= z) {
      cout << y << endl;
    } else if (y > z) {
      cout << z << endl;
    }
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    int[] parent;
    int[] size;
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        parent = new int[n];
        size = new int[n];
        for(int i = 0; i < n; i++){
            parent[i] = i;
            size[i] = 1;
        }
        for(int i = 0; i < m; i++){
            int a = scan.nextInt() - 1;
            int b = scan.nextInt() - 1;
            unite(a, b);
        }
        int out = -1;
        for(int i = 0; i < n; i++){
            out = Math.max(out, size[i]);
        }
        System.out.println(out);
    }
    
    int root(int x){
        if(parent[x] == x) return x;
        return parent[x] = root(parent[x]);
    }
    
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(size[x] < size[y]){
            parent[x] = y;
            size[y] += size[x];
        }else{
            parent[y] = x;
            size[x] += size[y];
        }
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}


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

const int N = 2e5+10;
int a[N];
int sum[N];
map<int, int> msk;

int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin>>n>>k;
    for(int i = 1; i <= n; i++){
        cin>>a[i];
        sum[i] = sum[i-1]+a[i];
    }
    for(int i = 1; i <= n; i++){
        sum[i] = (sum[i]-i)%k;
    }
    int ans = 0;
    msk[0]++;
    for(int i = 1; i <= n; i++){
        if(i>=k) msk[sum[i-k]]--;
        ans += msk[sum[i]];
        msk[sum[i]]++;
    }
    cout<<ans;
    return 0;
}

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


int main() {

    int n;
    cin >> n;
    for (double i = 1; i <= 50000; ++i) {
        int x = i * 1.08;
        if (x == n) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
N=100000
memo = [0] * (N+1)
(1..N+1).each do |i|
  a = []
  7.times do |j|
    k = i - 6 ** j
    a << memo[k] if k >= 0
    k = i - 9 ** j
    a << memo[k] if k >= 0
  end
  memo[i] = a.min + 1
end
p memo[gets.to_i]


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

int main(){
  int n,m;
  cin>>n>>m;
  int red[100001]={1};
  int cnt[100001]={};

  for(int i=0;i<n;i++)cnt[i]=1;
  
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    x--,y--;
    red[y]|=red[x];
    cnt[x]--,cnt[y]++;
    if(cnt[x]==0) red[x]=0;    
  }

  int ans=0;  
  for(int i=0;i<n;i++)ans+=red[i];

  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;



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

	int a, b;
	cin >> a >> b;
	string s;
	int ans = 0;
	bool f = true;
	repr(i, a, b+1) {
		s = to_string(i);
		f = true;
		rep(j, s.size()) {
			if (s[j] != s[s.size() - j - 1]) {
				f = false;
			}
		}
		if (f) ans++;
	}

	cout << ans << endl;

	return 0;
}


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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  
  int ans1 = 0; //黒の個数
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '#') ans1++;
  }
  
  int ans2 = n - ans1; //白の個数
  
  int ans3 = n;
  int rb = 0; //左にある黒の数
  int rw = ans2; //右にある白の数
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '#'){rb++;}
    else{
      rw--;
      if(rb + rw < ans3){ans3 = rb + rw;}
    }
  }
  cout << min({ans1, ans2, ans3}) << endl;
  
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> ans(26,100);
    vector<int> now(26,0);
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        for(int j=0;j<s.size();j++){
            now[s[j]-'a']++;
        }
        for(int j=0;j<26;j++){
            ans[j] = min(ans[j],now[j]);
        }
        now.clear();
        now.resize(26);        
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<deque>
#include<tuple>
#include<iomanip>
using namespace std;
#define int                  int64_t
#define double               long double
#define vi                   vector<int>
#define di                   deque<int>
#define si                   set<int>
#define vpii                 vector<pair<int,int>>
#define pi                   pair<int,int>
#define pub                  push_back
#define puf                  push_front
#define pob                  pop_back
#define pof                  pop_front
#define all(a)               (a).begin(),(a).end()
#define rall(a)              (a).rbegin(),(a).rend()
#define PI                   3.1415926535897932384626433832795
#define read(a)              for(auto& x:a) cin>>x
#define speak(a)             for(auto x:a) cout<<x<<' '
#define rep(i,s,n)           for(int i=s;i<n;++i)
#define repe(i,s,n)          for(int i=s;i<=n;++i)
#define repr(i,n,s)          for(int i=n;i>=s;--i)
#define endl                 '\n'
#define gap                  ' '
#define min3(a,b,c)          min(a, min(b, c))
#define max3(a,b,c)          max(a, max(b, c))
#define MOD                  1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a;cin>>a;
    cout<<a+a*a+a*a*a;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define LIMIT 10000
using namespace std;

bool ck(vector<int>&a){
  rep(i, a.size())
    if(i + 1 != a[i]) return false;
  return true;
}

int main(){
  int n, b, c, sum, j, i;
  vector<int>judge;
  for(i = 1; i < 199; i++) judge.push_back(i*(i+1)/2);
  while(scanf("%d", &n) && n){
    vector<int>v;
    sum = 0;
    for(i = 0; i < n; ++i){ scanf("%d", &b); sum += b; v.push_back(b);}
    i = LIMIT + 1;
    vector<int>::iterator idx = find(judge.begin(), judge.end(), sum);
    if(idx != judge.end()){
      for(i = 0; i <= LIMIT && !ck(v); i++){
	int k = v.size();
	rep(l, k) v[l]--;
	v.erase(remove(v.begin(),v.end(), 0), v.end());
	v.push_back(k);
      }
    }
    printf("%d\n", i > LIMIT?-1:i);
  }
  return 0;
}

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

char s[10];

int main()
{
	scanf( "%s", s );
	int len = strlen(s);
	for(int i = 0; i < len - 1; ++i)
		if(s[i] == 'A' && s[i + 1] == 'C')
		{
			puts("Yes");
			return 0;
		}
	puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  cout << abs(a[0] - *(a.end() - 1)) << endl;
}


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

#ifndef ONLINE_JUDGE
	#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
	#define W(x, y)
#endif

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi acosl(-1)
#define ld long double
#define prime (1000000000 + 7)
#define INF 1000000000

using namespace std;


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

    ll n;
    map<ll, ll> hist;
    cin >> n;
    for(int i = 0; i < n; ++i){
        ll a;
        cin >> a;
        hist[a]++;
    }
    if(hist.size() == n){
        cout << "YES" << endl;
    } else{
        cout << "NO" << endl;
    }

   
    return 0;
}


/*
    r   o   #   r   o   u   n   d
-1  0   0   0   1   2   0   0   0 
*/
// 1 = 3
// 2 = 3
// 3 = -1
// 4 = 0
// 5 = 1

Measured memory_bytes: 12800
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	int D, N;
	cin >> D >> N;

	ull step = 1;
	if (D == 1){
		step = 100;
	} else if (D == 2) {
		step = 10000;
	}

	ull value = step;
	ull cnt = 1;
	while (true) {
		if (cnt == N){
			break;
		}
		value += step;
		if (value % (step * 100) != 0){
			cnt++;
		}
	}

	cout << value << endl;

	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

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

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

    double r;
    cin >> r;

    cout << setprecision(20)  << r*2.*3.1415926535 << endl;

    return 0;
}


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


int main() {
    int N;
    cin >> N;
    map<int, int> m;
    for(int i=0; i<N; ++i) {
        int A;
        cin >> A;

        auto it = m.find(A);
        if (it != m.end()) {
            m.erase(A);
        }
        else m[A] = 1;        
    }
    cout << m.size() << endl;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-6;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

string s, t;
map<char,char> change1, change2;

void solve()
{
	const int N = s.length();
	bool ok = true;
	for(int i=0; i<N;++i){
		if(change1.count(s[i]) && (change1[s[i]] != t[i])){
			ok  = false;
			break;
		}
		if(change2.count(t[i]) && change2[t[i]] != s[i]){
			ok = false;
			break;
		}
		change1[s[i]] = t[i];
		change2[t[i]] = s[i];
	}
	if(ok) cout << "Yes" << endl;
	else cout << "No" << endl;
 }

int main()
{
	cin >> s >> t;
	solve();
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
struct Node {
	Node *l = 0, *r = 0;
	int val, y;
	int first, max;
	bool monotone;
	Node(int val) : val(val), y(rand()) {
		first = max = val;
		monotone = 1;
	}
	void reset() {
		first = max = val;
		monotone = 1;
	}
	void recalc();
	void recalc3();
};
 
inline void Node::recalc() {
	first = l ? l->first : val;
	int max = val;
	bool mon = 1;
	if (l) {
		max = std::max(max, l->max);
		if (!l->monotone || l->max > val) mon = 0;
	}
	if (r) {
		max = std::max(max, r->max);
		if (mon && (!r->monotone || r->first < val)) mon = 0;
	}
	this->max = max;
	monotone = mon;
}
 
inline void Node::recalc3() {
	first = l ? l->first : val;
	max = r ? r->max : val;
	monotone = 1;
}
 
Node* merge2(Node* l, Node* r) {
	if (l->y > r->y) {
		l->r = l->r ? merge2(l->r, r) : r;
		l->recalc();
		return l;
	} else {
		r->l = r->l ? merge2(l, r->l) : l;
		r->recalc();
		return r;
	}
}
 
inline Node* merge(Node* l, Node* r) {
	if (!l) return r;
	if (!r) return l;
	return merge2(l, r);
}
 
Node* merge32(Node* l, Node* r) {
	if (l->y > r->y) {
		l->r = l->r ? merge32(l->r, r) : r;
		l->recalc3();
		return l;
	} else {
		r->l = r->l ? merge32(l, r->l) : l;
		r->recalc3();
		return r;
	}
}
 
inline Node* merge3(Node* l, Node* r) {
	if (!l) return r;
	if (!r) return l;
	return merge32(l, r);
}
 
pair<Node*, Node*> split2(Node* n, int lo) {
	if (!n) return {0, 0};
	if (n->max < lo) return {0, n};
	if (n->monotone) {
		if (lo < n->first) return {n, 0};
		if (!n->l) {
			if (!n->r) return {0, n};
			assert(lo >= n->val);
			auto pa = split2(n->r, lo);
			n->r = 0;
			n->reset();
			pa.second = merge(n, pa.second);
			return pa;
		}
 
		if (lo < n->val) {
			auto pa = split2(n->l, lo);
			n->l = 0;
			n->recalc();
			pa.first = merge3(pa.first, n);
			return pa;
		}
		else {
			// if (!n->r) return {0, n};
			auto pa = split2(n->r, lo);
			n->r = 0;
			n->recalc();
			pa.second = merge(n, pa.second);
			return pa;
		}
	}
 
	Node *left = n->l, *right = n->r;
	n->l = n->r = 0;
	n->recalc();
	auto pa = split2(left, lo);
	if (pa.first) lo = pa.first->max;
	if (n->val > lo) {
		pa.first = merge3(pa.first, n);
		lo = n->val;
	}
	else {
		pa.second = merge(pa.second, n);
	}
	auto pa2 = split2(right, lo);
	return {merge3(pa.first, pa2.first), merge(pa.second, pa2.second)};
}
 
int main() {
	srand(2);
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	int N;
	cin >> N;
	vector<Node> nodes;
	rep(i,0,N) {
		int p;
		cin >> p;
		nodes.emplace_back(p);
	}
 
	Node* t = 0;
	rep(i,0,N)
		t = merge(t, &nodes[i]);
 
	int res = 0;
	while (!t->monotone) {
		++res;
		auto pa = split2(t, 0);
		t = merge(pa.second, pa.first);
	}
 
	cout << res << endl;
	exit(0);
}

Measured memory_bytes: 12524
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;
 
// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
// 
 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
 
#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return 
 
 
#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
 
#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>
 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
 
#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5

void solve(){
    ll n;
    string s;
    cin>>n>>s;
    set<char> sss;
    loop(i,0,n){
        sss.insert(s[i]);
    }
    if(sss.size() == n) {
        print(0);
        ret;
    }
    ll lo = 1, hi = n;
    while(hi > lo){
        ll mid = lo + (hi-lo+1)/2;
        map<string, vl> m;
        for(ll i=0; i <= n-mid; i++){
            string t(s, i, mid);
            // trace(t);
            m[t].pb(i);
        }
        // print("hhh "<<m["ba"].size());
        bool b = 0;
        for(auto x: m){
            // trace(x.fi);
            // printc(x.se);
            if(x.se.size() >= 2){
                ll a = x.se[0], bg = x.se[x.se.size()-1];
                if(a + mid <= bg){
                    b = 1;
                    break;
                }
            }
        }
        // trace(mid, b);
        if(b == 1){
            lo = mid;
        }
        else hi = mid-1;
    }
    print(lo);
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
 
    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
   
}


Measured memory_bytes: 6784
#AGC031 A Colorful Subsequence
# Answer
N = int(input())
S = input()
alpha = [0]*26
mod = 10**9+7

for n in S:
    num = ord(n)-97
    alpha[num] += 1
    
ans = 1
for i in range(26):
    ans *= (alpha[i]+1)

ans -= 1
ans %= mod
print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int H, W;
  cin>>H>>W;
  int N;
  cin>>N;
  int a[N];
  for(int i=0;i<N;++i) cin>>a[i];
  int ans[H][W];
  int index=0, num=0;
  for(int i=0;i<H;++i) {
    if(i%2==0) {
      for(int j=0;j<W;++j) {
        ans[i][j] = index+1;
        num++;
        if(a[index]==num) {
          index++;
          num=0;
        }
      }
    }
    else {
      for(int j=W-1;j>=0;--j) {
        ans[i][j] = index+1;
        num++;
        if(a[index]==num) {
          index++;
          num=0;
        }
      }
    }
  }
  for(int i=0;i<H;++i) {
    for(int j=0;j<W;++j) {
      cout<<ans[i][j]<<" ";
    }
    cout<<endl;
  }
}



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

int main(){
  int N;
  cin >> N;
  set<int64_t> s;
  priority_queue<int64_t> pq;
  for(int i=0;i<N;i++){
    int64_t a;
    cin >> a;
    if(s.count(a)){
      pq.push(a);
      s.erase(a);
    }else{
      s.insert(a);
    }
  }
  if(pq.size()<=1){
    cout << 0 << endl;
  }else{
    int64_t max = pq.top();
    pq.pop();
    cout << max*pq.top() << endl;
  }
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define  st first
#define  nd second
void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"
#define int long long

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef cc_hash_table<int, int, hash<int > > ht;

#define maxn 1000000
#define M   1000000007


int32_t main(){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int n ;
  cin >> n ;

  vector <int> a(n) , b(n) ;
  for ( int i = 0 ; i< n ; i++ ){
    cin >> a[i] ;
  }
   for ( int i = 0 ; i< n ; i++ ){
    cin >> b[i] ;
  }
  int x=  0 ;
  int y = 0 ;
  vector <int> v  ;
  for ( int i = 1 ; i<=n ; i++)
    v.push_back(i);
  int t=0 ;
  do {
    if(a == v)
        x = t ;
    if(b==v)
        y = t ;
    t++;
  }while (  next_permutation(v.begin() , v.end()));
  cout << abs(x-y) ;
  return 0 ;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    // 整数の入力
    long n,x[100],y[100],h[100],hm=0;
    bool fl=false;
    cin >> n;
    for(long i=0;i<n;i++){
      cin>>x[i]>>y[i]>>h[i];
      hm=max(hm,h[i]);
    }
    for(long i=hm;i<hm+220;i++){
      for(long j=0;j<=100;j++){
        for(long k=0;k<=100;k++){
          for(long l=0;l<n;l++){
            if(max(0l,i-abs(x[l]-j)-abs(y[l]-k))==h[l]){
              fl=true;
            }
            else{
              fl=false;
              break;
            }
          }
          if(fl){
            cout<<j<<" "<<k<<" "<<i;
            break;
          }
        }
        if(fl){
          break;
        }
      }
      if(fl){
        break;
      }
    }
    // スペース区切りの整数の入力

}

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

using namespace std;
using ll = long long;

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

const int mod = 1e9 + 7;

ll modpow(ll k, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * k % mod;
    k = k * k % mod;
    n /= 2;
  }
  return res;
}

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

  ll f[m + 1];
  f[0] = 1;
  rep(i, m) f[i + 1] = (i + 1) * f[i] % mod;
  ll fi[m + 1];
  rep(i, m + 1) fi[i] = modpow(f[i], mod - 2);

  auto p = [&](ll a, ll b) { return f[a] * fi[a - b] % mod; };

  auto choose = [&](ll a, ll b) {
    return (f[a] * fi[b] % mod) * fi[a - b] % mod;
  };

  ll ans = 0;
  for (int i = 0; i <= n; ++i) {
    ll now = choose(n, i);
    now = now * p(m - i, n - i) % mod;
    if (i & 1) now = mod - now;
    ans = (ans + now) % mod;
  }
  ans = ans * p(m, n) % mod;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11448
import copy
N, T = map(int, input().split())
t = list(map(int, input().split()))
tmp = copy.deepcopy(t)
for i in range(1, N):
    t[i] = tmp[i] - tmp[i-1]

ret = T
for i in range(1, N):
    if t[i] < T:
        ret -= T-t[i]
    ret += T
print(ret)


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

int main() {
  int n;
  long long k;
  cin >> n >> k;
  vector<pair<int, int>> ans(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    ans.at(i).first = a;
    ans.at(i).second = b;
  }
  sort(ans.begin(), ans.end());
  long long tmp = 0;
  for (int i = 0; i < n; i++) {
    tmp += ans.at(i).second;
    if (tmp >= k) {
      cout << ans.at(i).first;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

for i in range(N):
    H[i] = T - H[i]*0.006

t = 10**5
p = 0
for i in range(N):
    if abs(H[i]-A) < t:
        t = abs(H[i]-A)
        p = i+1
print(p)

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


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

    cout << (N + 1) / 2 << endl;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"

using namespace std;

int main() {
    int n, l; cin >> n >> l;
    
    int total = (2 * l + n - 1) * n / 2;
    if (l <= 0 && l + n - 1 < 0) {
        total -= l + n - 1;
    } else if (l > 0) {
        total -= l;
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath> 
#include <queue>
#include <functional>

using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
static const int dx[4] = {1, -1, 0, 0};
static const int dy[4] = {0, 0, 1, -1};


int main() {

    int n, k;
    cin >> n >> k;

    vector<int> x(n), y(n);
    vector<int> xaray, yaray;

    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        xaray.push_back(x[i]);
        yaray.push_back(y[i]);
    }

    sort(xaray.begin(), xaray.end());
    sort(yaray.begin(), yaray.end());

    ll ans = 1LL * (xaray[n-1] - xaray[0]) * (yaray[n-1] - yaray[0]);

    for (int xi = 0; xi < n; xi++) {
        for (int xj = xi + 1; xj < n; xj++) {
            for (int yi = 0; yi < n; yi++) {
                for (int yj = yi + 1; yj < n; yj++) {

                    int num = 0; 
                    ll lx = xaray[xi], rx = xaray[xj];
                    ll by = yaray[yi], uy = yaray[yj];

                    for (int  i = 0; i < n; i++) {
                        if (lx <= x[i] and x[i] <= rx and by <= y[i] and y[i] <= uy) {
                            num++;
                        }
                    }
                
                    if (num >= k) 
                        ans = min(ans, 1LL * (rx - lx) * (uy - by));
                }
            }
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
import kotlin.math.max

fun main() {
    println(solve())
}

val solve: () -> Any = {
    val (A, B, N) = readLongList()

    val n = N/B*B-1

    max((A*N)/B - A*(N/B), (A*n)/B - A*(n/B))
}

val mod: Int = 1_000_000_007

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun <T> T.alsoPrintln() = also { println(this) }

fun Boolean.toYesOrNo(yes: String = "Yes", no: String = "No") = if (this) yes else no

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

using namespace std;

int main(void) {
  string s;
  cin >> s;

  if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		String[] s = new String[n];
		int[] t = new int[n];
		int sum = 0;
		for (int i = 0; i < n; i++) {

			s[i] = scanner.next();
			sum += scanner.nextInt();
			t[i] = sum;
		}
		String x = scanner.next();
		for (int i = 0; i < n; i++) {
			if (s[i].equals(x)) {
				System.out.println(sum - t[i]);
				return;
			}
		}
	}

}


Measured memory_bytes: 21716
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    a = int(input())
    b = int(input())
    c = int(input())
    
    print((a+1-b)*(a+1-c))


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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int n,a = 0;
  string s;
  cin >> s;
  n = s.size();
  for (int i = 0; i < n; i++){
    if (i % 2 == 0 && (s[i] == 'R' || s[i] == 'U' || s[i] == 'D')){
      a += 1;
    }
    if (i % 2 == 1 && (s[i] == 'L' || s[i] == 'U' || s[i] == 'D')){
      a += 1;
    }
  }
  if (a == n){
    cout << "Yes\n";
  }
  else{
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    	int n;
    	double t,a;
    	cin>>n>>t>>a;
    	std::vector<double> v(n);
    	double mi=(double)INT_MAX;
    	int in=-1;
    	for (int i = 0; i < n; ++i)
    	{
    		cin>>v[i];
    		double ans=t-v[i]*0.006;
    		double dif=abs(ans-a);
    		if(dif < mi)
    		{
    			mi=dif;
    			in=i+1;
    		}
    	}
    	cout<<in<<endl;

    
	return 0;
}


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

int main(){
  int N; cin >> N;
  int A,B; cin >> A >> B;
  int res = 0;
  for(int i=0;i<N;i++){
    int t; cin >> t;
    if( A <= t && t < B ) continue;
    res++;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
//Date: 23/10/19
#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define pi 3.1415926535897932384
#define INF 2147483647
#define EPS 1e-8
#define MOD 1000000007
#define MAX 100005
using namespace std;

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

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
    #endif

    int a, b;

    cin>>a>>b;
    if(a >= 1 && a <= 9){
    	if(b >= 1 && b <= 9){
    		cout<<(a * b)<<endl;
    		return 0;
    	}
    }

    cout<<-1<<endl;

    return 0;
}


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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

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 main():
    n, k = LI()
    A = LI_()
    visited = set()
    path = []
    cur = 0
    while True:
        visited.add(cur)
        path.append(cur)
        cur = A[cur]
        if cur in visited:
            break
    for i, city in enumerate(path):
        if cur == city:
            loop_st = i
            break
    loop_en = len(path) - 1
    n_loop = loop_en - loop_st + 1
    
    if k > loop_st:
        k -= loop_st
        k %= n_loop
        print(path[loop_st + k] + 1)
    else:
        print(path[k] + 1)

main()



Measured memory_bytes: 33696
#include <iostream>

using namespace std;

int main()
{
    int a,b,z,c;
    cin>>a>>b;
  z=b%a;
  c=b-a;
   
    if(z==0)
    cout<<a+b;
    else 
    cout<<c;
    
    
     
    
    
    

    return 0;
}


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

using namespace std;

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  int n = s.length();
  int countOf1 = 0;
  int countOf2 = 0;
  for(int i = 0;i<n;i++){
    	if(s[i]=='1') {
        countOf1 ++;
      }else {
        countOf2 ++;
      }
  }
  if(countOf1<countOf2){
    cout << countOf1*2<<endl;
  }else{
    cout << countOf2*2 << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(){
  int o,n,k,i,j;
  int key;
  int A[110];
  scanf("%d",&n);
  for(i=1;i<=n;i++)scanf("%d",&A[i]);

   for(j=1;j<=n;j++)
    {
              key = A[j];
              i = j-1;
              while(i>0 && A[i]>key)
                {
                  A[i+1]=A[i];
                  i = i-1;
                }
              A[i+1] = key;
              for(k=1;k<=n;k++){
                if(k == n)
                  printf("%d\n",A[k]);
                else
                  printf("%d ",A[k]);
              }
    }

  return 0;
}



Measured memory_bytes: 2132
N, M = map(int,input().split())
L = []
R = []
for _ in range(M):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)

# Lの最大値以上、Rの最小値以下の整数の個数が答え。負になるときは0を出力
print(max(min(R)-max(L)+1,0))

Measured memory_bytes: 11052
import java.io.*;
    import java.util.*;
    import java.util.LinkedList;

    public class Main {

        public static void main(String[] args) throws IOException {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            InputReader in = new InputReader(inputStream);
            InputReader.OutputWriter out = new InputReader.OutputWriter(outputStream);
            BufferedReader reader = new BufferedReader(new InputReader(System.in));

            String s = in.next();
            String t = in.next();
            if(s.contains(t)) out.println(0);
            else {
                int ans = t.length();
                int n = t.length();
                for (int i = 0; i <=s.length() - n; i++) {
                    String sub = s.substring(i,i+n);
                    int diff = 0;
                    for (int j = 0; j < sub.length(); j++) {
                        if(sub.charAt(j) != t.charAt(j)) diff++;
                    }
                    ans = Math.min(ans,diff);
                }
                out.println(ans);
            }
            out.flush();
        }
        private static int gcd(int a, int b) {
            return b == 0 ? a : gcd(b,a%b);
        }
        private static void shuffle(int [] a) {
            for (int i = 0; i < a.length; i++) {
                int index = (int) (Math.random() * a.length);
                int temp = a[index];
                a[index] = a[i];
                a[i] = temp;
            }
        }
    }

    class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

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

        public Integer nextInt() {
            return Integer.valueOf(next());
        }
        public Long nextLong() {
            return  Long.valueOf(next());
        }
        public Double nextDouble () {
            return Double.valueOf(next());
        }


        static class OutputWriter extends PrintWriter {
            public OutputWriter(OutputStream outputStream) {
                super(outputStream);
            }

            public OutputWriter(Writer writer) {
                super(writer);
            }

            public OutputWriter(String filename) throws FileNotFoundException {
                super(filename);
            }

            public void close() {
                super.close();
            }
        }
    }

Measured memory_bytes: 33984
#include<bits/stdc++.h>
using namespace std;
#define MN 105
struct Point{
	double x,y;
	Point operator-(Point a){return (Point){x-a.x,y-a.y};}
	double operator /(Point a){return x*a.y-y*a.x;}
}P[MN];
int n,q[MN],rk[MN];
bool atbag[MN];
const double Pi=acos(-1);
double ans[MN];
#define cal(a,b,c) ((b-a)/(c-a))
bool cmp(int a,int b){return P[a].x<P[b].x||(P[a].x==P[b].x&&P[a].y<P[b].y);}
int main() {
	scanf("%d\n",&n);
	register int i;
	for(i=1;i<=n;i++) scanf("%lf%lf",&P[i].x,&P[i].y),rk[i]=i;
	sort(rk+1,rk+n+1,cmp);
	int t=0;
	for(int i=1;i<=n;i++){
		while(t>1&&cal(P[q[t-1]],P[q[t]],P[rk[i]])<=0) --t;
		q[++t]=rk[i];
	}
	int lt=t;
	for(int i=n-1; i; --i) {
		while(t>lt&&cal(P[q[t-1]],P[q[t]],P[rk[i]])<=0) --t;
		q[++t]=rk[i];
	}
	--t;
	for(int i=1;i<=t;i++) atbag[q[i]]=1;
	q[0]=q[t],q[t+1]=q[1];
	for(int i=1;i<=t;i++){
		Point p1=P[q[i-1]]-P[q[i]];
		Point p2=P[q[i+1]]-P[q[i]];
//		cout<<p1.y<<" "<<p1.x<<" "<<p2.y<<" "<<p2.x<<endl;
//		printf("%f %f %f %f\n",p1.y,p1.x,p2.y,p2.x);
		ans[q[i]]=fabs(0.5-((fabs(atan2(p2.y,p2.x)-atan2(p1.y,p1.x)))/(Pi*2.0)));
	}
	for(int i=1;i<=n;i++){
		if(!atbag[i]) printf("0.00000000000000000000\n");
		else printf("%lf\n",ans[i]);
	}
	return 0;
}

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

long long N,maxW;
long long dp[102][100002];
struct asdfklj{
    long long val,w;
}arr[102];

long long knapsack(long long i, long long current){
    if(current==0)return 0;
    if(current<0 || i==N)return INT_MAX;
    long long &ret=dp[i][current];
    if(ret!=-1)return ret;
    return ret = min(arr[i].w+knapsack(i+1,current-arr[i].val), knapsack(i+1,current));
}

int main(){
    cin>>N>>maxW;
    memset(dp,-1,sizeof(dp));
    for(long long i=0; i<N; i++)cin>>arr[i].w>>arr[i].val;
    for(long long i=100000;;i--)
        if(knapsack(0,i)<=maxW)
            printf("%d",i),exit(0);
}


Measured memory_bytes: 80000
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
# print(N,T,A)
# print(H)

def tmpt(T, x):
  return(T - x * 0.006)

mindiff = 100000
for iter, i in enumerate(H):
  diff = abs(A - tmpt(T, i))
  if mindiff > diff:
    mindiff = diff
    ans = iter + 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <numeric>

#define MAX 1000000

using namespace std;

int main() {
	bool prime[MAX];
	fill(prime, prime + MAX, true);
	prime[0] = prime[1] = false;
	for (int i = 2; i * i < MAX; i++) {
		for (int j = 2; i * j < MAX; j++) {
			if (!prime[i * j]) {
				continue;
			}
			prime[i * j] = false;
		}
	}

	int n, count;
	while (cin >> n) {
		count = 0;
		for (int i = 2; i <= n; i++) {
			if (prime[i]) {
				count++;
			}
		}
		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 3944
import sys
sys.setrecursionlimit(10**9)

class ABC(object):

    def __init__(self):
        pass


    def main(self):
        n = int(input())
        dd = [[int(_) for _ in input().split()] for i in range(n)]

        cnt = 0
        for d1, d2 in dd:
            if d1 == d2:
                cnt += 1
            else:
                cnt = 0

            if cnt >= 3:
                print('Yes')
                break
        else:
            print('No')

        return


if __name__ == "__main__":
    obj = ABC()
    obj.main()
    sys.exit(0)

Measured memory_bytes: 62540