akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
//#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
//#define fill(x,y) memset(x,y,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long


using namespace std;
typedef pair<int, int>P;

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


const int MAX = 500010;
const int MOD = 1000000007;
const ll INF = 10e17;

long long power(long long a, long long n) {//aのn乗を計算します。
	long long x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

signed main() {
	
	int k1 = -1, k2 = -1;
	int cnt = 0;//指数
	int A, B; cin >> A >> B;
	int rui = 1;
	int ans2 = 0;
	/*FOR(i, A, B + 1) {
		ans2 = ans2 ^ i;
	}
	print(ans2);*/
	if (A == B) {
		print(A);
		return 0;
	}
	while (k1 == -1 || k2 == -1) {
		if (cnt > 0)rui *= 2;
		int Pow = rui;
		if (Pow >= A) {
			if (k1 == -1)k1 = cnt;
		}
		if (Pow >= B) {
			if (k2 == -1)k2 = cnt;
		}
		cnt++;
	}
	//print(k1); print(k2);
	int ans = 0;

	int Pow1 = power(2, k1+1)-1;
	int Pow2 = power(2, k2-1);
	if (B <= 100000) {
		FOR(i, A, B + 1) {
			ans = ans ^ i;
		}
		print(ans);
		return 0;
	}
	if (k1 <= 2) {
		FOR(i, A, 4) {
			ans = ans ^ i;
		}
	}
	else{
		for (int i = A; i <= Pow1; i++) {
			ans = ans ^ i;
			if (i % 4 == 3)break;
		}
	}
	for (int i = B; i >= Pow2; i--) {
		ans = ans ^ i;
		if (i % 4 == 0)break;
	}

	
	//if (k1 > 1) {
	//	for (int i = A; i < power(2, k1); i++) {
	//		ans = ans ^ i;
	//		//print(1);
	//		if (i % 4 == 3)break;
	//	}
	//}
	//else if (B <= 3) {
	//	for (int i = A; i <= B; i++) {
	//		ans = ans ^ i;
	//	}
	//	print(ans); return 0;
	//}
	//else for (int i = A; i <= power(2, k1 + 1) - 1; i++)
	//{
	//	ans = ans ^ i;
	//	if (i % 4 == 3)break;
	//}

	///*for (int i = power(2, k2); i <= B; i++) {
	//	ans = ans ^ i;
	//}*/
	//int n = power(2, k2-1);
	//int m = 2;
	//if (B - n <= 10000) {
	//	for (int i = n; i <= B; i++) {
	//		ans = ans ^ i;
	//	}
	//	print(ans); return 0;
	//}
	//int Pow2 = power(2, k2);
	//while (true) {
	//	for (int i = B; i--;) {
	//		ans = ans ^ i;
	//		if (i % 4 == 0)break;
	//		if (Pow2>= B)break;
	//	}
	//}
	print(ans);
}

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

#define ll long long
#define fast_in_out  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main()
{
    fast_in_out;
    int p,q,r,x,y,z;
    cin >> p >> q >> r;
    x = p + q;
    y = q + r;
    z = r + p;
    cout << min(x,min(y,z));
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int dx = tx - sx, dy = ty - sy;
	rep(i, dy) cout << 'U';
	rep(i, dx) cout << 'R';
	rep(i, dy) cout << 'D';
	rep(i, dx) cout << 'L';
	cout << 'L';
	rep(i, dy+1) cout << 'U';
	rep(i, dx+1) cout << 'R';
	cout << "DR";
	rep(i, dy+1) cout << 'D';
	rep(i, dx+1) cout << 'L';
	cout << 'U' << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main(){

  int a,b,k; cin>>a>>b>>k;
  for(int i=0;i<k and a+i<=b;++i){
    cout<< a+i <<"\n";
  }
  int x=max(a+k,b-k+1);
  for(int i=x;i<=b;++i){
    cout<< i <<"\n";
  }
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin());  // 先頭文字削除
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1000000000;

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

    ll countR = 0;
    ll countG = 0;
    ll countB = 0;

    rep(i, N) {
        if (S[i] == 'R') {
            countR++;
        }
        if (S[i] == 'G') {
            countG++;
        }
        if (S[i] == 'B') {
            countB++;
        }
    }
    ll all = countR * countG * countB;
    // debug(all);
    ll count = 0;
    rep(i, N) {
        char first = S[i];
        rep2(j, i, N) {
            char second = S[j];
            int k = 2 * j - i;
            if (k > N) {
                continue;
            }
            char third = S[k];
            int a = int(first) + int(second) + int(third);
            if (a == 219) {
                count++;
            }
        }
    }

    COUT(all - count);
    return 0;
}

Measured memory_bytes: 3628
//@author yash2040
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define pb push_back
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
main()
{
	fast();
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n,m,X;
		cin>>n>>m>>X;
		int a[n][m];
		int x[n];
		for(int i=0;i<n;i++)
		{
			cin>>x[i];
			for(int j=0;j<m;j++)
			{
				cin>>a[i][j];
			}
		}
		int ans=LLONG_MAX;
		for(int i=0;i<=1<<n;i++)
		{
			int temp=0;
			int skill[m]={0};
			for(int j=0;j<n;j++)
			{
				if(i&(1<<j))
				{
					for(int k=0;k<m;k++)
					{
						skill[k]+=a[j][k];
					}
					
					temp+=x[j];
				}
			}
			int flag=0;
			for(int k=0;k<m;k++)
			{
				if(skill[k]<X)
				{
					flag=1;
					break;
				}
			}
			if(flag==0)
			ans=min(ans,temp);
			//int t=__builtin_popcount(i);
			
			
		}
		if(ans==LLONG_MAX)
		cout<<-1<<endl;
		else
		cout<<ans<<endl;
		
	}
	
}




Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
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; }


int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
#define rSORT(v) std::sort(v.begin(), v.end(),std::greater<int>())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,W;
    cin >> N >> W;
    vector<vector<ll>> dp(110, vector<ll>(100100, 0));
    vector<ll> w(110), v(110);
    for (int i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }

    for (int i = 0; i <= N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {
            if (sum_w - w[i] >= 0) {
                chmax(dp[i + 1][sum_w], dp[i][sum_w - w[i]] + v[i]);
            }

            chmax(dp[i + 1][sum_w], dp[i][sum_w]);
        }
    }

    cout << dp[N][W] << endl;
    return 0;
}

Measured memory_bytes: 87296
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using vi = vector<int>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define YESNO {cout<<"YES";}else{cout<<"NO";}
#define v(T) vector<T>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}
template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) {
  return i >> p.first >> p.second;
}
template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) {
  return i >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template<class T> ostream& operator<<(ostream& o, const vector<T>& v) {
  F0R(i, v.size()) {
    o << v[i] << ' ';
  }
  o << newl;
  return o;
}
template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) {
  for (auto& p : m) {
    o << p.first << ": " << p.second << newl;
  }
  o << newl;
  return o;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, i;
  cin >> N >> i;
  cout << (N - i + 1);
}
#endif


Measured memory_bytes: 3596
#include <iostream>

using namespace std;

int main()
{
	int n, x, t, a = 0;
	cin >> n >> x >> t;
	a = n / x;
	if(n % x != 0)
		cout << (a + 1) * t;
	else 
		cout << a * t;
return 0;
}


Measured memory_bytes: 3632
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, k] <- getIntList
    [r, s, p] <- getIntList
    ts <- grouping k <$> getLine
    print . sum $ map (solve r s p) ts

grouping k s = map (map snd) . groupBy g . sortBy f $ zip (cycle [1..k]) s
    where f (i, _) (j, _) = compare i j
          g (i, _) (j, _) = i == j

solve r s p ts = sum . map jan $ group ts
    where jan cs = ((length cs + 1) `div` 2) * (hand (head cs))
          hand c | c == 'r' = p
                 | c == 's' = r
                 | c == 'p' = s

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

int main()
{
	int l, r, k = 2019;

	cin >> l >> r;

	int m = l % 2019, p = r % 2019;

	if (m >= p || r > l + 2018)
		cout << 0 << endl;
	else {
		for (int i = m; i < p; i++) {
			for (int j = i + 1; j <= p; j++) {
				k = min(k, i * j % 2019);
				if (k == 0)
					break;
			}
			if (k == 0)
				break;
		}

		cout << k << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
using LL = long long;

int main() {
	int N, X, Y;
	cin >> N >> X >> Y;
	vector<int> ans(N+1, 0);
	vector<vector<int>> dist(N + 1, vector<int>(N+1, -1));

	for (int i = 1; i <= N - 1; i++) {
		queue<int> que;
		que.push(i);
		dist[i][i] = 0;
		while (!que.empty()) {
			int p = que.front();
			que.pop();
			if (p > 1 && dist[i][p - 1] == -1) {
				que.push(p - 1);
				dist[i][p - 1] = dist[i][p] + 1;
			}
			if(p+1 <= N && dist[i][p + 1] == -1){
				que.push(p + 1);
				dist[i][p + 1] = dist[i][p] + 1;
			}
			if (p == X && dist[i][Y] == -1) {
				que.push(Y);
				dist[i][Y] = dist[i][p] + 1;
			}


		}

		LL tem = 0;

	}
	for (int i = 1; i < N; i++) {
		for (int j = i + 1; j <= N; j++) {
			ans[dist[i][j]]++;
		}
	}

	for (int i = 1; i <= N - 1; i++) {
		cout << ans[i] << endl;
	}
	dist[0][0];
	return 0;

}

Measured memory_bytes: 18988
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define INF 1000000000;
int main(void){
    int n;
    cin>>n;
    vector<int>w(n);
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>w[i];
        sum+=w[i];
    }
    int s1=0,s2=sum;
    int ans=INF;
    for(int i=0;i<n;i++){
        s1+=w[i];
        s2-=w[i];
        int tmp=abs(s1-s2);
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

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

  ll n;
  cin >> n;
  map<ll, int> mp;
  REP(i, n) {
    ll tmp;
    cin >> tmp;
    mp[tmp]++;
  }

  if(n%2 != 0) {
    for (auto p: mp) {
      if(p.second != 2 && p.first != 0) {
        cout << 0 << endl;
        return 0;
      }
    }
  } else {
    for (auto p: mp) {
      if(p.second != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
  }

  ll ans = 1;
  for(int i=1; i<(n/2)+1; i++) {
    ans *= 2;
    ans %= 1000000007;
  }

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


Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n,a,b,c,x;
	while(cin>>n>>a>>b>>c>>x and n>0){
		int y[n]; rep(i,n) cin>>y[i];
		int roll=0,ans=-1;
		rep(i,10001){
			if(x==y[roll]) roll++;
			if(roll==n){
				ans=i; break;
			}
			x=(a*x+b)%c;
		}
		cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 3060
/* SANDEEP YADAV*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld double
#define lld long double
#define umap unordered_map<>
#define sz(x) ((ll)((x).size()))
#define all(x) (x).begin(),(x).end()
#define vi vector<int>
#define pi pair<int, int>
#define setp cout<<fixed<<setprecision(6)
#define loop(i,a,b)  for(int i=a;i<b;i++)
#define rloop(i,b,a) for(int i=b-1;i>=a;i--)
#define vl vector<ll>
#define pl pair<ll, ll>
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll gcd(ll a,ll b){ if(a<b) { a=a+b; b=a-b; a=a-b;}while(b!=0){ll r=a%b; a=b; b=r;} return a;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long power(long long a, long long b, long long m) {a %= m;long long res = 1;while (b > 0) {if (b & 1)res = res * a % m;a = a * a % m;b >>= 1;}return res;}
const int N=1000005;
void judge()
{
      #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
    #endif
}
struct myhash
{
    static uint64_t fxn(uint64_t x)
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator ()(uint64_t x) const
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return fxn(x + FIXED_RANDOM);
    }
};
void solve(int tc)
{
    
    ll n;
    cin>>n;

    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];

    ll ans[n]={};
    ans[0]=0;
    ans[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        ll x=0,y=0;
            x+=abs(a[i]-a[i-1])+ans[i-1];
            y+=abs(a[i]-a[i-2])+ans[i-2];
        ans[i]=min(x,y);
    }
    cout<<ans[n-1];
    return;
}
int main()
{
    fastio;
    //judge();

    int T=1;
    // cin>>T;
    for(int tc=1;tc<=T;tc++)
    {
        solve(tc);
    }
    return 0;
}

Measured memory_bytes: 5156
using System;
using static System.Console;
using static System.Int32;
using static System.Math;
using System.Linq;
using System.Collections.Generic;

class Solution
{
    static void Main()
    {
    lb:
        const long WARU = 1000000007;
        var sp = ReadLine().Split();
        var n = Parse(sp[0]);
        var k = Parse(sp[1]);
        var aryKosu = new long[k + 1];
        var ruijoDic = new Dictionary<int, long>();
        long r = 0;
        for (int gcb = k; 1 <= gcb; --gcb)
        {
            var bairitu = k / gcb;
            if (!ruijoDic.TryGetValue(bairitu, out var kosu))
            {
                kosu = bairitu;
                for(int i = 1; i < n; ++i)
                {
                    kosu = (kosu * bairitu) % WARU;
                }
                ruijoDic[bairitu] = kosu;
            }
            for(int i = 2; i <= bairitu; ++i)
            {
                kosu -= aryKosu[gcb * i];
                while (kosu < 0) kosu += WARU;
            }
            r = (r + gcb * kosu) % WARU;
            aryKosu[gcb] = kosu;
        }
        WriteLine(r);
        //goto lb;
    }
}


Measured memory_bytes: 28548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)


template<typename T>
struct LinearSystemIncidence {
  struct Edge {
    int id, to;
    bool fwd;
    Edge(int i, int t, bool f) : id(i), to(t), fwd(f) {}
  };

  int n, m;
  vector<T> x;
  vector<bool> seen;
  vector<vector<Edge>> G;
  
  LinearSystemIncidence(int n, vector<P> &E) : n(n), m(E.size()), G(n) {
    rep(i, m) {
      G[E[i].first].emplace_back(i, E[i].second, true);
      G[E[i].second].emplace_back(i, E[i].first, false);
    }
  }

  T dfs(vector<T> &b, int u) {
    seen[u] = true;
    T res = b[u];
    for (Edge e : G[u]) {
      if (seen[e.to]) continue;
      T tmp = dfs(b, e.to);
      x[e.id] = tmp * (e.fwd ? 1 : -1);
      res += tmp;

      // mod2
      x[e.id] %= 2;
      if (x[e.id] < 0) x[e.id] += 2;
      ////
    }
    res %= 2; // mod 2
    return res;
  }

  pair<bool, vector<T>> solve(vector<T> &b) {
    x.assign(m, 0);
    seen.assign(n, false);
    for (int s = 0; s < n; ++s) {
      if (seen[s]) continue;
      if (dfs(b, s)) return {false, vector<T>()};
    }
    return make_pair(true, move(x));
  }
};


int main() {
  ll n, m; cin >> n >> m;
  vector<P> E;
  Vll c(n);
  rep(i, m) {
    int u, v; cin >> u >> v;
    --u, --v;
    E.emplace_back(u, v);
    ++c[v];
  }

  LinearSystemIncidence<ll> LSI(n, E);
  auto sol = LSI.solve(c);

  if (!sol.first) {
    cout << -1 << "\n";
    return 0;
  }
  rep(i, m) {
    if (sol.second[i] == 0) swap(E[i].first, E[i].second);
    ++E[i].first;
    ++E[i].second;
    cout << E[i].first << " " << E[i].second << "\n";
  }
  return 0;
}

Measured memory_bytes: 12660
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    i64 a,b,k;
    cin>>a>>b>>k;
    int dir=0;
    while(k--){
        if(dir==0){
            if(a%2==1){
                a--;
            }

                a /= 2;
                b += a;
            dir = 1;
        }
        else if(dir==1){
            if(b%2==1){
                b--;
            }
                b /= 2;
                a += b;
                dir=0;
        }
    }

    cout<<a<<" "<<b<<endl;
    return 0;
}



Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::*;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use proconio::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

fn main() {
    input! {
        a: f64,
        b: f64,
        h: f64,
        m: f64,
    }

    let m_deg = m * 6.0;
    let h_deg = h * 30.0 + m / 2.0;

    eprintln!("{}", m_deg);
    eprintln!("{}", h_deg);
    let mut diff =
        if m_deg > h_deg { m_deg } else { h_deg } - if m_deg > h_deg { h_deg } else { m_deg };

    if diff > 180.0 {
        diff = 360.0 - diff;
    }

    eprintln!("{}", diff);

    println!(
        "{}",
        (a * a + b * b - 2.0 * a * b * (diff as f64).to_radians().cos()).sqrt()
    );

    // b^2+c^2-2bc cos alpha
}


Measured memory_bytes: 3036
#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>;
 
const int INF = 1001001001;
const int MOD = 998244353;

// auto MOD int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


// combination MOD prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < MOD);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} comb(1000005);

int main() {

    int N,M,K;
    cin >> N >> M >> K;
    
    mint ans = 0;
    rep(k,K+1) {
        mint tmp = 1;
        tmp *= comb(N-1,k)*M;
        mint tmp2 = M-1;
        tmp *= tmp2.pow(N-k-1);
        ans += tmp;
        //cout << tmp << endl;
    }
    cout << ans << endl;
}


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

s=sum(A)

ans=1
eda=1

if N==0:
  if A[0]==1:
    print(1)
  else:
    print(-1)
  exit()

if A[0]!=0:
  print(-1)
  exit()
  
for i in range(1,N+1):
  if eda*2<=s:
    eda*=2
  else:
    eda=s
  ans+=eda
  eda-=A[i]
  s-=A[i]
  if eda<=0 and i != N:
    print(-1)
    exit()
if eda!=0:
  print(-1)
  exit()
print(ans)

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

int main(){
  int n, a, b, c, x, y[10001];
  while(cin >> n >> a >> b >> c >> x, n){
    for(int j = 0 ; j < n ; j++){
      cin >> y[j];
    }
    int frame = 0, i = 0;
    while(true){
      if(x == y[i]) i++;
      if(i == n || frame > 10000) break;
      frame++;
      x = (a * x + b)%c;
    }
    if(frame > 10000){
      cout << -1 << '\n';
    }else{
      cout << frame << '\n';
    }
  }
  
  
  return 0;
}

Measured memory_bytes: 1164
# Fenwick Tree
class FenwickTree
  def initialize(arg)
    if arg.is_a?(Array)
      @n   = arg.size
      @data = Array.new(@n + 1) { 0 }
      arg.each_with_index { |e, i| add(i + 1, e) }
    elsif arg.is_a?(Integer)
      @n   = arg
      @data = Array.new(@n + 1) { 0 }
    else
      raise ArgumentError.new
    end
  end

  def add(i, x)
    while i <= @n
      @data[i] += x
      i += ( i & -i )
    end
  end

  def sum(l, r)
    _sum(r) - _sum(l)
  end

  def _sum(i)
    res = 0
    while i > 0
      res += @data[i]
      i -= ( i & -i )
    end
    res
  end
end

FeTree            = FenwickTree
BinaryIndexedTree = FenwickTree

n, q = gets.split.map { |e| e.to_i }
a    = gets.split.map { |e| e.to_i }

ft = FeTree.new(a)

q.times do
  t, u, v = gets.split.map { |e| e.to_i }

  if t == 0
    ft.add(u + 1, v)
  else
    puts ft.sum(u, v)
  end
end


Measured memory_bytes: 57400
#include <bits/stdc++.h>
typedef long long LL;
std::vector<int> vc;
const LL Mod = 1000000007;
LL qpow(LL a, LL times, LL mod)
{
	LL res = 1; LL tmp = a;
	while (times)
	{
		if (times & 1) res = res * tmp % mod;
		tmp = tmp * tmp % mod;
		times >>= 1;
	}
	return res;
}
LL F(LL n, LL m, LL mod)
{
	LL a = 1, b = 1;
	if (m > n) return 0;
	while (m)
	{

		a = a * n % mod; b = b * m % mod;
		m--; n--;
	}
	return (a * qpow(b, mod - 2, mod) % mod);
}
LL LU(LL n, LL m, LL mod)
{
	if (m == 0) return 1;
	return (F(n % mod, m % mod, mod) * LU(n / mod, m / mod, mod)) % mod;
}
int main()
{
    LL n, a, b;
    std::cin >> n >> a >> b;
    LL ans = (((qpow(2,n,Mod) - 1 + 2 * Mod) % Mod - LU(n, a, Mod) + 2 * Mod) % Mod - LU(n, b, Mod) + 2 * Mod) % Mod;
    std::cout<<ans<<'\n';
}

Measured memory_bytes: 256
n = int(input())
nums = list(map(int, input().split(' ')))
nums.sort()
total = 0

for i in range(n-1, -1, -1):
    l = 0
    r = i - 1
    while l < r:
        if nums[l] + nums[r] > nums[i]:
            total += r - l
            r -= 1
        else:
            l += 1
print(total)

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

using namespace std;

int main()
{
	string s;
	int n;
	cin >> n >> s;
	int r = 0, b = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') {
			r++;
		}
		else {
			b++;
		}
	}
	if (r > b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

int printMulti(int i, int j){
    printf("%dx%d=%d\n", i, j, i*j);
}


int main(){
    for (int k=1; k<10; k++){
        for (int l=1; l<10; l++){
            printMulti(k, l);
        }
    }
    return 0;
}


Measured memory_bytes: 3108
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,p=map(int,input().split())
def prime_factor(n):
    ass = []
    for i in range(2,int(n**0.5)+1):
        count=0
        while n % i==0:
            count+=1
            n = n//i
        if count!=0:
            ass.append((i,count))
    if n != 1:
        ass.append((n,1))
    return ass

ass=prime_factor(p)
for div,count in ass:
    pro*=div**(count//n)
print(pro)

Measured memory_bytes: 38512
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] str = in.readLine().split(" ");
    int[] a = new int[n];
    int aliceSum = 0;
    int bobSum = 0;
    for(int i=0 ; i<n; i++) {
      a[i] = Integer.parseInt(str[i]);
    }
    Arrays.sort(a);
    for(int i=n-1; i>=0; i=i-2) {
      aliceSum += a[i];
    }
    for(int i=n-2; i>=0; i=i-2) {
      bobSum += a[i];
      
    }
    System.out.println(aliceSum-bobSum);
  }
}

Measured memory_bytes: 32784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge
{
	int u;
	int v;
	int d;
	edge() :u(0), v(0), d(0) {}
	edge(int _u, int _v, int _d) :u(_u), v(_v), d(_d){}
};

vector<edge> G[100010];
int x[100010];
int vis[100010];

bool bfs(int s)
{
	queue<int> q;
	q.push(s);
	while (!q.empty())
	{
		int u = q.front();
		q.pop();
		for (int j = 0; j < G[u].size(); j++)
		{
			int v = G[u][j].v;
			int d = G[u][j].d;
			if (!vis[v])
			{
				vis[v] = true;
				x[v] = x[u] + d;
				q.push(v);
			}
			else
			{
				if (x[v] != x[u] + d)
				{
					return false;
				}
			}
		}
	}
	return true;
}
int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int l, r, d;
		cin >> l >> r >> d;
		G[l].push_back(edge(l, r, d));
		G[r].push_back(edge(r, l, -d));
	}
	bool flag = true;
	for (int i = 1; i <= n; i++)
	{
		if (!vis[i])
		{
			flag = bfs(i);
		}
		if (!flag) break;
	}
	cout << (flag ? "Yes\n" : "No\n");
	//system("pause");
}

Measured memory_bytes: 11592
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <regex>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vpii = vector<pii>;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end());
#define rSORT(a) sort((a).rbegin(),(a).rend());
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end());
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;

//sankou
//vvi = vector<vector<int>>(20, vector<int>(10, 0));

//seiki
//#include <regex>
/*bubun*/
//regex_search("u32", regex("[0-9]"));      // true
/*kanzen*/
//regex_match("u32", regex("(i|u)\\d+"));   // true

int isP(int n) {
    if(n<=1) return 0;
    FOR(i,2,(int)sqrt(n)) {
        if(n%i==0) return 0;
    }
    return 1;
}

int main() {

    int A,B;
    string s;
    cin >>A>>s>>B;
    if(s=="+") cout <<(A+B);
    if(s=="-") cout <<(A-B);

    return 0;
}





Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
vector<int> vt2[2010];
vector<int> gap;
vector<int> vt;
int p[2010],n,m,k;
int a[2010],sz[2010],update;
vector<vector<int>> vt1;
int ch[2010];
int find(int u)
{
	if (p[u] == u)return u;
	return p[u] = find(p[u]);
}
void merge(int u, int v)
{
	u = find(u); v = find(v);
	sz[v] += sz[u];
	for(int i=0;i<sz[u];i++)
	{
		vt2[v].push_back(vt2[u][i]);
	}
	vt2[u].clear();
	if (sz[v] >= m)
	{
		update = 1;
		sort(vt2[v].begin(), vt2[v].end());
		int t = sz[v] - m + 1;
		sz[v] = m - 1;
		for (int i = 0; i < t; i++)
		{
			gap.push_back(vt2[v][i]);
			vt2[v][i] = 2100000000;
		}
		sort(vt2[v].begin(), vt2[v].end());
	}
	sz[u] = 0;
	p[u] = v;
}
int getidx(int x)
{
	return lower_bound(vt.begin(), vt.end(), x) - vt.begin();
}
int main()
{
	scanf("%d %d %d", &n, &m, &k);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		vt.push_back(a[i]);
	}
	sort(vt.begin(), vt.end());
	int dap = vt[k - 1] - vt[0];
	vt.erase(unique(vt.begin(), vt.end()),vt.end());
	vt1.resize(vt.size());
	for (int i = 1; i <= n; i++)
	{
		a[i] = getidx(a[i]);
		vt1[a[i]].push_back(i);
	}
	for (int i = 1; i <= n; i++) {
		sz[i] = 1;
		p[i] = i;
		vt2[i].push_back(vt[a[i]]);
	}
	for (int i = vt.size() - 1; i >= 0; i--)
	{
		update = 0;
		for (int y = 0; y < vt1[i].size(); y++)
		{
			ch[vt1[i][y]] = 1;
			if (ch[vt1[i][y] - 1])
				merge(vt1[i][y] - 1, vt1[i][y]);
			if (ch[vt1[i][y] + 1])
				merge(vt1[i][y], vt1[i][y] + 1);
		}
		if (gap.size() >= k&&update)
		{
			sort(gap.begin(), gap.end());
			dap = min(gap[k - 1] - gap[0],dap);
		}
	}
	printf("%d", dap);
}

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

class Program
{
    static  int N,M,X;
    static int[][] data;
    static int answer=-1;
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        N = int.Parse(input[0]);
        M = int.Parse(input[1]);
        X = int.Parse(input[2]);

        data = new int[N][];
        for(int i=0;i<N;i++){
            input = Console.ReadLine().Split(' ');
            data[i] = new int[M+1];
            for(int j=0;j<M+1;j++){
                data[i][j]= int.Parse(input[j]);
            }
        }

        int[] skill = Enumerable.Repeat<int>(0,M+1).ToArray();//0がコスト、１～スキル

        for(int i=0;i<N;i++){
            search(i,skill);
        }

        Console.WriteLine(answer);

    }

    static void search(int s, int[] input_skill){
        for(int i=0;i<2;i++){
            int[] skill = input_skill;
            switch(i){
                //s番目の本を買う場合
                case 0:
                    skill = skill_sum(skill,data[s]);
                    break;
            }
            if(s+1<N){
                search(s+1,skill);
            }else{
                if(answer == -1 || skill[0]<answer){
                    if(checkSkill(skill)) answer = skill[0];
                }
            }
        }
    }
    static Boolean checkSkill(int[] skill){
        Boolean ret = true;

        for(int i=1;i<M+1;i++){
            if(skill[i]<X){
                ret = false;
                break;
            }
        }
        return ret;

    }
    static int[] skill_sum(int[] a, int[] b){
       
        if(a.Length != b.Length){
            return null;
        }

        int[] res = new int[a.Length];
        for(int i=0;i<a.Length;i++){
            res[i] = a[i]+b[i];
        }
        return res;

    }
    static int[] LoopFinder(int[] move, ref int[] route){
        int i=1;
        while(true){
            int next = move[i-1];
            if(route[next-1]>0||next == 1){
                return new int[2]{next, i};
            }else{
                route[next-1]=route[i-1]+1;
                i=next;
            }
        }
    }

    static int final_position(long step, int[] loop, int[] move, int[] route){
        //ループより前パターン
        if(step<route[loop[0]-1]){
            int res =1;
            for(int i=0;i<step;i++){
                res = move[res-1];
            }
            return res;
        }else{
            //ループの中
            step -= route[loop[0]-1];
            int len_loop = route[loop[1]-1]-route[loop[0]-1]+1;
            step = step % len_loop;
            int res = loop[0];
            for(int i=0;i<step;i++){
                res = move[res-1];
            }
            return res;
        }

    }
}


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

#define debug(x) cout<<#x<<"="<<x<<endl
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define mp make_pair

int absi(int a){
	if (a<0) return -a;
	return a;
}

int main(){
	int a,b,x;
	cin>>x>>a>>b;
	if (absi(a-x)>absi(b-x)) cout<<"B"; else cout<<"A";
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
vector<int> P,Q,R;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>x, P.push_back(x);
	FOR(i,N) cin>>x, Q.push_back(x);
	FOR(i,N) R.push_back(i+1);
	
	int num=0;
	int mask=0;
	do {
		if(P==R) mask|=1;
		if(Q==R) mask|=2;
		if(mask==1 || mask==2) num++;
	} while(next_permutation(ALL(R)));
	cout<<num<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

A = [A[i]-(i+1) for i in range(N)]
A.sort()
cumsum = [0]*N
cumsum[0] = A[0]
for i in range(1, N):
    cumsum[i] = cumsum[i-1] + A[i]
ans = 1e20
for i in range(N):
    tmp = -(cumsum[i]) + (cumsum[N-1]-cumsum[i]) + (i+1)*A[i] - (N-i-1)*A[i]
    ans = min(ans, tmp)
print(ans)



Measured memory_bytes: 113796
import copy
N=int(input())
A=list(int(input()) for _ in range(N))
a=copy.deepcopy(A)
a.sort(reverse=True)
x=a[0]
y=a[1]

for i in range(N):
    if A[i]==x:
        print(y)
    else:
        print(x)


Measured memory_bytes: 14572
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;

bool check(string s){
	REP(i,s.size()-1){
		int num=s[i]-'0';
		int num2=s[i+1]-'0';
		if(abs(num-num2)>1){
			return false;
		}
	}
	return true;
}

signed main(){
	cin>>N;
	queue<string> Q;
	if(N<=9){
		cout<<N<<endl;
		return 0;
	}
	int cnt=0;
	for(int i=1;i<=9;i++){
		Q.push(to_string(i));
	}
	while(Q.size()){
		string p=Q.front();Q.pop();
		cnt++;
		if(cnt==N){
			cout<<p<<endl;
			return 0;
		}
		int num=p.back()-'0';
		if(num!=0){
			Q.push(p+to_string(num-1));
		}
		Q.push(p+to_string(num));
		if(num!=9){
			Q.push(p+to_string(num+1));
		}
	}
	return 0;
}


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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main(){
  int n,a;
  cin >> n;
  
  rep(i,1,n+1){
    a = i*i;
    if(a > n){
      printf("%d\n",(i-1)*(i-1));
      return 0;
    }
    else if(a == n){
      printf("%d\n",a);
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
As=input()
if As[-1]=="2" or As[-1]=="4" or As[-1]=="5" or As[-1]=="7" or As[-1]=="9":
    print("hon")
elif As[-1]=="0" or As[-1]=="1" or As[-1]=="6" or As[-1]=="8":
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9116
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
	while(true) {
		int n, x;
		cin >> n >> x;
		if((n == 0) && (x == 0)) break;

		int count = 0;
		int imax = (x / 3 - 1 < n) ? (x / 3 - 1) : n;
		for(int i = 1; i <= imax; i++) {
			int jmax = (x - i) / 2;
			if(x - i - jmax == jmax) jmax -= 1;
			if(n < jmax) jmax = n;

			for(int j = i + 1; j <= jmax; j++) {
				int k = x - (i + j);
				if(k <= n) {
					count++;
				}
			}
		}
		cout << count << endl;
	}
	
    return 0;
}

Measured memory_bytes: 3024
import collections 

N=int(input())
A=list(map(int,input().split()))

A=collections.Counter(A)
A=list(A.items())
A.sort(reverse=True)
#print(A)

x,y=0,0
for a in A:
  if x and a[1]>=2:
    y=a[0]
    break
  if a[1]>=2:
    if a[1]>=4:
      x,y=a[0],a[0]
      break
    else:
      x=a[0]
#print(x,y)
print(x*y)

Measured memory_bytes: 21412
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int k, n;
	cin>>k>>n;
	int a[200020];
	for(int i=0; i<n; i++) cin>>a[i];
	int mx=0;
	for(int i=0; i<n-1; i++) mx=max(mx, a[i+1]-a[i]);
	mx=max(mx, k-a[n-1]+a[0]);
	cout<<k-mx<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll> stairs(n);
    for (ll i = 0; i < n; i++)
        cin >> stairs[i];
    bool can = true;

    for (ll i = max<ll>(0, n - 1); 1 <= i; i--)
    {
        if (stairs[i] + 1 == stairs[i - 1])
            stairs[i - 1]--;
        else if (stairs[i] + 1 < stairs[i - 1])
            can = false;
    }
    cout << (can ? "Yes" : "No") << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
        int N,K;
        int ans=1;
        scanf("%d", &N);
        scanf("%d", &K);
        for (int i = 0; i < N; i++) {
                if (K+ans>ans*2) {
                        ans *= 2;
                }else{
                        ans += K;
                }
        }
        printf("%d\n",ans);
        return 0;
}

Measured memory_bytes: 128
from collections import defaultdict
s = input()
n = len(s)

alp = defaultdict(list)
for i, a in enumerate(s):
    alp[a].append(i)

ans = 10 ** 9
for ind in alp.values():
    ind = [-1]+ind+[n]
    operate = -10**9
    for i, j in zip(ind[:-1], ind[1:]):
        operate = max(operate, j-i-1)

    ans = min(operate, ans)

print(ans)


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  int N,M,X;
  cin >> N >> M >> X;
  vector<int> A(100);
  int sum = 0;
  rep(i,M){
    int a;
    cin >> a;
    A.at(a) = 1;
    if(a <= X){
      sum ++;
    }
  }
  int rest = M - sum;
  cout << min(sum,rest) << endl;
  return 0;
}

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

int main(){
	int a, b;
	while (cin >> a >> b){
		int c = a + b;
		if (c == 0){
			cout << 1 << endl;
			continue;
		}
		int k = 0;
		while (c > 0){
			c = c / 10;
			k++;
		}
		cout << k << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
 class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        int n = in.nextInt();
        long t = in.nextLong();
        BigInteger b = new BigInteger("" + t);
        while (n > 1) {
            t = in.nextLong();
            BigInteger c = new BigInteger("" + t);
            BigInteger mul = b.multiply(c);
            mul = mul.divide(b.gcd(c));
            b = mul;
            n--;
        }
        System.out.println(b.toString());
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

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

    }
}


Measured memory_bytes: 22740
n=gets.to_i
a=[0]+gets.split.map(&:to_i)+[0]
 
d=0
for i in 0..n
  d+=(a[i+1]-a[i]).abs
end
for i in 0..n-1
  puts d-(a[i+1]-a[i]).abs-(a[i+2]-a[i+1]).abs+(a[i+2]-a[i]).abs
end

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  string s;
  cin>>n>>s;
  int ans = 0;
  REP(i,n+1){
    string a = s.substr(0,i);
    string b = s.substr(i);
    set<char> S,T;
    for(char c : a){
      S.insert(c);
    }
    for(char c : b){
      if(S.count(c))T.insert(c);
    }
    CHMAX(ans, (int)T.size());
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256