akhauriyash/Code-Regression huggingface dataset:
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.pop()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)


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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e4 + 10;
const int maxD = 1e2 + 10;
const ll mod = 1e9 + 7;

int n, d;
char a[maxN];
ll dp[maxN][maxD][2];

ll f(int i, int x, bool sm)
{
    if (i > n)
    {
        return x == 0;
    }
    ll &res = dp[i][x][sm];
    if (res != -1)
    {
        return res;
    }
    res = 0;
    if (sm)
    {
        for0(j, 10)
        {
            res += f(i + 1, (x + j) % d, 1);
        }
    }
    else
    {
        for0(j, a[i])
        {
            res += f(i + 1, (x + j) % d, 1);
        }
        res += f(i + 1, (x + a[i]) % d, 0);
    }
    return res %= mod;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> (a + 1) >> d;
    n = strlen(a + 1);
    for1(i, n)
    {
        a[i] -= '0';
    }
    memset(dp, 0xff, sizeof(dp));
    cout << (f(1, 0, 0) - 1 + mod) % mod;
    return 0;
}


Measured memory_bytes: 18304
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  bool isEnd = false;
  int turn = 0;
  while(isEnd == false){
    
    if(turn % 2 == 0){
      C -= B;
    }else{
      A -= D;
    }
    
    if(A <= 0 || C <= 0) isEnd = true;
    else turn++;
  }
  
  if(turn % 2 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

using Double = double;
using Point = complex<Double>;
const Double EPS = 1e-8;
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
namespace std {
  bool operator<(const Point a, const Point b){
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
}

vector<Point> circlesPointsRadius(const Point &a, const Point &b, const Double r){
  vector<Point> cs;
  Point abH = (b-a)*0.5;
  Double d = abs(abH);
  if(d == 0 || d > r) return cs;  // a==b  or  abs(a-b) > 2r
  Double dN = sqrt(r*r - d*d);
  Point n = abH * Point(0,1) * (dN / d);
  cs.push_back(a + abH + n);
  if(dN > 0) cs.push_back(a + abH - n);
  return cs;
}

int main(){
  int n;
  cin>>n;
  vector<Point> v(n);
  rep(i,n) {
    double x,y;
    cin>>x>>y;
    v[i] = Point(x,y);
  }

  double INF = 1000 * 1000 * 2.0;

  double l=0, r=INF;
   rep(_,100) {
    double m = (l+r)/2.0;

    auto ok = [&](){
      rep(i,n) rep(j,i+1,n){
       vector<Point> cand = circlesPointsRadius(v[i], v[j], m);
        for (auto c : cand) {
          bool inside = true;
          rep(k,n) {
            inside &= (abs(v[k]-c) <= m + EPS);
          }
          if(inside) return true;
        }
      }
      return false;
    };

    if(ok()) r = m;
    else l = m;
  }

  printf("%.9f\n", r);

  return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    ll a, b;
    cin >> a >> b;

    if (a == 0 && b == 0) {
      cout << "Zero" << endl;
      return 0;
    }

    if (a < 0 && b > 0) {
      cout << "Zero" << endl;
    }
    if (a > 0 && b > 0) {
      cout << "Positive" << endl;
      return 0;
    }
    if (a < 0 && b < 0) {
      a *= -1;
      b *= -1;
      if ((b - a) % 2) cout << "Positive" << endl;
      else cout << "Negative" << endl;
      return 0;
    }
    return 0;
}

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

#define int           long long 
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (int)(1e18)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii>

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){ cerr << name << " = " << arg1 << endl;}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args)
{ const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);}

template< typename T1, typename T2 > istream& operator>>(istream& in, pair<T1, T2> &q){ in >> q.F >> q.S; return in;}
template< typename T1, typename T2 > ostream& operator<<(ostream& out, pair<T1, T2> &q){ out << q.F << " " << q.S; return out;}
template< typename T1, typename T2 > pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F+p2.F, p1.S+p2.S};}
template< typename T1, typename T2 > pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){ return {p1.F-p2.F, p1.S-p2.S};}
template< typename T1, typename T2 > bool operator<(pair<T1, T2> p1, pair<T1, T2> p2){ return p1 < p2 ;}

template<typename T> void Unique(vector<T> &v){
    sort(all(v)), v.resize(distance(v.begin(), unique(all(v))));
}


void solve(int &test) {
	int h, w;
	cin >> h >> w;

	int sh, sw;
	cin >> sh >> sw;
	sh--, sw--;

	int dh, dw;
	cin >> dh >> dw;
	dh--, dw--;

	string s[h];
	int dis[h][w];
	for(int i = 0; i < h; i++) {
		cin >> s[i];
		for(int j = 0; j < w; j++)
			dis[i][j] = inf;
	}

	deque<pair<int, int> > q;
	dis[sh][sw] = 0;
	q.push_back(mp(sh, sw));

	while(!q.empty()) {
		int x = q.front().F;
		int y = q.front().S;

		q.pop_front();

		if(mp(x, y) == mp(dh, dw)) {
			cout << dis[dh][dw] << endl;
			return;
		}

		for(int i = -2; i <= 2; i++) {
			for(int j = -2; j <= 2; j++) {
				int nx = x+i, ny = y+j;
				if(nx < 0 || ny < 0 || ny >= w || nx >= h || s[nx][ny] == '#') {
					continue;
				}
				
				if(abs(i)+abs(j) == 1) {
					if(dis[nx][ny] > dis[x][y]){
						q.push_front(mp(nx, ny));
						dis[nx][ny] = dis[x][y];
					}
				}
				else {
					if(dis[nx][ny] > dis[x][y]+1){
						q.push_back(mp(nx, ny));
						dis[nx][ny] = dis[x][y]+1;
					}
				}
			}
		}
	}
	cout << -1 << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   
    start = clock(); 

    int t = 1;
    // cin >> t;

    cout << fixed << setprecision(2);
     
    for(int i = 1; i <= t; ++i){
        solve(i); 
    }

    cerr << time(start);
    return 0;
}

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

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

  string n;
  cin >> n;

  cout << (n[0] == '7' || n[1] == '7' || n[2] == '7' ? "Yes" : "No");
}

Measured memory_bytes: 3612
n=int(input())
xy=[]
for i in range(n):
    x,y=map(int,input().split())
    xy.append((x,y))
import itertools
import math
x=[i for i in range(n)]
s=list(itertools.permutations(x, n))
count=0
for item in s:
    for i in range(1,n):
        idx=item[i]
        pre=item[i-1]
        count+=math.sqrt((xy[idx][0]-xy[pre][0])**2+(xy[idx][1]-xy[pre][1])**2)
for i in range(1,n+1):
    count/=i
print(count)

Measured memory_bytes: 46832
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	int n, k;
	cin >> n >> k;
	int ans = 1;
	REP(i, n)
	{
		if (ans < k)
			ans *= 2;
		else
			ans += k;
	}
	print(ans);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


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

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size))scanf("%d",&(name)[i])
#define MOD 1000000007

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=n;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    ll N,K;
    cin>>N>>K;
    map<int,ll> list;
    FOR(i,N){
        int a;
        ll b;
        cin>>a>>b;
        list[a]+=b;
    }
    vector<pair<int,ll>> final;
    for(pair<int,ll> p:list){
        final.push_back(p);
    }
    sort(ALL(final),[](const pair<int,ll>& l,const pair<int,ll>& r){return l.first<r.first;});
    int i=0;
    while(1){
        K-=final[i].second;
        if(K<=0){
            print(final[i].first);
            break;
        }
        i++;
    }
    return 0;
}

Measured memory_bytes: 5368
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    unsigned long long n, m, cnt = 0;

    cin >> n >> m;

    if(n == 1 && m == 1) cnt = 1;
    else if(n == 1 || m == 1) cnt = max(n,m) - 2;
    else cnt = (n-2)*(m-2);

    cout << cnt << endl; 
}

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

int main() {
  int N, a;
  string b;
  cin >> N;
  a = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> b;
    if (b == "Y") {
      a = 1;
    }
  }
  
  if (a == 0){
    cout << "Three" << endl;
  }
  else if (a == 1){
    cout << "Four" << endl;
  }
}

Measured memory_bytes: 3604
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(n)]
AB.sort()
#print(AB)
cnt=0
i=-1
ans=0
while cnt<m:
    i+=1
    ans+=AB[i][0]*AB[i][1]
    cnt+=AB[i][1]
    #print(ans,cnt)
ans-=AB[i][0]*AB[i][1]
cnt-=AB[i][1]
#print(ans,cnt)
while cnt<m:
    ans+=AB[i][0]
    cnt+=1
print(ans)


Measured memory_bytes: 60888
import java.util.*;

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

    int N = in.nextInt();
    Tmp[] arr = new Tmp[N];

    for (int i = 0; i < N; i++) {
      arr[i] = new Tmp(in.nextLong(), in.nextLong());
    }

    Arrays.sort(arr);

    long anum = 0;
    long bnum = 0;

    for (int i = 0; i < N; i++) {
      if (i % 2 == 0) {
        anum += arr[i].a;
      } else {
        bnum += arr[i].b;
      }
    }

    System.out.println(anum - bnum);
  }

  /*
   * んー、これは何を改善すればとけるようになるのかがよくわからないな。。
   * 解説のとおりだと、一つが全部食べるというシミュレーションからかんがえるべきだったのかな？
   */

  public static int gcd(int a, int b) {
        if (b == 0) return a;
    return gcd(b, a % b);

  }

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

class Tmp implements Comparable<Tmp> {
  long a;
  long b;

  public Tmp(long a, long b) {
    this.a = a;
    this.b = b;
  }

  public int compareTo(Tmp t) {
    // Sort in descending order.
    return (int) (t.a + t.b - a - b);
  }
}

Measured memory_bytes: 53496
#include<iostream>
#include<cstdio>
#include<cstring>

const int N = 100100;

using namespace std;
int i,j,s1,s2,n,m,ans, sum, c1, c2;
bool a[N];
int p1[N], p2[N], l[N], r[N];
char ch;
inline int Abs(int x){
	return x<0?-x:x;
}
int main()
{
	scanf("%d\n",&n);
	for (int i = 1; i <= n; i++) {
		ch = getchar();
		if (ch == '>') {
			a[i] = 1; l[i]++; p1[++c1] = i;
		}
	}
	for (int i = n; i; i--) {
		r[i] = r[i - 1];
		if (!a[i]) {
			r[i]++; p2[++c2] = i;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (a[i]) {
			if (l[i] >= r[i]) {
				sum = n - p1[l[i] - r[i]] + 1;
			} else {
				sum = p2[r[i] - l[i] + 1];
			}
		} else {
			if (l[i] <= r[i]) {
				sum = p2[r[i] - l[i]];
			} else {
				sum = n - p1[l[i] - r[i] + 1] + 1;
			}
		}
		ans = max(ans, sum);
	}
	printf("%d\n",ans); 
	return 0;
}

Measured memory_bytes: 4368
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = Enumerable.Repeat(0, n).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        //始めは0
        //狭義単調増加列に分解

        //後ろから見ていって、Ni-1がそうあるべきだと考える

        //1 1みたいになったときは再構築しないとダメ
        //a[i-1]+1==a[i]のときはラッキーで+1
        
        //到達不能の検出漏れはない
        //到達可能なのに不能と判定されているかも。-> ない (13WA->13WA)
        //個数のミスだよなあ もうちょっと少なく出来る又は多い必要がある
        long res = 0;
        for (int i = a.Length - 1; i >= 1; i--)
        {
            if (a[i] - a[i - 1] > 1)
            {
                res = -1;
                goto end;
            }

            if (a[i - 1] + 1 == a[i]) res++;
            else res += a[i];
        }
        end:;
        if (a[0] != 0) res = -1;
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 17756
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    set<string> se;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        se.insert(s);
    }
    cout << se.size() << endl;
}

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

int main(){
   char c;
    cin >> c;
    if(c == 'a'){
       cout << "vowel" << endl;
} 
else if(c == 'e'){
       cout << "vowel" << endl;
}
else if(c == 'i'){
       cout << "vowel" << endl;
}
else if(c == 'o'){
       cout << "vowel" << endl;
}
else if(c == 'u'){
       cout << "vowel" << endl;
}
else {
        cout << "consonant" << endl;
}
}

Measured memory_bytes: 256
from collections import deque
s=deque(input())
q=int(input())
flag = 2

for i in range(q):
    query=input().split()
    if query[0] == "1":
        flag = 3 - flag
    elif int(query[1]) - flag :
         s.appendleft(query[2])
    else:
        s.append(query[2])

if flag-2:
    s.reverse()

print("".join(s))


Measured memory_bytes: 8436
import math
 
n,k = list(map(int, input().split()))
val = list(map(int, input().split()))

dist = val[k-1]-val[0]+abs(val[0])
minim = dist

for i in range(n-k):
    dist += val[i+k]-val[i+k-1]
    dist -= val[i+1]-val[i]
    dist -= abs(val[i])
    dist += abs(val[i+1])
    if(dist<minim):
        minim = dist

dist = val[k-1]-val[0]+abs(val[k-1])
if(dist<minim):
    minim = dist

for i in range(n-k):
    dist += val[i+k]-val[i+k-1]
    dist -= val[i+1]-val[i]
    dist -= abs(val[i+k-1])
    dist += abs(val[i+k])
    if(dist<minim):
        minim = dist
        
print(minim)

Measured memory_bytes: 15020
#include<stdio.h>
int main()
{
	int h,w,k,omen;
	scanf("%d %d %d",&h,&w,&k);
	if(h > w) omen = h;
	else omen = w;
	int count = 1;
	for(int i = omen;i<k;i += omen)
	{
		count++;
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 1728
n, k = map(int, input().split())
ans = 0.0
for i in range(1, n + 1):
  hops = 0
  while i < k:
    hops += 1
    i *= 2
  ans += pow(1.0 / 2.0, hops)
ans /= n
print('{:.10f}'.format(ans))

Measured memory_bytes: 39408
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
using namespace std;
int main(){
	
	int n;
	while(cin>>n,n!=0){
	vector<string> s(n);
	int k=0;
	double best=1000000;
	for(int i=0;i<n;i++){
		double a,b;
		cin>>s[i];
		cin>>a>>b;
		a=a*pow(10,-2);
		double bmi=double(b)/pow(a,2);
		
		if(abs(22-bmi)<best){
			k=i;
			best=abs(22-bmi);
		}
	}
	
	cout<<s[k]<<endl;
	
	}
	
	
}

Measured memory_bytes: 1288
#include<bits/stdc++.h>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define revrep(i,n) for(long long i=n-1;i>=0;i--)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define set0(x) memset(x,0,sizeof(x))
#define set1(x) memset(x,1,sizeof(x))
#define getarr(arr,n) int arr[n];rep(i,0,n)cin>>a[i]
#define getvec(vec,n) vi vec;int x;rep(i,0,n){cin>>x;vec.pb(x);}
#define sort_uniq(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define uniq(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
int isPowerof2(int x) { return (x && !(x & x-1)); }

int cnt[200005];
vi adj[200005];

void dfs(int s, int e) {
	cnt[s]+=cnt[e];
	for (auto u : adj[s]) {
		if (u != e) dfs(u, s);
	}
}

int32_t main(){
	boost;osit;
	int n,q;
	cin>>n>>q;
	rep(i,0,n-1){
		int x,y;
		cin>>x>>y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	set0(cnt);
	while(q--){
		int x,y;
		cin>>x>>y;
		cnt[x]+=y;
	}
	dfs(1,0);
	for(int i=1;i<=n;i++){
		cout<<cnt[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 24320
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int l[2],r[2],c,i,j;
	bool flag;
	string s[2];
	while(true){
		cin >> s[0];
		if(s[0]=="."){
			break;
		}
		cin >> s[1];
		if(s[0] == s[1]){
			cout << "IDENTICAL" << endl;
			continue;
		}
		c = 0;
		for(i=0; i<2; ++i){
			l[i] = 0;
			r[i] = s[i].l_ength()-1;
		}
		while(s[0][l[0]] == s[1][l[1]]){
			if(s[0][l[0]] == '\"'){
				++c;
			}
			++l[0]; ++l[1];
		}
		if(!(c%2)){
			cout << "DIFFERENT" << endl;
			continue;
		}
		while(s[0][r[0]] == s[1][r[1]]){
			--r[0]; --r[1];
		}
		flag = true;
		for(i=0; i<2; ++i){
			for(j=l[i]; j<=r[i]; ++j){
				if(s[i][j] == '\"'){
					flag = false;
					break;
				}
			}
			if(!flag){
				break;
			}
		}
		cout << ((flag)?"CLOSE":"DIFFERENT") << endl;
	}
	return 0;
}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin>>N;
    int n=0;
    while(N>0)
    {
        int rem=N%10;
        if(rem==7)
        {
            n++;
        }
        N=N/10;
    }
    if(n>0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


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

int main() {
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a, a + 3);
	if(a[0] == a[1] and a[1] == a[2]) puts("No");
	else if(a[0] == a[1] or a[1] == a[2]) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

struct stack {
	int data[20000];
	int point;
};

int main(void) {
	char str[30000] = {};
	int i = 0;
	int j = 0;
	struct stack data = {};
	struct stack width = {};
	int tmp = 0;
	int tmp1 = 0;
	int sum = 0;
	for ( i = 0; i < 20000; i++ ) {
	    data.data[i] = -3;
	}
	
	fgets(str,30000, stdin);
	i = 0;
	while(str[i] != '\0' ) {
		switch(str[i]) {
			case '\\':
				data.data[data.point] = 0;
				data.point++;
				break;
			case '_':
				data.data[data.point] = -1;
				data.point++;
				break;
			
			case '/':
			    j = data.point;
				while ( data.data[j] != 0 ) {
					j--;
					if ( j < 0 ) {
						break;
					}
				}
			    
				if ( j >= 0 ) {
					tmp = 0;
					tmp1 = 0;
					data.point--;
					while ( data.data[data.point] != 0 ) {
						if ( data.data[data.point] > 0 ) {
							width.point--;
							tmp += width.data[width.point];
							tmp1 += data.data[data.point];
						} else {
							tmp ++;
						}
						data.point--;
					}
					tmp1 += 1 + tmp;
					tmp += 2;
					data.data[data.point] = tmp1;
					width.data[width.point] = tmp;
					width.point++;
					data.point++;
				}
			default:
				break;
		}
		i++;
	}
	j = 0;
	for ( i = 0; i < data.point; i++ ) {
	    if ( data.data[i] > 0) {
    		j++;
    		sum += data.data[i];
	    }
	}
	
	printf("%d\n", sum);
	printf("%d", j);
	for ( i = 0; i < data.point; i++ ) {
	    if ( data.data[i] > 0) {
    		printf(" %d", data.data[i]);
	    }
	}
	printf("\n");
	
	return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 210000, mod = 998244353;

int n, dis[N], a, b;
ll f[N], g[N], pw[N];
vector<int> to[N];

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

inline void addEdg(int x, int y) {
	to[x].push_back(y), to[y].push_back(x);
	return;
}

void dfs1(int now, int fa) {
	dis[now] = dis[fa] + 1;
	for (auto &v : to[now]) {
		if (v == fa) continue;
		dfs1(v, now);
	}
	return;
}

int dfs2(int now, int fa, int maxD) {
	if (dis[now] == maxD) return 1;
	int ret = 0;
	for (auto &v : to[now]) {
		if (v == fa) continue;
		ret |= dfs2(v, now, maxD);
	}
	if (ret) {
		if (dis[now] == (maxD + 1) >> 1)
			a = now;
		else if (dis[now] == (maxD >> 1) + 1)
			b = now;
	}
	return ret;
}

void dfs3(int now, int fa, int maxD) {
	pw[now] = 1, dis[now] = dis[fa] + 1;
	if (dis[now] == (maxD + 1) >> 1) g[now] = 1;
	f[now] = 1 - g[now];
	for (auto &v : to[now]) {
		if (v == fa) continue;
		dfs3(v, now, maxD);
		g[now] = ((2 * pw[v] + f[v]) * g[now] + f[now] * g[v]) % mod;
		f[now] = (2 * pw[v] + f[v]) * f[now] % mod;
		pw[now] = pw[now] * pw[v] * 3 % mod;
	}
//	cout << "qwq " << now << ' ' << pw[now] << ' ' << f[now] << ' ' << g[now] << endl;
	return;
}

int main() {
	int x, y;
	read(n);
	for (R int i = 1; i < n; ++i)
		read(x), read(y), addEdg(x, y);
	dfs1(1, 0);
	int rt = 1, maxD = 1;
	for (R int i = 2; i <= n; ++i)
		if (dis[i] > maxD) maxD = dis[i], rt = i;
	dfs1(rt, 0), maxD = 1;
	for (R int i = 1; i <= n; ++i)
		maxD = max(maxD, dis[i]);
	dfs2(rt, 0, maxD);
	if (b) {
		dis[a] = 0, dfs3(b, a, maxD);
		dis[b] = 0, dfs3(a, b, maxD);
		printf("%lld\n", g[a] * g[b] % mod);
	}
	else {
		ll ans = 0;
		f[a] = 1, dis[a] = 1;
		for (auto &v : to[a]) {
			dfs3(v, a, maxD);
			ans = (ans * (pw[v] + 2 * f[v]) + g[a] * g[v]) % mod;
			g[a] = (g[a] * (pw[v] + 2 * f[v]) + f[a] * g[v]) % mod;
			f[a] = f[a] * (pw[v] + 2 * f[v]) % mod;
			//cout << "qwq " << v << ' ' << f[v] << ' ' << g[v] << endl;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 25088
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
bool F[100][10];
int P[100][11], n;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n)FOR(j, 0, 10) cin >> F[i][j];
  FOR(i, 0, n)FOR(j, 0, 11) cin >> P[i][j];
  int ans = -iinf;
  FOR(i, 1, 1<<10){
    int su = 0;
    FOR(j, 0, n){
      int c = 0;
      FOR(k, 0, 10) if(F[j][k] && ((1<<k)&i)) c++;
      su += P[j][c];
    }
    maxs(ans, su);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int nax=1e6+90;
vector<int >prime(nax,-1);

void sieve()
{
    for(int i=2;i*i<nax;i++)
    {
        if(prime[i]==-1)
        {
            for(int j=i*i;j<nax;j+=i)
            {
                prime[j]=i;
            }
        }
    }

}

int main(){
    sieve();
    //cout<<"HI\n";
    int n;
    cin>>n;
    int ans=0;
    for(int c=1;c<n;c++)
    {
//cout<<ans<<"\n";
       int val=n-c;
       if(val==1) {ans++;continue;}
       //find no of div
       ll pro=1;
       while(val>1)
       {
            int ctr=0;
            int div=prime[val];
            
            if(div==-1) {pro*=2;val=1;continue;}
            while(val%div==0)
            {
                ctr++;
                val=val/div;
            }
            pro=pro*1LL*(ctr+1);
               // cout<<val<<"\n";

       }
    //   cout<<pro<<"\n";
      if(pro>1)
       ans+=pro;
    }
    cout<<ans<<"\n";

 

}

Measured memory_bytes: 7068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    string s;cin>>s;
    rep(i,0,2){
        if(s[i]=='7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    
    cout<<"No"<<endl;
    return 0;
}





Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define msg(x) debug() << x
#define int long long
const int xx = 2e5;
const int MOD = 1e9 + 7;
vector<int>v;
int sq(int n){
  int x = sqrt(n);
  return x*x == n;
}
int dis(int x , int y){
  return (x-1) + (y-1);
}
signed main(){
  ios::sync_with_stdio(false);cin.tie(0);

  int n;
  cin >> n;

  int x = 1;

  for(int i=1;i*i<=n;i++){
    if(n%i==0){
      x = max(x,i);
    }
  }

  int ans = dis(x,n/x);

  if(sq(n)){
    int xx = sqrt(n);
    ans = min(ans , dis(xx,xx));
  }

  cout << ans << '\n';



}

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

B=[0 for i in range(N)]

B[0]=2
while 1:
  for i in range(1,N):
    B[i]=2*A[i]-B[i-1]
  if B[0]==2*A[0]-B[-1]:break
  else:
    B[0]= (B[0] + (2*A[0]-B[-1]))//2

B = [B[-1]]+B[:-1]

print(*B)

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

int main() {
    ll a, b, n;
    while(cin >> a >> b, a){
        ll dp[20][20]{};
        bool ng[20][20]{};
        cin >> n;
        for(int i=0;i<n;i++){
            int x, y;
            cin >> x >> y;
            x--; y--;
            ng[y][x] = true;
        }
        dp[0][0] = 1;
        for(int i=0;i<b;i++){
            for(int j=0;j<a;j++){
                if(ng[i][j]) continue;
                dp[i+1][j] += dp[i][j];
                dp[i][j+1] += dp[i][j];
            }
        }
        cout << dp[b-1][a-1] << endl;
    }

    return 0;
}



Measured memory_bytes: 3052
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<unordered_map>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<cmath>

#define vint vector<int>
#define vstr vector<string>
#define vll vector<long long>
#define ll long long
#define pf printf
#define sf scanf
#define sfd(n) scanf("%d", &n)
#define sflf(n) scanf("%lf", &n)
#define sfll(n) scanf("%lld", &n)
#define pfd(n) printf("%d", n)
#define pflf(n) printf("%lf", n)
#define pfll(n) printf("%lld", n)
#define pft	printf("\t")
#define pfn printf("\n")
#define pfk printf(" ")
#define check printf("asd\n")
#define PI 3.1415926
#define MAX 100000
#define M 1e18

using namespace std;

int main() {
	int n;
	sfd(n);
	int* a = new int[n+2];
	int* cnt = new int[n];
	a[0] = 0;
	for( int i=1; i<=n; i++ ) {
		sfd(a[i]);
	}
	a[n+1] = 0;
	int sum = 0;
	for( int i=0; i<=n; i++ ) {
		cnt[i] = abs(a[i]-a[i+1]);
		sum += cnt[i];
	}
	for( int i=1; i<=n; i++ ) {
		pfd(sum-cnt[i]-cnt[i-1]+abs(a[i+1]-a[i-1]));
		pfn;
	}
	return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
signed main(){
	ic(n) ic(a) ic(b)
	if(b-a<=2)c(1+n)
	else if(n<=a-1)c(1+n)
	else{
		n=n-a+1;
		if(n%2==0)c((b-a)*n/2+a)
		else c((b-a)*(n-1)/2+1+a)
	}
}	


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }


int main(){
    int H, A;
    cin >> H >> A;
    cout << (H + A - 1) / A << endl;
}

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

int main(){
  string S;
  cin >> S;
  bool flag = true;

  if (S.size() % 2 != 0) {
    cout << "No";
    return 0;
  }

  for (int i = 0; i < S.size(); i+=2){
    if (S.at(i) != 'h' || S.at(i + 1) != 'i') flag = false;
  }
  if (flag) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int n = sc.nextInt();
		int p = sc.nextInt();

		boolean isOdd = false;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (a % 2 == 1) {
				isOdd = true;
			}
		}

		long ans;
		if (isOdd) {
			ans = (long) Math.pow(2, n - 1);
		} else {
			if (p == 0)
				ans = (long) Math.pow(2, n);
			else
				ans = 0;
		}

		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 23892
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

k,t = inm()
a = inl()
b = k-max(a)
print(max(0,k-1-2*b))


Measured memory_bytes: 9052
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	int n; cin >> n;
	int a; cin >> a;
	cout << (n * n) - a << endl;
	return;
}

int main() {
	solve();
  return 0;
}

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

using namespace std;
using std::vector;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x, y) x = max(x,y)
#define chmin(x, y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i, n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) return(gcd(b, a%b));
  return b;
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int main(){

  int n; cin >> n;
  vl a(n);
  vl b(n);
  vl sub; //余っている得点
  ll sum_a = 0, sum_b = 0, sum = 0;
  
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];

  int ans = 0;

  rep(i,n){
    sum_a += a[i];
    sum_b += b[i];
    if(a[i] - b[i] < 0){
      sum += abs(a[i] - b[i]);
      ans ++;
    }
    else
      sub.pb(a[i] - b[i]);
  }
  
  if(sum_b > sum_a){
    pr("-1");
    return 0;
  }

  sort(rall(sub));

  if(sum <= 0){
      pr(ans);
      return 0;
    }

  for(int i = 0; i < sub.size(); i++){
    sum -= sub[i];
    ans ++;
    if(sum <= 0){
      pr(ans);
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 2936
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
// #define LOCAL
const int MAXN=2e5+10;
int n,p;
char s[MAXN];
int cnt[10010];
void solve()
{
    scanf("%d %d\n",&n,&p);
    scanf("%s",s);
    ll ans=0;
    if(p==2){
        for(int u=n-1;u>=0;u--){
            if((s[u]-'0')%2==0){
                ans+=u+1;
            }
        }
        cout<<ans;
        return;
    }
    if(p==5){
        for(int u=n-1;u>=0;u--){
            if(s[u]=='0'||s[u]=='5'){
                ans+=u+1;
            }
        }
        cout<<ans;
        return;
    }
    int m=0,b=1;
    cnt[0]++;
    for(int u=n-1;u>=0;u--){
        m=(m+(s[u]-'0')*b)%p;
        b=b*10%p;
        ans+=cnt[m];
        cnt[m]++;
    }
    cout<<ans;
}
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    solve();
}

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

int main() {
    int A, B;
    cin >> A >> B;
    string S;
    cin >> S;

    bool isOk = true;
    rep(i, S.size()) {
        if (i == A) {
            if (S.at(i) != '-')
                isOk = false;
        } else {
            if (S.at(i) < '0' || '9' < S.at(i))
                isOk = false;
        }
    }

    string ans = isOk ? "Yes" : "No";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;cin>>x>>y;
  if(y%2==1)
    cout<<"No"<<endl;
  else{
  int k=y/2-x;
    if(0<=k && k<=x)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();

        boolean greaterNumExists = false;
        int gcd = 0, tmp;
        for (int i=0; i<n; i++) {
            tmp = sc.nextInt();
            if (tmp == k) { System.out.println("POSSIBLE"); return; }

            if (!greaterNumExists && tmp > k) { greaterNumExists = true; }

            if (gcd == 0) { gcd = tmp; }
            if (tmp % gcd != 0) { gcd = GCD(gcd, tmp); }

            if (greaterNumExists && k % gcd == 0) { System.out.println("POSSIBLE"); return; }
        }
        System.out.println("IMPOSSIBLE");
    }

    public static int GCD(int x, int y) {   
        int r;
        while (y!=0) {
            r = x%y; x = y; y = r;
        }
        return x;
    }
}


Measured memory_bytes: 47676
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define ll long long int
ll a[500005], q[500005];
ll sz = 720, ans;

struct ele{
  ll l,r, id;  
    
};

ele p[500005];
ll f[500005];
bool cmp(ele p1, ele p2){
    ll v1 = p1.l/sz;
    ll v2 = p2.l/sz;
    if(v1 == v2) {
        if(v1 & 1) return p1.r > p2.r;
        return p1.r < p2.r;
    }
    return p1.l < p2.l;
}

void add(ll v){
    if(f[v] == 0) ans+=1;
    f[v] += 1;
}

void rem(ll v){
    if(f[v] == 1) ans -=1;
    f[v]-=1;
}




int main() {
	// your code goes here
	ll i,j,k,n,m,t;
	cin>>n>>t;
	for(i=1;i<=n;i++) cin>>a[i];
	for(i=1;i<=t;i++){
	    cin>>p[i].l>>p[i].r;
	    p[i].id = i;
	}
	
	sort(p+1, p+t+1, cmp);
	ll lt = 1, rt = 0; ans = 0;
	for(i=1;i<=t;i++){
	    ll cl = p[i].l, cr = p[i].r, cid = p[i].id;
	    while(rt < cr) add(a[++rt]);
	    while(lt > cl) add(a[--lt]);
	    while(rt>cr) rem(a[rt--]);
	    while(lt<cl) rem(a[lt++]);
	   // cout<<cl<<" "<<cr<<" "<<ans<<"\n";
	    q[cid] = ans;
	}
	//cout<<"\n";
	
	for(int i=1;i<=t;i++) cout<<q[i]<<"\n";
	
	return 0;
}


Measured memory_bytes: 27168