akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
#include<map>
using namespace std;
int faa[200005],fab[200005],n,m,k,i,j,x,y,ans;
//set<int> toa[200005],tob[200005];
map<int,int> to[200005];
int finda(int x)
{
	if (faa[x]==x) return x;
	return faa[x]=finda(faa[x]);
}
int findb(int x)
{
	if (fab[x]==x) return x;
	return fab[x]=findb(fab[x]);
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>m>>k;
	for (i=1;i<=n;i++) faa[i]=fab[i]=i;
	for (i=1;i<=m;i++)
	{
		cin>>x>>y;
		faa[finda(x)]=finda(y);
	}
	for (i=1;i<=k;i++)
	{
		cin>>x>>y;
		fab[findb(x)]=findb(y);
	}
	for (i=1;i<=n;i++)
	{
		//cerr<<faa[i]<<' '<<fab[i]<<endl;
		finda(i);findb(i);
		to[faa[i]][fab[i]]++;
		//toa[finda(i)].insert(i);
		//tob[findb(i)].insert(i);
		//cerr<<faa[i]<<' '<<fab[i]<<endl;
	}
	/*for (i=1;i<=n;i++)
	{
		ans=0;
		//cerr<<endl;
		for (set<int>::iterator it=toa[faa[i]].begin();it!=toa[faa[i]].end();it++)
		{
			//cerr<<*it<<' ';
			if (tob[fab[i]].count(*it)) ans++;
		}
		//cerr<<endl;
		cout<<ans<<' ';
		//return 0;
	}*/
	for (i=1;i<=n;i++) cout<<to[faa[i]][fab[i]]<<' ';
	return 0;
}

Measured memory_bytes: 20224
import sys

a = []
for _ in range(3):
	a.append(list(map(int,input().split())))

n = int(input())
a2 = [[0 for _ in range(3)]for _ in range(3)]

for i in range(n):
	b = int(input())
	for j in range(3):
		for k in range(3):
			if a[j][k] == b:
				a2[j][k] = 1

for i in range(3):
	if sum(a2[i]) == 3:
		print('Yes')
		sys.exit()
tate = 0
for i in range(3):
	for j in range(3):
		if a2[j][i] == 1:
			tate += 1
	if tate == 3:
		print('Yes')
		sys.exit()
	tate = 0
naname = 0
for i in range(3):
	if a2[i][i] == 1:
		naname += 1
if naname == 3:
	print('Yes')
	sys.exit()
naname = 0
for i in range(3):
	if a2[i][-i-1] == 1:
		naname += 1
if naname == 3:
	print('Yes')
	sys.exit()
print('No')

Measured memory_bytes: 3064
import qualified Data.IntMap.Strict as M
import Data.List

mapKeysValue p f g = M.fromDistinctAscList . filter p . map (\(k,v) -> (f k, g v)) . M.toList

main = do
 [n,w] <- map read . words <$> getLine
 wvs <- map (map read . words) . lines <$> getContents
 print (knap n w wvs)

knap n w = maximum . M.elems . foldl' dp (M.singleton 0 0)
 where dp im [w',v'] = M.unionWith max im (mapKeysValue ((<=w).fst) (+w') (+v') im)

Measured memory_bytes: 2428
#include<iostream>

using namespace std;

int main(){
    
    int n;
    cin>> n;
    
    if(n==0) cout<< 1<< endl;
    else if(n==1) cout<< 2<< endl;
    else if(n==2) cout<< 1<< endl;
    else cout<< 0<< endl;
    
    return 0;
}

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

int main()
{
  int n, a[101];
  while (cin >> n, n){
    int res = 0;
    for (int i = 0; i < n; i++){
      cin >> a[i];
      res += a[i];
    }
    sort(a, a + n);
    res -= (a[0] + a[n - 1]);
    cout << (int)floor(res / (n - 2)) << endl;
  }
}

Measured memory_bytes: 3084
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


int main(void) {
    
    int n;
    cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    map<int,int> m;
    rep(i,n){
        if(m.find(v[i]-1)==m.end()){
    // fin(i);
            m[v[i]]=1;
        } else {
            m[v[i]]=m[v[i]-1]+1;
            m.erase(m.find(v[i]-1));
        }
    }
    int len=0;
    for(auto it=m.begin();it!=m.end();it++){
        len=max(len,it->second);
    }
    fin(n-len);
}


Measured memory_bytes: 12416
#include <stdio.h>

int main(void) {
  int min = 999999999,max = -999999999,n,i,j,r,a,b;
  scanf("%d",&n);
  if(n == 2){
    scanf("%d%d",&a,&b);
    printf("%d\n",b - a);
  }
  else{
    for(i = 0; i < n; i++){
      scanf("%d",&r);
      if(i != 0 && max < r - min)max = r - min;
      if(min > r)min = r;
      //printf("max = %d,min = %d\n",max,min);
    }
    printf("%d\n",max);
  }
  return 0;
}


Measured memory_bytes: 2108
#include<cstdio>
#include<iostream>
using namespace std;
int a[100100];
int main()
{
	int n,x;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		a[x]=i;
	}
	for(int i=1;i<=n;i++)
		cout<<a[i]<<" ";
	return 0;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    ll v = 1;
    string ret;
    while (n != 0) {
//        cout << n << endl;
        if (n % (2 * v)) {
            ret = '1' + ret;
            n -= v;
        } else {
            ret = '0' + ret;
        }
        v *= -2;
    }
    if (ret == "") {
        cout << 0 << endl;
    } else {
        cout << ret << endl;
    }
    return 0;
}

static int speedUp = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    return 0;
}();

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

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

const int INF = 1000000007;

int main(void){
	int n,T;
	cin>>n>>T;
	int c[110]={0}, t[110]={0};
	for(int i=0;i<n;i++) cin>>c[i]>>t[i];

	int mincost=INF;
	for(int i=0;i<n;i++){
		if(t[i] <= T){
			mincost = min(mincost, c[i]);
		}
	}

	if(mincost != INF) printf("%d\n", mincost);
	else printf("TLE\n");	

	return 0;
}

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

int main()
{
    int l, r, d, i, count = 0;

    cin >> l >> r >> d;

    for (i = l; i <= r; i++)
    {
        if (i % d == 0)
        {
            count++;
        }
    }

    cout << count << "\n";
    return 0;
}

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


int main() {
  int A, B;
  string S;
  cin >> A >> B >> S;
  bool flg = true;
  for (int i = 0; i < A + B + 1; ++i) {
    if (i == A && S[i] != '-') {
      flg = false;
      break;
    }
    if (i != A && S[i] == '-') {
      flg = false;
      break;
    }
  }
  if (flg) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main(){
    int n;
    cin >> n;
    list<int> L;
    for(int i=0;i<n;i++){
        char s[20];
        int a;
        cin >> s;
        if(s[0]=='i'){
            cin >> a;
            L.push_front(a);
        }
        else if(strlen(s)>6){
            if(s[6]=='F'){
                L.pop_front();
            }
            else{
                L.pop_back();
            }
        }
        else{
            cin >> a;
            auto itr=L.begin();
            while(itr!=L.end()){
                if(*itr==a){
                    L.erase(itr);
                    break;
                }
                else{
                    itr++;
                }
            }
        }
    }
    auto itr=L.begin();
    while(itr!=L.end()){
        cout << *itr;
        itr++;
        if(itr!=L.end()) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 34256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll n, m; cin >> n >> m;
    ll left = 0;
    ll right = 100100;

    rep(i,m){
        ll l, r; cin >> l >> r;
        left = max(left,l);
        right = min(right, r);
    }

    ll ans = max(right - left, -1ll) + 1;

    dunk(ans);
    
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

static const int MAX = 100001;

vector<ll> v(MAX);
vector<ll> f(MAX);

int n;
long long k;

bool check(ll x)
{

    ll ct = 0;
    for(int i = 0; i < n; ++i)
    {
        if(v[i] * f[i] > x)
        {
            ct+= v[i] - x/f[i];
        }
    }
    if(ct<= k)
        return true;
    return false;
}

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

    
    cin >> n >> k;
    v = vector<ll>(n);
    f = vector<ll>(n);

    
    for(int i =0; i<n; ++i)
    {
        cin >> v[i];
    }

    for(int i = 0; i<n; ++i)
    {
        cin >> f[i];
    }

    sort(v.begin(),v.end());
    sort(f.begin(),f.end());
    reverse(f.begin(),f.end());

    ll low = 0, high = 1000000000010;

    

    for(int i = 1; i< 50; ++i)
    {
        ll mid = (low+high)/2;
        if(check(mid))
        {
            high = mid;
        }
        else
        {
            low = mid+1;
        }
        
    }
    if(check(min(low,high)))
    {
        cout << min(low,high) << '\n';
    }
    else
    {
        cout << max(low,high) << '\n';
    }
    




    return 0;
}

Measured memory_bytes: 4720
l,r=map(int,input().split())
if l//2019 != r//2019:
  print(0)
else:
  l%=2019
  r%=2019
  m=2019
  for i in range(l,r):
    for j in range(i+1,r+1):
      m=min(m,(i*j)%2019)
  print(m)

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdint>
#include <functional>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;
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;
}

template <std::uint_fast64_t Modulus>
class modint {
    using u64 = std::uint_fast64_t;

   public:
    u64 a;

    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};

using mint = modint<MOD>;

int f(long long n) {
    int res = 0;
    while (n % 2 == 0) {
        n /= 2;
        res += 1;
    }
    return res;
}

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

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<long long> a(N), t(N);
    REP(i, N) {
        cin >> a[i];
        t[i] = f(a[i]);
        a[i] /= 2;
    }
    REP(i, N - 1) {
        if (t[i] != t[i + 1]) {
            cout << 0 << endl;
            return 0;
        }
    }

    long long tmp = a[0];
    REP(i, N - 1) { tmp = lcm(tmp, a[i + 1]); }
    if (tmp > M) {
        cout << 0 << endl;
    } else {
        cout << (M / tmp + 1) / 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>
#include<iostream>
#include <vector>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<math.h>
#include<map>
typedef long long int ll;
typedef unsigned long long ull;
using namespace std;
#define maxn 0x3f3f3f3f
#define eps 1e-9
#define pb push_back
const ll mod=1e9+7;
const ll N=1e5;
ll gcd(ll a,ll b){ll r,t;if(a<b){t=a;a=b;b=t;}r=a%b;while(r){a=b;b=r;r=a%b;}return b;}
ll lcm(ll a,ll b){ll g=gcd(a,b);return a/g*b;}
ll poww(ll a,ll b){a%=mod;ll s=1;while(b){if(b&1)s=s*a%mod;a=(a*a)%mod;b>>=1;}return s%mod;}

ll fac[1000050];

ll cc(ll x,ll y)
{
    return fac[x]*poww(fac[y]*fac[x-y]%mod,mod-2)%mod;
}

ll n,e[1000050],b[1000050];
int main()
{
    fac[0]=1;
    for(ll i=1;i<=1000000;i++)
        fac[i]=fac[i-1]*i%mod;
    e[0]=1;b[0]=1;
    for(ll i=1;i<=1000000;i++)
    {
        e[i]=e[i-1]*2%mod;
        b[i]=b[i-1]*8%mod;
    }
    scanf("%lld",&n);
    ll ans=0;
    for(ll i=2;i<=n;i++)
    {
        ans=(ans+(cc(n,i)*(e[i]-2)%mod*b[n-i])%mod)%mod;
//        cout<<(e[i]-2)*b[n-i]<<endl;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 26572
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int num, i, max=0, sum=0, max_num;
    int *array;

    scanf("%d", &num);
    array=(int*)malloc(sizeof(int)*num);
    for(i=0;i<num;i++){
        scanf("%d", &array[i]);
        if(array[i]>max){
            max=array[i];
            max_num=i;
        }
    }

    for(i=0;i<num;i++){
        if(i!=max_num){
            sum+=array[i];
        }
    }

    if(sum>array[max_num]){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

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

  const int MOD = 1000000007;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }






int main() {

int N;
cin >> N;
vector<int>P(N);
REP(i, N) {
  cin >> P.at(i);
  P.at(i)--;
}

int ans = 0;
REP(i, N - 1){
  if(P.at(i) == i) {
    swap(P.at(i), P.at(i + 1));
    ans++;
}
}

if(P.at(N - 1) == N - 1) ans++;
print(ans);
}



Measured memory_bytes: 640
#include <iostream>

int main()
{
	int h, w;
	while (true)
	{
		std::cin >> h >> w;
		if (h == 0 && w == 0)break;
		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				if (i == 0 || i == h - 1 || j == 0 || j == w -1)
					std::cout << "#";
				else
					std::cout << ".";
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
ll int dp[1000][1000];
int main()
{
    int h,w;
    scanf("%d %d",&h,&w);
    char grid[h][w];
    for(int i=0;i<h;i++)
    {
        scanf("%s",grid[i]);
    }
    dp[h-1][w-1]=1;
    for(int i=h-1;i>=0;--i)
    {
        for(int j=w-1;j>=0;--j)
        {
            if(grid[i][j]=='.')
            {
                if(i+1<h&&grid[i+1][j]=='.')
                {
                    dp[i][j]=(dp[i][j]+dp[i+1][j])%mod;
                }
                if(j+1<w&&grid[i][j+1]=='.')
                {
                    dp[i][j]=(dp[i][j]+dp[i][j+1])%mod;
                }
            }
        }
    }
    printf("%lld",dp[0][0]);
}


Measured memory_bytes: 9088
n = gets.to_i
n.times do
    s = gets.chomp
    a = [s]
    (1..s.size-1).each{|i|
        x, y = s[0..i-1], s[i..-1]
        a << x + y.reverse
        a << x.reverse + y
        a << x.reverse + y.reverse
    }
    p (a + a.map(&:reverse)).uniq.size
end

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

int main(){
    int n; cin>>n;
    string s; cin >> s;
    int r=0;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='R') r++;
    }
    cerr << r << endl;
    int lw=0;
    for(int i=0; i<r; i++){
        if(s[i]=='W') lw++;
    }

    cout << lw << endl;
}


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

using namespace std;

const int N = 2000;

char maze[N + 5][N + 5];
int val[N + 5][N + 5];

int main(){
	memset(val,0,sizeof val);
	int r, c; scanf("%d %d",&r,&c);
	for(int i=1; i<=r; i++) scanf("%s",maze[i] + 1);
	for(int i=1; i<=r; i++){
		int lt = 1;
		for(int j=1; j<=c; j++){
			if(maze[i][j] == '#'){
				for(int k=lt; k<j; k++){
					val[i][k] += j - lt;
				}
				lt = j+1;
			}
		}
		for(int k=lt; k<=c; k++){
			val[i][k] += c+1 - lt;
		}
	}
	for(int j=1; j<=c; j++){
		int lt = 1;
		for(int i=1; i<=r; i++){
			if(maze[i][j] == '#'){
				for(int k=lt; k<i; k++){
					val[k][j] += i - lt;
				}
				lt = i+1;
			}
		}
		for(int k=lt; k<=r; k++){
			val[k][j] += r+1 - lt;
		}
	}
	int maxi = 0;
	for(int i=1; i<=r; i++){
		for(int j=1; j<=c; j++){
			maxi = max(maxi, val[i][j]-1);
		}
	}
	printf("%d\n",maxi);
	return 0;
}

Measured memory_bytes: 19840
S = input()

s = []
for c in S:
    s.append(c)

operator=[]    
for i in range(2**3):
    op = ['+']*3 + ['']
    for j in range(3):
        if (i>>j) & 1:
            op[2-j] = '-'

    operator.append(op)

F = []
for op in operator:
    f = "".join(a+b for a, b in zip(s,op))
    F.append(f)


for fm in F:
    if eval(fm)==7:
        print(fm + '=7')
        break


Measured memory_bytes: 3064
import java.util.*;
import static java.lang.Math.*;
public class Main {
	static Scanner in;
	public static void main(String[] args) {
		in = new Scanner(System.in);
		new Main().start();
	}
	private void start() {
		while(in.hasNext()) {
			System.out.println(solve(in.nextInt()));
		}
	}
	private long solve(int d) {
		long ans = 0L;
		for(int i = 0; i < 600/d; i++) ans+=(d*pow(d*i,2));
		return ans;
	}
}

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

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

string s;
int dp[100010][15];

signed main(){
	cin >> s;
	dp[0][0] = 1;
	for (int i = 0; i < (int)s.size(); i++) {
		if (s[i] == '?') {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 13; k++) {
					dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
				}
			}
		}
		else {
			int a = s[i] - '0';
			for (int j = 0; j < 13; j++) {
				dp[i + 1][(j * 10 + a) % 13] += dp[i][j];
			}
		}
		for (int j = 0; j < 13; j++) {
			dp[i + 1][j] %= mod;
		}
	}
	cout << dp[(int)s.size()][5] << endl;
}

Measured memory_bytes: 12160
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int solve(int n, int m, vector<int>& c) {
    vector<int> dp(n + 1, 50001);
    dp[0] = 0;

    for (int i = 0; i < n + 1; i++) {
        for (int j = 0; j < m; j++) {
            if (c[j] <= i) {
                dp[i] = min(dp[i], dp[i - c[j]] + 1);
            }
        }
    }

    return dp[n];
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> c(m, 0);
    for (int i = 0; i < m; i++) {
        cin >> c[i];
    }
    
    cout << solve(n, m, c) << endl;

    return 0;
}



Measured memory_bytes: 3180
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "l    ", long, "r");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, x, y;
    scan(n, x, y);
    x--, y--;
    auto cost = new long[][](n, n);
    foreach (i; iota(n))
    {
        foreach (j; iota(i + 1, n))
        {
            cost[i][j] = min(j - i, abs(j - y) + abs(i - x) + 1);
        }
    }
    auto ans = new long[](n);
    foreach (i; iota(n))
    {
        foreach (j; iota(i + 1, n))
        {
            ans[cost[i][j]]++;
        }
    }
    foreach (e; ans[1 .. $])
    {
        e.writeln();
    }
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

int main() {
	int a[5], k;
	int maxA = 0;
	int minA = 1e+9;
	
	int i;
	for (i = 0; i < 5; i++) {
		cin >> a[i];
		maxA = max(maxA, a[i]);
		minA = min(minA, a[i]);
	}
	cin >> k;
	
	if (k >= maxA - minA) { cout << "Yay!" << endl; }
	else { cout << ":(" << endl; }
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

void change(int *, int *);

int main(void)
{
	int x, y;
	
	while(1){
		scanf("%d %d", &x, &y);
		if(x == 0 && y == 0)
		break;
		int count = 0;
		if(x < y)
			change(&x, &y);
		while(y){
			count++;
			x %= y;
			change(&x, &y);
		}
		cout << x << ' ' << count << endl;
	}
	return 0;
}

void change(int *a, int *b)
{
	int temp;
	temp = *a;
	*a = *b;
	*b = temp;
	
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  vector<int> w(N);
  REP(i, N) w[i] = nextInt();
  int S = accumulate(ALL(w), 0);
  int ans = S;
  int t = 0;
  for (int i = 0; i < N; i++) {
    t += w[i];
    int u = S-t;
    ans = min(ans, abs(t-u));
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


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

int main(void) {
    int64_t N;
    int64_t minsum=LONG_MAX,sum=0;
    cin >> N;

    vector<int64_t> X(N);
    for(int i=0;i<N;i++) {
        cin >> X[i];
    }
    sort(X.begin(),X.end());

    for(int i=X[0];i<=X[N-1];i++){
        sum = 0;
        for(int j=0;j<N;j++) {
            sum+= ((X[j]-i) * (X[j]-i));
        }

        if(minsum > sum) minsum = sum;
    }

    cout << minsum << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator
#define VL V<LL>::iterator
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define MAX 1e18
#define MIN -1e18
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
V<LL>v;
map<LL,LL>u;
int main()
{
    LL n,m,i,j,k,p,q,o,l,s,t,z=0,r;
    string a,b;
  cin>>n;
  p=0;
  q=MAX;
  for(i=0;i<n;i++)
  {
      cin>>o;
      v.PSB(o);
      p=max(p,o);
      q=min(q,o);
  }
  k=MAX;
  for(i=q;i<=p;i++)
  {
      l=0;
      for(j=0;j<v.SZ;j++)
      {
          l+=((i-v[j])*(i-v[j]));
      }
      k=min(l,k);
  }
  cout<<k<<endl;
}



Measured memory_bytes: 256
A, B = map(int, input().split())

def calc(x):
  if x <= 0:
    return 0
    
  ans = 0

  # i桁目の偶奇を調べる
  for i in range(50):
      # 0桁目 -> 周期2
      # 1桁目 -> 周期4
      # 2桁目 -> 周期8
      # ...
      loop = 2 ** (i+1)
      cnt = (x // loop) * (loop // 2)
      cnt += max(0, (x % loop) - (loop // 2) + 1)

      # その桁の１の数が奇数だったら足す
      if cnt % 2 == 1:
          ans += 1 << i
 
  return ans

ans = calc(B) ^ calc(A-1)
 
print(ans)

Measured memory_bytes: 3064
#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};

vector<vl> g, ans(2);
ll n, m;
vb seen;

void f(ll i, ll t) {
  for(auto v : g[i]) {
    if(seen[v]) continue;
    seen[v] = true;
    ans[t].push_back(v + 1);
    f(v, t);
    break;
  }
}

int main() {
  cin >> n >> m;
  g.resize(n);
  ll s1, s2;
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
    if(i == 0) {
      s1 = a;
      s2 = b;
    }
  }
  seen.resize(n, false);
  seen[s1] = true;
  seen[s2] = true;
  ans[0].push_back(s1 + 1);
  ans[1].push_back(s2 + 1);
  f(s1, 0);
  f(s2, 1);
  reverse(all(ans[0]));
  cout << ans[0].size() + ans[1].size() << '\n';
  for(auto v : ans[0]) cout << v << ' ';
  for(auto v : ans[1]) cout << v << ' ';
  cout << endl;
}

Measured memory_bytes: 13560
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define int long long
#define _ ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL);
#define dbg(x) cerr << #x << " is " << x << endl;
#define F(i,b) for(int i = 0 ; i < (int)(b) ; i++)
#define RF(j,b) for(int j = (int)(b)-1 ; j >= 0 ; j--)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pii pair<int,int>
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 2e5+7 ;
const int INF = 1e9 ;
const int MOD = INF + 7 ;
string s ;

void solve(){
	int n ;
	cin >>  n ;
	vi a(n) ;
	for(auto& x : a) cin >> x ;
	sort(all(a)) ;
	int ans = 0 ;
	for(int i = 0 ; i < n-2 ; i++){
		for(int j = i+1 ; j < n-1 ; j++){
			int sm = a[i]+ a[j] ;
			int idx = upper_bound(all(a), sm-1) - a.begin();
			ans += (idx-(j+1)) ;
		}
	}
		cout << ans << endl ;
}

int32_t main(){_
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}

}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

fn main() {
    input!{
        n: String,
    }

    if n.chars().filter(|&x| x == '7').count() != 0 {
        println!("Yes")
    } else {
        println!("No")
    }
}


Measured memory_bytes: 2160
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;

  int ans;

  int arr[1000000];


int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS


    int n,m;
    cin >> n >> m;


    for(int i = 1; i <= m; i++)
    {
      int l,r;
      cin >> l >> r;
      arr[l]++;
      arr[r+1]--;
    }



    for(int i = 1; i <= n;i++)
    {
      arr[i] += arr[i-1];
      ans += arr[i] == m;
    }
    cout << ans;


    return 0;
}


Measured memory_bytes: 4456
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

int main() {
	long long int N, Y, x, y, z;

	cin >> N >> Y;
	
	if (Y > N * 10000 || N * 1000 > Y) {
		x = -1;
		y = -1;
		z = -1;
	}

	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			z = N - i - j;
			if (i * 10000 + j * 5000 + 1000 * z == Y && z >= 0) {
				x = i;
				y = j;
				goto Ans;
			}
		}
	}

	x = -1;
	y = -1;
	z = -1;

	Ans:
	cout << x << " " << y << " " << z;

	return 0;
}

Measured memory_bytes: 3172
import java.util.*;

public class Main {

    static int N;
    static int K;
    static int[] P;
    static long[] C;
    static boolean[] used;
    static long ans = Long.MIN_VALUE;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        K = sc.nextInt();
        P = new int[N];
        C = new long[N];
        for (int i = 0; i < N; i++) {
            P[i] = sc.nextInt()-1;
        }
        for (int i = 0; i < N; i++) {
            C[i] = sc.nextLong();
        }
        for (int i = 0; i < N; i++) {
            long[] suma = new long[N+1];
            int len = 1;
            int nex = P[i];
            long sum = C[nex];
            if(ans < sum) ans = sum;
            suma[1] = sum;
            int maxidx = 1;
            long maxsum = Math.max(0, sum);
            while(i != nex && len < K){
                nex = P[nex];
                sum += C[nex];
                len++;
                if(ans < sum) ans = sum;
                suma[len] = sum;
                if(maxsum < sum){
                    maxsum = sum;
                    maxidx = len;
                }
            }
            if(0 < sum && len < K){
                long sho = K / len;
                long r = K % len;
                for (int j = 1; j <= r; j++) {
                    ans = Math.max(ans, sum * sho + suma[j]);
                }
                if(r < maxidx){
                    ans = Math.max(ans, sum * (sho-1) + maxsum);
                }
            }
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 57560
use std::io::prelude::*;
use std::str::FromStr;
pub struct Scanner<R: Read>(R);
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self(reader)
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let token = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| (b as char).is_whitespace())
            .take_while(|&b| !(b as char).is_whitespace())
            .collect::<Vec<u8>>();
        unsafe { std::str::from_utf8_unchecked(token.as_slice()) }
            .parse()
            .ok()
            .expect("Can't parse it.")
    }
    pub fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let mut sc = Scanner::new(stdin.lock());
    let mut out = std::io::BufWriter::new(stdout.lock());
    solve(&mut sc, &mut out);
    out.flush().ok().unwrap();
}
fn solve(sc: &mut Scanner<std::io::StdinLock>, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    let (n, a, b): (u32, u32, u32) = (sc.read(), sc.read(), sc.read());

    println!(
        "{}",
        (1..=n)
            .filter(|s| {
                let sum: u32 = s.to_string().chars().map(|c| (c as u8 - b'0') as u32).sum();
                sum >= a && sum <= b
            })
            .sum::<u32>()
    );
}


Measured memory_bytes: 2188
N = int(input())

SIZE = 101

base_data = None
data = []
for i in range(N):
    d = list(map(int, input().split()))
    data.append(d)
    if d[2] > 0:
        base_data = d
for x in range(SIZE):
    for y in range(SIZE):
        H = max(base_data[2] + abs(base_data[0] - x) + abs(base_data[1] - y), 0)
        all = True
        for d in data:
            h = max(H - abs(d[0] - x) - abs(d[1] - y), 0)
            if h != d[2]:
                all = False
                break
        if all:
            print(str(x) + " " + str(y) + " " + str(H))
            exit()

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  string s; cin >> s;
  cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No") << endl; 
  return 0;
}


Measured memory_bytes: 3476
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890

using namespace std;

int main()
{
    int i,j,k;
    int N;

    scanf("%d",&N);
    int cnt= 0;
    for(i=1;i<=N;i++)
    {
        for(j=1,k=1; k*10<=i; j++, k*=10);
        if(j%2==1)
        {
            // printf(">>>%d\n",i);
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
queue<int> q[1010];
queue<int> ans;
set<int> t;
queue<int> a;
int main()
{
	int N;
	int i,j,k;
	int p = 0;
	cin >> N;
	for(i=0;i<N;++i)
	{
		for(k=0;k<N-1;++k)
		{
			cin >> j;
			q[i].push(j-1);
		}
		a.push(i);
	}
	while(!a.empty())
	{
		p++;
		i = a.front();
		a.pop();
		j = q[i].front();
		q[i].pop();
		k = MIN(i,j)*10000+MAX(i,j);
		auto itr = t.find(k);
		if(itr != t.end())
		{
			ans.push(k);
			t.erase(itr);
			if(!q[i].empty())
				a.push(i);
			if(!q[j].empty())
				a.push(j);
		}
		else
		{
			t.insert(k);
		}
	}

	int days = 1;
	set<int> used;
	if(p==N*(N-1))
	{
		while(!ans.empty())
		{
			k = ans.front();
			ans.pop();
			i = k/10000;
			j = k%10000;
			if(used.count(i)||used.count(j))
			{
				used.clear();
				days ++;
			}
			used.insert(i);
			used.insert(j);
		}
	}
	else
	{
		days = -1;
	}
	cout << days << endl;
	return 0;
}




















Measured memory_bytes: 4992
#!/usr/bin/env python3
from bisect import bisect_left, bisect_right
import sys


def count(seq, element):
    "Return number of occurrences of item"
    i = bisect_left(seq, element)
    j = bisect_right(seq, element)
    return seq[i:j].count(element)


def solve(N: int, A: "List[int]"):
    ans = 0
    seta = sorted(list(set(A)))
    sa = sorted(A)
    for a in seta:
        if count(sa, a) % 2 != 0:
            ans += 1
    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)


if __name__ == "__main__":
    main()


Measured memory_bytes: 13196
fn solve() {
    let n: usize = read();
    let mut dic: HashMap<i64, usize> = HashMap::new();
    let mut s = 0;
    for i in 0..n {
        let a = read();
        match dic.get_mut(&a) {
            Some(v) => *v += 1,
            None => {
                dic.insert(a, 1);
            }
        }
        s += a;
    }
    let q: usize = read();
    for _ in 0..q {
        let b = read();
        let numb;
        match dic.get(&b) {
            Some(vb) => {
                numb = *vb;
            }
            None => {
                read::<usize>();
                println!("{}", s);
                continue;
            }
        }
        let c = read();
        match dic.get_mut(&c) {
            Some(vc) => {
                *vc += numb;
            }
            None => {
                dic.insert(c, numb);
            }
        }
        dic.insert(b, 0);
        s += (c - b) * numb as i64;
        println!("{}", s);
    }
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 4536
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  x = InputLine.to_i

  n = 0
  y = 100.to_f
  while y < x do
    y = (y * 1.01).floor.to_f
    n += 1
  end
  
  puts n.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 14304
import sys

input = sys.stdin.readline
_, m = map(int, input().split())

d = {}
for _ in range(m):
    p, s = input().split()
    p = int(p)
    if p in d:  # やっている(やった)問題
        if d[p][0]:  # AC済の問題だった場合
            continue
        if s == "WA":
            d[p][1] += 1
        else:
            d[p][0] = True
    else:  #  初めての問題
        if s == "WA":
            d[p] = [False, 1]  # 中身：AC判定と、ACまでのWAの数
        else:
            d[p] = [True, 0]

cnt_ac = 0
cnt_wa = 0
for v in d.values():
    if v[0]:
        cnt_ac += 1
        cnt_wa += v[1]

print(cnt_ac, cnt_wa)

Measured memory_bytes: 26116
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;
// get<K>(tuple型の変数)


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

    int n; cin >> n;
    vector<pair<int, int>> v(n);
    rep(i, n){
        int a; cin >> a;
        v[i]=make_pair(a, i+1);
    }
    sort(v.begin(), v.end());

    rep(i, n){
        if(i)cout << ' ';
        cout << v[i].second;
    }
    cout << endl;

    

    return 0;
}

Measured memory_bytes: 1664
N, K = map(int, input().split())
X = list(map(int, input().split()))
T = 10**18
for i in range(N-K+1):
  if X[i+K-1]<=0:
    T = min(T, -X[i])
  elif X[i]>=0:
    T = min(T, X[i+K-1])
  else:
    T = min(T, X[i+K-1]-X[i]+min(-X[i], X[i+K-1]))
print(T)

Measured memory_bytes: 20348
n = gets.to_i
s = gets.chomp
ans = s
cnt = 0
n.times do |i|
    if s[i] == '('
        cnt += 1
    else
        if cnt > 0
            cnt -= 1
        else
            ans = '(' + ans
        end
    end
end
cnt = 0
(n-1).downto(0) do |i|
    if s[i] == ')'
        cnt += 1
    else
        if cnt > 0
            cnt -= 1
        else
            ans = ans + ')'
        end
    end
end

puts ans

Measured memory_bytes: 1788
#include<stdio.h>
int main(){
    int n;
    int i,j;
    int sum;
    int cnt;
    while (1) {
        cnt=0;
        scanf("%d",&n);
        if(n==0){
            break;
        }
        for(i=0;i<n/2;i++){
            sum=0;
            for (j=i+1; sum<n; j++) {
                sum+=j;
            }
            if(sum==n){
                cnt++;
               
            }
        }
        printf("%d\n",cnt);
        
    }
    return 0;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

typedef long long ll;

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

ll lcm(int a,int b){
	//int table[2][100000];
	//for(int i = 0; i < 2; i++)
	//	fill(table[i],table[i]+100000,0);
	//// 1ÍÇ¿çÌà1Â¾¯Â
	//table[0][1] = 1;
	//table[1][1] = 1;

	//int t_a=a;
	//for(int i = 2; i*i <= t_a; i++){
	//	while(t_a % i == 0){
	//		table[0][i]++;
	//		t_a/=i;
	//	}
	//}
	//if(table[0][t_a] == 0)
	//	table[0][t_a]=1;

	//int t_b=b;
	//for(int i = 2; i*i <= t_b; i++){
	//	while(t_b % i == 0){
	//		table[1][i]++;
	//		t_b/=i;
	//	}
	//}
	//if(table[1][t_b] == 0)
	//	table[1][t_b]=1;

	//ll mul = 1;
	//for(int i = 2; i <= 100000; i++){
	//	if(table[0][i] == 0 && table[1][i] == 0)
	//		continue;
	//	else{
	//		int mc = max(table[0][i],table[1][i]);
	//		for(int j = 0; j < mc; j++)
	//			mul *= i;
	//	}
	//}

	ll mul = 1;
	mul = (b/gcd(a,b))*a;

	return mul;
}

int main(){

	ll a,b;
	while(1){
		cin >> a >> b;
		if(cin.eof()){
			break;
		}
		cout << gcd(a,b) << " " << lcm(a,b) << endl;
	}

	return 0;
}

Measured memory_bytes: 0
/* AtCoder コピペ */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repEq(i, n) for (int i = 0; i <= (int)(n); i++)
#define repVector(i, v) for (auto i = v.begin(); i != v.end(); ++i)

#define ifBetween(n, a, b) if (n > a && n < b)
#define ifBetweenEq(n, a, b) if (n >= a && n <= b)

int main() {
  	int N;
	cin >> N;
  
  	string S;
  	cin >> S;
  
  	int n = S.length();
  	char sc[n + 1];
    strcpy(sc, S.c_str());
  
  	vector<char> vec(sc, sc + sizeof sc / sizeof sc[0]);
  	vec.erase(unique(vec.begin(), vec.end()), vec.end());

  	cout << vec.size() - 1 << endl;
}


Measured memory_bytes: 512