akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <cassert>

using size_t = std::size_t;

template<class id_type>
class Graph{
public:
  using vertex_type = size_t;
  struct Edge{
    vertex_type to;
    id_type id;
  };

  struct Edge_Pair{
    vertex_type from;
    vertex_type to;
    id_type id;
  };
private:
  std::vector<vertex_type> ver;
  std::vector<Edge_Pair> edges;
  std::vector<std::vector<Edge>> G;
  std::vector<std::vector<Edge>> rG;
public:
  Graph(size_t sz) : ver(sz) , G(sz) , rG(sz){
    for(size_t i = 0;i < ver.size();i++) ver[i] = i;
  }

  const std::vector<vertex_type>& V() const{
    return ver;
  }

  const std::vector<Edge_Pair>& E() const{
    return edges;
  }

  void add_edge(const Edge_Pair& e){
    edges.push_back(e);
    G[e.from].push_back({e.to,e.id});
    rG[e.to].push_back({e.from,e.id});
  }

  void add_edge(vertex_type from,vertex_type to,id_type id){
    add_edge({from,to,id});
  }

  Graph operator+=(const Edge_Pair& e){
    add_edge(e);
    return *this;
  }


  const std::vector<Edge>& delta_p(vertex_type v) const{
    return G[v];
  }

  const std::vector<Edge>& delta_m(vertex_type v) const{
    return rG[v];
  }

  const std::vector<Edge>& operator[](vertex_type v) const{
    return this->delta_p(v);
  }
};

#include <set>
#include <queue>
#include <functional>

template<class dist_type,class id_type>
std::vector<dist_type> dijkstra(const Graph<id_type>& g,std::function<dist_type(id_type)> cost,size_t s,dist_type init,dist_type INF){
    using vt = typename Graph<id_type>::vertex_type;
    using P = std::pair<dist_type,vt>;
    std::vector<dist_type> dist(g.V().size(),INF);
    dist[s] = init;

    std::priority_queue<P,std::vector<P>,std::greater<P>> que;

    que.push({dist[s],s});

    while(!que.empty()){
      vt v = que.top().second;
      dist_type d = que.top().first;
      que.pop();
      if(dist[v] < d) continue;
      for(const auto & e : g.delta_p(v)){
        if(dist[e.to] > dist[v] + cost(e.id)){
          dist[e.to] = dist[v] + cost(e.id);
          que.push({dist[e.to],e.to});
        }
      }
    }

    return dist;
}

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  int n;
  cin >> n;
  Graph<size_t> g(n);
  vector<i64> cost;
  for(int i = 0;i < n;i++){
    size_t u,t;
    cin >> u >> t;
    for(int j = 0;j < t;j++){
      size_t v;
      i64 c;
      cin >> v >> c;
      g.add_edge(u,v,cost.size());
      cost.push_back(c);
    }
  }

  auto res = dijkstra<i64,size_t>(g,[&](size_t id)->i64{return cost[id];},0UL,0LL,(i64)1e9);
  for(int i = 0;i < n;i++){
    cout << i << " " << res[i] << endl;
  }
}



Measured memory_bytes: 38312
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using ll = long long;
using namespace std;
#define modmod 1000000007

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


int main(){
    int N;
    cin >> N;
    int A[N]={0};
    int a;
    for(int i = 0; i < N; i++){
        cin >> a;
        A[a/2]++;
    }

    int limit;
    if(N%2 == 0){
        limit = N/2-1;
    }else{
        limit = N/2;
    }

    //printf("limit : %d\n",limit);

    for(int i = 0; i <= limit; i++){
        //printf("A[%d] : %d\n",i,A[i]);
        if(i == 0){
            if(N%2 == 1 and A[0] != 1){
                cout << 0 << endl;
                return 0;
            }
            if(N%2 == 0 and A[0] != 2){
                cout << 0 << endl;
                return 0;
            }
        }else{
            if(A[i]!=2){
            cout << 0 << endl;
            return 0;
            }
        }
    }
    ll result = 1;
    for(int i = 0; i < N; i++){
        if(A[i]!=0){
            result = ((result%modmod) * (A[i]%modmod)) % modmod;
        }
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main(){
    int n;
    cin>>n;
    
    int ans=0;
    for(int bit=0; bit<(1<<18); bit++){
        string now="";
        
        bool cont=false;
        bool zero=false;
        
        bool shichi=false;
        bool go=false;
        bool san=false;
        
        rep(i,9){
            if(bit&(1<<(2*i)) && bit&(1<<(2*i+1))){
                if(zero) cont=true;
            }
            else if(bit&(1<<(2*i))){
                now+='7';
                zero=true;
                shichi=true;
            }
            else if(bit&(1<<(2*i+1))){
                now+='5';
                zero=true;
                go=true;
            }
            else{
                now+='3';
                zero=true;
                san=true;
            }
        }
        if(cont) continue;
        if(shichi&&go&&san&&stoi(now)<=n) ans++;
    }
    cout<<ans<<endl;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	vi v(3);
	REP(i, s.size()) {
		v[s[i] - 'a']++;
	}
	sort(ALL(v));
	int n = s.size();
	if (n % 3 == 0) {
		if (v[0] == v[1] && v[1] == v[2])cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	else if (n % 3 == 1) {
		if (v[0] == v[1] && v[1]+1 == v[2])cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	else {
		if (v[0]+1 == v[1] && v[1] == v[2])cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}


Measured memory_bytes: 512
<?php
$n_str = trim(fgets(STDIN));
$s = trim(fgets(STDIN));
$n = intval($n_str);
$result = 0;
$max = 0;


for ($i = 0; $i < $n; $i++) {
    if($s[$i] === 'I') {
        $result++;
    }
    if($s[$i] === 'D') {
        $result--;
    }
    if($result > $max) {
        $max = $result;
    }

}

printf("$max\n");

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

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int N, M, Q;
vector<int> a;
vector<int> b;
vector<int> c;
vector<int> d;
vector<int> ary;
int ans = 0;

void dfs(int idx){
    if(idx == N - 1) {
        int sum = 0;
        for(int i = 0; i < Q; i++){
            if(ary[b[i] - 1] - ary[a[i] - 1] == c[i]) sum += d[i];
        }
        ans = max(ans, sum);
        return;
    }
    for(int i = ary[idx]; i <= M; i++){
        ary[idx + 1] = i;
        dfs(idx + 1);
    }
}

int main(){
    read(N, M, Q);
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    ary.resize(N);
    for(int i = 0; i < Q; i++){
        read(a[i], b[i], c[i], d[i]);
    }
    for(int i = 1; i <= M; i++){
        ary[0] = i;
        dfs(0);
    }
    write(ans);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	int n,a; cin >> n >> a;
	if(n%500 <= a) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

//宣言
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//数値
#define MOD 1000000007
#define INF (1<<20)
const double EPS = 1e-10;
const double PI = acos(-1.0);

//操作
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)
#define REPB(i,n) for(int i=n;i>=0;--i)
#define SORT(A) sort(A,A+sizeof(A)/sizeof(A[0]))
#define VSORT(A) sort(A.begin(),A.end())
#define EXIST(s,e) (s.find(e)!=s.end())
#define PB push_back
#define MP make_pair
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);

//DEBUG
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
	ll k; cin >> k;
	ll a[100002] = { 0 };
	REP(i, k) cin >> a[i];
	if (a[k - 1] != 2){
		cout << -1 << endl;
		return 0;
	}
   ll max = 3, min = 2;
	for (int i = k - 2;i >= 0;i--) {
	   if(min%a[i]) min += (a[i]-min%a[i]);
	   if(max>=a[i]) max += a[i] - 1 - (max%a[i]);
	}
	if (max < min) cout << -1 << endl;
	else cout << min << " " << max << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

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

    string S, add[4] = {"dream", "dreamer", "erase", "eraser"};
    cin >> S;

    int len[4];
    for (int i = 0; i < 4; ++i)
        reverse(add[i].begin(), add[i].end());
    reverse(S.begin(), S.end());

    bool flag;
    for (int i = 0; i < S.length() - 4; ++i) {
        flag = false;
        for (int j = 0; j < 4; ++j) {
            if (!S.compare(i, add[j].length(), add[j])) {
                flag = true;
                i += add[j].length() - 1;
                break;
            }
        }
        if (!flag)
            break;
    }
    cout << (flag ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

int main() {
  int n, q;
  while (cin >> n >> q, n > 0) {
    vector<tuple<int, int, string>> eras(n);  // (開始年, 終了年, 元号)
    for (int i = 0; i < n; i++) {
      int diff;
      cin >> get<2>(eras[i]) >> diff >> get<1>(eras[i]);
      get<0>(eras[i]) = get<1>(eras[i]) - diff + 1;
    }
    for (int i = 0; i < q; i++) {
      int year;
      cin >> year;
      bool flag = false;
      for (int j = 0; j < n; j++) {
        if (get<0>(eras[j]) <= year && year <= get<1>(eras[j])) {
          cout << get<2>(eras[j]) << ' ' << year - get<0>(eras[j]) + 1 << endl;
          flag = true;
          break;
        }
      }
      if (!flag) cout << "Unknown" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N,K,A[5005];
signed dpl[5005][5005],dpr[5005][5005];
signed main(){
	cin>>N>>K;
	rep(i,N){
		cin>>A[i];
	}
	dpl[0][0]=1;
	rep(i,N){
		rep(j,K+1){
			dpl[i][j]=(bool)dpl[i][j];
			dpl[i+1][j]|=dpl[i][j];
			dpl[i+1][min(K,j+A[i])]|=dpl[i][j];
		}
	}
	dpr[N][0]=1;
	for(int i=N;i>0;i--){
		rep(j,K+1){
			dpr[i][j]=(bool)dpr[i][j];
			dpr[i-1][j]|=dpr[i][j];
			dpr[i-1][min(K,j+A[i-1])]|=dpr[i][j];
		}
		for(int j=K;j>0;j--)dpr[i][j-1]+=dpr[i][j];
	}
	int ans=0;
	rep(i,N){
		bool flag=true;
		rep(j,K+1){
			if(!dpl[i][j])continue;
			if(dpr[i+1][max(0ll,K-A[i]-j)]-dpr[i+1][K-j])flag=false;
		}
		ans+=flag;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 195968
#include "bits/stdc++.h"
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int N=2e5+5;



void solve(){
	int n;
	cin>>n;
	
	multiset<pii> s,neg;
	int ans = 0;
	
	rep(i,0,n){
		int k,l,r;
		cin>>k>>l>>r;
		if(l>r) s.insert({k,r-l}) , ans += r;
		else  neg.insert({n-k,l-r}) , ans += l;
		// else ans += l;
	}
	
	multiset<int> taken;
	
	while(sz(s)){
		auto x = *s.begin();
		s.erase(s.begin());
		
		if(sz(taken) < x.fr){
			taken.insert(x.sc);
		}
		else if(sz(taken)){
			auto it = taken.end();
			it--;
			if(*it > x.sc){
				taken.erase(it);
				taken.insert(x.sc);
			}
		}
	}
	for(int x:taken) ans -= x;
	
	taken.clear();
	while(sz(neg)){
		auto x = *neg.begin();
		neg.erase(neg.begin());
		if(sz(taken) < x.fr){
			taken.insert(x.sc);
		}
		else if(sz(taken)){
			auto it = taken.end();
			it--;
			if(*it > x.sc){
				taken.erase(it);
				taken.insert(x.sc);
			}
		}
	}
	
	for(int x:taken) ans -= x;
	
	cout<<ans<<"\n";
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SIEVE
		sieve();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 16112
//#i#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <cassert>
#include <fstream>
#include <stdio.h>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

template<typename T>
struct BIT{
    std::vector<T> li;
    int size;
    BIT (int n){
        li=std::vector<T>(n+1,0);
        size=n;
    }
    T sum (int i){
        int s=0;
        while(i>0){
            s+=li[i];
            i-=i & -i;
        }
        return s;
    }
    void add(int i,T x){
        assert(0 < i && i < size);
        while(i<=size){
            li[i]+=x;
            i+=i & -i;
        }
    }
};

using namespace std;

int n;

ll cal(vector<ll> &da, ll mi){//midianがmi以下の区間をカウントする
    int k = n+1;//mi超過-mi以下
    ll ret = 0;
    BIT<ll> bt(300000);
    rip(i,n,0){
        bt.add(k, 1);
        if(da[i] <= mi) k++;
        else k--;
    }
    //vdeb(bt.li);
    rip(i,n,0){
        ret += bt.sum(k-1);
        if(da[n-i-1] <= mi){
            k--;
        }
        else{
            k++;
        }
        bt.add(k, -1);
        //cout << k << endl;vdeb(bt.li);
    }
    return ret;
}

int main(){
    cin >> n;
    vector<ll> da(n);
    rip(i,n,0) cin >> da[i];
    ll le = 0, ri = INT_MAX/2, m = (ll)n*(n+1)/4+1;
    while(ri-le > 1){
        ll mi = (ri+le)/2;
        if(cal(da,mi) >= m){
            ri = mi;
        }
        else{
            le = mi;
        }
    }
    cout << ri << endl;
    //cout << cal(da, 10) << endl;
}


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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int iy[]={0, 0, 1, -1};
int ix[]={1, -1, 0, 0};

int x, y, ans;
string s;
int main(){
	cin >> s;
	y=s.size()-1;
	while(1){
		if(x==y){			
			break;
		}
		if(y-x==1&&s[x]==s[y]){			
			break;
		}
		if(s[x]!=s[y]&&(s[x]!='x'&&s[y]!='x')){
			cout << "-1" << endl;
			return 0;
		}else if(s[x]==s[y]){
			x++; y--;
		}else if(s[x]=='x'){
			x++;
			ans++;
		}else if(s[y]=='x'){
			y--;
			ans++;
		}
		if(x-y==1){
			break;
		}
	}

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

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int n, P, dp[MAXN * 3][MAXN];
void update(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}
int main() {
	read(n), read(P), dp[n * 3][n] = 1;
	for (int i = n * 3; i >= 1; i--)
	for (int j = 0; j <= n; j++) {
		int tmp = dp[i][j];
		if (tmp == 0) continue;
		update(dp[i - 1][j], tmp);
		tmp = 1ll * tmp * (i - 1) % P;
		if (i >= 2 && j != 0) update(dp[i - 2][j - 1], tmp);
		tmp = 1ll * tmp * (i - 2) % P;
		if (i >= 3 && j != 0) update(dp[i - 3][j - 1], tmp);
	}
	int ans = 0;
	for (int i = 0; i <= n; i++)
		update(ans, dp[0][i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 47360
# -*- coding: utf-8 -*-
import numpy as np
import math
import itertools

n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]
# print(xy)

fa = math.factorial(n)
it = [i for i in range(n)]
itt =  list(itertools.permutations(it))

ans = 0

for idxlist in itt:
    for i in range(n-1):
        j = i+1
        # print(i, j)
        # print([idxlist[i]], [idxlist[j]])
        # print(xy[idxlist[i]][0], xy[idxlist[j]][0])

        ans += np.sqrt((xy[idxlist[i]][0]-xy[idxlist[j]][0])**2+(xy[idxlist[i]][1]-xy[idxlist[j]][1])**2)
        # print(ans)
    # print(' ')

print(ans/fa)

Measured memory_bytes: 19048
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<long long>
#define sz(x) (int)x.size()
#define pi pair<long long, long long>
#define endl '\n'
#define _ << ' '
#define FAST_LOG2(x) (sizeof(unsigned long)*8 - 1 - __builtin_clzl((unsigned long)(x)))
#define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = 998244353;
const ll INF = (ll)1e9+1;
const ll N = 1e5;

ll n, m;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("B.txt", "r", stdin);
    #endif
    cin >> n >> m;
    if(n==1) n = 3;
    if(m==1) m = 3;
    cout << (n-2) * (m-2);
}


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

const int MOD = 1e9 + 7;

int main() {
    int h, w;
    cin >> h >> w;
    int sy, sx, gy, gx;
    cin >> sy >> sx >> gy >> gx;
    sy--; sx--; gy--; gx--;
    vector<string> s(h);
    for (auto &i : s) cin >> i;
    vector<vector<int>> grid(h, vector<int>(w, MOD));
    deque<P> que;
    que.push_back({sy, sx});
    grid.at(sy).at(sx) = 0;
    vector<int> dir = { 1, 0, -1, 0, 1 };
    while (!que.empty()) {
        int cy, cx;
        tie(cy, cx) = que.front();
        que.pop_front();
        rep(i,4) {
            int ny = cy + dir.at(i);
            int nx = cx + dir.at(i+1);
            if (ny < 0 || nx < 0 || h <= ny || w <= nx) continue;
            if (s.at(ny).at(nx) == '#') continue;
            if (grid.at(cy).at(cx) < grid.at(ny).at(nx)) {
                grid.at(ny).at(nx) = grid.at(cy).at(cx);
                que.push_front({ ny, nx });
            }
        }
        for (int i = -2; i <= 2; ++i) {
            for (int j = -2; j <= 2; ++j) {
                int ny = cy + i;
                int nx = cx + j;
                if (ny < 0 || nx < 0 || h <= ny || w <= nx) continue;
                if (s.at(ny).at(nx) == '#') continue;
                if (grid.at(cy).at(cx) + 1 < grid.at(ny).at(nx)) {
                    grid.at(ny).at(nx) = grid.at(cy).at(cx) + 1;
                    que.push_back({ ny, nx });
                }
            }
        }
    }
    if (grid.at(gy).at(gx) == MOD) grid.at(gy).at(gx) = -1;
    cout << grid.at(gy).at(gx) << endl;
    return 0;
}

Measured memory_bytes: 9480
#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
                 // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>>
#define vll vector <pair<ll,ll>>
#define vi vector <int>
#define vl vector <ll>
#define pb(v,x) v.push_back(x)
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Sort(v) sort(v.begin(),v.end())
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#include <set>
#include <map>


int main(){
    string s1,s2,u;
    cin>>s1>>s2;
    map<string,int>ma;
    int n1,n2;
    cin>>n1>>n2;
    ma[s1]=n1;
    ma[s2]=n2;
    cin>>u;
    ma[u]--;
    cout<<ma[s1]<<" "<<ma[s2];
}

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

void print(vector<int> v,int n)
{
	for (int i = 0; i < n; i++)
	{
		cout << v[i];
		if (i == n - 1)break;
		cout << " " ;
	}
	cout << endl;
}

int main()
{
	int n, m;
	cin >> n;
	vector<int> v;
	int j, k;
	for (int i = 0; i < n; i++) { cin >> m; v.push_back(m); }
	for (int i = 0; i < n; i++)
	{
		j = v[i];
		for (k = i ; k >= 0; k--)
		{
			if (k>0 && v[k-1] > j)v[k] = v[k-1];
			else  
			{
				v[k] = j;
				break;
			}
		}
		print(v, n);
	}
	return 0;
}

Measured memory_bytes: 3108
k,n = map(int,input().split())
a = list(map(int,input().split()))
#頂点間の距離を出す
distance = []
for i in range(len(a)-1):
    d = abs(a[i+1]-a[i])
    distance.append(d)
a = sum(distance)
distance.append(k-a)
print(sum(distance)-max(distance))

Measured memory_bytes: 26100
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  int n;
  vi v(4);
  cin >> n >> v;
  for (auto &x : v) x--;
  int mini = INF;
  for (int w = 1; w <= n; w++) {
    vpii p(4);
    rep(i, 4) p[i] = {v[i] % w, v[i] / w};
    int d = 0;
    rep(i, 2) d += abs(p[i * 2].first - p[i * 2 + 1].first) + abs(p[i * 2].second - p[i * 2 + 1].second);
    cmin(mini, d);
  }
  cout << mini << endl;
}

Measured memory_bytes: 3120
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  string s;
  cin >> s;

  string ans;

  if(s == "Sunny"){
    ans = "Cloudy";
  } else if(s == "Cloudy"){
    ans = "Rainy";
  } else if(s == "Rainy") {
    ans = "Sunny";
  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

int main()
{
    int n, k;
    string s;
    cin >> n >> k >> s;
    s[k-1] = s[k-1] + 32;
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
f=[list(map(str,input().split()))for i in range(n)]
p=[list(map(int,input().split()))for i in range(n)]
d=[]
for i in range(n):
    c=""
    for j in range(10):
        c+=f[i][j]
    else:
        d.append(int(c,2))
ans=float("-inf")
for i in range(1,1024):
    k=0
    for j in range(n):
        k+=p[j][bin(d[j]&i).count("1")] 
    else:
        ans=max(k,ans)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >>n ;
    vector<int> data(n);
    for (auto &v : data)
        cin >> v;
    sort(data.begin(), data.end());
    cout << data[n / 2] - data[n / 2 - 1] << '\n';
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100000

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  int M;
  cin >> M;

  cout << 24 + 24-M << endl;

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

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

// Main
type Node struct {
	key    int
	parent *Node
	left   *Node
	right  *Node
}

var root *Node

func insert(z *Node) {
	var y *Node
	x := root
	for x != nil {
		y = x
		if z.key < y.key {
			x = y.left
		} else {
			x = y.right
		}
	}
	z.parent = y
	if y == nil {
		root = z
	} else if z.key < y.key {
		y.left = z
	} else {
		y.right = z
	}
}

func find(k int) bool {
	n := root
	for n != nil {
		if n.key == k {
			return true
		} else if k < n.key {
			n = n.left
		} else if n.key < k {
			n = n.right
		}
	}
	return false
}

func printByInOrder(w io.Writer, n *Node) {
	if n.left != nil {
		printByInOrder(w, n.left)
	}
	fmt.Fprint(w, " ", n.key)
	if n.right != nil {
		printByInOrder(w, n.right)
	}
}

func printByPreOrder(w io.Writer, n *Node) {
	fmt.Fprint(w, " ", n.key)
	if n.left != nil {
		printByPreOrder(w, n.left)
	}
	if n.right != nil {
		printByPreOrder(w, n.right)
	}
}

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	for i := 0; i < N; i++ {
		op := sc.nextStr()
		if op == "insert" {
			insert(&Node{sc.nextInt(), nil, nil, nil})
		} else if op == "print" {
			printByInOrder(wtr, root)
			fmt.Fprintln(wtr)
			printByPreOrder(wtr, root)
			fmt.Fprintln(wtr)
		} else {
			if find(sc.nextInt()) {
				fmt.Fprintln(wtr, "yes")
			} else {
				fmt.Fprintln(wtr, "no")
			}
		}
	}

	wtr.Flush()
}



Measured memory_bytes: 23532
s = int(input())

def odd(i):
    return int(3*i+1)

def even(i):
    return int(i/2)

lib = {
    s: 0
}


index = 1

while True:
    if s % 2 == 0:
        s = even(s)
    else:
        s = odd(s)
    
    if s not in lib.keys():
        lib[s] = index
        index += 1
    else:
        index+=1
        break


print(index)

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

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

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    int q;
    cin >> s >> q;
    stack<char> beg;
    queue<char> en;
    int rev = 0;
    while (q--) {
        int t, f;
        cin >> t;
        if (t == 1)
            rev ^= 1;
        else {
            char c;
            cin >> f >> c;
            --f;
            f ^= rev;
            if (f == 0)
                beg.push(c);
            else
                en.push(c);
        }
    }
    string kek = "";
    while (!beg.empty()) {
        kek += beg.top();
        beg.pop();
    }
    kek += s;
    while (!en.empty()) {
        kek += en.front();
        en.pop();
    }
    if (rev)
        reverse(kek.begin(), kek.end());
    cout << kek;

    return 0;
}


Measured memory_bytes: 1328
import java.io.*;

public class Main {

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] in = br.readLine().split(" ");
    int n = Integer.parseInt(in[0]);

    String a = br.readLine();
    String b = br.readLine();
    String c = br.readLine();

    br.close();

    int ans = 0;

    for(int i = 0; i < n; i++){
      int sameNum = 0;
      if(a.charAt(i) == b.charAt(i)) sameNum++;
      if(b.charAt(i) == c.charAt(i)) sameNum++;
      if(c.charAt(i) == a.charAt(i)) sameNum++;

      int add = 0;
      if(sameNum == 0) add = 2;
      if(sameNum == 1) add = 1;

      ans += add;
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 20948
// No.190049041520
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define mk make_pair
#define fi first
#define se second
#define N 500500
const int b1 = 7546823, m1 = 277425539;
const int b2 = 1000033, m2 = 277444379;

inline void inc(int &x, const int &y, const int &Mod) {
    x = (x + y) % Mod;
}

inline int fsp(int x, int k, int p) {
    if (k < 0) k += p - 1;
    int res = 1;
    while (k) {
        if (k & 1) res = 1ll * res * x % p;
        x = 1ll * x * x % p, k >>= 1;
    }
    return res;
}

int n, po1[N], po2[N];
char s[N];
pii h[N];
map<pii, int> num;

int main() {
#ifdef isLOCAL
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#endif

    cin >> n;
    scanf("%s", s + 1);

    int p1 = po1[0] = 1, p2 = po2[0] = 1, c1 = 0, c2 = 0, i1, i2;
    i1 = fsp(b1, -1, m1), i2 = fsp(b2, -1, m2);
    for (int i = 1; i <= n; ++i) {
        if (s[i] == '+') inc(c1, p1, m1), inc(c2, p2, m2);
        if (s[i] == '-') inc(c1, m1 - p1, m1), inc(c2, m2 - p2, m2);
        if (s[i] == '<') p1 = 1ll * p1 * i1 % m1, p2 = 1ll * p2 * i2 % m2;
        if (s[i] == '>') p1 = 1ll * p1 * b1 % m1, p2 = 1ll * p2 * b2 % m2;
        if (c1 < 0) c1 += m1;
        if (c2 < 0) c2 += m2;
        po1[i] = p1, po2[i] = p2;
        h[i] = mk(c1, c2);
    }

    long long ans = 0; ++num[h[n]];
    for (int i = n - 1, tc1, tc2; i >= 0; --i) {
        tc1 = (h[i].fi + 1ll * po1[i] * h[n].fi) % m1;
        tc2 = (h[i].se + 1ll * po2[i] * h[n].se) % m2;
        ans += num[mk(tc1, tc2)], ++num[h[i]];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 39680
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define fi first 
#define se second
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
// ミント
const int mod = 1e9+7 ;
  //998244353;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//昆布
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n,int k){
    return fact[n]*ifact[n-k] ;
  }
  }  c(4000005);
 
mint modpow(ll a,ll b){
 if(b==0) return 1 ;
 mint c= modpow(a,b/2) ;
 if(b%2==1) return c*c*a ;
 else return c*c ;
}

mint komb(ll n,ll m){
  mint x=1 ;mint y=1 ;
  rep(i,m){
    x*= n-i ;
    y*= i+1 ;
  }
  return x/y ;
}

 map<ll,ll> factor(ll n){  //素因数とオーダーをマップで管理
  map <ll,ll> ord ;  
  for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int res=0;
            while(n%i==0){
                n/=i;
                res++;
            }
            ord[i]=res;
        }
    }
   if(n!=1) ord[n]++;
   return ord ;
 }
 
  
 
int main(){
   ll n; cin>>n ;
   vector<ll> A(n) ;
   rep(i,n) cin>>A[i] ;
   mint sum=0ll ;
   rep(i,n) sum+=mint(A[i]) ;
   mint ans= sum*sum ;
   rep(i,n){
     ans-= mint(A[i]*A[i]) ;
   }

   mint bns= ans/mint(2) ;
   cout<<bns<<endl ;

     return 0;
  }
   



Measured memory_bytes: 67360
#include <cstdio>

int main() {
    int k;
    scanf("%d", &k);
    if (k % 2 == 0) {
        printf("%d\n", (k / 2) * (k / 2));
    } else {
        printf("%d\n", (k / 2) * (k / 2 + 1));
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    long N = sc.nextLong();
    long a = 0;
    long c_N = N;
    
    while (N != 0) {
      a += N % 10;
      N /= 10;
    }
    
    System.out.println(c_N % a == 0 ? "Yes" : "No");
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define mp make_pair
#define sqr(x) (x)*(x)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=100007;
const ll inf=0x3f3f3f3f;
const int mod=998244353;
#define rep(i,x,y) for(auto i=(x);i<=(y);++i)
#define dep(i,x,y) for(auto i=(x);i>=(y);--i)
int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int main(){
    string s;
    cin>>s;
    cout<<(s=="ABC"?"ARC":"ABC");
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;
typedef long long ll;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;

    cout << min(n%k, k - n%k) << '\n';

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int mINF = 1e9;
const int MOD = 1e9+7;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int a,b,c; cin >> a >> b >> c;
    if(a+b>=c-1){
        cout << b+c << endl;
    }else{
        cout << a+b+1+b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N,W = map(int,input().split())
dp = [[0]*(W+1) for _ in range(N+1)]
v = [0]*N
w = [0]*N
for i in range(N):
    v[i], w[i] = map(int,input().split())
for i in range(N):
    for j in range(W+1):
        if w[i] <= j:
            dp[i+1][j] = max(dp[i][j], dp[i+1][j-w[i]] + v[i])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[N][W])


Measured memory_bytes: 15692
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>

using namespace std;

int main() {
  int n;
  long long h;
  cin >> n >> h;

  vector<long long> a(n), b(n);
  long long max_a = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    max_a = max(max_a, a[i]);
  }

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

  int ans = 0;
  for (int i = n - 1; i >= 0 && h > 0; i--) {
    if (b[i] >= max_a) {
      h -= b[i];
      ans++;
    }
  }
  ans += max(0LL, (h + max_a - 1) / max_a);
  cout << ans << endl;
}


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

int main(){
  string S;
  cin >> S;
  int ans = 0;
  for(int i = 0;i < 4; i++){
    if(S[i] == '+') ans++;
    else ans--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <iostream>
#include <math.h>

int sum = 0;

void dfs(int n, long long seed, bool has_3, bool has_5, bool has_7) {
	if (has_3 && has_5 && has_7 && seed <= n) {
		sum += 1;
	}
	if (seed > n) {
		return ;
	}
	dfs(n, seed * 10 + 3, true, has_5, has_7);
	dfs(n, seed * 10 + 5, has_3, true, has_7);
	dfs(n, seed * 10 + 7, has_3, has_5, true);
}

int main () {
	int n;
	std::cin >> n;
	dfs(n, 0, false, false, false);
	std::cout << sum << std::endl;
	return 0;
}

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

using namespace std;

int main(){
    int m, d;
    
    cin >> m >> d;
    
    int cnt = 0;
    
    for(int i = 1 ; i <= m ; i++){
        for(int k = 2 ; k <= 9 ; k++){
            for(int e = 2 ; e <= 9 ; e++){
                if(e * 10 + k > d) continue;
                
                if(e * k == i){
                 //   printf("%d %d%d\n", i, e, k);
                    cnt++;
                }
            }
        }
    }
    
    printf("%d\n", cnt);
    
    return 0;
}

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

#define ll long long

// 全探索の問題
// youtubeのほうは桁ごとに出している
// 解説はqueueを用いている
int main()
{
    ll K;
    std::cin >> K;

    std::vector<ll> a;
    for(int i=1; i <= 9; i++) {
        a.push_back(i);
    }

    ll count = 0;
    ll ans;
    while(true) {
        if(K <= a.size()) {
            std::cout << a[K-1] << std::endl;
            return 0;
        }
        K -= a.size();
        std::vector<ll> old;
        swap(old, a);
        for(ll x : old) {
            for(int i=-1; i <= 1; i++) {
                int d = x % 10 + i;
                if(d < 0 || d > 9) continue;
                ll nx = x * 10 + d;
                a.push_back(nx);
            }
        }
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 4612
N = int(input())
l_all = [list(map(int,input().split())) for i in range (N)]
l_all.sort(key = lambda x:x[1])
ryo = 0
for i in range(N):
    if l_all[i][1] < ryo + l_all[i][0]:
        print('No')
        exit()
    else:
        ryo += l_all[i][0]
print('Yes')

Measured memory_bytes: 53600
#include<iostream>
#include<math.h>
using namespace std;



int main(){
    int A, B;
    cin >> A >> B;
    for (double i = 1; i < 1001; i++)
    {
        if(floor(i*0.08) == A && floor(i*0.1) == B)
        {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)

{

int i,n;

int number;

long long int sum=0;

int min=0;

int max=0;

scanf ("%d",&n);

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

{

scanf("%d",&number);

if(i==0)

{

min = number;

max = number;

}

if(number<min) min = number;

if(number>max) max = number;

sum += number;

}

printf("%d %d %lld\n",min,max,sum);

return 0;

}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll a;
    string b;
    cin >> a >> b;
    ll ans = a * (b[0]-'0')*100 + a*(b[2]-'0')*10 + a*(b[3]-'0');
    cout << ans/100 << endl;
}

Measured memory_bytes: 3496