akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int r,c,k;
int val[3000][3000];

ll rec(int i,int j,int cnt){
  static ll mem[3000][3000][4];
  static bool used[3000][3000][4];
  if(cnt > 3) return -1001001001001001;
  if(used[i][j][cnt]) return mem[i][j][cnt];
  used[i][j][cnt] = 1;
  if(i == r-1 && j == c-1){
    if(cnt < 3)return mem[i][j][cnt] = val[i][j];
    else return mem[i][j][cnt] = 0;
  }
  ll ret = -1001001001001001;
  if(i < r-1){
    if(cnt<3)ret = max({rec(i+1,j,0),rec(i+1,j,0)+val[i][j],ret});
    else ret = max({rec(i+1,j,0),ret});
  }
  if(j < c-1){
    if(cnt<3)ret = max({rec(i,j+1,cnt),rec(i,j+1,cnt+1)+val[i][j],ret});
    else ret = max({rec(i,j+1,cnt),ret});
  }
  return mem[i][j][cnt] = ret;
}

int main(){
  cin >> r >> c >> k;
  for(int i = 0; i < k; ++i){
    int y,x; cin >> y >> x;
    y--;x--;
    int v; cin >> v;
    val[y][x] = v;
  }
  cout << rec(0,0,0) << endl;
  return 0;
}


Measured memory_bytes: 355532
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int Z =0;
    //--------------
    int n,a,b;
    cin>>n>>a>>b;

    cout<<min(n*a,b)<<endl;


    //cout<<endl;
    


    //---------------------
    cin>>Z;

    return 0;
}

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

using namespace std;
typedef long long int ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//chmax=change max , chmin=change min

#define KAZARI 2
#define INF 1 << 30

int main(){
    int n,k; cin >> n >> k;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin >> h[i];
    }

    vector<int> dp(n,INF);

    dp[0]=0;

    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            chmin(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }

    cout << dp[n-1] << endl;

}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    string n;
    cin >> n;
    if (n[n.size() - 1] == 's')
        n += "es";
    else
        n += "s";

    cout << n << endl;

    return 0;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> broken(n+1);
    rep(i,m) {
        int a;
        cin >> a;
        broken[a] = 1;
    }
    vector<int> dp(n+2);
    const int mod = 1000000007;
    dp[n] = 1;
    for (int i = n-1; i >= 0; i--) {
        if (broken[i]) {
            dp[i] = 0;
            continue;
        }
        dp[i] = (dp[i+1] + dp[i+2]) % mod;
    }
    cout << dp[0] << endl;
     return 0;
}    


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int call(int n){
    int x;
    for (int i = 1; i <= n; i++){
        x = i;
        if ( x % 3 == 0){
            cout << " " << i;
        }else{
            while (x){
                if ( x % 10 == 3 ){
                    cout << " " << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;
    return 0;
}
int main(){
    int n;
    cin >> n;
    // if(n){
    //      cout << "ok";
    //}
    call(n);
    return 0;
}


Measured memory_bytes: 3112
#include<iostream>
using namespace std;
int main()
{
	long long x=0x3f3f3f3f,y=0x3f3f3f3f,a,b,ans;
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		if(b<y)
		{
			x=a;
			y=b;
		}
		ans=x+y;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl   = input.ReadLine().Split(' ');
        var a     = int.Parse(spl[0]);
        var b     = int.Parse(spl[1]);

        var aa = "";
        for(int i=0; i<b; i++) {
            aa += a;
        }
        
        var bb = "";
        for(int i=0; i<a; i++) {
            bb += b;
        }

        return aa.CompareTo(bb) < 0 ? aa : bb;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl =strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}

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

int main(){
	int n, t;
	cin >> n;
	vector<int> a(n+1);
	vector<bool> b(n+1);
	int cnt=0;

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

	for(int i=n; i>=1; i--){
		t = 0;
		for(int j=2*i; j<=n; j+=i){
			t += b[j];
		}
		t = t%2;
		if(t == a[i]){
			b[i] = 0;
		}else{
			b[i] = 1;
			cnt++;
		}
	}
	cout << cnt << endl;
	if(cnt==0){
		return 0;
	}
	for(int i=1; i<=n; i++){
		if(b[i] == 1){
			cout << i << " ";
		}
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 1792
import sys
n, m = map(int, input().split())
    
array1 = [list(input()) for _ in range(n)]
array2 = [list(input()) for _ in range(m)]
    
for i in range(n-m+1):
    for j in range(n-m+1):
        for k in range(m):
            if array1[i+k][j:j+m] != array2[k][:]:
                break
        else:
            print("Yes")
            sys.exit()
print("No")      


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    int a, b, c, k;
    scanf("%d%d%d%d", &a, &b, &c, &k);
    int ans = 0;
    if(a > k) ans += k;
    else ans += a, k -= a;
    k = max(0, k - b);
    ans -= k;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3828
n = gets.chomp.to_i
x = []
y = []
h = []

n.times do |i|
  x[i], y[i], h[i] = gets.chomp.split.map(&:to_i)
end

101.times do |xx|
  101.times do |yy|
    highest = nil
    n.times do |i|
      if h[i] != 0
        highest = h[i] + (x[i] - xx).abs + (y[i] - yy).abs
        break
      end
    end
    flag = true
    n.times do |i|
      if h[i] != [highest - (x[i] - xx).abs - (y[i] - yy).abs, 0].max
        flag = false
        break
      end
    end
    if flag
      puts "#{xx} #{yy} #{highest}"
      exit
    end
  end
end


Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

  int n, c, k;
  cin >> n >> c >> k;
  vector<int> T(n);
  for (int i = 0; i < n; i++) {
    cin >> T[i];
  }
  sort(T.begin(), T.end());
  int ans = 0;
  for (int i = 0; i < n;) {
    const int r = T[i] + k;
    int x = 0;
    while (i < n && T[i] <= r && x + 1 <= c) {
      ++i;
      ++x;
    }
    ++ans;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
//https://atcoder.jp/contests/abc157/tasks/abc157_d
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}

struct uf_tree {
    std::vector<int> parent;
    int __size;
    uf_tree(int size_) : parent(size_, -1), __size(size_) {}
    void unite(int x, int y) {
        if ((x = find(x)) != (y = find(y))) {
            if (parent[y] < parent[x]) std::swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
            __size--;
        }
    }
    bool is_same(int x, int y) { return find(x) == find(y); }
    int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    int size(int x) { return -parent[find(x)]; }
    int size() { return __size; }
};

//https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/1/DSL_1_A
// using namespace std;
// using ll=int64_t;
// #define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
// #define REP(i,n)  FOR(i,0,n)
// int main() {
//     ll n, q; cin>>n>>q;
//     uf_tree uft(n);
//     REP(i,q){
//         ll com,x,y; cin>>com>>x>>y;
//         if (com==0){ //連結
//             uft.unite(x,y);
//         }else{
//             cout<<uft.is_same(x,y)<<endl;
//         }
//     }
//     return 0;
// }

int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-3.in");
    //std::ifstream in("./input.txt");
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N, M, K; cin>>N>>M>>K;
    vector<set<ll>> frd(N+1);
    vector<set<ll>> blk(N+1);
    uf_tree uft(N+1);
    REP(i,M){
        ll a,b; cin>>a>>b;
        frd.at(a).insert(b);
        frd.at(b).insert(a);
        uft.unite(a,b);
    }
    REP(i,K){
        ll a,b; cin>>a>>b;
        blk.at(a).insert(b);
        blk.at(b).insert(a);
    }

    FOR(i,1,frd.size()){
        ll ans=uft.size(i)-frd.at(i).size()-1;
        for(auto& b: blk.at(i)){
            if(uft.is_same(i,b))--ans;
        }
        if(i!=1)cout<<" ";
        cout<<ans;
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 29312
S = input()
N = len(S)
MOD = 10**9 + 7

# dp[i+1][j]: i桁目まで見たとき、j=1でSより厳密に小さく、13で割った時あまりがjになる個数
dp = [[0 for _ in range(13)] for _ in range(N+1)]
dp[0][0] = 1

"""
遷移
dp[i][j] -> dp[i+1][j+m] : i-1まで見た時あまりがkになる数字について、末尾にS[i]が追加されると、i-1までのあまりは10倍になるから、10*j+mを13で割ったあまりが新たなあまり
: S[i]が？の場合可能
dp[i][j] -> dp[i+1][k]   : S[i]もS[i-1]も？ではない

"""

for i in range(N):
    for j in range(13):
        if S[i] == "?":
            # ?に0~9がいれられる
            for num in range(10):
                dp[i+1][(10*j + num) % 13] += dp[i][j]
                dp[i+1][(10*j + num) % 13] %= MOD
        else:
            # i桁目の値は固定
            dp[i+1][(10*j + int(S[i])) % 13] += dp[i][j]
            dp[i+1][(10*j + int(S[i])) % 13] %= MOD


print(dp[-1][5])

Measured memory_bytes: 66140
import math
#sys.exit()
#sorted( ,reverse=True)
R = int(input())
#S,T = map(int, input().split())
#A = list(map(int, input().split()))
#print(N)
#print(S,T)
#print(A)

#print('Yes')
#print('No')

print(2*R*math.pi)


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

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

    int sum;
    string ans;
// bit全探索
    for (int bit = 0; bit < 8; bit++) {
        sum = abcd.at(0) - '0';
        ans = abcd.at(0);
        for (int i = 0; i < 3; i++) {
            if (bit & (1<<i)) {
                sum += abcd.at(i + 1) - '0';
                ans += '+';
                ans += abcd.at(i + 1);
            }
            else {
                sum -= abcd.at(i + 1) - '0';
                ans += '-';
                ans += abcd.at(i + 1);
            }
        }
        
        if (sum == 7) {
            ans += "=7";
            cout << ans << endl;
            break;
        }
    } 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
//void chmin(int &a, int b) { if (a > b) a = b; }
//void chmax(int &a, int b) { if (a < b) a = b; }

const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    double n,k,ans = 0.0;
    vector<double> kakuritu;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        double p;
        cin >> p;
        double bunsi = 0.0;
        for (double j = 1; j <= p; ++j) {
            bunsi += j;
        }
        bunsi /= p;
        kakuritu.push_back(bunsi);
    }
    double tmp = 0.0;
    for (int i = 0; i < k; ++i) {
        tmp += kakuritu[i];
    }
    ans = tmp;

    for (int i = k; i < n; ++i) {
        double tmp2 = tmp-kakuritu[i-k]+kakuritu[i];
        ans = max(ans,tmp2);
        tmp = tmp2;
    }

    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func main() {
	line := nextLine()
	N, _ := strconv.Atoi(line)
	S := nextLine()
	dp := make([][]int, N+5)
	for i := range dp {
		dp[i] = make([]int, N+5)
	}
	for i := N - 1; i > -1; i-- {
		for j := N - 1; j > -1; j-- {
			if S[i] != S[j] {
				dp[i][j] = 0
			} else {
				dp[i][j] = dp[i+1][j+1] + 1
			}
		}
	}
	ans := 0
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if i >= j {
				continue
			}
			ans = max(ans, min(dp[i][j], j-i))
		}
	}
	fmt.Println(ans)
}


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

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

	for(int bit=0;bit<(1<<n);++bit){
		cout<<bit<<":";
		for(int i=0;i<n;++i){
			if(bit>>i&1) {
				cout<<" "<<i;
			}
		}
		cout<<endl;
	}
  return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)
#define SP(i)           fixed << setprecision(i) 

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll n,m;
    cin>>n>>m;
    ll arr[n];
    ll sum=0;
    rep(i,0,n){cin>>arr[i];sum+=arr[i];}
    sort(arr,arr+n);
    reverse(arr,arr+n);
    ll meow=ceil(sum/(4.0*m));
    if (arr[m-1]>=meow){
    	cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;

}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
const double inf=1e9;
typedef long long ll;
typedef pair<ll,ll>pr;
const ll mod=1e9+7;
ll _pow(ll  a,ll b) {
    ll ans=1;
    while(b) {
        if(b&1)
            ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
vector<int>a[maxn];
int n,d;
int getans(int pos1,int pos2){
  int num=0;
  for(int i=0;i<d;i++){
    num+=(a[pos1][i]-a[pos2][i])*(a[pos1][i]-a[pos2][i]);
  }
  return num;
}

int main(){
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin>>n>>d;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=d;j++){
      int x;
      cin>>x;
      a[i].push_back(x);
    }
  }
  int id=-1,minx=-1,num=0;
  for(int i=1;i<=n;i++){
    for(int j=i+1;j<=n;j++){
      int s=getans(i,j);
      //cout<<s<<" "<<i<<endl;
      int s1=sqrt(s);
      if(s==s1*s1){
        num++;
      }
    }
  }
  cout<<num<<endl;
  return 0;
}


Measured memory_bytes: 4992
#include <iostream>

using namespace std;
int main(){
	string str;
	cin >> str;
	int count_0,count_1;
	count_0 = count_1 = 0;
	for(char c: str){
		if(c=='0'){
			count_0++;
		}else{
			count_1++;
		}
	}
	cout << 2*min(count_0,count_1) << endl;
	return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3




def main():
    s = input()
    Q = int(input())
    q = [list(input().split()) for i in range(Q)]

    # print(q)

    rq = [0] * (Q+1)
    for i in range(Q):
        if len(q[i]) == 1:
            rq[i+1] = rq[i] + int(q[i][0])
        else:
            rq[i+1] = rq[i]
        rq[i+1] %= 2

    b = []
    a = []

    for i in range(Q):
        if len(q[i]) != 1:
            if (q[i][1] == '1' and rq[i+1] == 0) or (q[i][1] == '2' and rq[i+1] == 1):
                b.append(q[i][2])
            else:
                a.append(q[i][2])

    b = b[::-1]

    if rq[Q]%2 == 1:
        b, a = reversed(a), reversed(b)
        s = s[::-1]


    ans = ''.join([''.join(b), s, ''.join(a)])

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 34404
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
  ll A,B,K;
  cin>>A>>B>>K;

  deque<ll> deq;
  
  for(ll i=A;i<=A+K-1;++i){
  if(i>=A && i<=B) deq.push_back(i);
  }
  for(ll i=B-K+1;i<=B;++i){
  if(i>=A && i<=B) deq.push_back(i);
  }

sort(deq.begin(),deq.end());
deq.erase(unique(deq.begin(),deq.end()),deq.end());

ll m=deq.size();

for(ll i=0;i<m;++i){
cout<<deq[i]<<endl;
}

}

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

int main() {
  ll n; cin >> n;
  ll mod = (ll)1e9+7;
  vector<ll> A(n),B(n+1,0);
  
  rep(i, n){
    cin >> A[i];
    B[i+1] = B[i] + A[i];
  }
  
  ll ans = 0;
  
  rep(i, n){
    ll sum = (B[n] - B[i+1]) % mod; 
    ans += A[i] * sum ;
    ans %= mod;
  }
    
  cout << ans << endl;
}

Measured memory_bytes: 6304
N = int(input())
a = list(map(int, input().split()))

num = [0] * 100005
for i in range(N):
    num[a[i]] += 1
ans = 0
for i in range(100001):
    ans = max(ans, num[i-1] + num[i] + num[i+1])
print(ans)


Measured memory_bytes: 13964
#include<stdio.h>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
string str[30];
char in[100];
string q[100];
int pts[100];
int conv[30];
int to[100];
int ans[100];
int sz;
int n;
int dfs(){
	int at=-1;
	int len=0;
	int pt=0;
	for(int i=0;i<sz;i++){
		if(!~to[i]){
			if(pt<pts[i]){
				at=i;len=q[i].size();pt=pts[i];
			}
		}
	}
	if(!len){
		for(int i=0;i<sz;i++)ans[i]=to[i];
		return 1;
	}
	int ret=0;
	for(int i=0;i<n;i++){
		if(str[i].size()!=len)continue;
		bool ok=true;
		for(int j=0;j<str[i].size();j++){
			if((~conv[str[i][j]-'A']&&conv[str[i][j]-'A']!=q[at][j]-'A')||
			(~conv[q[at][j]-'A']&&conv[q[at][j]-'A']!=str[i][j]-'A'))ok=false;
		}
		if(ok){
			int rev[26];
			for(int j=0;j<26;j++)rev[j]=conv[j];
			to[at]=i;
			for(int j=0;j<str[i].size();j++){
				if(!~conv[str[i][j]-'A']){
					conv[str[i][j]-'A']=q[at][j]-'A';
				}else if(conv[str[i][j]-'A']!=q[at][j]-'A')ok=false;
				if(!~conv[q[at][j]-'A']){
					conv[q[at][j]-'A']=str[i][j]-'A';
				}else if(conv[q[at][j]-'A']!=str[i][j]-'A')ok=false;
			}
			if(ok)ret+=dfs();
			to[at]=-1;
			for(int j=0;j<26;j++)conv[j]=rev[j];
		}
		if(ret>1)return 2;
	}
	return ret;
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		n=a;
		for(int i=0;i<a;i++){
			scanf("%s",in);
			str[i]=in;
		}
		sz=0;
		while(1){
			scanf("%s",in);
			if(in[strlen(in)-1]=='.'){
				in[strlen(in)-1]=0;
				q[sz++]=in;
				break;
			}
			q[sz++]=in;
		}
		for(int i=0;i<26;i++)conv[i]=-1;
		for(int i=0;i<sz;i++)to[i]=-1;
		for(int i=0;i<sz;i++)pts[i]=0;
		for(int i=0;i<26;i++){
			for(int j=0;j<sz;j++){
				bool ok=false;
				for(int k=0;k<q[j].size();k++){
					if(q[j][k]=='A'+i)ok=true;
				}
				if(ok)pts[j]++;
			}
		}
		int ret=dfs();
		if(ret>1)printf("-.\n");
		else{
			for(int i=0;i<sz;i++){
				if(i)printf(" ");
				printf("%s",str[ans[i]].c_str());
			}
			printf(".\n");
		}
	}
}

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

string a ,b;

int main(){
  cin >> a >> b;
  int A = a.size();
  int B = b.size();
  if(A > B){
    cout << "GREATER" << endl;
  }
  else if(A < B){
    cout << "LESS" << endl;
  }
  else if(a < b){
    cout << "LESS" << endl;
  }
  else if(a > b){
    cout << "GREATER" << endl;
  }
  else{
    cout << "EQUAL" << endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	for(int y = 1; y <= 1000; ++y){
		for(int x = 1; x <= 1000; ++x){
			if(a*y == b*x + c){
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3660
a, b, c, d = gets.split.map(&:to_i)
t = b - (a-1)
c_tmp = b/c - (a-1)/c
d_tmp = b/d - (a-1)/d
cd_tmp = b/c.lcm(d) - (a-1)/c.lcm(d)
puts t - c_tmp - d_tmp + cd_tmp


Measured memory_bytes: 1916
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] stones = new int[n];
        for (int i = 0; i < n; i++) {
            stones[i] = scanner.nextInt();
        }
        int[] dp = new int[n];
        int[] cal = new int[n];
        System.out.println(minInjured(stones, n - 1, dp, cal));
    }

    public static int minInjured(int[] stones, int n, int[] dp,int[] cal) {
        if (n == 0) {
            return 0;
        }

        if (n == 1) {
            return Math.abs(stones[1] - stones[0]);
        }

        if (cal[n] == 1) {
            return dp[n];
        }

        if (cal[n-1] != 1) {
            dp[n - 1] = minInjured(stones, n - 1, dp, cal);
            cal[n - 1] = 1;
        }
        if (dp[n - 2] != 1) {
            dp[n - 2] = minInjured(stones, n - 2, dp, cal);
            cal[n - 2] = 1;
        }
        
        dp[n] = Math.min(dp[n - 1] + Math.abs(stones[n] - stones[n - 1]),
                dp[n - 2] + Math.abs(stones[n] - stones[n - 2]));
        return dp[n];
    }
}

Measured memory_bytes: 63824
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int dp[100010];
const int M = 1000000007;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<bool> fl(n + 1, false);
    rep(i, m)
    {
        int x;
        cin >> x;
        fl[x] = true;
    }
    dp[0] = 1;
    rep(i, n + 1)
    {
        if (fl[i] == true)
            continue;
        dp[i + 1] += dp[i];
        dp[i + 2] += dp[i];
        dp[i + 1] %= M;
        dp[i + 2] %= M;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
 
char t[6] = { 'M', 'A', 'R', 'C', 'H' };
 
int main(){
	int n;
	long long int c[5] = {};
	string s;
	long long int ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> s;
		for (int j = 0; j < 5; j++){
			if (s[0] == t[j]){
				c[j]++;
			}
		}
	}
	/*組み合わせは5C3で10通り*/
	for (int i = 0; i < 5; i++){
		for (int j = i+1; j < 5; j++){
			for (int k = j+1; k < 5; k++){
				ans += c[i] * c[j] * c[k];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
 
int main(){
    string s ;
    cin>>s;
    vector<ll> n;

    if(s[0]=='<') n.push_back(0);
    char before = 'A';
    rep(i, s.length()){
        if(s[i]==before){
            n[n.size()-1]++;
        }else{
            n.push_back(1);
            before = s[i];
        }
        if(i < s.length() && s[i]=='>' && s[i+1]=='<'){
            n.push_back(0);
        }
    }

    if(s[s.size()-1]=='>') n.push_back(0);

    ll A[n.size()];
    rep(i, n.size()) A[i] = 0;
    ll sum = 0;
    if (n[1]==0){
        REP(i, 1, n[0]+1) sum += i;
        A[0] = sum;
    }
    REP(i, 2, n.size()){

        if(n[i]==0){
                ll ma = max(n[i-1], n[i-2]);
                ll mi = min(n[i-1], n[i-2]);
                sum = 0;
                REP(i, 1, ma+1){
                    sum += i;
                }
                REP(i, 1, mi){
                    sum += i;
                }
                A[i] = sum;

            
        }
    }
    if(n[n.size()-1]!=0){
        sum = 0;
        REP(i, 1, n[n.size()-1]+1) sum += i;
        A[n.size()-1] = sum;
    }

    ll ans = 0;
    rep(i, n.size()) ans += A[i];


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


Measured memory_bytes: 7412
#include <iostream>
#include <vector>
#include <algorithm>

int gcd(int m, int n)
{
  while (n)
  {
    if (m > n) std::swap(m, n);
    n %= m;
  }
  return m;
}

int main()
{
  int N, X;
  std::cin >> N >> X;
  std::vector<int> x(N);
  int ans = 1;
  for (int i = 0; i < N; i++)
  {
    std::cin >> x.at(i);
    x.at(i) = std::abs(x.at(i) - X);
    if (i == 0)
      ans = x.at(i);
    else
      ans = gcd(x.at(i), ans);
  }
  std::cout << ans << std::endl;
}


Measured memory_bytes: 768
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cmath>

using namespace std;

int main(int argc, char *argv[]) {
	int n, d;
	cin >> n >> d;
	int ans = (n + 2 * d) / (2 * d + 1);
	cout << ans << endl;
	return 0;
}


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

int main() {
  int N,x;
  cin>>N>>x;
  
  vector<int> vec(N);
  for (int i=0;i<N;i++) {
    cin >> vec.at(i);
  }
  int A=0;
  sort(vec.begin(), vec.end());
  for (int i=0;i<N;i++) {
    x-=vec.at(i);
    if (x<0) {
      break;
    }
    A++;
  }
  if (x>0) {
    A--;
  }
cout << A << endl;    
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
typedef std::vector <int> vi;
vi PRIMES;
vi prime(int n){
	int i=0,j=1,h=(n+1)/2,x;
	vi s(h),p;
	while(j<=n){
		s[i++]=j;
		j+=2;
	}
	for (i=1;i<=(int)pow(n,0.5);i++)
		if (x=s[i]) for (j=i+x;j<h;j+=x) s[j]=0;
	s[0]=2;
	for (i=0;i<h;i++) if(s[i]!=0) p.push_back(s[i]);
	return p;
}
int main(void){
	int n,s;
	PRIMES=prime(105000);
	while (true){
		std::cin>>n; if (n==0) break;
		s=0;
		for (;n--;) s+=PRIMES[n];
		std::cout<<s<<"\n";
	}
} 

Measured memory_bytes: 1360
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"YES"<<endl
#define prN         cout<<"NO"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5],B[MAXN+5],C[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	sc(n);
	v=oo;
	f1(i,n-1){
		sc(A[i]);
		ans+=min(v,A[i]);
		v=A[i];
	}
	ans+=v;
	pr(ans);
	
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	if(fopen("locin.txt", "r"))INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	}
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

Measured memory_bytes: 2304
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0558
AC
"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline


def bfs(field, sx, sy, gx, gy):
    """
    ??????????????°???????????´????????°????????§????????¢????±???????
    :param field:
    :param sx: ??????????????°????????§?¨?
    :param sy:
    :param gx: ??´????????°????????§?¨?
    :param gy:
    :return: ????????????????????´???????????§????????¢
    """
    # ????????????????§????????????´????????§?¨?????????????
    dy = [-1, 1, 0, 0]
    dx = [0, 0, -1, 1]

    # ??°???????????????(?§????????????£????????????????????????????????§??????????????¨)
    Y = len(field)
    X = len(field[0])
    d = [[float('inf')] * X for _ in range(Y)] #  ??????????????°?????????????????¢???INF??§?????????

    # ???????????????????????????????????°???????????´????????°????????§????????¢????±???????
    Q = deque()
    Q.append((sx, sy))
    d[sy][sx] = 0               #  ??????????????°??????????????????0
    while Q:
        cx, cy = Q.popleft()        #  ?????¨??°?????§?¨?
        if cx == gx and cy == gy:
            break
        for i in range(4):
            nx = cx + dx[i]
            ny = cy + dy[i]
            # ?§?????????? ??°????????????????????????????????? and ?£?????????£???????????? and ??¢?????¢?´¢?????§?????? ??´???
            if (0 <= nx < X) and (0 <= ny < Y) and field[ny][nx] != 'X' and d[ny][nx] == float('inf'):
                Q.append((nx, ny))
                d[ny][nx] = d[cy][cx] + 1
    return d[gy][gx]


def solve(field, N):
    # ??????????????°???(S)??¨??´????????°???(N)?????????
    pos = [[None, None] for _ in range(N+1)]
    for y, row in enumerate(field):
        for mark in 'S123456789':
            if mark in row:
                if mark == 'S':
                    pos[0] = [row.index(mark), y]
                else:
                    pos[int(mark)] = [row.index(mark), y]

    total_move = 0
    start = pos[0]
    for goal in pos[1:]:
        sx, sy = start
        gx, gy = goal
        res = bfs(field, sx, sy, gx, gy)
        # print('From: ({}, {}) -> To: ({}, {}), step: {}'.format(sx, sy, gx, gy, res))
        # print('min move: {}'.format(abs(sx-gx) + abs(sy-gy)))
        total_move += res
        start = goal

    return total_move


def main(args):
    # N = 9
    # data = [
    #     '.X...X.S.X',
    #     '6..5X..X1X',
    #     '...XXXX..X',
    #     'X..9X...X.',
    #     '8.X2X..X3X',
    #     '...XX.X4..',
    #     'XX....7X..',
    #     'X..X..XX..',
    #     'X...X.XX..',
    #     '..X.......'
    # ]
    H, W, N = map(int, input().split())
    data = [input().strip('\n') for _ in range(H)]
    field = [list(x) for x in data] #  data????????????????????????????????????????????????
    result = solve(field, N)
    print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 38364
#include<stdio.h>

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

  scanf("%d%d%d",&a,&b,&c);
  if( b < a ){
    ex = a;
    a = b;
    b = ex;
  }

  if( a < c && b < c )  printf("%d %d %d\n",a,b,c);
  else if( a < c && c < b )  printf("%d %d %d\n",a,c,b);
  else printf("%d %d %d\n",c,a,b);

  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
#define bas 1000
#define lst3 1000000000
int n,c[410][4],need[4][4];
ll val[410],nval[4];
map<ll,int> mp;

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;
}

void insert(ll now,int val)
{
	rep(i,0,3)
	{
		mp[now]+=val;
		now=now/bas+(now%bas)*lst3;
	}
}

int calc(ll val,int pos)
{
	rep(i,1,3-pos) val/=bas;
	return val%bas;
}

int main()
{
	n=read();
	rep(i,1,n) 
	{
		rep(j,0,3) c[i][j]=read();
		rep(j,0,3) val[i]=val[i]*bas+c[i][j];
		//cout << val[i] << " ";cout << endl;
		insert(val[i],1);
	}
	ll ans=0;
	rep(i,1,n) 
	{
		insert(val[i],-1);
		rep(j,i+1,n)
		{
			insert(val[j],-1);
			rep(k,0,3)
			{
				need[0][0]=calc(val[j],1);need[0][1]=calc(val[j],0);need[0][2]=calc(val[i],1);need[0][3]=calc(val[i],0);
				need[1][0]=calc(val[i],1);need[1][1]=calc(val[j],0);need[1][2]=calc(val[j],3);need[1][3]=calc(val[i],2);
				need[2][0]=calc(val[j],3);need[2][1]=calc(val[j],2);need[2][2]=calc(val[i],3);need[2][3]=calc(val[i],2);
				need[3][0]=calc(val[j],1);need[3][1]=calc(val[i],0);need[3][2]=calc(val[i],3);need[3][3]=calc(val[j],2);
				rep(p,0,3) 
				{
					nval[p]=0;
					rep(q,0,3) nval[p]=nval[p]*bas+need[p][q];
				}
				ll nans=1;int del=-1;
				rep(p,0,3)
				{
					if (mp[nval[p]]) 
					{
						nans*=mp[nval[p]];
						insert(nval[p],-1);del=p;
					}
					else {nans=0;break;}
				}
				rep(p,0,del) insert(nval[p],1);
				//cout << nans << endl;
				ans+=nans;
				val[j]=val[j]/bas+(val[j]%bas)*lst3;
			}
			insert(val[j],1);
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 20352
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int isprime(int n){
    int count =0;
    for(int i=2;i<=sqrt(n);i++)
    if(n%i==0)count++;
    if(count)return 0;
    return 1;
}
int main()
{
  int x,y;
  cin>>x>>y;
  if(y%2)cout<<"No";
  else{
      int maxi ,mini;
      if(y%4==0)mini = y/4;
      else mini = 1+y/4;
      maxi = y/2;
      if(x>=mini&&x<=maxi)cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
  }
     return 0;
}




Measured memory_bytes: 3644
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________
# ... 最小側の制約も確認した？
# ... オーバーフローしない？
a, b, c = map(int, input().split())
for i in range(1, b+1):
    if (a*i-c)%b: i+=1
    else:
        print("YES")
        exit()
print("NO")

Measured memory_bytes: 9388
S = input()
Ls = ['L', 'U', 'D'] #偶数
Rs = ['R', 'U', 'D'] #奇数
f = True
for i in range(len(S)):
    if (i%2 == 0 and S[i] in Rs) or (i%2 == 1 and S[i] in Ls):
        pass
    else:
        f = False
        break
print('Yes' if f else 'No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1e9
#define MOD 1e9+7
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

ll N,W,sm=0;
vector<ll> v1,v2,v3,v4;
ll w0,w,v;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N>>W;
    REP(i,N){
        cin>>w>>v;
        if(i==0){
            w0 = w;
            v1.push_back(v);
        }
        else{
            ll dif = w-w0;
            if(dif==0) v1.push_back(v);
            if(dif==1) v2.push_back(v);
            if(dif==2) v3.push_back(v);
            if(dif==3) v4.push_back(v);
        }
    }
    VRSORT(v1);
    VRSORT(v2);
    VRSORT(v3);
    VRSORT(v4);

    for(int i=1;i<v1.size();i++) v1[i]+=v1[i-1];
    for(int i=1;i<v2.size();i++) v2[i]+=v2[i-1];
    for(int i=1;i<v3.size();i++) v3[i]+=v3[i-1];
    for(int i=1;i<v4.size();i++) v4[i]+=v4[i-1];
    
    v1.insert(v1.begin(), 0);
    v2.insert(v2.begin(), 0);
    v3.insert(v3.begin(), 0);
    v4.insert(v4.begin(), 0);

    ll ans=0;
    REP(i,v1.size()){
        REP(j,v2.size()){
            REP(k,v3.size()){
                REP(l,v4.size()){
                    if(i*w0 + j*(w0+1) + k*(w0+2) + l*(w0+3)<=W) ans = max(ans,v1[i]+v2[j]+v3[k]+v4[l]);
                }
            }
        }
    }
    cout<<ans<<endl;
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

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

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

// 最大公約数
LL gcd(LL a, LL b){
    if(b == 0){
        return a;
    }
   if (a%b == 0) {
       return(b);
   }
   else {
       return(gcd(b, a%b));
   }
}

void Main()
{
    int n;cin>>n;

    vector<LL> a(n+2);
    vector<LL> l(n+2);
    vector<LL> r(n+2);
    REP(i,n){
        cin>>a[i+1];
    }

    REP(i,n){
        l[i+1] = gcd(l[i],a[i+1]);
        //dump(i)
        //dump(l[i+1])
    }
    PER(i,n){
        r[i+1] = gcd(r[i+2],a[i+1]);
        //dump(i)
        //dump(r[i+1])
    }

    dump(r[4])

    LL result = 0;
    REP(i,n){
        //dump(i)
        //dump(l[i])
        //dump(r[i+2])
        //dump(gcd(l[i],r[i+2]))
        result = max(result,gcd(l[i],r[i+2]));
    }

    cout<<result<<endl;

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<pair<int,int>,null_type, less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e8+1, mod=1e9+7;

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int n,i;
	cin>>n;
	int x=0,y=0,z=0;
	for(i=0;i<n;i++){
		int a,b,c, nx,ny,nz;
		cin>>a>>b>>c;
		
		nx=a+max(y,z);
		ny=b+max(x,z);
		nz=c+max(x,y);
		x=nx; y=ny; z=nz;
	}
	
	cout<<max(x,max(y,z));
}
// check for any potential overflow before submitting



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

namespace CSharpSample01
{

    
    class Program
    {


        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int H = int.Parse(str[0]);
            int W = int.Parse(str[1]);
            str = Console.ReadLine().Split(' ');
            int h = int.Parse(str[0]);
            int w = int.Parse(str[1]);

            int ans = 0;
            for(int i = w + 1; i <= W; i++)
            {
                for(int j = h + 1; j <= H; j++)
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);

        }
    }
}


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

int isPrime(int x){
  int i;
  if(x<2) return 0;
  else if(x==2) return 1;
  if(x%2 == 0) return 0;
  for(i=3;i*i<=x;i+=2){
    if(x%i == 0) return 0;
  }
  return 1;
}

int main() {
  int n, x;
  int cnt = 0;
  cin >> n;
  for(int i; i<n;i++){
    cin >> x;
    if(isPrime(x)) cnt++;
  }
  cout << cnt << endl;
}



Measured memory_bytes: 3052
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define y0 y_0
#define y1 y_1
#define yn y_n
#include <assert.h>
#include <algorithm>
#include <vector>
using namespace std;

int n;
char a[305][305];

bool symmetric(int r0,int c0,int w){
	for(int i=0;i<w;i++)for(int j=0;j<w;j++){
		if(a[r0+i][c0+j]!=a[r0+j][c0+i])return false;
	}
//	printf("Symmetric(%d,%d,%d) is true\n",r0,c0,w);
	return true;
}

bool symmetric2(int r0,int c0,int r1,int c1,int w,int h){
	for(int i=0;i<h;i++)for(int j=0;j<w;j++){
		int i0=r0+h-1-i,j0=c0+w-1-j;
		int i1=r1+j,j1=c1+i;
		if(a[i0][j0]!=a[i1][j1])return false;
	}
//	printf("Symmetric2(%d,%d,%d,%d, %d,%d) is true\n",r0,c0,r1,c1,w,h);
	return true;
}

bool check(int x){
	for(int i=0;i<n;i++)for(int j=0;j<n;j++){
		if(a[i][(j+x)%n]!=a[j][(i+x)%n])return false;
	}
	return true;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%s",a+i);
	int res=0;
	for(int i=0;i<n;i++){
		//if(symmetric(i,0,n-i)&&symmetric(0,n-i,i)&&symmetric2(0,0,i,n-i,n-i,i))res++;
		res+=check(i);
	}
	printf("%d\n",res*n);
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main()
{
  int a,i;
  scanf("%d",&a);
   
  for(i=1;i<=a;i++){
    if(i%3==0)printf(" %d",i);
    else if(i%10==3 || i/10%10==3 || i/100%10==3 || i/1000%10==3 )printf(" %d",i);
  }
 
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
////////////////いろいろあるよ//////////////////////////////////
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream>
 #include<bitset>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;
////////////////いろいろあるよ//////////////////////////////////
 
int main(){
   string A;
	cin >> A;
   REP(i,A.size())cout << "x";
  cout << endl;
	return 0;
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n"
#define rep(i,n) for(int i=0; i<(n); ++i)

typedef pair<int, int> P;
typedef pair<string, int> Psi;

int d[5];

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

	int n;cin>>n;

	 rep(i,n){
		 string s;cin>>s;

		 if(s[0] =='M'){
			 d[0]++;
		 }else if (s[0] =='A') {
			 d[1]++;
		}else if (s[0] =='R') {
			d[2]++;
		}else if (s[0] =='C') {
			d[3]++;
		}else if(s[0] =='H'){
			d[4]++;
		}
	 }

	 ll ans=0;
	 rep(i,5){
		 for(int j =i+1; j<5; j++){
			 for(int k= j+1; k<5; k++){
				ans += (ll)d[i]*d[j]*d[k];
			 }
		 }
	 }

	 writeln(ans);



}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[300005],b[300005];
set<pair<int,int> > st;
vector<int> l,r;
int main(){
	int h,w,m,x,y,maxa=0,maxb=0;
	cin>>h>>w>>m;
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		st.insert(make_pair(x,y));
		a[x]++; b[y]++;
		if(a[x]>maxa){
			l.clear(); maxa=a[x];
		}
		if(a[x]==maxa) l.push_back(x);
		if(b[y]>maxb){
			r.clear(); maxb=b[y];
		}
		if(b[y]==maxb) r.push_back(y);
	}
	int p=l.size(),q=r.size();
	for(int i=0;i<p;i++){
		for(int j=0;j<q;j++){
			if(st.find(make_pair(l[i],r[j]))==st.end()){
				cout<<maxa+maxb;
				return 0;
			}
		}
	}
	cout<<maxa+maxb-1;
	return 0;
}

Measured memory_bytes: 21808