akhauriyash/Code-Regression huggingface dataset:
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#endif
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n;
signed main(){
	cin>>n;int ans=n-1;
	for(int i=1;i*i<=n;i++){
		if(n%i==0){
			ans=min(ans,i+n/i-2);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    int n;
    cin>>n;
    vi t(n),a(n);
    cin>>t>>a;
    vi ma(n,INF);
    vector<bool> fixed(n,0);
    REP(i,n){
        ma[i]=t[i];
        if(i==0 || t[i-1]<t[i]){
            fixed[i]=1;
        }
    }
    dprint(ma);
    dprint(fixed);
    REP(i,n){
        if(i==n-1 || a[i]>a[i+1]){
            if(fixed[i] && ma[i]!=a[i]){
                dprint("boo");
                cout<<0<<endl;
                return 0;
            }
            fixed[i]=1;
        }
        else if(fixed[i] && ma[i]>a[i]){
            dprint("boo!");
            cout<<0<<endl;
            return 0;
        }
        chmin(ma[i],a[i]);
    }
    ll ans=1;
    REP(i,n){
        if(!fixed[i])
            (ans*=ma[i])%=MOD;
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 1408
#include<iostream>
#include<string.h>
using namespace std;

int main()
{
    char w[105];
    int i,j,p=1;
    cin>>w;
    for( i=0;i<strlen(w);i++){
        if(w[i]=='0')
        continue;
        for(j=i+1;j<strlen(w);j++){
            if(w[i]==w[j]&&w[i]>='a'&&w[i]<='z'){
                p++;
                w[j]='0';
            }
        }
        if(p%2!=0){
            cout<<"No"<<endl;
            return 0;
        }
        p=1;
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 3528
n = int(input())
H = [int(x) for x in input().split()]

curr = H[0] - 1 if H[0] > 0 else H[0]
success = True
for nxt in H[1:]:
  if nxt - curr >= 1:
    nxt -= 1
  if nxt >= curr:
    pass
  else:
    success = False
    break
  curr = nxt
    
if success:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
int main(){
	vector<pair<int,int>>v;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		v.push_back({x,y});
	}
	for(int i=0;i<=n-3;i++){
		if(v[i].first==v[i].second &&v[i+1].first==v[i+1].second &&v[i+2].first==v[i+2].second){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cstring>

int main() {
	char s[201];
	scanf("%s", s);
	//printf("%d\n", strlen(s));
	int k = strlen(s);
	if (k % 2 != 0) {
		s[k-1] = '\0';
		k--;
	}
	//printf("%s\n", s);
	int first = 1;
	while(1) {
		char s1[101], s2[101];
		for(int i = 0; i < k/2; i++) {
			s1[i] = s[i];
			s2[i] = s[i + k/2];
		}
		s1[k/2] = '\0';
		s2[k/2] = '\0';
		//printf("%s %s\n", s1, s2);
		if (strcmp(s1, s2) == 0 && first != 1) {
			printf("%d\n", k);
			break;
		} else {
			k -= 2;
			first = 0;
		}
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#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 pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 1300000;

int main() {
    VI primes, d(N,1);
    FOR(i,2,N-1){
        if (!d[i]) continue;
        primes.push_back(i);
        int x = 2*i;
        while (x < N){
            d[x] = 0;
            x += i;
        }
    }
    int n;
    while (cin >> n && n){
        int i = 0;
        while (primes[i] < n) i++;
        cout << (primes[i] == n ? 0 : primes[i]-primes[i-1]) << endl;
    }

    return 0;
}

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

if len(S) == A+B+1:
    for i in range(A+B+1):
        if i != A:
            if S[i] == '-':
                print('No')
                quit()
        else:
            if S[i] != '-':
                print('No')
                quit()
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;
vector<pair<int,int>> v[2];
vector<int> ans;
int d[310][310];
int main(){
	int i,n,s,t;
	cin >> n >> s >> t;
	for(i=1;i<=n;i++){
		cout << "? " << s << " " << i << endl;
		int x; cin >> x; v[0].push_back({x,i});
		d[s][i] = x;
		cout << "? " << i << " " << t << endl;
		cin >> x; v[1].push_back({x,i});
		d[i][t] = x;
	}
	sort(v[0].begin(),v[0].end());
	ans.push_back(s);
	for(i=0;i<n;i++){
		pair<int,int> p = v[0][i];
		if(p.second==s) continue;
		cout << "? " << s << " " << p.second << endl;
		int x; cin >> x; d[s][p.second] = x;
		if(d[s][p.second] + d[p.second][t]==d[s][t]){
			ans.push_back(p.second);
			s = p.second;
		}
	}
	cout << "! " ;
	for(int x:ans){
		cout << x << " ";
	}
	cout << endl;
}
		
		
	
	


Measured memory_bytes: 4688
#include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
string getParts(string s,int num){
	string tmp = "";
	for (int i = 0; i < num; ++i)
	{
		/* code */
		tmp += s[i];
	}
	return tmp;
}
int main () {
	string s1,s2;
	cin >> s1 >> s2;
	int a = (int)s1.size() + 1;
	int b = (int)s2.size() + 1;
	int map[a][b];
	for (int i = 0; i < a; ++i)
	{
		/* code */
		for (int j = 0; j < b; ++j)
		{
			/* code */
			map[i][j] = 0;
		}
	}
	for (int i = 0; i < a; ++i)
	{
		/* code */
		map[i][0] = i;
	}
	for (int i = 0; i < b; ++i)
	{
		/* code */
		map[0][i] = i;
	}
	for (int i = 1; i < a; ++i)
	{
		/* code */
		for (int j = 1; j < b; ++j)
		{
			/* code */
			int p = map[i-1][j]+1;
			int q = map[i][j-1]+1;
			int r = map[i-1][j-1];
			if(s1[i-1] != s2[j-1]){
				r = map[i-1][j-1] + 1;
			}
			int tmp;
			tmp = min(p,q);
			tmp = min(tmp,r);
			map[i][j] = tmp;
		}
	}
	cout << map[a-1][b-1] << endl;
}


Measured memory_bytes: 7092
n = gets.to_i
 
class Player
  attr_accessor :id, :battle_orders, :possible_game, :end
 
  def initialize(id, battle_orders)
    @id = id
    @battle_orders = battle_orders
    @possible_game = true
    @end = false
  end
 
  def next_opponent_id
    battle_orders.first - 1
  end
 
  def battle
    battle_orders.shift
    self.possible_game = false
    self.end = true if finish?
  end
 
  def finish?
    battle_orders.empty?
  end
 
  def reset
    self.possible_game = true if possible_game == false
  end
end
 
 
players = []
n.times do |i|
  players << Player.new(i, gets.split.map(&:to_i))
end
 
day = 0
gamed_players = []
while true
  day += 1
  flg = true
  gamed_players2 = []
  gamed_players.each do |gamed_player|
    gamed_players2 << gamed_player
  end
  gamed_players = []
  gamed_players2 = players if day == 1
  gamed_players2.each do |player|
    next if player.end
    opponent_player = players[player.next_opponent_id]
    next if opponent_player.next_opponent_id != player.id || opponent_player.end
    if player.possible_game && opponent_player.possible_game
      flg = false
      player.battle
      opponent_player.battle
      gamed_players << player
      gamed_players << opponent_player
    end
  end
  if flg
    break
  end
  gamed_players.each(&:reset)
end
if players.all?(&:end)
  p day - 1
else
  p -1
end


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

typedef long long LL;
typedef pair<LL, LL> P;

int main() {
    LL n, x, d;
    cin >> n >> x >> d;

    if ( d==0 ) {
        if ( x==0 ) {
            cout << 1 << '\n';
        } else {
            cout << n+1 << '\n';
        }
        return 0;
    }

    if ( d<0 ) {
        d=-d; x=-x;
    }

    map<LL,vector<P>> mp;
    for ( int k=0; k<=n; k++ ) {
        LL s=k*x;
        LL l=(LL)k*(k-1)/2;  // 0+1+..+k-1
        LL r=l+(n-k)*k;      // (n-k)+..+n-1
        mp[(s%d+d)%d].emplace_back(s/d+l,s/d+r+1);
    }

    LL ans=0;
    for ( auto &p:mp ) {
        auto v=p.second;
        sort(v.begin(),v.end());
        LL now=-1e18;
        for ( int i=0; i<v.size(); i++ ) {
            LL l=v[i].first, r=v[i].second;
            if ( l>now ) {
                ans+=r-l;
                now=r;
            } else if ( r>now ) {
                ans+=r-now;
                now=r;
            }
        }
    }
    cout << ans << '\n';
    return 0;
}













Measured memory_bytes: 22144
/**
*    author:  yuya1234
*    created: 25.07.2020 21:03:01
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define SORT(x) sort(x.begin(),x.end())
#define SORTD(x) sort(x.rbegin(),x.rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define SZ(x) ll(x.size())

#define MEMSET(v, h) memset((v), h, sizeof(v))

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

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

  int a,b,c,k;
  cin>>a>>b>>c>>k;

  REP(i,k)
  {
    if(a<b && b<c)break;
    if(a>=b) b*=2;
    else if(b>=c) c*=2;
  }

  if(a<b && b<c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 3644
import math


class Vector2():
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, v):
        return Vector2(self.x+v.x, self.y+v.y)

    def __sub__(self, v):
        return Vector2(self.x-v.x, self.y-v.y)

    def __mul__(self, v):
        return Vector2(self.x*v, self.y*v)

    def __truediv__(self, v):
        return Vector2(self.x/v, self.y/v)

    def __abs__(self):
        return math.sqrt(float(self.x*self.x+self.y*self.y))

    def dot(self, v):
        return self.x*v.x+self.y*v.y

    def cross(self, v):
        return self.x*v.y-self.y*v.x

    def norm(self):
        d = abs(self)
        return Vector2(self.x/d, self.y/d)


def distanceLP(v1, v2, p):
    '''
    v1 -> v2の直線とpとの距離
    '''
    return abs((v2-v1).cross(p-v1))/abs(v2-v1)


def distanceSP(v1, v2, p):
    '''
    v1 -> v2の線分とpとの距離
    '''
    if (v2-v1).dot(p-v1) < 0.0:
        return abs(p-v1)
    if (v1-v2).dot(p-v2) < 0.0:
        return abs(p-v2)
    return distanceLP(v1, v2, p)


def intersect(p1, p2, p3, p4):
    '''
    p1p2とp3p4の交差判定
    '''
    t1 = (p1.x-p2.x)*(p3.y-p1.y)+(p1.y-p2.y)*(p1.x-p3.x)
    t2 = (p1.x-p2.x)*(p4.y-p1.y)+(p1.y-p2.y)*(p1.x-p4.x)
    t3 = (p3.x-p4.x)*(p1.y-p3.y)+(p3.y-p4.y)*(p3.x-p1.x)
    t4 = (p3.x-p4.x)*(p2.y-p3.y)+(p3.y-p4.y)*(p3.x-p2.x)
    return (t1*t2) < 0.0 and (t3*t4) < 0.0


def distance(a1, a2, b1, b2):
    '''
    線分a1a2とb1b2の距離
    '''
    if intersect(a1, a2, b1, b2):
        return 0.0
    return min([
        min([distanceSP(a1, a2, b1), distanceSP(a1, a2, b2)]),
        min([distanceSP(b1, b2, a1), distanceSP(b1, b2, a2)])
    ])


p0x, p0y, p1x, p1y = map(int, input().split())
p0 = Vector2(p0x, p0y)
p1 = Vector2(p1x, p1y)
q = int(input())
for i in range(q):
    x, y = map(int, input().split())
    p2 = Vector2(x, y)
    c = (p1-p0).cross(p2-p0)
    if math.isclose(c, 0.0):
        d = (p1-p0).dot(p2-p0)
        if d < 0.0:
            print("ONLINE_BACK")
        else:
            d1 = abs(p1-p0)
            d2 = abs(p2-p0)
            if d1 < d2:
                print("ONLINE_FRONT")
            else:
                print("ON_SEGMENT")
    elif c < 0.0:
        print("CLOCKWISE")
    else:
        print("COUNTER_CLOCKWISE")



Measured memory_bytes: 5768
//
//  main.cpp
//  beginner2
//
//  Created by zer0 on 2020/03/22.
//  Copyright © 2020 zer0. All rights reserved.
//

#include <iostream>
#include<string>

int main(int argc, const char * argv[]) {
    
    std::string str;
    std::cin >> str;
    int n = (int)str.length();
    
    std::string frontStr = str.substr(0, (n-1)/2);
    std::string lastStr = str.substr((n+3)/2-1, n+1-(n+3)/2);
    
    if(frontStr == lastStr){
        std::cout << "Yes";
    }else{
        std::cout << "No";
    }
    
    return 0;
}


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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 29
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

string s;
vector<char> ans;

int main(){
  cin >> s;
  REP(i,s.size()){
    if(s[i]!='B'){
      ans.push_back(s[i]);
    }else{
      if(ans.empty()) continue;
      ans.pop_back();
    }
  }
  REP(i,ans.size()){
    cout << ans[i];
  }
  cout << endl;
}


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

int main() {
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    priority_queue<ll, vector<ll>, greater<ll>> p, q;
    priority_queue<ll> r;
    //p入力
    for (int i = 0; i < A; i++) {
        ll a; cin >> a;
        p.push(a);
    }
    //大きいX項を残す
    for (int i = 0; i < A-X; i++) {
        p.pop();
    }
    
    //q入力
    for (int i = 0; i < B; i++) {
        ll b; cin >> b;
        q.push(b);
    }
    //大きいY項を残す
    for (int i = 0; i < B-Y; i++) {
        q.pop();
    }

    //r入力
    for (int i = 0; i < C; i++) {
        ll c; cin >> c;
        r.push(c);
    }
    
    //p, qについて，先頭（一番小さい項）をとりだす。
    ll flagp = 0; 
    ll flagq = 0;
    while(true) {
        ll mip = p.top();
        ll miq = q.top();
        if (flagp == X && flagq < Y) {
            if (r.top() > miq) {
                q.pop();
                q.push(r.top());
                flagq ++;
                r.pop();
            }
            else break;
        }
        else if (flagp < X && flagq == Y) {
            if (r.top() > mip) {
                p.pop();
                p.push(r.top());
                flagp ++;
                r.pop();
            }
            else break;
        }
        else if (flagp == X && flagq == Y) break;
        else {
            if (r.top() > min(mip, miq)) {
                ll val = r.top();
                r.pop();
                if (mip >= miq) {
                    q.pop();
                    q.push(val);
                    flagq ++;
                }
                else {
                    p.pop();
                    p.push(val);
                    flagp ++;
                }
            }
            else break;
        }
        if (r.size() == 0) break;
    }

    //p, qに入った値をすべて足す
    ll ans = 0;
    for (int i = 0; i < X; i++) {
        ans += p.top();
        p.pop();
    }
    for (int i = 0; i < Y; i++) {
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
using namespace std;
typedef long long ll;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;

int main() {
    int N;
    cin >> N;
    vector<string> v(N);
    vector<int> t(N);
    rep(i,N) cin >> v[i] >> t[i];
    string X;
    cin >> X;
    int m;
    rep(i,N) if(X == v[i]) m = i;
    int ans = 0;
    repi(i,m+1,N) ans += t[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    
    if (A%2 == 0 || B%2 == 0 || C%2 ==0) {
      System.out.println(0);
      return;
    }
    System.out.println(Math.min(Math.min((long) A*B, (long) B*C), (long) C*A));
  }
}


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

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

int main() {
	long long n,m,i,j,k,ans,cur,res,mod=1000000007;
	string s,t;
	cin >> n;
	vector<long long> a(n);
	for(i=0; i<n; i++){
		cin >> a[i];
	}
	cur=0;
	for(i=0; i<n; i++){
		if(cur+1==a[i]){
			cur++;
		}
	}
	if(cur==0){
		cout << -1;
	}else{
		cout << n-cur;
	}

	return 0;
}

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

void swap(int *a, int *b){
	int work;
	work = *a;
	*a = *b;
	*b = work;
}

int selectionSort(int array[],int n){
	int minj,cnt=0;
	for(int i=0;i<n;i++){
		minj=i;
		for(int j=i;j<n;j++){
			if(array[j]<array[minj]){
				minj=j;
			}
		}
		if(i!=minj){
			swap(&array[i],&array[minj]);
			cnt++;
		}
	}
	return cnt;
}

void printArray(int array[],int n){
	for(int i=0;i<n;i++){
		if(i>0) cout << " ";
		cout << array[i];
	}
	cout << endl;
}

int main(){
	int n,cnt;
	cin >> n;
	int array[101];
	for(int i=0;i<n;i++){
		cin >> array[i];
	}
	cnt = selectionSort(array,n);
	printArray(array,n);
	cout << cnt << endl;
}

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

using namespace std;

int main(){
  int A, B;
  cin >> A >> B;
  if(A+B==3) cout << 3 << endl;
  else if(A+B==4) cout << 2 << endl;
  else if(A+B==5) cout << 1 << endl;
  
  return 0;
}

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

for i in range(n):
    A[i] = A[i] - (i + 1)

A.sort()

tmp = sum(A) - n * A[0]
m = tmp

for i in range(n-1):
    tmp += (A[i+1]-A[i]) * (2*i+2-n)
    m = min(m, tmp)

print(m)


Measured memory_bytes: 26020
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

inline int read() {
	int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
	for (;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
}


int main() {
	
	int n,m;
	cin >> n >> m;
	if (n * m == 15) cout << "*";
	else if (n + m == 15) cout << "+";
	else cout << "x"; 
	
	return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

const int MAX_STRING_SIZE = 1000000;

ll base = 1007;

vector<ll> MODS({2147483647, 6700417, 524287, 1000000007}

);

vector<vector<ll>> invs(MODS.size()), pows(MODS.size());

ll powm(ll e, ll x, ll m) {
  if (x == 0) return 1;
  if (x == 1) return e;
  if (x % 2 == 0) return powm((e * e) % m, x / 2, m);
  return (e * powm(e, x - 1, m)) % m;
}

void RHinit() {
  int i = 0;
  for (auto &p : MODS) {
    invs[i].resize(MAX_STRING_SIZE + 1);
    invs[i][0] = 1;
    ll inv = powm(base, p - 2, p);
    for (int j = 1; j <= MAX_STRING_SIZE; j++) {
      invs[i][j] = (invs[i][j - 1] * inv) % p;
    }
    pows[i].resize(MAX_STRING_SIZE + 1);
    pows[i][0] = 1;
    for (int j = 1; j <= MAX_STRING_SIZE; j++) {
      pows[i][j] = (pows[i][j - 1] * base) % p;
    }
    i++;
  }
}

struct RH {
  int n;
  string s;
  vector<vector<ll>> hs;

  RH(string &s) : s(s) {
    if (pows[0].empty()) {
      RHinit();
    }
    n = s.size();
    hs.resize(MODS.size());
    for (int i = 0; i < MODS.size(); i++) {
      hs[i].resize(n + 1);
      hs[i][0] = 0;
      for (int j = 0; j < n; j++) {
        hs[i][j + 1] = (hs[i][j] + pows[i][j] * s[j]) % MODS[i];
      }
    }
  }

  vector<ll> substr(int l, int r) {
    vector<ll> ret(MODS.size());
    for (int i = 0; i < MODS.size(); i++) {
      ret[i] = (hs[i][r] - hs[i][l] + MODS[i]) % MODS[i];
      ret[i] *= invs[i][l];
      ret[i] %= MODS[i];
    }
    return ret;
  }
};

struct N {
  vector<ll> v;
};

bool operator<(const N &l, const N &r) {
  if (l.v[0] == r.v[0]) {
    if (l.v[1] == r.v[1]) {
      if (l.v[2] == r.v[2]) {
        return l.v[3] < r.v[3];
      }
      return l.v[2] < r.v[2];
    }
    return l.v[1] < r.v[1];
  }
  return l.v[0] < r.v[0];
}

int main() {
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  RH h(s);
  int l = 0, r = 1;
  set<N> ss;
  for (int i = 0; i < m; i++) {
    string t;
    cin >> t;
    if (t == "L++") {
      l++;
      r;
    } else if (t == "L--") {
      l--;
      r;
    } else if (t == "R++") {
      l;
      r++;
    } else if (t == "R--") {
      l;
      r--;
    }
    ss.insert(N{h.substr(l, r)});
  }
  cout << ss.size() << endl;
  return 0;
}



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

int main() {

    int N, T, A;
    cin >> N >> T >> A;
    vector<int> H(N, 0);
    vector<double> diff(N, 0);

    for (size_t i=0; i<H.size(); ++i) {
        cin >> H[i];
        diff[i] = abs((T - H[i] * 0.006) - A);
    }

    auto iter = min_element(diff.begin(), diff.end());
    size_t d = distance(diff.begin(), iter);
    cout << d + 1 << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B,K;
  cin>>A>>B>>K;
  vector<int>nazo(110,0);
  int a=1;
 for(int i=min(A,B);i>=1;i--){
 	if(A%i==0 && B%i==0){
    	nazo.at(a)=i;
      a++;
    }
 }
  cout<<nazo.at(K)<<endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
   double r,g;cin>>r>>g;
   cout<<g*2-r;
}



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

int main() {
  int N, a, b, c, d;
  cin >> N;
  a=N/1000;
  b=(N-N/1000*1000)/100;
  c=(N-(N/1000*1000)-(N-N/1000*1000)/100*100)/10;
  d=N-(N/1000*1000)-(N-N/1000*1000)/100*100-(N-(N/1000*1000)-(N-N/1000*1000)/100*100)/10*10;
 
  if (a==b && b==c){
    cout << "Yes" << endl;
  }
  else if (b==c && c==d){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

ll M;
int N;
vector<int> G[100000];
ll dp[100000];
ll dp1[100000];
ll dp2[100000];
bool used[100000];

void clear(){
    for(int i = 0; i < N; i++) used[i] = false;
}

void dfs(int v){
    used[v] = true;
    dp[v] = 1;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i]]){
            dfs(G[v][i]);
            dp[v] *= (dp[G[v][i]]+1);
            dp[v] %= M;
        }
    }
}

void dfs1(int v, int p){
    used[v] = true;
    vector<int> u;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i]]){
            u.push_back(G[v][i]);
        }
    }
    int n = u.size();
    vector<ll> vl(n+1);
    vl[0] = 1;
    vector<ll> vr(n+1);
    vr[n] = 1;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        vl[i+1] = vl[i]*(dp[u[i]]+1);
        vl[i+1] %= M;
    }
    cnt = 0;
    for(int i = n-1; i >= 0; i--){
        vr[i] = vr[i+1]*(dp[u[i]]+1);
        vr[i] %= M;
    }
    for(int i = 0; i < n; i++){
        dp1[u[i]] = (dp1[v]);
        dp1[u[i]] *= (vl[i]*vr[i+1])%M;
        dp1[u[i]] %= M;
        dp2[u[i]] = (dp2[v]-dp1[u[i]]+dp[u[i]])%M;
        dp2[u[i]] += M;
        dp2[u[i]] %= M;
        dp1[u[i]]++;
        dp1[u[i]] %= M;
        dfs1(u[i], v);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M;
    for(int i = 0; i < N-1; i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dfs(0);
    clear();
    dp1[0] = 1;
    dp2[0] = dp[0];
    dfs1(0, 0);
    for(int i = 0; i < N; i++){
        cout << dp2[i] << endl;
    }
}

Measured memory_bytes: 22656
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long ll;
typedef long double ld;
#define INF (1LL<<60)
#define MOD1 1000000007
/*swap 交換*/
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
/*2つのうち大きい数を返す*/
ll max2(ll a,ll b){return a>=b?a:b;}
/*2つのうち小さい数を返す*/
ll min2(ll a,ll b){return a>=b?b:a;}
/*絶対値*/
ll ABS(ll a){return a>=0?a:(-a);}
typedef struct{
    ll aa;
    ll bb;
}frequent;
// 小大
int compare(const void *a, const void *b){
    return *(ll *)a>*(ll *)b?1:*(ll *)a<*(ll *)b?-1:0;}
/*GCD*/
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
/*LCM*/
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(void){
    ll n,m,i;
    scanf("%lld%lld",&n,&m);
    char s[n+5],t[m+5];
    scanf("%s%s",s,t);
    ll p=gcd(n,m)-1;

    for(i=0;i<=p;i++){
        ll a=lcm(n,m)/m*i, b=lcm(n,m)/n*i;
        if(s[a]!=t[b]){
            printf("-1\n");
            return 0;
        }
    }
    printf("%lld\n",lcm(n,m));
    return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
cost=[]
value=[]
ans=[]

for _ in range(N):
    a,b=map(int, input().split())
    cost.append(a)
    value.append(b)

ans.append(sum([value[j] for j in range(N) if (K|cost[j])==K]))

for i in range(30):
    tmp=0
    if ((K>>i)&1)==1:
        Kr=(K&~(1 << i))|((1 << i)-1)
        for j in range(N):
            if (Kr | cost[j])==Kr:
                tmp+=value[j]
        ans.append(tmp)

print(max(ans))

Measured memory_bytes: 11864
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<tuple<string,int,int>> A;
  for(int i=1;i<N+1;i++){
    string S;
    int P;
    cin >> S >> P;
    P*=-1;
    A.push_back(tie(S,P,i));
  }
  sort(A.begin(),A.end());
  for(int i=0;i<N;i++){
    cout << get<2>(A.at(i)) <<endl;
  }
}
    
  

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

long long f(long long n)
{
    if (n == 0 || n == 1) {
        return 1;
    } else {
        return n * f(n - 2);
    }
}

int main()
{
    long long n;
    cin >> n;
    if (n % 2 == 1) {
        cout << 0 << endl;
    } else {
        long long m = 5, ans = 0;
        while ((n / 2) / m) {
            ans += (n / 2) / m;
            m *= 5;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
    cin>>a>>b;
    if(a>0)
        cout<<"Positive";
    else if(a==0||(a<0&&b>0))
        cout<<"Zero";
    else if((abs(b)-abs(a))%2!=0)
        cout<<"Positive";
    else cout<<"Negative";
    return 0;
}

Measured memory_bytes: 256
n=int(input())
ac=0
wa=0
tle=0
re=0
for i in range(n):
  x=input()
  if x=="AC":
    ac+=1
  elif x=="WA":
  	wa+=1
  elif x=="TLE":
  	tle+=1
  elif x=="RE":
    re+=1
print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle)) 
print("RE x "+str(re))

Measured memory_bytes: 9208
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> G[100005];

int ans, n, k;
bool v[100005];

int dfs(int cur = 1) {
	v[cur] = true;
	int h = 0;
	//printf("now %d\n", cur);
	for(int nx: G[cur]) {
		//printf("chk %d\n", nx);
		int ch = dfs(nx);
		if(ch == k - 1) {
			if(cur != 1) ans++;
		}
		else h = max(h, ch + 1);
	}
	return h;
} 

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 0;i < n;i++) {
		int d;
		scanf("%d", &d);
		if(i != 0) G[d].push_back(i + 1);//, printf("%d -> %d\n", d, i + 1);
		else if(d != 1) ans = 1;
	}
	//for(int i = 1;i <= n;i++)
	//	for(int to: G[i]) printf("%d -> %d\n", i, to);
	dfs();
	printf("%d\n", ans);
}

Measured memory_bytes: 10496
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using lld = long long int ;
#define mod 1000000007; 

int main(){
    lld N;
    cin >> N ;
    vector<int > A;
    int tmp;
    for(int i=0;i<N;i++){
        cin >> tmp;
        A.push_back(tmp);
    }
    sort(A.begin(),A.end());
    
    lld k=0;
    lld  ans=0;
    for(int i=1;i<N;i++){
        k=i/2;
        ans+=A[N-1-k];
    }
    cout << ans <<endl;
    return 0;
    return 0;
}

Measured memory_bytes: 4296
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll a, b; cin >> a >> b; ll cnt = 0;
    // 制約が優しいので、a~bの範囲で全探索
    for(ll i=a; i<=b; i++){
        // 必ず5桁なので、一の位と万の位、十の位と千の位が等しいか確認
        if(i/10000 == i%10 && (i/1000)%10 == (i/10)%10) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/soundhound2018-summer-qual/tasks/soundhound2018_summer_qual_c
//C - Ordinary Beauty
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
void test(){
    ll sum=0;
    FOR(i,1,3) FOR(j,1,3) FOR(k,1,3) FOR(l,1,3){
        vector<ll> tbl={
            i,j,k,l
        };
        FOR(p,1,tbl.size()){
            if(abs(tbl[p]-tbl[p-1])==1){
                ++sum;
            }
        }
    }
    double r=(double)sum/16.0;
    dump(sum,r);
}
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-2.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
#if LOCAL
    test();
#endif
    ll n,m,d; cin>>n>>m>>d;
    ll sc=0;
    sc += (n-d);
    if(d!=0)sc*=2;
    double r1=(double)sc/(double)(n*n);
    dump(r1);
    double ans=r1*(double)(m-1);
    cout<<fixed<<std::setprecision(10)<<ans<<endl;
    return 0;
}

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

typedef pair<int,int> pii;

/*
obv O(NM) dp, but we can use a heap/set to find minimum
actually we can amortize?
*/

/*
remember to read the statement carefully...
*/

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,m;	
	string s;
	cin >> n >> m >> s;
	set<pii> moves;
	moves.insert({0,n});
	int ans = -1;
	int dp[n+1];
	dp[n] = 0;
	for(int i = n-1; i >= 0; --i){
		if(s[i] == '0'){
			while(moves.size() && moves.begin()->second > i + m)moves.erase(moves.begin());
			if(moves.size()){
				auto it = moves.begin();	
				dp[i] = it->second - i;
				moves.insert({it->first + 1, i});
			}
			else{
				dp[i] = -1;	
			}
		}
		else{
			dp[i] = -1;
		}
	}
	if(dp[0] != -1){
		vector<int> ans;
		int ind = 0;
		while(ind != n){
			ans.push_back(dp[ind]);
			ind += dp[ind];
		}
		for(int a:ans){
			cout << a << ' ';	
		}
		cout << '\n';
	}
	else{
		cout << -1 << '\n';
	}
}


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

int main() {
  int num[101] = {0};
  int a;
  int maxi = 0;
  while(cin >> a) {
    maxi = max(maxi, ++num[a]);
  }
  for(int i = 0; i < 101; ++i) {
    if(num[i] == maxi) cout << i << endl;
  }
  return 0;
}

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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int N = (int) 1e9;

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
#ifdef _DEBUG
	int t_start = clock();
#endif
	
	int n;
	scanf("%d", &n);
	int a[n];
	ll total = 0;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
		total += a[i];
	}
	ll ans = 2e9 + 7;
	ll sum = 0;
	for (int i = 0; i < n-1; ++i) {
		sum += a[i];
		total -= a[i];
		ans = min(ans, abs(sum - total));
	}

	printf("%I64d\n", ans);

#ifdef _DEBUG
	fprintf(stderr, "time: %d ms", clock() - t_start);
#endif
	return 0;
}


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

using namespace std;

// template for creating 2d vector
template<typename T>
vector<vector<T>> make_2d_vector(size_t rows, size_t cols, T init)
{ return vector< vector<T> >(rows, vector<T>(cols, init)); }

#define debug(x) cout << #x << "==" << x << endl;
const int inf = 1e+8;
const int mod = 1e+9 + 7;
typedef long long ll;

// a^b
ll pow(ll a, int b){
    int ret = 1;
    while(b){
        if(b & 1) ret = (1ll) * ret * a % mod;
        b >>= 1;
        a = (1ll) * a * a % mod;
    }
    return ret;
}


int main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

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

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

  bool ok = true;

  if( N % 2 == 0 ) {
    int n = 1;
    for(int i = 0; i < N; i += 2) {
      if( a[i] == n and a[i+1] == n ) {
        n += 2;
      } else {
        ok = false;
        break;
      }
    }
  }
  else {
    if( a[0] != 0 ) { ok = false; }
    else {
      int n = 2;
      for(int i = 1; i < N; i += 2 ) {
        if( a[i] == n and a[i+1] == n ) {
          n += 2;
        } else {
          ok = false;
          break;
        }
      }
    }
  }

  if( not ok ) {
    cout << 0 << "\n";
  } else {
    cout << pow(2, N / 2) << "\n";
  }


  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <cctype>
#include <cstdlib>
#include <set>
#include <map>
#include <sstream>
using namespace  std;
#define  ll long long
#define mINF(a) memset(a,INF,sizeof(a))
#define m0(a) memset(a,0,sizeof(a))
#define mf1(a) memset(a,-1,sizeof(a))
#define lson i<<1,l,l+r>>1
#define rson i<<1|1,((l+r)>>1)+1,r
typedef pair<ll,ll>P;
static const ll INF=1e18;
static const ll len=2e5+7;
int main()
{
	ll m[4][4];
	for(ll i=1;i<=3;++i)
	{
		for(ll j=1;j<=3;++j)
			cin>>m[i][j];
	}
	ll a[4],b[4],w=0;
	for(a[1]=0;a[1]<=100;++a[1])
	{
		b[1]=m[1][1]-a[1];
		a[2]=m[2][1]-b[1];
		a[3]=m[3][1]-b[1];
		b[2]=m[1][2]-a[1];
		b[3]=m[1][3]-a[1];
		w=0;
		for(ll i=1;i<=3;++i)
		{
			for(ll j=1;j<=3;++j)
				if(a[i]+b[j]!=m[i][j])
					w=1;
		}
	}
	if(w)puts("No");
	else puts("Yes");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
//
//
int main(){
	ll A,B,C,K;
	cin>>A>>B>>C>>K;
	if(K%2==0){
		if((A-B)>1e18){
			cout<<"Unfair"<<endl;
		}else{
			cout<<A-B<<endl;
		}
	}else{
		if((B-A)>1e18){
			cout<<"Unfair"<<endl;
		}else{
			cout<<B-A<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	int d, g;
	cin >> d >> g;
	vector<pair<int, int> > s(d);
	for(int i=0; i<d; i++)
		cin >> s[i].first >> s[i].second;
	int ans=INT_MAX;
	for(int i=0; i<1<<d; i++){
		int num=0, p=0, higher0;
		for(int j=0; j<d; j++){
			if(i&1<<j){
				num+=s[j].first;
				p+=(j+1)*100*s[j].first+s[j].second;
			}
			else
				higher0=j;
		}
		if(p+(higher0+1)*100*(s[higher0].first-1)<g)
			continue;
		while(p<g){
			num++;
			p+=(higher0+1)*100;
		}
		ans=min(ans, num);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;

const int maxn=1e5+5;

int n,rt,tot,deg[maxn];
int A[maxn],now[maxn],pre[maxn*2],son[maxn*2];

int read() {
    int x=0,f=1;char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
    return x*f;
}

void add(int a,int b) {
    pre[++tot]=now[a];
    now[a]=tot,son[tot]=b;
}

ll dfs(int fa,int u) {
    if(deg[u]==1)return A[u];
    ll remain=A[u]<<1;
    for(int p=now[u],v=son[p];p;p=pre[p],v=son[p])
        if(v!=fa) {
            ll tmp=dfs(u,v);
            if(tmp>A[u]) {puts("NO");exit(0);}
            remain-=tmp;
        }
    if(remain<0||remain>A[u]) {puts("NO");exit(0);}
    return remain;
}

int main() {
    n=read();
    for(int i=1;i<=n;i++)
        A[i]=read();
    if(n==2) {
        if(A[1]==A[2])puts("YES");
        else puts("NO");return 0;
    }
    for(int i=1;i<n;i++) {
        int x=read(),y=read();
        add(x,y),add(y,x);deg[x]++,deg[y]++;
        if(deg[x]>1)rt=x;if(deg[y]>1)rt=y;
    }
    if(dfs(0,rt))puts("NO");
    else puts("YES");
    return 0;
}

Measured memory_bytes: 7552
using System;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		// スペース区切りの整数の入力
		string[] input = Console.ReadLine().Split(' ');
		int b = int.Parse(input[0]);
		string c = input[1];
		int d = int.Parse(input[2]);
		if(c=="+")
		Console.WriteLine(b+d);
      if(c=="-")Console.WriteLine(b-d);
	}
}

Measured memory_bytes: 11220
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

    ans = 0
    for i in range(N - 2):
        if S[i : i + 3] == 'ABC':
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61720
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
#include <cfloat>
#include <complex>
using namespace std;
int main() {
	int n; cin >> n;
	string state; cin >> state;
	int left = 0, right = n - 1;
	int count = 0;
	while (left < right) {
		while (left < state.size() && state[left] != 'W') {
			++left;
		}
		while (right >= 0 && state[right] != 'R') {
			--right;
		}
		if (left < right) {
			++count;
			swap(state[left], state[right]);
		}
	}
	cout << count << '\n';
}

Measured memory_bytes: 3708
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var b = new int[n];
        for (int i = 0; i < n; i++) b[i] = a[i] - (i + 1);
        //if (n % 2 == 1)
        {
            var med = getMed(b);
            Console.WriteLine(getSum(a, med));
        }
        //else
        //{
        //    var med1 = b[n / 2];
        //    var ret1 = getSum(b, med1);
        //    var med2 = b[n / 2 - 1];
        //    var ret2 = getSum(b, med2);
        //    Console.WriteLine(Math.Min(ret1, ret2));
        //}
    }
    public static int getMed(int[] a)
    {
        Array.Sort(a);
        return a[a.Length / 2];
    }
    public static long getSum(int[] a, int b)
    {
        var n = a.Length;
        var ret = 0L;
        for (int i = 0; i < n; i++)
            ret += Math.Abs(a[i] - b - i - 1);
        return ret;
    }
}

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

int D;

int main(){
    scanf("%d", &D);
    if (D == 25) puts("Christmas");
    if (D == 24) puts("Christmas Eve");
    if (D == 23) puts("Christmas Eve Eve");
    if (D == 22) puts("Christmas Eve Eve Eve");
    return 0;
}


Measured memory_bytes: 256
#include "stdio.h"

int main()
{
	int x, y, z;
	scanf("%d %d %d\n", &x, &y, &z);

	if (x <= y && y <= z) {
		printf("%d %d %d\n", x, y, z);
	}
	else if (y <= z && z <= x) {
		printf("%d %d %d\n", y, z, x);
	}
	else if (z <= x && x <= y) {
		printf("%d %d %d\n", z, x, y);
	}
	else if (x <= z && z <= y) {
		printf("%d %d %d\n", x, z, y);
	}
	else if (y <= x && x <= z) {
		printf("%d %d %d\n", y, x, z);
	}
	else if (z <= y && y <= x) {
		printf("%d %d %d\n", z, y, x);
	}

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define db double
#define Pi acos(-1)
db A, B, H, M;
int main(){
    cin>>A>>B>>H>>M;
    db a = 2 * Pi / 60.0 * (H * 60 + M);
    db b = 2 * Pi / 720.0 * (H * 60 + M);
    db c = fabs(a - b);
    printf("%.9lf\n", sqrt(A * A + B * B - 2 * B * A * cos(c)));
    return 0;
}


Measured memory_bytes: 4216
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = pow(10, 8);
int main(){
  int n, m;cin>>n>>m;char z;
  vector<vector<int> > dis(n, vector<int>(n, INF));
  for(int i=0;i<m;i++){
    int a, b, c, d;cin>>a>>z>>b>>z>>c>>z>>d;
    a--;b--;
    dis[a][b]=c;dis[b][a]=d;
  }
  for(int i=0;i<n;i++)dis[i][i]=0;
  int s, g, v, p;cin>>s>>z>>g>>z>>v>>z>>p;s--;g--;
  int ans=v-p;
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        dis[i][j]=min(dis[i][j], dis[i][k]+dis[k][j]);
      }
    }
  }
  ans -= dis[s][g]+dis[g][s];
  cout<<ans<<endl;
  return 0;
}



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

public class Main {

	void run() throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int N = Integer.parseInt(br.readLine());

		int[] number = new int[N];
		for (int i = 0; i < N; i++) {
			number[i] = Integer.parseInt(br.readLine());
		}

		int maxv = -1000000000;
		int minv = number[0];
		for (int i = 1; i < N; i++) {
			maxv = Math.max(maxv, number[i] - minv); 
			minv = Math.min(number[i], minv);
		}
		System.out.println(maxv);
	}

	public static void main(String[] args) throws IOException {
		new Main().run();
	}
}

Measured memory_bytes: 43144
import re

def solution(N):
    if (N < 1000 or N > 9999):
        print ("No")
        return  
    N_str = list(str(N))

    if (N_str[0] == N_str[1] == N_str[2]):
          print ("Yes")
          exit()
    if (N_str[3] == N_str[1] == N_str[2]):
          print ("Yes")
          exit()      
    print ("No")
    return


if __name__ == '__main__':
    N = input()
    if re.match('^[0-9]{1,}$', N):
        solution(int(N))
    else:
        print ("No")
        exit()


Measured memory_bytes: 3188