akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 100000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

signed main(void) {
    int N; cin >> N;
    string str, last;
    set<string> S;
    bool out = false;
    rep(i, N) {
        cin >> str;
        if (S.count(str)) out = true;
        if (i > 0 && last[last.size()-1] != str[0]) out = true;
        S.insert(str);
        last = str;
    }
    if (out) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

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

using namespace std;

using ll = long long;
using vl = vector<ll>;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)

int main() {
	ll n;
	cin >> n;
	ll count = 0;
	ll last = -1;
	ll subcount = 0;
	FOR(i,0,n) {
		ll x;
		cin >> x;
		if (x != last) {
			if (last != -1) {
				count += subcount / 2;
			}
			last = x;
			subcount = 1;
		} else {
			subcount++;
		}
	}
	count += subcount / 2;
	cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;
bool debug = true;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<ll> P(N);
  for (ll i = 0; i < N; ++i) {
    ll p;
    cin >> p;
    P.at(i) = p - 1;
  }
  vector<ll> num(N, 0);
  for (ll i = 0; i < N; ++i) {
    if (P.at(i) == 0) {
      num.at(P.at(i)) = 1;
    }
    else {
      num.at(P.at(i)) = num.at(P.at(i) - 1) + 1;
    }
  }
  ll ans = 0;
  for (ll i = 0; i < N; ++i) {
    ans = max(ans, num.at(i));
  }
  // for (ll i = 0; i < N; ++i) {
  //   cout << num.at(i) << " ";
  // }
  cout << N - ans << "\n";
}


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

#define       sf                 scanf
#define       pf                 printf
#define       pb                 push_back
#define       sz                 200005
#define       inf                0x3f3f3f3f
#define       MOD                1000000007
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);

using namespace std;

typedef       long long int      ll;

int main()
{
    // READ
    optimize

    int tc;

    map <string, int> m;

    string s[sz];
    
    cin >> tc;
    
    for(int i = 0; i < tc; i++)
    {
    	cin >> s[i];

    	m[s[i]]++;
    }

    cout << "AC" << " x " << m["AC"] << endl;
    cout << "WA" << " x " << m["WA"] << endl;
    cout << "TLE" << " x " << m["TLE"] << endl;
    cout << "RE" << " x " << m["RE"] << endl;

    return 0;
}


Measured memory_bytes: 9800
def getint(): return int(input())
def getints(): return list(map(int, input().split()))

n,k = getints()
vs = getints()

res = 0
for take_operation in range(0, k + 1):
    sute_operation = k - take_operation
    if take_operation > n:
        continue
    for take_from_left in range(0, take_operation+1):
        take_from_right = take_operation - take_from_left
        item_values = []
        for i in range(0, take_from_left):
            item_values.append(vs[i])
        for i in range(0, take_from_right):
            item_values.append(vs[n - 1 - i])
        item_values = list(sorted(item_values, reverse=True))
        for i in range(sute_operation):
            if item_values and item_values[-1] < 0:
                item_values.pop()
        tmp = 0 if not item_values else sum(item_values)
        res = max(res, tmp)
print(res)


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  vector<int> A(1, vec.at(0));

  for(int i =0; i < N ; i++){
    A.push_back( vec.at( A.at(i)-1 ) );
  }

  for(int j = 0; j < N; j++){
    if(A.at(j) == 2){
      cout << j+1 << endl;
      break;
    }
    else if(j == N-1){
      cout << -1 << endl;
    }
  }
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; }
template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int A,B;
  cin >> A >> B;
  int sum = A + B;
  if (sum % 2 == 1) {
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << sum / 2 << endl;
  }

  return 0;
}

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

int main()
{
    long long l,r;;
    cin >> l >> r;
        if(l/2019!=r/2019)
            cout << 0 << endl;
        else
        {
            long long ans=999999999;
            for(long long i=l;i<=r;i++)
            {
                for(long long j=i+1;j<=r;j++)
                {
                    ans=min(i*j%2019,ans);
                }
            }
            cout << ans << endl;
        }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n;
	int i = 1;
	char c;
	char h[150];
	while (cin >> c) {
		n = i;
		h[i] = c;
		i++;
	}
	int ans = 0;
	for (int j = 1; j <= n / 2; j++) {
		if (h[j] != h[n + 1 - j])ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,M,i,d;
    scanf("%d%d",&N,&M);
    int H[N+1],C[N+1],A[M],B[M];
    for(i=1;i<=N;i++){
        scanf("%d",&H[i]);
    }
    for(i=1;i<=N;i++){
        C[i]=1;
    }
    for(i=0;i<M;i++){
        scanf("%d%d",&A[i],&B[i]);
        if(H[A[i]]<=H[B[i]])
           C[A[i]]=0;
        if(H[B[i]]<=H[A[i]])
            C[B[i]]=0;
    }
    d=0;
    for(i=1;i<=N;i++){
        if(C[i]==1)
           d++;
    }
    printf("%d\n",d);
    return 0;
}


Measured memory_bytes: 5388
#include<bits/stdc++.h>
using namespace std;
#define M ((ll)(1e9)+7)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;

bool comp(pair<ll,ll> a,pair<ll,ll> b)
{
    if(a.S<b.S)
    return true;
    return false;
}
void solve()
{
    int n;
    cin>>n;
    vector<pair<ll,ll>> v;ll a,b;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        v.pb({a-b,a+b});
    }
    sort(v.begin(),v.end(),comp);
    ll ma=v[0].S;int c=0;
    for(int i=1;i<v.size();i++)
    {
        if(v[i].F<ma)
        c++;
        else
        {
            ma=v[i].S;
        }
    }
    cout<<n-c<<endl;
}
int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <math.h>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;

	int sum = a + b;
	int sub = a - b;
	int mul = a * b;

	cout << max({ sum, sub, mul }) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

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

class Union_Find{
private:
    vector<int> par, rank;

    int find(int x){
        if(par[x] == x){
            return x;
        }else{
            return par[x] = find(par[x]);
        }
    }
public:
    Union_Find(int Max_Node){
        par.resize(Max_Node);
        rank.resize(Max_Node);
    }

    void init(int n) {
        for(int i = 0; i < n; i++){
            par[i] = i;
            rank[i] = 0;
        }
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y)return ;

        if(rank[x] < rank[y]){
            par[x] = y;
        }else{
            par[y] = x;
            if(rank[x] == rank[y])rank[x]++;
        }
    }

    bool same(int x, int y){
        return (find(x) == find(y));
    }
};

int main(){
  int n,q,com,x,y;
  cin>>n>>q;
  Union_Find uf(n+1);
  uf.init(n);
  rep(i,q){
    cin>>com>>x>>y;
    if(com==0){
      uf.unite(x,y);
    }else{
      cout<<uf.same(x,y)<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3196
N,M,R=gets.split.map(&:to_i)
r=gets.split.map(&:to_i)

len=(0..N).map{[1e9]*(N+1)}

M.times{
  a,b,c=gets.split.map(&:to_i)
  len[a][b]=len[b][a]=c
}

(1..N).each{|k|(1..N).each{|i|(1..N).each{|j|
  t = len[i][k]+len[k][j]
  len[i][j] = t if t < len[i][j]
}}}

p r.permutation.map{|a|
  a.each_cons(2).inject(0){|s,(r1,r2)|s+len[r1][r2]}
}.min


Measured memory_bytes: 2552
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions
bool second_greater(const pii& left, const pii& right) {
    return left.second > right.second;
}
#endif


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

    ll X, Y;  cin >> X >> Y;

    vl A;
    ll n = X;
    A.push_back(n);
    while(true){
        n *= 2;
        if (n > Y) break;
        A.push_back(n);
    }

    int ans = A.size();
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MOD = 1000000007;
const int MAX = 1100000;

long long fac[MAX], finv[MAX], inv[MAX];

void comInit() {
	fac[0] = fac[1] = inv[1] = finv[0] = finv[1] = 1;
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

long long nCr(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

int main() {
	comInit();
	int s; cin >> s;
	long long ans = 0;
	for (int i = 0; i <= s / 3; ++i) {
		int t = s - 3 * (i + 1);
		ans = (ans + nCr(t + i, t)) % MOD;
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 

#define INF 1000000000000000000
#define MOD 10007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

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

  //0101
  int ans1=0; 
  for(int i=0;i<S.size();i++){
    if(i%2&&S[i]!='1')ans1++;
    if(!(i%2)&&S[i]!='0')ans1++;
  }

  //1010
  int ans2=0;
  for(int i=0;i<S.size();i++){
    if(i%2&&S[i]!='0')ans2++;
    if(!(i%2)&&S[i]!='1')ans2++;
  }

  cout<<min(ans1,ans2)<<endl;
  return 0;
}



Measured memory_bytes: 512
// 'By Anki'
 
#include<bits/stdc++.h>
// #include<iostream>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define wr(i) cout<<#i<<" = "<<i<<",  ";
#define wre(i) cout<<#i<<"  =  "<<i<<endl;
#define all(v) v.begin(),v.end()
typedef long long ll;
#define lim 1000000007LL
typedef unsigned long long ull;
#define M 10004
using u64= uint64_t;

int main()
{
fast
ll t=1LL;
// cin>>t;
while(t--)
{
   ll n;
   cin>>n;
   vector<ll>v(n);
   for(auto &x:v)cin>>x;
   sort(all(v),greater<int>());
   ll ans=v[0];
   ll k=n-2;
   for(int i=1;i<n;i++){
     if(!k)break;
     ans+=v[i];
     if(--k <=0)break;
     ans+=v[i];
     if(--k<=0)break;
   }
   cout<<ans<<"\n";
}
} 

Measured memory_bytes: 4784
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

void max_self(ll& a, ll b) {
	a = max(a, b);
}

int main() {
	int n;
	cin >> n;
	int base = 1;
	while (base <= n) {
		base *= 2;
	}
	vector<ll> tree(base * 2), dp(n + 1);
	vector<int> height(n), weight(n);
	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		cin >> height[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> weight[i];
	}
	for (int flower = 0; flower < n; ++flower) {
		ll best = 0;
		ll x = height[flower] + base;
		while (x > 1) {
			if (x % 2 == 1) {
				max_self(best, tree[x - 1]);
			}
			x /= 2;
		}

		dp[height[flower]] = weight[flower] + best;

		for (int i = height[flower] + base; i >= 1; i /= 2) {
		    max_self(tree[i], dp[height[flower]]);
		}
	}
	for (auto each : dp) {
		max_self(ans, each);
	}
	cout << ans << endl;
}


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

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

  ll sum = 0;

  for (int i = 1; i <= n; i++)
  {
    if (i % 3 == 0 && i % 5 == 0){}
    else if(i%3 == 0){}
    else if(i%5 == 0){}
    else{
      sum += i;
    }
  }

  cout << sum;
}


Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

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

const ll LINF = 1e18;
const int INF = 1e9;
const int MOD = 1e9+7;

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

int h, n;
int a[1005], b[1005];
int dp[1005][10005];

int solve(int i, int resta){
	if(resta <= 0) return 0;
	if(i == n) return INF;
	if(dp[i][resta] != -1) return dp[i][resta];
	return dp[i][resta] = min(solve(i, resta-a[i])+b[i], solve(i+1, resta));
}

int main(){
	fastio;
	cin >> h >> n;
	memset(dp, -1, sizeof dp);
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}
	cout << solve(0, h) << endl;
	return 0;
}

Measured memory_bytes: 40064
#include <bits/stdc++.h>
using namespace std;
using namespace std;
 
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007

vector<vector<ll> >vii;

int main() 

{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,m,c=0;
    cin>>n>>m;
    vector<ll>v;
    double sum=0.0;
    f(i,0,n){
        ll x;
        cin>>x;
        v.pb(x);
        sum+=x;
    }
    sum=sum/4;
    sum=sum/m;
    f(i,0,n){
        if(v[i]>=sum) c++;
    }
    if(c>=m) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoder
{
    class Program2
    {

        static void Main(string[] args)
        {
            string[] input1 = Console.ReadLine().Split(' ');
            int N = int.Parse(input1[0]);
            int M = int.Parse(input1[1]);

            var duraciones = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
            int suma = duraciones.Sum();
            int resta = N - suma;

            if(resta < 0)
                Console.WriteLine("-1");
            else
                Console.WriteLine(resta.ToString());

        }
    }
}

Measured memory_bytes: 29260
import java.util.Scanner;
public class Main{
 public static void main(String[] args) {
   Scanner kbd = new Scanner(System.in);
   int x=kbd.nextInt();
   int g=0;
   if(x<500){
     g=0;
   }else{
   g=x/500;
}
 int p=0;
if(x-500*g<5){
   p=0;
 }else{
  p=(x-500*g)/5;
}

   int a=0;
   a=1000*g+5*p;
   System.out.println(a);
}
}


Measured memory_bytes: 23764
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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



	int x, a, b;
	cin >> a >> b;

	cout << max(0LL, a-b) << endl;
	return 0;
}



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

int main(){
  int N;
  cin >> N;
  vector<vector<int>> v(N,vector<int>(3));
  for (int i=0;i<N;i++){
    cin >> v[i][0] >> v[i][1] >> v[i][2];
  }
  int Cx=-1,Cy,Ht;
  for (int x=0;x<101;x++){
    for (int y=0;y<101;y++){
      int pos=1000010000,H=-1;
      for (int i=0;i<N;i++){
        if (v[i][2]==0){
          pos=min(pos,abs(v[i][0]-x)+abs(v[i][1]-y));
          if (H!=-1&&H>pos){
            break;
          }
        }
        else if (H==-1){
          if (v[i][2]+abs(v[i][0]-x)+abs(v[i][1]-y)<=pos){
            H=v[i][2]+abs(v[i][0]-x)+abs(v[i][1]-y);
          }
          else {
            break;
          }
        }
        else {
          if (H-abs(v[i][0]-x)-abs(v[i][1]-y)!=v[i][2]){
            break;
          }
        }
        if (i==N-1){
          Cx=x;
          Cy=y;
          Ht=H;
          break;
        }
      }
      if (Cx!=-1){
        break;
      }
    }
    if (Cx!=-1){
      break;
    }
  }
  cout << Cx << ' ' << Cy << ' ' << Ht << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int map[60][5];
int main(void) {
	vector<int> list;
	for (;;) {
		int  h,score=0;
		cin >> h;
		if (!h)return 0;
		int cnt = 1;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < 5; j++) {
				cin >> map[i][j];
			}
		}
		bool update = true;
		for (; update;) {
			update = false;
			for (int i = 0; i < h; i++) {
				int pos = 0, num = 0, cnt = 0;
				for (int j = 0; j < 5; j++) {
					if (num != map[i][j]) {
						if (cnt > 2 && num) {
							for (int j = pos; j < pos + cnt; j++) {
								map[i][j] = 0;
							}
							score += num*cnt;
							update = true;
						}
						pos = j;
						num = map[i][j];
						cnt = 1;
					}
					else cnt++;
				}
				if (cnt > 2 && num) {
					for (int j = pos; j < pos + cnt ; j++) {
						map[i][j] = 0;
					}
					score += num*cnt;
					update = true;
				}
			}
			for (int j = 0; j < 5; j++) {
				int pos = h - 1;
				for (int i = h - 1; i >= 0; i--) {
					if (map[i][j]) {
						map[pos][j] = map[i][j];
						if (pos != i)map[i][j] = 0;
						pos--;
					}
				}
			}
		}
		cout << score << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import numpy as np
n,m,x = map(int,input().split())
b = []
for _ in range(n):
    c = np.array(list(map(int,input().split())))
    b.append(c)
ans = float('INF')
d = np.array([x]*m)
for i in range(2**n):
    bag = []
    for j in range(n):
        if ((i>>j) & 1):
            bag.append(b[j])
    if bag:
        c = sum(bag)
        e = c[1:] - d
        if all(i >= 0 for i in e):
            ans = min(ans, c[0])
if ans == float('INF'):
    print(-1)
else:
    print(ans)

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


int main(){
	string s;
	cin>>s;
	int ans=1e9;
	for(char c='a';c<='z';c++){
	    int res=0,cnt=0;
	    for(auto &e : s){
	        cnt= c==e ? 0 : cnt+1;
	        res=max(res,cnt);
	    }
	    ans=min(ans,res);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long L = scan.nextLong();
        long R = scan.nextLong();
        
        long result = 2018;

        for (long i = L; i < R; i++){
            for (long j = i + 1; j <= R; j++){
                long mod = (i * j) % 2019;
                if(result == 0) break;
                if(result > mod) result = mod;
                if(result == 0) break;
            }
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 21844
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_7_B: Binary Trees

#include <algorithm>
#include <cstdio>

class BinaryTree {
public:
  static const int NIL = -1;

  struct Node {
    // id is index of nodes_
    int parent = NIL;
    int left = NIL;
    int right = NIL;
    unsigned int depth = 0u;
    unsigned int height = 0u;
  };

private:
  unsigned int n_;
  Node* nodes_;
  
public:
  BinaryTree(unsigned int n) : n_(n), nodes_(new Node[n]) { }

  ~BinaryTree() { delete[] nodes_; }

  Node& operator[](unsigned int id) { return nodes_[id]; }

  void set_depth_and_height()
  {
    (void)set_depth_and_height_internal(root(), 0u);
  }

  void print_nodes() const
  {
    for (auto id = 0u; id < n_; ++id) {
      print_node(id);
    }
  }

private:
  unsigned int set_depth_and_height_internal(int id, unsigned int depth)
  {
    if (id == NIL) {
      return 0u;
    }
    auto& node = nodes_[id];
    node.depth = depth;
    const auto left_height = set_depth_and_height_internal(node.left, depth + 1);
    const auto right_height = set_depth_and_height_internal(node.right, depth + 1);
    auto height = std::max(left_height, right_height);
    node.height = height;
    return height + 1;
  }

  int root() const
  {
    for (auto id = 0u; id < n_; ++id) {
      const auto& node = nodes_[id];
      if (node.parent == NIL) {
        return id;
      }
    }
    return NIL;
  }

  void print_node(unsigned int id) const
  {
    const auto& node = nodes_[id];
    std::printf("node %u: parent = %d, ", id, node.parent);
    std::printf("sibling = %d, degree = %u, ", sibling(id), degree(id));
    std::printf("depth = %u, height = %u, ", node.depth, node.height);
    std::printf("%s\n", type(id));
  }

  int sibling(unsigned int id) const
  {
    const auto& node = nodes_[id];
    if (node.parent == NIL) {
      return NIL;
    }
    auto left = nodes_[node.parent].left;
    auto right = nodes_[node.parent].right;
    auto sibling =
      (left != NIL && static_cast<unsigned int>(left) != id) ? left :
      (right != NIL && static_cast<unsigned int>(right) != id) ? right :
      NIL;
    return sibling;
  }

  int degree(unsigned int id) const
  {
    const auto& node = nodes_[id];
    auto degree = 0u;
    if (node.left != NIL) ++degree;
    if (node.right != NIL) ++degree;
    return degree;
  }

  const char* type(unsigned int id) const
  {
    const auto& node = nodes_[id];
    auto type =
      node.parent == NIL ? "root" :
      node.left == NIL && node.right == NIL ? "leaf" :
      "internal node";
    return type;
  }    
};

int main()
{
  unsigned int n;
  std::scanf("%u", &n);
  BinaryTree tree(n);

  for (auto i = 0u; i < n; ++i) {
    unsigned int id;
    int left, right;
    std::scanf("%u %d %d", &id, &left, &right);

    tree[id].left = left;
    if (left != BinaryTree::NIL) {
      tree[left].parent = id;
    }
    tree[id].right = right;
    if (right != BinaryTree::NIL) {
      tree[right].parent = id;
    }
  }
  tree.set_depth_and_height();

  tree.print_nodes();
}

// eof

Measured memory_bytes: 2720
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<queue>
#include<deque>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    string s;
    cin >> s;

    if(s[5] == '1' || s[6] > '4')cout << "TBD\n";
    else cout << "Heisei\n";

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		boolean[][] w = new boolean[H][W];
		int sy=0,sx=0;
		for(int i=0; i<H; i++) {
			char[] c = sc.next().toCharArray();
			for(int j=0; j<W; j++) {
				w[i][j] = c[j]=='#';
				if(c[j]=='S') {
					sy = i;
					sx = j;
				}
			}
		}

		int[] dy = {-1, 0, 1, 0};
		int[] dx = {0, -1, 0, 1};
		boolean[][] visited = new boolean[H][W];
		LinkedList<Long> q = new LinkedList<>();
		q.add(new Long(sy<<10 | sx));
		visited[sy][sx] = true;
		
		int nearest = 10000;
		
		while(!q.isEmpty()) {
			Long next = q.remove();
			int y = (int)((next>>10) & ((1<<10)-1));
			int x = (int)(next & ((1<<10)-1));
			int step = (int)(next>>20);
			
			int dis2Wall = Math.min(Math.min(y, H-1-y), Math.min(x, W-1-x));
			nearest = Math.min(nearest, dis2Wall);
			if(step<K) {
				for(int d=0; d<4; d++) {
					int ny = y + dy[d];
					int nx = x + dx[d];
					if(0<=ny && ny<H && 0<=nx && nx<W && !w[ny][nx] && !visited[ny][nx]) {
						q.add(new Long((step+1)<<20 | ny<<10 | nx));
						visited[ny][nx] = true;
					}
				}
			}
		}
		
		System.out.println((nearest+K-1)/K+1);
		sc.close();
	}
}


Measured memory_bytes: 45032
import sys
input = sys.stdin.readline

class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]
        # 正==子: 根の頂点番号 / 負==根: 連結頂点数

    def find(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        else:
            if self.size(x) < self.size(y):
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        x = self.find(x)
        return -self.parent[x]

    def is_root(self, x):
        return self.parent[x] < 0


N,M = map(int,input().split())
p = list(map(int,input().split()))
uf = UnionFind(N)
for i in range(M):
    x,y = map(int,input().split())
    uf.unite(x-1,y-1)

ans = 0
for i in range(N):
    if p[i]-1 == i:
        ans += 1
    else:
        if uf.same(p[i]-1,i):
            ans += 1
print(ans)

Measured memory_bytes: 14516
#include <bits/stdc++.h>
using namespace std;
#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 rep3(i, s, n) for (int i = (s); i <=(int) (n); i++)
#define chmax(x,y) x = max(x,y)

	int a[3005][3005];
	long long dp[3005][3005][5];


int main() {
	int R,C,n;
	cin >> R >> C >> n;

	rep(i, n) {
	int r,c,v;
		cin >> r >> c >> v;
		a[r][c]=v;
	}

	rep3(i,1,R){
 		rep3(j,1,C) {
			dp[i][j][3]=max(dp[i][j][3],dp[i][j][2]+a[i][j]);
			dp[i][j][2]=max(dp[i][j][2],dp[i][j][1]+a[i][j]);
			dp[i][j][1]=max(dp[i][j][1],dp[i][j][0]+a[i][j]);
			dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][0]);
			dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][1]);
			dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][2]);
			dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][3]);
			dp[i][j+1][0]=max(dp[i][j+1][0],dp[i][j][0]);
			dp[i][j+1][1]=max(dp[i][j+1][1],dp[i][j][1]);
			dp[i][j+1][2]=max(dp[i][j+1][2],dp[i][j][2]);
			dp[i][j+1][3]=max(dp[i][j+1][3],dp[i][j][3]);
		}
	}
	long long ans =0;
	rep(k,4) chmax(ans,dp[R][C][k]);

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


Measured memory_bytes: 391060
def is_unique(seq):
    return len(seq)==len(set(seq))

s=int(input())
lstA=[s]
cnt=1
while is_unique(lstA)==True:
    if s%2==0:
        s=s/2
    else:
        s=3*s+1
    lstA.append(s)
    cnt+=1
print(cnt)


Measured memory_bytes: 2940
import sys

read = sys.stdin.read
readline = sys.stdin.readline


def cmb(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n - r] % mod


def make_table2(n, mod=10 ** 9 + 7):
    # 元テーブル
    g1 = [0] * (n + 1)
    g1[0] = 1
    g1[1] = 1
    tmp = 1

    for i in range(2, n + 1):
        tmp = tmp * i % mod
        g1[i] = tmp

    # 逆元テーブル
    g2 = [0] * (n + 1)
    g2[-1] = pow(g1[-1], mod - 2, mod)
    tmp = g2[-1]

    for i in range(n - 1, -1, -1):
        tmp = tmp * (i + 1) % mod
        g2[i] = tmp

    return g1, g2


N, M, K = map(int, read().split())
mod = 998244353
g1, g2 = make_table2(N, mod)
answer = 0
for i in range(K + 1):
    answer = (answer + cmb(N - 1, i, mod) * M * pow(M - 1, N - i - 1, mod)) % mod

print(answer)


Measured memory_bytes: 24392
#include <iostream>
#define C std::cout<<
main() {int H,W,i,j;while(std::cin>>H>>W&&H){for(i=0;i<H;i++,C"#\n")for(j=0;j<W-1;)C(i*(i+1-H)*j++?".":"#");C"\n";}}

Measured memory_bytes: 3032
cnt = 1
while True:
    input_ = list(map(int, input().split()))

    if cnt % 2 == 1:
        n = input_
        if n[0] == 0:
            break
    else:
        scores = input_
        m = sum(scores) / len(scores)
        sigma = (sum([(score - m)**2 for score in scores]) / len(scores)) ** (1/2)
        print(sigma)
    cnt += 1



Measured memory_bytes: 5668
import java.util.*;

public class Main {
	static TreeMap<Integer,Integer> map;
	static String numstr;
	static int L;
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		while(true) {
			numstr=in.next();
			map=new TreeMap<>();
			L=Integer.parseInt(in.next());
			if(L==0)break;
			map.put(Integer.parseInt(numstr), 0);
			
			int i=1,reskey;
			while(true) {
				int max=0,min=0;
				int diff=L-numstr.length(); 
				char[] numchars=numstr.toCharArray();
				Arrays.sort(numchars);
				int a=toNum(numchars);
				
				
				for(int j=0;j<numchars.length/2;j++) {
					char tt=numchars[j];
					numchars[j]=numchars[numchars.length-1-j];
					numchars[numchars.length-1-j]=tt;
				}
				int b=toNum(numchars);
				
				if(a>b) {
					max=a;
					min=b;
				}
				else {
					max=b;
					min=a;
				}
				max*=Math.pow(10, diff);
				
				//System.out.printf("a%d=%d-%d=%d\n",i,max,min,max-min);
				
				if(map.containsKey(max-min)) {
					reskey=max-min;
					numstr=String.valueOf(max-min);
					break;
				}
				else {
					map.put(max-min, i);
					i++;
					numstr=String.valueOf(max-min);
				}
			}
			
			System.out.println(map.get(reskey)+" "+numstr+" "+(i-map.get(reskey)));
		}
	}
	
	static int toNum(char[] A) {
		int sum=0;
		for(int i=0;i<A.length;i++) {
			sum+=(A[i]-48)*Math.pow(10, i);
		}
		return sum;
	}
}



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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b){
  if (a > b) return a = b, true; else return false;
}

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

// 素因数分解
map< ll, int > PrimeFactor(ll n) {
  map< ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

void solve(){
  ll A, B;
  cin >> A >> B;

  ll gcdab = gcd(A, B);
  auto m = PrimeFactor(gcdab);

  int ans = 1;
  for(auto a : m) ans++;

  cout << ans << endl;
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <list>
#include <queue>
using namespace std;

int inf = (1 << 30);
int mod = 1e9 + 7;
int64_t inf64 = (1LL << 60);

template <typename T>
T gcd(T a, T b) {
    if(b == 0) return a;
    else return gcd(b, a % b);
}

template <typename T>
T lcm(T a, T b) {
    T g = gcd(a, b);
    return a / g * b;
}

bool check(vector<int> a, int index, int key){
    if(a[index] >= key) return true;
    else return false;
}

int lower_bound(vector<int> a, int key){
    int left = -1, right = a.size();
    while(right - left > 1){
        int mid = left + (left + right) / 2;
        if(check(a, mid, key)) right = mid;
        else left = mid;
    }
    return right;
}

int main(){

    string O, E;
    cin >> O >> E;

    for(int i = 0; i < E.length(); i++){
        cout << O[i];
        cout << E[i];
    }
    if(O.length() != E.length()) cout << O.back() << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ITP1_4_A_A_B_Problem
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split( ' ' ).Select( int.Parse ).ToArray();
            Console.WriteLine( "{0:d} {1:d} {2:f6}", input[ 0 ] / input[ 1 ], input[ 0 ] % input[ 1 ], (double)input[ 0 ] / input[ 1 ] );
        }
    }
}

Measured memory_bytes: 7952
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <memory>
#include <numeric>
#include <type_traits>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
typedef long long ll;


int main() {
    int n;
    cin >> n;
    ll res = 0;
    rep(i,n){
        if ((i+1)%3 == 0) continue;
        else if ((i+1)%5 == 0) continue;
        else {
            res += i+1;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cmath>
#include<cassert>
#include<cstdlib>
using namespace std;
#define EPS 0.0000001


main(){
  int tcase;   cin >> tcase;
  double x1, y1, x2, y2, x3, y3, x4, y4;
  for ( int i = 0; i < tcase; i++ ){
      cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;

  
      if ( abs((y2 - y1)*(x4 - x3) - (y4 - y3)*(x2 - x1) ) < EPS ) cout << "YES" << endl;
      else cout << "NO" << endl;
  }
}

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

int main(){
    int n,h;
    cin >> h >> n;
    vector<int> r(n);
    rep(i,n) cin >> r.at(i);
//  sort(r.begin(),e.end());
    for(int x:r) {
        h -= x;
    }
    cout << (h <= 0 ? "Yes" : "No") << endl;
}


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

int main()
{
    int N;
    cin >> N;
    int d[N];
    for (int i=0; i<N; i++) {
        cin >> d[i];
    }

    int result = 0;
    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            if (i>=j) {continue;}
            result += d[i]*d[j];
        }
    }

    cout << result;
 
    return 0;
}

Measured memory_bytes: 256
#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<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 unsigned 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;

std::vector<int> dec(int n){
	std::vector<int> v;
	int a=2;
	while(n>=a*a){
		if(n%a==0){
			v.push_back(a);
			n/=a;
		}
		else{
			a++;
		}
	}
	v.push_back(n);
	return v;
}

signed main(){
	cin>>N;
	vector<int> v=dec(N);
	set<int> U;
	REP(i,v.size()){
		U.insert(v[i]);
	}
	if(N==1){
		cout<<0<<endl;
		return 0;
	}
	int ans=0;
	for(auto x:U){
		DEB(x)END
		int s=x;
		while(N%s==0){
			N/=s;
			s*=x;
			ans++;
			DEB(s)END
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    long long K, A, B;
    cin >> K >> A >> B;

    long long cur = 1;
    if (K < A || B < A + 2) {
        cur += K;
    } else {
        cur = A;
        K -= A - 1;
        cur += K % 2;
        cur += K / 2 * (B - A);
    }
    cout << cur << "\n";


    /*for (int i = 0; i < K; ++i) {
        if (i + 1 < K && cur >= A && B >= A + 2) {
            cur -= A;
            cur += B;
            ++i;
        } else {
            ++cur;
        }
    }
    cout << cur << "\n";*/

    return 0;
}

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

int main(){
	int n;
	int pow10[]={10000,1000,100,10,1};
	while(!(cin>>n))return 0;
	while(1){
		for(int i=0;i<2;i++){
			for(int j=0;j<5;j++){
				if(i==(5<=n/pow10[j]%10))cout<<'*';
				else cout<<' ';
			}
			cout<<endl;
		}
		cout<<"=====\n";
		for(int i=0;i<5;i++){
			for(int j=0;j<5;j++){
				if(n/pow10[j]%5==i)cout<<' ';
				else cout<<'*';
			}
			cout<<endl;
		}
		if(cin>>n)cout<<endl;
		else break;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  set<int> s;
 
  int a, b, k;
  cin >> a >> b >> k;
  for (int i = a; i <= min(a + k - 1, b); i++)
    s.insert(i);
  for (int i = b; i >= max(b - k + 1, a); i--)
    s.insert(i);
 
  for (int h : s)
    cout << h << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=100005;
int n,k,a[maxn],b[maxn];
namespace seg{
	int l[maxn<<2],r[maxn<<2],mini[maxn<<2];
	inline void build(int x,int lq,int rq){
		l[x]=lq;r[x]=rq;mini[x]=1e9;
		if(lq==rq)return;
		int md=(lq+rq)>>1;
		build(ls,lq,md);build(rs,md+1,rq);
	}
	inline int query(int x,int k){
		if(l[x]==r[x])return mini[x];
		int md=(l[x]+r[x])>>1;
		if(k<=md)
			return min(mini[x],query(ls,k));
		else
			return min(mini[x],query(rs,k));
	}
	inline void update(int x,int lq,int rq,int v){
		if(lq>rq)return;
		if(lq<=l[x]&&r[x]<=rq){
			mini[x]=min(mini[x],v);
			return;
		}int md=(l[x]+r[x])>>1;
		if(lq<=md)update(ls,lq,rq,v);
		if(rq> md)update(rs,lq,rq,v);
	}
}
namespace szsz{
	i64 sum[maxn];
 	inline void add(int x,i64 v){
		for(;x<=maxn-5;x+=lowbit(x))sum[x]+=v;
	}
	inline i64 query(int x){
		int ans=0;
		for(;x;x-=lowbit(x))ans+=sum[x];
		return ans;
	}
}int l[maxn],r[maxn],w[maxn<<1],tot;
i64 f[maxn],g[maxn];
i64 ans=1e18;
inline void solve(){
	read(n);read(k);
	rep(i,1,n)read(a[i]),read(b[i]);int cur=0;
	rep(i,1,n){
		if(b[i]==2)l[i]=0,r[i]=k-1;
		else{
			if(a[i]*2>k){
				puts("-1");
				return;
			}
			l[i]=cur;r[i]=(cur-a[i]*2+k)%k;
		}
		cur=(cur-(a[i]*2)%k+k)%k;
	}int tot=0;
	rep(i,1,n)w[++tot]=l[i],w[++tot]=r[i];
	sort(w+1,w+1+tot);tot=unique(w+1,w+1+tot)-w-1;
	rep(i,1,n)l[i]=lower_bound(w+1,w+1+tot,l[i])-w,
			  r[i]=lower_bound(w+1,w+1+tot,r[i])-w;
	seg::build(1,1,tot);
	per(i,n,1){
		int t=seg::query(1,l[i]);
		if(t!=1e9)f[i]=min(f[t]+(w[l[t]]-w[l[i]]+k)%k,g[t]+(w[r[t]]-w[l[i]]+k)%k);
		    t=seg::query(1,r[i]);
		if(t!=1e9)g[i]=min(f[t]+(w[l[t]]-w[r[i]]+k)%k,g[t]+(w[r[t]]-w[r[i]]+k)%k);
		if(l[i]<=r[i])seg::update(1,1,l[i]-1,i),seg::update(1,r[i]+1,tot,i);
		else seg::update(1,r[i]+1,l[i]-1,i);
	}
	rep(i,1,n){
		if(szsz::query(l[i])==i-1)ans=min(ans,f[i]);
		if(szsz::query(r[i])==i-1)ans=min(ans,g[i]);
		if(l[i]<=r[i])szsz::add(l[i],1),szsz::add(r[i]+1,-1);
		else szsz::add(1,1),szsz::add(r[i]+1,-1),szsz::add(l[i],1);
	}
	rep(i,1,n)ans+=2*a[i];
	printf("%lld\n",ans);
}
int main(){
	solve();
	return 0;
}


Measured memory_bytes: 9216
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 2333333;
int n;char s[N],t[N];
int a[N],lzyp,lzyc,off,v[N];
char getc(int i){return lzyp<=i?lzyc:s[i];}
inline int query(int p){int r=0;while(p)r+=v[p],p-=p&-p;return r;}
inline void modify(int p, int x){while(p<=2*n+1)v[p]+=x,p+=p&-p;}
int main() {
	read(n);scanf("%s%s",s+1,t+1);lzyp=n+1;
	for(int i=n,j=n;i>=1;i--){
		s[i]=getc(i);//if(lzyp<=i)s[i]=lzyc;
		if(s[i]!=t[i]){
			j=min(j,i-1);while(j&&getc(j)!=t[i])j--;
		//	printf("find %d %d\n",i,j);
			if(!j){puts("-1");return 0;}
			lzyp=j;lzyc=s[j];
			
		//	printf("seg %d %d\n",j,i);
			int rec=query(off+i)+1;
			off++;
			modify(j+off,1);modify(i+off,-1);
			int now=rec-query(off+i);
			if(now){modify(i+off,now);modify(i+off+1,-now);}
		//	a[j+off]++;a[i+1+off]--;
			
			j--;
		}
	}
//	rep(i,1,n*2+1)a[i]+=a[i-1];
	int mx=0;rep(i,1,n*2+1)umax(mx,query(i));cout<<mx;
	return 0;
}


Measured memory_bytes: 14464
my $div = 998244353;

my $line = <STDIN>;
chomp $line;
my $n = $line;

my @x;
for (my $i = 0; $i < $n; $i++) {
    $line = <STDIN>;
    chomp $line;
    $x[$i] = [];
    ($x[$i]->[0], $x[$i]->[1]) = split ' ', $line;
}
@x = sort {$a->[0] <=> $b->[0]} @x;
my $i = 0;
my $cases = 1;
while ($i < $n) {
    my ($i2, $case) = count_a_cluster($i);
    $cases = $cases * $case % $div;
    $i = $i2;
}
print "$cases\n";

sub count_a_cluster {
    my ($i) = @_;
    my $reach = $x[$i]->[0] + $x[$i]->[1];
    my $j = $i + 1;
    my $cases = 1;
    while ($j < $n and $x[$j]->[0] < $reach) {
        my ($i2, $case) = count_a_cluster($j);
        $cases = $cases * $case % $div;
        $j = $i2;
    }
    return ($j, $cases + 1);
}


Measured memory_bytes: 294500
using System;
using System.Linq;

class Program
{
    public static void Main(string[] args) {
        string s = Console.ReadLine();
        int[] x = new int[s.Length-2];
        for (int i = 0; i < s.Length-2; i ++) {
            x[i] = 753 - int.Parse(s.Substring(i, 3));
            if (x[i] < 0) x[i] = x[i] * -1;
        }
        Console.WriteLine(x.Min());
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int h;
  vector<int> m;
  for(int i = 0; i < 10; i ++) {
    cin >> h;
    m.push_back(h);
  }

  sort(m.begin(), m.end());
  

  for(int i = 1; i <= 3; i ++) {
    cout << m[m.size()-i] << endl;
  }

  return 0;
}

Measured memory_bytes: 1220