akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MAXN 110
using namespace std;

int a, b;
char ans[MAXN][MAXN];

int main() {
    scanf("%d%d", &a, &b); --a; --b;
    for (register int i = 1; i <= 50; ++i)
        for (register int j = 1; j <= 100; ++j)
            ans[i][j] = '.';
    for (register int i = 51; i <= 100; ++i)
        for (register int j = 1; j <= 100; ++j)
            ans[i][j] = '#';
    //fprintf(stderr, "init complated %d %d\n", a, b);
    for (register int i = 1; b; i += 2)
        for (register int j = 1; b && j <= 100; j += 2) {
            ans[i][j] = '#'; --b;
        }
    for (register int i = 52; a; i += 2)
        for (register int j = 2; a && j <= 100; j += 2) {
            ans[i][j] = '.'; --a;
        }
    puts("100 100");
    for (register int i = 1; i <= 100; ++i) {
        for (register int j = 1; j <= 100; ++j)
            putchar(ans[i][j]);
        putchar('\n');
    }
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
long ans[51][51][50 * 50 + 1];

int main() {
  int N, A;
  cin >> N >> A;
  vector<int> x(N);
  for (int i = 0; i < N; i++)
    cin >> x[i];

  fill(ans[0][0], ans[51][0], 0);
  ans[0][0][0] = 1;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= i; j++) {
      for (int k = 0; k < N * 50 + 1; k++) {
        ans[i + 1][j + 1][k + x[i]] += ans[i][j][k];
        ans[i + 1][j][k] += ans[i][j][k];
      }
    }
  }

  long result = 0;
  for (int i = 1; i <= N; i++) {
    result += ans[N][i][i * A];
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 51072
n = int(input())
a = list(map(int, input().split()))

mod = pow(10, 9) + 7

sum_array = [a[-1]]
for i in range(n - 1):
    sum_array.append(sum_array[i] + a[n - i - 2])

ans = 0
for i in range(n - 1):
    ans += sum_array[n - i - 2] * a[i]

ans %= mod
print(ans)

Measured memory_bytes: 31680
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int a[101][101];
	int r,c;
	cin>>r>>c;
	int i,j;
	int b[101]={0};
	int cd[101]={0};
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			cin>>a[i][j];
		}
	}
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			b[i]+=a[i][j];
		}
	}
	for(j=0;j<c;j++){
		for(i=0;i<r;i++){
			cd[j]+=a[i][j];
		}
	}
	int x=0;
	for(i=0;i<r;i++){
		
		x+=b[i];
	}
	for(i=0;i<r;i++){
		cout<<a[i][0];
		for(j=1;j<c;j++){
			cout<<" "<<a[i][j];
		}
		cout<<" "<<b[i]<<endl;
	}
	cout<<cd[0];
	for(i=1;i<c;i++){
		cout<<" "<<cd[i];
	}
	cout<<" "<<x<<endl;
	
	return 0;
}
	
	
	


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> jobs(m);
  rep(i,n) {
    int a, b;
    cin >> a >> b;
    if (a > m) continue; 
    jobs[m-a].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  for (int i = m-1; i >= 0; --i) {
    for (int b : jobs[i]) {
      q.push(b);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}


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

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

Measured memory_bytes: 3852
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
using ll = long long;



int main() {
	string s;
	int c = 0;
	cin >> s;
	for (int i = 0; i < s.size(); i++) if (s[i] == 'o') c++;
	cout << 700 + 100 * c << endl;

	return 0;
}

Measured memory_bytes: 256
s = list(input())

ans = 'AC'
if s[0] != 'A':
    ans = 'WA'  

if s[2:-1].count('C') != 1:
    ans = 'WA'

cnt = 0
for i in s:
    
    if 'A' <= i <= 'Z':
        cnt += 1

if cnt != 2:
    ans = 'WA'

print(ans)

Measured memory_bytes: 38256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            MyInputStream cin = new MyInputStream();

            var h = cin.ReadLong();
            var w = cin.ReadLong();

            for (int i = 0; i < h; ++i)
            {
                var s = cin.ReadLine();
                WriteLine(s);
                WriteLine(s);
            }
        }
    }

    public static class MyExtensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class MyInputStream
    {
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(char separator = ' ')
        {
            this.separator = separator;
            inputStream = new Queue<string>();
        }

        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = Console.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; i++)
            {
                inputStream.Enqueue(tmp[i]);
            }
            return inputStream.Dequeue();
        }
        public string ReadLine() => Console.ReadLine();
        public int ReadInt() => int.Parse(Read());
        public long ReadLong() => long.Parse(Read());
        public double ReadDouble() => double.Parse(Read());
    }

    public class Pair<T1, T2>
    {
        public T1 First;
        public T2 Second;
        public Pair() { First = default(T1); Second = default(T2); }
        public Pair(T1 f, T2 s) { First = f; Second = s; }
        public override string ToString() { return "(" + First + ", " + Second + ")"; }
        public override int GetHashCode() { return First.GetHashCode() ^ Second.GetHashCode(); }
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(this, obj)) return true;
            else if (obj == null) return false;
            var tmp = obj as Pair<T1, T2>;
            return (object)tmp != null && First.Equals(tmp.First) && Second.Equals(tmp.Second);
        }
    }

    #region HashMap
    public class HashMap<K, V> : Dictionary<K, V>
    {
        public HashMap() : base() { }
        public HashMap(int cap) : base(cap) { }
        public HashMap(IDictionary<K, V> dictionary) : base(dictionary) { }
        new public V this[K i]
        {
            get
            {
                V v;
                return TryGetValue(i, out v) ? v : base[i] = default(V);
            }
            set { base[i] = value; }
        }
    }
    #endregion
}


Measured memory_bytes: 13268
import java.util.Scanner;
import java.util.Arrays;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N=sc.nextLong();
    long Sum=0;
    long x=1;
      for(long i =1 ; i <=N; i++){
        if(!(x%3==0)&&!(x%5==0)){
          Sum+=x;
        }
        x++;
      }



        System.out.println(Sum);

        }
      }


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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define fi first
#define se second
#define All(a) (a).begin(), (a).end()
#define rAll(a) (a).rbegin(), (a).rend()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CCIN(...)                                                              \
    char __VA_ARGS__;                                                          \
    CIN(__VA_ARGS__)
#define DCIN(...)                                                              \
    double __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename T = string> inline void eputs(T s) {
    cout << s << "\n";
    exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}
template <typename T> using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using PQ = priority_queue<T>;

typedef long long ll;
typedef pair<ll, ll> PL;
typedef vector<PL> VPL;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<double> VD;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double PI = atan(1.0) * 4.0;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};
#define PI 3.141592653589793238

void cinfast() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

signed main() {
    SCIN(S);
    bool judge;
    judge = S[0] == S.back();
    judge ^= S.length() % 2;
    cout << (judge ? "First" : "Second") << "\n";
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include <unordered_map>  
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <sstream>
using namespace std;


int main() {
	int n;
	int c[500], s[500], f[500];
	cin >> n;

	for (int i = 0; i < n - 1; ++i) {
		cin >> c[i] >> s[i] >> f[i];
	}

	for (int i = 0; i < n - 1; ++i) {
		int sum = s[i] + c[i] ;
		for (int k = i + 1; k < n - 1; ++k) {
			if (sum < s[k]) {
				sum = s[k] + c[k];
			}
			else {
				sum = sum % f[k] == 0 ? sum + c[k] : sum + (f[k] - sum % f[k]) + c[k];
			}
			
		}
		cout << sum << endl;
	}

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

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

#ifdef LOCAL 
string to_string(char a) { return string(1,a); }
string to_string(bool a) { return a ? "1" : "0"; }
string to_string(const char* a) { return (string)a; }
string to_string(string a) { return a; }
string to_string(vector<bool> v) {
	string s = "["; for(unsigned i=0;i<v.size();i++){ s += ((i>0)?" ":"");
    s += char('0'+v[i]); } 	s += "]"; return s; }
template<class A, class B> string to_string(pair<A,B> p);
template<class T> string to_string(T v) {
	bool b = 1; string s = "["; for (const auto& x: v) {
		if (!b) {s += ", ";} b = 0; s += to_string(x); } s += "]"; return s; }
template<class A, class B> string to_string(pair<A,B> p) {
	return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
void dbgf() { cerr << endl; }
template<class H, class... T> void dbgf(H h, T... t) {
	cerr << to_string(h); if (sizeof...(t)) cerr << ", ";
	dbgf(t...); }
#define dbg(...) cerr << #__VA_ARGS__ << " = ", dbgf(__VA_ARGS__)
#else
#define dbg(...) 0
#endif
#define boolout(x) cout<<(x?"YES":"NO")<<endl;
typedef long long ll;


void solve()
{
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n);
    vector<ll> prefa(n);
    vector<ll> b(m);
    vector<ll> prefb(m);
    ll start=-1;
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
        if (i) {
            prefa[i] = prefa[i-1] + a[i];
        } else {
            prefa[i] = a[i];
        }
        if (prefa[i]<=k) {
            start = i;
        }
    }
    for (ll i = 0; i < m; ++i) {
        cin >> b[i];
        if (i) {
            prefb[i] = prefb[i-1] + b[i];
        } else {
            prefb[i] = b[i];
        }
    }

    dbg(start);
    ll res=start+1;
    ll cnt2=0;
    for (ll i = start; i >=-1; --i) {
        while (cnt2<m && prefb[cnt2]<= k-(i==-1?0:prefa[i])) {
            dbg(i, cnt2);
            res = max(res, (ll)i+cnt2+2);
            cnt2++;
        }
    }

    cout << res << endl;

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t; // read t. cin knows that t is an int, so it reads it as such.
    for (int i = 1; i <= t; ++i) {
        solve();
    }
    return 0;
}



Measured memory_bytes: 9504
/*
ID: skipian1
PROB: 
LANG: C++11
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF = 2000000000
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define X first
#define Y second

int main() {
  ll n, n1, n2;
  cin >> n;
  ll a[3];
  ll b[3];
  for (int i = 0; i < 3; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < 3; i++) {
    cin >> b[i];
  }
  ll dpab[n+1];
  for (ll j = 0; j <= n; j++) {
    dpab[j] = j;
    for (int i = 0; i < 3; i++) {
      if (a[i] < b[i]) {
	if (j >= a[i]) dpab[j] = max(dpab[j], dpab[j-a[i]]+b[i]);
      }
    }
  }
  n1 = dpab[n];
  ll dpba[n1+1];
  for (ll j = 0; j <= n1; j++) {
    dpba[j] = j;
    for (int i = 0; i < 3; i++) { 
      if (b[i] < a[i]) {
	if (j >= b[i]) dpba[j] = max(dpba[j],dpba[j-b[i]]+a[i]);
      }
    }
  }
  cout << dpba[n1] << "\n";
}


Measured memory_bytes: 195584
import itertools


n = int(input())
xs, ys = list(), list()
points = list()
for i in range(n):
    x, y = map(int, input().split())
    xs.append(x)
    ys.append(y)
    points.append((x, y))

candidates = list()
indices = itertools.combinations(range(n), 2)
points = sorted(points)
for i, j in indices:
    p = points[j][0] - points[i][0]
    q = points[j][1] - points[i][1]
    candidates.append((p, q))

ans = n * 2
for p, q in candidates:
    indices = list(range(n))
    cost = 0

    idx = 0
    cost += 1

    while True:
        x, y = points[idx]
        indices.remove(idx)
        if len(indices) == 0:
            break

        try:
            idx = points.index((x + p, y + q))
        except Exception:
            idx = indices[0]
            cost += 1
    
    ans = min(ans, cost)

if n == 1:
    print(1)
else:
    print(ans)

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

int d[100000]={};
pair<int,int> q[100000];

int main(){
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  for(int i=0; i<Q; i++){
    int l, r;
    cin >> l >> r;
    pair<int, int> p =make_pair(l,r);
    q[i] = p;
  }
  char pre=S[0];
  for(int i=1; i<N; i++){
    if(pre=='A' && S[i]=='C'){
      d[i]=d[i-1]+1;
    }
    else{
      d[i]=d[i-1];
    }
    pre = S[i];
  }
  for(int i=0; i<Q; i++){
    cout << d[q[i].second-1]-d[q[i].first-1] << endl;
  }
  return 0;
}

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

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''
from decimal import Decimal
a,b= input().split()
a=int(a)
b=int(Decimal(b)*100)

print(a*b//100)

Measured memory_bytes: 10076
#include <stdio.h>

#define MAX 300000

int main()
{
	int i;
	int w = 0, e = 0;
	char buf[MAX + 1];
	int len, ecount[MAX + 1], wcount[MAX + 1];
	int min;
	
	scanf("%d", &len);
	scanf("%s", buf);

	for (i = 0; buf[i] != '\0'; i++) {
		if (buf[i] == 'W') {
			w++;
		} else if (buf[i] == 'E') {
			e++;
		}
	}
	
	ecount[0] = e;
	wcount[0] = 0;
	if (buf[0] == 'E') {
		ecount[0] = e - 1;
	} else if (buf[0] == 'W') {
		wcount[1] = 1;
	}
	for (i = 1; buf[i] != '\0'; i++) {
		if (buf[i] == 'E') {
			ecount[i] = ecount[i - 1] - 1;
			wcount[i + 1] = wcount[i];
		} else if (buf[i] == 'W') {
			ecount[i] = ecount[i - 1];
			wcount[i + 1] = wcount[i] + 1;
		}
	}

	for (i = 1, min = ecount[0] + wcount[0]; i < len; i++) {
		if (min > ecount[i] + wcount[i]) {
			min = ecount[i] + wcount[i];
		}
	}

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

	return 0;
}


Measured memory_bytes: 2816
N=int(input())
A=[int(i) for i in input().split()]
ans=0
while max(A)>N-1:
    A.sort()
    t=A[-1]//N
    A[-1]=A[-1]-t*N
    ans+=t
    for i in range(N-1):
        A[i]+=t
print(ans)

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

int main() {
  int n, h[105], ans = 0, t = 0;
  cin >> n;
  REP(i, n) cin >> h[i];
  REP(i, n) {
    if (h[i] > t) {
      ans += h[i] - t;
    }
    t = h[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n,x,count,i,j,k;
  
  while(1){
    scanf("%d %d",&n,&x);
    if(n == 0 && x == 0)break;

    count = 0;
    
    for(i = 1;i <= n;i++){
      for(j = 1;j <= n;j++){
	if(i >= j)continue;
	for(k = 1;k <= n;k++){
	  if(j >= k)continue;
	  if(i + j + k == x){
	    count++;
	  }
	}
      }
    }
    
    printf("%d\n",count);
  }
  
  return 0; 
}

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

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

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

  if (n % 2) {
    cout << 0 << endl;
  } else {
    ll num = 0;
    ll t = 10;
    for (;t <= n; t *= 5) {
      num += n / t;
    }

    cout << num << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef pair<int,int> Pii;
typedef pair<Pii,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	char d[] = {'R','D','L','U'};
	bool w[5][9]={{false}};
	rep(i,9){
		int lim = 4+i%2;
		rep(j,lim){
			char t;
			cin >> t;
			w[j][i] = (t == '1');
		}
	}
	int x,y,s;
	x = y = s = 0;
	while(true){
		int nx,ny;
		s--;
		s = (s+4) % 4;
		rep(i,4){
			nx = x + dx[s];
			ny = y + dy[s];
			if(nx >= 0 && nx <= 4 && ny >= 0 && ny <= 4){
				if(s%2==0 && w[min(x,nx)][y*2])break;
				if(s%2==1 && w[x][min(y,ny) * 2 + 1])break;
			}
			s++;
			s %= 4;
		}
		y = ny;
		x = nx;
		cout << d[s];
		if((x == 0 && y == 0))break;
	}
	puts("");
	return 0;
}

Measured memory_bytes: 1100
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
const int p = (int)1e9+7;

int dp[1100][1100];

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> a(H);
	for (int i = 0; i < H; i++) {
		cin >> a[i];
	}

	dp[0][0] = 1;

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (a[i][j] == '.') {
				if(i+1 < H) dp[i+1][j] += dp[i][j] % p;
				if(j+1 < W) dp[i][j+1] += dp[i][j] % p;
			}
		}
	}

	cout << dp[H-1][W-1]%p << endl;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int n;
vector<vector<int>>v;
vector<int>a, c;
int kaijo(int x) {
	int ans = 1;
	for (int i = 1; i <= x; i++)ans *= i;
	return ans;
}
int main() {
	cin >> n;
	a.resize(n);
	c.resize(n);
	rep(i, n)cin >> a[i];
	if (n == 1) {
		puts("1");
		return 0;
	}
	rep(i, n)c[i] = i + 1;
	do {
		v.push_back(c);
	} while (next_permutation(c.begin(), c.end()));
	rep(i, v.size()) {
		if (v[i] == a) {
			if (i == 0) {
				rep(j, v[i].size())cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " ");
				i++;
				rep(j, v[i].size())cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " ");
				return 0;
			}
			else if (i == v.size() - 1) {
				i--;
				rep(j, v[i].size())cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " ");
				i++;
				rep(j, v[i].size())cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " ");
				return 0;
			}
			else {
				i--;
				rep(j, v[i].size())cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " ");
				i++;
				rep(j, v[i].size())cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " ");
				i++;
				rep(j, v[i].size())cout << v[i][j] << (j == v[i].size() - 1 ? "\n" : " ");
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 28280
#include <iostream>

using namespace std;

int main(){
  unsigned long long N, A, B;
  cin >> N >> A >> B;
  unsigned long long n = N / (A + B), y = N % (A + B);
  unsigned long long b = n * A;
  if (y > A){
    b += A;
    printf("%llu\n", b);
  }else{
    b += y;
    printf("%llu\n", b);
  }
  
}


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

int main() {
    int N;
    cin >> N;
    int x = 0, y = 0, t = 0;
    bool ok = true;
    for (int i = 0; i < N; i++) {
        int nt, nx, ny;
        cin >> nt >> nx >> ny;

        int dt = nt - t;
        int dx = abs(nx - x);
        int dy = abs(ny - y);
        if (dx + dy > dt || (dt - dx - dy) % 2 != 0) {
            ok = false;
        }
        t = nt;
        x = nx;
        y = ny;
    }
    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 384
s = input()
t = input()

sp = sorted(s)
tp = sorted(t, reverse=True)

res = 'No'
for i in range(len(tp)):
  if i > len(sp) - 1:
    res = 'Yes'
    break
  if tp[i] > sp[i]:
    res = 'Yes'
    break
  elif tp[i] < sp[i]:
    break

print(res)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
ll x;
struct blu{
    ll b,l,u;
};

bool o(blu a,blu b){
    return x*a.u-(a.u-a.l)*a.b>x*b.u-(b.u-b.l)*b.b;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,an=0,ans=0,aw=1e18;
    cin>>n>>x;
    vector<ll> b(n),l(n),u(n),f(n);
    vector<blu> br(n);
    fr(i,n){
        cin>>br[i].b>>br[i].l>>br[i].u;
        an-=br[i].b*br[i].l;
    }
    sort(br.begin(),br.end(),o);
    fr(i,n){
        f[i]=x*br[i].u-(br[i].u-br[i].l)*br[i].b;
        b[i]=br[i].b;
        l[i]=br[i].l;
        u[i]=br[i].u;
        //cout<<b[i]<<" "<<l[i]<<" "<<u[i]<<" "<<f[i]<<endl;
    }
    //cout<<an<<endl;
    int j=0;
    while(j<n&&an+f[j]<=0){
        //cout<<"!"<<j<<endl;
        an+=f[j];
        ++j;
        ans+=x;
    }
    //cout<<j<<" "<<an<<endl;
    //cout<<j<<endl;
    if(an==0){
        cout<<ans<<endl;
        return 0;
    }
    ll ka=-an;
    for(int k=j;k<n;++k){
        if(b[k]*l[k]>=ka){
            aw=min(aw,ans+(ka-1)/l[k]+1);
            //cout<<k<<" "<<ans+(ka-1)/l[k]+1<<endl;
        }
        else{
            if(ka>b[k]*l[k]+u[k]*(x-b[k])) continue;
            aw=min(aw,ans+b[k]+(ka-b[k]*l[k]-1)/u[k]+1);
            //cout<<k<<" "<<ans+b[k]+(ka-b[k]*l[k]-1)/u[k]+1<<endl;
        }
    }
    an+=f[j];
    for(int k=0;k<=j;++k){
        ka=-an;
        ka+=f[k];
        if(b[k]*l[k]>=ka){
            aw=min(aw,ans+(ka-1)/l[k]+1);
            //cout<<k<<" "<<ans+(ka-1)/l[k]+1<<endl;
        }
        else{
            if(ka>b[k]*l[k]+u[k]*(x-b[k])) continue;
            aw=min(aw,ans+b[k]+(ka-b[k]*l[k]-1)/u[k]+1);
            //cout<<k<<" "<<ans+b[k]+(ka-b[k]*l[k]-1)/u[k]+1<<endl;
        }
    }
    cout<<aw<<endl;
}

Measured memory_bytes: 5760
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=0,m=0,k=0;

        if(scan.hasNext())
            n=scan.nextInt();

        if(scan.hasNext())
            m=scan.nextInt();
        String str="";
        boolean[] brr=new boolean[n];
        int[] arr=new int[n];
        for(int i=0;i<m;i++){
            if(scan.hasNext())
                k=scan.nextInt();
            if(scan.hasNext())
                str=scan.next();
            if(str.equals("AC")){
                brr[k-1]=true;
            }else{
                if(!brr[k-1]){
                    arr[k-1]+=1;
                }
            }
        }
        int ca=0,pen=0;
        for(int i=0;i<n;i++){
            if(brr[i]){
                ca++;
                pen+=arr[i];
            }
        }
        System.out.println(ca+" "+pen);
    }
}


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

typedef long long ll;

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

    int N, X, Y;

    cin >> N >> X >> Y;
    X--;
    Y--;

    vector<int> A(N);

    for(int i = 0; i < N - 1; i++) {
        for(int j = i + 1; j < N; j++) {
            int min = j - i;
            int x = abs(X - i) + abs(j - Y) + 1;
            if(x < min) {
                min = x;
            }
            A[min]++;
        }
    }
/*
    for(int i = 0; i < N - 1; i++) {
        int min = abs(X - i) + 1;
        int x = abs(Y - i) + 1;
        if(x < min) {
            min = x;
        }
        A[min]++;

        //cerr << min << endl;
    }
*/
    for(int i = 1; i < N; i++) {
        cout << A[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, p;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  int ans = 0;
  FOR(i, 0, n){
    int h;
    cin >> h;
    if(p < h) ans += h-p;
    p = h;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// INCLUDES
#include <bits/stdc++.h>
#include<assert.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
//DEFINES
#define MAX 1000001
#define pii pair<int, int>
#define c1 __builtin_popcount
#define F first
#define S second
#define all(s) begin(s),end(s)
#define MIN3POS(a, b, c) (a) =< (b) ? ((a) =< (c) ? 1 : 3) : ((b) =< (c) ? 2 : 3)
#define MAX3POS(a,b,c) (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2:3)
#define endl '\n'
#define int long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define FOR(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define IOS   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//NAMESPACES
using namespace __gnu_pbds; 
using namespace std;
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    os << "["; 
    for (int i = 0; i < v.size(); ++i) { 
        cout << v[i]; 
        if (i != v.size() - 1) 
            os << ", "; 
    } 
    os << "]"; 
    return os; 
} 
template <typename T> 
ostream& operator<<(ostream& os, const set<T>& v) 
{ 
    os << "["; 
    for (auto it : v) { 
        os << it; 
        if (it != *v.rbegin()) 
            os << ", "; 
    } 
    os << "]"; 
    return os; 
} 
  template <typename T, typename S> 
ostream& operator<<(ostream& os, const map<T, S>& v) 
{ 
    for (auto it : v)  
        cout << it.first << " : " 
           << it.second << "\n"; 
      
    return os; 
} 
template <typename T, typename S> 
ostream& operator<<(ostream& os, const pair<T, S>& v) 
{ 
    os << "("; 
    cout << v.first << ", " 
       << v.second << ")"; 
    return os; 
} 
  
// D

void solve(){
char a;
cin>>a;
if(isupper(a)) cout<<"A";
else cout<<"a";
}
int32_t main()
{
IOS
int t=1;
// cin>>t;
while(t--) {
    solve();
}

return 0;
}
// Use emplace back in place of pushback
// Use tie function , for object destructuring

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define endl '\n'
#define pii pair<int, int>

using namespace std;

int n, a;
int matriz[100005][5];
long long dp[100005][5];

void inicializar()
{
	for(int i = 0; i < 3; i++)
	{
		dp[0][i] = matriz[0][i];
	}
}

long long maximo()
{
	long long resp = 0;
	for(int i = 0; i < 3; i++)
	{
		resp = max(resp, dp[n - 1][i]);
	}
	return resp;
}

void imprimir()
{
    cout << "matriz" << endl;
    for(int i = 0; i  < n; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            cout << matriz[i][j] << " ";
        }
        cout << endl;
    }

    cout << "dp" << endl;
    for(int i = 0; i  < n; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
}

long long vacation()
{
	inicializar();

	for(int i = 1; i < n; i++)
	{
		for(int j = 0; j < 3; j++)
		{
			if(j == 0)
				dp[i][j] = matriz[i][j] + max(dp[i - 1][1], dp[i - 1][2]);
			else if(j == 1)
				dp[i][j] = matriz[i][j] + max(dp[i - 1][0], dp[i - 1][2]);
			else
				dp[i][j] = matriz[i][j] + max(dp[i - 1][0], dp[i - 1][1]);
		}
	}

    //imprimir();
	long long resp = maximo();
	return resp;
}

int main()
{
    cin >> n;

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            cin >> a;
            matriz[i][j] = a;
        }
    }

    long long resp = vacation();

    cout << resp << endl;
}

Measured memory_bytes: 6144
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <math.h>
#include <time.h>

typedef int32_t i32;
typedef int64_t i64;
typedef double f64;

void *const null=(void *)0;
i64 const llinf=4611686018427387903LL;
i64 const mod=1000000009LL;
f64 const pi=3.141592653589793;
f64 const rad=57.295779513082323;

#define CODE_

i32 main(void){
    i64 l,a,b,c,d;
    scanf("%lli%lli%lli%lli%lli",&l,&a,&b,&c,&d);
    i64 jd=a/c;
    if(jd*c!=a) ++jd;
    i64 md=b/d;
    if(md*d!=b) ++md;
    printf("%lli\n",l-(jd>=md?jd:md));
    return 0;
}



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

int H, W;
int d[10][10];

void warshall_floyd(){
    for(int k = 0; k < 10; k++){
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            cin >> d[i][j];
        }
    }
    warshall_floyd();
    long long ans = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int a; cin >> a;
            if(abs(a) != 1) ans += d[a][1];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  string s;in(s);
  if(s=="SUN")out(7);
  if(s=="MON")out(6);
  if(s=="TUE")out(5);
  if(s=="WED")out(4);
  if(s=="THU")out(3);
  if(s=="FRI")out(2);
  if(s=="SAT")out(1);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
import java.util.*
 
fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    var other = 0
    val size = (1..n).map {
        when (sc.nextInt()) {
            in 1..399 -> 1
            in 400..799 -> 2
            in 800..1199 -> 3
            in 1200..1599 -> 4
            in 1600..1999 -> 5
            in 2000..2399 -> 6
            in 2400..2799 -> 7
            in 2800..3199 -> 8
            else -> {
                other++
                0
            }
        }
    }.toSet().filterNot { it == 0 }.size
 
    println("${Math.max(1, size)} ${size + other}")
}

Measured memory_bytes: 31512
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    A = list(map(int, input().split()))

    for i in range(N):
        if A[i] % 2 == 0:
            if not (A[i] % 3 == 0 or A[i] % 5 == 0):
                print('DENIED')
                exit()
    else:
        print('APPROVED')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
import sys


class Solution(object):
    def __init__(self):
        self.N = int(sys.stdin.readline())
        self.s = []
        for _ in range(self.N):
            self.s.append(int(sys.stdin.readline()))

    # def solve(self):
    def naive_solve(self):
        sums = [0]
        for num in self.s:
            sums.extend([s + num for s in sums])
        for r in sorted(sums, reverse=True):
            if r % 10:
                return r
        return 0

    def answer_solve(self):
        S = sum(self.s)
        if S % 10:
            return S
        smallest = float('inf')
        for num in self.s:
            if num % 10:
                smallest = min(smallest, num)
        if smallest != float('inf'):
            return S - smallest
        return 0




print(Solution().answer_solve())


Measured memory_bytes: 3064
N = int(input())
a_list = list(map(int,input().split()))
b_list = list(map(int,input().split()))
c_list = list(map(int,input().split()))

sum = 0

for i in range(N):
    sum += b_list[a_list[i]-1]
    if (i>=1 and a_list[i]-a_list[i-1] == 1):
        sum += c_list[a_list[i]-2]

print(sum)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int n, m;
    string s;
    cin >> n >> m >> s;
    int c = 0;
    for (int i = 0; i < n - 1; i++) {
        if (s[i] == s[i+1]) c++;
    }
    cout << min(n-1, c + 2*m) << endl;
    return 0;
}

Measured memory_bytes: 512
s = input()
t = input()
dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]
for i in range(1, len(s) + 1):
  for j in range(1, len(t) + 1):
    k = dp[i - 1][j]
    if dp[i][j - 1] > k:
      k = dp[i][j - 1]
    if (s[i - 1] == t[j - 1]) and (dp[i - 1][j - 1] + 1 > k):
      k = dp[i - 1][j - 1] + 1
    dp[i][j] = k
u = []
while i > 0 and j > 0:
  if dp[i - 1][j] == dp[i][j]:
    i -= 1
  elif dp[i][j - 1] == dp[i][j]:
    j -= 1
  else:
    u.append(s[i - 1])
    i -= 1
    j -= 1
print(''.join(reversed(u)))

Measured memory_bytes: 112988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 1000000007;
const int MOD = (int)1e9+7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
int dy[4] = {-1, 0, 1, 1};
int dx[4] = {0, 1, 0, 1};

int n;
vi d;
int ret;

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	cin >> n;
	d.resize(n);
	rep(i,0,n) {
		cin >> d[i];
	}
	ret = 0;
	rep(i,0,n) rep(j,i+1,n) {
		ret += d[i]*d[j];
	}
	cout << ret << '\n';
	return 0;
}


Measured memory_bytes: 256
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=10010;
const double eps=1e-6;
int n,f[N];
double calc1(int x,int y,int n)
{
    double delta=(x+y)*(x+y)-4*(x*x+y*y+x*y-n);
    if((x+y)*(x+y)<=4*(x*x+y*y+x*y-n)) return -1;
    return (sqrt(delta)-(x+y))/2.0;
}
int calc2(int x,int y,int n)
{
    int delta=(x+y)*(x+y)-4*(x*x+y*y+x*y-n);
    if(delta<=0) return -2;
    return (sqrt(delta)-(x+y))/2;
}
int main()
{
    IO;
    cin>>n;
    for(int k=1;k<=n;k++)
        for(int i=1;i<=k/i;i++)
            for(int j=1;j<=k/j;j++)
            {
                double x=calc1(i,j,k);
                int y=calc2(i,j,k);
                if(x<eps) continue;
                if(abs(x-y)<eps) f[k]++;
            }
    for(int i=1;i<=n;i++) cout<<f[i]<<endl;
    return 0;
}

Measured memory_bytes: 3544
#!/usr/bin/python3
# vim: set fileencoding=utf-8:
import sys
import collections
input = sys.stdin.readline

"""
H = int(input())
h = [int(ele) for ele in input().split()]
h = [0] + h
"""


def main():
    N = int(input())
    d = [0] * (N)
    for i in range(N):
        d[i] = int(input().rstrip())

    c = collections.Counter(d)
    print(len(c.keys()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
import sys
input = sys.stdin.buffer.readline


class SegmentTree:
    """一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する。
    build(array)   := arrayを初期値とするセグメント木を構築する O(N)。
    update(i, val) := i番目の要素をvalに変更する。
    get_val(l, r)  := 区間[l, r)に対する二項演算の畳み込みの結果を返す。
    """
    def __init__(self, n, op, e):
        """要素数、二項演算、単位元を引数として渡す
        例) 区間最小値 SegmentTree(n, min, 10 ** 18)
            区間和     SegmentTree(n, lambda a, b : a + b, 0)
        """
        self.n = n
        self.op = op
        self.e = e
        self.size = 2 ** ((n - 1).bit_length())
        self.node = [self.e] * (2 * self.size)

    def build(self, array):
        """arrayを初期値とするセグメント木を構築する"""
        for i in range(self.n):
            self.node[self.size + i] = array[i]
        for i in range(self.size - 1, 0, -1):
            self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])

    def update(self, i, val):
        """i番目の要素をvalに変更する"""
        i += self.size
        self.node[i] = val
        while i > 1:
            i >>= 1
            self.node[i] = self.op(self.node[i << 1], self.node[(i << 1) + 1])

    def get_val(self, l, r):
        """[l, r)の畳み込みの結果を返す"""
        l, r = l + self.size, r + self.size
        res_l, res_r = self.e, self.e
        while l < r:
            if l & 1:
                res_l = self.op(res_l, self.node[l])
                l += 1
            if r & 1:
                r -= 1
                res_r = self.op(self.node[r], res_r)
            l, r = l >> 1, r >> 1
        return self.op(res_l, res_r)

      
n, k = map(int, input().split())
a = [int(input()) for i in range(n)]
max_a = max(a)

ans = 0
st = SegmentTree(max_a + 1, max, 0)
ans = 0
for val in a:
    l, r = max(val - k, 0), min(val + k + 1, max_a + 1)
    res = st.get_val(l, r)
    ans = max(res, ans)
    st.update(val, res + 1)
print(ans + 1)

Measured memory_bytes: 87356
#include<stdio.h>
int main(void){
  int n, m, c, b[20], a[1000][20], i, j, k, l, o, d = 0, e = 0;

  scanf("%d %d %d", &n, &m, &c);
  for(i = 0; i < m; i++) scanf("%d", &b[i]);
  for(j = 0; j < n; j++){
    for(k = 0; k < m; k++) scanf("%d", &a[j][k]);
  }
  for(l = 0; l < n; l++){
    d = 0;
    for(o = 0; o < m; o++){
      d = d + b[o]*a[l][o];
    }
    d = d + c;
    if(d > 0) e++;
  }
  printf("%d\n", e);
  return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;

long long f(long long N, long long X, vector<long long> &len, vector<long long> &p) {
    if (N == 0) {
        return 1;
    }

    if (X == 1) {
        return 0;
    } else if (X <= 1 + len[N - 1]) {
        return f(N - 1, X - 1, len, p);
    } else if (X == 2 + len[N - 1]) {
        return p[N - 1] + 1;
    } else if (X <= 2 + 2 * len[N - 1]) {
        return p[N - 1] + 1 + f(N - 1, X - 2 - len[N - 1], len, p);
    } else {
        return 2 * p[N - 1] + 1;
    }
}

int main() {
    long long N, X;
    cin >> N >> X;

    vector<long long> len(N + 1);
    vector<long long> p(N + 1);

    len[0] = p[0] = 1;
    for (int i = 1; i < N + 1; i++) {
        len[i] = len[i - 1] * 2 + 3;
        p[i] = p[i - 1] * 2 + 1;
    }

    cout << f(N, X, len, p) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.lang.Math.*

data class Point(val x:Double, val y:Double)
fun Point.distanceFrom(origin:Point):Double = sqrt((this.x - origin.x) * (this.x - origin.x) + (this.y - origin.y) * (this.y - origin.y))
fun main(args:Array<String>):Unit {
    val n = readLine()!!.toInt()
    val points = Array(n){readLine()!!.split(' ').map(String::toDouble).let{Point(it.first(), it.last())}}
    var posB = 0
    var maxLength:Double = .0
    for (posA in 0 until n){
        while (points[posA].distanceFrom(points[posB]) <= points[posA].distanceFrom(points[(posB + 1) % n])) {
            posB = (posB + 1) % n
        }
        if (maxLength < points[posA].distanceFrom(points[posB])) maxLength = points[posA].distanceFrom(points[posB])
    }
    println(maxLength)
}


Measured memory_bytes: 80560