akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int mode = 0; // 0:平坦，1:上り，2:下り
    ll before = a[0];
    int cnt = 1;
    for (int i = 1; i < n; i++)
    {
        if (mode == 0)
        {
            if (before < a[i])
            {
                mode = 1;
            }
            else if (before > a[i])
            {
                mode = 2;
            }
            else
            {
                mode = 0;
            }
        }
        else if (mode == 1)
        {
            if (before > a[i])
            {
                ++cnt;
                mode = 0;
            }
        }
        else
        {
            if (before < a[i])
            {
                ++cnt;
                mode = 0;
            }
        }
        before = a[i];
    }
    cout << cnt << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
};

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);

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

mint dp[100005][13];

int main() {
    string s;
    cin >> s;
    int n = s.size();
    dp[0][0] = 1;
    rep(i,n) {
        int c;
        if (s[i] == '?') c = -1;
        else c = s[i]-'0';
        for (int j = 0; j <= 9; j++) {
            if (c != -1 && c != j) continue;
            for (int k = 0; k <= 12; k++) {
                dp[i+1][(k*10 + j)%13] += dp[i][k]; 
            }
        }
    }
    cout << dp[n][5] << endl;
    return 0;
}

Measured memory_bytes: 13884
#include <stdio.h>
#define MAX 100000
int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

int main(){
  int H,i,A[MAX+1];
  scanf("%d",&H);
  for (i=1 ; i<=H ; i++) scanf("%d",&A[i]);
  for (i=1 ; i<=H ; i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1) printf("parent key = %d, ",A[parent(i)]);
    if(left(i) <= H) printf("left key = %d, ",A[left(i)]);
    if(right(i)<= H) printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}
  



Measured memory_bytes: 2080
/* ex3_4
  terakura */

#include <stdio.h>

int main(void){
    int number, a = 9;
    scanf("%d", &number);

//1〜9で割り切れてかつ商が一桁のものを探す
    while(a > 0){
        if(number%a == 0 && number/a < 10){
            printf("Yes\n");
            break;      //見つかったら”yes”で終了

        }else{
            a--;
        }

//上で見つからなかったら終了
    if(a == 0){
        printf("No\n");
    }

    }

    return 0;
}


Measured memory_bytes: 128
#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>

using namespace std;

#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 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 GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

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(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

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

void print() {
  cout << endl;
}

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

int main() {
  GS(L);
  int N = L.size();
  ll ans = 1;
  vector<ll> tri_fact(N + 1);
  vector<ll> dp(N + 1);
  tri_fact[0] = 1;
  FORIN(i, 1, N + 1) tri_fact[i] = tri_fact[i - 1] * 3 % MOD;
  FOR(i, N) {
    if (L[N - 1 - i] == '1') {
      dp[i] = ((i > 0 ? dp[i - 1] : 1) * 2 + tri_fact[i]) % MOD;
    } else {
      dp[i] = i > 0 ? dp[i - 1] : 1;
    }
  }
  print(dp[N - 1]);
  return 0;
}

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

int main(){
  string s;
  cin>>s;
  int a[4];
  rep(i,4){
    a[i]=s[i]-'0';
  }
  rep(i,1<<3){
    int cal=a[0];
    string eq[3];
    rep(j,3){
      if((i>>j)&1){
        cal+=a[j+1];
        eq[j]='+';
      }else{
        cal-=a[j+1];
        eq[j]='-';
      }
    }
    if(cal==7){
      cout<<a[0];
      rep(i,3)cout<<eq[i]<<a[i+1];
      cout<<"=7"<<endl;
      return 0;
    }

  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
using namespace std;

int N,M,redu,add,ans = 0;

struct NODE{
	string U;
	int V;
}a[10005];

struct NODD{
	string U;
	int V;
}b[10005];

int main(){
	cin >> N;
	for(int i = 1;i <= N;i++){
		cin >> a[i].U;
	}
	cin >> M;
	for(int i = 1;i <= M;i++){
		cin >> b[i].U;
	}
	for(int i = 1;i <= N;i++){
		if(a[i].V == 0){
			redu = 0,add = 0;
			a[i].V = 1;
			for(int j = 1;j <= N;j++){
				if(a[i].U == a[j].U){
					a[j].V = 1;
					add++;
				}
			}
			for(int k = 1;k <= M;k++){
				if(a[i].U == b[k].U){
					b[k].V ==1;
					redu++;
				}
			}
			ans = max(ans,add - redu);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
import math
N = int(input())
mod = 1000000007
x = [1 for _ in range(1001)]
Sum = 1

for i in range(1, N + 1):
    z = i
    for j in range(2, int(math.sqrt(N)) + 1):
        while z % j == 0:
            x[j] += 1
            z = int(z / j)
    if z != 1:
        x[z] += 1

for i in x:
    Sum *= i
    Sum %= mod

print(Sum)


Measured memory_bytes: 9020
#if defined(LOCAL)
#define PROBLEM_NAME "a"
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) (debug(x, #x))
#define C(x...) CHECK(x)
#else
#define L(x, ...) (x)
#define C(x, ...) ;
#include <bits/stdc++.h>
#endif

using namespace std;
using vi = vector<int>; using vvi = vector<vi>;
using ii = pair<int,int>; using vii = vector<ii>;
using l = long long; using vl = vector<l>; using vvl = vector<vl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using lu = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<l>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(c) - 1; a >= l(b); a--)
#define MAX(a,b)({__typeof__(a)__x=(a);__typeof__(b)__y=(b);__x<__y?__y:__x;})
#define MIN(a,b)({__typeof__(a)__x=(a);__typeof__(b)__y=(b);__x<__y?__x:__y;})

void solve(istream& cin, ostream& cout) {
  string s; cin >> s;
  cout << s.substr(0, s.size() - 8) << endl;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
  maybe_run_tests(cin, cout);
#else
  solve(cin, cout);
#endif
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int K, N, max=0;
    cin >> K>>N;
    int A[N];
    for (int i=0; i<N; i++) cin >> A[i];
    for (int i=0; i<N-1; i++){
        if (max <= A[i+1] - A[i]) max=A[i+1]-A[i];
    }
    if (max < K-(A[N-1]-A[0])) max = K-(A[N-1]-A[0]);
    cout << K-max<< endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
#define foreach(ix,a) for(auto& (ix) : (a)
double kitaichi(int i){
  double x= i+1;
  x=x*i/2;
  return x/=i;
}
int main(){
  ios::sync_with_stdio(false);
  std::cout<<std::fixed<<std::setprecision(10);
  cin.tie(nullptr);
  int a,b;
  cin>>a>>b;
  int d[a];
  double k[a+1];
  k[0]=0;
  rep(i,a)cin>>d[i];
  rep(i,a)k[i]=kitaichi(d[i]);
  double sum[a+1];
  sum[0]=0;
  rep(i,a)sum[i+1]=sum[i]+k[i];
  double ans =0.0;
  rep(i,a-b+1){
    ans= max(ans,sum[i+b]-sum[i]);
  }
  cout<<ans<<endl;


}

Measured memory_bytes: 4224
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

public class Main {

	public static void main(String[] args) {
		while (true) {
			int N = nextInt();
			if (N == 0) {
				break;
			}

			HashMap<Integer, ArrayList<Integer>> hashMap = new HashMap<Integer, ArrayList<Integer>>();

			for (int i = 0; i < N; i++) {
				int M = nextInt();
				ArrayList<Integer> list = new ArrayList<Integer>();
				for (int j = 0; j < M; j++) {
					list.add(nextInt());
				}
				hashMap.put(i, list);
			}

			ArrayList<Integer> lost = new ArrayList<Integer>();
			int K = nextInt();
			for (int i = 0; i < K; i++) {
				lost.add(nextInt());
			}

			int badman = -1;
			for (int i = 0; i < hashMap.size(); i++) {
				boolean find = true;

				for (int looser : lost) {
					if (hashMap.get(i).size() == 0) {
						find = false;
						break;
					}
					for (int j = 0; j < hashMap.get(i).size(); j++) {
						if (hashMap.get(i).get(j) == looser) {
							break;
						}
						if (j == hashMap.get(i).size() - 1) {
							find = false;
						}
					}
					if (!find) {
						break;
					}
				}

				if (find) {
					if (badman == -1) {
						badman = i + 1;
					} else {
						badman = -1;
						break;
					}
				}
			}

			System.out.println(badman);

		}

	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

}

Measured memory_bytes: 28580
//start of jonathanirvings' template v3.0.3 (BETA)

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <deque>
#include <string>
#include <string.h>
#include <vector>
#include <stack>
#include <queue>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <time.h>
#include <bitset>
#include <list>
#include <assert.h>
#include <time.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

LL k,a,b;

int main()
{
  scanf("%lld %lld %lld",&k,&a,&b);
  if (a >= k)
  {
    puts("1");
    return 0;
  }
  LL butuh = k - a;
  if (a <= b)
  {
    puts("-1");
    return 0;
  }
  LL risan = (butuh + (a - b) - 1) / (a - b) * 2;
  printf("%lld\n",risan+1);
  return 0;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())


int main(){
	int x; cin >> x;
	repn(i,9)repn(j,9){
		if(i*j == x){
			puts("Yes"); return 0;
		}
	}
	puts("No");
}

Measured memory_bytes: 256
import sys

s = input().split('/')

y = int(s[0])
m = int(s[1])
d = int(s[2])

if y < 2019:
    print('Heisei')
    sys.exit(0)
if y > 2019:
    print('TBD')
    sys.exit(0)

if m < 4:
    print('Heisei')
    sys.exit(0)
if m > 4:
    print('TBD')
    sys.exit(0)


if d <= 30:
    print('Heisei')
    sys.exit(0)
if m > 30:
    print('TBD')
    sys.exit(0)




Measured memory_bytes: 38256
def fun(a):
    return a*(a-1)//2
import sys
def main():
    n = int(input())
    l = [int(j) for j in sys.stdin.readline().split()]
    d = dict()
    for i in range(n):
        if l[i] in d:
            d[l[i]]+=1
        else:
            d[l[i]]=1
    # print(d)
    ans = 0
    for key in d:
        ans+=fun(d[key])
    # a = len(d)*(len(d)-1)//2
    # b = (len(d)-1)*(len(d)-2)//2
    for i in range(n):
        if d[l[i]]==1:
            print(ans)
        else:
            print(ans - fun(d[l[i]]) + fun(d[l[i]]-1))
main()



Measured memory_bytes: 83404
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int c[3][3],i,j,x=0,y=0;
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			cin>>c[i][j];
		}
	}
	
	if(c[0][0]-c[0][1]==c[1][0]-c[1][1])
	{
		if(c[1][0]-c[1][1]==c[2][0]-c[2][1])
		{
			x=1;
		}
	}
	if(c[0][1]-c[0][2]==c[1][1]-c[1][2])
	{
		if(c[1][1]-c[1][2]==c[2][1]-c[2][2])
		{
			y=1;
		}
	}
	if(x==1 && y==1)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 3632
#include <iostream>
#include <cmath>

using namespace std;

bool isPrime(int num) {
    if (num != 2 && num % 2 == 0) {
        
        return false;
    }

    for (int i = 3; i <= num / i; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }
    
    return true;
}

int main() {
    int n;
    int num;
    int ans = 0;
    
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> num;
        if (isPrime(num)) {
            ans++;
        }
    }

    cout << ans << endl;
}




Measured memory_bytes: 3088
#include<iostream>
using namespace std;
typedef struct{
  char mark;
  int value;
  int order;
}t;
  
int main(){
  int N,minj,f=0;
  t C1[36],C2[36],a;
  cin>>N;
 
  if(N>0 && N<37){
    for(int i=0;i<=N-1;i++){
      while(1){
      cin>>C1[i].mark;
      if(C1[i].mark!='D'&&C1[i].mark!='C'&&C1[i].mark!='S'&&C1[i].mark!='H')continue;	
      cin>>C1[i].value;
      break;
      }
      C1[i].order=i+1;
      C2[i]=C1[i];
    }
  
    for(int i=0;i<=N-1;i++)//バブルソート
      for(int j=N-1;j>=i+1;j--)
	if(C1[j].value < C1[j-1].value){
	  a=C1[j];
	  C1[j]=C1[j-1];
	  C1[j-1]=a;
	}	
  
    for(int i=0;i<N-1;i++) cout<<C1[i].mark<<C1[i].value<<' ';
    cout<<C1[N-1].mark<<C1[N-1].value<<endl;
  
    for(int i=0;i<=N-1;i++)
      if(C1[i].value==C1[i-1].value && C1[i].order-C1[i-1].order<0)f=1;
  
  if(f==0) cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
  f=0;
  
  for(int i=0;i<=N-1;i++){//セレクションソート
    minj=i;
    for(int j=i;j<=N-1;j++)
      if(C2[j].value < C2[minj].value)minj=j;
    a=C2[i];
    C2[i]=C2[minj];
    C2[minj]=a;
  }
  
  for(int i=0;i<N-1;i++)cout<<C2[i].mark<<C2[i].value<<' ';
  cout<<C2[N-1].mark<<C2[N-1].value<<endl;
  for(int i=1;i<N;i++)
    if(C2[i].value==C2[i-1].value && C2[i].order-C2[i-1].order<0)f=1;
  if(f==0)cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
  }
  return 0;
}



Measured memory_bytes: 3104
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.num = [1] * (n+1)#集合の要素の数

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.num[y]+=self.num[x]
        else:
            self.par[y] = x
            self.num[x]+=self.num[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

      
n, m = map(int, input().split())
b = UnionFind(n)
comb = n*(n-1)//2
bridge = [list(map(int, input().split())) for i in range(m)]
rev = bridge[::-1]
ans = [0]*m 
ans[-1] = comb
for i in range(m-1):
  x, y = rev[i]
  if b.same_check(x, y):
      ans[-(i+2)]=ans[-(i+1)]
  else:
      s=b.num[b.find(x)]
      t=b.num[b.find(y)]
      ans[-(i+2)]=ans[-(i+1)]-s*t
      b.union(x, y)
for i in range(m):
  print(ans[i])

Measured memory_bytes: 100208
n, k = map(int, input().split())
s = input()

def search(s):
    ret = 0
    for i in range(len(s)):
        if s[i] == 'R' and i != n - 1:
            if s[i + 1] == 'R':
                ret += 1
        if s[i] == 'L' and i != 0:
            if s[i - 1] == 'L':
                ret += 1
    return ret

ans = search(s)
print(min(ans + 2 * k, len(s) - 1))


Measured memory_bytes: 40304
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, d;
  cin >> n >> d;
  vl x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  ll ans = 0;
  rep(i, n) {
    ll now = x[i] * x[i] + y[i] * y[i];
    if(now <= d * d) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6424
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    reverse(all(s));
    vec a(n+1,INF); a[0]=0;
    rep(i,n){
        int b=0;
        if(s[i]=='1') continue;
        for(int j=1;j<=m;j++){  
            if(range(i+j,0,n+1)){
                if(s[i+j]=='1') continue;
                chmin(a[i+j],a[i]+1); 
                chmax(b,i+j);
            }
        }
        if(b!=0)i=b-1;
    }
    // rep(i,n+1) debug(a[i]);
    if(a[n]==INF) cout<<-1<<endl;
    else{
        vec ans;
        map<int,int> mp;
        rep(i,n+1){
            if(s[i]=='1') continue;
            chmax(mp[a[i]],i);
        }
        for(auto x:mp) ans.pb(x.sc);
        reverse(all(ans));
        rep(i,ans.size()-1){
            cout<<ans[i]-ans[i+1]<<endl;
        }
    }
    
}


Measured memory_bytes: 8524
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
    
int main(){
  int n,id=1,nv,ch,index,syuryo=1;
      
  scanf("%d\n",&n);
  
  int *A = new int[100040];
  bool *B = new bool[100040];
  int *C = new int[100040];
  string *D = new string[100040];
  int st,ed;
  for(int i=0;i<=100040;i++){
    A[i]=0; // hukasa
    C[i]=-1; // oya
    B[i]=false; //false nara ko wo motte inai
  }
  for(int i=0;i<n;i++){
    scanf("%d",&id);
     
    getline(cin,D[id]);
  
    syuryo=1;
    for(int r=1;r<=D[id].length();r++){
      if(D[id][r] == ' '){
	syuryo = r-1; // String no iti gime
	break;
      }
    }
    
    index = atoi(D[id].substr(1,syuryo).c_str()); 
 
    if(index != 0)B[id]=true;
        
 
    if(index != 0){
      st = syuryo+2;   
      for(int d = syuryo+2;d<=D[id].length();d++){
	if(D[id][d] == ' ' || d == D[id].length()){
	  A[atoi(D[id].substr(st,d-st).c_str())]=A[id]+1;
	  C[atoi(D[id].substr(st,d-st).c_str())]=id;
	  if(B[atoi(D[id].substr(st,d-st).c_str())]){
	    int st2=3;
         
	    for(int j = syuryo+2;j<=D[atoi(D[id].substr(st,d-st).c_str())].length();j++){
           
	      if(D[atoi(D[id].substr(st,d-st).c_str())][j] == ' ' || j == D[atoi(D[id].substr(st,d-st).c_str())].length()){
		A[atoi(D[atoi(D[id].substr(st,d-st).c_str())].substr(st2,j-st2).c_str())]=A[atoi(D[id].substr(st,d-st).c_str())]+1;
		st2=j+1;
	      }
	    }
	  }
	  st = d+1;
	}
      }
       
    }
     
  }
      
  
      
  for(int i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,C[i],A[i]);
    int cou=0;
    if(C[i] == -1){printf("root, [");}
    else if(!B[i])printf("leaf, [");
    else printf("internal node, [");
     
 
    syuryo=1;
    for(int r=1;r<=D[i].length();r++){
      if(D[i][r] == ' '){
	syuryo = r-1;
	break;
      }
    }
    index = atoi(D[i].substr(1,syuryo).c_str());
     
    st=syuryo+2;
    if(index != 0){     
      for(int j=syuryo+2;j<=D[i].length();j++){
	if(D[i][j] == ' ' || D[i].length() == j ){
	  printf("%d",atoi(D[i].substr(st,j-st).c_str()));
	  if(j != D[i].length())printf(", ");
	  st=j+1;
	}
      }
    }
    printf("]\n");
  }
      
  delete [] A;
  delete [] B;
  delete [] C;
  delete [] D;
  return 0;
}

Measured memory_bytes: 5216
K, N = map(int, input().split()) 
# K:円周, N :家の数
A = list(map(int, input().split()))
# A:北から時計回りの家距離
k = []
for c in range(N):
    if c == N - 1:
        kk = K - sum(k)
    else:
        kk = A[c + 1] - A[c]
    k.append(kk)
print(sum(k) - max(k))

Measured memory_bytes: 26444
S = input()

def solve2():
    head = 0
    tail = 2
    while head < len(S):
        # print(S[head:tail])
        # print("\t" + S[head:tail][0:1])
        # print("\t" + S[head:tail][1:2])
        if S[head:tail][0:1] == S[head:tail][1:2]:
            return head + 1, tail
        head += 1
        tail += 1

    head = 0
    tail = 3
    while head < len(S):
        # print(S[head:tail])
        # print("\t" + S[head:tail][0:1])
        # print("\t" + S[head:tail][1:2])
        # print("\t" + S[head:tail][2:3])
        if S[head:tail][0:1] == S[head:tail][2:3]:
            return head + 1, tail
        head += 1
        tail += 1

    return -1, -1

res = solve2()
print(res[0], res[1])


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

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

    for(int i = 0; i < S.size(); i++){
        if(i % 2 == 1 && (S.at(i) == 'L' || S.at(i) == 'U' || S.at(i) == 'D'))
            continue;
        else if(i % 2 == 0  && (S.at(i) == 'R' || S.at(i) == 'U' || S.at(i) == 'D'))
            continue;
        else{
            cout << "No" << endl;
            return 0;
        }
    }   

    cout << "Yes" << endl;
}


Measured memory_bytes: 256
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


def lcm(a, b):
	return a * b // gcd (a, b)

A, B, C, D= list(map(int, input().split()))

cd = lcm(C,D)

print(B - A + 1 - (B // C - (A-1) // C) -(B // D - (A-1) // D) + (B // cd - (A-1) // cd))

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

#define M 1000000007
#define pb emplace_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; ++i)
#define repn(i, st, ed) for(ll i=st; i<=ed; ++i)
#define repb(i, ed, st) for(ll i=ed; i>=st; --i)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vec;
typedef vector<pll> vecp;
typedef map<ll, ll> mpll;

const long double PI  = 3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << to_string(H) << endl;
  debug_out(T...);
}
#define LOCAL 3
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif


void solve()
{
	int n; cin>>n;
	string s;
	cin>>s;
	ll asn= 0;
	rep(i, 0, n-2)
	{
		if(s[i] == 'A' && s[i+1] == 'B'&& s[i+2] == 'C') asn++;
	}
	cout<<asn<<endl;
}


int main()
{
	ll Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
    	solve();
    }
    return 0;
}

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

vector<vector<ll>> c;

ll comb(ll n, ll m){
    if(c[n][m] != -1) return c[n][m];
    if(n==m || m==0){
        c[n][m] = 1;
    }else{
        c[n][m] = comb(n-1,m-1) + comb(n-1,m);
    }
    return c[n][m];
}

int main(){
    int N, A, B;  cin >> N >> A >> B;
    vector<ll> v(N);
    for(int i=0; i<N; i++) cin >> v[i];
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    ll sum = 0;
    for(int i=0; i<A; i++){
        sum += v[i];
    }
    cout << fixed << setprecision(9) << 1.0*sum/A << endl;

    map<ll,ll> cnt;
    for(int i=0; v[i]>=v[A-1]; i++){
        if(cnt.find(v[i]) == cnt.end()){
            cnt[v[i]] = 1;
        }else{
            cnt[v[i]]++;
        }
    }

    c = vector<vector<ll>>(51, vector<ll>(51,-1));
    if(v[A-1] < v[0]){
        int n = 0;
        for(auto i=cnt.begin(); i!=cnt.end(); i++){
            if(i->first != v[A-1]){
                n+=i->second;
            }
        }
        cout << comb(cnt[v[A-1]], A-n) << endl;
    }else{
        ll ans = 0;
        ll n = cnt[v[0]];
        for(int i=0; i<=B-A; i++){
            if(v[A+i-1]<v[0]) break;
            ans += comb(n,A+i);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll INF=1000000010;
const int MAX=100001;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
ll dp[41][1<<17];
int main(){
    ll n,x,y,z;cin>>n>>x>>y>>z;
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<(1<<(x+y+z));j++){
            for(int k=1;k<=10;k++){
                ll to=((1<<(x+y+z))-1)&((j<<k)|(1<<(k-1)));
                if((to&(1<<(x+y+z-1)))&&(to&(1<<(y+z-1)))&&(to&(1<<(z-1))))continue;
                (dp[i+1][to]+=dp[i][j])%=MOD;
            }
        }
    }
    ll ans=1;
    for(int i=0;i<n;i++){
        (ans*=10)%=MOD;
    }
    ll sum=0;
    for(int i=0;i<(1<<(x+y+z));i++){
        (sum+=dp[n][i])%=MOD;
    }
    ans=(ans-sum+MOD)%MOD;
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 42368
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var nm=arr.shift().split(" ").map(Number);
var n=nm[0];
var m=nm[1];
var d=[];
for(var i=0;i<n;i++)d.push(arr.shift()-0);
var c=[];
for(var i=0;i<m;i++)c.push(arr.shift()-0);
var dp=[];
for(var i=0;i<=m;i++){
   dp[i]=[];
   for(var j=0;j<=n;j++){
      dp[i][j]=Infinity;
   }
}
dp[0][0]=0;
for(var i=0;i<m;i++){
   var C=c[i];
   for(var j=0;j<n;j++){
      var D=d[j];
      for(var k=1;i+k<=m;k++){
         dp[i+k][j]=Math.min(dp[i+k][j],dp[i][j]);
         dp[i+k][j+1]=Math.min(dp[i+k][j+1],dp[i][j]+C*D);
      }
   }
}
console.log(dp[m][n]);

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

int main()
{
    int N, maxX = 0, minX = 100;
    int minP = 1000000;
    int x[100];
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> x[i];
        if (maxX <= x[i])
            maxX = x[i];

        if (minX >= x[i])
            minX = x[i];
    }

    for (int i=minX; i <= maxX; i++)
    {
        int len = 0;
        for (int j = 0; j < N; j++)
        {
            len = len + (x[j] - i) * (x[j] - i);
        }
        if(minP > len){
            minP = len;
        }
    }

    cout << minP;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int time;
    scanf("%d",&time);
    int h=0,m=0,s=0;
    while(time>=3600){
        time-=3600;
        h++;
    }
    while(time>=60){
        time-=60;
        m++;
    }
    while(time>0){
        time-=1;
        s++;
    }
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


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

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

    int N, M;
    cin >> N >> M;
    vector<ll> a(N), b(N);
    for (int i = 0; i < N; ++i) {
        cin >> a.at(i) >> b.at(i);
    }
    vector<ll> c(M), d(M);
    for (int i = 0; i < M; ++i) {
        cin >> c.at(i) >> d.at(i);
    }

    for (int i = 0; i < N; ++i) {
        int ans = 0;
        ll mind = LLONG_MAX;
        for (int j = 0; j < M; ++j) {
            ll dist = abs(a.at(i) - c.at(j)) + abs(b.at(i) - d.at(j));
            if (dist < mind) {
                mind = dist;
                ans = j + 1;
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;


signed main(){

    std::vector<int> v(3);
    int temp = -1000;
    bool flag = true;

    for(int i = 0; i < 3; i++){
        std::cin >> v[i];
        if (temp < v[i]){
            temp = v[i];
        }
        else{
            flag = false;
        }
    }

    if (flag == true){
        std::cout << "Yes" << std::endl;
    }
    else{
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    int x, t;
    cin >> x >> t;

    cout << max(0, x - t) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1e9+7
using namespace std;
typedef long long ll;
const double pi=acos(-1);

int f(int x){
    int cnt=0;
    int i;
    for(i=1;i*i<x;++i){
        if(x%i==0) cnt+=2;
    }
    if(i*i==x) cnt++;
    return cnt;
}
int main(){
    int n;
    cin >> n;
    int ans=0;
    for(int c=1;c<n-1;++c){
        ans+=f(n-c);
    }
    ans++;
    cout << ans << endl;
}

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

int main()
{
	int s;
	cin>>s;
	
	bool fY=0,fM=0;
	if(0<s%100&&s%100<=12) fY=1;
	if(0<s/100&&s/100<=12) fM=1;
	
	if(fY==1&&fM==1) cout<<"AMBIGUOUS"<<endl;
	if(fY==1&&fM==0) cout<<"YYMM"<<endl;
	if(fY==0&&fM==1) cout<<"MMYY"<<endl;
	if(fY==0&&fM==0) cout<<"NA"<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

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

int main() {
  int k, s;
  cin >> k >> s;

  int ans = 0;
  for (int x=0; x<=k; ++x) {
    for (int y=0; y<=k; ++y) {
      int z = s - (x+y);
      if (0<=z && k>=z) ++ans;
    }
  }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    long long ans=(n-a+1)*(n-b+1);
    if(ans>0)
        printf("%lld",ans);
    else
        printf("0");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  string s;
  cin >> s;
  sort(ALL(s));
  if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2])
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}


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

#define int long long
const int INF = 100000000000000000;

const int MAX_N = 100005;
const int MAX_M = 100005;

int N, M;
int A[MAX_M], B[MAX_M];

bool used[MAX_M];
vector<int> L[MAX_N];
vector<int> R[MAX_N];

signed main()
{
    cin >> N;
    LL ans = 0;
    for(int i = 0; i < N; i++) {
        int a; cin >> a;
        ans += a-1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6400
N=int(input())
A=list(map(int,input().split()))
MOD=1000000007

D=[0]*N
s=0
for i in range(N):
    s += A[i]
    D[i] = s

s = 0
for i in range(1,N):
    a = A[i]*D[i-1]
    s = (s+a)%MOD
print(s)


Measured memory_bytes: 31500
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define SZ(x) ((int)((x).size()))

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

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

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

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

template<class TH>
void _dbg(const char* name, TH val){
    clog << name << ": " << val << endl;
}
template<class TH, class... TA>
void _dbg(const char* names, TH curr_val, TA... vals) {
    while(*names != ',') clog << *names++;
    clog << ": " << curr_val << ", ";
    _dbg(names+1, vals...);
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
    #define dbg_arr(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg(...)
    #define dbg_arr(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

const int MAXN = -1;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!

    LL A, B, C;
    cin >> A >> B >> C;
    cout <<  B + min(C, A+B+1) << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

int main(void)
{
	ll x[1000], y[1000], s[1000];
	ll temp;
	vp v;
	ll i = 0;

	while (1) {
		while (1) {
			cin >> x[i] >> y[i] >> s[i];
			if (x[i] == 0 && y[i] == 0 && s[i] == 0) {
				break;
			}
			i++;
		}
		n = i;
		REP(i, n)
		{
			ll mx = 0;
			FOR(j, 1, s[i])
			{
				FOR(k, j, s[i])
				{
					temp = j * (100 + x[i]) / 100 + k * (100 + x[i]) / 100;
					if (temp == s[i]) {
						temp = j * (100 + y[i]) / 100 + k * (100 + y[i]) / 100;
						if (temp > mx) {
							mx = temp;
						}
					}
				}
			}
			cout << mx << endl;
		}
		if (i == n) {
			return 0;
		}
	}
}

Measured memory_bytes: 3176
import itertools


def main():
    N = int(input())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    lst = sorted(P)

    for i, j in enumerate(itertools.permutations(lst)):
        if list(j) == P:
            a = i
        if list(j) == Q:
            b = i

    print(abs(a - b))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9072
//???????????????????????????????????????????°??????????????????¨?????????????????§, ???????????§???????????????
#include <iostream>
#include <algorithm>
using namespace std;

int power10[8];

int next(int n) {
	int ret = 0;
	for (int i = 1; i < 7; i++) {
		int a = n / power10[i];
		int b = n % power10[i];
		ret = max(ret, a * b);
	}
	return ret;
}

int main() {
	int q, n;
	
	power10[0] = 1;
	for (int i = 1; i < 8; i++) power10[i] = power10[i - 1] * 10;
	
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> n;
		for (int j = 0; ; j++) {
			if (n < 10) {
				cout << j << endl;
				break;
			}
			n = next(n);
		}
	}
	return 0;
}

Measured memory_bytes: 3120
from math import sqrt,ceil




# n=int(input())
# c,b=map(int,input().split())
# a=list(map(int,input().split()))

n,m=map(int,input().split())
a=list(map(int,input().split()))
if(n>=sum(a)):
    print(n-sum(a))
else:
    print("-1")

Measured memory_bytes: 67988
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 200010
ll n,k;
ll p[N];
vector<ll> g[N];
ll l[N],r[N];
void dfs1(ll x,ll from){
    for(auto y:g[x])if(y!=from){
	dfs1(y,x);
    }
    if(-1!=p[x]){
	l[x]=r[x]=p[x];
    }
    else{
	l[x]=-1e17,r[x]=1e17;
	for(auto y:g[x])if(y!=from){
	    chmax(l[x],l[y]-1);
	    chmin(r[x],r[y]+1);
	}
    }
}
bool dfs2(ll x,ll from,ll t){
    if((t+10000001)%2!=(l[x]+1000000000)%2&&l[x]>-1e9)return 0;
    if(l[x]<=t+1&&t+1<=r[x])p[x]=t+1;
    else if(l[x]<=t-1&&t-1<=r[x])p[x]=t-1;
    else return 0;
    for(auto y:g[x])if(y!=from){
	if(dfs2(y,x,p[x])==0)return 0;
    }
    return 1;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>n;
    for(int i=0;i<n-1;i++){
	ll a,b; cin>>a>>b;
	g[a].push_back(b);
	g[b].push_back(a);
    }
    for(int i=1;i<=n;i++){
	p[i]=-1;
    }
    cin>>k;
    ll root=-1;
    for(int i=0;i<k;i++){
	ll v; cin>>v;
	cin>>p[v];
	root=v;
    }
    dfs1(root,0);
    /*cout<<root<<endl;
    for(int i=1;i<=n;i++)cout<<i<<":"<<l[i]<<" "<<r[i]<<endl;*/
    bool ok=1;
    for(auto x:g[root]){
	ok&=dfs2(x,root,p[root]);
    }
    if(ok){
	cout<<"Yes"<<endl;
	for(int i=1;i<=n;i++){
	    for(auto x:g[i]){
		if(abs(p[i]-p[x])!=1)cout<<1/0<<endl;
	    }
	    cout<<p[i]<<endl;
	}
    }
    else cout<<"No"<<endl;
}




Measured memory_bytes: 18176
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let t = read::<usize>();
    let mut tseq = vec![0; n + 1];
    for i in 0..n {
        tseq[i] = read::<usize>();
    }
    tseq[n] = 1 << 40;
    let mut ans = 0;
    for i in 0..n {
        ans += std::cmp::min(t, tseq[i + 1] - tseq[i]);
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
vector<pair<pair<string, int>,int>>v;
signed main() {
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		string s; int p; cin >> s >> p;
		v.push_back(make_pair(make_pair(s, 100 - p), i + 1));
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; i++)cout << v[i].second << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int a, b, c; scanf("%d%d%d", &a, &b, &c);
  vector<int> array{a, b, c};
  sort(array.begin(), array.end());
  printf("%d %d %d\n", array[0], array[1], array[2]);
}
  


Measured memory_bytes: 2684
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <fstream>

using namespace std;

int main(){
	string s;
	cin>>s;
	int l = s.size();
	for(int k = l; k >=1; k--){
		if (l - k > k -1) continue;
		for(int i = l - k; i <= k - 1; i++){
			if (s[l - k] != s[i]) break;
			if (i ==k-1){
				cout<<k;
				return 0;
			}
		}
	}
	if (l%2 == 1) cout<<(l+1)/2<<endl;
	if (l%2 == 0) cout<<l/2<<endl;
	return 0;
}


Measured memory_bytes: 512