akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void) {
    double x1,y1,x2,y2,x3,y3,xp,yp,k,l;
    while (scanf("%lf %lf %lf %lf %lf %lf %lf %lf\n",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)!=EOF) {
        k=((xp-x1)*(y3-y1)-(yp-y1)*(x3-x1))/((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1));
        l=((yp-y1)*(x2-x1)-(xp-x1)*(y2-y1))/((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1));
        if (k>0.0&&l>0.0&&k+l<1.0) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;

int main() {
  int N ; cin >> N;
  vector<ll> vs(N);
  rep(i, N) {
    cin >> vs[i];
  }

  ll X = 0;
  ll Y = std::accumulate(vs.begin(), vs.end(), 0LL);
  ll ans = std::numeric_limits<ll>::max();
  for (int i = 0; i < N - 1; ++i) {
    X += vs[i];
    Y -= vs[i];
    ans = min(ans, abs(X - Y));
  }

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

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;

int main(){
  int n;
  string s;
  cin >> n >> s;
  
  int max=0,x=0;
  rep(i,n){
    if(s[i]=='I') x++;
    else x--;
    if(x > max) max = x;
  } 
  
  cout << max << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

const int MAX_N = 1100;
const int MAX_H = 10100;

int dp[MAX_N][MAX_H];

int main() {
  // cin.tie(0);
  // ios::sync_with_stdio(false);
  int H, N;
  cin >> H >> N;
  int A[N], B[N];
  REP(i, N) cin >> A[i] >> B[i];
  REP(i, MAX_N) REP(j, MAX_H) dp[i][j] = 1 << 29;
  REP(i, N + 1) dp[i][0] = 0;

  REP(i, N) {
    REP(d, H + 1) {
      dp[i + 1][d] = min(dp[i + 1][max(0, d - A[i])] + B[i], dp[i][d]);
      // cout << dp[i + 1][d] << " ";
    }
    // cout << '\n';
  }
  cout << dp[N][H] << endl;
}

Measured memory_bytes: 43648
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#define fi(p) for(int i=0;i<(p);i++)
using namespace std;
int N;
int L;
int P;
const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	int k;
	int x;
	cin >> k >> x;
	vector<int> res;
	for (int i = -(k - 1); i < k; i++) {
		if (i == k - 1) {
			cout << i + x;
		}
		else {
			cout << i + x << " ";
		}
	}
}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

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

using namespace std;


int main() {
    int A, B, C;
    cin >> A >> B >> C;


    // C が一番大さい
    if (A < C && B < C) {
        cout << "No" << endl;
        return 0;
    }

    // C が一番小さい
    if (C < A && C < B) {
        cout << "No" << endl;
        return 0;
    }

//    // A と B が等しい
//    if (A == B) {
//        cout << "Yes" << endl;
//        return 0;
//    }
//
//    // Bと C が等しい
//    if (B == C) {
//        cout << "No" << endl;
//        return 0;
//    }

    cout << "Yes" << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
#include <cmath>
using namespace std;
#define MAXA 1001
#define MAXB 1001
#define MAXH 1000000001
#define MAXW 1000000007
#define INF 1000000007
#define MAXN 10
#define MAXM 1001
#define MAXP 1000001
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

int N, M, cnt;
int V[MAXN], used[MAXN], E[MAXN][MAXN];

void dfs(int s){
    used[s] = 1;
    bool flag = true;
    for(int i = 0;i < N;i++){
        if(!used[i]) flag = false;
    }
    if(flag){
        cnt++;
    }
    for(int i = 0;i < N;i++){
        if(E[s][i] && !used[i]){
            dfs(i);
        } 
    }
    used[s] = 0;
    return;
}
int main(){
    cin >> N >> M;
    int s, t;
    for(int i = 0;i < M;i++){
        cin >> s >> t;
        E[s - 1][t - 1] = 1;
        E[t - 1][s - 1] = 1;
    }

    dfs(0);

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

    return 0;
}

Measured memory_bytes: 256
X, N = map(int, input().split())
if N !=0:
    A = list(map(int, input().split()))

    c=0
    for i in range(100):
        if X-c not in A:
            print(X-c)
            break
        if X+c not in A:
            print(X+c)
            break
        c += 1
else:
    print(X)

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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
using V = vector<ll>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll hcnt[300005],wcnt[300005];

int main() {
  ll W,H,x,y;
  cin>>W>>H>>x>>y;
  lb ans = (lb)W*H/2;
  cout<<fixed<<setprecision(5);
  cout<<ans<<" ";
  if(x*2==W&&y*2==H) cout<<1<<endl;
  else cout<<0<<endl;
}


Measured memory_bytes: 3728
S=input()
N=len(S)
for i in range(N-1):
    if S[i]==S[i+1]:
        print(i+1,i+2)
        exit()
for i in range(N-2):
    if S[i]==S[i+2]:
        print(i+1,i+3)
        exit()
print(-1,-1)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#include<queue>
using namespace std;
 
#define what_is(x) cout << #x << " is " << x << endl; 
#define PI acos(-1)
#define hell 1000000007
#define HELL 998244353
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
// #define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define bug(n) {outl(n);return;}
#define pii pair<int,int>
#define lim 9223372036854775805
#define ninf -9223372036854775802
#define M 1000000007
#define eps 1e-9
#define MAX 5
#define N 500001
#define db(a) for(auto it:a) {cout<<it<<" ";}cout<<endl;
ll prime[MAX]; 
ll fact[MAX];

const long long INF64 = 1e18;
ll vpow(ll a,ll b,ll p){
    if(b==0)
        return 1;
    if(b==1)
            return a;
    ll temp=vpow(a,b/2,p);
    temp*=temp;
    temp%=p;
    if(b%2==0)
        return temp;
    temp=temp*a;
    temp%=p;
    return temp;
}

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

 
ll inverseMod(ll a,ll b,ll p){
    if(b==0)
        return 1;
    ll temp=vpow(b,p-2,p);
    ll ans=temp*a;
    ans%=p;
    return ans;
}
void sieve() 
{ 
    prime[0] = prime[1] = 1; 
    for (ll i = 2; i < MAX; i++) { 
        if (prime[i] == 0) {
            for (int j = i * 2; j < MAX; j += i) { 
                if (prime[j] == 0) { 
                    prime[j] = i; 
                } 
            } 
            prime[i] = i; 
        } 
    } 
}

void factorial(){
    fact[0]=1;
    fact[1]=1;
    rep(i,2,MAX){
        fact[i]=(fact[i-1]*i);
        // fact[i]%=M;
    }
}

void solve(ll ttt){
	ll n,x,t;
	cin>>n>>x>>t;
	x=(n+x-1)/x;
	cout<<(t*x)<<endl;
}

int main(){
    io;
   
    // sieve();
    // factorial();
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
   // freopen("output1.txt","w",stdout);
#endif
    ll t=1;
    // cin>>t;
    fix(12);
    rep(q,1,t+1){
        // cout<<"Case #"<<q<<": ";
         solve(q);
        //solve2();
    }
    return 0;
    
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
#define NMAX 100000
int N, M, res[NMAX];
bool used[NMAX];
vector<int> edge[NMAX];
queue<pint> q;

void bfs() {
  res[0] = 0;
  used[0] = true;
  for (auto &e: edge[0])
    q.push({0, e});
  while (!q.empty()) {
    pint w = q.front();
    int p = w.first, n = w.second;
    q.pop();
    if (used[n])
      continue;
    res[n] = p+1;
    used[n] = true;
    for (auto &e: edge[n]) {
      if (used[e])
        continue;
      q.push({n, e});
    }
  }
  return;
}

int main() {
  cin >> N >> M;
  int a, b;
  for (int i=0; i<M; i++) {
    cin >> a >> b;
    a--; b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  bfs();
  cout << "Yes" << endl;
  for (int i=1; i<N; i++)
    cout << res[i] << endl;
  return 0;
}

Measured memory_bytes: 11004
#include<stdio.h>
int main()
{
    int n,q=0,t=0;
    scanf("%d",&n);
    int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        b[i]=0;
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]!=i+1){
            b[i]=-1;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(b[i]==-1)
            t++;
    }
    if(t==2||t==0)
        printf("YES");
    else
        printf("NO");
}


Measured memory_bytes: 128
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
using namespace std;
typedef long long ll;

static ll p = 1000000007;

ll fact(ll n){
  if(n==1) return 1;
  return n*fact(n-1)%p;
}

int main(){
  ll n,m;
  cin >> n >> m;
  ll ans;
  if(abs(n-m)>1){
    ans = 0;
  }else if(n==m){
    ans = fact(n)*fact(m)%p*2%p;
  }else{
    ans = fact(n)*fact(m)%p;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
def do():
    N, K, Q = map(int,input().split())
    A = []
    for i in range(Q):
        A.append(int(input()))
    
    A_p = [K]*N
    for i in range(Q):
        A_p[A[i]-1] += 1
    for i in range(N):
        if A_p[i] - Q <= 0:
            print('No')
        else:
            print('Yes')
    
if __name__ == '__main__':
    do()

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int n; cin >> n;
    vector<lint> a(n);
    rep(i, n) cin >> a[i];

    if(a[0] != 0){
        out(-1); return 0;
    }

    lint now = 0, ans = 0;
    rep(i, n-1){
        if(a[i+1] > a[i] + 1){
            out(-1); return 0;
        }
        if(a[i+1] == now + 1){
            now++; continue;
        }
        if(a[i+1] <= now){
            ans += now;
            now = a[i+1];
        }
    }

    out(ans + now);
}

Measured memory_bytes: 1920
#include <bits/stdc++.h> 
using namespace std; 
typedef   long long int ll;
int main () 
{
   string s;cin>>s;
   ll k=s.length(),p=1,q=1,m=1;
   for (ll i=0;i<k/2;i++) {
       if (s[i]!=s[k-1-i]) {p=0;break;}
   }
   for (ll i=0;i<k/4;i++) {
       if (s[i]!=s[k/2-1-i]) {q=0;break;}
   }
   for (ll i=0;i<k/4;i++) {
       if (s[k/2 + 1+i]!=s[k-1-i]) {m=0;break;}
   }
   if (p==1&&q==1&&m==1) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    R = II()
    from math import pi
    print(R*2*pi)

if __name__ == '__main__':
    main()

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

int main(){
  string s, t;
  cin >> s >> t;
  int ans = 1001;
  for (int i = 0; i < 1 + s.size() - t.size(); i++) {
  	int cnt = 0;
    for (int j = 0; j < t.length(); j++) {
      if (s[i+j] != t[j])
        cnt++;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
#define SORT(v) sort(v.begin(), v.end())
#define REV(v) reverse(v.begin(), v.end())
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;
template<typename T>
using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; //小さいものから取り出す

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,0,n-1)cin >> a[i];
    SORT(a);
    set<int> s;
    int ans = 0;
    int prev = -1;
    rep(i,0,n-1){
         
        bool flg = true;
        for(int j = 1;j*j <= a[i];j++){
            if(a[i]%j==0){
                if((s.find(j) != s.end()) || (s.find(a[i]/j) != s.end())){
                    flg = false;
                    break;
                }
            }
        }
        s.insert(a[i]);
        if(prev == a[i])continue;
        if(i != n-1&& a[i] == a[i+1]){prev = a[i];continue;}
        if(flg)ans++;
        // cout << ans << endl;
        prev = a[i];
    }

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

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

tA = 0
tB = 0
for i in range(N-1):

    if A[i] < B[i]:
        M = B[i] - A[i]
        C = M//2
        if tA >= C:
            tA -= C
        else:
            D = C - tA
            tA = 0
            tB += D

    elif A[i] > B[i]:
        M = A[i] - B[i]
        C = M
        if tB >= C:
            tB -= C
        else:
            D = C - tB
            tB = 0
            tA += D

a = A[-1]
b = B[-1]
a += 2*tA
b += tB
if a <= b:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 4596
module ABC086

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none
  
  type obj_taskB

    ! data field
    integer(INT32), private :: a
    integer(INT32), private :: b
  
    ! contained <subroutine>s and <function>s are below
    contains

    procedure :: Concatenate           => taskB_Concatenate
    procedure :: IsConcatenatedSquare  => taskB_IsConcatenatedSquare
  
  end type obj_taskB

  ! constructor
  interface obj_taskB
    module procedure taskB_constructor
  end interface obj_taskB

  ! contained <subroutine>s and <function>s are below
  contains

  function taskB_constructor () result(obj)

    ! return value of this <function>
    type(obj_taskB) :: obj

    read(unit=INPUT_UNIT, fmt=*) obj%a, obj%b

    return

  end function taskB_constructor

  pure function taskB_Concatenate (obj_self) result(concatenated)

    ! arguments for this <function>
    class(obj_taskB), intent(in) :: obj_self

    ! return value of this <function>
    integer(INT32) :: concatenated

    select case (obj_self%b)
      case(        : 9_INT32); concatenated =   10_INT32 * obj_self%a
      case(10_INT32:99_INT32); concatenated =  100_INT32 * obj_self%a
      case default;            concatenated = 1000_INT32 * obj_self%a
    end select

    concatenated = concatenated + obj_self%b

    return

  end function taskB_Concatenate

  pure function taskB_IsConcatenatedSquare (obj_self) result(isSquare)

    ! arguments for this <function>
    class(obj_taskB), intent(in) :: obj_self

    ! return value of this <function>
    logical :: isSquare

    ! variables for this <function>
    integer(INT32) :: iter
    integer(INT32) :: iterSquare

    iter       = 1_INT32
    iterSquare = 1_INT32
    isSquare   = .false.

    do while ( iterSquare .le. obj_self%Concatenate() )

      if ( iterSquare .eq. obj_self%Concatenate() ) then
        isSquare = .true.
        exit
      else
        iter       = iter + 1_INT32
        iterSquare = iter * iter
      end if

    end do

    return

  end function taskB_IsConcatenatedSquare

end module ABC086

program main

  ! <module>s to import
  use, non_intrinsic :: ABC086

  ! require all variables to be explicitly declared
  implicit none

  type(obj_taskB) :: obj_given_data

  ! STEP.01
  ! initialize the instace
  obj_given_data = obj_taskB()

  ! STEP.02
  ! compute & output the answer of ABC086 A
  if ( obj_given_data%IsConcatenatedSquare() ) then
    write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') 'Yes'
  else
    write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') 'No'
  end if

end program main

Measured memory_bytes: 256
#include <stdio.h>
#define N 25
#define NE -1

struct node{
  int id;
  int left;
  int right;
};

struct node tree[N];

void Pre(int);
void In(int);
void Post(int);

int main(){

  int i, n, num, left, right, root, p[N];
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    p[i]=0;
  }

  for(i=0;i<n;i++){
    scanf("%d %d %d", &num, &left, &right);
    tree[num].id=num;
    tree[tree[num].id].left=left;
    tree[tree[num].id].right=right;
    if(left!=NE) p[tree[num].left]=1;
    if(right!=NE) p[tree[num].right]=1;
  }
  
  for(i=0;i<n;i++){
    if(p[i]==0) root=i;
  }

  
  printf("Preorder\n");
  Pre(root);
  printf("\n");

  printf("Inorder\n");
  In(root);
  printf("\n");

  printf("Postorder\n");
  Post(root);
  printf("\n");

  return 0;
}
    
void Pre(int id){
  if(id==NE) return;
  
  else{
    printf(" %d",id);
    Pre(tree[id].left);
    Pre(tree[id].right);
  }
}


void In(int id){
  if(id==NE) return;
  else{
    In(tree[id].left);
    printf(" %d", id);
    In(tree[id].right);
  }
}

void Post(int id){
  if(id==NE) return;
  else{
    Post(tree[id].left);
    Post(tree[id].right);
    printf(" %d", id);
  }
}

  




Measured memory_bytes: 2148
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
int main() {
  int W, H, x, y, ans, c;
  string s;
  while (cin >> W >> H, W) {
    vector<string> M;
    ans = 0;
    M.push_back(string(W+2, '#'));
    for (int i = 0; i < H; ++i) {
      cin >> s;
      for (int j = 0; j < W; ++j) {
	if (s[j] == '@') {
	  x = i+1;
	  y = j+1;
	  s[j] = '!';
	  break;
	}
      }
      s = '#' + s + '#';
      M.push_back(s);
    }
    M.push_back(string(W+2, '#'));
    queue<vector<int>> que;
    que.push({x, y});
    while (!que.empty()) {
      ++ans;
      x = que.front()[0];
      y = que.front()[1];
      que.pop();
      if (M[x-1][y] == '.') {
	M[x-1][y] = '!';
	que.push({x-1,y});
      }
      if (M[x][y-1] == '.') {
	M[x][y-1] = '!';
	que.push({x,y-1});
      }
      if (M[x+1][y] == '.') {
	M[x+1][y] = '!';
	que.push({x+1,y});
      }
      if (M[x][y+1] == '.') {
	M[x][y+1] = '!';
	que.push({x,y+1});
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,k;
    cin >> n >> k;
    vector <int> a(n+1,0);
    REP(i,n){
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    int answer = accumulate(a.begin()+k,a.end(),0);
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
typedef long long int ll;
using namespace std;
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	int ans=0;
	if(a<b){
		if(b<c){
			ans=c*10+b+a;
		}else{
			ans=b*10+c+a;
		}
	}else{
		if(a<c){
			ans=c*10+b+a;
		}else{
			ans=a*10+c+b;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
# define pll pair<ll,ll>
	
int main()
{
	string ans[]={"AC","WA","TLE","RE"};
	int n;	
	cin>>n;
	string s;
	int a[4]={0,0,0,0};
	for(int i=0;i<n;i++)
	{
		cin>>s;
		for(int j=0;j<4;j++)
		{
			if(ans[j]==s)
			++a[j];
		}
	}
	for(int i=0;i<4;i++)
	{
		cout<<ans[i]<<" x "<<a[i]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3624
import math

A,B,H,M = map(int, input().split())

HC = H*0.5*60 + 0.5*M
MC = M*6

# print(MC)
# print(HC)

if MC-HC >= 0:
    CC = MC-HC

else:
    CC = HC-MC
    
# print(CC)

T = (A**2 + B**2 - 2*A*B*math.cos(math.radians(CC)))**(1/2)
print(T)

Measured memory_bytes: 9568
#include <bits/stdc++.h>
using namespace std;
const int maxn=100000;
struct _node{
	int A;
	int p;
	static bool cmp(_node &a,_node &b){
		return a.A<b.A;
	}
};
_node l[maxn+1];
int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&l[i].A);
		l[i].p=i;
	}
	sort(l+1,l+1+n,_node::cmp);
	int cnt=0;
	for(int i=1;i<=n;++i){
		cnt+=abs(l[i].p-i)%2;
	}
	printf("%d",cnt/2);
	return 0;
}


Measured memory_bytes: 1024
str_list = input().split(' ')
int_list = [int(x) for x in str_list]
N, K, Q = int_list[0], int_list[1], int_list[2]
A = []
for _ in range(Q):
    A.append( int(input()) )
point = [int(K)]*N
import numpy as np
point = np.array(point)
for ii in range(Q):
    point[A[ii]-1] += 1
point -= Q
for ii in range(N):
    if point[ii] <= 0:
        print('No')
    else:
        print('Yes')


Measured memory_bytes: 18784
n = int(input())
d = []
for i in range(n - 1):#h:高さ
    d.append([int(m) for m in input().split()])
q, k = map(int, input().split())
z = []
for i in range(q):#h:高さ
    z.append([int(m) for m in input().split()])

for i in range(n - 1):
    d[i][0] -= 1
    d[i][1] -= 1
for i in range(q):
    z[i][0] -= 1
    z[i][1] -= 1
def BFS(k, edges, N):
  roots=[ [] for i in range(N)]
  for a,b,c in edges:
    roots[a]+=[(b,c)]
    roots[b]+=[(a,c)]
  dist=[-1]*N
  stack=[]
  stack.append(k)
  dist[k]=0
  while stack:
    label=stack.pop(-1)
    for i,c in roots[label]:
      if dist[i]==-1:
        dist[i]=dist[label]+c
        stack+=[i]
  return dist

root = BFS(k - 1, d, n)

for i in range(q):
    print(root[z[i][0]] + root[z[i][1]])

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

n = int(input())
L, R = [], []
LR = []
INF = 10**9+1
m, M = INF, 0
for i in range(n):
  x, y = map(int, input().split())
  if x > y:
    x, y = y, x
  L.append(x)
  R.append(y)
  LR.append((x, y))
  if m > x:
    m = x
    idx_m = i
  if M < y:
    M = y
    idx_M = i
ans1 = (M-min(R))*(max(L)-m)
if idx_m == idx_M:
  print(ans1)
  exit()
a, b = L[idx_M], R[idx_m]
if a > b:
  a, b = b, a
LR = sorted([lr for i, lr in enumerate(LR) if i != idx_m and i != idx_M])
if not LR:
  print(ans1)
  exit()
L, R = zip(*LR)
max_R = [-1]*(n-2)
min_R = [-1]*(n-2)
max_R[0] = R[0]
min_R[0] = R[0]
for i in range(n-3):
  max_R[i+1] = max(max_R[i], R[i+1])
  min_R[i+1] = min(min_R[i], R[i+1])
l_min, l_max = L[0], L[-1]
ans2 = max(b, l_max) - min(a, l_min)
for i in range(n-2):
  if i < n-3:
    l_min = min(min_R[i], L[i+1])
  else:
    l_min = min_R[i]
  l_max = max(l_max, max_R[i])
  ans2 = min(ans2, max(b, l_max) - min(a, l_min))
ans2 *= M-m
ans = min(ans1, ans2)
print(ans)

Measured memory_bytes: 121720
shop_num, want_drink_num = STDIN.gets.split.map(&:to_i)

cost_index = Hash.new {|h, k| h[k] = []}
buyables = []
shop_num.times do |i|
  cost, buyable = STDIN.gets.split.map(&:to_i)
  cost_index[cost] << i
  buyables << buyable
end

payment = 0

def get_buy_num(buyable, surplus)
  return buyable if surplus > buyable
  surplus
end

cost_index.sort.each do |cost, idxs|
  idxs.each do |i|
    buy_num = get_buy_num(buyables[i], want_drink_num)
    payment += cost * buy_num
    want_drink_num -= buy_num
    break if want_drink_num == 0
  end
end

STDOUT.puts payment

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

using namespace std;

map<char,int> addValueChar(map<char,int> m, string s)
{
	transform(s.begin(), s.end(), s.begin(), ::tolower);
	
	for(int i = 0; i < s.size(); i++)
		m[s[i]] += 1;
	
	return m;
}

int main()
{
	int num_char = 26, initial_ascii = 97, final_ascii = 122;
	string s;
	
	map<char, int> m;
	
	for(int i = 0; i < num_char; m[(char)initial_ascii+i] = 0, i++);
	
	while(true)
	{
		getline(cin, s);
		
		if(cin.eof())
			break;
		
		m = addValueChar(m, s);
	}
	
	m = addValueChar(m, s);
	
	map<char, int>::iterator it;
	
	for(it = m.begin(); it != m.end(); it++)
		if((int)it->first >= initial_ascii && (int)it->first <= final_ascii)
			cout << it->first << " : " << it->second << "\n";
	
	return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // AGC002A - Range Product
  ll a, b; cin >> a >> b;
  if(a <= 0 && b >= 0){
    cout << "Zero" << endl;
  }else if(b < 0){
    if((b - a) % 2 == 0){
      cout << "Negative" << endl;
    }else{
      cout << "Positive" << endl;
    }
  }else if(a > 0){
    cout << "Positive" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, h[100];
vector<char> s;
set<char> first;
vector<string> vs(20);
bool used[10];

bool calc(){
  int left, item, ans;
  left = 0;
  ans = 0;
  for (int i = 0; i < vs[n - 1].size(); i++) {
    ans = 10*ans + h[vs[n - 1][i]];
  }
  for (int i = 0; i < n - 1; ++i) {
    item = 0;
    for (int j = 0; j < vs[i].size(); ++j) {
      item = 10*item + h[vs[i][j]];
    }
    left = left + item;
    if(left > ans)return false;
  }
  return left == ans;
}
 
int dfs(int size = 0){
  if(size == s.size()){
    return calc();
  }
  int res;
  res = 0;
  for (int i = 0; i < 10; ++i) {
    if(used[i])continue;
    if(i == 0 and first.find(s[size]) != first.end())
      continue;
    h[s[size]] = i;
    used[i] = true;
    res += dfs(size + 1);
    used[i] = false;
  }
  return res;
}
 
int main(){
  while(std::cin >> n, n){
    s.clear();
    first.clear();
    for (int i = 0; i < n; ++i) {
      std::cin >> vs[i];
      if(vs[i].size() != 1)first.insert(vs[i][0]);
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < vs[i].size(); ++j) {
        s.push_back(vs[i][j]);
      }
    }
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    std::cout << dfs() << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
/*
int dfs(int i, int j){
	if(N == i)return 0;
	if(j-w[i] >= 0)dfs(i,j-w[i]);
	else dfs(i+1, j);
}


*/
int dp[101][10001];

int main(void){
	int N, W;
	cin >> N >> W;
	int v[101], w[101];
	//dp[?????°N][??????0~W]
	rep(i,N)cin >> v[i] >> w[i];
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= W; j++){
			if(j-w[i] >= 0){
				dp[i+1][j] = max(dp[i][j], dp[i+1][j-w[i]] + v[i]);
			}else{
				dp[i+1][j] = dp[i][j];
			}
		}
	}
	FIN(dp[N][W]);



	return 0;
}

Measured memory_bytes: 5068
n = int(raw_input())

ans = 100000

d = []

for a in range(1,7):d.append( 6**a )
for a in range(1,6):d.append( 9**a )
d.append(1)
d.sort()
#print d

dp = [1000000000] * 100001
dp[0] = 0
for x in range(0,n+1):
  for y in d:
    if x-y >= 0:
      dp[x] = min( dp[x-y] + 1, dp[x] )

print dp[n]


Measured memory_bytes: 6532
#include<cstdio>
#include<algorithm>
using namespace std;
double a[51];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lf",&a[i]);
	}
	sort(a+1,a+1+n);
	double val=a[1];
	for(int i=2;i<=n;i++){
		val=(val+a[i])/2.0;
	}
	printf("%lf",val);
	return 0;
}

Measured memory_bytes: 128
from collections import OrderedDict
from math import factorial


def comb(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)


N, A, B = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
counter = OrderedDict()
for i in range(N):
    if v[i] in counter:
        counter[v[i]][0] += 1
    else:
        counter[v[i]] = [1, i + 1]
average = []
for i in range(A, B + 1):
    ave = sum(v[:i]) / i
    num = comb(counter[v[i - 1]][0], i - counter[v[i - 1]][1] + 1)
    average.append([ave, num])
average.sort(key=lambda x: -x[0])
M_arv = average[0][0]
ans = 0
for item in average:
    if item[0] == M_arv:
        ans += item[1]
    else:
        break
print('{:.6f}'.format(M_arv))
print(int(ans))

Measured memory_bytes: 3316
from collections import deque,Counter

N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()

T = T.translate(str.maketrans({'r': 'p', 's': 'r','p': 's'}))
cnt = Counter(T)
dic = {"r":R, "s":S, "p":P}

ans = cnt["r"]*R + cnt["s"]*S +cnt["p"]*P
checked = []
for i in range(N-K+1):
    if i%K in checked:
        continue
    else:
        j = i
        tmp = 0
        while j <len(T):
            if tmp == T[j]:
                ans -= dic[T[j]]
                tmp = 0
            else:
                tmp = T[j]
            j += K
        checked.append(i%K)

print(ans)



Measured memory_bytes: 45936
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut l: [usize; n],
    }
    l.sort();
    let mut ans = 0;
    for i in 0..n {
        let a = l[i];
        for j in i + 1..n {
            let b = l[j];
            let ab = a + b;
            for k in (j + 1..n).rev() {
                if l[k] < ab {
                    ans += k - j;
                    break;                
                }
            }
        }
    }
    println!("{}", ans);
        
}

Measured memory_bytes: 2160
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<utility>

using std::cin;
using std::cout;
using std::vector;
using std::queue;
using std::string;
using std::pair;
using std::make_pair;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

int h, w;
char s[100][100];
int bfs(int sx, int sy, int gx, int gy) {
    int dist[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            dist[i][j]=-1;
        }
    }
    dist[0][0] = 0;

    queue<pair<int, int>> q;
    q.push(make_pair(sx, sy));
    while(!q.empty()) {
        pair<int, int> now = q.front();
        q.pop();
        for(int i=0;i<4;i++) {
            int next_y = now.second + dy[i];
            int next_x = now.first + dx[i];
            if(0 <= next_y && next_y < h && 0 <= next_x && next_x < w && s[next_y][next_x] != '#') {
                if(dist[next_y][next_x]==-1 || dist[next_y][next_x] > dist[now.second][now.first] + 1) {
                    q.push(make_pair(next_x,next_y));
                    dist[next_y][next_x] = dist[now.second][now.first] + 1;
                }
            }
        }
    }
    return dist[h-1][w-1];
}

int main() {
    cin >> h >> w;
    string buf;
    for(int i=0;i<h;i++) {
        scanf("%s", s[i]);
    }

    int cnt = 0;
    for(int i=0;i<h;i++) {
        for(int j=0;j<w;j++){
            if(s[i][j]=='.'){
                cnt++;
            }
        }
    }
    int res = bfs(0, 0, h-1, w-1);
    if(res==-1){
        printf("-1");
    }else{
        printf("%d\n", cnt-1-res);
    }
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class C {
    static bool OK(HashSet<int> banned, int n) =>
        n.ToString().All(k => !banned.Contains(k - '0'));

    public static void Main() {
        var line = Console.ReadLine().Split();
        var n = int.Parse(line[0]);
        var d = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var banned = new HashSet<int>(d);
        while (!OK(banned, n)) ++n;
        Console.WriteLine(n);
    }
}


Measured memory_bytes: 15328
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(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 maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    string S;
    cin >> S;
    
    string T;
    cin >> T;

    int ans = 0;
    for(int i = 0; i < 3; i++) {
        if (S[i] == T[i]) ans++;
    }


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

Measured memory_bytes: 256
#include<stdio.h>
#define A 1000
#define N 100

main(){
  int a,b[A],i,j,v;
  scanf("%d",&a);
  for(j=0;j<a;j++){
    scanf("%d",&b[j]);
  }

  for(i=1;i<a+1;i++){
    for(j=0;j<a-1;j++){
      printf("%d ",b[j]);
    }
    printf("%d",b[a-1]);
    printf("\n");
    v = b[i];
    j = i - 1;
   while(j>=0 && b[j]>v){
     b[j+1] = b[j];
     j--;
     b[j+1] = v;
   }
  }
  return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(int i = 0; i<(int)rept;++i)
typedef long long ll;
using namespace std;
const int mod = 1e+9 + 7;

std::vector<bool> IsPrime;



int main() {
	//13日目

	cin.tie(0); ios::sync_with_stdio(false);

	int n = 0;
	cin >> n;
	int count[1000] = {};

	for (int i = 1; i <= n; i++) {
		int t = i;
		for (int j = 2; j <= i; j++) {//最初に2で割れるだけ割っている(ｔの数はwhileから出てもそのまま！)なので重複しない
			while (t%j == 0) {
				t /= j;
				count[j]++;
			}
		}
	}

	long long ans = 1;
	for (int i = 2; i <= n; i++) {
		ans *= (count[i] + 1);
		ans %= mod;
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

const int MAX_N = 100000;
int N;
int A[MAX_N], B[MAX_N];

int main(){
  cin >> N;
  int mi = INFi;
  ll su = 0;

  REP(i, N) {
    cin >> A[i] >> B[i];
    if(A[i] > B[i]) mi = min(B[i], mi);
    su = su + A[i];
  }
  if (mi == INFi) cout << 0 << endl;
  else cout << su - mi << endl;


  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k%2==0&&a-b>=-1000000000000000000&&a-b<=1000000000000000000){
		cout<<a-b<<endl;
	}
	else if(k%2==1&&b-a>=-1000000000000000000&&b-a<=1000000000000000000){
		cout<<b-a<<endl;
	}
	else{
		cout<<"Unfair"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 209
#define pi pair<int,int>
using namespace std;
typedef long long ll;
priority_queue<ll>adj[123456];
int main()
{
    ll n,m;
    cin>>n>>m;
    ll h[n+4];
    for(ll i=1;i<=n;i++) cin>>h[i];
    while(m--)
    {
        ll u,v;
        cin>>u>>v;
        adj[u].push(h[v]);
        adj[v].push(h[u]);
    }
    ll cnt=0;
    for(ll i=1;i<=n;i++)
    {
        if(!adj[i].empty())
        {
            //cout<<i<<" X "<<adj[i].top()<<endl;
            if(h[i]>adj[i].top())
            {
                cnt++;
            }
        }
        else cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 11776
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,c;
	cin>>a>>b>>c;
	long long j=c-a-b;
	if(j>0&&4*a*b<j*j)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>

int main(){
	int r;
	std::cin >> r;
	if (r < 1200) std::cout << "ABC" << std::endl;
	else if (r < 2800) std::cout << "ARC" << std::endl;
	else std::cout << "AGC" << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
  int N,M;
  cin >> N >> M;
  int answer;
  answer = N*(N-1)/2+M*(M-1)/2;
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    int N;cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin >> A[i];
    ll sum = A[0];
    ll ans = 0;
    for(int i=1;i<N;i++){
        ans += sum * A[i];
        ans %= 1000000007;
        sum += A[i];
        sum %= 1000000007;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4040
#include <stdio.h>
int main(void)
{
	int temp,L,R,i,ans=3000,m;
	scanf("%d%d",&L,&R);
	temp= L % 2019;
  if(R-L > 2019){
    printf("0");
  }
  else if(temp+R-L >= 2019){
    printf("0");
  }
  else{
    for(i = temp;i<=R%2019;i++){
      for(m =temp;m<=R%2019;m++){
      if(i!=m){
        if(ans>(i*m)%2019){
          ans=(i*m)%2019;
          }
      }
      }
    }
    printf("%d",ans);
  }
return 0;
}


Measured memory_bytes: 128
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.log(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,1);
  var primeCountList = {
  	"1" : 1
  };
  for(var i = 1; i <= input; i++){
    var tmpI = i;
    var div = 2;
    while(tmpI != 1){
       if(tmpI % div == 0){
         if(primeCountList[div] == null){
           primeCountList[div] = 1;
         }else{
           primeCountList[div]++;
         }
         tmpI /= div;
       }else{
         div = (div == 2) ? div+1 : div+2;
       }
    }
  }
  //myout(primeCountList);
  var primeList = Object.keys(primeCountList);
  
  var result442 = 0;//P1^4,P2^4,P3^2
  var result242 = 0;//P1^24,P3^2
  var result144 = 0;//P1^14,P2^4,
  var result74 = 0;//P1^74
  var result2 = 0;
  var result4 = 0;
  var result14 = 0;
  var result24 = 0;
  var result74 = 0;
  for(var i = 0; i < primeList.length; i++){
    if(primeCountList[primeList[i]] >= 2){
       result2++;
    }
    if(primeCountList[primeList[i]] >= 4){
       result4++;
    }
    if(primeCountList[primeList[i]] >= 14){
       result14++;
    }
    if(primeCountList[primeList[i]] >= 24){
       result24++;
    }
    if(primeCountList[primeList[i]] >= 74){
       result74++;
    }
  }
  result442 = (result4 * (result4 -1)) / 2 * (result2 -2);
  result242 = result24 * (result2 -1);
  result144 = result14 * (result4 -1);
  
  myout(result442 + result242 + result144 + result74);
  
}

function getPrimeFactorization(val){
	var primeList = {
		"1" : 1
	};
	var div = 2;
	while(val != 1){
		if(val % div == 0){
			if(primeList[div] == null){
				primeList[div] = 1;
			}else{
				primeList[div]++;
			}
			val /= div;
		}else{
			div = (div == 2) ? div+1 : div+2;
		}
    }
  return primeList;
}

for(var i = 1; i <= 10; i++){
  //Main(i);
}

Main(myin());


Measured memory_bytes: 7628
#include <bits/stdc++.h>
#define REP(i, n) for (decltype(n) i = 0; i < n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define readvec(vec)    \
  for (auto& e : vec) { \
    cin >> e;           \
  }
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
int main() {
  init();
  int n;
  cin >> n;
  vecll a(n);
  for (auto& e : a) cin >> e;
  sort(all(a));
  vecll sum(n, 0);
  sum[0] = a[0];
  REP(i, n - 1) sum[i + 1] = sum[i] + a[i + 1];
  // for (auto& e : sum) cout << e << endl;
  auto check = [&](int i) -> bool {
    ll s = sum[i];
    for (int j = i; j < n; j++) {
      if (2 * s >= a[j]) {
        s = sum[j];
      } else {
        return false;
      }
    }
    return true;
  };
  int l = 0;
  int r = n - 1;
  if (check(l)) {
    cout << n << endl;
    return 0;
  }
  while (r - l > 1) {
    int c = (l + r) / 2;
    // cout << c << " " << check(c) << endl;
    if (!check(c)) {
      l = c;
    } else {
      r = c;
    }
  }
  cout << n - l - 1 << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(){
int F[50],i,n;
 scanf("%d",&n);
 F[0]=F[1]=1;
 for(i=2;i<=n;+i++){
   F[i]=F[i-1]+F[i-2];
 }

 printf("%d\n",F[n]);

return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
 
using namespace std;
 
#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define rall(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const ll MOD = 1e9+7;

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
 
	set<string> s;
	int n; cin >> n;

	FOR(i, n){
		string x; cin >> x;
		s.insert(x);
	}

	cout << s.size() << '\n';

	return 0;
}

Measured memory_bytes: 19212
n = int(input())
a = list(map(int,input().split()))
n4 = 0
n2 = 0
for i in range(n):
    if a[i]%4==0:
        n4+=1
    elif a[i]%2==0:
        n2+=1
if n2 ==1:
    n2 = 0
l = n4*2 + n2
if l>=n or n4*2+1 == n:
    print('Yes')
else:
    print('No')


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


#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int keta_sum(int x){
  
  int sum = 0; //各桁の和
  
  while(true){
    int r = x%10;
    sum += r;
    x = x/10;
    if(x == 0) break;
  }
  
  return sum;
  
}

int main(){
  int N;
  cin >> N;
  if(N % keta_sum(N) == 0) cout << "Yes" << endl;
  else cout << "No" <<endl;
}

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

int main() {
    ios_base::sync_with_stdio(false);	
    cin.tie(0);
	int x, y;
	cin >> x >> y;
	if (x * 2 <= y && x * 4 >= y && y % 2 == 0) cout << "Yes" << "\n";
	else cout << "No" << "\n";
	return 0;
}


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

template<size_t max_sz,size_t num>
struct primes{
  using i64 = int_fast64_t;
  i64 is_p[max_sz];
  i64 p[num];
  size_t cnt = 0;
  constexpr primes():is_p(),p(){
    for(i64 i=2;i<max_sz;++i){
      if(is_p[i]==0){
        is_p[i] = 1;
        p[cnt++] = i;
      }
      if(cnt>=num)break;
      for(i64 x=i*i;x<max_sz;x+=i){
        is_p[x] = 2;
      }
    }
  }
};

signed main(){

  constexpr auto prime = primes<250000,22044>();

  int n;
  cin>>n;
  cout<< *lower_bound(begin(prime.p),end(prime.p),n) <<endl;

}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define off  exit( 0 )
#define cn   continue
#define rt   return
#define sc   scanf
#define pr   printf
#define pb   push_back
#define pf   push_front
#define p_f  pop_front
#define p_b  pop_back
#define ff   first
#define ss   second
#define ll   long long
#define ld   long double
#define N    100256
#define M    1000000007
#define I    1000000000000000000
#define pdd  pair < ld, ld >
#define pll  pair < ll, ll >
#define pii  pair < int, int >
#define sqr( a )           a * a
#define all( c )           c.begin(), c.end()
#define srt( c )           sort( all( c ) )
#define rev( c )           reverse( all( c ) )
#define srtr( c )          sort( c.rbegin(), c.rend() );
using namespace std;

ll n, m, k;
ll a, b, c;
ll ans, sum, cnt, cur;
string s, t;


void solve()
{
    cin >> k >> s;
    for( int i = 0; i < s.size(); i ++ )
    {
        cout << char( ( s[i] - 'A' + k ) % 26 + 'A' );
    }
}
int main()
{
    ll tt = 1;
   // sc( "%d", &tt );
    for( ll i = 1; i <= tt; i ++ )
    {
        solve();
    }
}












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

int q, n;

int keta(int n){
  int count=1;
  while (1){
    if (n>=10){
      count++;
      n = n/10;
    }
    else break;
  }
  return count;
}

int maain(){
  cin >> q;
  for (int i=0;i<q;i++){
    cin >> n;
    cout << keta(n) << endl;
  }
  return 0;
}

int main(){
  int a,b;
  cin >> q;
  for (int i=0;i<q;i++){
    cin >> n;
    int ans=0;
    while (n>=10){
      int max=0;
      int ket=keta(n);
      for (int j=1;j<ket;j++){
	a=n/pow(10,j);
	b=n-a*pow(10,j);
	if (a*b>max) max=a*b;
      }
      n=max;
      ans++;
    }
    cout << ans << endl;
  }
  return 0; 
}

Measured memory_bytes: 3272