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

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

using namespace std;
using lint = long long;

vector<int> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){     // resizeで要素数が減らないように
        IsPrime.resize(max+1,true); // IsPrimeに必要な要素数を確保
    } 
    IsPrime[0] = false; // 0は素数ではない
    IsPrime[1] = false; // 1は素数ではない

    for(size_t i=2; i*i<=max; ++i) // 0からsqrt(max)まで調べる
        if(IsPrime[i]) // iが素数ならば
            for(size_t j=2; i*j<=max; ++j) // (max以下の)iの倍数は
                IsPrime[i*j] = false;      // 素数ではない
}

int main(void)
{
   int X;
   cin >> X;
   sieve(100010);
   for(int i = X; ;i++){
       if(IsPrime[i]){
           cout << i << endl;
           return 0;
       }
   }
    return 0;
}

Measured memory_bytes: 640
n,m=map(int,input().split())
h=list(map(int,input().split()))
c=[1]*n
for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]>h[b-1]:
        c[b-1]=0
    elif h[a-1]<h[b-1]:
        c[a-1]=0
    else:
        c[a-1]=0
        c[b-1]=0
print(c.count(1))

Measured memory_bytes: 20108
import java.util.Scanner;
import java.util.regex.*;

public class Main {
	
	private static final int PLAYER = 4;
	private static final int TRICK = 13;
	private static final Matcher[] SUIT_MATCHER = {
		Pattern.compile("S").matcher(""),
		Pattern.compile("H").matcher(""),
		Pattern.compile("D").matcher(""),
		Pattern.compile("C").matcher("")
	};
	private static final Matcher[] RANK_MATCHER = {
		Pattern.compile("T").matcher(""),
		Pattern.compile("J").matcher(""),
		Pattern.compile("Q").matcher(""),
		Pattern.compile("K").matcher(""),
		Pattern.compile("A").matcher("")
	};
	
	public static void main(String[] args) {
		
		final Scanner scanner = new Scanner(System.in);
		
		for (String trump = scanner.nextLine(); !trump.equals("#"); trump = scanner.nextLine()) {
			
			int score = - 6;
			final int playedCardStrength[][] = new int[PLAYER][TRICK];
			
			final Matcher trumpMatcher = Pattern.compile(trump).matcher("");
			for (int i = 0;i < PLAYER;i ++) {
				
				String playedCardString = trumpMatcher.reset(new StringBuilder(scanner.nextLine()).reverse().toString()).replaceAll("10");
				for (int j = 0; j < SUIT_MATCHER.length; j ++) {
					
					playedCardString = SUIT_MATCHER[j].reset(playedCardString).replaceAll((1 << j) + "");
				}
				for (int j = RANK_MATCHER.length - 1; j >= 0; j --) {
					
					playedCardString = RANK_MATCHER[j].reset(playedCardString).replaceAll((char) ('A' + j) + "");
				}
				
				final Scanner playedCardScanner = new Scanner(playedCardString);
				for (int j = TRICK - 1; j >= 0; j --) {
					
					playedCardStrength[i][j] = Integer.valueOf(playedCardScanner.next(), 16);
				}
			}
			
			int winner = 0;
			for (int j = 0; j < TRICK; j ++) {
				
				int led = playedCardStrength[winner][j] & 0xF0 | ~0xF0;
				for (int i = 0;i < PLAYER;i ++) {
					
					if ((playedCardStrength[i][j] & led) > playedCardStrength[winner][j]) {
						
						winner = i;
					}
				}
				score += winner & 1;
			}
			
			System.out.println((score > 0) ? ("EW " + score): ("NS " + (1 - score)));
		}
	}
}

Measured memory_bytes: 0
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll R,G,B,N;
	cin>>R>>G>>B>>N;
	
	// 解法
	ll ans = 0;
	REP(r,3001){
		REP(g,3001){
			ll target = N - r*R-g*G;
			if (target>=0 & target%B==0)ans++;
		}
	}
	//出力
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }

const int NMAX = 1e+5+1;
bool prime[NMAX];
void Sieve(){
  rep(i,NMAX) prime[i] = true;
  prime[0] = prime[1] = false;
  for(int i=2;i<NMAX;++i){
    if(prime[i]){
      int j = i*2;
      while(j<=NMAX){
	prime[j] = false;
	j += i;
      }
    }
  }
}

int main()
{
  int q;cin >> q;
  vector<int> l(q), r(q);
  rep(i,q) cin >> l[i] >> r[i];

  Sieve();
  vector<int> sum(NMAX+1);
  sum[0] = 0;
  rep(i,NMAX) {
    int x = 0;
    if(prime[i] && prime[(i+1)/2]) {
      x = 1;
    }
    sum[i+1] = sum[i] + x;
  }

  rep(i,q) {
    cout << sum[r[i]+1] - sum[l[i]] << "\n";
  }
	    
  
  return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
#include<cstring>
// #include<queue>
#include<vector>
#include<utility>
using namespace std;
int inf=1e9;
//vector<long long int>adj[10000];

int main()
{
	int t;
	string str;
	cin>>str;
	int l=str.size();
	if(str[l-1]=='s')
	{
		cout<<str<<"es"<<endl;
	}
	else
	{
		cout<<str<<"s"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3604
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

//The Most Powerful Spell
public class Main{

	static class E{
		public int s;
		public int t;
		public String spell;
		public E(int s, int t, String spell) {
			super();
			this.s = s;
			this.t = t;
			this.spell = spell;
		}
	}

	static String[][] dp;
	static boolean[][] flag;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int LEN = 6*39*2;
		while(true){
			int n = sc.nextInt();
			int a = sc.nextInt();
			int s = sc.nextInt();
			int g = sc.nextInt();
			if((n|a|s|g)==0)break;
			List<E> edge = new ArrayList<E>();
			for(int i=0;i<a;i++){
				edge.add(new E(sc.nextInt(), sc.nextInt(), sc.next()));
			}
			dp = new String[n][LEN+1];
			flag = new boolean[n][LEN+1];
			String[] ans = new String[n];
			Arrays.fill(ans, "");
			for(int i=0;i<n;i++)for(int j=0;j<=LEN;j++)dp[i][j]=null;
			dp[s][0] = "";
			flag[s][0] = true;
			int loopCount = 0;
			boolean update = true;
			int updateN = 0;
			while(loopCount <= 100){
				update = false;
				for(int j=0;j<=LEN;j++){
					for(int i=0;i<n;i++){
						if(flag[i][j]){
							flag[i][j] = false;
							for(E e:edge){
								if(e.s == i){
									String next = dp[i][j] + e.spell;
									if(e.t==g && next.length() > LEN && next.compareTo(ans[g]) < 0){
//										System.out.println("LOOP:");
										loopCount = 100;
										break;
									}
									else if(next.length() <= LEN && (dp[e.t][next.length()]==null || next.compareTo(dp[e.t][next.length()])<0)){
										update = true;
										if(e.t==g)updateN++;
										flag[e.t][next.length()] = true;
										dp[e.t][next.length()] = next;
										if(ans[e.t].equals("") || next.compareTo(ans[e.t]) < 0){
											ans[e.t] = next;
//																						System.out.println(e.t + " is UPDATE:" + ans[e.t]);
										}
									}
								}
							}
						}
					}
				}
				if(!update) break;
//								System.out.println(loopCount + " : " + update);
				loopCount++;
			}
			if(loopCount > 100)System.out.println("NO");
			else System.out.println(ans[g].equals("")||ans[g].length()>=(n-1)*6?"NO":ans[g]);
		}
	}
}

Measured memory_bytes: 29000
from math import factorial
import sys
input = sys.stdin.readline
def ncr(n):
 if n <= 1:
  return 0
 elif n == 2:
  return 1
 else:
  return  (factorial(n) // 2) // factorial(n - 2)

n= int(input())
a = list(int(i) for i in input().split())
s = [0]
for i in range(n):
  s.append(s[i]+a[i])
s = sorted(s,reverse =True)
ans = 0
tmp = 1
for i in range(len(s)-1):
  if s[i] == s[i+1]:
   tmp += 1
  else:
   ans += ncr(tmp)
   tmp = 1
ans += ncr(tmp)
print(ans)


Measured memory_bytes: 27268
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

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

int main(void) {
    string S;
    cin >> S;
    const int slen = (int) S.size();

    string ans;

    for (int i = 0; i < slen; i++) {
        if (S[i] == '?') {
            // if (i < slen - 1 && S[i + 1] == 'D') {
            //     ans.push_back('P');
            // } else {
            //     ans.push_back('D');
            // }
            ans.push_back('D');
        } else {
            ans.push_back(S[i]);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3928
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  ll A,B;
  cin>>A>>B;
  
  if(A>=10||B>=10){
cout<<-1<<endl;
  }
  
  else{
    cout<<A*B<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  string a,b;cin>>a>>b;

  string temp=a+b;
  int t=stoi(temp);
  int x=sqrt(t);
  
  if(x*x==t){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    string s, t;  cin >> s >> t;
    REP(i, s.length())
      if(s[i] != t[i]){
        cout << "No" << endl;
        return 0;
      }

    cout << "Yes" << endl;
	return 0;
}


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

int main() {
  int N, a, b, c, d;
  
  cin >> N;
  
  a = N / 1000;
  b = (N - a * 1000) / 100;
  c = (N - a * 1000 - b * 100) / 10;
  d = N - a * 1000 - b * 100 - c * 10;
  
  if (a == b && b == c)	cout << "Yes" << endl;
  else if (b == c && c == d) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
n, x = map(int, input().split())
n = int(n)
x = int(x)
d = []
for i in range(n):
    d.append(input())
# [d1, d2, d3, ..., dN]
m = [int(k) for k in d]

t = sum(m)
t2 = len(m)
m.sort()

u = int((x - t) / m[0])

print(t2 + u)

Measured memory_bytes: 3064
import java.util.Map.Entry;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		long K = sc.nextLong();
		
		if(K % 2 == 1){
			System.out.println(B-A);
		}else{
			System.out.println(A-B);
		}
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}


Measured memory_bytes: 23124
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "limits.h"
#include "bitset"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
using namespace std;

int n, c[499], s[499], f[499];

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}

int main(){
	cin >> n;
	lp(n-1)
		cin >> c[i] >> s[i] >> f[i];
	
	lp(n) {
		int t = 0;
		for (int j = i; j < n - 1; j++) {
			if (t <= s[j])t = s[j]+c[j];
			else t = (((t-s[j]-1)/f[j])+1)*f[j]+s[j]+c[j];
		}
		cout << t << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
	long long int n, a, b;
	cin >> n >> a >> b;
	long long int r = n / (a + b);
	cout << r * a + min(n % (a + b), a) << endl;
}









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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables **************/
string s;
/**********************************************/

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

    cin >> s;
    int n = s.size();
    
    int ans = n;
    REP(i, n-1){
        if(s[i] != s[i+1]) ans = min(ans, max(i+1, n-i-1));
    }

    cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{

		int h,n;
		cin>>h>>n;
		int a[n],sum=0;
		for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>=h)
	cout<<"Yes";
	else
	cout<<"No";
}

Measured memory_bytes: 3964
#import <iostream>
#import <algorithm>
using namespace std;

int main(){
	int n,judge;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	for(int i=1;i<=a[0];i++){
		judge=0;
		for(int j=0;j<n;j++){
			if(a[j]%i==0){
				judge++;
			}
		}
		if(judge==n)cout<<i<<endl;
	}
	return 0;
}


Measured memory_bytes: 3120
while True:
    h, w = map(int, input().split(' '))
    if h == 0 and w == 0:
        break
    for i in range(h):
        if i == 0 or i == h - 1:
            for i in range(w):
                print('#', end ='')
            print()
        else:
            print('#'+'.'*(w - 2)+'#')
    print()


Measured memory_bytes: 5620
n=int(input())
s=input()
result=0
for i in range(n):
    x=s[0:i+1]
    y=s[i+1:]
    kind=0
    for j in range(len(x)):
        if x[j] in y:
            if x[j] in x[0:j]:
                pass
            else:
                kind+=1
    if kind>result:
        result=kind
print(result)

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

int main(){
    using namespace std;
    unsigned long N, Q;
    cin >> N >> Q;
    vector<unsigned long> c(N);
    for(auto&& i : c){
        cin >> i;
        --i;
    }
    vector<tuple<unsigned long, unsigned long, unsigned long>> queries(Q);
    {
        unsigned long cnt{0};
        for(auto&& [i, l, r] : queries){
            cin >> l >> r;
            --l;
            i = cnt++;
        }
    }
    constexpr unsigned long B{1400};
    sort(begin(queries), end(queries), [&B](const auto& lhs, const auto& rhs){
        const auto& [i, li, ri] = lhs;
        const auto& [j, lj, rj] = rhs;
        return li / B == lj / B ? (li / B) & 1 ? ri > rj : ri < rj : li < lj;
    });
    unsigned long nl{0}, nr{0}, now{0};
    vector<unsigned long> cnt(N), ans(Q);
    for(const auto& [i, l, r] : queries){
        while(nr < r)now += !cnt[c[nr++]]++;
        while(nr > r)now -= !--cnt[c[--nr]];
        while(nl < l)now -= !--cnt[c[nl++]];
        while(nl > l)now += !cnt[c[--nl]]++;
        ans[i] = now;
    }
    for(const auto& i : ans)cout << i << endl;
    return 0;
}

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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

struct pot {
    int a, b, c;
};

int sa = 1, sb = 1, sc = 1;

void solve() {
    int n, m;
    cin >> n >> m;

    vector<pot> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i].a >> v[i].b >> v[i].c;
    }

    int ans = 0;
    for (int bit = 0; bit < 8; bit++) {
        if (bit & (1 << 0))sa = -1;
        else sa = 1;
        if (bit & (1 << 1))sb = -1;
        else sb = 1;
        if (bit & (1 << 2))sc = -1;
        else sc = 1;
        sort(v.begin(), v.end(), [](pot a, pot b) {
            return a.a * sa + a.b * sb + a.c * sc > b.a * sa + b.b * sb + b.c * sc;
        });
        int pa = 0, pb = 0, pc = 0;
        for (int i = 0; i < m; i++) {
            pa += v[i].a * sa;
            pb += v[i].b * sa;
            pc += v[i].c * sa;
        }
        ans = max(ans, abs(pa) + abs(pb) + abs(pc));
    }
    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int n,h,w;

struct unionFind{
  unionFind(int n){
    init(n);
  }
  vector<int> par,size;
  int grup;
  void init(int n){
    grup=n;
    par.resize(n);
    size.resize(n);
    for(int i=0;i<n;i++){
      par[i]=i;
      size[i]=1;
    }
  }
  int find(int x){
    if(par[x] == x) return x;
    return par[x]=find(par[x]);
  }
  void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x==y) return;
    if(size[x]<size[y]) swap(x,y);
    par[y] = x;
    size[x]+=size[y];
    grup--;
  }
  bool same(int x,int y){return find(x) == find(y);}
  int getg(){return grup;}
};

map<int,vector<int> > xx;
map<int,vector<int> > yy;
int main(){
  cin>>n>>w>>h;
  bool f=0;
  for(int i=0;i<n;i++){
    int x,y;
    cin>>x>>y;
    if(x==1 || y==1 || x==w || y==h) f=1;
    xx[x].push_back(i);
    yy[y].push_back(i);
  }
  unionFind u(n);
  
  map<int,vector<int> >::iterator it;
  for(it=xx.begin();it!=xx.end();it++){
    vector<int> &vec = it->second;
    for(int i=0;i<(int)vec.size()-1;i++){
      u.unite(vec[i],vec[i+1]);
    }
  }
  for(it=yy.begin();it!=yy.end();it++){
    vector<int> &vec = it->second;
    for(int i=0;i<(int)vec.size()-1;i++){
      u.unite(vec[i],vec[i+1]);
    }
  }
  int cnt=u.getg();
  if(cnt==1) cout<<n-cnt<<endl;
  else cout<<n+cnt-1-f<<endl;     
  return 0;
}

Measured memory_bytes: 10568
#include <stdio.h>

int main(){
	int a=1,n,i,data[6]={2,4,8,16,32,64};
	scanf("%d",&n);
	
	for(i=0;i<6;i++){
		if(n>=data[i]){	
			a=data[i];
		}
	}
	
	printf("%d\n",a);

return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
class segtree{
    public:
    struct node{
        int l,r,val;
    };
    vector <node> st;
    void resize(int n){
        st.resize(4*n);
        build(0,n-1);
    }
    void build(int l,int r,int k=0){
        st[k].l=l,st[k].r=r;
        if(l==r){
            st[k].val=0;
            return;
        }
        build(l,(l+r)/2,2*k+1);
        build((l+r)/2+1,r,2*k+2);
        st[k].val=max(st[2*k+1].val,st[2*k+2].val);
    }
    int query(int l,int r,int k=0){
        int ll=st[k].l,rr=st[k].r;
        if(ll>r || l>rr)return 0;
        if(ll>=l && rr<=r)return st[k].val;
        return max(query(l,r,2*k+1),query(l,r,2*k+2));
    }
    void update(int id,int val,int k=0){
        if(st[k].l>id || st[k].r<id)return;
        if(st[k].l==st[k].r){
            st[k].val=val;
            return;
        }
        update(id,val,2*k+1);
        update(id,val,2*k+2);
        st[k].val=max(st[2*k+1].val,st[2*k+2].val);
    }
};
int n,a[1<<18];
int ans[1<<18];
vector <int> graph[1<<18];
segtree ST;
void dfs(int u,int p){
    int prev=ST.query(a[u],a[u]);
    ans[u]=ST.query(0,a[u]-1)+1;
    ST.update(a[u],ans[u]);
    ans[u]=max(ans[u],ans[p]);
    for(auto x:graph[u]){
        if(x==p)continue;
        dfs(x,u);
    }
    ST.update(a[u],prev);
}

int main(){

    int t=1;
    // cin>>t;
    while(t--){
        ST.resize(1<<20);
        cin>>n;
        for(int i=0;i<n;i++)cin>>a[i+1];
        map <int,int> tocompress;
        for(int i=0;i<n;i++)tocompress[a[i+1]]++;
        int count=0;
        for(auto x:tocompress){
            count++;
            tocompress[x.first]=count;
        }
        for(int i=1;i<n+1;i++)a[i]=tocompress[a[i]];
        for(int i=0;i<n-1;i++){
            int u,v;cin>>u>>v;
            graph[u].push_back(v);
            graph[v].push_back(u);
        }
        dfs(1,0);
        for(int i=1;i<=n;i++)cout<<ans[i]<<"\n";
        // cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 89248
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    K, X = [int(x) for x in sys.stdin.readline().split()]

    logger.debug('{}'.format([K, X]))

    if K * 500 >= X:
        print('Yes')
    else:
        print('No')


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 900"""
        output = """Yes"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """1 501"""
        output = """No"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """4 2000"""
        output = """Yes"""
        self.assertIO(input, output)


Measured memory_bytes: 6440
while 1:
    count = 0
    n,x = map(int,input().split())
    if n == 0 and x == 0:
        break
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j+1,n+1):
                if (i + j + k) == x:
                    count += 1
    print(count)

Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int n,k;cin>>n>>k;
    vector<ll> X(n),Y(n),x(n),y(n);
    rep(i,n){
        cin>>x[i]>>y[i];
        X[i]=x[i];Y[i]=y[i];
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    ll res=5*(1e+18);
    for(int lx=0;lx<n;lx++){
        for(int ly=0;ly<n;ly++){
            for(int rx=lx+1;rx<n;rx++){
                for(int ry=ly+1;ry<n;ry++){
                    //cout<<x[lx]<<" "<<x[rx]<<" "<<y[ly]<<" "<<y[ry]<<endl;
                    int tmp=0;
                    rep(i,n) if(x[lx]<=X[i]&&X[i]<=x[rx]&&y[ly]<=Y[i]&&Y[i]<=y[ry])tmp++;
                    if(tmp>=k)chmin(res,(x[rx]-x[lx])*(y[ry]-y[ly]));
                }
            }
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);

	if (b - a == c - b)
	{
		printf( "YES\n"   );
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int n,flg;
int main(){
  
  while(cin>>n){
    flg=0;
    for(int i=1;n>0;i*=2){
      
      if(n&1){
	if(flg>0)cout<<' ';
	cout<<i;
	flg=1;
      }
      n=n>>1;
    }
    cout<<endl;
  }
  return 0;
}

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

N = int(input())
A = [int(i) for i in input().split()]

rate = [400,800,1200,1600,2000,2400,2800,3200]
R = [False]*len(rate)
red_plus = 0

for a in A:
    if a >= rate[-1]:
        red_plus += 1
    else:
        for i,r in enumerate(rate):
            if a < r:
                R[i] = True
                break
    
if R.count(True) == 0:
    print(1, R.count(True)+red_plus)
else:
    print(R.count(True), R.count(True)+red_plus)
    



Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e6 + 7;
const int md = 1e9 + 7;
void sol() {
  int n, k, s;
  cin >> n >> k >> s;
  if(k > 0) {
    if(s == 1000000000) {
      for(int i=0; i<k; i++) {
          cout << s << " ";
      }
      for(int i=k; i<n; i++) {
        cout << s-1 << " ";
      }
    }
    else {
      for(int i=0; i<k; i++) {
          cout << s << " ";
      }
      for(int i=k; i<n; i++) {
        cout << s + 1 << " ";
      }
    }
  }
  else {
    if(s == 1000000000) {
      for(int i=0; i<n; i++) {
        cout << 1 << " ";
      }
    }
    else {
      for(int i=0; i<n; i++) {
        cout << s + 1 << " ";
      }
    }
  }
}

int32_t main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  //cin >> T; while(T--) 
  sol();
  return 0;
}


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

int main()
{
	string S;
	cin >> S;
	if (S.size() & 1) {
		cout << "No" << endl;
	}
	else {
		bool flag = false;
		for (int i = 0; i < S.size() / 2; i++) {
			if (!(S[i] == 'b' && S[S.size() - i - 1] == 'd') && !(S[i] == 'd' && S[S.size() - i - 1] == 'b')
				&& !(S[i] == 'p' && S[S.size() - i - 1] == 'q') && !(S[i] == 'q' && S[S.size() - i - 1] == 'p')) {
				flag = true;
				break;
			}
		}
		cout << (flag ? "No" : "Yes") << endl;
	}
	return 0;
}


Measured memory_bytes: 512
def main():
    n = int(input())
    ans = 0

    fac = 2
    e = 1
    while True:
        div = pow(fac, e)
        if n % div == 0:
            n //= div
            ans += 1
            e += 1
        else:
            while n % fac == 0:
                n //= fac
            fac += 1
            if fac * fac > n:
                break
            e = 1
    if n != 1:
        ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9168
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <random>

using ll = long long int;
using P = std::pair<ll, int>;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int l[30];
ll c[30],s[400][30],ans[111];

int main(void){
	int d,i,j,n=26,k,m=100;
	ll ansm = -INFLL;
	std::vector<int> v[m];
	for(k=0; k<m; ++k){
		for(j=0; j<n; ++j){
			v[k].push_back(j);
		}
		std::random_device seed_gen;
		std::mt19937 engine(seed_gen());
		std::shuffle(v[k].begin(), v[k].end(), engine);
	}
	std::cin >> d;
	for(i=0; i<26; ++i){
		std::cin >> c[i];
	}
	for(i=0; i<d; ++i){
		for(j=0; j<n; ++j){
			std::cin >> s[i][j];
		}
	}
	for(k=0; k<m; ++k){
		for(j=0; j<n; ++j){
			l[j] = -1;
		}
		for(i=0; i<d; ++i){
			ans[k] += s[i][v[k][i%26]];
			l[v[k][i%26]] = i;
			for(j=0; j<n; ++j){
				ans[k] -= c[j]*(i-l[j]);
			}
		}
		ansm = std::max(ansm,ans[k]);
		// std::cout << ans[k] << std::endl;
	}
	for(k=0; k<m; ++k){
		if(ans[k] == ansm){
			for(i=0; i<d; ++i){
				std::cout << v[k][i%26]+1 << std::endl;
			}
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
int main()
{
    vector<string>str;
    string str1;
    int n,m,i;
    cin>>n>>m;
    for( i = 0; i < n; i++)
    {
        cin>>str1;
        str1 += "#";
        str.push_back(str1);
    }
    for(i = 0; i < m+2; i++)
        cout<<"#";
    cout<<endl;
    for(i = 0; i < str.size(); i++)
    {
        cout<<"#"<<str[i]<<endl;
    }
    for(i = 0; i < m+2; i++)
        cout<<"#";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include "stdio.h"
#include "string.h"
int main() {
    char str[3] = { 0 };
    scanf("%s", str);
    if (!strcmp(str, "ABC"))
        printf("ARC"); 
    else
        printf("ABC");
    return 0;
}

Measured memory_bytes: 3224
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;

static class MainClass
{
    public static void Main(string[] args)
    {
        var s = Console.ReadLine();
        Console.WriteLine(s[0] + (s.Length - 2).ToString() + s[s.Length -1]);
        Console.ReadLine();
    }


    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    #endregion
}


Measured memory_bytes: 13140
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        s: Chars
    };
    let mut ss = s.clone();
    ss.sort();
    ss.dedup();
    println!("{}", ["no", "yes"][(s.len() == ss.len()) as usize]);
}


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

int main()
{
	int N;
	while (cin >> N)
	{
		for (int i = 0; i < N; i++)
		{
			int a, b, c;
			cin >> a >> b >> c;
			
			bool A = a * a + b * b == c * c;
			bool B = c * c + b * b == a * a;
			bool C = a * a + c * c == b * b;
			if (A || B || C)
			{
				cout << "YES" << endl;
			}
			else
			{
				cout << "NO" << endl;
			}
		}
	}



	return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define maxN 1000000


long int dp[maxN][4];

long int find(std::vector<std::vector<int>> &input, int index,int n, int prev) {
    if (index >= n) return 0;
    if ( prev != -1 && dp[index][prev] != -1) return dp[index][prev];
    long int ans = 0;
    for(int i =0; i < 3; i++) {
        if (i != prev) {
            ans = std::max(ans, input[index][i] + find(input, index + 1, n,i));
        }
    }
    if (prev != - 1) dp[index][prev] = ans;
    return ans;
}

int main() {
    int n;
    std::cin>>n;
    std::vector<std::vector<int>> input(n, std::vector<int>(3, 0));
    for(int i =0; i <=n;i++) {
        for(int j = 0; j <= 3; j++) {
            dp[i][j] = -1;
        }
    }
    for(int i =0; i < n; i++) {
        std::cin>>input[i][0]>>input[i][1]>>input[i][2];
    }    
    std::cout << find(input, 0, n, -1) << std::endl;
}

Measured memory_bytes: 17664
// 最大値がnで中央値に一番近いやつがmっぽい lower_boundとupper_boundで見つける
// なんかうまくいかないのでアドホックに当てた

package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}
	sort.Ints(A)
	P := A[N-1]
	Q1 := A[sort.Search(N, func(j int) bool {
		return P/2 <= A[j]
	})]
	sort.Sort(sort.Reverse(sort.IntSlice(A)))
	Q2 := A[sort.Search(N, func(j int) bool {
		return P/2 >= A[j]
	})]
	if abs(float64(P)/2.0-float64(Q1)) < abs(float64(P)/2.0-float64(Q2)) {
		fmt.Println(P, Q1)
	} else {
		fmt.Println(P, Q2)
	}
}

func abs(x float64) float64 {
	if x < 0 {
		x *= -1.0
	}
	return x
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,C,D,L=0,R=0;
  cin >> A >>B >>C >> D;
  L=A+B;
  R=C+D;
  if(L<R){
  	cout << "Right" << endl;
  } else if(L==R){
  	cout << "Balanced" << endl;
  } else if(L>R){
  	cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1<<30;

int main(){
  int r;cin>>r;
  if(r<1200)cout<<"ABC"<<endl;
  else if(r<2800)cout<<"ARC"<<endl;
  else cout<<"AGC"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define stop char nyaa;cin>>nyaa;

ll powmod(ll n, ll k) {
	ll ret = 1;
	while (k) {
		if (k & 1)ret = ret * n%mod;
		n = n * n%mod;
		k >>= 1;
	}
	return ret;
}


ll dp[1010][1010];
void solve() {
	ll n, s;
	cin >> n >> s;
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, i + 1) {
			dp[i + 1][j + 1] = (dp[i][j] + (j + 1) * dp[i][j + 1]) % mod;
		}
	}
	vector<ll> p(n + 2);
	p[0] = 1;
	rep(i, n + 1) {
		p[i + 1] = p[i] * (s + 1 - i) % mod;
	}
	rep(i, n) {
		p[i + 1] = p[i + 1] * powmod(i + 1, mod - 2) % mod;
	}
	ll sum1 = 0, sum2 = 0;
	rep(i, n + 1) {
		sum2 += p[i + 1] * dp[n - 2][i] % mod;
		sum1 += p[i + 1] * dp[n - 1][i] % mod;
	}
	sum1 %= mod;
	sum2 %= mod;

	//cout << sum1 << " " << sum2 << endl;
	ll t = (s) / 2;
	p[0] = 1;
	rep(i, n + 1) {
		p[i + 1] = p[i] * (t + 1 - i) % mod;
	}
	rep(i, n) {
		p[i + 1] = p[i + 1] * powmod(i + 1, mod - 2) % mod;
	}
	ll e1 = 0, e2 = 0;
	rep(i, n + 1) {
		e2 += p[i + 1] * dp[n - 2][i] % mod;
		e1 += p[i + 1] * dp[n - 1][i] % mod;
	}
	e1 = e1 % mod * powmod(2, n - 1) % mod;
	e2 = e2 % mod * powmod(2, n - 2) % mod;
	//cout << e1 << " " << e2 << endl;
	ll o1 = (sum1 - e1 + mod) % mod, o2 = (sum2 - e2 + mod) % mod;
	ll ans = s * powmod(2, mod - 2) % mod*powmod(s + 1, n - 1) % mod;
	if (s % 2 == 0 ) {
		ans += e1 - o1 + mod;
	}
	else {
		ans += o1 - e1 + mod;
	}
	cout << ans % mod << endl;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	stop
		return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> d(N);
  rep(i, N) cin >> d[i];
  sort(d.begin(), d.end());
  int cnt =0;
  for (int i = 0; i < d.size()-1; i++)
  {
    if (d[i]<d[i+1]) {
      cnt ++;
    }
  }
  cout << cnt+1 << endl;
}


Measured memory_bytes: 256
#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, islower
#include <math.h>

#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long; using ld = long double;
using P = pair<int, int>;
long long n, m, x, y, z;
const long long template_arry_size = 1000625;
long long a[template_arry_size];
long long b[template_arry_size];
long long c[template_arry_size];
string s, t;
long long ans = 0;
long long mod = 1'000'000'007;

void solve() {
    cin >> n ;
    rep(i,n) {
        cin >> a[i];
    }
    int x = 0;
    rep(i,n) {
        ans =(ans + (ll)a[i]*x)%mod;
        x =(x+a[i])%mod;
    }
    cout << ans << endl;
}

int main(){

    solve();
    
}

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

ll mod=1e9+7;

ll power(ll n){
    ll ans=1;
    rep(i,n)(ans*=4)%=mod;
    return ans;
}

int main(){
    ll n;
    cin>>n;
    vector<ll> c(n);
    rep(i,n)cin>>c[i];
    sort(c.begin(),c.end(),greater<ll>());
    ll sum=0;
    rep(i,n){
        (sum+=c[i]*(i+2))%=mod;
    }
    ll ans=(power(n-1)*sum)%mod;
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  long long n,k;
  cin>>n>>k;
  long long a[n];
  for(int i=0;i<n;i++){
    long long l;
    cin>>l;
    a[i]=l;
  }
  sort(a,a+n);
  if(a[n-1]<k)cout<<"IMPOSSIBLE"<<endl;
  else {
    long long g;
    g=a[0];
  for(int i=1;i<n;i++){
    while(g!=a[i]){
      if(g%a[i]==0||a[i]%g==0){
        g=min(a[i],g);
      a[i]=g;
      }
      else if(g>a[i])g%=a[i];
      else a[i]%=g;
    }
  }
  if(k%g==0)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
  }
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

//エラトステネスの篩
int prime[MAX]; //i番目の素数
bool is_prime[MAX]; //素数かどうか
bool similar[MAX];
int sum[MAX];

void sieve(int n) {
    int p = 0;
    for (int i = 0; i <= n; i++) {
        is_prime[i] = true;
    }
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (int j = 2 * i; j <= n; j += i) {
                is_prime[j] = false;
            }
        }
    }
    for(int i = 0; i<=n; i++) similar[i] = false;
    for(int i = 3; i<=n; i+=2){
      if(is_prime[i] and is_prime[(i+1)/2]) similar[i] = true;
    }
    for(int i = 3; i<=n; i++){
      if(similar[i]) sum[i] = sum[i-1] + 1;
      else sum[i] = sum[i-1];
    }
}


int main(){
  ll Q; cin>>Q;
  sieve(100005);
  while(Q--){
    int a,b; cin>>a>>b;
    cout<<sum[b] - sum[a-1]<<endl;
  }
}


Measured memory_bytes: 3072
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
  	cin >> s;
    
  	string res = "Yes";
  	for (long i=0; i < s.size(); i++) {
      	if (res=="No") break;
    	if (
                (i+1)%2 == 0 && !(s[i]=='L'||s[i]=='U'||s[i]=='D')
            ) res="No";
    	if ( (i+1)%2 == 1 && !(s[i]=='R'||s[i]=='U'||s[i]=='D') ) res="No";
    }
  
  	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll maxn=2e5+1;
void solve()
{
	ll N;
	cin>>N;
	ll a[maxn];
	for(ll i=0;i<N;i++)
	{
		cin>>a[i];
	}
	sort(a,a+N);
	ll ans=0;
	for(ll i=0;i<N;i++)
	{
		for(ll j=i+1;j<N;j++)
		{
			ll l=j;
			ll r=lower_bound(a,a+N,a[i]+a[j])-a;
			ans+=(r-l-1);
		}
	}
	cout<<ans<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1,p=0;
	//cin>>T;
	do
	{
		solve();
		p++;
	}while(p<T);
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define repm(i,a,b) for(ll i=(ll)(a);i>(ll)(b);i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(),(x).rend()
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb =vector<bool>;
using vvb=vector<vb>;
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; }
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    ll d;
    cin >> d;
    vll c(26);
    rep(i, 26) cin >> c[i];
    vvll s(d,vll(26));
    rep(i,d){
        rep(j,26) cin>>s[i][j];
    }
    ll v=0;
    vector<set<int>>set(26);
    vll ans(d);
    rep(i,26) set[i].insert(0);
    rep(i,d){
        ll ma=0;
        ll key=0;;
        rep(j,26){
            if(ma<c[j]*(i+1-(*--set[j].end()))+s[i][j]){
                key=j;
                ma=c[j]*(i+1-(*--set[j].end()))+s[i][j];
            }
            v-=c[j]*(i+1-(*(--set[j].end())));
        }
        set[key].insert(i+1);
        ans[i]=key;
    }
    bool flag=true;
    if(flag){
        rep(i,100000){
            ll day=rand()%d;
            ll cont=rand()%26;
            if(ans[day]==cont)continue;
            auto itr=set[ans[day]].find(day+1);
            ll next,prev;
            next=*(++itr);
            prev=*(--itr);
            ll lost=(next-day+2)*(day-prev)*c[ans[day]]+s[day][ans[day]];
            auto itr2=upper_bound(all(set[cont]),day+1);
            next=*itr2;
            prev=*(--itr2);
            ll prof=(next-day+2)*(day-prev)*c[cont]+s[day][cont];
            if(prof>lost){
                set[ans[day]].erase(day+1);
                ans[day]=cont;
                set[cont].insert(day+1);
            }
        }
    }
    rep(i,d){
        cout<<ans[i]+1<<endl;
    }
}

Measured memory_bytes: 3744
#include <iostream>
#include <vector>
#include <deque>
#include <climits>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<long long int>
#define vc vector<char>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(i = (a); i < (n); i++)
#define fi(i,a,n) for(i = (a); i <= (n); i++)
#define F first
#define S second
int main(){
    ll n;
    cin>>n;
    ll t = 0;
    t += (n-1)*n/2;
    cout<<t<<endl;
}

Measured memory_bytes: 256