akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

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 FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

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

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

const int N_MAX = 100010;
ll Per[N_MAX] = {}; // n!
ll Per_inv[N_MAX] = {}; //(n!)^-1

ll nCr(ll n, ll r){
    if(n<r) return 0;
 
    if (n == r || r == 0)
        return 1;
    else
        return Per[n] * Per_inv[n-r] % mod * Per_inv[r] % mod;  
}
 
// a^b mod p
ll mod_pow(ll a, ll b){
    if(b==0) return 1;
 
    // 肩が奇数
    if(b%2==1){
        return a * mod_pow(a, b-1) % mod;
    }
    else{
        return mod_pow(a*a % mod, b/2) % mod;
    }
}

void prepare_nCr(){
    // nCr高速化準備
    Per[1] = 1;
    FOR(i, 2, N_MAX){
        Per[i] = i * Per[i-1] % mod;
    }
    Per_inv[1] = 1;
    FOR(i, 2, N_MAX){
        Per_inv[i] = mod_pow(Per[i], 1000000005);
    }
}

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

    prepare_nCr();

    // input
    ll N, K;
    cin >> N >> K;

    FOR(i, 1, K+1){
        ll a = nCr(N-K+1, i) % mod;

        if(i==1){
            p(a);
            continue;
        }
        
        ll rest = K-i;
        if(rest==0){
            p(a);
            continue;
        }

        // 分割数
        ll b = Per[K-1] * Per_inv[K-i] % mod * Per_inv[i-1] % mod;

        ll c = a * b % mod;
        p(c);
    }

    return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec A(N-1), B(N-1);
    vector<vector<ll>> G(N+1);
    REP(i,0,N-1) {
        cin >> A[i] >> B[i];
        G[A[i]].pb(B[i]);
        G[B[i]].pb(A[i]);
    }
    G[0].pb(1);
    G[1].pb(0);

    queue<ll> Q;
    vector<bool> F(N+1, false);
    vec P(N+1);
    map<pll,ll> E;
    ll K = 0;
    Q.push(1);
    F[0] = true;
    F[1] = true;
    P[1] = 0;
    while(!Q.empty()) {
        ll v = Q.front(); Q.pop();
        ll c = 1, pc = E[{P[v], v}];
        FORR(nv,G[v]) {
            if(!F[nv]) {
                if(c == pc) ++c;
                E[{v, nv}] = c;
                E[{nv, v}] = c;
                K = MAX(K,c);
                Q.push(nv);
                F[nv] = true;
                P[nv] = v;
                ++c;
            }
        }
    }

    PR(K);
    REP(i,0,N-1) cout << E[{A[i],B[i]}] << endl;

    return 0;
}

/*



*/

Measured memory_bytes: 24020
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	for(int i=1;i<=h;i++){for(int j=1;j<=w;j++)
	{
		if((j>a&&i<=b)||(i>b&&j<=a)) putchar('1');
		else putchar('0');
	}putchar('\n');}
}

Measured memory_bytes: 3612
//author: Harsh :)
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define maxN 100007
using namespace std;
int main(){
  fastio;
  ll n=0;
  cin>>n;
  map<string,ll>mp;
  for(ll i=0;i<n;++i){
    string s;
    cin>>s;
    ++mp[s];
  }
  ll maxm=INT_MIN;
  for(auto i:mp){
    maxm=max(i.S,maxm);
  }

  set<string>st;
  for(auto i:mp){
    if(i.S==maxm)
      st.insert(i.F);
  }
  for(auto i:st) cout<<i<<"\n";
  return 0;
}


Measured memory_bytes: 34876
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	string rev_N = N;
	reverse(rev_N.begin(), rev_N.end());

	if (N == rev_N) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define int long long int 
int32_t main() {
	int s;
	cin>>s;
	int inf = 1e9;
	int x = (inf-s%inf)%inf;
	int y = (s+x)/inf;
	cout<<"0 0 "<<inf<<" 1 "<<x<<" "<<y;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<tuple>
#include<vector>
#include<map>
using namespace std;

static const int N_MAX = 110, NUL = -1;

int main(void){
  //入力
  int N;
  long long int x[N_MAX], y[N_MAX], h[N_MAX];
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> x[i] >> y[i] >> h[i];
  }
  long long int cx, cy, ch;
  bool flag = true;
  //ピラミッドの中心座標を推定する。0-100をgreedyに調べよう
  for(cx = 0; cx <= 100; cx++){
    for(cy = 0; cy <= 100; cy++){
      flag = true;
      long long int exh[N_MAX];
      long long int minh = 9999999999;
      for(int i = 0; i < N; i++){
        exh[i] = NUL;
      }
      //各kについてのx[k],y[k]から求まるh[k]が全てが一致するかで判定
      //0の時は不等式条件としてminhを更新する。
      for(int i = 0; i < N; i++){
        if(h[i] != 0){
          exh[i] = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
        }
        else{
          long long int temph = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
          if(minh > temph) minh = temph;
        }
      }
      //不等式条件を満たす範囲で，h[k]が全て一致するかを調べる。
      long long int tot_exh = NUL;
      for(int i = 0; i < N; i++){
        //tot_exhが初めての更新：代入
        if(exh[i] != NUL && tot_exh == NUL) tot_exh = exh[i];
        //exhが等式条件で，tot_exhが存在する時:tot_exhと一致しないならfalse
        else if(exh[i] != NUL && tot_exh != NUL){
          if(tot_exh != exh[i]) flag = false;
        }
      }
      //最後に不等式条件を満たすか調べる
      if(tot_exh > minh) flag = false;
      if(flag){
        ch = tot_exh;
        break;
      }
    }
    if(flag)break;
  }
  //出力
  cout << cx << " " << cy << " " << ch << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <stack>
using namespace std;

int d[100];
int f[100];
int map[100][100];
int tim;
int n;
stack<int> s;
void visit(int);

int main(){
	tim=0;
	int i,j,k,u,v;
	for(i=0;i<100;i++) d[i]=-1; //?????¢??\
	for(i=0;i<100;i++) f[i]=-1;
	cin >> n;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			map[i][j]=-1;
		}
	}
	for(i=0;i<n;i++){
		cin>>u>>k;
		for(j=0;j<k;j++){
			cin>>v;
			map[u-1][v-1]=1; //?????????????????????????????????????????????
		}
	}
	 //????????¢?????¢?´¢
	for(i=0;i<n;i++){
		if(d[i]==-1) visit(i);
	}
	for(i=0;i<n;i++) cout<< i+1 <<" "<<d[i]<<" "<<f[i]<<endl;
	return 0;
}

void visit(int a){
	s.push(a); //?????¨??°
	if(d[a]==-1){
		d[a]=++tim;
	}
	for(int i=0;i<n;i++){
		if(map[a][i]==1 && d[i]==-1){ //?????¢?´¢
			visit(i);
		}
	}
	s.pop();
	f[a]=++tim;
}

Measured memory_bytes: 1240
INCREASE = '<'

s = gets.chomp.split('')
n = s.length + 1
a = Array.new(n, nil)
prev = ''
top_index = nil
s.each_with_index do |t, i|
  if t == prev
    if t == INCREASE
      a[i+1] = a[i]+1
    end
  else
    if t == INCREASE
      a[i] = 0
      a[i+1] = 1
      if top_index
        (top_index..i-1).reverse_each do |j|
          a[j] = a[j+1] + 1
        end
        if top_index > 0
          if a[top_index - 1] == a[top_index]
            a[top_index] = a[top_index] + 1
          elsif a[top_index - 1] > a[top_index]
            a[top_index] = a[top_index-1] + 1
          end
        end
      end
    else
      top_index = i.zero? ? 0 : i
    end
  end
  if i == n - 2 && t != INCREASE
    a[i+1] = 0
    if top_index
      (top_index..i).reverse_each do |j|
        a[j] = a[j+1] + 1
      end
    end
  end
  prev = t
end
puts a.sum

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

using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)for(auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); blockTime.second;debug("%s: %.5lf s\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()/1000.0), blockTime.second = false)

template <typename T>std::string NumberToString ( T Number ){std::ostringstream ss; ss << Number;return ss.str(); } // Usages NumberToString(3)
template <typename T>T StringToNumber ( const string &Text ){istringstream ss(Text);T result;return ss >> result ? result : 0;} // StringToNumber<int>("3")
template<class T> inline constexpr T _pow_(const T base, unsigned const exponent){ return (exponent == 0) ? 1 : (base * pow(base, exponent-1));} // _pow_(2,5)
string StrCpy(string str, long long int start, long long int end){string temp = "";for(long long int i=start; i<=end; i++){temp += str[i];} return temp;} // StrCoy(abcd,1,2)

#define ull unsigned long long int
#define ll long long int 
#define gcd(a, b)  __gcd(a, b)
#define lcm(a, b)  ((a*b)/gcd(a, b))


int solve(){

    ll X;

    cin >> X;

    for(ll i=-1000; i<=1000; i++){
        for(ll j=-1000; j<=1000; j++)
            if(_pow_(i,5) - _pow_(j,5) == X){
                cout << i << " " << j << endl;
                return 0;
            }
    }
    
    return 0;
}

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

    time__("programm time"){
        solve();
	}
    return 0;

}

Measured memory_bytes: 4260
import itertools, operator
def combinations_with_replacement_counts(n, r):
    size = n + r - 1
    for indices in itertools.combinations(range(size), n-1):
        starts = [0] + [index+1 for index in indices]
        stops = indices + (size,)
        yield tuple(map(operator.sub, stops, starts))
        
a = (input())
ok = dict()
aller = list(range(len(a)))
out = 0
if len(a) <= 2:
	print(0)
if len(a) >= 3:
	num = int(a)
	for times in range(len(a) - 3):
		no = list(range(times + 3))
		for i in combinations_with_replacement_counts(3, times):
			for j in itertools.combinations(no, i[0] + 1):
				for k in itertools.combinations([ele for ele in no if ele not in j], i[1] +1):
					for l in itertools.combinations([ele for ele in no if ele not in j and ele not in k], i[2] + 1):
						out += 1
					
	for i in combinations_with_replacement_counts(3, len(a) - 3):
		for j in itertools.combinations(aller, i[0] + 1):
			for k in itertools.combinations([ele for ele in aller if ele not in j], i[1] +1):
				for l in itertools.combinations([ele for ele in aller if ele not in j and ele not in k], i[2] + 1):
					number = sum([3*10**ele for ele in j]) +sum([5*10**ele for ele in k]) + sum([7*10**ele for ele in l])
					if number <= num:
						out += 1
	print(out)
	

Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

int main(){
    ll a,b,k;
    cin>>a>>b>>k;
    for(int i=0;i<k;i++){
        if(i%2==0){
            if(a%2==1) a--;
            a/=2;
            b += a;
        }
        else{
            if(b%2==1) b--;
            b/=2;
            a += b;
        }
    }
    cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
from collections import deque
d = deque()
d.extend(list(input()))
q = int(input())
z = 0
F = ""
R = ""
for i in range(q):
    a = tuple(input().split())
    if a[0] == "1":
        z += 1
        z %= 2
    else:
        if (int(a[1]) + z) % 2 == 0:
            d.append(a[2])
        else:
            d.appendleft(a[2])

ans = "".join(d)
if z % 2 == 0:
    print(ans)
else:
    print(ans[::-1])


Measured memory_bytes: 76136
#include<stdio.h>
long long gcd(long long a,long long b){  
    int temp;  
    if(a < b){  
      temp = a;  
      a = b;  
      b = temp;  
    }    
    if(a%b == 0)
	{  
        return b;    
    }else
	{    
        return gcd(b,a%b);    
    }    
} 
int main()
{
	int n;
	long long  gcd(long long a,long long b);
    long long  c[109],sum;
	while(~scanf("%d",&n))
	{
		sum=0;
		for(int i=0;i<n;i++)
		scanf("%lld",&c[i]);
		while(n==1)
		{
			printf("%lld\n",c[0]);
			return 0;
		}
			for(int i=0;i<n-1;i++)
			{	
				sum=(c[i]/gcd(c[i],c[i+1]))*c[i+1];
				c[i+1]=sum;
			}
			printf("%lld\n",sum);
		
	}
}

Measured memory_bytes: 128
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define print2(x, y) cout << (x) << ' ' << (y) << '\n'
#define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n'
#define printn(v) rep(i, (v).size() - 1) cout << (v)[i] << ' '; cout << (v)[n - 1] << '\n';
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define debug2(x, y) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

// End of template.

int64 gcd(int64 a, int64 b) {
  if(a < b) return gcd(b, a);
  int64 r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
    cout << fixed << setprecision(15);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int64 a, b;
    cin >> a >> b;

    int64 g = gcd(a, b);
    int64 gf = g;
    int64 sqrtg = sqrt(g);
    debug(g);

    unordered_set<int64> s;
    s.insert(1);
    while (g % 2 == 0) {s.insert(2); g /= 2;}
    for (int i = 3; i < sqrtg + 3 && g > 1; i += 2) {
        while (g % i == 0) {
            s.insert(i);
            g /= i;
        }
    }

    s.insert(g);
    
    print(s.size());



    return 0;
}



Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;
 


public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);

    String str = sc.nextStr();
    String str2 = sc.nextStr();
    String str3 = sc.nextStr();

    System.out.print("A");
    System.out.print(str2.charAt(0));
    System.out.print("C");
 

  }
 
//nextChar を追加したよ！

//System.out.printf("? %d %d\n", i, j);

  
// LinkedList<Integer>[] setsu = new LinkedList[n];
// for(int i = 0; i < n; i++){
//   setsu[i] = new LinkedList<Integer>();
// } 

 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;

      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }

      public char nextChar() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        char ret;
        do{
          ret = (char)c;
          c = next();
        }while(!isSpaceChar(c));
        return ret;
      }

      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

Measured memory_bytes: 7892
while 1:
    try:
        a, b, c, d, e, f = map(float, raw_input().split())
        matrix = [[a, b, c], [d, e, f]]
        for i in range(2):
            tmp = matrix[i][i]
            for j in range(3):
                matrix[i][j] = matrix[i][j] / tmp
            for j in range(2):
                if i == j:
                    continue
                else:
                    a = matrix[j][i]
                    for k in range(i, 3):
                        matrix[j][k] = matrix[j][k] - a * matrix[i][k]
        print "%.3f %.3f" % (matrix[0][2], matrix[1][2])
    except:
        break

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

int main(){
	int N;
	cin >> N;
	vector<pair<long long,long long>> BA(N);
	for(int i=0;i<N;i++){
		long long A,B;
		cin >> A >> B;
		BA[i].first=B;
		BA[i].second=A;
	}
	sort(BA.begin(),BA.end());
	long long sum=0;
	for(int i=0;i<N;i++){
		sum+=BA[i].second;
		if(sum>BA[i].first){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3328
//varun
#include <stdio.h>

 int main(void){
 int a, b, c;

 scanf("%d%d%d", &a, &b, &c);

 int ispoor = 0;
 if (a == b && b != c) ispoor = 1;
 if (b == c && c != a) ispoor = 1;
 if (c == a && a != b) ispoor = 1;

 if (ispoor) {
 puts("Yes");
 } else {
 puts("No");
 }

 return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, m;
    cin >> n >> m;
    vi a(m);
    rep(i, m) cin >> a[i];
    int sum = 0;
    rep(i, m) sum += a[i];
    int ans = n - sum;
    cout << max(ans, -1) << endl;
    return 0;
}


Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
    int x=0,f=1;char ch =getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return x*f;
}
#define y1 wanzxy
#define y2 dwwnccjb
int x1,y1,x2,y2;
main(){
    x1=read();y1=read();x2=read();y2=read();
    int dx=x2-x1,dy=y2-y1;
    printf("%lld %lld %lld %lld\n",x2-dy,y2+dx,x1-dy,y1+dx);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define MOD 1000000007
#define T true
#define F false

using namespace std;

int main(void) {
	int num, y = F, i = 1;
	long long ans = 3;
	string s;
	cin >> num >> s >> s;
	if (s[0] == s[1]) {
		y = T;
		ans = 6;
		i = 2;
	}
	for (; i < num - 1; i++) {
		if (y) {
			if (s[i] == s[i + 1]) {
				ans *= 3;
				ans %= MOD;
				i++;
			}
			else
				y = F;
		}
		else {
			if (s[i] == s[i + 1]) {
				y = T;
				i++;
			}
			ans <<= 1;
			ans %= MOD;
		}
	}
	if (num > 1 && y == F) {
		ans <<= 1;
		ans %= MOD;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int N;
    cin >> N;
    vector<pair<ll, ll>> v(N);
    for (auto &&i : v) {
        cin >> i.first >> i.second;
    }
    reverse(ALL(v));
    ll ans = 0;
    for (auto &&i : v) {
        ll x = ans + i.first;
        ll y = ((x + i.second - 1) / i.second) * i.second;
        ans += y - x;
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int n, m, q;
vector<vector<int>> suret;

void make_ret(vector<int> ary){
    if(ary.size() == n){
        suret.push_back(ary);
    }
    else if(ary.size() < n){
        int start = 1;
        if(!ary.empty())start = ary.back();

        for(int i = start; i <= m; ++i){
            vector<int> cp = ary;
            cp.push_back(i);
            make_ret(cp);
        }
    }
}

int main(){
    cin >> n >> m >> q;

    int a[q], b[q], c[q];
    ll d[q];
    rep(i, q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--, b[i]--;
    }

    vector<int> inp;
    make_ret(inp);

    ll ans = 0;

    rep(i, suret.size()){
        ll score = 0;
        rep(j, q){
            int res = suret[i][b[j]] - suret[i][a[j]];
            if(res == c[j])score += d[j];
        }
        ans = max(ans, score);
    }

    cout << ans << endl;
}

Measured memory_bytes: 9776
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main()
{
  long long a, b, c, X, Y;
  int D, G;
//  char s[101]={};
//  char s_temp[101]={};
  char t[101]={};
//  char s[10000000000000000001]={};
  char s[101]={};
  int len=0;
  int N, M;
  int A[20000]={};
  int B[20000]={};
  int C[20000]={};
  int i,j,k;
  int flag=0;
  int tmp=0;
  int min=101;
  int cnt=0;
  int max=0;
  int ans=0;

//  long cnt =0;
  long long A_temp;
//    int k=0;

  scanf("%s %d", s, &b);
//  printf("%d %d\n",D,G);

//  for(i=0;i<D;i++){
//    scanf("%d %d", &A[i], &B[i]);
//    printf("%d %d", A[i], B[i]);
//  }

for(i=0;i<b+1;i++){
  if(s[i]=='1'){
    if(i==(b-1)){
      printf("1\n");
      return 0;
    }
  }
  else {
      printf("%c\n", s[i]);
    return 0;
  }

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


Measured memory_bytes: 128
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());

        int b[] = new int[m];
        for(int i = 0; i < m; i++){
            b[i] = Integer.parseInt(sc.next());
        }

        int a[][] = new int[n][m];

        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                a[i][j] = Integer.parseInt(sc.next());
            }
        }

        int sum = 0;
        int cnt = 0;

        for (int i = 0; i < n; i++) {
            sum = 0;
            for (int j = 0; j < m; j++) {
                sum += a[i][j] * b[j];
            }
            if(sum + c > 0){
                cnt ++;
            }
        }

        System.out.println(cnt);
    }
}

Measured memory_bytes: 23636
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	var p int

	fmt.Scan(&n)
	fmt.Scan(&p)

	if n == 1 {
		fmt.Println(p)
		return
	}

	result := p
	end := int(math.Pow(float64(p), float64(1.0)/float64(n)))
	for i := 1; i <= end; i++ {
		pow := int(math.Floor((math.Pow(float64(i), float64(n)))))
		if (p % pow) == 0 {
			result = i
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 512
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>
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;
}

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define llINF (1LL<<60)
#define mINF -1e9
#define mllINF -(1LL<<60)
#define endl "\n"
#define CONT continue
#define BRK break
#define modulo(n, m) (((n)%(m)+(m))%m)

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
using vs = std::vector<string>;
using Mi = map<int,int>;
using Mll = map<ll,ll>;
using UMi = unordered_map<int,int>;
using UMll = unordered_map<ll,ll>;
using Pi = pair<int,int>;
using Pll = pair<ll,ll>;
using vPi = vector<Pi>;
using vPll = vector<Pll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using pqgi = priority_queue<int,vector<int>,greater<int>>;
using pqsi = priority_queue<int,vector<int>,less<int>>;
using pqgll = priority_queue<int,vector<int>,greater<int>>;
using pssll = priority_queue<int,vector<int>,less<int>>;
template<class T>
using vec = vector<T>;
#define int long long



int L,R;
//here begins your code
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> L >> R;
  int ans = llINF;
  for(int i = L; i <= R && i < L + 2019; i++){
  	for(int j = i + 1; j <= R && j < i + 2019; j++){
  		chmin(ans,(i * j % 2019));
  	}
  }
  cout << ans << endl;
  //check types
  //do not eb if you resize
  //resize before you access by idx
  return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
    // Your code here!
    int N;
    double ans,A = 0.0;
    cin>>N;
    for (int i=1;i<=N;i++){
        cin>>A;
        ans+=1.0/A;
    }
    ans=1.0/ans;
    cout << setprecision(14) << ans <<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>

using namespace std;

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

#define pb push_back
#define fs first
#define sc second
#define openfile {freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}
#define debug 0

struct card
{
	char x, y;

	bool operator > (const card &a)
	{
		if (y != a.y)
		{
			if (a.y == 'S' && (y == 'H' || y == 'D' || y == 'C')) return true;
			if (a.y == 'H' && (y == 'D' || y == 'C')) return true;
			if (a.y == 'D' && y == 'C') return true;
			return false;
		}
		if (a.x <= '9' && x > a.x) return true;
		if (a.x == 'T' && (x == 'J' || x == 'Q' || x == 'K' || x == 'A')) return true;
		if (a.x == 'J' && (x == 'Q' || x == 'K' || x == 'A')) return true;
		if (a.x == 'Q' && (x == 'K' || x == 'A')) return true;
		if (a.x == 'K' && x == 'A') return true;
		return false;
	}
};

card a[5][20];
char trumph;

void inputFile()
{
	for (int k = 1; k <= 4; k++)
	for (int i = 1; i <= 13; i++)
	{
		char x;
		scanf("%c%c%c", &a[k][i].x, &a[k][i].y, &x);
	}
}

void solve()
{
	int turn = 1;
	int EW = 0, NS = 0;
	for (int i = 1; i <= 13; i++)
	{
		card maxx = a[1][i];
		int x = 1;
		for (int j = 2; j <= 4; j++)
			if (a[j][i].y == trumph)
			{
				if (maxx.y != trumph || a[j][i] > maxx)
				{
					maxx = a[j][i];
					x = j;
				}
			}
		if (maxx.y == trumph)
		{
			if (x == 1 || x == 3) NS++;
			else EW++;
			turn = x;
			continue;
		}

		maxx = a[turn][i];
		x = turn;
		for (int j = 1; j <= 4; j++)
			if (j != turn && a[j][i].y == a[turn][i].y && a[j][i] > maxx)
			{
				maxx = a[j][i];
				x = j;
			}
		if (x == 1 || x == 3) NS++;
		else EW++;
		turn = x;
	}
	if (EW > NS) printf("EW %d\n", EW-6);
	else printf("NS %d\n", NS-6);
}

int main()
{
   if (debug) openfile;

   while (scanf("%c\n", &trumph) && trumph != '#')
   {
		inputFile();
		solve();
   }

   return 0;
}

Measured memory_bytes: 1140
def resolve():
    from scipy.sparse.csgraph import floyd_warshall
    import numpy as np
    import sys
    input = sys.stdin.readline
    n, m, l = map(int, input().split())
    inf = 10 ** 20
    ar = np.zeros((n, n))
    for _ in range(m):
        a, b, c = map(int, input().split())
        ar[a - 1, b - 1] = c
        ar[b - 1, a - 1] = c
    x = floyd_warshall(ar)
    br = np.zeros((n, n))
    for i in range(n):
        for j in range(i + 1, n):
            if x[i, j] <= l:
                br[i, j] = 1
                br[j, i] = 1
    y = floyd_warshall(br)
    q = int(input())
    for _ in range(q):
        s, t = map(int, input().split())
        p = y[s - 1, t - 1]
        print(int(p) - 1 if p < inf else -1)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 26152
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);

  int a, b;
  int ans = 0;

  cin >> a >> b;

  for(int i=a;i<=b;i++){
    if((i/10000) == (i%10) && ((i/1000)%10) == ((i/10)%10))ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[200000];
int main(){
    int n,index;
    cin >> n;
    for(int i=0;i<n;i++) cin >> a[i];
    index = n-1;
    while(index >= 1){
        cout << a[index] << " ";
        index -= 2;
    }
    cout << a[0] << " ";
    index = 2-n%2;
    while(index < n-1){
        cout << a[index] << " ";
        index += 2;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 2944
n,m=list(map(int,input().split()))
mod=10**9+7

if abs(n-m)>1:
    print(0)
    exit(0)

if abs(n-m)==1:
    ans=1
else:
    ans=2

while n>0:
    ans*=n
    ans%=mod
    n-=1

while m>0:
    ans*=m
    ans%=mod
    m-=1

print(ans)

Measured memory_bytes: 63788
from collections import deque
s = input()
Q = int(input())
s = deque([s])
rev = 1
for i in range(Q):
    tmp = list(input().split())
    if len(tmp)==1:
        rev *= -1
    else:
        f,c = tmp[1], tmp[2]
        if rev > 0:
            if f=='1':
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f=='1':
                s.append(c)
            else:
                s.appendleft(c)
s = ''.join(list(s))
print(s if rev > 0 else s[::-1])

Measured memory_bytes: 64480
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

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

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += a[i].second % 2 != i % 2;
    }

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

Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int in[5];
  for(int i = 0; i < 5; i++)
    cin >> in[i];
  sort(in, in+5, greater<int>());
  for(int i = 0; i < 4; i++)
    cout << in[i] << " ";
  cout << in[4] << endl;
}

Measured memory_bytes: 1176
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, K; cin >> N >> M >> K;
	bool ok = false;
	rep(i, 0, N + 1)rep(j, 0, M + 1) {
		if (K == i*(M - j) + j*(N - i)) {
			ok = true;
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,d1,d2,flag=0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> d1 >> d2;
        if(d1==d2){
            flag++;
            if(flag==3){
                cout << "Yes";
                return 0;
            }
        }else{
            flag=0;
        }
    }
    cout << "No";
}

Measured memory_bytes: 3596
#include <cstdio>

typedef long long ll;

int n, S, X[100005];
ll P[100005];

int last(int l, int r) {
	if (S < X[l]) return r;
	if (S > X[r]) return l;
	return P[l] >= P[r] ? r : l;
}

int main() {
	scanf("%d%d", &n, &S);
	for (int i = 1; i <= n; ++i)
		scanf("%d%lld", X + i, P + i);
	ll ans = 0;
	for (int l = 1, r = n;;) {
		if (S < X[l]) { ans += X[r] - S; break; }
		if (S > X[r]) { ans += S - X[l]; break; }
		if (P[l] >= P[r]) P[l] += P[r], ans += X[r] - X[last(l, r - 1)], --r;
		else P[r] += P[l], ans += X[last(l + 1, r)] - X[l], ++l;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1280
import java.io.*;
import java.util.*;


	public class Main {
		public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String x = sc.next();
		int aposition = x.indexOf("A");
		int zposition=x.lastIndexOf("Z");
		int total = zposition-aposition +1;
		System.out.print(total);
		}
		}
	


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

int main()
{
  int n,k;
  scanf("%d%d",&n,&k);
  
  int a[n];
  for(int i=0;i<n;i++)
  {
     scanf("%d",&a[i]);
    
  }
  sort(a,a+n);
 
  int min = 1000000001;
   int diff;
  for(int i=0;i<=n-k;i++)
  {
    diff = a[i+k-1]-a[i];
     
    if(min>=diff)
    min = diff;
   }
   printf("%d",min);


}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=998244353;
const int MAX = 510000;
const int INF = 1e9;
const double pi=acos(-1);

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
  int n,m;
  cin >> n >> m;
  UnionFind tree(n);
  vector<int>a(m);
  vector<int>b(m);
  rep(i,m) cin >> a[i] >> b[i];
  
  int sum=0;
  rep(i,m){
    UnionFind tree(n);
    int A;
    rep(j,m){
      if(i!=j){
        tree.merge(a[j]-1,b[j]-1);
        A=a[j]-1;
      }
    }
    if(tree.size(A)!=n)sum++;
  }
  
  cout << sum<< endl;
  return 0;
  
}

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

int main() {
    int t, a=0, b=0;
    for (int i = 0; i < 4; i++) {
        std::scanf("%d", &t);
        a += t;
    }
    for (int i = 0; i < 4; i++) {
        std::scanf("%d", &t);
        b += t;
    }
    (a > b) ? std::cout << a << std::endl : std::cout << b << std::endl;
    
    
    return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[6] = {-1,-1,0,0,1,1};
int dy[6] = {-1,0,-1,1,0,1};

int a[100005];
int dp[100005];
int n;
int solve(int idx){
    if(idx==(n-1))
        return 0;
    if(idx>=n)
        return INF;
    int &ret = dp[idx];
    if(~ret)
        return ret;
    ret = INF;
    ret=min(ret,solve(idx+1)+abs(a[idx+1]-a[idx]));
    ret=min(ret,solve(idx+2)+abs(a[idx+2]-a[idx]));
    return ret;
}



int main(){

    cin>>n;
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    memset(dp,-1,sizeof dp);
    cout<<solve(0)<<endl;
    return 0;
}

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

int32_t main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i = 0; i < n; i++){
        cin >> vec[i];
    }
    vector<int> prefixSum;
    prefixSum.push_back(0);
    for(int i = 0; i < n; i++){
        prefixSum.push_back(prefixSum.back() + vec[i]);
    }
    int ans = 0;
    for(int i = 0; i < n - 1; i++){
        ans += ((prefixSum.back() - prefixSum[i + 1]) % MOD * vec[i] % MOD) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 6864
q,h,s,d = map(int,input().split())

n = int(input())

price = [q,h,s,d]
base = [8,4,2,1]
quant = [1,2,4,8]

comp = []
for i in range(4):
    comp.append([price[i]*base[i],i])

comp.sort()
# print(comp)

ans = 0
n *= 4

for ind in range(4):
    tag = comp[ind][1]
    p = price[tag]
    q = quant[tag]
    pos = n//q
    # print(pos)
    if pos >= 0:
        ans += p*pos
        n -= q*pos
    else:
        continue

print(ans)

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

typedef struct Tree{
  int key;
  struct Tree *r,*l,*p;
} Tree;

Tree *root;

void insert(int k){
  Tree *a = NULL;
  Tree *b = root;
  Tree *t;

  t = malloc(sizeof(Tree));

  t->key = k;
  t->l = NULL;
  t->r = NULL;

  while(b != NULL){
    a = b;
    if(t->key < b->key){
      b = b->l;
    }else{
      b = b->r;
    }
  }

  t->p = a;

  if(a == NULL){
    root = t;
  }else{
    if(t->key < a->key){
      a->l = t;
    }else{
      a->r = t;
    }
  }
}

Tree *find(Tree *t, int k){
  while(t != NULL && k != t->key){
    if(k < t->key){
      t = t->l;
    }else{
      t = t->r;
    }
  }
  return t;
}

void ino(Tree *t){
  if(t == NULL) return;
  ino(t->l);
  printf(" %d",t->key);
  ino(t->r);
}

void pre(Tree *t){
  if(t == NULL) return;
  printf(" %d",t->key);
  pre(t->l);
  pre(t->r);
}

int main(){
  int n,x,y,i;
  Tree *found;
  char order[10];

  scanf("%d",&n);

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

    scanf("%s",order);

    if(order[0] == 'i'){
      scanf("%d",&x);
      insert(x);

    }else if(order[0] == 'p'){
      ino(root);
      printf("\n");
      pre(root);
      printf("\n");

    }else if(order[0] == 'f'){
      scanf("%d",&y);
      found = find(root,y);

      if(found != NULL){
	printf("yes\n");
      }else{
	printf("no\n");
      }

    }
  }
  return 0;
}

Measured memory_bytes: 19364
#include <bits/stdc++.h>
using namespace std;
int calculate(int num1,int num2,int num3){
  int sum=num1+num2+num3;
  for(int i=0;i<sum;i++){
  	num1--;
  	if(num1==0&&num2==0&&num3==0){
  	  return 0;
  	}else if(num1<0){
  	  return -1;
  	}  	
  	num2--;
  	if(num1==0&&num2==0&&num3==0){
  	  return 0;
  	}else if(num2<0){
  	  return -1;
  	}  	
  	num3--;
  	if(num1==0&&num2==0&&num3==0){
  	  return 0;
  	}else if(num3<0){
  	  return -1;
  	}
  }
  return -1;
}
int main(void){
  string str;
  int count_a,count_b,count_c;
  count_a=count_b=count_c=0;
  cin>>str;
  for(int i=0;i<str.size();i++){
    if(str[i]=='a'){
      count_a++;
    }else if(str[i]=='b'){
      count_b++;
    }else{
      count_c++;
    }
  }
  if(max({count_a,count_b,count_c})==count_a){
  	if(max(count_b,count_c)==count_b){
  	  if(calculate(count_a,count_b,count_c)==0){
  	  	cout<<"YES"<<endl;
  	  }else{
  	  	cout<<"NO"<<endl;
  	  }
  	}else{
  	  if(calculate(count_a,count_c,count_b)==0){
  	  	cout<<"YES"<<endl;
  	  }else{
  	  	cout<<"NO"<<endl;
  	  }
  	}
  }else if(max({count_a,count_b,count_c})==count_b){
    if(max(count_a,count_c)==count_a){
  	  if(calculate(count_b,count_a,count_c)==0){
  	  	cout<<"YES"<<endl;
  	  }else{
  	  	cout<<"NO"<<endl;
  	  }
  	}else{
  	  if(calculate(count_b,count_c,count_a)==0){
  	  	cout<<"YES"<<endl;
  	  }else{
  	  	cout<<"NO"<<endl;
  	  }
  	}
  }else if(max({count_a,count_b,count_c})==count_c){
    if(max(count_a,count_b)==count_a){
  	  if(calculate(count_c,count_a,count_b)==0){
  	  	cout<<"YES"<<endl;
  	  }else{
  	  	cout<<"NO"<<endl;
  	  }
  	}else{
  	  if(calculate(count_c,count_b,count_a)==0){
  	  	cout<<"YES"<<endl;
  	  }else{
  	  	cout<<"NO"<<endl;
  	  }
  	}
  }
}


Measured memory_bytes: 512
package main

import (
	"fmt"
	"math"
)

var K, S int
var ans, res int
var mod int = pow(10, 9) + 7

func main() {
	fmt.Scan(&K, &S)

	for i := 0; i <= K; i++ {
		for j := 0; j <= K; j++ {
			k := S - i - j

			if 0 <= k && k <= K {
				ans++
			}
		}
	}
	fmt.Println(ans)
}

/*  ----------------------------------------  */
func lcm(x, y uint64) uint64 {
	return (x / gcd(x, y)) * y
}

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	return a[i][1] < a[j][1]
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if((a==b && b != c) || (b==c && a!=c) || (a==c && c!=b))
		cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 3592
import sys
sys.setrecursionlimit(300000)

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N, K = MI()
s = set()
for i in range(K):
    I()
    for a in LMI():
        s.add(a)

ans = 0
for i in range(1, N + 1):
    if i not in s:
        ans += 1
print(ans)



Measured memory_bytes: 67844
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt(), b = sc.nextInt();
		ArrayList<Integer> pa = new ArrayList<Integer>();
		ArrayList<Integer> pab = new ArrayList<Integer>();
		ArrayList<Integer> pb = new ArrayList<Integer>();
		for(int i = 0;i < n;i ++) {
			int p = sc.nextInt();
			if(p <= a) pa.add(p);
			else if(a + 1 <= p && p <= b) pab.add(p);
			else pb.add(p);
		}
		int min = pa.size();
		if(pab.size() < min) min = pab.size();
		if(pb.size() < min) min = pb.size();
		System.out.println(min);
	}
}

Measured memory_bytes: 24276