akhauriyash/Code-Regression huggingface dataset:
def s(n):
    ret=0    
    for i in range(15):
        ret+=(n%10**(i+1))//10**i
    return ret

k=int(input())
ksnk=set()

for i in range(13):
    for j in range(1,1000):
        n=int(str(j)+'9'*i)
        ksnk.add(n)
ksnk=sorted(list(ksnk), reverse=True)

fmin=float('inf')
ans=[]
for a in ksnk:
    fa=a/s(a)    
    if fa<=fmin:
        ans.append(a)
        fmin=fa
ans.reverse()
for a in ans[:k]:
    print(a)


Measured memory_bytes: 4076
#include <stdio.h>
int main() {
	int n, le[100], x, l = 0, r, m, i;
	scanf("%d %d", &n, &x);
	r = n;
	m = n/2;
	for(i = 0; i < n; i++) {
		scanf("%d", &le[i]);
		if(i)
			le[i] += le[i - 1];
	}
	while(1) {
		if(l + 1 >= r) {
			m = l;
			break;
		}
		if(le[m] == x)
			break;
		else {
			if(le[m] > x)
				r = m;
			else
				l = m;
			m = (l+r)/2;
		}
	}
	printf("%d", m + 2);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        int a = scn.nextInt();
        int b = scn.nextInt();
        int c = scn.nextInt();
        int d = scn.nextInt();
        String answer = "No";
        if(Math.abs(a-c)<=d){
            answer = "Yes";
        }else if(Math.abs(a-b)<=d&&Math.abs(b-c)<=d){
            answer = "Yes";
        }
        System.out.println(answer);
    }
}


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

int main(){
    int i=0,j=0,k=0,tmp=0;
    while(cin >> tmp){
        if (tmp > i)
        {
            k = j;
            j = i;
            i = tmp;
        }
        else if (tmp > j)
        {
            k = j;
            j = tmp;
        }
        else if (tmp > k)
        {
            k = tmp;
        }
    }
    cout << i << endl << j << endl << k << endl;
    return 0;
}

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

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long> vll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvll;
typedef vector<string> vs;
typedef map<int, int> mi;
typedef map<long long, long long> mll;
typedef map<string, int> msi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define B begin()
#define E end()
// for (auto it = .B; it < .E; it++) {

int main() {
    int n, k, d, s;
    cin >> n >> k;
    int val[n] = {0};
    for (int i = 0; i < k; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            cin >> s;
            val[s - 1] = 1;
        }
    }
    int t = 0;
    for (int s : val) {
        if (s == 0) {
            t++;
        }
    }
    cout << t << "\n";

    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  int c = a * b;
  if(c % 2 == 0){
    cout << "No\n";
  }
  else{
    cout << "Yes\n";
  }
}

Measured memory_bytes: 3596
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]

counter = Counter(S)
count = counter.most_common()
most = count[0][1]
c = []

for i in range(len(counter)):
    if count[i][1] == most:
        c.append(count[i][0])

c.sort()
print(*c, sep='\n')

Measured memory_bytes: 50188
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());

//        sc.nextLine();
        String[] texts = new String[N];
        for (int n = 0; n < N; n++) {
            texts[n] = sc.nextLine();
        }

        HashMap<String, Integer> words = new HashMap<String, Integer>();
//        System.out.println("\n\n"+N);
        int max = 0;
        for (int n = 0; n < N; n++) {
            if (!words.keySet().contains(texts[n])){
                words.put(texts[n], 1);
            } else {
                words.put(texts[n], words.get(texts[n]) + 1);
            }

            if (max < words.get(texts[n])) max = words.get(texts[n]);
//            System.out.println(texts[n]);
//            words.add(texts[n]);
        }

        List<String> maxz = new ArrayList<String>();
//        System.out.println(max);

        for (String w:words.keySet()){
//            System.out.println(w+" "+words.get(w));
            if (max == words.get(w)){
                maxz.add(w);
            }
        }

//        List<String> sortedList = maxz.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList());
        Collections.sort(maxz);
        for (String i: maxz){
            System.out.println(i);
        }

    }
}

Measured memory_bytes: 173992
<?php
$N = trim(fgets(STDIN));

if ($N % 4 == 0 || $N % 7 == 0)
{
    echo 'Yes';
}
else
{
    $i = 1;
    do 
    {
        $tmp = $N - 7 * $i;
        if ( $tmp < 0)
        {
            echo 'No';
            break;
        }
        if ( $tmp % 4 == 0 )
        {
            echo 'Yes';
            break;
        }
        else
        {
            $i++;
        }
    } while($i <= 14);
}
?>

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())

const int N = 2e5 + 1e3;
int a[N];
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] -= i + 1;
    }
    sort(a , a + n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += abs(a[i] - a[n / 2]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define chal ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
    int t=1;
    //cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll a[n],b[n],i,ans=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
        }
        b[n-1]=0;
        for(i=n-2;i>=0;i--)
        {
            b[i]=(b[i+1]%mod+a[i+1]%mod)%mod;
        }
        for(i=0;i<n;i++)
        {
            ans=(ans%mod+(a[i]*b[i])%mod)%mod;
        }
        cout<<ans;

    }
    return 0;
}


Measured memory_bytes: 6732
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];



int main() {
    long long k,a,b;
    long long ret=0;
    cin>>k>>a>>b;
    long long step=k;
    if(b-a>2){
        if(k+1<=a){
            ret=k+1;
        }
        else{
            ret=a+((k-(a-1))/2)*(b-a)+(k-a+1)%2;
        }
    }
    else{
        ret=k+1;
    }
    cout<<ret<<endl;

}


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

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

    if (n % 2 != 0)
    {
        cout << "No" << endl;
        return 0;
    }

    rep(i, n / 2)
    {
        if (s[i] != s[i + n / 2])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}
double min(double a,double b){
  if(a<b) return a;
  else return b;
}
int absolute(int a,int b){
  if(a-b<0) return -(a-b);
  else return a-b;
}
int sum_keta(int n){
  if(n==0) return 0;
  return n%10 + sum_keta(n/10);
}
int main(void){
  int A,B,C,X; cin >> A >> B >> C >> X;
  
  int count = 0;
  for(int i=0;i<=A;i++){
  	for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
      	int money = i*500 + j*100 + k*50;
        if(money == X) count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
#define ll long long
using namespace std;
typedef pair<int,int> P;
vector<P> island(200010);
 
int main()
{
    int n,m;
    cin >> n >> m;
    
    REP(i,m) cin >> island[i].first >> island[i].second;
    set<int> memo_list;
    REP(i,m){
        if(island[i].first == 1){
            memo_list.insert(island[i].second);
        }
    }

    int flag = 0;
    sort(island.begin(),island.end(),greater<P>());//降順ソート
    REP(i, m){
        if(island[i].second  == n){
            if(memo_list.count(island[i].first)){
                    flag = 1;
                    break;
            }
        }
    }
 
    if(flag == 0) cout << "IMPOSSIBLE" << endl;
    else if(flag == 1) cout << "POSSIBLE" << endl;
    //cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>
#include <math.h>
void kock(int n,double x1,double y1,double x2,double y2) {
  double sx,sy,ux,uy,tx,ty;
  if(n != 0) {
  sx = (2 * x1 + x2) / 3;
  sy = (2 * y1 + y2) / 3;
  
  tx = (x1 + 2 * x2) / 3;
  ty = (y1 + 2 * y2) / 3;
  
  ux = ((tx - sx) * cos(M_PI/3) - (ty - sy) * sin(M_PI/3)) + sx;
  uy = ((tx - sx) * sin(M_PI/3) + (ty - sy) * cos(M_PI/3)) + sy;
  
  kock(n-1, x1,y1,sx, sy);
  printf("%f %f\n",sx,sy);
  kock(n-1, sx,sy,ux,uy);
  printf("%f %f\n",ux,uy);
  kock(n-1, ux,uy,tx,ty);
  printf("%f %f\n",tx,ty);
  kock(n-1, tx,ty,x2,y2);
  }

}


int main() {
  int n,k;
  double x1 = 0.0,x2 = 100.0,y1 =0.0,y2 = 0.0;
  scanf("%d",&n);
  printf("%f %f\n",x1,y1);
  kock(n,x1,y1,x2,y2);
  printf("%f %f\n",x2,y2);
  return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
int n,a[100010];
void f(int p){
    int dx=0,dy=a[p]-p;
    for(int i = p+1;i<=n&&a[i]==p;++i){
        ++dx;
    }
    if((dx&1)||(dy&1))puts("First");
    else puts("Second");
}
int main()
{
    cin>>n;
    for(int i = 1;i <= n;++i)scanf("%d",&a[i]);
    if(n==1){
        if(a[1]&1)puts("Second");
        else puts("First");
        return 0;
    }
    sort(a+1,a+1+n,greater<int>());
    int p = 1;
    for(int i = 1;i <= n;++i){
        if(a[i+1]<i+1){
            p=i;
            break;
        }
    }
    f(p);
    return 0;
}


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

using namespace std;

int main(void) {
	int N;
	cin >> N;
	if(N % 2 == 0) {
		cout << (N / 2) << '\n';
	} else {
		cout << (N / 2 + 1) << '\n';
	}
	return 0;
}



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

int main() {
  int N, M;
  int NMIN, NMAX;
  cin >> N >> M;
  vector<int> L(M), R(M);
  for (int i=0; i<M; i++) {
    cin >> L.at(i) >> R.at(i);
  }
  
  NMIN = 1;
  NMAX = N;
  
  for (int i=0; i<M; i++){
    if (NMIN < L.at(i)){
      NMIN = L.at(i);
    }
    if (R.at(i) < NMAX){
      NMAX = R.at(i);
    }
  }
  
  if (NMAX < NMIN) {
    cout << 0 << endl;
  }
  else {
    cout << NMAX - NMIN + 1 << endl;
  }
}



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

using namespace std;

const vector<int64_t> divisor = {2, 3, 5};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  for (int i = 0; i < T; i++) {
    int64_t N;
    vector<int64_t> X(4);
    cin >> N;
    for (int i = 0; i < 4; i++) {
      cin >> X[i];
    }
    int64_t res = INT64_C(1) << 58;
    priority_queue<pair<int64_t, int64_t>, vector<pair<int64_t, int64_t>>,
                   greater<pair<int64_t, int64_t>>>
        que;
    que.push(make_pair(0, N));
    set<int64_t> st;
    while (!que.empty()) {
      auto q = que.top();
      que.pop();
      int64_t c = q.first, n = q.second;
      if (n == 0) res = min(res, c);
      if (st.find(n) != st.end()) continue;
      st.insert(n);
      for (int i = 0; i < 3; i++) {
        int64_t d = divisor[i];
        if (n % d == 0) {
          int64_t m = n / d, nc = c + X[i];
          if (n - m < (INT64_C(1) << 32)) nc = min(nc, c + (n - m) * X[3]);
          que.push(make_pair(nc, m));
        } else {
          int64_t dn = n % d;
          que.push(make_pair(c + dn * X[3], n - dn));
          que.push(make_pair(c + (d - dn) * X[3], n + (d - dn)));
        }
      }
    }
    cout << res << '\n';
  }
  return 0;
}


Measured memory_bytes: 11280
#include <bits/stdc++.h>
using namespace std;
#define ll long long int


int main(){
    string s; cin >> s;
    int q; cin >> q;
    bool flag = true;
    deque<char> v;

    for(int i=0;i<s.size();i++){
        v.push_back(s[i]);
    }


    for(int i=0; i<q; i++){
        int t; cin >> t;

        if(t == 1){
            flag = !flag;
        }else{
            int f; char c;
            cin >> f >> c;
            if(f==1){
                if(flag) v.push_front(c);
                else     v.push_back(c);
            }else{
                if(flag) v.push_back(c);
                else     v.push_front(c);
            }
        }
        }
        int v_size = v.size();
        if(flag){
            for(int i=0;i<v_size;i++){
                char cv = v.front();
                v.pop_front();
                cout << cv ;
            }
        }else{
            for(int i=0;i<v_size;i++){
                char cv = v.back();
                v.pop_back();
                cout << cv;
            }
        }
        cout << endl;
}

Measured memory_bytes: 896
l = int(input())
a = list(str(l))
n = len(a)
mod = 10**9 + 7
san = [1]
for i in range(n-1):
    san.append((san[i]*3)%mod)
ans = san[-1]
count = 1
for i in range(1,n):
    if a[i] == "1":
        count *= 2
        count %= mod
        ans += (count*san[-(i+1)])%mod
        ans %= mod
ans = (ans+count*2)%mod
print(ans)

Measured memory_bytes: 7924
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define setp(x) setprecision(x)
using namespace std;
using ull = unsigned long long;
using ll = long long;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> food(N, vector<int>(M, 0));
    for(int i = 0; i < N; i++){
        int K;
        cin >> K;
        for(int j = 0; j < K; j++){
            int like;
            cin >> like;
            food[i][like - 1] = 1;
        }
    }
    int ans = 0;
    for(int j = 0; j < M; j++){
        bool flag = true;
        for(int i = 0; i < N; i++){
            if(food[i][j] == 0) flag = false;
        }
        if(flag) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 101

int main(){
  int n, m, l, o, i, j;
  int g[N][N];
  for( i = 0; i < N; i++){
    for( j = 0; j < N; j ++){
      g[i][j] = 0;
    }}

  scanf("%d", &n);
  
  for( i = 1; i <= n; i++){
    
    scanf("%d%d", &m, &l);

    for( j = 1; j <= l; j++){

      scanf("%d", &o);  
      g[m][o] = 1;

    }
  }

  for(i = 1; i <= n; i++){

    for( j = 1; j <= n; j++){

      printf("%d",g[i][j]);
      if(j != n) printf(" ");

    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 644
n, m, x = map(int, input().split())
numlist = []
minimum = -1
for i in range(n):
    numlist.append(list(map(int, input().split())))
for i in range(1<<n):
    result = [0] * (m+1)
    for j in range(n):
        if(i>>j & 1 == 1):
            for k in range(m+1):
                result[k] += numlist[j][k]
    for k in range(m):
        if(result[k+1] < x): break
    else:
        if(minimum > result[0] or minimum == -1): minimum = result[0]
print(minimum)

Measured memory_bytes: 68448
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	bool f = 1;
	for(int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		if(x % 2 == 0) {
			if(x % 3 != 0 && x % 5 != 0) {
				f = 0;
			}
		}
	}
	if(f) {
		cout << "APPROVED" << '\n';
	} else {
		cout << "DENIED" << '\n';
	}
	return 0;
}

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

int main() {
  string s;
  int ans = 0;
  cin >> s;
  if (s[0] == '1') ans++;
  if (s[1] == '1') ans++;
  if (s[2] == '1') ans++;
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define n_max 100000

int
main(int argc, char *argv[])
{
  int n, k, a[n_max];
  scanf("%d%d", &n, &k);
  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }

  int sum = 0; int t = 0;
  while(sum < n - 1){
    sum += k - 1;
    t++;
  }

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

  return 0;
}
    


Measured memory_bytes: 512
function main(input) {
  const args = input.split('\n');
  const items1 = args[0].split(' ').map(i => parseInt(i));
  const N = items1[0] + 1;
  const X = items1[1];
  const List = args[1].split(' ').map(i => parseInt(i));

  if (List[0] > X) {
    console.log(0);
    return;
  }

  for (var i = 1; i <= N; i++) {
    var total = List.slice(0, i).reduce((x, y) => x + y, 0);
    if (total == X) {
      console.log(i + 1);
      return;
    } else if (total > X) {
      console.log(i);
      return;
    }
  }
  console.log(N);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21192
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,a,b) for(ll i=(a); i < (b); i++)
#define RFOR(i,a,b) for(ll i=(b)-1; i >= (a); i--)
#define rep(i,n) FOR(i,0,(n))
#define rrep(i,n) RFOR(i,0,(n))

int main() {
	int Q;
	cin >> Q;
	for(int q = 0; q < Q; q++) {
		ll A, B;
		cin >> A >> B;
		if(A > B) {
			swap(A, B);
		}
		// A < B;
		ll res = 0;
		res += (A-1)*2;

		ll l, r, n;
		l = A; r = B;
		n = -1;
		while(l <= r) {
			ll m = (l+r)/2;
			if(m*m < A*B) {
				n = m;
				l = m+1;
			}
			else {
				r = m-1;
			}
		}
		if(n+1) {
			res += (n-A)*2 + 1 - (n*(n+1) >= A*B);
		}
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 256
S = input()
T = input()

pos = -1
for i in range(len(S)-len(T)+1):
	#check it out
	contain = True
	for j in range(len(T)):
		if(S[i+j] != T[j] and S[i+j] != '?'):
			contain = False
			break
	if contain :
		pos = i
		
if pos == -1: print("UNRESTORABLE")
else:	
	ans = S[0:pos] + T + S[pos+len(T):]
	print(ans.replace('?','a'))


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>    // std::transform
using namespace std;

int main(int argc, char const *argv[])
{
	string W, T;
	int count = 0;
	cin >> W;
	while(cin >> T) {
	    if(T.compare("END_OF_TEXT") == 0) break;
	    transform(T.begin(),T.end(),T.begin(),::tolower);
	    if(T.compare(W) == 0) ++count;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3172
#include<stdio.h>
int main()
{
    int N,i,count=0;
    float probability;
    scanf("%d",&N);
    for(i=1;i<=N;i++)
    {
        if(i%2!=0)
        {
            count++;
        }
    }
    probability=(float)count/N;
    printf("%0.10f\n",probability);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main() {
	int L, D = 0;
	int N, X;
	int c = 1;
	scanf("%d", &N);
	scanf("%d", &X);
	
	for (int i = 0; i < N; i++) {
		scanf("%d", &L);
		D += L;
		if (D <= X) {
			c++;
		}
	}
	printf("%d", c);
}

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

int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i=0; i<N; i++) cin >> A[i];
    sort(A, A+N, greater<int>());
    int sum = 0;
    for (int i=1; i<N; i++) sum += A[i];
    if (A[0] < sum) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int a[5];
	int k;
	
	rep(i, 5)
	{
		cin >> a[i];
	}

	cin >> k;

	sort(a, a+5);

	if (a[4] - a[0] > k)
	{
		cout << ":(" << endl;
	}
	else
	{
		cout << "Yay!" << endl;
	}
	

	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	cin>>a;
	cin>>b;
	int ma=-1,mi=200;
	for(int i=0;i<a.size();i++){
		mi=min(mi,(int)a[i]);
	}
	for(int i=0;i<b.size();i++){
		ma=max(ma,(int)b[i]);
	}
	if(ma>mi){
		cout<<"Yes";
		return 0;
	}
	if(ma==mi){
		int j=0;
	for(;a[j]&&b[j]&&a[j]==b[j];j++);
	if(a[j]||b[j]=='\0'){
		cout<<"No";
		return 0;
	}else{
		cout<<"Yes";
		return 0;
	}
	}
	cout<<"No";
    return 0;
}



Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
def MAIN():
    n, m = map(int, input().split())
    li = [i for i in range(n)]
    def f(a):
        if li[a] == a:
            return a
        li[a] = f(li[a])
        return li[a]
    def f2(a, b):
        if li[a] == a:
            li[a] = b
            return
        f2(li[a], b)
        li[a] = b
    for _ in range(m):
        x, y = map(int, readline().split())
        if f(x) > f(y):
            f2(x, li[y])
        elif f(x) < f(y):
            f2(y, li[x])
    for _ in range(int(input())):
        x, y = map(int, readline().split())
        print("yes" if f(x) == f(y) else "no")
MAIN()



Measured memory_bytes: 10032
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;

VI tmp;

void dfs(int t) {
	//cout << t << endl;
	if (t > 3234566667)return;
	tmp.push_back(t);
	int a = t % 10;
	dfs(t * 10 + a);
	if (a != 0)dfs(t * 10 + a - 1);
	if (a != 9)dfs(t * 10 + a + 1);
}


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

	int K; cin >> K;
	

	REP(i, 9)dfs(i+1);
	SORT(tmp);
	cout << tmp[--K] << endl;
	//cout << tmp.size() << endl;
	//REP(i, 10)cout << tmp[i] << endl;


	return 0;
}



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

#define rep(i,j,n) for(int i=(j);i<(n);++i)
#define erep(i,j,n) for(int i=(j);i<=(n);++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	string s;
	cin >> s;
	int cou = 1;
	char t = s[0];
	rep(i, 1, s.size()) {
		if (t != s[i]) {
			t = s[i];
			cou++;
		}
	}
	cout << cou - 1 << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0;i < N;i++)
int main()
{
  int data[10];
  int sum[2];
  Rep(p,2) {
    Rep(i,10)cin >> data[i];
    sort(data, data + 10,greater<int>());
    sum[p] = accumulate(data, data + 3,0);
  }
  cout << sum[0] << " " << sum[1] << endl;
  return 0;
}

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

using namespace std;

typedef  long long int lli;

int main(){
	
	lli n,k;
	
	cin>>n>>k;
	if(n>=k){
		lli r=n%k;
//		cout<<r;
//		cout<<abs(r-k);
		if(r<=abs(r-k)){
			cout<<r;
		}
		else{
			cout<<abs(r-k);
		}
	}
	else{
		if(n<=abs(n-k)){
			cout<<n;
		}
		else{
			cout<<abs(n-k);
		}
//		cout<<min(n,abs(n-k));
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  for(int i = 1; i < n + 1; i++){
  if(i % 3 ==0){
    cout << " " << i;
  }
  else if(i % 10 == 3){
    cout << " " << i;
  }
  else if(i / 10 % 10 == 3){
    cout << " " << i;
  }
    else if(i / 100 % 10 == 3){
    cout << " " << i;
  }
    else if(i / 1000 % 10 == 3){
    cout << " " << i;
  }
  }
  cout << endl;
    
}


Measured memory_bytes: 3080
import java.util.*;
public class Main {
public static void main(String...args) {
  final Scanner sc = new Scanner(System.in);
  int N = sc.nextInt();
  int[] a = new int[N * 2];
  for(int i = 0; i < 2 * N; i++)
    a[i] = sc.nextInt();
  Arrays.sort(a);
  int ans = 0;
  for(int i = 0; i < N; i++)
    ans += a[i * 2];
  System.out.println(ans);
}
}

Measured memory_bytes: 9940
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int n;
int s[1001][1024];
int calc(int y,int x,int n){
	int a,b,c,d;
	n--;
	a=s[y-1][x-1];
	b=s[y-1][x+n];
	c=s[y+n][x-1];
	d=s[y+n][x+n];
	return d-c-b+a;
}
int main(){
	while(cin>>n,n){
		memset(s,0,sizeof(s));
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				char c;
				cin>>c;
				s[i][j] = (c=='*')+s[i-1][j]+s[i][j-1]-s[i-1][j-1];
			}
		}
		int ans=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				int lb=0,ub=n-max(i,j)+2;
				while(ub-lb>1){
					int m=(lb+ub)/2;
					if(calc(i,j,m))ub=m;
					else lb=m;
				}
				ans=max(ans,lb);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 5172
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;

using namespace std;

int main() 
{
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s == "abc") { 
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}
    



Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())

a,b,ab = 0, 0, 0

a = X
b = Y
ab = 0

m = a * A + b * B + ab * C
big = max(X,Y)
while ab // 2 <= big:
    ab += 2
    if a > 0:
        a -= 1
    if b > 0:
        b -= 1
    m = min(m, a * A + b * B + ab * C)

print(m)

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

using namespace std;

int main() {
    long long int N;
    cin >> N;
    string strings[N];
    string input;
        
    getline(cin, input);

    for (int i = 0; i < N; i++)
    {
        getline(cin, input);
        strings[i] = input;
        sort(strings[i].begin(), strings[i].end());
    }

    sort(strings, strings + N);

    long long int in_a_row = 1, pairs = 0;
    for (int i = 0; i < N - 1; i++)
    {
        if (strings[i] == strings[i + 1])
        {
            pairs += in_a_row;
            in_a_row++;
        } else {
            in_a_row = 1;
        }
    }

    cout << pairs;
}


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

int n, m;
const int MX_N = 8, MX_M = 28;
int p[MX_N];
bool connect[MX_N][MX_N] = {};

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) p[i] = i;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        connect[a - 1][b - 1] = connect[b - 1][a - 1] = true;
    }

    int count = 0;

    do {
        bool ok = true;
        for (int i = 0; i < n - 1; i++) {
            if (!connect[p[i]][p[i + 1]]) {
                ok = false;
                break;
            }
        }
        if (ok) count++;
    } while (next_permutation(p + 1, p + n));

    cout << count << endl;

    return 0;
}

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


int main()
{
	auto& in = cin;
	string s;
	in >> s;
	if (s == "SSS")
		cout << 0;
	else if (s == "SSR")
		cout << 1;
	else if (s == "SRS")
		cout << 1;
	else if (s == "SRR")
		cout << 2;
	else if (s == "RSS")
		cout << 1;
	else if (s == "RSR")
		cout << 1;
	else if (s == "RRS")
		cout << 2;
	else
		cout << 3;

	return 0;
}


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

int main()
{
  static const int STATE_GTCOUNT = 0;
  static const int STATE_LTCOUNT = 1;
  int state = STATE_GTCOUNT;
  int64_t gtCount = 0;
  int64_t ltCount = 0;
  int64_t sum = 0;

  string s;
  cin >> s;

  for (const auto& c : s)
  {
    if (c == '<')
    {
      if (state == STATE_LTCOUNT)
      {
        sum += ltCount * (ltCount - 1) / 2 + gtCount * (gtCount - 1) / 2 + max(ltCount, gtCount);

        gtCount = 0;
        ltCount = 0;
        state = STATE_GTCOUNT;
      }
      gtCount++;
    }
    else // if (c == '>')
    {
      ltCount++;
      if (state == STATE_GTCOUNT)
      {
        state = STATE_LTCOUNT;
      }
    }
  }
  sum += ltCount * (ltCount - 1) / 2 + gtCount * (gtCount - 1) / 2 + max(ltCount, gtCount);
  cout << sum << endl;

  return 0;
}


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

int main(){
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if(0 <= x-r && x+r <= w && 0 <= y-r && y+r <= h){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3076
N = int(input())
sorted_As = sorted(map(int, input().split()))
A_max = sorted_As[N-1]

dp = [True for i in range(A_max+1)]

ans = 0
for i in range(len(sorted_As)):
    a = sorted_As[i]
    
    if not dp[a]:
        continue

    if i == len(sorted_As)-1 or a != sorted_As[i+1]:
        ans += 1

    i = 1
    while a*i <= A_max:
        dp[a*i] = False
        i += 1

print(ans)


Measured memory_bytes: 32388
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define eps 1e-9
#define mp make_pair
#define MOD 1000000007
 
int n,a[55],cnt,pnt;
LL ans;
char s[2][55];
 
int main() {
	scanf("%d",&n);
	scanf("%s",s[0]);
	scanf("%s",s[1]);
	cnt=0;
	pnt=0;
	while (pnt<n) {
		if (s[0][pnt]==s[1][pnt]) {
			pnt+=1;
			a[cnt]=1;
			++cnt;
		}
		else {
			pnt+=2;
			a[cnt]=2;
			++cnt;
		}
	}
	if (a[0]==1) ans=3;
	else ans=6;
	FOR(i,1,cnt) {
		if (a[i-1]==1 && a[i]==1) ans=ans*2%MOD;
		else if (a[i-1]==1 && a[i]==2) ans=ans*2%MOD;
		else if (a[i-1]==2 && a[i]==1) ans=ans*1%MOD;
		else if (a[i-1]==2 && a[i]==2) ans=ans*3%MOD;
	}
	printf("%lld\n",(LL)ans);
return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int A, B; cin >> A >> B;
  string s; cin >> s;
  bool ok = true;
  for (int i = 0; i < A; i++) {
    if (!('0' <= s[i] && s[i] <= '9')) ok = false;
  }
  if (s[A] != '-') ok = false;
  for (int i = A + 1; i < A+B+1; i++) {
    if (!('0' <= s[i] && s[i] <= '9')) ok = false;
  }

  cout << (ok ? "Yes":"No") << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cina(a, n) for (int i = 0; i < n; ++i){ cin >> a[i]; }
#define ll long long
#define ld long double

using namespace std;

int main () {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll n, a, b;
	cin >> n >> a >> b;
	ll blue = (n / (a + b)) * a;
	n %= (a+b);
	blue += min(a, n);
	cout << blue;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int d;
	cin >> d;
	if (d ==25) {
		cout << "Christmas" << endl;
	}
	if (d ==24) {
		cout << "Christmas Eve" << endl;
	}
	if (d ==23) {
		cout << "Christmas Eve Eve" << endl;
	}
	if (d ==22) {
		cout << "Christmas Eve Eve Eve" << endl;
	}
	return 0;
}


Measured memory_bytes: 384
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N,K=map(int,input().split())
A=[int(i) for i in input().split()]
gcd = gcd_list(A)

if K > max(A):
    print("IMPOSSIBLE")
elif K % gcd !=0:
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")

Measured memory_bytes: 16276
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<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;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll N;
    cin >> N;
    usleep(1999);
    if(N % 2 == 0)cout << N << endl;
    else cout << 2 * N << endl;
}

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

//-std=c++11
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define LL long long
#define FI ios_base::sync_with_stdio(false); cin.tie(NULL);
#define PREC cout << setprecision(10) << fixed;

const int MOD = 998244353;
const int INF = 1e9 + 9;
const int MX = 2e5 + 5;

#define int long long

int mod10[MX];
int dig[10][MX];
void calc() {
	for(int d=1;d<=9;d++) {
		int curr = d;
		dig[d][1] = curr;
		for(int i=2;i<MX;i++) {
			curr = ((curr * 10)%MOD + d)%MOD;
			dig[d][i] = curr;
		}
	}

	mod10[0] = 1;
	for(int i=1;i<MX;i++) {
		mod10[i] = (mod10[i-1] * 10)%MOD;
	}
}

struct SegTree {
	vector<int> tree;
	vector<int> lazy;

	SegTree(int n) {
		tree.resize(4*n, 0);
		lazy.resize(4*n, -1);
	}

	int combine(int x, int y, int l1, int l2) {
		int ret = 0;
		ret = ((x * mod10[l2])%MOD + y)%MOD;
		return  ret;
	}

	void propagate(int node, int st, int en) {
		if(lazy[node] == -1) return;

		tree[node] = dig[lazy[node]][en - st + 1];

		if(st != en) {
			lazy[2*node] = lazy[node];
			lazy[2*node + 1] = lazy[node];
		}

		lazy[node] = -1; 
	}

	void update(int node, int st, int en, int i, int j, int d) {
		propagate(node, st, en);
		if(i > en || j < st) return;
		if(i <= st && en <= j) {
			//lazy update
			lazy[node] = d;
			propagate(node, st, en);
			return;
		}
		int mid = (st + en)/2;
		update(2*node, st, mid, i, j, d);
		update(2*node + 1, mid + 1, en, i, j, d);
		tree[node] = combine(tree[2*node], tree[2*node + 1], mid - st + 1, en - (mid + 1) + 1);
	}

	int query() {
		return tree[1];
	}

	pair<int, int> query(int node, int st, int en, int i, int j) {
		if(i > en || j < st) return {0, 0};
		if(i <= st && en <= j) {
			return {tree[node], en - st  + 1};
		}
		int mid = (st + en)/2;
		pair<int,int> left = query(2*node, st, mid, i, j);
		pair<int,int> right = query(2*node + 1, mid + 1, en, i, j);
		int val = combine(left.first, right.first, left.second, right.second);
		int len = left.second + right.second;
		return {val, len};
	}
};

#undef int 
int main() {
	#define int long long
	calc();

	int n,q;
	cin >> n >> q;

	SegTree seg(n);
	seg.update(1, 0, n-1, 0, n-1, 1);

	int l,r,d;
	while(q--) {
		cin >> l >> r >> d;
		l--;r--;
		seg.update(1, 0, n-1, l, r, d);
		int ans = seg.query();
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 31496
#include <stdio.h>

int main()
{
    char s[10];

    scanf("%s",s);

    if(s[0] ==s[1] || s[1] == s[2] || s[2] == s[3] )
    printf("Bad\n");

    else
    {
        
        printf("Good\n");
    }
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a=1;cin>>n;
  vector<int>h(n);
  for(int i=0;i<n;i++)cin>>h.at(i);
  if(n!=1){
    for(int i=1;i<n;i++){
      int c=0;
      for(int j=0;j<i;j++){
        if(h.at(j)>h.at(i))c++;
      }
      if(c==0)a++;
    }
  }
  cout<<a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll lg=31;
const ll N=1e5+5;
const ll INF=3e18;
const ll mod = 1e9 + 7;
const double PI = 3.14159265358979323846;

#define f first
#define s second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repp(i, a, b) for(int i = a; i > (b); --i)
#define sz(x) (int)(x).size()
#define pb push_back
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main() {
	FASTIO;
	ll n, res = 0, sum = 0, sub;
	cin >> n;
	vl v(n);
	rep(i, 0, n) {
	    cin >> v[i];
	    sum += v[i];
	}
	sub = v[0];
	vl s(n - 1);
	for (int i = 0; i < n - 1; i++) {
	    s[i] = sum - sub;
	    sub += v[i + 1];
	}
	for (int i = 0; i < n - 1; i++) {
	    res += ((s[i] % mod) * v[i]) % mod;
	    res %= mod;
	}
	res = res % mod;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 6344
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
#define yes cout<<"Yes";
#define no cout<<"No";
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
int main(){
  int n;
  cin>>n;
  vector<ll> l(n);
  rep(i,n) cin>>l[i];
  int count=0;
  sort(all(l));
  rep(i,n-2){
    rep2(j,i+1,n-1){
      rep2(k,j+1,n){
        if(l[i]!=l[j]&&l[j]!=l[k]&&(l[i]+l[j]>l[k])) count++;
      }
    }
  }
  cout<<count;
return 0;
}


Measured memory_bytes: 3628
chokkaku,eikaku,donkaku = 0,0,0
while 1:
    abc = sorted((map(int,input().split())))
    a,b,c = abc[0],abc[1],abc[2]
    if a+b <= c:
        print(chokkaku+eikaku+donkaku,chokkaku,eikaku,donkaku)
        break
    elif a**2+b**2 > c**2:
        eikaku += 1
    elif a**2+b**2 < c**2:
        donkaku += 1
    else:
        chokkaku += 1


Measured memory_bytes: 5604
#include<iostream>
using namespace std;
int main()
{
	int n,k;
	int t;
	cin>>n>>k;
	long long sum=0;
	for(int i=1;i<=k;i++){
			int j=k-(i%k);
			long long b=(n-j+k)/k;
			for(t=k-(i%k);t<=n;t+=k)
				if((t+j)%k==0){
					long long d=(n-t+k)/k;
					sum+=b*d;
					break;
				}
		}
		sum*=(n/k);
	for(int i=1;i<=n%k;i++){
			int j=k-(i%k);
			long long b=(n-j+k)/k;
			for(t=k-(i%k);t<=n;t+=k)
				if((t+j)%k==0){
					long long d=(n-t+k)/k;
					sum+=b*d;
					break;
				}
		}
	cout<<sum<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int N;
    int W;
    cin >> N >> W;

    int v[100];
    int w[100];
    for(int i=0;i<N;i++){
        cin >> v[i] >> w[i];
    }

    int dp[11000];
    
    for(int i=0;i<=W;i++){
        for(int j=0;j<N;j++){
            if(i >= w[j]){ 
                dp[i] = max(dp[i], dp[i-w[j]]+v[j]);
            }
        }
    }

    cout << dp[W] << endl;
    return 0;
}


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

int main() {
  int N, M, A, B = 1e9+7;
  scanf("%d %d", &N,&M);

  vector<int> vec(N + 1, -1);
  vec.at(0) = 1;
  vec.at(1) = 1;

  for (int i = 0; i < M; i++) {
    scanf("%d", &A);
    vec.at(A) = 0;
  }

  for (int i = 2; i < N + 1; i++) {
    if (vec.at(i) != 0) vec.at(i) = (vec.at(i - 2) + vec.at(i - 1)) % B;
  }

  printf("%d\n",vec.at(N));
}

Measured memory_bytes: 640
import sys
stdin = sys.stdin
def ls(): return stdin.readline()

S = ls()
num_1, num_0 = 0, 0

for s in S:

    if s == '1':
        num_1 += 1
    elif s == '0':
        num_0 += 1
print( 2 * min(num_1, num_0) )

Measured memory_bytes: 3188
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class AMultipleOf2AndN {
public:
	void solve(istream& in, ostream& out) {
        ll n; in >> n;
        if(n % 2 == 0) out << n << endl;
        else out << n * 2 << endl;
	}
};

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

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<50);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

void solve(){
	ll n,k,s;
  cin>>n>>k>>s;
  ll index=0;
  ll inf=pow(10,9);
  if(s==inf){
    for(;index<k;index++){
      cout<<inf<<" ";
    }
    for(;index<n;index++){
      cout<<1<<" ";
    }
    cout<<endl;
    return;
  }

  for(;index<k;index++){
    cout<<s<<" ";
  }
  for(;index<n;index++){
    cout<<inf<<" ";
  }
  cout<<endl;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	solve();
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

ll N,M;
ll K;
int main(){
  cin >> N >> M >> K;
  rep(i,N+1){
    ll k_count = 0;
    ll t = N-i*2;
    k_count = i*M;
    rep(j,M+1){
      if(k_count + t*j == K){
        cout << "Yes" << endl;
        return 0;
      }
    }

  }
  cout << "No" << endl;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define fine cout<<"fine"<<endl;
#define ll long long int
#define pb push_back
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
const ll inf=(ll)2e18;
const int mod=1e9+7;
bool overflow(ll a,ll b){
    if (a <= (inf+b-1)/b) return false;
    return true;
}
ll fact[100005],inv[100005];
ll power(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res=(res*x)%mod;
        y=y>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll ncr(ll n,ll r){
    if(r>n)
        return 0;
    ll res=(fact[n]*inv[r])%mod;
    res=(res*inv[n-r])%mod;
    return res;
}
int main(){
FASTIO;
ll i;
fact[0]=1,inv[0]=1;
for(i=1;i<=100000;i++){
    fact[i]=(fact[i-1]*i)%mod;
}
for(i=1;i<=100000;i++){
    inv[i]=power(fact[i],mod-2);
}
ll n,k,ans=0;
cin>>n>>k;
ll a[n];
for(i=0;i<n;i++){
    cin>>a[i];
}
sort(a,a+n);
for(i=0;i<n;i++){
    ll time=ncr(n-i-1,k-1);
    ans=(ans-(time*a[i])%mod+mod)%mod;
    time=ncr(i,k-1);
    ans=(ans+(time*a[i])%mod+mod)%mod;
}
cout<<ans<<endl;
}


Measured memory_bytes: 2560