akhauriyash/Code-Regression huggingface dataset:
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#include <cstdio>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef std::vector<int> VI;
typedef std::pair<int,int> P;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

double eps=1e-11;
char s[50];

int wei(char *s)
{
    int dian=1,r=48;
    while(dian<=30 && s[dian]!='.') dian++;
    if(dian>30) return 0;
    while(s[r]==0 || s[r]=='0') r--;
    return r-dian;
}

LL get(char *s)
{
    int dian=1,r=48;
    while(dian<=30 && s[dian]!='.') dian++;
    if(dian>30)
    {
        LL ret=0;
        for(int i=1;s[i];i++) ret=ret*10+s[i]-'0';
        return ret;
    }
    while(s[r]==0 || s[r]=='0') r--;
    LL ret=0;
    REP(i,1,r) if(s[i]!='.') ret=ret*10+s[i]-'0';
    return ret;
}

LL f[100][100][15];

int main()
{
    int n=read(),na=0,nb=0;
    int max2=0,max5=0;
    REP(i,1,n)
    {
        mem(s,0);
        scanf("%s",s+1);
        int w=wei(s);
        LL y=get(s);
        int n2=0,n5=0;
        while(y%2==0) n2++,y/=2;
        while(y%5==0) n5++,y/=5;
        //cout<<w<<' '<<n2<<' '<<n5<<' '<<s+1<<endl;
        f[n2][n5][w]++;
        max2=max(max2,n2);
        max5=max(max5,n5);
    }
    LL ans=0;
    REP(i,0,max2) REP(j,0,max5) REP(k,0,9) if(f[i][j][k])
    {
        //cout<<i<<' '<<j<<' '<<k<<' '<<f[i][j][k]<<endl;
        REP(ii,0,max2) REP(jj,0,max5) REP(kk,0,9)
            if(f[ii][jj][kk])
                if(!(i==ii && j==jj && k==kk))
                {
                    LL x=f[i][j][k],y=f[ii][jj][kk];
                    if(min(i+ii,j+jj)>=k+kk)
                    {
                        ans+=x*y;
                        //cout<<ii<<' '<<jj<<' '<<kk<<' '<<x<<' '<<y<<endl;
                    }
                }
        if(min(i+i,j+j)>=k+k)
        {
            LL x=f[i][j][k];
            ans+=x*(x-1);
        }
    }
    cout<<ans/2;

    return 0;
}


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

#define dump(x) cout << (x) << endl
#define Int int64_t
#define fi first
#define se second

Int INF = 1e9;
Int mod = 1e9+7;

int main() {
    Int n;
    cin >> n;
    vector<Int> d(n);
    for (Int i = 0; i < n; i++) {
        cin >> d[i];
        d[i] = min(d[i], 24 - d[i]);
    }
    d.push_back(0);
    sort(d.begin(), d.end());
    for (Int i = 0; i <= n; i+=2) {
       d[i] = (24 - d[i]) % 24;
    }
    sort(d.begin(), d.end());
    Int res = d.back() - d.front();
    for (Int i = 0; i < n; i++) {
        res = min(res, d[i + 1] - d[i]);
    }
    dump(res);
    return 0;
}

Measured memory_bytes: 256
N = int(input())
reds = [list(map(int, input().split())) for i in range(N)]
blues = [list(map(int, input().split())) for i in range(N)]
reds.sort(key=lambda x: x[0], reverse=True)
blues.sort(key=lambda x: x[1])
red_used = []
blue_used = []

for red in reds:
    for blue in blues:
        if red in red_used or blue in blue_used:
            continue
        if red[0] < blue[0] and red[1] < blue[1]:
            red_used.append(red)
            blue_used.append(blue)

print(len(blue_used))


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

int main()
{
    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    long long ans;
    bool apl = a >= 0;
    bool bpl = b >= 0;
    bool cpl = c >= 0;
    bool dpl = d >= 0;
    
    if (apl && bpl && cpl && dpl) {
        ans = b * d;
    }
    else if (apl && bpl && !cpl && dpl) {
        ans = b * d;
    }
    else if (apl && bpl && !cpl && !dpl) {
        ans = a * d;
    }
    else if (!apl && bpl && cpl && dpl) {
        ans = b * d;
    }
    else if (!apl && bpl && !cpl && dpl) {
        if (b * d > a * c) {
            ans = b * d;
        }
        else {
            ans = a * c;
        }
    }
    else if (!apl && bpl && !cpl && !dpl) {
        ans = a * c;
    }
    else if (!apl && !bpl && cpl && dpl) {
        ans = b * c;
    }
    else if (!apl && !bpl && !cpl && dpl) {
        ans = a * c;
    }
    else if (!apl && !bpl && !cpl && !dpl) {
        ans = a * c;
    }

    cout << ans;
}

Measured memory_bytes: 3164
'use strict';
(function(stdin) {
  var inputs = stdin.toString().trim().split('\n');
  var cols   = inputs[0].split(' ').map(Number);

  (function(a,b) {
    console.log(
      Math.floor(a / b),
      a % b,
     Number((a / b).toFixed(6))
    );

  // ????????????????????????
  })(cols[0],cols[1]);

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15724
#入力を受け取る
n = int(input())
a = []
for i in range (5):
  a += [int(input())]
min = a[0]
for i in range (1,5):
  if min > a[i]:
    min = a[i]
b =n % min
c = n // min
if b == 0:
  t = c + 4
else:
  t = c + 5
print(t)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=1100;
int h,w,n,dis[maxn][maxn],sx,sy,ans=0;
char maze[maxn][maxn];
int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int>P;
int bfs(int x,int y,int c){
	char order=c+'0';
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)dis[i][j]=maxn;
	queue<P>que;
	que.push(P(x,y));
	dis[x][y]=0;
	while(que.size()){
		P point=que.front();que.pop();
		if(maze[point.first][point.second]==order){
			sx=point.first,sy=point.second;
			return dis[point.first][point.second];
			break;
		}
		for(int i=0;i<4;i++){
			int nx=point.first+dx[i],ny=point.second+dy[i];
			if(1<=nx&&nx<=h&&1<=ny&&ny<=w&&maze[nx][ny]!='X'&&dis[nx][ny]==maxn){
				que.push(P(nx,ny));
				dis[nx][ny]=dis[point.first][point.second]+1;
			}
		}
	}
}
int main()
{
	//freopen("read.txt", "r", stdin);
	cin>>h>>w>>n;
	getchar();
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>maze[i][j];
			if(maze[i][j]=='S'){
				sx=i;sy=j;
			}
		}
		getchar();
	}
	for(int k=1;k<=n;k++){
		ans+=bfs(sx,sy,k);
	}
	cout<<ans<<endl;
	//fclose(stdin);
	return 0;
}

Measured memory_bytes: 8476
let (n,a,b) = Scanf.scanf "%d %d %d\n" (fun x y z -> (x,y,z))

let pr x = print_endline @@ string_of_int x

let (--) m n =
  let rec iter i res =
    if i >= m then iter (i - 1) (i::res)
    else res in
  let rec iter' i res =
    if i <= m then iter' (i + 1) (i::res)
    else res in
  if m <= n then iter n []
  else iter' n []

let digit_list_of_num n =
  let rec iter rem res =
    let top = rem mod 10 in
    if rem < 10 then top::res
    else iter (rem / 10) (top::res) in
  iter n []

let sum_digits n =  List.fold_left (+) 0 @@ digit_list_of_num n
    
let () = List.fold_left
           (fun sum x ->
             let s = sum_digits x in
             if s >= a && s <= b then sum + x
             else sum) 0 (1--n)
         |> pr


Measured memory_bytes: 1536
#include "stdio.h"
#include "iostream"

using namespace std;
int main() {
	int a, b, c, d;
	cin >> a>> b>> c>> d;
	if (abs(a - c) <= d)
		cout << "Yes";
	else if (abs(a - b) <= d && abs(c - b) <= d)
		cout << "Yes";
	else
		cout << "No";
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<bool> AC(N+1, false);
    vector<int> WA(N+1,0);

    int ACnum = 0, WAnum = 0;
    for(int i = 0; i < M; i++){
        int p;
        string S;
        cin >> p >> S;
        if(AC.at(p) == true) continue;
        if(S == "AC"){
            AC.at(p) = true;
            ACnum++;
            WAnum += WA.at(p);
        }else{
            WA.at(p)++;
        }
    }
    cout << ACnum << " " << WAnum << endl;
}


Measured memory_bytes: 3776
A = int(input()) 
B = int(input())
C = int(input())
X = int(input())

count=0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if (500*a + 100*b + 50*c) == X:
                count += 1

print(count)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 struct node{
	int key;
	struct node *prev;
	struct node *next;
};
typedef struct node * NodePoineter;

NodePoineter nil;

NodePoineter listSearch(int key){
	NodePoineter p;
	int i;
	p=nil->next;

	while((p!=nil)&&(p->key!=key)){
		p=p->next;
	}
	return p;
}

void init(){
	nil=malloc(sizeof(struct node));
	nil->prev=nil;
	nil->next=nil;
}

void printList(){
	NodePoineter cur =nil->next;
	int isf=1;
	while(1){
		if(cur == nil) break;
		if(isf == 0) printf(" ");
		printf("%d",cur->key);
		cur=cur->next;
		isf=0;
	}
	printf("\n");
}

void deleteNode(NodePoineter t){
	t->prev->next=t->next;
	t->next->prev=t->prev;
}

void deleteFirst(){
	NodePoineter t = nil->next;
	if(t==nil) return;
	deleteNode(t);
}

void deleteLast(){
	NodePoineter t = nil->prev;
	if(t==nil) return;
	deleteNode(t);
}

void delete(int key){
	NodePoineter t;
	if((t=listSearch(key))!=NULL){
		if(t==nil) return;
		deleteNode(t);
	}
}

void insert(int key){
	NodePoineter n;
	n=malloc(sizeof(struct node));
	n->key=key;
	n->next=nil->next;

	nil->next->prev=n;
	nil->next=n;
	n->prev=nil;
}

int main(){
	int i,n,m,key;
	char command[12];
	scanf("%d",&n);
	init();
	for(i=0;i<n;i++){
		scanf("%s",command);
		if(strcmp(command,"insert")==0){
			scanf("%d",&key);
			insert(key);
		}else if(strcmp(command,"delete")==0){
			scanf("%d",&key);
			delete(key);
		}else if(strcmp(command,"deleteFirst")==0){
			deleteFirst();
		}else{
			deleteLast();
		}
	}

	printList();
	return 0;
}

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

map<ll, ll>pos;

int main()
{
	ll n;
	cin >> n;
	ll c = 0;
	vector<ll>a;
	for (ll i = 0; i <= 2e9+1000; i+=++c) {
		a.push_back(i);
		pos[i] = c;
	}
	ll lb = *(lower_bound(a.begin(), a.end(), n));
	cout << pos[lb] << endl;
	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	string s;
	cin >> s;

	rep(i, 3) cout << (s[i] == '1'  ? '9' : '1');
	cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
int n, a[N];
int cntPos(int i, long long val) {
	int lo = i + 1, hi = n - 1, ret = i;
  	while (lo <= hi) {
    	int mid = (lo + hi) / 2;
      	if ((long long) a[i] * a[mid] <= val) {
			ret = mid;
          	lo = mid + 1;
        } else{
        	hi = mid - 1;
        }
    }
	return ret - i;
}
int cntNeg(int i, long long val) {
	int lo = i + 1, hi = n - 1, ret = n;
  	while (lo <= hi) {
    	int mid = (lo + hi) / 2;
      	if ((long long) a[i] * a[mid] <= val) {
			ret = mid;
        	hi = mid - 1;
        } else{
          	lo = mid + 1;
        }
    }
	return n - ret;
}
int main() {
	long long k;
  	cin >> n >> k;
  	for (int i = 0; i < n; ++i)
      	cin >> a[i];
  	sort(a, a + n);
	long long lo = -1e18, hi = 1e18, res = -1; 
	while (lo <= hi) {
		long long mid = (lo + hi) / 2, counter = 0;
		for (int i = 0; i < n; ++i) {
          	if (a[i] > 0)
              counter += cntPos(i, mid);
          	else
            	counter += cntNeg(i, mid);
        }
		if (counter < k) {
			lo = mid + 1;
		} else {
			res = mid;
			hi = mid - 1;
		}
	}
	cout << res << endl;	
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main() { 
	int t[4][14]; 
	int n, i,j,c; 
	char m, d; 
	for(i=0; i < 4; i++){ 
		for(j=0; j < 14; j++){ 
			t[i][j]=0; 
		} 
	} 
	scanf("%d", &c); 
	for(i = 0; i < c; i++){
		scanf("%c", &d); 
		scanf("%c %d", &m, &n); 
		if(m == 'S'){ 
			t[0][n] = 1;
		} else if(m == 'H'){ 
			t[1][n] = 1; 
		} else if(m == 'C'){
			t[2][n] = 1; 
		} else if(m == 'D'){
			t[3][n] = 1; 
		} 
	} 
	for(j=1; j < 14; j++){ 
		if(t[0][j] != 1){
			printf("S %d\n", j); 
		}
	} 
	for(j=1; j < 14; j++){ 
		if(t[1][j] != 1){
			printf("H %d\n", j);
		}
	}
	for(j=1; j < 14; j++){
		if(t[2][j] != 1){
			printf("C %d\n", j); 
		} 
	} 
	for(j=1; j < 14; j++){
		if(t[3][j] != 1){
			printf("D %d\n", j);
		} 
	}
	return 0;
} 



Measured memory_bytes: 2672
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
int main() {
	int N;
	ll Cur = 0;
	scanf("%d", &N);
	vector<pair<int, int>> T(N);
	rep(i, 0, N)scanf("%d%d", &T[i].second, &T[i].first);
	sort(all(T));
	rep(i, 0, N) {
		Cur += T[i].second;
		if (Cur > T[i].first) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1792
#include <iostream> // {{{
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <cstdio> // }}}

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

using namespace std;

int h,w;
char s[52][52];

void prove(int y, int x) {
    if (s[y][x] == '#') {
        return;
    }
    int sum = 0;
    if (y > 0 && s[y-1][x] == '#') {
        sum++;
    }
    if (y < h-1 && s[y+1][x] == '#') {
        sum++;
    }
    if (x > 0 && s[y][x-1] == '#') {
        sum++;
    }
    if (x < w-1 && s[y][x+1] == '#') {
        sum++;
    }
    if (y > 0 && x > 0 && s[y-1][x-1] == '#') {
        sum++;
    }
    if (y > 0 && x < w-1 && s[y-1][x+1] == '#') {
        sum++;
    }
    if (y < h-1 && x > 0 && s[y+1][x-1] == '#') {
        sum++;
    }
    if (y < h-1 && x < w-1 && s[y+1][x+1] == '#') {
        sum++;
    }

    s[y][x] = '0' + sum;
}

int main() {
    scanf("%d %d", &h, &w);
    rep(i,h){
        scanf("%s", s[i]);
    }
    rep(i,h)rep(j,w){
        prove(i,j);
    }
    rep(i,h){
        printf("%s\n", s[i]);
    }
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
      	if(N<105){
        	System.out.println(0);
        }else{
        	int cntnum = 0;
          	for(int i=105;i<=N;i+=2){
              	int cnt = 0;
            	for(int j=1;j<=N;j++){
                	if(i%j==0){
                    	cnt++;
                    }
                }
              	if(cnt==8){
                	cntnum++;
                }
            }
          	System.out.println(cntnum);
        }
    }
}

Measured memory_bytes: 23636
function main(input) {
  input = input.trim();
  let result = "Good";
  for (let i = 1; i < input.length; i++) {
  	if (input[i] === input[i-1]) {
      result = "Bad";
      break;
    }
  }
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

int main() {
  long long L, R;
  cin >> L >> R;

  if (R - L >= 2019) {
    cout << 0 << endl;
  } else {
    long long min = 2019;

    for (long long i = L; i <= R; i++) {
      for (long long j = i + 1; j <= R; j++) {
        long long product = i * j;
        long long result = (product % 2019 + 2019) % 2019;
        if (result < min) {
          min = result;
        }
      }
    }
    cout << min << endl;
  }

  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val hw = readLine()!!.split(' ').map { it.toInt() }
    val height = hw[0]
    var computed: MutableList<List<Char>> = mutableListOf()

    for(i in 1..height) {
        val line = readLine()!!.toMutableList()
        computed.add(line)
        computed.add(line)
    }

    computed.forEach {
        println(it.joinToString(separator = ""))
    }

}

Measured memory_bytes: 40644
import sys
from fractions import gcd
n, x, d = map(int, input().split())

if x == 0 and d == 0:
	print(1)
	sys.exit()
elif d == 0:
	print(n+1)
	sys.exit()

if x < 0 and x + (n-1) * d < 0:
	x, d = -x, -d

if x >= 0 and d < 0:
	x, d = x + (n-1) * d, -d

g = gcd(x, d)

ans = 1
if x >= 0:
	for i in range(1, n+1):
		k = max((i - d//g) * (2*n - 1 - i + d//g) // 2 - x//g, i * (i-1) // 2 - 1)
		ans += max((i * (2*n-1-i)) // 2 - k, 0)

else:
	for i in range(1, n+1):
		overlap_u = min((i - d//g) * (2*n - 1 - i + d//g) // 2 - x//g, i * (2*n-1-i) // 2)
		overlap_l = max((i - d//g) * (i - d//g - 1) // 2 - x//g, i * (i-1) // 2)
		ans += i * (2*n-1-i) // 2 - i * (i-1) // 2 + 1 - max(overlap_u - overlap_l + 1, 0)

print(ans)

Measured memory_bytes: 5048
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rep2(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rev(i, n) for (int (i) = (n)-1; (i) >= 0; (i)--)
#define rev2(i, a, b) for (int (i) = (a)-1; (i) >= (b); (i)--)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pll = pair<long long, long long>;
template<class T> using Vec = vector<T>;
template<class T> using VVec = vector<vector<T>>;
long long TEN(int i) {return !i ? 1 : TEN(i-1)*10LL;}
template<class T, class U> 
bool chmin(T& a, const U& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U> 
bool chmax(T& a, const U& b) {if (a < b) {a = b; return 1;} return 0;}
 
struct IoSetup {
  	IoSetup() {
    	cin.tie(nullptr);
    	ios::sync_with_stdio(false);
    	cout << fixed << setprecision(10);
  	}
} iosetup;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

template<long long mod>
class ModInt {
public:
	long long v;
	ModInt(long long v = 0) : v((v % mod + mod) % mod) {}
	ModInt operator+(ModInt t) {return ModInt((v + t.v) % mod);}
	ModInt operator-(ModInt t) {return ModInt((v - t.v + mod) % mod);}
	ModInt operator*(ModInt t) {return ModInt((v * t.v) % mod);}
	ModInt operator+=(ModInt t) {return *this = *this + t;} 
	ModInt operator-=(ModInt t) {return *this = *this - t;}
	ModInt operator*=(ModInt t) {return *this = *this * t;}
	ModInt operator-() {return ModInt(-v);}
	ModInt mpow(long long t) {
		if (t == 0) return ModInt(1);
		ModInt a = mpow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	ModInt inv() {mpow(mod - 2);}
	ModInt operator/(ModInt t) {return ModInt(v) * t.inv();}
	ModInt operator/=(ModInt t) {return *this = *this / t;}
	ModInt operator==(ModInt t) {return *this.v == t.v;}
	ModInt operator!=(ModInt t) {return *this.v != t.v;}
	friend ostream& operator<<(ostream& os, const ModInt& mi) {
		os << mi.v;
		return os;
	}
};

using mint = ModInt<1000000007>;

// ans = mod_pow(a, b, (ll)MOD);
template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}


int main() {
	int N;
	cin >> N;
	ll A[N];
	rep (i, N) cin >> A[i];

	mint sum = 0;
	rep (i, N) sum += mint(A[i]);

	

	mint ans = mint(0);
	rep (i, N) ans += (mint(A[i])) * (sum - mint(A[i]));


	ll aaa = ans.v;
	aaa = aaa * mod_pow(2LL, 1000000005LL, 1000000007LL) % 1000000007LL;
	
	cout << aaa << endl; 
	
	return 0;
}


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

int main(){
    ll n;
    cin >> n;
    int k;
    cin >> k;
    ll ans = 0;
    while(n>0) {
        n/=k;
        ans++;
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
// best coder in the world do not mess with me!!
#include <bits/stdc++.h>
#define REP(ii,nn) for(int ii=0; ii<nn ;ii++)
#define FOR(ii, aa, bb) for (int ii = (aa); ii < (bb); ii++)
#define FORD(ii, aa, bb) for(int ii = (aa); ii > (bb); ii--)
#define pb(aa) push_back(aa)
#define fastaff ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mp(aa,bb) make_pair(aa,bb)
#define v(a,b) vector<int> a(b)
typedef long long int ll;
using namespace std;
void sol()
{ll num1,m;cin>>num1>>m;
	cout<<(num1*(num1-1))/2+(m*(m-1))/2<<'\n';}
int main()
{
	fastaff
	ll t = 1;while(t--)
	{sol();}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,m,a[200],b[200],c[200],d[200],e[200],ans[200];
  cin >> n >> m;
  rep(i,n)e[i]=INF;
  rep(i,n)cin >> a[i] >> b[i];
  rep(i,m)cin >> c[i] >> d[i];
  rep(i,n){
    rep(j,m){
      if(e[i]>abs(a[i]-c[j])+abs(b[i]-d[j]))ans[i]=j+1;
      e[i]=min(e[i],abs(a[i]-c[j])+abs(b[i]-d[j]));
    }
  }
  rep(i,n)printf("%lld\n",ans[i]);
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
//?¶????????????????????????????????????§??????????????????????¢????????????????
constexpr int INF = 2000000000;
const double PI = acos(-1);

vector<pair<int, int>> keitai(string s) {
	vector<pair<int, int>> v;
	int cnt = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '0') {
			if (cnt) v.push_back(make_pair(s[i - 1] - '0', cnt));
			cnt = 0;
		}
		else ++cnt;
	}

	return v;
}

char phone[10][10] = { {} ,{ '-','.',',','!','?',' ' },{ '-','a','b','c' },{ '-','d','e','f' } ,{ '-','g','h','i' } ,{ '-','j','k','l' } ,{ '-','m','n','o' },{ '-','p','q','r','s' },{ '-','t','u','v' },{ '-','w','x','y','z' } };


char ans(int a, int b) {
	if (a == 1) {
		b %= 5;
		if (b == 0)b=5;
	}
	else if (a == 7 || a == 9) {
		b %= 4;
		if (b == 0)b = 4;
	}
	else {
		b %= 3;
		if (b == 0)b = 3;
	}
	return phone[a][b];
}

int main() {
	int n;
	string s;

	cin >> n;

	while (n--) {
		cin >> s;

		vector<pair<int, int>> v = keitai(s);

		for (int i = 0; i < v.size(); ++i) {
			cout << ans(v[i].first, v[i].second);
		}
		cout << endl;
	}
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

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

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

const bool debug = true;

#define MAX 200100
ll N, x[MAX], y[MAX]; // x[i] <= y[i]

inline bool in(ll v ,ll mini,ll maxi) { return mini <= v && v <= maxi; }

bool cmp(int i,int j) { return x[i] < x[j]; }

struct Data {
  ll v;
  int id;
  bool operator < ( const Data & data ) const {
    if( v != data.v ) return v < data.v;
    return id > data.id;
  }
  bool operator > ( const Data & data ) const {
    if( v != data.v ) return v > data.v;
    return id < data.id;
  }
};

void compute(ll mini,ll maxi) {
  ll ans = LLONG_MAX;

  // mini -> R, maxi -> B
  ll Rmax = mini;
  ll Bmin = maxi;
  rep(i,N) {
    if( !( x[i] <= y[i] ) ) swap(x[i],y[i]);
    Rmax = max(Rmax,x[i]);
    Bmin = min(Bmin,y[i]);
  }
  ans = ( Rmax - mini ) * ( maxi - Bmin );

  // mini -> R, maxi -> R
  vector<int> vec(N);
  rep(i,N) vec[i] = i;
  sort(ALL(vec),cmp);
  priority_queue<Data> maxQ;
  priority_queue<Data,vector<Data>,greater<Data> > minQ;
  vector<ll> cur_val(N);
  rep(i,N) {
    cur_val[i] = x[i];
    maxQ.push((Data){x[i],i});
    minQ.push((Data){x[i],i});
  }
  ans = min(ans,(maxi-mini)*(maxQ.top().v-minQ.top().v));
  rep(i,N) {
    cur_val[vec[i]] = y[vec[i]];
    maxQ.push((Data){y[vec[i]],vec[i]});
    minQ.push((Data){y[vec[i]],vec[i]});
    while( !maxQ.empty() && cur_val[maxQ.top().id] != maxQ.top().v ) maxQ.pop();
    while( !minQ.empty() && cur_val[minQ.top().id] != minQ.top().v ) minQ.pop();
    ans = min(ans,(maxi-mini)*(maxQ.top().v-minQ.top().v));
  }
  cout << ans << endl;
}

int main() {
  cin >> N;
  ll mini = LLONG_MAX, maxi =- LLONG_MAX;
  rep(i,N) {
    cin >> x[i] >> y[i];
    mini = min(mini,min(x[i],y[i]));
    maxi = max(maxi,max(x[i],y[i]));
  }
  compute(mini,maxi);
  return 0;
}


Measured memory_bytes: 21844
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	w, h, n := nextInt(), nextInt(), nextInt()

	up, down, right, left := h, 0, w, 0
	for i := 0; i < n; i++ {
		x, y, a := nextInt(), nextInt(), nextInt()
		switch a {
		case 1:
			left = max(left, x)
		case 2:
			right = min(right, x)
		case 3:
			down = max(down, y)
		case 4:
			up = min(up, y)
		}
	}

	ans := 0
	if left <= right && down <= up {
		ans = (right - left) * (up - down)
	}
	puts(ans)
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

/**
 * Rectangular Searching
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("0 0")) {
			int h = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			int w = Integer.parseInt(line.substring(line.indexOf(' ') + 1));

			// read grid and count (create histogram)
			int[][] g = new int[h][w + 1];
			for (int i = 0; i < h; i++) {
				line = br.readLine();
				for (int j = 0; j < w + 1; j++) {
					if (j < w) {
						g[i][j] = line.toCharArray()[j] == '*' ? 0 : 1;
						if (i > 0 && g[i][j] != 0) {
							g[i][j] += g[i - 1][j];
						}
					} else {
						g[i][j] = 0;
					}
				}
			}

			// search
			int area = 0;
			Deque<int[]> queue = new ArrayDeque<int[]>();
			for (int i = 0; i < h; i++) {
				queue.push(new int[] { 0, g[i][0] });
				for (int j = 1; j < w + 1; j++) {
					if (g[i][j] > queue.peek()[1]) {
						queue.push(new int[] { j, g[i][j] });
					} else if (g[i][j] < queue.peek()[1]) {
						int[] prev = null;
						while (!queue.isEmpty() && g[i][j] <= queue.peek()[1]) {
							prev = queue.pop();
							area = Math.max(area, prev[1] * (j - prev[0]));
						}
						queue.push(new int[] { prev[0], g[i][j] });
					}
				}
			}
			System.out.println(area);
		}
	}
}

Measured memory_bytes: 158104
program scoring
    implicit none
    integer(8)::D,C(26),last(26),last_sim(26),i,j,k,vcalc
    integer(8),allocatable::S(:,:),T(:),V(:)
    !入力
    read*,D,C
    allocate(S(26,D))
    allocate(T(D))
    allocate(V(D))
    read*,S
    T=0
    V=0
    last=0
    last_sim=0

    !各日にちについて貪欲に計算
    do i=1,D
        !すべての選択肢を試す
        do j=1,26
            !vcalcとlast_simを初期化
            if(i==1)then
                vcalc=V(i)
            else
                vcalc=V(i-1)
            end if
            last_sim=last

            !得点をシミュレート
            vcalc=vcalc+S(j,i)
            last_sim(j)=i
            do k=1,26
                vcalc=vcalc-C(k)*(i-last_sim(k))
            end do

            !比較していって最大値を更新したらVに格納する
            if(vcalc>=V(i).or.j==1)then
                V(i)=vcalc
                T(i)=j
            end if
        end do
        !最終的に選んだ選択肢をもとに更新
        last(T(i))=i
    end do

    !答えの出力
    do i=1,D
        print'(i0)',T(i)
    end do
end program scoring

Measured memory_bytes: 2968
N, K = map(int, input().split())
Max = N*(N-1)//2-(N-1)
if Max<K:
    print(-1)
else:
    d = Max-K
    print(N-1+d)
    for i in range(2, N+1):
        print(1, i)
    for i in range(2, N+1):
        for j in range(i+1, N+1):
            if d>0:
                print(i, j)
                d-=1
            else:
                break


Measured memory_bytes: 44528
#include <iostream>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int count = 0;
  for (int i = 0; i < n; ++i) {
    int h;
    cin >> h;
    if (h >= k)
      ++count;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
    int m, f, r;

    while (1) {
        cin >> m >> f >> r;

        if (m == -1 && f == -1 && r == -1) {
            break;
        }

        if (m == -1 || f == -1 || m + f < 30) {
            cout << "F" << endl;
        } else if (30 <= m + f && m + f < 50) {
            if (r >= 50) {
                cout << "C" << endl;
            } else {
                cout << "D" << endl;
            }
        } else if (50 <= m + f && m + f < 65) {
            cout << "C" << endl;
        } else if (65 <= m + f && m + f < 80) {
            cout << "B" << endl;
        } else {
            cout << "A" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3088
#include<stdio.h>
int main() {
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d = a / b;
	r = a % b;
	f = (double)a / b;
	printf("%d %d %f\n",d,r,f);
	return 0;
}

Measured memory_bytes: 1852
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long; 

int main() {
    ll a,b,c,count=0;
    ll na,nb,nc;
    cin >> a >> b >> c;

    while (true) {
        if (a%2==1 or b%2==1 or c%2==1) {
            cout << count << endl;
            break;
        }
        else {
            na=(b+c)/2;nb=(a+c)/2;nc=(a+b)/2;
            a=na;b=nb;c=nc;
            ++count;
            if (count > 9999999) {
                cout << "-1" << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
            sum += a[i];
        }
        int count = 0;
        for (int i = 0 ; i < n ; i++) {
            if (a[i] * 4 * m >= sum) {
                count++;
            }
        }

        if (count >= m) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <iomanip> 
using namespace std; 
#define rep(i,a,b)		for(long int i=a;i<=b;i++)
#define MOD 1e9+7

int n,m,check;
unordered_map<string,int> ans;
int cnt=INT_MIN;
string temp;
int main() 
{ 
	ios::sync_with_stdio(false);
    cin.tie(NULL);  
   
	cin>>n;
	rep(i,1,n)
	{
		cin>>temp;
		ans[temp]+=1;
	}
	cin>>m;
	rep(i,1,m)
	{
		cin>>temp;
		ans[temp]-=1;
	}
	for(auto it:ans)
	{
		check = it.second;
		cnt = max(check,cnt);
	}
	cout<<max(0,cnt);

}
	

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.S;
		bool b=true;
		for(int i = 0;i<s.Length;i++) {
			if(i%2==1&&s[i]=='R'){b=false;}
			if(i%2==0&&s[i]=='L'){b=false;}
		}
		Console.WriteLine("{0}",b?"Yes":"No");
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

public class Main {

	public static void main(String[] args) throws Exception {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		
		int[] t = sc.nextIntArray(n);
		
		int m = sc.nextInt();
		
		int[] p = new int[m];
		int[] x = new int[m];
		
		int sum = Arrays.stream(t).sum();
		
		for(int i = 0; i < m; i++) {
			p[i] = sc.nextInt();
			x[i] = sc.nextInt();
			
			out.println(sum - t[p[i] - 1] + x[i]);
		}
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(K key, V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 27348
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    LL H,W;cin >> H >> W;
    if(H % 3 == 0 || W % 3 == 0)cout << 0 << endl;
    else{
        LL Sa,Sb,Sc;
        LL ans = INF;
        LL tmp1,tmp2;
        for(int i = 1;i<=H;i++){
            if((H-i)%2==0){
                Sa = i*W;
                Sb = (H-i)/2 * W;
                Sc = (H-i)/2 * W;
            }
            else{
                Sa = i*W;
                Sb = (H-i-1)/2 * W;
                Sc = (H-i+1)/2 * W;                
            }
            tmp1 = min(Sa,min(Sb,Sc));
            tmp2 = max(Sa,max(Sb,Sc));
            ans = min(ans,tmp2-tmp1);
        }
        for(int i = 1;i<=H;i++){
            if(W%2==0){
                Sa = i*W;
                Sb = (H-i)*W/2;
                Sc = (H-i)*W/2;
            }
            else{
                Sa = i*W;
                Sb = (H-i)*(W-1)/2;
                Sc = (H-i)*(W+1)/2;                
            }

            tmp1 = min(Sa,min(Sb,Sc));
            tmp2 = max(Sa,max(Sb,Sc));
            ans = min(ans,tmp2-tmp1);
        }
        swap(H,W);
        for(int i = 1;i<=H;i++){
            if((H-i)%2==0){
                Sa = i*W;
                Sb = (H-i)/2 * W;
                Sc = (H-i)/2 * W;
            }
            else{
                Sa = i*W;
                Sb = (H-i-1)/2 * W;
                Sc = (H-i+1)/2 * W;                
            }
            tmp1 = min(Sa,min(Sb,Sc));
            tmp2 = max(Sa,max(Sb,Sc));
            ans = min(ans,tmp2-tmp1);
        }
        for(int i = 1;i<=H;i++){
            if(W%2==0){
                Sa = i*W;
                Sb = (H-i)*W/2;
                Sc = (H-i)*W/2;
            }
            else{
                Sa = i*W;
                Sb = (H-i)*(W-1)/2;
                Sc = (H-i)*(W+1)/2;                
            }

            tmp1 = min(Sa,min(Sb,Sc));
            tmp2 = max(Sa,max(Sb,Sc));
            ans = min(ans,tmp2-tmp1);
        }     

        cout << ans << endl;
    }
}

// ABC062 C - Chocolate Bar
// ・チョコを3分割するが、各ピースは長方形になる。

// チョコを分割する際に解説のように4パターンになる。

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)

class UnionFind
{
public:
	UnionFind(ll _size) : parent(_size), rank(_size) {
		for (ll i = 0; i < _size; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	};

	ll root(ll x) {
		if (parent[x] == x) {
			return x;
		}
		else {
			return parent[x] = root(parent[x]);
		}
	}

	bool same(ll x, ll y) {
		return root(x) == root(y);
	}

	void unite(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return;

		if (rank[x] < rank[y]) {
			parent[x] = y;
		}
		else {
			parent[y] = x;
			if (rank[x] == rank[y]) rank[x]++;
		}
	}


private:
	//parent[i]==j  : iの親がj
	vector<ll> parent;
	vector<ll> rank;

};

//変数
int N, K, L;

//解法
void solve() {

	UnionFind road(N), train(N);
	rep(i, K) {
		ll p, q;
		cin >> p >> q;
		road.unite(p-1, q-1);
	}
	rep(i, L) {
		ll r, s;
		cin >> r >> s;
		train.unite(r-1, s-1);
	}

	vector<ll> road_group(N), train_group(N);
	rep(i, N) {
		road_group[i] = road.root(i);
		train_group[i] = train.root(i);
	}

	map<pair<ll, ll>, int> mp;
	rep(i, N) {
		mp[pair<ll, ll>(road_group[i], train_group[i])]++;
	}

	rep(i, N) {
		cout << mp[pair<ll, ll>(road_group[i], train_group[i])] << " ";
	}

	return;
}

int main() {
	//入力
	cin >> N >> K >> L;
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 21120
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    H = int(input())

    monster = H
    c = 0
    while monster > 0:
        c += 1
        if monster < 1:
            monster = 0
        else:
            monster = monster // 2
    ans = 0
    for i in range(c):
        ans += 2 ** i
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string s;
    int n,ac=0,wa=0,tle=0,re=0;
    cin>>n;
    for(int i=0; i<n; i++){
            cin>>s;
            if(s=="AC"){
                    ac++;
            }
            if(s=="WA"){
                    wa++;
            }
            if(s=="TLE"){
                    tle++;
            }
            if(s=="RE"){
                    re++;
            }
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
}


Measured memory_bytes: 3580
n = gets.to_i
array = gets.split.map(&:to_i)
count = 0

(0..(n - 1)).each do |i|
    minj = i
    (i..(n - 1)).each do |j|
        if array[minj] > array[j]
            minj = j
        end
    end
    if array[minj] < array[i]
        array[i],array[minj] = array[minj],array[i]
        count += 1 
    end
    
end

print array.join(" ")
puts "\n#{count}" 


Measured memory_bytes: 6872
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
a.unshift(0)
ans = 1000
(1...n).each do |i|
    have_stock = 0
    have_stock = ans / a[i] if a[i] < a[i+1]
    ans += (a[i+1]- a[i]) * have_stock
end
puts ans

Measured memory_bytes: 14368
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>

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

  std::string s(a, '0'+b);
  std::string t(b, '0'+a);
  printf("%s\n", std::min(s, t).c_str());
}


Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  s <- T.getLine :: IO T.Text
  let
    tailRems :: VU.Vector Int
    tailRems = VU.map snd . VU.scanr step (10, 0) . VU.map unsafeCharToInt . VU.unfoldr T.uncons $ s
      where
        step :: Int -> (Int, Int) -> (Int, Int)
        step d (l, r) = (l', r')
          where
            l' = 10 * l `mod` 2019
            r' = (d * l + r) `mod` 2019
    cs :: VU.Vector Int
    cs = count tailRems
  print . VU.sum . VU.map (\k -> k * pred k `div` 2) $ cs

count :: VU.Vector Int -> VU.Vector Int
count v = VU.accumulate_ (+) (VU.replicate 2019 0) v (VU.replicate (VU.length v) 1)

unsafeCharToInt :: Char -> Int
unsafeCharToInt c = fromEnum c - 48


Measured memory_bytes: 11012
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_d

//参考：
//https://scrapbox.io/ganariya/AtCoder%E5%85%A8%E5%9B%BD%E7%B5%B1%E4%B8%80%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9F%E3%83%B3%E3%82%B0%E7%8E%8B%E6%B1%BA%E5%AE%9A%E6%88%A6%E4%BA%88%E9%81%B8_D%E5%95%8F%E9%A1%8C500%E7%82%B9_%E3%80%8CRestore_the_Tree%E3%80%8D

//ポイント：トポロジカルソート（詳細はコード内で説明）

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,M;
vector<vector<LL>> out;
vector<vector<LL>> in;

vector<LL> ans;

void solve(){
    //トポロジカルソート
    //有向グラフで、かつ閉路がない場合に使える（このようなグラフをDEGという）
    //頂点i->jという辺がある時、dist[i]<dist[j]が成り立つように数列distを組む
    //このようなdistをトポロジカル順序という（点startから点iへの距離的なもの）

    //ある頂点iに入っていく辺の個数をin_num[i]とおく
    //ついでにトポロジカルソートのスタート地点にしたい点を求める
    //入っていく辺のない頂点がスタート地点となる点である
    vector<LL> in_num(N+1,0);
    LL start;//トポロジカルソートのスタート地点にしたい点
    for(int i=1;i<=N;i++){
        in_num[i] = in[i].size();
        if(in_num[i]==0) start = i;
    }

    //BFSを使ってトポロジカル順序(点startから点iへの距離的なもの)を求める
    queue<LL> q;
    //dist,parentにはトポロジカルソートの結果を格納
    vector<LL> dist(N+1,0);//点startから点iへの距離的なもの
    vector<LL> parent(N+1,0);//点iの直接の親をparent[i]とする
    q.push(start);
    dist[start] = 0;
    while(!q.empty()){
        LL now = q.front();q.pop();
        for(LL next:out[now]){
            if(dist[next]<dist[now]+1){//距離がでかい方優先
                dist[next] = dist[now]+1;
                parent[next] = now;//親を更新
                in_num[next]--;
                if(in_num[next]==0) q.push(next);
            }
        }
    }

    ans = vector<LL>(N+1,0);
    for(int i=1;i<=N;i++){
        ans[i] = parent[i];
    }
}

int main(){
    cin >> N >> M;
    out = vector<vector<LL>>(N+1);
    in = vector<vector<LL>>(N+1);
    for(int i=0;i<N+M-1;i++){
    	LL u,v;cin >> u >> v;
    	out[u].push_back(v);
        in[v].push_back(u);
    }

    solve();

    for(int i=1;i<=N;i++)cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 14336
n = int(input())
x = input().split()
c = 0
for i in range(n):
  if i == 0 or i == n-1:
    continue
  elif (int(x[i]) < int(x[i-1]) and int(x[i]) > int(x[i+1])) or (int(x[i]) < int(x[i+1]) and int(x[i]) > int(x[i-1])):
      c = c + 1
print(c)

Measured memory_bytes: 3064