akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		char[] a = sc.next().toCharArray();
		char[] b = sc.next().toCharArray();
		char[] c = sc.next().toCharArray();

		if (a[a.length - 1] == b[0] && b[b.length - 1] == c[0]) {
			pr.println("YES");
		} else {
			pr.println("NO");
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 24020
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> p;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);

int main() {

    ll N;
    cin >> N;

    vector<ll> A(N);
    ll cnt = 0, tmp;
    bool flag = false;
    
    rep(i, N) {
        cin >> tmp;

        if (tmp == 0) {
            flag = true;
        }
        if (tmp < 0) {
            cnt++;
        }
        A[i] = abs(tmp);
    }

    if (cnt % 2 == 0) {
        flag = true;
    }

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

    ll ans = 0;

    rep(i, N) {
        ans += A[i];
    }

    if (flag) {
        cout << ans;
    }
    else {
        cout << ans - A[0] * 2;
    }

    return 0;
}



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

Measured memory_bytes: 4048
S = input()
N = len(S)


# 0101…にする場合
cnt1 = sum([1 for i in range(N) if i%2==0 and S[i]=="0"])
cnt2 = sum([1 for i in range(N) if i%2!=0 and S[i]=="1"])
cnt_S01 = cnt1 + cnt2
# 1010…にする場合
cnt3 = sum([1 for i in range(N) if i%2==0 and S[i]=="1"])
cnt4 = sum([1 for i in range(N) if i%2!=0 and S[i]=="0"])
cnt_S10 = cnt3 + cnt4

ans = min(cnt_S01, cnt_S10)
print(ans)

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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//----------------------------------------------------------------

int main(void) {
  ll a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  ll ans1=0, ans2=0;
  rep(op1,40){
    rep(op2,40){
      rep(op3,40){
        rep(op4,40){
          ll water = 100*a*op1 + 100*b*op2;
          ll sugar = c*op3 + d*op4;
          if(water*e/100<sugar) continue;
          if(water+sugar==0) continue;
          if(water+sugar>f) continue;
          if(ans1==0 && ans2==0){
            ans1 = sugar+water;
            ans2 = sugar;
            continue;
          }
          ll old = ans2 * (water+sugar);
          ll tmp = sugar * ans1;
          if(old<tmp){
            ans1 = sugar+water;
            ans2 = sugar;
          }
        }
      }
    }
  }

  prt2(ans1, ans2);
}



Measured memory_bytes: 3604
#include<time.h>
#include<string.h>
#include<stdlib.h>
#include<stdio.h> 
int main()
{
	int a[10][20],i,n,t;
	char h;
	for(i=1;i<=7;i++)
		for(t=1;t<=17;t++)
			a[i][t]=0;
	scanf("%d",&n);

	for(i=1;i<=n;i++)
	{
		scanf(" %c %d",&h,&t);//C=1 D=2 H=3 S=4,S H C D
		if(h=='C')
			a[1][t]=1;
		if(h=='D')
			a[2][t]=1;
		if(h=='H')
			a[3][t]=1;
		if(h=='S')
			a[4][t]=1;
	}

	for(i=1;i<=13;i++)
	{
		if(a[4][i]==0)
			printf("S %d\n",i);
	}
	for(i=1;i<=13;i++)
	{
		if(a[3][i]==0)
			printf("H %d\n",i);
	}
	for(i=1;i<=13;i++)
	{
		if(a[1][i]==0)
			printf("C %d\n",i);
	}
	for(i=1;i<=13;i++)
	{
		if(a[2][i]==0)
			printf("D %d\n",i);
	}
	return 0;
}


Measured memory_bytes: 2048
#include<stdio.h>
#include<stdlib.h>

int main(){
    int r,c,i,j;
    int **E;

    scanf("%d %d",&r,&c);
    E=(int*)malloc(sizeof(int*)*(r+1));
    for(i=0;i<=r;i++)
        E[i]=(int*)malloc(sizeof(int)*(c+1));
    for(i=0;i<r+1;i++){
        for(j=0;j<c+1;j++)
            E[i][j]=0;
    }

    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&E[i][j]);
            E[i][c]+=E[i][j];
            E[r][j]+=E[i][j];
        }
    }


    for(i=0;i<r;i++){
        for(j=0;j<c;j++)
            E[r][c]+=E[i][j];
    }

    for(i=0;i<r+1;i++){
        for(j=0;j<c+1;j++){
            printf("%d",E[i][j]);
            if(j!=c)printf(" ");
        }
        if(i!=r)printf("\n");
    }
    printf("\n");
    free(E);
 return 0;
}

Measured memory_bytes: 644
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=9000000009;

signed main(){
  string s,t;
  cin>>s>>t;
  sort(ALL(s));
  sort(ALL(t));
  reverse(ALL(t));
  cout<<(s<t?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class BROTN {
public:
	void solve(std::istream& in, std::ostream& out) {
        string s;
        int n;
        in >> n >> s;
        string al="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        for(int i=0;i<(int)s.size();i++){
            for(int j=0;j<26;j++){
                if(s[i]==al[j]){
                    out << al[(j+n)%26];
                    break;
                }
            }
        }
        out << endl;
	}
};


int main() {
	BROTN solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

typedef long long ll;

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

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

const ll MIN_A = -10000;
const ll MAX_A = -10000;

ll solve(const ll n, const ll k, const vector<ll> as) {
    ll acc = 0;
    for (int i = 0; i < k; i++) {
        acc += as[i];
    }
    ll cand = MIN_A;

    for (int i = k; i < n; i++) {
        acc -= as[i - k];
        acc += as[i];
        chmax(cand, acc);
    }

    return cand;
}

int main(void) {
    ll n, k;
    while (1) {
        cin >> n >> k;
        if (n == 0 && k == 0) {
            break;
        }

        vector<ll> as(n);
        for (int i = 0; i < n; i++) {
            cin >> as[i];
        }
        cout << solve(n, k, as) << endl;
    }
    
    return 0;
}



Measured memory_bytes: 4364
n,m = map(int,input().split())
l = [0] * m
r = [0] * m
l_max = 1
r_min = n
for i in range(m):
    l[i], r[i] = map(int,input().split())
    l_max = max(l[i],l_max)
    r_min = min(r[i], r_min)
if r_min >= l_max:
    print(r_min - l_max + 1)
else:
    print(0)

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

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

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

void debug() {
  cerr << endl;
}

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

void print() {
  cout << endl;
}

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

int main() {
  GI2(H, W);
  vector<string> S(H);
  vector<int> yoko(H * W), tate(H * W);
  FOR(i, H) cin >> S[i];
  FOR(i, H) {
    int now_count = 0;
    FOR(j, W) {
      if (S[i][j] == '.') {
        now_count++;
      } else {
        for (int x = j - now_count; x < j; ++x) {
          yoko[i * W + x] = now_count;
        }
        now_count = 0;
      }
    }
    if (now_count > 0) {
      for (int x = W - now_count; x < W; ++x) {
        yoko[i * W + x] = now_count;
      }
    }
  }
  FOR(j, W) {
    int now_count = 0;
    FOR(i, H) {
      if (S[i][j] == '.') {
        now_count++;
      } else {
        for (int y = i - now_count; y < i; ++y) {
          tate[y * W + j] = now_count;
        }
        now_count = 0;
      }
    }
    if (now_count > 0) {
      for (int y = H - now_count; y < H; ++y) {
        tate[y * W + j] = now_count;
      }
    }
  }
  int ans = 0;
  FOR(i, H) {
    FOR(j, W) {
      ans = max(ans, yoko[i * W + j] + tate[i * W + j] -
                         (yoko[i * W + j] > 0 && tate[i * W + j] ? 1 : 0));
    }
  }
  print(ans);
  return 0;
}

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

int main() {
  int64_t h,w;
  cin >> h >> w;
  
  if(h == 1 || w == 1){
    cout << 1 << endl;
  }
  
  else{
    cout << (h*w+1)/2 << endl;
  }
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
 
using namespace std;

int main (){
    int n,a,b,c,d,count[10];
	cin >> n >> a >> b >> c >> d;
	string s;
	cin >> s;

	rep(i,0,10){
    	count[i] = 0;
	}

	rep(i,b-1,d){
		if(s[i-1]=='.' && s[i]=='.' && s[i+1]=='.'){
			count[0]++;
		}
	}

	rep(i,a-1,c){
		if(s[i]=='#' && s[i+1]=='#'){
			count[1]++;
		}
	}

	rep(i,b-1,d){
		if(s[i]=='#' && s[i+1]=='#'){
			count[1]++;
		}
	}

	if(d<c && count[0]==0){
		cout << "No" << endl;
	}
	else if(count[1]>0){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;



vector<pair<ll,ll>> t(0);

#define binary_search_vector t



bool isOK(ll index, ll key) {
    if (binary_search_vector[index].FI <= key) return true;
    else return false;
}

int binary_search(ll key) {
    int ok = -1; 
    int ng = (int) binary_search_vector.size(); 

    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    return ok;
}
map<ll,ll> m;
//
void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B){
    sort(all(t));
    ll ans=0;
    ll pre=1;
    ll now=0;
    m[0]=100001;
    repf(i,1,M+1){
        while(1){
            if(now>=t.size())break;
            if(t[now].FI<=i){
                m[t[now].SE]++;
                now++;
            }else break;
        }
        //if(now>=t.size())break;
        //cout<<i<<" "<<m.rbegin()->FI<<endl;
        ans+=m.rbegin()->FI;
        if(m.rbegin()->SE>1) m.rbegin()->SE--;
        else m.erase(m.rbegin()->FI);
        
    }
    op(ans)
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
   
    t.push_back(make_pair(0,0));
    
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
        t.push_back(make_pair(A[i],B[i]));
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 3956
#include <iostream>
#include <utility>
#include <stdint.h>
#include <string>

using namespace std;

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

  int ans = 0;
  for (int ii=0; ii<3; ++ii)
    ans  += S[ii] == T[ii];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition) cout << "Yes" << '\n'; else{ cout << "No" << '\n'; }
#define YES(condition) if(condition) cout << "YES" << '\n'; else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition) cout << "yes" << '\n'; else{ cout << "no" << '\n'; }



ll gcd(ll a, ll b){
    return b? gcd(b, a % b) : a;
}

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> b;
    for(ll i = 1; i <= sqrt(m); i++){
        if(m % i == 0){
            b.push_back(i);
            b.push_back(m / i);
        }
    }
    sort(b.begin(), b.end());
    ll ans = 1;
    for(ll i = 0; i < b.size(); i++){
        if(b[i] * n <= m){
            ans = b[i];
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    string s1,s2;
    s1="ABC";
    s2="ARC";
    if(s==s1)
    {
        cout<<s2<<endl;
    }
    else
        cout<<s1<<endl;
return 0;
}

Measured memory_bytes: 3556
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;

int main() {
  int n;
  int x;
  vector<int> v;
  cin >> n;
  for (int i=0; i<n; i++){
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());

  int ans = 0;
  int ans_m = 1000000000;
  for (int j=1; j<= *max_element(v.begin(), v.end()); j++) {
    ans = 0;
    for (int k=0; k<n; k++) {
      ans += pow((v[k] - j), 2);
    }
    if (ans < ans_m) {
      ans_m = ans;
    }
  }
  cout << ans_m << endl;
}


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

#define ll              long long
#define ull             unsigned long long

int main()
{
    //freopen("A.txt","r",stdin);
    //freopen("A.txt","w",stdout);
    ios_base::sync_with_stdio(0);

    int n,a;
    cin>>n>>a;
    int p=a*n;
   if(p%2==1)
        cout<<"Odd"<<endl;
    else
        cout<<"Even"<<endl;

}



Measured memory_bytes: 256
<?php

while (true) {
    fscanf(STDIN, "%d %d", $n, $x);
    if (0 == $n && 0 == $x) break;

    $count = 0;
    foreach (range(1, $n-2) as $a1) {
        foreach (range($a1+1, $n-1) as $a2) {
            foreach (range($a2+1, $n) as $a3) {
                if ($a1+$a2+$a3 == $x) {
                    $count += 1;
                }
            }
        }
    }

    echo "$count\n";
}

Measured memory_bytes: 6648
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

int hidiv(int x,int y){
    if(x%y==0){
        return x/y;
    }
    else{
        return x/y+1;
    }
}

signed main(){
    int D,G;
    int ans=1000;
    cin >>D>>G;
  	int copyG=G;
    vector<vector<int>>vec(D,vector<int>(2));
    REP(i,D){
        cin>>vec[i][0]>>vec[i][1];
    }
    for(int tmp=0;tmp<(1<<D);tmp++){
        G=copyG;
      	int ifans=0;
        bitset<10>s(tmp);
        REP(i,D){
            if(s.test(i)){
                G-=vec[i][0]*(i+1)*100+vec[i][1];
                ifans+=vec[i][0];
            }
        }
        int MAX=-1;
        REP(i,D){
            if(!s.test(i)){
                MAX=i;
            }
        }
        if(G>0&&MAX!=-1){
            int d=hidiv(G,(MAX+1)*100);
          	if(d<=vec[MAX][0]){
              ifans+=d;
              G-=d*100*(MAX+1);
            }
        }
        if(G<=0){
            ans =min(ans,ifans);
        }
    }
    cout <<ans<<endl;
}

Measured memory_bytes: 256
import static java.lang.Math.abs;
import static java.lang.Math.atan2;
import static java.lang.Math.sqrt;
import static java.util.Arrays.deepToString;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		
		int[] ms = {
			1, 2, 1, 2, 1, 4, 1, 4,
			1, 2, 1, 2, 1, 4, 1, 4,
		};

		for (;sc.hasNext();) {
			int[] a = new int[8];
			for (int i = 0; i < 8; i++) a[i] = sc.nextInt();
			
			int best = -1;
			int best_pos = 0;
			for (int p = 0; p < 8; p++) {
				int here = 0;
				for (int i = 0; i < 8; i++) {
					int r = Math.min(a[i], ms[i + p]);
					here += r;
				}
				if (best < here) {
					best = here;
					best_pos = p;
				} else if (best == here && lt(p, best_pos, ms)) {
					best = here;
					best_pos = p;
				}
			}
			
			System.out.print(ms[best_pos]);
			for (int i = 1; i < 8; i++) {
				System.out.print(" " + ms[i+best_pos]);
			}
			System.out.println();
		}
	}
	boolean lt(int p, int best_pos, int[] ms) {
		for (int i = 0; i < 8; i++) {
			if (ms[i + p] < ms[i + best_pos]) return true;
			if (ms[i + p] > ms[i + best_pos]) return false;
		}
		return false;
	}
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes";
    else
        cout << "No";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<bitset>
#include<tuple>
#include<time.h>
#include<list>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

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

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



int h, n, a[101010];

void solve(){
	cin >> h >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		h -= a[i];
	}
	if(h <= 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (ll)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

ll digsum(ll n){
    ll sum = 0;
    while(n > 0){
        sum += n % 10;
        n /= 10;
    }

    return sum;
}

int main()
{
    ll n;
    cin >> n;

    vll a(n), b(n), c(n-1);
    rep(i,n)cin >> a[i];
    rep(i,n)cin >> b[i];
    rep(i,n-1)cin >> c[i];

    ll ans = 0;
    rep(i,n){
        ans += b[a[i] - 1];

        if(i < n-1 && a[i] + 1 == a[i+1])ans += c[a[i]-1];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import deque


def bellman_ford(start: int, goal: int, graph: list) -> list:
    '''bellman-ford法: 始点startから終点goalへの最小コストを求める
    重み付きグラフgraphは隣接リストで与えられ、辺のコストは負でも良い
    次の3種類のパターンが存在する
        1. 始点startから終点goalにたどり着くことが不可能である
           -> float("inf")を返す

        2. 始点startから終点goalにたどり着くことが可能であり、
           パス上に負閉路が存在する
           -> -float("inf")を返す

        3. 始点startから終点goalにたどり着くことが可能であり、
           パス上に負閉路が存在しない
           -> 最小コストを返す

    計算量: O(|E||V|)
    '''
    INF = float("inf")
    n = len(graph)

    # スタートから到達可能な地点を調べる
    is_reachable = [False] * n
    is_reachable[start] = True
    q = deque([start])
    while q:
        pos = q.popleft()
        for next_pos, _ in graph[pos]:
            if is_reachable[next_pos]:
                continue
            is_reachable[next_pos] = True
            q.append(next_pos)

    # 逆辺で構築したグラフで、ゴールから到着可能な地点を調べる
    reverse_graph = [[] for i in range(n)]
    for pos, edge in enumerate(graph):
        for next_pos, cost in edge:
            reverse_graph[next_pos].append((pos, cost))

    is_rev_reachable = [False] * n
    is_rev_reachable[goal] = True
    q = deque([goal])
    while q:
        pos = q.popleft()
        for next_pos, _ in reverse_graph[pos]:
            if is_rev_reachable[next_pos]:
                continue
            is_rev_reachable[next_pos] = True
            q.append(next_pos)            

    is_on_the_path_from_start_to_goal = [False] * n
    for i in range(n):
        is_on_the_path_from_start_to_goal[i] = is_reachable[i] and is_rev_reachable[i]

    distance = [INF] * n
    distance[start] = 0
    for _ in range(n):
        is_updated = False
        for pos, edge in enumerate(graph):
            for next_pos, cost in edge:
                if not is_on_the_path_from_start_to_goal[next_pos]:
                    continue
                if distance[pos] != INF and distance[pos] + cost < distance[next_pos]:
                    distance[next_pos] = distance[pos] + cost
                    is_updated = True
        if not is_updated:
            return distance[goal]
    # 負閉路が存在する
    return -INF


n, m, p = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]

graph = [[] for i in range(n)]
for i in range(m):
    a, b, c = info[i]
    graph[a - 1].append((b - 1, -(c - p)))
ans = bellman_ford(0, n-1, graph)

if ans == -float("inf"):
    print(-1)
else:
    print(max(-ans, 0))

Measured memory_bytes: 54360
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve()
{
    int x;
    cin>>x;
    if(x==0){
        cout<<"1"<<endl;return;
    }
    cout<<"0"<<endl;return;
}
int main()
{
    solve();
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const long long MOD=1000000007;

int main(){
    long long N;
    cin >> N;
    long long ju=1,hachi=1, kyu=1;
    long long i;
    for(i=0; i<N; i++){
        ju*=10;
        ju%=MOD;
        kyu*=9;
        kyu%=MOD;
        hachi*=8;
        hachi%=MOD;
    }
    long long ans=0;
    ans+=ju;
    ans+=(MOD-kyu);
    ans%=MOD;
    ans+=(MOD-kyu);
    ans%=MOD;
    ans+=hachi;
    ans%=MOD;
    cout << ans << endl;
    system("pause");
    return 0;
}

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

const int MAXV = 99999;

bool check_num(int i, set<int> D) {
    string str = to_string(i);
    for (auto ch : str) {
        if (D.find(ch - '0') != D.end()) return false;
    }
    return true;
}

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

    int N, K;
    cin >> N >> K;
    set<int> D;
    for (int i = 0; i < K; i++) {
        int d;
        cin >> d;
        D.insert(d);
    }
    for (int i = N; i < MAXV; i++) {
        if (check_num(i, D)) {
            cout << i << endl;
            break;
        }
    }


    return 0;
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn main() {
    let (k, a, b) = i::u3();
    for i in a..(b + 1) {
        if i % k == 0 {
            println!("{}", "OK");
            return;
        }
    }
    println!("{}", "NG");
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 2160
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  
  int k = 26;
  
  string s = "";
  
  int i = 0;
  while(n){
    n--;
    s  += (char)('a' + n % 26);
    n /= 26;
    
  }
  
  reverse(s.begin(), s.end());
  
  cout << s << endl;
    
  

}

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

int main()
{
	string S, answer1,answer2;
	int i;
	cin >> S;
	size_t size = S.length();
	for (i = 0; i < size; i = i + 2) {
		if (S[i] == 'L') {
			answer1 = "No";
			i = i + 100;
		}
		else {
			answer1 = "Yes";
		}
	}
	for (i = 1; i < size; i = i + 2){
	if (S[i] == 'R') {
		answer2 = "No";
		i = i + 100;
	}
	else {
		answer2 = "Yes";
	}
	}
	if (answer1 == "No" || answer2 == "No") {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG    //空コンテナ操作禁止　Clang環境では#define _LIBCPP_DEBUG 0
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
  string S;
  cin >> S;
  int N = S.size();
  vector<int> RtoL(N,0), LtoR(N,0);

  int repeat = 0;
  for( int i=1, repeat=1; i<N; i++ ){
    if( S.at(i-1) == 'R' ){
      if( S.at(i) == 'R' ){
        repeat++;
      }else{
        RtoL.at(i) = repeat / 2;
        RtoL.at(i-1) = ( repeat + 1 )/2;
        repeat = 0;
      }
    }else{
      if( S.at(i) == 'R' ){
        repeat++;
      }else{
        repeat = 0;
      }
    }
  }
  for( int j=1, repeat=1; j<N; j++ ){
    if( S.at(N-j) == 'L' ){
      if( S.at(N-j-1) == 'L' ){
        repeat++;
      }else{
        LtoR.at(N-j-1) = repeat / 2;
        LtoR.at(N-j) = ( repeat + 1 )/2;
        repeat = 0;
      }
    }else{
      if( S.at(N-j-1) == 'L' ){
        repeat++;
      }else{
        repeat = 0;
      }
    }
  }
  
  for( int i=0; i<N; i++ ){
    printf( "%d ", RtoL.at(i) + LtoR.at(i) );
  }
  return 0;
}


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

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

    int N;
    string S;
    cin>>N>>S;
    vector<int> R, G, B;
    for(int i = 0; i < N; i++)
    {
        if(S[i] == 'R')
            R.push_back(i);
        else if(S[i] == 'G')
            G.push_back(i);
        else if(S[i] == 'B')
            B.push_back(i);
    }
    long long int total = R.size() * G.size() * B.size();
    for(int dis = 1; dis <= N; dis++){
        for(int i = 0; i < N && (i+2*dis) < N; i++)
        {
            if(S[i] != S[i+dis] && S[i] != S[i+2*dis] && S[i + dis] != S[i+2*dis]){
                total--;
            }
            // cout<<i<<" "<<dis<<endl;
        }
    }
    cout<<total<<endl;
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<pair<int, int>> AB(N);
	for (pair<int, int>& i : AB) cin >> i.first >> i.second;
	sort(AB.begin(), AB.end());
	cout << AB.back().first + AB.back().second;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e5;
int main(){
  int N; scanf("%d", &N);
  vector<vector<int>> to(N,vector<int>(N,0));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      char c; cin >> c; int d = c-'0'; 
      if( d == 0 ){ d = INF;} 
      if( i == j ){ d = 0;}
      to[i][j] = d;}}
  
  vector<int> color(N,0); //0が未到達、1が白、２が黒
  
  queue<int> Q; Q.push(0); color[0] = 1;
  bool flag = true;
  while(!Q.empty()){
    int p = Q.front(); Q.pop();
    for(int i = 0; i < N; i++){ 
      if( to[p][i] == 1 ){ //隣接しているところに進む
        if( color[i] == 0){ 
          if(color[p] == 1){ color[i] = 2;}
          else{ color[i] = 1;}
          
          Q.push(i);
        }
        else{
          if( color[i] == color[p]){ //二部じゃない
            flag = false; break;}
        }
      }
    }
      if(!flag){ break;}
  }
    
  if(!flag){ printf("%d", -1); return 0;}
  
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        to[i][j] = min(to[i][j], to[i][k]+to[k][j]);
      }
    }
  }
  
  int ans = 0;
  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      ans = max(ans, to[i][j]);
    }
  }
  
  printf("%d\n", ans+1); return 0;
}
  
  

Measured memory_bytes: 384
#include <stdio.h>
int main(){
  int a, b, c, k;
  scanf("%d %d %d %d", &a, &b, &c, &k);
  if (k <= a) printf("%d\n", k);
  else if (a < k && k <= a+b) printf("%d\n", a);
  else if (a+b < k) printf("%d\n", 2*a+b-k);
  return 0;
}

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

int a[26];

int main(){
	ios_base::sync_with_stdio(0);
	string s;
	cin>>s;
	int c=0,d;
	for (int i = 0; i < s.size(); ++i)
	{
		a[(int)(s[i]-'a')]++;
		if(s[i]!='x') c++;
	}
	int ans=0;
	for (int i = 0; i < 26; ++i)
	{
		if(i!=23 and a[i]%2==1) ans++;
	}
	int id;
	if(ans>1) {
		cout<<-1<<endl;
		return 0;
	}
	int i=0,j=s.size()-1;
	d=0;
	ans=0;
	while(1){
		// cout<<"dfs "<<i<<" "<<j<<endl;
		if(s[i]==s[j]){
			if(s[i]!='x') d++;
			i++;
			j--;

		}
		else if(s[i]!=s[j] and (s[i]!='x') and (s[j]!='x')){
			cout<<-1<<endl;
			return 0;
		}
		else if(s[i]!=s[j]){
			// cout<<i<<" "<<j<<endl;
			if(s[i]=='x') i++;
			else j--;
			ans++;
		}
		if(d==(c+1)/2) break;
	}
	cout<<ans<<endl;
	return 0;	
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void){
	int a,b,c,n;
	n=0;
	scanf("%d %d %d",&a,&b,&c);
	for(;a<=b;a++){
		if(c%a == 0)
			n++;
	}

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

Measured memory_bytes: 596
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var a = int.Parse(line[1]);
        var b = int.Parse(line[2]);
        var res = Math.Abs(a - b);
        Console.WriteLine(res % 2 == 0 ? "Alice" : "Borys");
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string.h>
#include "math.h"
using namespace std;
int main(void){

    double A,B,H,M;
    double result=0;
    cin>>A>>B>>H>>M;
    double angle_a;
    double angle_b;
    if(H!=0){
    angle_a=(360/12*H)+(30*M/60);
    }
    else{
        angle_a=(30*M/60);
    }
    if(M!=0){
    angle_b=360/60*M;
    }
    else{
        angle_b=0;
    }
    double angle=0;
    if(angle_a-angle_b>=180){
        if(angle_b-angle_a>=0){
        angle=angle_b-angle_a;
        }
        else{
            angle=(angle_b-angle_a)*(-1);
    }
    }
    else{
        if(angle_a-angle_b>=0){
            angle=angle_a-angle_b;
        }
        else{
            angle=(angle_a-angle_b)*(-1);
        }
    }
   

    result=sqrt(A*A+B*B-2*A*B*cos(angle/180*3.1415926535));
    
    printf("%.16f", result);
}

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

int main(){
  int K,A,B;
  cin >> K >> A >> B;
  for (int i=A; i<=B; i++){
    if (i%K==0) {cout << "OK" << endl; return 0;}
  }

  cout << "NG" << endl;
  
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  switch (n) {
    case 1:
             cout << "Hello World" << endl;
               break;
    case 2:
               int a,b;
               cin >> a;
               cin >> b;
               cout << a+b << endl;
  }
  return 0;
}

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

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


Measured memory_bytes: 256
# AOJ 1138: Traveling by Stagecoach
# Python3 2018.7.15 bal4u

INF = 0x7fffffff
import heapq
def dijkstra(V, start, goal, to, ti):
	n = len(ti)
	node = [[INF for j in range(1<<n)] for i in range(V)]
	Q = []
	heapq.heappush(Q, (0, start, 0))
	while Q:
		t, s, c = heapq.heappop(Q)
		for i in range(n):
			if c & (1<<i): continue
			nc = c|(1<<i)
			for e, cost in to[s]:
				nt = t + cost/ti[i]
				if node[e][nc] > nt:
					node[e][nc] = nt
					heapq.heappush(Q, (nt, e, nc))
	return node[goal]
	
while True:
	N, M, P, A, B = map(int, input().split())
	if N == 0: break
	A -= 1; B -= 1
	ti = list(map(int, input().split()))
	to = [[] for i in range(M)]
	for i in range(P):
		x, y, z = map(int, input().split())
		x -= 1; y -= 1
		to[x].append((y, z))
		to[y].append((x, z))
	node = dijkstra(M, A, B, to, ti)
	ans = INF
	for i in range(1<<N): ans = min(ans, node[i])
	print(ans if ans < INF else "Impossible")



Measured memory_bytes: 11244
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};  // num[i] : i(iは1-index)を作るのに必要なマッチの本数

int main() {
    ll n, m;
    cin >> n >> m;

    vl a(m);
    rep(i, m) {
        cin >> a[i];
    }
    sort(rall(a));

    vl dp(n+1, -INF);  // dp[i] : i本(iは1-index)のマッチ棒全て使って作れる桁数の最大値
    dp[0] = 0;
    rep(i, n+1) {
        rep(j, m) {
            if(i >= num[a[j]]) {
                chmax(dp[i], dp[i - num[a[j]]] + 1);
            }
        }
    }

    ll nokori = n;
    while(nokori > 0) {
        rep(j, m) {
            if(nokori >= num[a[j]] && dp[nokori] == dp[nokori - num[a[j]]] + 1) {
                cout << a[j];
                nokori -= num[a[j]];
                break;
            }
        }
    }
    
    cout << endl;
    re0;
}

Measured memory_bytes: 384
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))


diff = []
npA = np.array(A)
lenA = len(A)
for a in A:
    temp = list(np.array([a for i in range(lenA)]) - npA)
    diff.append(temp)

D = np.array(diff)

upD = np.triu(D,k=1)

upC = np.count_nonzero(upD>0)
dwC = np.count_nonzero(upD<0)

ans = (K*(K+1)//2)*upC + ((K-1)*K//2)*dwC
print(ans%(1000000007))

Measured memory_bytes: 266504
# 解説 AC

# 参考1: https://twitter.com/rickytheta/status/1175412019006074880
# 参考2: https://maspypy.com/atcoder-%E5%8F%82%E5%8A%A0%E6%84%9F%E6%83%B3-2019-09-21agc-038

mod = 998244353
max_A = 10**6
N = int(input())
A = list(map(int, input().split()))

# nまでの自然数が素数かどうかを表すリストを返す  O(nloglogn)
def make_prime_checker(n):
    is_prime = [False, True, False, False, False, True] * (n//6+1)
    del is_prime[n+1:]
    is_prime[1:4] = False, True, True
    for i in range(5, int(n**0.5)+1):
        if is_prime[i]:
            is_prime[i*i::i] = [False] * (n//i-i+1)
    return is_prime

primes = [p for p, is_prime in enumerate(make_prime_checker(max_A)) if is_prime]  # max_A 以下の素数のリスト

g = [0] * (max_A+1)
for a in A:
    g[a] += a
for p in primes:
    # 倍数集合の高速ゼータ変換みたいなやつ  O((max_A)loglog(max_A))
    # 参考: http://noshi91.hatenablog.com/entry/2018/12/27/121649
    # 大量に約数列挙みたいなことをするときはこれで高速化できる場合が多そう？（みんぷろ 2018 本戦 A - Uncommon など）
    for k in range(max_A//p, 0, -1):
        g[k] = (g[k] + g[k*p]) % mod

# この時点で g[d] = Σ_{d|a} a  (A の要素のうち d の倍数であるものの総和)

g = [v * v % mod for v in g]

# この時点で
# g[d] = (Σ_{d|a} a)(Σ_{d|b} b)
#      = Σ_{(d|a)∧(d|b)} ab
#      = Σ_{d | gcd(a,b)} ab

# この式変形天才すぎないか？（これを使った一連の操作を gcd 畳み込み というらしい？）

for p in primes:
    # 倍数集合の高速メビウス変換みたいなやつ  O((max_A)loglog(max_A))

    # for k in range(1, max_A//p+1):
    #     g[k] -= g[k*p]  # 包除原理ヤバい

    for k, g_kp in enumerate(g[p::p], 1):  # 高速化（ゼータ変換の方は途中で g が変化するので高速化できない）
        g[k] = (g[k] - g_kp) % mod  # 包除原理ヤバい

# この時点で g[d] = Σ_{gcd(a,b)=d} ab

def make_modinv_list(n, mod=10**9+7):
    # 0 から n までの mod 逆元のリストを返す O(n)
    modinv = [0, 1]
    for i in range(2, n+1):
        modinv.append(mod - mod//i * modinv[mod%i] % mod)
    return modinv

modinv_list = make_modinv_list(max_A, mod)
ans = sum((gg % mod * minv % mod for gg, minv in zip(g, modinv_list)))
ans %= mod

# この時点で
# ans = Σ_d ( Σ_{gcd(a,b)=d} ab/d )
#     = Σ_d ( Σ_{gcd(a,b)=d} lcm(a,b) )
#     = Σ_a Σ_b lcm(a,b)

ans -= sum(A)
ans *= modinv_list[2]
ans %= mod

# この時点で ans = Σ_{i<j} lcm(a,b)

print(ans)


Measured memory_bytes: 149640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
using namespace std;
const constexpr int INF = 1e9;
typedef pair<int, int> P;

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

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9 + 7;
const int BITSIZE = 100010;

struct Less {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.second < y.second;
	}
};
struct More {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.first > y.first;
	}
};
//1-indexed
int bit[100010];
int bit_query(int i) {
	int res = 0;
	for (; i >= 1; i -= i & -i) res = max(res, bit[i]);
	return res;
}

void bit_set(int x, int v) {
	for (; x <= BITSIZE; x += x & -x) {
		bit[x] = max(bit[x], v);
	}
}

bool sieve[55556];
int main() {
	int N; cin >> N;
	REP(i, 55556) sieve[i] = true;
	sieve[0] = sieve[1] = false;
	for (int i = 2; i*i < 55556; ++i) {
		if (sieve[i]) {
			for (int j = 2; i*j < 55556; ++j) sieve[i*j] = false;
		}
	}

	vector<int> p;
	for (int i = 0; i < 55556; ++i) if (sieve[i] && i % 5 == 1) p.push_back(i);
	
	for (int i = 0; i < N; ++i) {
		if (i) cout << " ";
		cout << p[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
using namespace std;

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

	if (U == S)cout << A - 1 << " " << B << endl;
	else cout << A << " " << B - 1<< endl;

	return 0;
}


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

int main(){
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        if(i%2){
            if(s[i] == 'R'){
                cout << "No";
                return 0;
            }
        }else{
            if(s[i] == 'L'){
                cout << "No";
                return 0;
            }
        }
    }
    cout << "Yes";
    return 0;
}


Measured memory_bytes: 256
import sys
import bisect
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
ans = 10 ** 9
for t in range(1, n + 1):
    ans = min(ans, abs(sum(w[:(t + 1)]) - sum(w[(t + 1):])))
print(ans)

Measured memory_bytes: 3188
n,m = map(int,raw_input().split())

arr = [1 for i in range(n)]
isexist = [False for i in range(n)]

isexist[0] = True

for i in range(m):
	frm,to = map(int,raw_input().split())
	frm -= 1
	to -= 1

	arr[frm] -= 1
	arr[to] += 1

	if isexist[frm] :
		isexist[to] = True

	if arr[frm] == 0:
		isexist[frm] = False




count = 0
for i in range(n):
	if isexist[i] : 
		count += 1

print count

Measured memory_bytes: 7292
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define forn(b) for(int i = 0; i < b; i++)
#define rforn(b) for(int i = b - 1 ;i >= 0; i--)
#define It(m) for(auto it = m.begin(); it != m.end(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
const ll mod = (ll)1e9 + 7;
	
int main(){
	speed;
	int n; cin >> n;
	vi v(n);
	forn(n) cin >> v[i];
	int cnt = 0;
	forn(n) {
		if(i % 2 == 0 && v[i] % 2 == 1)cnt++;
	}	
	cout << cnt;
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n,m;
    vector<int> a;
    int k;
    cin >> n >> m;
    for (int i=0;i<n;i++){
        cin >> k;
        a.push_back(k);
    }
    sort(a.begin(),a.end(),std::greater<int>());
    int sum = 0;
    for(int x : a) {
        sum+=x;
    }
    if(a[m-1]*(4*m) >= sum){
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
    
using namespace std;
    
using ll = long long;
using ld = long double;
using ull = unsigned long long;

signed main(){
    io();
    int a, b; cin >> a >> b;
    string s = "";
    for(int i = 0; i < max(a, b); ++i){
        s += (min(a, b)  + '0');
    }
    cout << s << '\n';
    return 0;
}

Measured memory_bytes: 3608