akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	vector< int > S(N);
	rep(i, N) cin >> S[i];
	int ans = 0;
	for (int t = 1; t < N; t++) {
		int tmp = 0;
		set< int > s;
		int l = 0, r = N - 1;
		s.insert(0);
		s.insert(N - 1);
		while (r > t) {
			tmp += S[l] + S[r];
			chmax(ans, tmp);
			// if (tmp == 35)
			// cout << t << " " << l << endl;
			l += t, r -= t;
			if (s.find(l) != s.end())
				break;
			s.insert(l);
			if (s.find(r) != s.end())
				break;
			s.insert(r);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7808
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
using base = complex<double>;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define M2 998244353
#define ll long long
#define pll pair<long, long>
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define ff first
#define ss second
#define pb push_back
#define db pop_back
#define mp make_pair
#define mt make_tuple
#define g(a, b) get<a>(b)
#define INF (ll)1e18 + 100
#define vl vector<ll>
#define vi vector<int>
#define vll vector<pair<ll, ll>>
#define vii vector<pair<int, int>>
#define all(v) v.begin(), v.end()
#define bset(a, p) ((a) | (1ll << (p)))
#define bchk(a, p) ((a) & (1ll << (p)))
#define bxor(a, p) ((a) ^ (1ll << (p)));
#define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a))
#define INT_SIZE 32
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/

#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
ll powM(ll x, ll y, ll m)
{
    ll ans = 1, r = 1;
    x %= m;
    while (r > 0 && r <= y)
    {
        if (r & y)
        {
            ans *= x;
            ans %= m;
        }
        r <<= 1;
        x *= x;
        x %= m;
    }
    return ans;
}
ll modI(ll a, ll m)
{
    ll m0 = m, y = 0, x = 1;
    if (m == 1)
        return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m;
        a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
        x += m0;
    return x;
}

ll logint(ll x, ll y)
{
    ll ans = 0;
    ll a = 1;
    for (ll i = 0; i <= x; i++)
    {
        if (x < a)
        {
            return ans;
        }
        ans++;
        a *= y;
    }
    return -1;
}
ll extended(ll a, ll b, ll &x, ll &y)
{
    if (a == 0)
    {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = extended(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll lcm(ll x, ll y) {
    return (x * y) / (__gcd(x, y));
}

void solve() {
    //What solution other than brute force ??
    ll k, s;
    cin >> k >> s;
    ll ans = 0;
    REP(i, 0, k + 1) {
        REP(j, 0, k + 1) {
            ll m = s - (i + j);
            if (m <= k && m >= 0) {
                ans++;
            }
        }
    }
    cout << ans;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen("b1.in", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ll ntc;
    // cin >> ntc;
    ntc = 1;
    REP(tc, 1, ntc + 1)
    {
        // cout << "Case #" << tc << ": ";
        solve();
    }
}



Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

typedef vector<P> G;

struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
};

int main() {
  double x,y;
  G g;
  while(scanf("%lf,%lf\n",&x,&y)==2)
    g.push_back(P(x,y));
  double ans = 0;
  REP(i, g.size()) {
    ans += cross(g[i],g[i<g.size()-1?i+1:0]);
  }
  printf("%.6lf\n",abs(ans / 2));
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args)throws IOException{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        double r = Double.parseDouble(br.readLine());
        
        System.out.printf("%f %f",r*r*Math.PI,2*r*Math.PI);
     }
}

Measured memory_bytes: 24864
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60

// a*2^n >= bとなる最小のn
int f(int a, int b) {
	int res = 0;
	while (a < b) {
		a *= 2;
		res++;
	}
	return res;
}

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

	int N, K; cin >> N >> K;

	double ans = 0;

	for (int i = 1; i <= N; i++) {
		int num = f(i, K);

		double tmp = 1 / double(N);
		for (int j = 0; j < num; j++) tmp /= 2;
		ans += tmp;

	}

	cout << std::setprecision(13) << ans << endl;

	return 0;
}

Measured memory_bytes: 256
000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. ABC123_A.
000300 DATA DIVISION.
000400 WORKING-STORAGE SECTION.
000500 01 A   PIC 9(3).
000600 01 E   PIC 9(3).
000700 01 K   PIC 9(3).
000800 PROCEDURE DIVISION.
000900 MAIN.
001000     ACCEPT A FROM CONSOLE
001100     ACCEPT E FROM CONSOLE
001200     ACCEPT E FROM CONSOLE
001300     ACCEPT E FROM CONSOLE
001400     ACCEPT E FROM CONSOLE
001500     ACCEPT K FROM CONSOLE
001600     SUBTRACT A FROM E
001700     IF E IS NOT GREATER THAN K
001800           DISPLAY 'Yay!' UPON CONSOLE
001900     ELSE
002000           DISPLAY ':(' UPON CONSOLE
002100     END-IF
002200     STOP RUN.


Measured memory_bytes: 636
#include<bits/stdc++.h>
//#include <boost/lexical_cast.hpp>
using namespace std;

#define pb push_back
#define mp make_pair  //access values using v[i].first,v[i].second
#define mt make_tuple //access values using get<1>(v[i]),get<0>(v[i]) etc

#define MAX 1000000000
#define MOD 1000000007

#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w",stdout);

#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define sc(n) scanf("%c",&n)
#define sd(n) scanf("%lf",&n)

#define pin(n) printf("%d\n",n)
#define pln(n) printf("%lld\n",n)
#define pdn(n) printf("%lf\n",n)

#define pis(n) printf("%d ",n)
#define pls(n) printf("%lld ",n)

#define pn printf("\n")
#define ps(n) printf("%s",n)
#define psn(n) printf("%s\n",n)

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


int main()
{
    //FIN;
    string t,s;
    cin>>t>>s;
    int n=s.length();
    if(s.substr(0,n-1)==t)psn("Yes");
    else psn("No");
}

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

int main(){
  string A,B,C;
  cin >> A >> B >> C;
  int countA=0,countB=0,countC=0;
  char next='a';
  while(true){
    if(next=='a'){
      if(countA==A.size()){
        cout << 'A' << endl;
        break;
      }
      next=A.at(countA);
      countA++;
    }
    if(next=='b'){
      if(countB==B.size()){
        cout << 'B' << endl;
        break;
      }
      next=B.at(countB);
      countB++;
    }
    if(next=='c'){
      if(countC==C.size()){
        cout << 'C' << endl;
        break;
      }
      next=C.at(countC);
      countC++;
    }
  }
}

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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int main() {
	int N;
	cin >> N;
	vector<int> v(N);
	cin >> v;
	auto u = v;
	sort(ALL(u));
	for (int i : range(N)) {
		if (v[i] <= u[N / 2 - 1])
			cout << u[N / 2] << endl;
		else
			cout << u[N / 2 - 1] << endl;
	}


	return 0;
}


Measured memory_bytes: 3840
n=int(input())
a=list(map(int,input().split()))
amax=max(a)
amin=min(a)
if amax-amin>=2:
    print("No")
    exit()
elif amax==amin:
    if amax==n-1 or amax*2<=n:
        print("Yes")
        exit()
    else:
        print("No")
        exit()
ac=a.count(amin)
ad=n-ac
if amin-ac<0:
    print("No")
    exit()

if (amax-ac)*2<=ad:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 20796
#include<bits/stdc++.h>
using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/
#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*/
#define error(args...) {vector <string> _v = split(#args, ','); err(_v.begin(), args); cout << endl;}
vector <string> split(const string &s, char c) {
    vector <string> v;
    stringstream ss(s); string x;
    while (getline(ss, x, c)) v.emplace_back(x);
    return move(v);
}
void err(vector <string> :: iterator it) {}
template <typename T, typename... Args>
void err(vector <string> :: iterator it, T a, Args... args) {
    cout << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", ";
    err(++it, args...);
}
 
int ini(){int x; scanf("%d",&x);return x;}
long long inl(){ long long x;scanf("%lld",&x); return x;}
double ind(){double x; scanf("%lf",&x);return x;}
#define Iin ini();
#define Lin inl();
#define Din ind();

int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;

int a[N];

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int t=1,te=0;
    
    while(t--){
        int a,b,c;
        cin>>a>>b>>c;

        if(a+b+c >=22){
            printf("bust\n");
        }
        else{
            printf("win\n");
        }


        //printf("Case %d: ",++te);
    }
    return 0;
}




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


int main() {
  int n;
  int64_t cnt = 0;
  cin >> n;
 
  map<char,int64_t>mp;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    char a = s.at(0);
    mp[a]++;
  }
  
  int64_t c = mp['M'];
  int64_t b = mp['A'];
  int64_t e = mp['R'];
  int64_t d = mp['C'];
  int64_t f = mp['H'];
  
  cnt += b*(c*d + c*e + c*f + d*e + d*f + e*f)+c*(d*e + d*f + e*f) + d*e*f;
  cout << cnt << endl;
}

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

const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

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

  int a[5];
  REP(i,5) cin >> a[i];

  int k = -1;
  int ans = 0;
  REP(i,5) {
    if (a[i] % 10 != 0) {
      if (k == -1) k = a[i]%10;
      else k = min(k,a[i]%10);
    }
    ans += 10 * ((a[i] + 9)/10);
  }
  if (k == -1) cout << ans << endl;
  else cout << ans - 10 + k << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int Q = scan.nextInt();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for (int i = 0; i < Q; i++) {
            l[i] = scan.nextInt();
            r[i] = scan.nextInt();
        }
        int MAX = 100000;
        boolean[] prime = new boolean[MAX + 1];
        Arrays.fill(prime, true);
        prime[0] = false;
        prime[1] = false;

        for (int i = 2; i * i <= MAX; i++) {
            if (!prime[i]) {
                continue;
            }
            for (int j = 2; i * j <= MAX; j++) {
                prime[i * j] = false;
            }
        }
        Set<Integer> primes = new HashSet<>();
        for (int i = 0; i <= MAX; i++) {
            if (prime[i])  {
                primes.add(i);
            }
        }
        boolean[] likeN = new boolean[MAX + 1];
        for (int i = 1; i <= MAX; i++) {
            if (!primes.contains(i)) {
                continue;
            }
            if (primes.contains((i + 1) / 2)) {
                likeN[i] = true;
            }
        }
        int[] sum = new int[MAX+1];
        sum[0] = 0;
        for (int i = 1; i <= MAX; i++) {
            sum[i] = sum[i-1] + (likeN[i] ? 1 : 0);
        }
        for (int i = 0; i < Q; i++) {
            System.out.println(sum[r[i]]-sum[l[i]-1]);
        }
    }
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

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

  string S;
  cin >> S;

  int bias = (S[0] == S.back() ? 1 : 0);
  
  string ans;
  if ((S.size() + bias) & 1) ans = "First";
  else ans = "Second";

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 512
import java.util.Scanner;

class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();
    int m = scan.nextInt();
    boolean[] kirai = new boolean[10];
    for(int i = 0; i < m; i++) kirai[scan.nextInt()] = true;
    int[] suki = new int[10-m];
    int dummy__Count = 0;
    for(int i = 0; i < 10; i++) {
      if(!kirai[i]) {
        suki[dummy__Count] = i;
        dummy__Count++;
      }
    }

    int count = 0;
    int num = 0;
    int keta = 1;
    do {
      num = 0;
      for(int i = keta-1; i >= 0; i--) {
        num*=10;
        num += suki[(count/(int)Math.pow(suki.length,i))%suki.length];

      }

      count++;
      if(count>=(int)Math.pow(suki.length,keta)) {
        keta++;
        count = 0;
      }
    }while(num < n);
    System.out.println(num);
  }
}


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

int f(string s, int st,int ed){
    int flag=1;
    while(st<ed){
        if(s[st]!=s[ed]){
            flag=0;
            break;
        }
        st++;ed--;
    }
    return flag;
}

int main(){
    string S;
    cin>>S;
    int n=S.size();

    if(f(S,0,n-1)*f(S,0,(n-3)/2)*f(S,(n+1)/2,n-1)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    

    return 0;
}

Measured memory_bytes: 3616
#include<iostream>

using namespace std;

int main(){

  int data[6];
  while(1){
    int tmp = 0;
    for(int i = 0; i < 6; i++){
      cin >> data[i];
      tmp += data[i];
    }
    if(tmp == 0) break;
   
    int a = data[0]+data[3];
    int b = data[1]+data[4];
    int c = data[2]+data[5];

    int lim = min(2,min(a,min(b,c)));

    int ans = 0;
    for(int i = 0; i <= lim; i++) ans = max(ans,i+(a-i)/3+(b-i)/3+(c-i)/3);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(void)
{
    char s[100];

    scanf("%s", s);


    if(s[0]=='1')
        printf("Heisei\n");
    else if(s[0]>='3') printf("TBD\n");
    else if(s[1]>'0') printf("TBD\n");
    else if(s[2]>'1') printf("TBD\n");
    else if(s[2]=='1' && s[3]=='9' && s[5]>='1') printf("TBD\n");
    else if(s[6]>'4') printf("TBD\n");
    else printf("Heisei\n");

    return 0;
}


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

using namespace std ;

const int MAX = 1e6 + 10 ;

int n ;
int vis[MAX] ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n ;
	int now = 0 ;
	for(int i = 1 ; ; ++i)
	{
		now = now * 10 + 7 ;
		now %= n ;
		if(vis[now])
			return cout<<-1<<"\n" , 0 ;
		if(now == 0)
			return cout<<i<<"\n" , 0 ;
		vis[now] = 1 ;
	}
	return 0 ;
}

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

long long mod=1000000007LL;
uint64_t dp[100005][13];
int main(void){
    // Your code here!
    string s;
    std::cin >> s;

    int n=s.length();
    dp[0][0]=1;

    for (int i = 0; i < n; i++) {
        int c;
        if(s[i]=='?')c=-1;
        else c=s[i]-'0';

        for (int j = 0;j < 10; j++) {
            if(c!=-1 && c!=j)continue;
            for (int k = 0; k < 13; k++) {
                dp[i+1][(k*10+j)%13]+=dp[i][k];
                
            }
        }
        for (int j = 0; j < 13; j++) {
            dp[i+1][j]%=mod;
        }
    }

    std::cout << dp[n][5] << std::endl;
    
}


Measured memory_bytes: 10624
// AOJ 2894: Binary String with Slit
// 2019.2.24 bal4u

#include <stdio.h>
#include <stdlib.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int ins(char *s)
{
	char *p = s;
	do *s = gc();
	while (*s++ > ' ');
	*--s = 0;
	return s - p;
}

char s[55] = { '1' }, *S = s + 1;
char t[55] = { '1' }, *T = t + 1;
int main()
{
	int Q, i, j, k, n, ans;

	Q = in();
	while (Q--) {
		n = ins(S), ins(T), T[n] = 1;
		i = 0; while (S[i] == T[i]) i++;
		if (i == n) ans = 0;
		else {
			j = k = n - 1;
			while (S[j] == '0') j--;
			while (T[k] == '0') k--;
			if (j < i) ans = k - j;
			else if (k < i) ans = j - k;
			else if (k == i) ans = j - i;
			else ans = j + k - 2*i;
		}
		printf("%d\n", ans);
	}
	return 0;
}



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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int tc; cin>>tc; while(tc--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();


    int n, s1= 0, s2=0;
    cin>> n;
    int a[n];

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


    for(int i=n-1, j=0; i>=j; )
    {
        if( s1< s2)
        {
            s1+= a[i];
            i--;
        }
        else
        {
            s2+= a[j];
            j++;
        }

    }



    cout << abs( s2-s1);

    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;


int main(){
    string s, t="";   cin >> s;
    int n=s.size(), ans=0;
    
    for(int i=0; i<n; i++)
        if(s[i]!='x') t += s[i];
    string bef = t.substr(0,t.size()/2), aft;
    reverse(t.begin(), t.end());
    aft=t.substr(0, t.size()/2);

    if(bef==aft){
        vector<ll> xcnt(t.size()+1, 0);
        int index=0;
        for(int i=0; i<n; i++){
            if(s[i]=='x') xcnt[index] += 1;
            else index += 1;
        }
        for(int i=0; i<=t.size()/2; i++)
            ans += abs(xcnt[i]-xcnt[t.size()-i]);
    }else ans=-1;
    cout << ans << endl;
}



Measured memory_bytes: 1408
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    def prime_factor(n):
        lst = []
        while n%2 == 0:
            n //= 2
            lst.append(2)
        f = 3
        while f**2 <= n:
            if n%f == 0:
                n //= f
                lst.append(f)
            else:
                f += 2
        if n != 1:
            lst.append(n)
        return lst
    dic = collections.Counter(prime_factor(n))
    ans = 0

    for key,value in dic.items():
        cnt = 0
        while value>=cnt+1:
            cnt += 1
            value -= cnt

        ans += cnt
    # print(dic)
    print(ans)
        
main()            


Measured memory_bytes: 74664
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(b-a==c-b){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;

int main()
{
	char buf[81];
	int n = 0;
	while (scanf("%s\n", buf) != EOF)
	{
		int t = 0;
		for (int i = 0; buf[i] != '\0'; ++i)
		{
			char c = buf[i];
			if (isdigit(c))
				t = t*10 + (c-'0');
			else
			{
				n += t;
				t = 0;
			}
		}
		n += t;
	}
	printf("%d\n", n);
	
	return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<string> S(N);
  for(int i=0;i<N;++i) cin>>S[i];
  vector<vector<int> > edge(N);
  for(int i=0;i<N;++i) {
    for(int j=0;j<N;++j) {
      if(S[i][j]=='1') edge[i].push_back(j);
    }
  }
  map<int, int> amap;
  for(int i=0;i<N;++i) amap[i] = -1;
  queue<pair<int, int> > que;
  que.push(mp(0, 0));
  pair<int, int> state;
  bool nibu = true;
  while(!que.empty()) {
    state = que.front();que.pop();
    if(amap[state.fi]>-1) continue;
    amap[state.fi] = state.se;
    for(int i=0;i<edge[state.fi].size();++i) {
      if(amap[edge[state.fi][i]]>-1) {
        if(amap[edge[state.fi][i]]%2!=(state.se+1)%2) nibu = false;
        continue;
      }
      que.push(mp(edge[state.fi][i], state.se+1));
    }
  }
  if(!nibu) {
    cout<<-1<<endl;
    return 0;
  }
  int dist[N][N];
  for(int i=0;i<N;++i) {
    for(int j=0;j<N;++j) {
      if(i==j) dist[i][j] = 0;
      else if(S[i][j]=='1') dist[i][j] = 1;
      else dist[i][j] = inf;
    }
  }
  for(int k=0;k<N;++k) {
    for(int i=0;i<N;++i) {
      for(int j=0;j<N;++j) {
        dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
      }
    }
  }
  int ans = 0;
  for(int i=0;i<N;++i) {
    for(int j=0;j<N;++j) {
      ans = max(ans, dist[i][j]);
    }
  }
  cout<<ans+1<<endl;
}



Measured memory_bytes: 4020
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>
#include <queue>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e18 + 7;

int main() {
	ll n, sum = 0, sum2 = 0, minv = INF;
	cin >> n;
	vector<ll> a(n);
	rep(i,0,n){
		cin >> a[i];
		sum += a[i];
	}
	rep(i, 0, n) {
		sum2 += a[i];
		if(i<n-1)minv = min(minv, abs(sum - 2 * sum2));
	}
	cout << minv << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

long long N,W,w1,w2,w3,w4;
int main(){
	cin >> N >> W;
	vector<vector<long long>> V(4);
	for(int i=0;i<N;i++){
		long long w,v;
		cin >> w >> v;
		if(i==0){
			w1 = w;
			w2 = w+1;
			w3 = w+2;
			w4 = w+3;
		}
		V[w-w1].push_back(v);
	}
	for(int i=0;i<=3;i++){
		V[i].push_back(0);
		sort(V[i].begin(),V[i].end());
		reverse(V[i].begin() + 1,V[i].end());
		for(int j=0;j<V[i].size()-1;j++){
			V[i][j+1] += V[i][j];
		}
	}
	long long ans = 0;
	for(int i=0;i<V[0].size();i++){
		for(int j=0;j<V[1].size();j++){
			for(int k=0;k<V[2].size();k++){
				for(int l=0;l<V[3].size();l++){
					if(w1*(i)+w2*(j)+w3*(k)+w4*(l)<=W && V[0][i]+V[1][j]+V[2][k]+V[3][l] > ans){
						ans = V[0][i]+V[1][j]+V[2][k]+V[3][l];
					}
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX 500009
#define MOD 1000000007
#define INF 1000000000000000000

int main(){
  int N,M;
  cin>>N>>M;
  vector<pair<int,int>> L(M);
  vector<int> R(M);
  vector<ll> C(M);
  for(int i=0;i<M;i++){
    cin>>L.at(i).first>>R.at(i)>>C.at(i);
    L.at(i).second=i;
    L.at(i).first--;
    R.at(i)--;
  }
  sort(L.begin(),L.end());

  vector<ll> dist(N,INF);
  dist.at(0)=0;
  priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
  pq.push(make_pair(dist.at(0),0));
  int j=0;
  for(int i=0;i<N;i++){
    //cout<<i<<" ";
    if(pq.empty()){
      break;
    }
    while(pq.top().second<i){
      pq.pop();
      if(pq.empty()){
        break;
      }
    }
    if(!pq.empty()){
      dist.at(i)=min<ll>(dist.at(i),pq.top().first);
    }
    //cout<<i<<" ";
    if(j==M){
      continue;
    }
    //cout<<i<<" ";
    while(L.at(j).first==i){
      int k=L.at(j).second;
      pq.push(make_pair(dist.at(i)+C.at(k),R.at(k)));
      j++;
      if(j==M){
        break;
      }
    }
    //cout<<i<<endl;
  }

  if(dist.at(N-1)==INF){
    cout<<-1<<endl;
  }else{
    cout<<dist.at(N-1)<<endl;
  }
}


Measured memory_bytes: 4980
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, R;
    cin >> N >> R;
    if (N >= 10) {
        cout << R << endl;
    } else {
        cout << R + 100 * (10 - N) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

import copy

string = [x for x in input()]

concat_string = copy.copy(string)
num_delete = 0

i = 0
j = 1
not_delete_list = []
while True:
    if j >= len(concat_string) or i < 0:
        break
    if concat_string[i] != concat_string[j]:
        num_delete += 2
        
        if i == 0:
            i = j + 1
            j = i + 1
        else:
            if len(not_delete_list) > 0:
                i = not_delete_list.pop(-1)
                j = j + 1
            else:
                i = j + 1
                j = i + 1
    else:
        not_delete_list.append(i)
        i = j
        j = i + 1


print(num_delete)

Measured memory_bytes: 9064
def check_block(str)
  q = []
  str.chars.each do |c|
    if c == '(' or c == '['
      q.push(c)
    elsif c == ')'
      r = q.pop() rescue nil
      return 'no' if r != '('
    elsif c == ']'
      r = q.pop() rescue nil
      return 'no' if r != '['
    end
  end
  q.count == 0 ? 'yes' : 'no'
end

while gets
  break if $_.chomp == '.'
  puts check_block($_.chomp)
end

Measured memory_bytes: 6092
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		String output = "No";

		Scanner scanner = new Scanner(System.in);

		String s = scanner.nextLine();
		String t = scanner.nextLine();

		char[] sChar = s.toCharArray();
		char[] tChar = t.toCharArray();

		Character[] td = new Character[tChar.length];

		for(int i = 0,len = tChar.length;i<len;i++) {
			td[i]= Character.valueOf(tChar[i]);
		}

		Arrays.sort(sChar);
		Arrays.sort(td, Collections.reverseOrder());

		s = String.valueOf(sChar);

		for(int i = 0,len = tChar.length;i<len;i++) {
			tChar[i]= td[i].charValue();
		}

		t = String.valueOf(tChar);


		if(s.compareTo(t) <= -1)
			output ="Yes";

		System.out.println(output);

		scanner.close();
	}

}

Measured memory_bytes: 22868
n=int(input())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
u=list(map(int,input().split()))
v=list(map(int,input().split()))
ans=[n*[0]for _ in range(n)]
ss=[u[i]if s[i]==0 else 0 for i in range(n)]
tt=[v[i]if t[i]==0 else 0 for i in range(n)]
son=[[]for _ in range(n)]
ton=[[]for _ in range(n)]
sno=[[n-1]*64 for _ in range(n)]
tno=[[n-1]*64 for _ in range(n)]
for i in range(n):
  for j in range(n):
    ans[i][j]=u[i]&v[j]
    if s[i]==0:
      ans[i][j]|=u[i]
      ss[i]&=ans[i][j]
    else:
      ss[i]|=ans[i][j]
    if t[j]==0:
      ans[i][j]|=v[j]
      tt[j]&=ans[i][j]
    else:
      tt[j]|=ans[i][j]
    if s[i]==0 or t[i]==0:
      for k in range(64):
        if ans[i][j]&1<<k:
          if s[i]==0:sno[i][k]-=1
          if t[j]==0:tno[j][k]-=1
    if j==n-1:
      if s[i]==1:
        if ss[i]|u[i]>u[i]:print(-1);exit()
        if ss[i]!=u[i]:
          for k in range(64):
            if u[i]&1<<k:
              if (ss[i]&1<<k)==0:
                son[i].append(k)
          ss[i]=1
        else:ss[i]=0
      else:
        if ss[i]!=u[i]:print(-1);exit()
        else:ss[i]=2
    if i==n-1:
      if t[j]==1:
        if tt[j]|v[j]>v[j]:print(-1);exit()
        if tt[j]!=v[j]:
          for k in range(64):
            if v[j]&1<<k:
              if (tt[j]&1<<k)==0:
                ton[j].append(k)
          tt[j]=1
        else:tt[j]=0
      else:
        if tt[j]!=v[j]:print(-1);exit()
        else:tt[j]=2
for i in range(n):
  for k in son[i]:
    for j in range(n):
      if t[j]==0:
        if tno[j][k]>0:
          ans[i][j]|=1<<k
          tno[j][k]-=1
          break
      if j==n-1:print(-1);exit()
for j in range(n):
  for k in ton[j]:
    for i in range(n):
      if s[i]==0:
        if sno[i][k]>0:
          ans[i][j]|=1<<k
          sno[i][k]-=1
          break
      if i==n-1:print(-1);exit()
for i in range(n):
  if s[i]==0:uu=ans[i][0]
  else:uu=0
  for j in range(n):
    if s[i]==0:uu&=ans[i][j]
    else:uu|=ans[i][j]
  if uu!=u[i]:print(-1);exit()
for j in range(n):
  if t[j]==0:vv=ans[0][j]
  else:vv=0
  for i in range(n):
    if t[j]==0:vv&=ans[i][j]
    else:vv|=ans[i][j]
  if vv!=v[j]:print(-1);exit()
for i in ans:print(*i)


Measured memory_bytes: 116628
#include<bits/stdc++.h>
#define U [1<<17]={}
typedef long long L;using namespace std;map<L,L> path U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p,r;char s U;
L D(L a){Z[a]=1;for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){L d=I->first;if(d-P[a]){P[d]=a;E[d]=E[a]+1;C[d]=I->second;D(d);Z[a]+=Z[d];!H[a]|Z[H[a]]<Z[d]?H[a]=d:0;}}}
L G(L a){r=A[a]+A[P[a]]+C[a];return r%k?r:0;}
L M(L i){return i?B[i]+M(i-(i&-i)):0;}
L S(L x,L i){for(x=G(x)-M(i+1)+M(i++);i<1<<17;B[i]+=x,i+=i&-i);}
main(){for(cin>>n>>k;p<n-1;p++)cin>>a>>b>>c,path[a][b]=path[b][a]=c;
       for(D(c=p=0);p<n;p++)if(!p|H[P[p]]-p)for(a=p;!c|a;S(a=H[a],O[a]=c++))X[a]=p;
       for(cin>>a;cin>>s>>a>>b;)if(*s&2){
           for(c=0;p=X[a],n=X[b],p-n;a=P[p])E[p]<E[n]?swap(p,n),swap(a,b),0:0,c+=M(O[a])-M(O[p])+G(p);cout<<c+abs(M(O[a])-M(O[b]))<<endl;}
       else A[a]+=b,S(H[a],O[a]),a?S(a,O[a]-1):0;}

Measured memory_bytes: 33464
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
using namespace std;

int main()
{
	int a, b, c, x,cnt=0,tmp=0;
	cin >> a >> b >> c >> x;
	for (int i = 0; i <= a; i++) {
		for (int j = 0; j <= b; j++) {
			tmp = x - (500 * i + 100 * j);
			if (tmp % 50 == 0 && tmp / 50 <= c && tmp >= 0)cnt++;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char ch[100000];
    scanf("%s",&ch);
    int len=strlen(ch),cnt=0;
    if(len==1)
    {
        printf("0\n");
        return 0;
    }
    for(int i=0; i<len-1; i++)
    {
        if(ch[i]==ch[i+1])
        {
            if(ch[i]=='0')
            {
                ch[i+1]='1';
                ++cnt;
            }
            else if(ch[i]=='1')
            {
                ch[i+1]='0';
                ++cnt;
            }
        }
    }
    printf("%d\n",cnt);
}


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

const int N = 100010;

int mx[N << 2], mn[N << 2], add[N << 2], val[N << 2];
#define mid ((l + r) >> 1)

int X, k, q, n;
vector< pair<int,int> > Z;
int pos[N];
int ans[N];

void push(int v, int l, int r) {
	if (l > r) return;
	if (l < r) {
		if (val[v] == -1) {
			add[v << 1] += add[v], add[v << 1 | 1] += add[v];
		} else {
			add[v << 1] = add[v], add[v << 1 | 1] = add[v];
			val[v << 1] = val[v], val[v << 1 | 1] = val[v];
		}
	}
	if (val[v] == -1) {
		mx[v] += add[v], mn[v] += add[v];
	} else {
		mx[v] = mn[v] = val[v] + add[v];
	}
	val[v] = -1; add[v] = 0;
}

void upd(int v, int l, int r, int L, int R, int x, int type) {
	push(v, l, r);
	if (l > r || R < l || L > r) return;
	if (L <= l && r <= R) {
		if (type == 0) val[v] = x; else add[v] = x;
		push(v, l, r);
		return;
	}
	upd(v << 1, l, mid, L, R, x, type); upd(v << 1 | 1, mid + 1, r, L, R, x, type);
	mx[v] = max(mx[v << 1], mx[v << 1 | 1]);
	mn[v] = min(mn[v << 1], mn[v << 1 | 1]);
}

int lef(int v, int l, int r, int x) {
	if (l == r) {
		if (mn[v] >= x) return 0;
		else return l;
	}
	push(v << 1, l, mid); push(v << 1 | 1, mid + 1, r);
	if (mn[v << 1 | 1] < x) return lef(v << 1 | 1, mid + 1, r, x);
	else return lef(v << 1, l, mid, x);
}

int rig(int v, int l, int r, int x) {
	if (l == r) {
		if (mx[v] <= x) return (q + 1);
		else return l;
	}
	push(v << 1, l, mid); push(v << 1 | 1, mid + 1, r);
	if (mx[v << 1] > x) return rig(v << 1, l, mid, x);
	else return rig(v << 1 | 1, mid + 1, r, x);
}

int get(int v, int l, int r, int pos) {
	push(v, l, r);
	if (l > r || r < pos || l > pos) return 0;
	if (l == r) return mx[v];
	return max(get(v << 1, l, mid, pos), get(v << 1 | 1, mid + 1, r, pos));
}

struct query {
	int time; int tp; int a; int id;
	bool operator < (const query &other) const {
		return time < other.time;
	}
} v[N << 1];

void build(int v, int l, int r) {
	if (l > r) return;
	if (l == r) {
		mx[v] = mn[v] = Z[l-1].first;
		add[v] = 0; val[v] = -1;
		return;
	}
	build(v << 1, l, mid); build(v << 1 | 1, mid + 1, r);
	mx[v] = max(mx[v << 1], mx[v << 1 | 1]);
	mn[v] = min(mn[v << 1], mn[v << 1 | 1]);
	add[v] = 0; val[v] = -1;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> X >> k;
	for (int i = 1; i <= k; ++i) cin >> v[i].time, v[i].tp = 'r';
	cin >> q;
	for (int i = 1 + k; i <= q + k; ++i) {
		cin >> v[i].time >> v[i].a, v[i].tp = 't', v[i].id = i - k;
		Z.push_back(make_pair(v[i].a, i - k));
	}

	sort(v + 1, v + k + q + 1);
	sort(Z.begin(), Z.end());
	for (int i = 0; i < (int)Z.size(); ++i) {
		pos[Z[i].second] = i + 1;
	}

	build(1, 1, q);
	n = k + q;

	int upper = 1;
	int lst = 0;
	for (int i = 1; i <= n; ++i) {
		int T = v[i].time - lst;
		lst = v[i].time;
		if (upper == 1) {
			int ll = lef(1, 1, q, T);
			upd(1, 1, q, 1, ll, 0, 0);
			upd(1, 1, q, ll + 1, q, -T, 1);
		} else {
			int rr = rig(1, 1, q, X - T);
			upd(1, 1, q, rr, q, X, 0);
			upd(1, 1, q, 1, rr - 1, T, 1);
		}

		if (v[i].tp == 'r') upper ^= 1;
		else {
			ans[v[i].id] = get(1, 1, q, pos[v[i].id]);
		}
	}	

	for (int i = 1; i <= q; ++i) {
		printf("%d\n", ans[i]);
	}
}

Measured memory_bytes: 11380
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long ,long long>pll;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

unsigned long long modpow(unsigned long long n, unsigned long long k, unsigned long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
    int n,m;
    cin >> n >> m;
    vector<int>v(n),w(n);
    for(int i = 0;i<n;i++)
        cin >> w[i] >> v[i];
    vector<vector<int>>dp(n+1,vector<int>(1e5+10,1e9+10));
    for(int i = 0;i<=n;i++) dp[i][0] = 0;
    for(int i = 0;i<n;i++){
        for(int j = 100000;j>=0;j--){
            dp[i+1][j] = dp[i][j];
            if(j>=v[i]) dp[i+1][j] = min(dp[i+1][j],dp[i][j-v[i]]+w[i]);
        }
    }
    for(int i = 100000;i>=0;i--){
        if(dp[n][i]<=m) {
            cout << i ;
            return;
        }
    }
}

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

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

const int mod = 998244353;
typedef long long LL;
void reduce(int & x) { x += x >> 31 & mod; }
int mul(int a, int b) { return (LL) a * b % mod; }
int pow(int a, int b, int res = 1) {
	for (; b; b >>= 1, a = mul(a, a)) if (b & 1) res = mul(res, a);
	return res;
}
const int D = 4000;
typedef std::bitset<D + 10> B;
B X, t, g;
int get(B x, int at = D) {
	while (at && !x.test(at)) --at;
	return at;
}
B gcd(B a, B b) {
	for (int i = D; ~i; )
		if (a.test(i) || b.test(i)) {
			if (b.test(i) && !a.test(i)) std::swap(a, b);
			if (b.none()) return a;
			a ^= b << i - get(b);
		} else --i;
}
int n, ans = 0;
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> X;
	while (n --> 0) std::cin >> t, g = gcd(g, t);
	int u = get(X), d = get(g);
	ans = 1;
	for (int i = d; i <= u; ++i) if (X.test(i))
		reduce(ans += pow(2, i - d) - mod);
	B r;
	for (int i = u; i >= d; --i)
		if (X.test(i) != r.test(i)) r ^= g << i - d;
	for (int i = u; ~i; --i)
		if (X.test(i) != r.test(i)) {
			if (!X.test(i)) reduce(ans -= 1);
			break;
		}
	std::cout << ans << std::endl;
	return 0;
}


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

using namespace std;

int main() {
  int n,a[200000],num[200000];
  cin >> n;
  
  for(int i = 0; i < 200000; i++)
    num[i] = 0;
  
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    num[a[i]]++;
  }

  int ans = 0, cnt;
  for(int i = 0; i < 110000; i++) {
    if(i == 0) 
      cnt = num[i] + num[i+1];
    else
      cnt = num[i-1] + num[i] + num[i+1];
    
    ans = max(ans, cnt);
  }

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

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

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

#define ll long long int

//const int mod=1000000007;
using namespace std;
 
/*int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};
*/


vector<int> g[110000];
int dp[110000];

int solve(int a)
{
    if(dp[a]!=-1)
        return dp[a];
    
    int ret=0;
    for(int i=0;i<g[a].size();i++)
    {
        
        ret=max(ret, solve(g[a][i])+1 );
        
    }
    
    return dp[a]=ret;
}



int main()
{

    
    int a,b;
    cin>>a>>b;
    
    for(int i=0;i<b;i++)
    {
        int x,y;
        cin>>x>>y;
        
        x--;y--;
        g[x].push_back(y);
        
    }

    memset(dp,-1,sizeof(dp));
    int ret=0;
    for(int i=0;i<a;i++)
    {
        ret= max(ret, solve(i));
        
    }
    
    cout<<ret<<endl;
    
    
}


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

int main()
{
    long long X;
    cin >> X;
    int count;
    count = 0;
    for(long long i = 100; i < X; i *= 1.01) {
        //cout << i << endl;
        count++;
    }
    cout << count << endl;
    return 0;
}

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

long long int n,m;
double dp[5005][5005];


double a[100000];

double find(int i,int noTails)
{
    if(i==n)
        return 1.0;

    if(dp[i][noTails] != -1.0)
        return dp[i][noTails];

    if(noTails < m)
        return dp[i][noTails] = (a[i]*find(i+1,noTails) + ((1.0-a[i])*find(i+1,noTails+1)));

    return dp[i][noTails] = a[i]*find(i+1,noTails);
}





int main()
{
    cin>>n;
    for(int i = 0;i<5005;i++)
        for(int j=0;j<5005;j++)
            dp[i][j] = -1.0;
    for(int i=0;i<n;i++)
        cin>>a[i];
    m = n%2==0?(n/2-1):n/2;
    cout<<setprecision(10)<<(double)find(0,0)<<"\n";

    return 0;
}


Measured memory_bytes: 196224
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def cmb(n):
    if n < 2: return 0
    return n * (n-1) // 2


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

    D = [0]*(N+1)
    for i in range(N):
        D[A[i]] += 1
    
    tmp = 0
    for n in range(1, N+1):
        tmp += cmb(D[n])
    for k in range(N):
        res = tmp - cmb(D[A[k]]) + cmb(D[A[k]]-1)
        print(res)


if __name__ == '__main__':
    main()

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

int main() {
  int K, S;
  int count;
  cin >> K >> S;

  count = 0;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K ; j++) {
      if (i+j <= S && S <= i+j+K) count++;
    }
  }
  cout << count;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>
//#include <algorithm>
using namespace std;

string ope(int opeid){
  if(opeid == 0){
    return "+";
  }else{
    return "-";
  }
}

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

  int n[4];
  for(int i = 0; i < 4; i++){
    n[i] = s[i] - '0';
  }

  int op[3];
  for(int i1 = 0; i1 < 2; i1++){
    op[0] = i1;
    for(int i2 = 0; i2 < 2; i2++){
      op[1] = i2;
      for(int i3 = 0; i3 < 2; i3++){
        op[2] = i3;

          int total = n[0];
          for(int i = 0; i < 3; i++){
            if(op[i] == 0){
              total += n[i + 1];
            }else{
              total -= n[i + 1];
            }
          }
          if(total == 7){
            cout << n[0] << ope(op[0]) << n[1] << ope(op[1]) << n[2] << ope(op[2]) << n[3] << "=7" << endl;
            return 0;
          }

        }
      }
    }
  }


Measured memory_bytes: 256