akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    out(x / 10);
    }
    putchar('0' + x % 10);
}
int cnt[1005][1005],N,D,a;
int s2[1005][1005],s3[1005][1005];
int sum2(int x1,int y1,int x2,int y2) {
    if(x1 > x2 || y1 > y2) return 0;
    ++x1,++y1,++x2,++y2;
    return s2[x2][y2] - s2[x2][y1 - 1] - s2[x1 - 1][y2] + s2[x1 - 1][y1 - 1];
}
int sum3(int x1,int y1,int x2,int y2) {
    if(x1 > x2 || y1 > y2) return 0;
    ++x1,++y1,++x2,++y2;
    
    return s3[x2][y2] - s3[x2][y1 - 1] - s3[x1 - 1][y2] + s3[x1 - 1][y1 - 1];
}
bool check2(int x,int y,int b) {
    int d1 = sum2(max(0,b + x - D + 1),max(0,b + y - D + 1),x - 1,y - 1);
    int d2 = sum2(x + b + 1,y + b + 1,D - 1,D - 1);
    int d3 = sum2(max(0,b + x - D + 1),y + b + 1,x - 1,D - 1);
    int d4 = sum2(x + b + 1,max(0,b + y - D + 1),D - 1,y - 1);
    return !d1 && !d2 && !d3 && !d4;
}
bool check3(int x,int y,int b) {
    int d1 = sum3(x + b + 1,0,D - 1,D - 1);
    int d2 = sum3(0,y + b + 1,D - 1,D - 1);
    int d3 = sum3(max(0,b + x - D + 1),0,x - 1,D - 1);
    int d4 = sum3(0,max(0,b + y - D + 1),D - 1,y - 1);
    return !d1 && !d2 && !d3 && !d4;
}
void Solve() {
    read(N);read(D);
    int x,y;
    for(int i = 1 ; i <= N ; ++i) {
    read(x);read(y);
    cnt[x % D][y % D]++;
    }
    int t = 0;
    for(int i = 0 ; i < D ; ++i) {
    for(int j = 0 ; j < D ; ++j) {
        if(cnt[i][j]) {
        t = sqrt(cnt[i][j]);
        if(t * t < cnt[i][j]) ++t;
        a = max(t - 1,a);
        }
    }
    }
    for(int i = 0 ; i < D ; ++i) {
    for(int j = 0 ; j < D ; ++j) {
        if(cnt[i][j] > a * a && cnt[i][j] <= a * (a + 1)) s2[i + 1][j + 1]++;
        else if(cnt[i][j] > a * (a + 1)) s3[i + 1][j + 1]++;
    }
    }
    for(int i = 1 ; i <= D ; ++i) {
    for(int j = 1 ; j <= D ; ++j) {
        s2[i][j] = s2[i][j] + s2[i - 1][j] + s2[i][j - 1] - s2[i - 1][j - 1];
        s3[i][j] = s3[i][j] + s3[i - 1][j] + s3[i][j - 1] - s3[i - 1][j - 1];
    }
    }
    int b;
    for(b = 0 ; b < D ; ++b) {
    if(check2(0,0,b) && check3(0,0,b)) break; 
    }
    for(int i = 0 ; i < D ; ++i) {
    for(int j = 0 ; j < D ; ++j) {
        if(!(i + j)) continue;
        while(b) {
        if(check2(i,j,b - 1) && check3(i,j,b - 1)) --b;
        else break;
        }
    }
    }
    out(a * D + b);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}

Measured memory_bytes: 12032
N,M=map(int,input().split())

H=[0]*N
for i in range(N):
    K,*H[i],=map(int,input().split())

ans=M
j=1
while j<=M:
    for x in H:
        if j not in x:
            ans-=1
            break
    j+=1

print(ans)

Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d%d",&a,&b);
	if(a == b) printf("Draw");
	else if(a == 1) printf("Alice");
	else if(b == 1) printf("Bob");
	else if(a>b) printf("Alice");
	else if(a<b) printf("Bob");

	return 0;
}



Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, T;
ll A[3010], B[3010];
ll dp[3010][3010];
std::vector<P> ps;
ll right[3010];

int main()
{
  std::cin >> N >> T;
  
  rep( i, N ) {
    std::cin >> A[i] >> B[i];

    ps.emplace_back( A[i], B[i] );
  }

  std::sort(all(ps));

  rep( i, N )
    A[i] = ps[i].first, B[i] = ps[i].second;

  rep( i, N ) rep( j, T ) {
    chmax( dp[i+1][j], dp[i][j] );
    
    if( j-A[i] >= 0 )
      chmax( dp[i+1][j], dp[i][j-A[i]]+B[i] );
  }

  ll ans = 0;

  rep( i, N+1 )
    chmax( ans, dp[i][T-1]+B[i] );

  std::cout << ans << std::endl;

  return 0;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int counter = 0;
  for (int i = 0; i < S.size(); i++) {
    char a = S.at(i);
    char b = T.at(i);
    if (a == b)
      counter += 0;
    else if (a != b)
      counter += 1;
  }
  cout << counter << endl;
}


Measured memory_bytes: 3912
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, K] = [int(input_raw[0]), int(input_raw[1])]
    A = []
    for i in range(N):
        input_raw = read_func().strip().split()
        [a, b] = [int(input_raw[0]), int(input_raw[1])]
        A.append((a, b))
    A.sort()

    count = 0L
    for i in range(N):
        count += A[i][1]
        if count >= K:
            print A[i][0]
            return




if __name__ == '__main__':
    main()


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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    ll a, b, n;
    cin >> a >> b >> n;
    ll ans;
    if (n >= b - 1)
        ans = (a * (b - 1)) / b;
    else
        ans = (a * n) / b;

    out(ans);
    return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>

#define n 10000
#define q 500

int main(){

  int a,b,i,j,status;

  int count = 0;
  
  int S[n],T[q];
  
  scanf("%d",&a);

  for(i=0;i<a;i++){
    scanf("%d",&S[i]);
  }

  scanf("%d",&b);

  for(i=0;i<b;i++){
    scanf("%d",&T[i]);
    j = 0;
    while(j<a){
      if(S[j] == T[i]){
	count++;
	break;
      }
      j++;
    }
  }

  printf("%d\n",count);



  return 0;
}



Measured memory_bytes: 2140
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#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 mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


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


int main() {
	int N = 60000;
	vi p(N, 1);
	p[0] = p[1] = 0;
	rep (i, N) if (p[i]) for(int j = i + i; j < N; j += i) p[j] = 0;
	for (int n; cin >> n; ) {
		for(int i = n - 1; ; i--) if (p[i]) {
			cout << i << ' ';
			break;
		}
		for(int i = n + 1; ; i++) if (p[i]) {
			cout << i << endl;
			break;
		}
	}
	
	return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
  static inline int64 Normalize(int64 x) {
    if (0 <= x && x < P) return x; x %= P; if (x < 0) x += P; return x;
  }
 public:
  FiniteField(int64 x) : x(Normalize(x)) {}
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

tuple<vector<FiniteField>, vector<FiniteField>> MakeFactorialTables(int n) {
  vector<FiniteField> factorials(n + 1);
  vector<FiniteField> inverse_factorials(n + 1);
  factorials[0] = 1;
  for (int i = 1; i <= n; i++) {
    factorials[i] = factorials[i - 1] * i;
  }
  inverse_factorials[n] = FiniteField(1) / factorials[n];
  for (int i = n; i >= 1; i--) {
    inverse_factorials[i - 1] = inverse_factorials[i] * i;
  }
  return make_tuple(factorials, inverse_factorials);
}

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

  int n, m;
  cin >> n >> m;
  if (abs(n - m) >= 2) {
    cout << 0 << endl;
    return 0;
  }

  vector<FiniteField> fs;
  tie(fs, ignore) = MakeFactorialTables(max(n, m) + 1);
  auto ans = fs[n] * fs[m];
  if (n == m) ans *= 2;
  cout << ans.Value() << endl;
}

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

int main() {
	int a = 0;
	for(int i = 0; i < 3; i++) {
		int b;
		cin >> b;
		a *= 2;
		a += b;
	}
	if(a == 6 || a == 1)
		cout << "Open" << endl;
	else
		cout << "Close" << endl;
}

Measured memory_bytes: 1156
#include <cstdio>
#include <cstring>

int ch[1000010][26],pr[1000010];
int ct[1000010],ex[1000010][26];
bool fn[1000010];
int N;


void add(int i,char *s)
{
  //printf("%d %c\n",i,*s);
  if(*s==0){
    fn[i]=true;
  }
  else if(ch[i][(*s)-'a']==-1){
    ch[i][(*s)-'a']=N;
    for(int x=0;x<26;x++){
      ch[N][x]=-1;
    }
    fn[N]=false;
    N++;
    add(N-1,s+1);
  }
  else{
    add(ch[i][(*s)-'a'],s+1);
  }
}

long long ans;

void count(int i)
{
  ct[i]=(fn[i]?1:0);
  for(int y=0;y<26;y++){
    ex[i][y]=0;
  }
  for(int x=0;x<26;x++){
    int j=ch[i][x];
    if(j==-1)continue;
    count(j);
    ct[i]+=ct[j];
    for(int y=0;y<26;y++){
      if(y==x){
	ex[i][y]+=ct[j];
      }
      else{
	ex[i][y]+=ex[j][y];
      }
    }
  }
  for(int x=0;x<26;x++){
    int j=ch[i][x];
    if(j!=-1&&fn[j]){
      ans+=ex[i][x]-1;
    }
  }
}


int main()
{
  int n;
  scanf("%d",&n);
  for(int x=0;x<26;x++){
    ch[0][x]=-1;
  }
  fn[0]=false;
  N=1;
  for(int i=0;i<n;i++){
    static char t[1000010],s[1000010];
    scanf("%s",t);
    int l=strlen(t);
    for(int j=0;j<l;j++){
      s[l-j-1]=t[j];
    }
    s[l]=0;
    add(0,s);
  }
  ans=0ll;
  count(0);
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 284908
#include <bits/stdc++.h>
using namespace std;
typedef   long long int  ll ;
#define len(x)            x.length()
#define pb                push_back
#define mp                make_pair
#define all(x)            (x).begin(),(x).end()
#define M                 1000000007
#define MM                998244353
#define ff                first
#define ss                second
#define pii               pair<int,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define GCD(x,y)          (__gcd((x), (y)))
#define LCM(x,y)          (((x)/__gcd((x), (y)))*(y))
#define mem0(x)           memset(x, 0, sizeof (x))
#define mem1(x)           memset(x, -1, sizeof (x))
#define forn(i, n)        for (int i = 0; i < int(n); i++)

ll su1(ll n){
  return (n*(n+1))/2;
}
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 
int main()
{
  ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
  ll n,m;
  cin>>n>>m;
  if(n<m)cout<<min(n,abs(n-m));
  else cout<<min(n%m,abs(n%m - m));



}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using ll = long long;
using namespace std;
#define modmod 1000000007


int main(){
    int N;
    string S;
    cin >> N >> S;
    int left=0, right=0;
    string result;
    for(int i = 0; i < N; i ++){
        if(S[i] == '('){
            left++;
        }else{
            right++;
        }
        result.push_back(S[i]);
        if(right > left){
            result.insert(result.begin(),'(');
            left++;
        }
    }

    for(int i = 0; i < left-right; i ++){
        result.push_back(')');
    }

    printf("%s",result.c_str());

    return 0;
}


Measured memory_bytes: 256
n,m,x = map(int, input().split())
# print(n,m,x)
c = [0]*n
a = [[]]*n
# print(a)
for i in range(n):
    d = [*map(int, input().split())]
    c[i] = d[0]
    a[i] = d[1:]
    # print(x)
# print(c)
# print(a)
ans = inf = 10**18

for bit in range(1<<n): #  [0,(2^N)-1] full search
    cost = 0
    skill = [0]*m
    for book in range(n): # [0,N-1] book no.
        # print(book, bit, bit>>(n-1-book))
        if(bit>>book & 1): # buy
            cost += c[book]
            for j in range(m):
                skill[j] += a[book][j] # skill get
    # print(skill)
    # print(cost)

    # ok = True
    # for s in skill:
    #     if s < x:
    #         ok = False
    #         break
    # if ok: ans = min(ans, cost)
    if min(skill) >= x: ans = min(ans, cost)
# print(ans,inf)
if ans == inf: ans = -1
print(ans)


Measured memory_bytes: 9224
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;

typedef long double ld;
typedef pair<ll,ll> pp;
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> super_set;

#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
#define log sdfdsfdsf

const ll DIM = 1E6+7;
const ll MOD = 1e9+7;

const ll INF = 1E17;
const ld eps = 0.00000000000001;
const ld PI = 3.14159265358979323846;
int getInt(int a = 0, int b = INT_MAX){
    static mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution <int> (a, b)(rng);
}
pp A[DIM],res[DIM];
ld vp(ld x, ld y, ld x1, ld y1, ld x2, ld y2) {
    return (x1-x)*(y2-y) - (x2-x)*(y1-y);
}
ll F(ll a,ll b){
    return abs(res[a].fi-res[b].fi)+abs(res[a].sc-res[b].sc);
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    cin>>n;
    forn(i,n)cin>>A[i].fi>>A[i].sc;
    sort(A+1,A+1+n);
    ll all = 1;
    res[1] = A[1];
    forn(i,n){
        while(all>1 && vp(res[all-1].fi,res[all-1].sc,res[all].fi,res[all].sc,A[i].fi,A[i].sc)>=0){
            --all;
        }
        ++all;
        res[all] = A[i];
    }
    ll tmp = all;
    for(ll i = n-1;i>=1;--i){
        while(all>tmp && vp(res[all-1].fi,res[all-1].sc,res[all].fi,res[all].sc,A[i].fi,A[i].sc)>=0 ){
            --all;
        }
        ++all;
        res[all] = A[i];
    }
    --all;
    for(ll i = all+1;i<=all*2;++i)res[i] = res[i-all];
    ll ans = 0;
    forn(i,tmp){
        ll l = tmp+1,r = all;
        while(r-l>2){
            ll tl = (l*2+r)/3;
            ll tr = (r*2+l)/3;
            if (F(i,tl)>F(i,tr))r = tr;
            else l = tl;
        }
        ll tm = (l+r)/2;
        if (F(i,tm)>F(i,l)) l = tm;

        if (F(i,l)>F(i,r))r = l;
        else l = r;
        ans = max(ans,F(i,l));
    }
    ans = max(ans,F(1,tmp));
    ans = max(ans,F(tmp+1,all));
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 6764
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
using namespace std;

int Gcd(int x, int y);
int Lcm(int x, int y);

int main()
{
	int n;
	int a[10];
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	
	int lcm = a[0];
	for (int i = 1; i < n; i++)
	{
		lcm = Lcm(lcm, a[i]);
	}

	cout << lcm << endl;
	return 0;
}

int Gcd(int x, int y)
{
	if (x < y)
	{
		swap(x, y);
	}

	int rest;

	while (true)
	{
		rest = x % y;
		if (rest == 0)
		{
			return y;
		}
		else
		{
			x = y;
			y = rest;
		}
	}
}

int Lcm(int x, int y)
{
	return x * y / Gcd(x, y);
}

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

int main()
{

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	string sh;
	cin >> sh;
	int S = 0, R = 0;
	int ocuur = 0;
	for (int i = 0; i < 3; ++i)
	{
		if(sh[i] == 'S')
		{
			S++;
			ocuur = i;
		}
		else
		{
			R++;
		}
	}
	if(S == 3)
		cout << 0 << endl;
	else if(S == 2)
		cout << 1 << endl;
	else if(S == 0)
		cout << 3 << endl;
	else
	{
		if(ocuur == 1)
			cout << 1 << endl;
		else 
			cout << 2 << endl;
	}

	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define ok return 0;
#define MOAE                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);

int main()
{
    MOAE;
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int sum, temp;
    if (a >= k)
        sum = k;
    else
    {
        sum = a;
        temp = k - a;
        if (b < temp)
        {
            temp -= b;
            if (c < temp)
                sum -= c;
            else
                sum -= temp;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define reg register
using namespace std;
const int MAXN = 2e5 + 10;
int n;
int a[MAXN];
int main() {
    scanf("%d", &n);
    for(reg int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    sort(a + 1, a + n + 1);
    for(reg int i = 1; i <= n; ++i) {
        if(a[i] == a[i + 1]) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <iostream>

using namespace std;

int main()
{
	int A, B;

	cin >> A >> B;

	if (A > 9 || B > 9)
	{
		cout << "-1" << endl;
		return 0;
	}

	cout << A * B << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        if(n % 2 == 1){
        	System.out.println((double)(n/2+1)/n);
        }else{
        	System.out.println((double)(n/2)/n);
        }
	}        
}

Measured memory_bytes: 23764
/**
*@author: Ritchie Zhang
*@date:2020-4-26
**/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int a[100010];
int main()
{
	int S, W;
	cin >> S >> W;
	printf(S > W ? "safe" : "unsafe");
}


Measured memory_bytes: 3256
// https://atcoder.jp/contests/abc143/tasks/abc143_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, sum = 0;
    cin >> n;
    vector<int> v(n);
    REP(i, n) cin >> v[i];
    sort(ALL(v));
    REP(i, n) FOR(j, i + 1, n) {
        int less = lower_bound(ALL(v), v[i] + v[j]) - (v.begin() + j + 1);
        sum += less;
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char S[3],T[3];
  int c=0,i;
  scanf("%s",S);
  scanf("%s",T);
  
  for(i=0;i<3;i++){
    if(T[i]==S[i])c++;
  }
  printf("%d",c);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

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

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clzll(x) - 1;	}

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

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

	int ans = -1;

	max_self(ans, a + a - 1);
	max_self(ans, a + b);
	max_self(ans, b + b - 1);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
m=[0,abs(l[1]-l[0])]
if n==2:
    print(m[1])
else:
    p1=abs(l[2]-l[0])
    p2=m[1]+abs(l[2]-l[1])
    m.append(min(p1,p2))
    for i in range(3,n):
        p1=m[i-2]+abs(l[i]-l[i-2])
        p2=m[i-1]+abs(l[i]-l[i-1])
        m.append(min(p1,p2))
    print(abs(m[-1]))

Measured memory_bytes: 13928
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	const int n = s.size();
	int answer = 0;
	for(int i = 0; i + 1 < n; ++i){
		if(s[i] != s[i + 1]){ ++answer; }
	}
	cout << answer << endl;
	return 0;
}



Measured memory_bytes: 512
#include <iostream>

using namespace std;

int A[100];

int BubbleSort(int a[], int n) {
    int count = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = n - 1; j > i; --j) {
            if (a[j - 1] <= a[j]) continue;
            swap(a[j - 1], a[j]);
            count++;
        }
    }
    return count;
}

int main() {
    int n, count;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    count = BubbleSort(A, n);
    cout << A[0];
    for (int i = 1; i < n; ++i) cout << ' ' << A[i];
    cout << endl << count << endl;
    return 0;
}



Measured memory_bytes: 3096
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  let
    f :: [Int] -> (Maybe (Int, Int), Int)
    f = foldr step (Nothing, 0)
      where
        step :: Int -> (Maybe (Int, Int), Int) -> (Maybe (Int, Int), Int)
        step h (Nothing, m) = (Just (h, 0), m)
        step h (Just (h', l), m) | h' <= h   = (Just (h, l + 1), m)
                                 | otherwise = (Just (h, 0), l `max` m)
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  hs <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  print . (max <$> maybe 0 snd . fst <*> snd) . f $ hs

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 18896
n = int(input())
w = [input() for i in range(n)]
ans1=""
for i in range(n-1):
    if w[i][-1]!=w[i+1][0]:
        ans1="No"
if len(w)==len(set(w)):
    ans2="Yes"
else:
    ans2="No"
if ans1=="" and ans2=="Yes":
    ans="Yes"
else:
    ans="No"
print(ans)

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

B = sorted([(a - (n + 1)) for n, a in enumerate(A)])

M = -1
if N % 2 != 0:
    i = N // 2 
    M = B[i]
else:
    i1 = N // 2 - 1
    i2 = i1 + 1
    M = (B[i1] + B[i2]) // 2

AE = [abs(a - (M + (n + 1))) for n, a in enumerate(A)]
R = sum(AE)

print(R)


Measured memory_bytes: 27616
#include<stdio.h>

void insertionSort(int *A,int N);

int main(void){

  int n;
  int a[1000];
  int i;


  scanf("%d",&n);

  for(i=0;i<n;i++)
    scanf("%d",&a[i]);

   insertionSort(a,n);


   return 0;
}

void insertionSort(int *A,int N){

  int i,j,v,k;

   for(k=0;k<N-1;k++)
      printf("%d ",A[k]);
    printf("%d\n",A[N-1]);
    
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;

    while(j>=0 && A[j]>v){

      A[j+1]=A[j];
      j--;
      A[j+1]=v;
    }
    for(k=0;k<N-1;k++)
      printf("%d ",A[k]);
    printf("%d\n",A[N-1]);
  }
}



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

int main() {
	int a, b, c, d, e;
	while ( cin >> a >> b >> c >> d >> e ) {
		int t = 0;
		t += (a+9)/10;
		t += (b+9)/10;
		t += (c+9)/10;
		t += (d+9)/10;
		t += (e+9)/10;
		t *= 10;
		t += min( min( min( min( (a-1)%10, (b-1)%10 ), (c-1)%10 ), (d-1)%10 ), (e-1)%10 ) + 1;
		t -= 10;
		
		cout << t << '\n';
	}
	return 0;
}

Measured memory_bytes: 764
n = int(input())
p = []
for i in range(n):
    p.append([int(s) for s in input().split()])

dsum = 0.0
count = 0
for i in range(n):
    for j in range(i):
        d = ((p[i][0]-p[j][0])**2 + (p[i][1]-p[j][1])**2)**0.5
        dsum += d
        count += 1
print((n-1)*dsum/count)

Measured memory_bytes: 3064
a=int(input())

length=list(map(int,input().split()))
#print(length)
maximum=int(max(length))
goukei=int(sum(length))
#print(maximum)
#print(sum(length))
#print(goukei)

if 2*maximum<goukei:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
object Main extends App {
	override def main(args : Array[String]){
		val sc = new java.util.Scanner(System.in)
		val str1,str2 = io.StdIn.readLine
		val message = check(str1,str2) match {
			case true => "Yes"
			case false => "No"
		}
		println(message)
	}
	def check(s1 : String, s2 : String):Boolean = {
		s1.length >= s2.length &&
		(s1+s1).contains(s2)
	}
}

Measured memory_bytes: 44976
N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
  t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1] - t[l-1])


Measured memory_bytes: 9540
"use strict";

((stdin) => {
  let input = stdin.split("\n");
  // 10進数に変換
  let n = parseInt(input[0], 10);
  let a = input[1].split(" ");

  for (let i = 0; i < n; i++) {
    a[i] = parseInt(a[i], 10);
  }

  let ans = 0;
  let up = false;
  let down = false;
  for (let i = 0; i < n - 1; i++) {
    if (a[i] < a[i + 1]) {
      up = true;
    }
    if (a[i] > a[i + 1]) {
      down = true;
    }
    if (up && down) {
      up = down = false;
      ans++;
    }
  }

  console.log(ans + 1);
})(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 17612
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int n,a[200200];
ll k;
int vis[200200];
vi id;

int main()
{
    n=read();k=readll();
    rep(i,1,n) a[i]=read();
    id.pb(1);int now=1,c=0;
    memset(vis,-1,sizeof(vis));vis[now]=0;
    int bas,period;
    while (1)
    {
        //rep(i,1,n) cout << vis[i] << " ";cout << endl;
        now=a[now];
        if (vis[now]>-1) 
        {
            bas=vis[now];
            period=c+1-vis[now];
            break;
        }
        else 
        {
            vis[now]=(++c);
            id.pb(now);
        }
    }
    //cout << bas << " " << period << endl;
    int ans=0;
    if (k<bas) ans=id[k];
    else 
    {
        int tmp=(k-bas)%period+bas;
        ans=id[tmp];
    }
    printf("%d",ans);
    return 0;
}

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

int main() {
  int k,l;
  int p = 0;
  int i =0;
  int a[10000];
  while(1){
  cin >> k;
  l = k*(k-1)/2;
  if(k==0){break;}
  for(i=0;i<l;i++){
    cin >> a[i];
    p += a[i];
  }
  cout << p/(k-1)<<endl;
  p =0;
  }
    return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
int n,m,a[100007],b[100007];
vector < pair <int,int> > pos;
map <int,long long> bit;
const long long mod=1e9+7,lim=1e9+1;
bool cmp(pair<int,int> x, pair<int,int> y){
	return ((x.fi<y.fi) || (x.fi==y.fi && x.se>y.se));
}
void update(int pos,long long val){
	for(int i=pos;i<=lim;i+=i&(-i)){
		bit[i]=(bit[i]+val)%mod;
	}
}
long long get(int pos){
	long long ret=0;
	for(int i=pos;i>=1;i-=i&(-i)){
		ret=(ret+bit[i])%mod;
	}
	return ret;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=m;i++) cin>>b[i];
	int cnt=0;
	for(int i=1;i<=n;i++){
		while(cnt<m && b[cnt+1]<=a[i]){
			cnt++;
		}
		if(cnt>=1 && cnt<m && a[i]!=b[cnt] && a[i]!=b[cnt+1]){
			pos.pb(mp(a[i]-b[cnt],b[cnt+1]-a[i]));
		}
	}
	sort(pos.begin(),pos.end(),cmp);
	update(1,1);
	for(int i=0;i<(int)pos.size();i++){
		if(i==0 || pos[i]!=pos[i-1]){
			update(pos[i].se+1,get(pos[i].se));
		}
	}
	cout<<get(lim);
}


Measured memory_bytes: 72948
#include<bits/stdc++.h>
#define ll long long
#define cri const register int
#define re register
using namespace std;
vector<int>to[1010];
int n,m,a[200010],b[200010],fi[2][1010][1010];
int V[1010],v[1010],X,now,dfn[1010],low[1010],bl[1010],sta[1010],top,num,dcc;
void tj(cri x){
	sta[++top]=x;v[x]=1;
	dfn[x]=low[x]=++num;
	for(int y:to[x]) if(!dfn[y])
		tj(y),low[x]=min(low[x],low[y]);
	else if(v[y]) low[x]=min(low[x],dfn[y]);
	if(low[x]==dfn[x]){
		++dcc;
		while(sta[top]!=x) bl[sta[top]]=dcc,v[sta[top--]]=0;
		bl[sta[top]]=dcc;v[sta[top--]]=0;
	}
}
void dfs(cri x,cri opt,cri fr){
	if(V[x]==now) return;
	fi[opt][X][x]=fr;V[x]=now;
	for(int y:to[x]) dfs(y,opt,fr);
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++) 
		scanf("%d%d",&a[i],&b[i]),to[a[i]].push_back(b[i]);
	for(int i=1;i<=n;i++) if(!dfn[i]) tj(i);//cout<<1<<endl;
	for(int i=1;i<=n;i++){
		V[i]=++now;X=i;
		for(int j=0;j<to[i].size();j++) dfs(to[i][j],0,to[i][j]);
		V[i]=++now;
		for(int j=-1+to[i].size();~j;j--) dfs(to[i][j],1,to[i][j]);
	}
	for(int i=1;i<=m;i++){
		cri x=a[i],y=b[i];
		if(bl[x]!=bl[y]&&fi[0][x][y]!=fi[1][x][y]) puts("diff");
		else if(bl[x]==bl[y]&&fi[0][x][y]==y&&fi[1][x][y]==y) puts("diff");
		else puts("same");
	}
}

Measured memory_bytes: 14760
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
char s[200010];
int n,num=0;
LL ans=0;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=n;i>=1;i--)
	{
		if(s[i]=='B')
		{
			ans+=(n-i-num);
			num++;
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 384
use proconio::{input, marker::Chars};

fn main() {
    input! {
        x: Chars,
    }

    let mut count_s = 0;
    let mut count_t = 0;
    
    for c in x {
        match c {
            'S' => {
                count_s += 1;
            },
            'T' => {
                if count_s > 0 {
                    count_s -= 1;
                } else {
                    count_t += 1;
                }
            },
            _ => {},
        }
    }

    println!("{}", count_s + count_t);
}


Measured memory_bytes: 2952
alphabets = {}          #This is dict for reference by word's first character
alphabets_num = {}      #saves numbar of that
vartexs = []            #all vertices come out in a single operation
fail_check = {}         #for the check to avoid unnecessary search
 
class Vartex():
    def __init__(self, string):
        global alphabets
        self.ID = string
        self.link = []
        self.hasArrived = False
        return
 
    def register(self, new_vartex):
        self.link.append(new_vartex)
        return

def hasAllArrived(vartexs):
    for content in vartexs:
        if not content.hasArrived:
            return False
    return True
 
def dfs(start_vartex, vartex_list):
    global vartexs

    start_vartex.hasArrived = True

    for link_vartex in start_vartex.link:
        if link_vartex.hasArrived:
            if hasAllArrived(vartex_list):
                return True
            else :
                continue
        else:
            if dfs(link_vartex, vartex_list):
                return True
            else:
                continue
    start_vartex.hasArrived = False
    return False
 
 
while True:
#initalize for global variabale
    alphabets = {}
    alphabets_num = {}
    vartexs = []
    fail_check = {}

    for al in range(ord("a"), ord("z")+1):
        alphabets[chr(al)] = []
        alphabets_num[chr(al)] = 0
        fail_check[chr(al)] = 0
 
#bug appears for some reason without this processing
    s = raw_input()
    if s == '':
        continue
 
    n = int(s)
 
    if not n:
        break
 
    for x in range(n):
        word = raw_input()
        vartex = Vartex(word)
        vartexs.append(vartex)
        alphabets[word[0]].append(vartex)
        alphabets_num[word[0]] += 1
     
    for x in range(n):
        vartex = vartexs[x]
        string = vartex.ID
        fail_check[string[-1]] += 1
        for content in alphabets[string[-1]]:
            vartex.register(content)

#list of the first characters and the last characters must be consistent

    if alphabets_num != fail_check:
        print "NG"
        continue

#depth-first search
    start = vartexs[0]
    if dfs(start, vartexs):
        print "OK"
    else:
        print "NG"

Measured memory_bytes: 56932
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << 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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vector<ll>s,t;
int n,m;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>m;
    s.resize(n);
    t.resize(m);
    for (int i = 0; i <n; i++)
    {
        cin>>s[i];
    }
    rep(i,m)cin>>t[i];
    vector<vector<ll>>dp(n+1,vector<ll>(m+1,0));
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        dp[i][0]=1;
    }
    for(int j=1;j<=m;j++){
        dp[0][j]=1;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1]==t[j-1]){
                dp[i][j]=dp[i-1][j]+dp[i][j-1];//新しく作られるものは下のダブルカウントのぶんとちょうど同じ
            }
            else{
                dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];//ダブルカウントの分を引く
                dp[i][j]+=MOD;
            }
            dp[i][j]%=MOD;
        }
    }
    /*
    rep(i,n+1){
        debug(dp[i]);
    }*/
    cout << dp[n][m] << "\n";
}


Measured memory_bytes: 31616
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var NK = ReadLine().Split().Select(int.Parse).ToArray();
        var N = NK[0];
        var K = NK[1];
        if (N * (N - 1) / 2 - K < N - 1)
        {
            WriteLine("-1");
            return;
        }
        var u = new int[N * (N - 1) / 2];
        var v = new int[N * (N - 1) / 2];
        var a = 0;
        for (int i = 0; i < N; i++)
        {
            for (int j = i + 1; j < N; j++)
            {
                u[a] = i;
                v[a] = j;
                a++;
            }
        }
        var r = new List<int>[N];
        for (int i = 0; i < N; i++)
        {
            r[i] = new List<int>();
        }
        for (int i = 0; i < u.Length; i++)
        {
            r[u[i]].Add(v[i]);
        }
        var c = 0;
        for (int i = 0; i < K;)
        {
            if(r[c].Count>1)
            {
                r[c].RemoveAt(0);
                i ++;
            }
            else
            {
                c++;
            }
        }

        WriteLine(u.Length - K);
        for (int i = 0; i < r.Length; i++)
        {
            foreach (var k in r[i])
            {
                WriteLine($"{i+1} {k+1}");
            }
        }
    }
}


Measured memory_bytes: 13396
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int n;
	cin>>n;
	vi l(n);
	vi cnt(5010,0);
	FOR(i,0,n){
		cin>>l[i];
		cnt[l[i]]++;
	}
	LL ans=0;
	sort(l.begin(),l.end());
	FOR(i,0,n){
		FOR(j,i+1,n){
			int mn=max(abs(l[i]-l[j]),0);
			int mx=l[i]+l[j];
			int idx=lower_bound(l.begin(),l.end(),mn+1)-l.begin();
			ans+=max(0,i-1-idx+1);
			//cerr<<i<<" "<<j<<" "<<ans<<endl;
		}
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <iostream>
int main(int argc, char const *argv[]) {
  int A,B,C,D,E,K;
  std::cin >> A>>B>>C>>D>>E>>K;
  if (E-A<=K ) {std::cout << "Yay!" << '\n';
}else {std::cout << ":(" << '\n';}
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    // read in integer 
    string s;
    cin >> s;
    if (s[2]==s[3] && s[4]==s[5]) cout << "Yes"<< endl;
    else  cout << "No"<< endl;
}

Measured memory_bytes: 256
S = input()

def func(s):
    if s[0] == 'A':
        if s[2:-1].count('C') == 1:
            s_ = s[2:-1].replace('C', '')
            ss = s[1] + s_ + s[-1]
            return ss.islower()
        else:
            return False
    else:
        return False

if func(S):
    print('AC')
else:
    print('WA')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N >> K;
    int k = (N - 1) * (N - 2) / 2;
    if (K > k) {
        cout << -1 << endl;
    } else {
        cout << N - 1 + k - K << endl;
        REP(i, N - 1) {
            cout << 1 << " " << i + 2 << endl;
        }
        int cnt = k - K;
        REP(i, N - 1)
        FOR(j, i + 1, N - 1) {
            if (cnt-- == 0)
                return 0;
            cout << i + 2 << " " << j + 2 << endl;
        }
    }
}

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

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


Measured memory_bytes: 256
//JAG2017C クイズ　8/23 13:33~

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(void){
	while(1){
		int n, m; cin >> n >> m;
		if(!n && !m) break;

		vector<int> sum(n, 0);
		vector<int> only(n, 0);
		for(int i=0; i<m; i++){
			int s, k;
			cin >> s >> k;
			for(int j=0; j<k; j++){
				int c; cin >> c;
				c--;
				sum[c] += s;
				if(k == 1){
					only[c] += s;
				}
			}
		}

		int smin = 1000*1000;
		int smax = -1;
		int top_idx = -1;
		for(int i=0; i<n; i++){
			if(smax < sum[i]){
				smax = sum[i];
				top_idx = i;
			} else if (smax == sum[i]){
				if(only[i] > only[top_idx]){
					top_idx = i;
				}
			}
		}
		for(int i=0; i<n; i++){
			if(i == top_idx) continue;
			smin = min(smin, only[i]);
		}

		int ans = smax - smin + 1;
		cout << ans << endl;

	}
	return 0;
}


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


int main()
{
  ll n;
  int m;
  cin >> n >> m;
  map<int, ll, greater<int>> mp;
  rep(i, n)
  {
    int a;
    cin >> a;
    mp[a]++;
  }
  rep(i, m)
  {
    int b, c;
    cin >> b >> c;
    mp[c] += b;
  }
  ll ans = 0;
  for (auto i : mp)
  {
    ans += min(n, i.second) * i.first;
    n -= i.second;
    if (n <= 0)
      break;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 12800
#include <iostream>

using namespace std;

int log2_int(int x, int res){
  if (x % 2 == 1) {
    return(res);
  } else {
    return(log2_int(x / 2, ++res));
  }
}

int main(){
  int n;
  int ans = 0;
  cin >> n;
  for (int i=0;i<n;i++) {
    int a;
    cin >> a;
    ans += log2_int(a, 0);
  }
  cout << ans << endl;
  return(0);
}


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

n = int(input())
A = list(map(int,input().split()))

D = {}
for i in range(n):
    try:
        D[i-A[i]] += 1
    except:
        D[i-A[i]] = 1

# print(D)

ans = 0
for i in range(n):
    D[i-A[i]] -= 1
    # print(i+A[i])
    try:
        ans += D[i+A[i]]
    except:
        continue

print(ans)

Measured memory_bytes: 111232
#include <stdio.h>

int main()
{
  int H, W;
  scanf("%d %d", &H, &W);
  char a[H][W + 1];
  for(int i = 0; i < H; i++){
    scanf("%s", a[i]);
  }

  char b[H + 2][W + 2];
  for(int i = 0; i < H + 2; i++){
    for(int j = 0; j < W + 2; j++){
      b[i][j] = '#';
    }
  }
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      b[i + 1][j + 1] = a[i][j];
    }
  }
  for(int i = 0; i < H + 2; i++){
    for(int j = 0; j < W + 2; j++){
      printf("%c", b[i][j]);
    }
    printf("\n");
  }
  return 0;
}


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

int main() {
    char str;

    // 変数aで入力を受け取る
    cin >> str;

    if (str == 'a' || str == 'i' ||str == 'u' ||str == 'e' ||str == 'o'){
        cout << "vowel";
    }
    else{
        cout << "consonant";
    }


}


Measured memory_bytes: 256