akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    int ans[H][W];
    for(int i = 0; i < B; i++){
        for(int j = 0; j < A; j++){
            ans[i][j] = 0;
        }
        for(int j = A; j < W; j++){
            ans[i][j] = 1;
        }
    }
    for(int i = B; i < H; i++){
        for(int j = 0; j < A; j++){
            ans[i][j] = 1;
        }
        for(int j = A; j < W; j++){
            ans[i][j] = 0;
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cout << ans[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main(){
int a;
  cin>>a;
  int b[a],sum=0;
  for(int i=0;i<a;i++)cin>>b[i];
  for(int i=0;i<a-2;i++){
  for(int j=i+1;j<a-1;j++){
  for(int k=j+1;k<a;k++){
  if(b[i]+b[j]>b[k]&&b[i]+b[k]>b[j]&&b[k]+b[j]>b[i]&&b[i]!=b[j]&&b[j]!=b[k]&&b[k]!=b[i])sum++;
  
  }
    
    }
  }


cout<<sum;
return 0;}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define INF 10101010

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    int count=0;
    while(a>=b){
        
            b*=2;
            count++;
            if(count>k){
                No;
                return 0;
            }
        
    }while(b>=c){
        
            c*=2;
            count++;
            if(count>k){
                No;
                return 0;
            }
        
    }
    Yes;    
    
    
}

Measured memory_bytes: 3628
N=int(input())
a=list(map(int,input().split()))
dp=[[0]*(N+1) for i in range(N+1)]
#dp[a][b]でa:残っている数列の長さ b:左端
for w in range(1,N+1):
  for l in range(N-w+1):
    r=l+w
    dpl=-dp[l+1][r]+a[l]
    dpr=-dp[l][r-1]+a[r-1]
    dp[l][r]=max(dpl,dpr)
print(dp[0][N])

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int A[105];

int main()
{
    int N;
    cin >> N;
    REP(i, N)
    {
        cin >> A[i];
    }

    ll min = INF;
    for (int i = -100; i <= 100; ++i)
    {
        ll s = 0;
        REP(j, N)
        {
            s += pow(abs(i - A[j]), 2);
        }
        min = std::min(min, s);
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    char text [15];
    int i;
    gets(text);

    for (i=0;text[i]!='\0';i++)
    {
        if (i==3)
        {
            text[i]=text[i]+1;
        }
    }

    printf ("%s\n",text);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int a = sc.nextInt();
   String word = sc.next(); 
   int wordlong = sc.nextInt();
   String catchspell = word.substring(wordlong-1,wordlong);
   word = word.replaceAll(catchspell,"100");
   word = word.replaceAll("[a-z]","*");

   word = word.replaceAll("100",catchspell);   
   System.out.print(word);
 }
}

Measured memory_bytes: 22740
n,x = map(int, input().split())
l = list(map(int, input().split()))
c = 0
d = []
d.append(0)

for i in range(n):
    if (d[i] + l[i]) > x:
        break
    d.append( (d[i] + l[i]) )
    c = c + 1
print(c+1)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#define ll long long
#define inf 1<<30
#define il inline 
#define in1(a) readl(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il void readl(ll &x){
    x=0;ll f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
il void read(int &x){
    x=0;int f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    x*=f;
}
using namespace std;
/*===================Header Template=====================*/
#define N 100010
map<int,int>mp;
ll n,m,a[N],ans=0;
ll c[N];
int main(){
	in2(n,m);
	for(int i=1;i<=n;i++)in1(a[i]);
	for(int i=1;i<=n;i++)c[i]=c[i-1]+a[i],c[i]%=m,mp[c[i]]++;
	ll ans=mp[0];
	if(mp[0]>1)ans+=1ll*mp[0]*(mp[0]-1)/2;
	mp[0]=0;
	for(int i=1;i<=n;i++)
		if(mp[c[i]])
			ans+=1ll*mp[c[i]]*(mp[c[i]]-1)/2,mp[c[i]]=0; 
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4736
N, Q = map(int, input().split())
S = input()
S_con = [0 for i in range(len(S))]

def convert_N_AC():
    
    for i in range(1, len(S)):
        tmp = 0
        if (S[i - 1 : i + 1] == 'AC'):
            tmp = 1
        S_con[i] += tmp + S_con[i-1]

convert_N_AC()

for i in range(Q):
    l, r = map(int, input().split())
    answer = S_con[r - 1] - S_con[l - 1]
    print(answer)


Measured memory_bytes: 7772
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for(int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;

struct Pos {
  int x;
  int y;
  int depth;
};

vector<int> y_vec = {0, 0, -1, 1};
vector<int> x_vec = {-1, 1, 0, 0};
int main() {
  int H, W;
  cin >> H >> W;
  int s[H][W];
  int white = 0;
  REP(i, H) {
    string ss;
    cin >> ss;
    white += count(ALL(ss), '.');
    REP(j, W) s[i][j] = ss[j];
  }

  queue<Pos> q;
  vector<pair<int, int>> checked;

  q.push(Pos{0, 0, 1});
  while(!q.empty()) {
    auto cur = q.front();
    q.pop();
    if(count(ALL(checked), make_pair(cur.x, cur.y))) continue;
    checked.push_back({cur.x, cur.y});

    if(cur.x == H - 1 && cur.y == W - 1) {
      cout << white - cur.depth << endl;
      return 0;
    }

    REP(i, 4) {
      if(cur.y + y_vec[i] < 0 && cur.y + y_vec[i] >= H) continue;
      if(cur.x + x_vec[i] < 0 && cur.x + x_vec[i] >= W) continue;
      if(s[cur.x + x_vec[i]][cur.y + y_vec[i]] == '.') {
        q.push(Pos{cur.x + x_vec[i], cur.y + y_vec[i], cur.depth + 1});
      }
    }
  }
  cout << -1 << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,x=0,y=0;
    cin>>a>>b>>c>>d;
    while(1)
    {
        c=c-b;
        a=a-d;
        if(c<=0)
        {
            x=1;
            break;

        }
        if(a<=0)
        {
            y=1;
            break;
        }

    }
    if(x==1)
    {
        cout<<"Yes"<<endl;
    }
    if(y==1)
    {
        cout<<"No"<<endl;
    }




}


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

int main()
{
	string s;
	int count = 0;
	cin >> s;
	for (int i = 0; i < 3; i++) {
		if (s[i] == '1') {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math;

struct UFTree(T)
{
    struct Node
    {
        T parent;
        T rank = 1;
    }

    this(T n)
    {
        nodes.length = n;
        foreach (i, ref node; nodes) node = Node(i.to!T);
    }

    void unite(T a, T b)
    {
        a = root(a);
        b = root(b);

        if (a == b) return;

        if (nodes[a].rank < nodes[b].rank) {
            nodes[b].parent = nodes[a].parent;
        } else {
            nodes[a].parent = nodes[b].parent;
            if (nodes[a].rank == nodes[b].rank) nodes[a].rank += 1;
        }
    }

    bool is_same(T a, T b)
    {
        return root(a) == root(b);
    }

private:
    Node[] nodes;

    T root(T i)
    {
        if (nodes[i].parent == i) return i;

        return nodes[i].parent = root(nodes[i].parent);
    }
}

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];

    auto PS = readln.split.to!(int[]);

    auto uft = UFTree!int(N+1);
    foreach (_; 0..M) {
        auto xy = readln.split.to!(int[]);
        uft.unite(xy[0], xy[1]);
    }

    int res;
    foreach (int i, p; PS) {
        if (uft.is_same(i+1, p)) ++res;
    }

    writeln(res);
}

Measured memory_bytes: 4796
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *d = map(int, read().split())
d.sort()
p = [0, 24]
m = [0, 24]
for i, dd in enumerate(d):
    if i % 2 == 0:
        p.append(dd)
        m.append(24 - dd)
    else:
        p.append(24 - dd)
        m.append(dd)
pp, mm = float('inf'), float('inf')
p.sort()
m.sort()
for (bp, ap, bm, am) in zip(p, p[1:], m, m[1:]):
    pp = min(pp, ap - bp)
    mm = min(mm, am - bm)
print(max(pp, mm))


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<int> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N, K; cin >> N >> K;
  vector<int> D;
  REP(i, K) {
    int k; cin >> k;
    D.push_back(k);
  }
  bool flag = false;
  while(true) {
    string s = to_string(N);
    for(int i = 0; i < s.size(); ++i) {
      if(vector_finder(D, char_to_int(s[i])) == 1) {
        break;
      }
      if(i == s.size() - 1) {
        flag = true;
      }
    }
    if(flag == false) N++;
    else break;
  }
  cout << N << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;
const ll mod=1e9+7;

int main(){
    string s;
    cin >> s;
    ll w;
    cin >> w;
    ll n=s.length();
    string ans="";
    rep(i,n){
        if(i%w==0) ans+=s[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3536
#include<stdio.h>
#include<stdlib.h>
void printMatrix(int**,int);
int main(void)
{
  int i,j;//counter
  int v1,v2;//input(v2 adjacent to v1)
  int n;//the number of vertices
  int k;//the number of vertives adjacent to v1
  int **adjList;
  scanf("%d",&n);
  adjList=(int**)malloc(sizeof(int*)*n);
  for(i=0;i<n;i++)
    {
      adjList[i]=(int*)malloc(sizeof(int)*n);
      for(j=0;j<n;j++) adjList[i][j]=0;
    }
  for(i=0;i<n;i++)
    {
      scanf("%d",&v1);
      scanf("%d",&k);
      for(j=0;j<k;j++)
        {
          scanf("%d",&v2);
          adjList[v1-1][v2-1]++;
        }
    }
  printMatrix(adjList,n);
  return 0;
}
void printMatrix(int **mat,int n)
{
  int i,j;//counter
  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
        {
          if(j>0) printf(" ");
          printf("%d",mat[i][j]);
        }
      printf("\n");
    }
}


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


using namespace std;


void print(int a, int b, string &str)
{
	string tmp_str = "";

	for(int i = a; i <= b; i++)
		tmp_str += str[i];

	cout << tmp_str << endl;
}


void reverse(int a, int b, string &str)
{
	char tmp_c;
	int i, j;

	for(i = a, j = 0; i <= (a + b) / 2; i++, j++){
		tmp_c = str[b - j];
		str[b - j] = str[i];
		str[i] = tmp_c;
	}
}


void replace(int a, int b, string p, string &str)
{
	int i, j;

	for(i = a, j = 0; i <= b; i++, j++)
		str[i] = p[j];
}


int main()
{
	string str, com, p;
	int n, a, b;

	cin >> str;
	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> com >> a >> b;

		if(com == "print")
			print(a, b, str);
		else if(com == "reverse")
			reverse(a, b, str);
		else if(com == "replace"){
			cin >> p;
			replace(a, b, p, str);
		}
	}

	return 0;
}


Measured memory_bytes: 3224
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
using namespace std;
int main(void){
    
    long long int n,k;
    
    cin >> n;
    cin >> k;
 

 
    // cout << k << endl;
    if(k==1 || (n>k && n%k==0)){
        cout<<0<<endl;
        
    }else{
        if(n>k){
            n=n%k;    
        }
        // vector<long long int> v;
    
        // v.push_back(n);
        long long int i=0;
        while(i<1000000000000000){
            if(n<=abs(n-k)){
                break;
            }
            // v.push_back(abs(n-k));
            n=abs(n-k);
            i++;
        }
    
 
        // cout << *std::min_element(v.begin(), v.end());
        cout << n;
    }
    return 0;
}

Measured memory_bytes: 256
n, m, X, Y = map(int, input().split())
a_pos = list(map(int, input().split()))
b_pos = list(map(int, input().split()))

a_pos.sort()
b_pos.sort()

num = a_pos[-1] + 1

ansflg = 0
for z in range(X + 1, Y + 1):
  flg = 1
  for x in a_pos:
    if z <= x:
      flg = 0
      break
  if flg:
    for y in b_pos:
      if y < z:
        flg = 0
        break
  if flg:
    ansflg = 1
    break

if ansflg:
  print("No War")
else:
  print("War")

Measured memory_bytes: 3064
def divisors(N):
    res = []
    i = 1
    while i * i <= N:
        if N % i == 0:
            res.append(i)
            if i != N // i:
                res.append(N // i)
        i += 1
    res.sort()
    return res

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))


Measured memory_bytes: 3060
#include <stdio.h>

int main(){
    int h, w;
    int i,j;
    int min_i,min_j,m_h;
    long int taikaku,min;

    while(1){
        min = 0;
        

        scanf("%d %d",&h,&w);
        if(h == 0 && w == 0){
            break;
        }

        taikaku = h*h + w*w;
        min_i = h;
        min_j = 0;
        m_h = 150;

        min = 150*150 + 150*150;
        for(i = 1; i <= 150 ; i++){
            for(j = i + 1; j <= 150 ; j++){
                if(h == i && w == j)
                    break;
                
                       
                if( (i*i + j*j) > taikaku && min >= (i*i + j*j) ){
                    if(min == (i*i + j*j)){
                        if(i < min_i){
                         min_i = i;
                         min_j = j;
                        }
                        
                    }else{
                        min = i*i+j*j;
                        min_i = i;
                        min_j = j;

                 }
               }else if((i*i + j*j) == taikaku){
                   if(i > h && i <= m_h){
                    m_h = i;
                    min_i = i;
                    min_j = j;
                    min = i*i+j*j;
                   }
               }
               
            }
        }
        printf("%d %d\n",min_i,min_j);



    }
    return 0;

}


Measured memory_bytes: 2068
#include<iostream>
#include <stdio.h>
using namespace std;
  
int main(){
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	if(a<40){a=40;}
	if(b<40){b=40;}
	if(c<40){c=40;}
    if(d<40){d=40;}
	if(e<40){e=40;}
    cout<<(a+b+c+d+e)/5<<endl;

	return 0;}


Measured memory_bytes: 1160
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

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

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};


int main() {
	int n;
	cin >> n;
	int ans = 0;
	int a[2001];
	rep(i, 0, n)cin >> a[i];
	sort(a, a+n);
	for (int i = n - 1; i >= 0; i--) {
		for (int j = i - 1; j >= 0; j--) {
			ans += j-(lower_bound(a, a + j, a[i] - a[j] + 1) - a);
		}
	}
	cout << ans << endl;
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	if(S=="a") return _P("vowel\n");
	if(S=="i") return _P("vowel\n");
	if(S=="u") return _P("vowel\n");
	if(S=="e") return _P("vowel\n");
	if(S=="o") return _P("vowel\n");
	_P("consonant\n");
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char S[3];
  scanf("%s",&S);
  int i,counta=0,countb=0,countc=0;
  for(i=0;i<3;i++){
    if(S[i]=='a')counta++;
    if(S[i]=='b')countb++;
    if(S[i]=='c')countc++;
  }
  if(counta==1&&countb==1&countc==1)printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 128
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($A,$B,$C,$D) =  explode(" ",trim(fgets(STDIN)));
$d =  explode(" ",trim(fgets(STDIN)));
$res=0;
sort($d);
printf("%d\n",$d[$N/2]-$d[($N/2)-1]);


Measured memory_bytes: 12792
# coding:utf-8

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
# print(c)
black = 0
H = []
W = []
ans = 0

for bit_h in range(2**h):
    for bit_w in range(2**w):
        black = 0
        for i in range(h):
            if ((bit_h >> i) & 1) == 1:
                continue
            for j in range(w):
                if ((bit_w >> j) & 1) == 1:
                    continue
                if c[i][j] == '#':
                    black += 1
        if black == k:
            ans += 1
print(ans)


Measured memory_bytes: 9132
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int m=0;
    int c=0;
    vector<string> s(n);
    for(int i=0;i<n;i++){
        cin>>s.at(i);
    }
    
    sort(s.begin(),s.end());
    s.push_back(" ");
    for(int i=0;i<n;i++){
        if(s.at(i)!=s.at(i+1)){
            c++;
        }
    }cout<<c<<endl;
            
    }
 

Measured memory_bytes: 15664
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int N, ans = 0;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    for (int i = 0; i < N - 1; i++){
        if (A.at(i) == A.at(i + 1)){
            ans++;
            A.at(i + 1) = 10001;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
S = [0 for i in range(300000)]
S2 = []
A = [-1, 1]
for i in range(1, int(300000 / 7) + 1):
    d = 7 * i
    for a in A:
        da = d + a
        if da < 300000 and S[da] == 0:
            S2.append(da)
            for j in range(2, int(300000 / 2)):
                if da * j >= 300000:break
                S[da * j] = -1
while 1:
    n = int(input())
    if n == 1:break
    print(str(n) + ':',' '.join([str(x) for x in S2 if n % x == 0 and x <= n]))

Measured memory_bytes: 11024
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=200005;
int n,l[N],r[N],a[N],b[N],ans;
signed main(){
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)scanf("%lld",&a[i]);
	int tot=0;
	for (int i=1;i<=n;i++){
		while (tot&&a[i]<a[b[tot]])tot--;
		l[i]=b[tot];
		b[++tot]=i;
	}
	tot=1;b[1]=n+1;
	for (int i=n;i;i--){
		while (tot>1&&a[i]<a[b[tot]])tot--;
		r[i]=b[tot];
		b[++tot]=i;
	}
	//for (int i=1;i<=n;i++)printf("%lld %lld\n",l[i],r[i]);
	for (int i=1;i<=n;i++)ans+=(r[i]-i)*(i-l[i])*a[i];
	printf("%lld",ans);
} 

Measured memory_bytes: 6528
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


typedef pair <int, II> NODE;
typedef queue <NODE> QUEUE;

const int DSIZE = 12;
const int dr[DSIZE] = { 2, 2, 2, -2, -2, -2, 1, 0, -1, 1, 0, -1 };
const int dc[DSIZE] = { 1, 0, -1, 1, 0, -1, 2, 2, 2, -2, -2, -2 };
const string YES = "OK";
const string NO = "NA";

int sr, sc;
int n;
const int SIZE = 11;
int R[SIZE], C[SIZE];
bool V[10][10][11];

bool isValidPos( int r1, int c1, int r2, int c2 ) {
    for ( int i = -1; i < 2; ++ i ) {
        for ( int j = -1; j < 2; ++ j ) {
            int nr = r2 + i;
            int nc = c2 + j;
            if ( nr < 0 || nr >= 10 ) continue;
            if ( nc < 0 || nc >= 10 ) continue;
            if ( nr == r1 && nc == c1 ) return true;
        }
    }
    return false;
}

string solve() {
    fill( (bool*)V, (bool*)V + 10*10*10, false );
    QUEUE Q;
    Q.push( NODE( 0, II( sr, sc ) ) );
    V[sr][sc][0] = true;
    while ( ! Q.empty() ) {
        NODE node = Q.front();
        Q.pop();
        int step = node.first;
        int r = node.second.first;
        int c = node.second.second;

        if ( step == n && isValidPos( r, c, R[n - 1], C[n - 1] ) ) {
            return YES;
        }
        
        for ( int i = 0; i < DSIZE; ++ i ) {
            int nr = r + dr[i];
            int nc = c + dc[i];
            int nstep = step + 1;
            if ( nr < 0 || nr >= 10 ) continue;
            if ( nc < 0 || nc >= 10 ) continue;
            if ( ! isValidPos( nr, nc, R[step], C[step] ) ) continue;
            if ( V[nr][nc][nstep] ) continue;
            V[nr][nc][nstep] = true;
            NODE next( nstep, II( nr, nc ) );
            Q.push( next );
        }
    }
    return NO;
}

int main() {
    while ( cin >> sc >> sr ) {
        if ( sr == 0 && sc == 0 ) break;
        cin >> n;
        for ( int i = 0; i < n; ++ i ) {
            cin >> C[i] >> R[i];
        }
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n, p;
  cin >> n >> p;
  int a, cnt=0;
  for(int i=0;i<n;i++){
    cin >> a;
    cnt += a%2;
  }
  if(cnt == 0) cout << (p==0?(ll)pow(2,n):0) << endl;
  else cout << (ll)pow(2,n-1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <queue>
#include <map>

#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> a(100001, 0);
	rep1(i, N)
	{
		int tmp;
		cin >> tmp;
		a[tmp]++;
	}
	vector<int> b(100001, 0);
	rep1(i, 100001)
	{
		if (i < 100001)
			b[i] = a[i - 1] + a[i] + a[i + 1];
		else
			b[i] = a[i - 1] + a[i];
	}
	int ans = 0;
	rep1(i, 100001) ans = max(ans, b[i]);
	co(ans);
	return 0;
}

Measured memory_bytes: 1024
n, k = gets.split.map(&:to_i)
hs = n.times.map { gets.to_i }.sort!

ans = (10 ** 9) - 1
(n - k + 1).times do |i|
  diff = hs[i + k - 1] - hs[i]
  ans = diff if diff <= ans
end

puts ans


Measured memory_bytes: 4016
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n) cin >> a[i], a[i]--;

    ll idx = 0, now = 0;
    vector<ll> used(n, -1);
    while(used[now] == -1) {
        used[now] = idx;
        now = a[now];
        idx++;
    }

    ll start = used[now], period = idx - used[now];
    dump(start, period);

    vector<PII> v;
    REP(i, n) if(used[i] != -1) v.push_back({used[i], i});
    sort(ALL(v));
    
    vector<ll> v1, v2;
    REP(i, start) v1.push_back(v[i].second);
    FOR(i, start, v.size()) v2.push_back(v[i].second);
    dump(v1);
    dump(v2);

    if(k < start) {
        cout << v1[k]+1 << endl;
    } else {
        cout << v2[(k-start)%period]+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 13048
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys
# import numpy as np
# import itertools

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, *P = map(int, read().split())
print(sum(x<y<z or x>y>z for x,y,z in zip(P,P[1:],P[2:])))


Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,0},dy[]={0,1};

signed main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin>>N;
    ll A[210000],B[210000];
    priority_queue<P> que;
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=0;i<N;i++){
        cin>>B[i];
        if(A[i]>B[i]){
            cout<<-1<<endl;
            return 0;
        }else if(A[i]!=B[i]) que.push(P(B[i],i));
    }
    ll ans=0;
    int pre=-1;
    //cout<<1<<endl;
    while(!que.empty()){
        P t=que.top(); que.pop();
        int x=t.second;
        //cout<<t.first<<" "<<t.second<<endl;
        if(pre==x){
            cout<<-1<<endl;
            return 0;
        }
        pre=x;
        ll n=(B[x]-A[x])/(B[(x+1)%N]+B[(x-1+N)%N]);
        ans+=n;
        B[x]-=(B[(x+1)%N]+B[(x-1+N)%N])*n;
        if(B[x]!=A[x]){
            que.push(P(B[x],x));
        }
    }
    //cout<<2<<endl;
    cout<<ans<<endl;

}


Measured memory_bytes: 9456
//ABC121B
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int N,M,C;
    cin >> N >> M >> C;
    int B[20];
    for(int i = 0;i < M;i++){
        cin >> B[i];
    }
    int A[20][20];
    int sum[20];
    for(int i = 0;i < N;i ++){
        sum[i] = C;
        for(int j = 0;j < M;j++){
            cin >> A[i][j];
            sum[i] += A[i][j]*B[j];
        }

    }

    int count = 0;
    for(int k = 0;k < N;k++){
        if(sum[k] > 0) count ++;
    }
    cout << count <<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

ll mod;

ll powimod(ll x,ll n,ll mod){
    ll res=1;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

ll powi(ll x,ll n){
    ll res=1;
    while(n){
        if(n&1) res*=x;
        x*=x;
        n>>=1;
    }
    return res;
}

vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll a[n+1];
    memset(a,0,sizeof(a));
    for(ll i=1;i<=n;i++)
    {
    for(ll j=i;j<=n;j+=i)
    {
    a[j]++;
    }
    }
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
    ans+=i*a[i];
    }
    cout<<ans;
}


Measured memory_bytes: 81732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var N = NextInt();
            var A = NextInt();

            if((N % 500) <= A) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }

    class MyMath {
        static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 11220
def main():
    N = int(input())
    d = [list(map(int, input().split())) for _ in range(N-1)]
    for i in range(N-1):
        measure_time(d[i], d[i+1:])
    print(0)


def measure_time(start, remain):
    t = 0
    t = start[1] + start[0]
    for r in remain:
        if t < r[1]:
            t = r[1]
        elif (t - r[1]) % r[2] != 0:
            t += r[2] - (t - r[1]) % r[2]
        t += r[0]
    print(t)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74308
from collections import deque
s = input()
q = int(input())
que = deque([s])
flg=False
for _ in range(q):
    a = list(input().split())
    if a[0]=='1':
        flg=not(flg)
#        s=s[::-1]
    else:
        if flg ^ (a[1]!='1'):
            que.append(a[2])
        else:
            que.appendleft(a[2])

ans = ''.join(que)

if flg:
    ans = ans[::-1]
print(ans)


Measured memory_bytes: 6900
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 A, B;
  std::cin >> A >> B;
  std::cout << (A <= 5 ? 0 : A <= 12 ? B / 2 : B) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <deque>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#include <vector>

using namespace std;

#define int long long
struct Fast
{
  Fast()
  {
    std::cin.tie(0);
    std::cout.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;

#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

#define debug(x) cerr << #x << ": " << x << endl;

const int MOD = 1e9 + 7;

signed main(void)
{

  int W, H, x, y; cin >> W >> H >> x >> y;
  cout << W * H / 2. << " ";
  if (2 * x == W && 2 * y == H) cout << 1 << endl;
  else cout << 0 << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

bool possible(const int r,double t,map<int,int>& mp)
{
    rep(i,r){
        if(mp[i] < sqrt(r*r-i*i)+t-r){
            return false;
        }
    }
    for(int i=-r;i<0;i++){
        if(mp[i] < sqrt(r*r-(i+1)*(i+1))+t-r){
            return false;
        }
    }
    return true;
}

int main()
{
    while(1){
        int r,n;
        map<int,int> mp;
        cin >> r >> n;
        if(r == 0){
            break;
        }
        rep(i,n){
            int a,b,c;
            cin >> a >> b >> c;
            for(int j=a;j<b;j++){
                mp[j] = max(mp[j],c);
            }
        }
        double l = 0;
        double h = 21;
        while(1){
            double mid = (l+h) / 2.0;
            if(mid - l < EPS){
                printf("%.10f\n",l);
                break;
            }else{
                if(possible(r,mid,mp)){
                    l = mid;;
                }else{
                    h = mid;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3208
#include "iostream"
#include "string"
#include "vector"
#include "algorithm"
using namespace std;

int main()
{
	int n, l;
	cin >> n >> l;
	vector<string>s(n);
	for (int i = 0; i < n; i++)
		cin >> s[i];
	sort(s.begin(), s.end());
	for (int i = 1; i < n; i++)
		s[0] += s[i];
	cout << s[0] << endl;
    return 0;
}

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

using namespace std;

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

	int i = 0, j = s.length() - 1;
	int ans = 0;
	while (i < j) {
		if (s[i] == s[j]) {
			i++;
			j--;
		} else if (s[i] == 'x') {
			ans++;
			i++;
		} else if (s[j] == 'x') {
			ans++;
			j--;
		} else {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int mxn = 303;
bool vis[mxn][mxn];
long long  mat[mxn][mxn] , given[mxn][mxn];
int n;
void f()
{
    for(int k= 1; k <= n; k++)
    {
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                if(mat[i][j] > mat[i][k]+mat[k][j])
                {
                    mat[i][j] = mat[i][k] + mat[k][j];
                    vis[i][j] = true;
                }
                else if(mat[i][j] ==  mat[i][k]+mat[k][j] && k!=i && k!=j)
                {
                    vis[i][j] = true;
                }
            }
        }
    }
}
int main()
{
    cin>>n;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            cin>>given[i][j];
            mat[i][j] = given[i][j];
        }
    }
    memset(vis , false ,sizeof vis);
    f();
    bool flag = true;
    for(int i = 1 ; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            if(mat[i][j]!= given[i][j]) {flag = false ; break;}
        }
    }
    if(flag)
    {
        long long tot_cnt = 0;
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                if(!vis[i][j]) tot_cnt += given[i][j];
            }
        }
        cout<<tot_cnt/2<<endl;
    }
    else
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int a, b;
	cin >> a >> b;
	if (1 <= a && a <= 9 && 1 <= b && b <= 9)
		cout << a * b << endl;
	else
		cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<math.h>
typedef long long int ll;
int main()
{
    ll m,n,k,max,lcount,rcount,x;
    scanf("%lld %lld %lld",&n,&m,&k);
    ll stack1[n],stack2[m],prev=0;
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&x);
        stack1[i]=prev+x;
        prev=stack1[i];
    }
    prev=0;
    for(int i=0;i<m;i++)
    {
        scanf("%lld",&x);
        stack2[i]=prev+x;
        prev=stack2[i];
    }
    lcount=n,rcount=m;
    for(int i=0;i<n;i++)
    {
        if(stack1[i]>k)
        {
            lcount=i;
            break;
        }
    }
    for(int i=0;i<m;i++)
    {
        if(stack2[i]>k)
        {
            rcount=i;
            break;
        }
    }
    max=lcount>rcount?lcount:rcount;
    if(max==0)printf("0\n");
    else 
    {
        ll j=0;
        for(ll i=lcount-1;i>=0;i--)
        {
            for(;j<rcount;j++)
            {
                if(stack2[j]+stack1[i]>k)
                break;
            }
            max=i+j+1>max?i+j+1:max;
        }
        printf("%lld\n",max);
    }
}


Measured memory_bytes: 4832
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int maxn = 200005;
LL a[maxn], b[maxn];
int ans;
inline void work() {
    LL n, m, k;
    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for (int i = 1; i <= m; ++i) {
        cin >> b[i];
        b[i] += b[i - 1];
    }
    for (int i = 0, j = m; i <= n; ++i) {
        if (a[i] <= k) {
            while (a[i] + b[j] > k) --j;
            ans = max(ans, i + j);
        }
    }
    cout << ans << endl;
}

int main() {
    // freopen(".txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 6748
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (abs(b - a) <= d && abs(c - b) <= d) {
    cout << "Yes" << endl;
  } else if (abs(c - a) <= d) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3636
import java.util.*;
public class Main {
		
	public static void main(String[] args) {		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		
		int count = 0;
		for(int i=1;i<=N;i++) {
			String S = Integer.toString(i);
			// 111 -> "111"
			int length = S.length();
			// "111" -> 3
			if(length % 2 == 1)count++;
		}
		System.out.println(count);
	}
	
}

Measured memory_bytes: 27732
#include <vector>
#include <cstdio>
#include <iostream>
#include <tuple>
#include <stdexcept>
#include <map>
#include <set>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <deque>
#include <numeric>
#include <unordered_map>
#include <bitset>
#include <queue>

#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
#define mod LL(1e9 + 7)
#define mp make_pair
#define pb push_back

int n, m, v, u, a[888][888];
int was[777];
vector <int> g[2], s[2];

void go(int v, int f) {
    g[f].pb(v);
    was[v] = 1;
    for (int i = 1; i <= n; i++) {
        if (!a[v][i] && !was[i]) {
            go(i, f ^ 1);
        }
    }
}

int main() {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> v >> u;
        a[v][u] = a[u][v] = 1;
    }
    for (int i = 1; i <= n; i++)
        a[i][i] = 1;


    bitset<777> dp;
    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        if (!was[i]) {
            g[0].clear();
            g[1].clear();
            go(i, 0);
            dp = (dp << (g[0].size())) | (dp << (g[1].size()));
            if (g[0].size() < g[1].size()) swap(g[0], g[1]);
            if (s[0].size() < s[1].size()) swap(s[0], s[1]);
            for (int x: g[1])
                s[0].pb(x);
            for (int x: g[0])
                s[1].pb(x);
        }
    }



    for (int x: s[0])
        for (int y: s[0])
            if (!a[x][y]) {
                cout << -1;
                return 0;
            }

    for (int x: s[1])
        for (int y: s[1])
            if (!a[x][y]) {
                cout << -1;
                return 0;
            }
    int ans = 1e9;
    for (int x = 0;x <= n; x++) {
        if (dp[x])
            ans = min(ans, x * (x - 1) / 2 + (n - x) * (n - x - 1) / 2);
    }
    cout << ans;
}


Measured memory_bytes: 2688