akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,k;
    cin>>n>>k;

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

    int sum=0;

    for (int i=0;i<n;i++) {
        sum+=min(x[i],k-x[i])*2;
    }

    cout<<sum<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

int main()
{
  int N,T,A,H[1001],X,Y,ind;
  double mi=9999999;
  cin >> N;
  cin >> T >> A;
  REP(i,N)cin >> H[i];
  REP(i,N){
    if(fabs(A-(1.*T-H[i]*0.006)) < mi){
      ind = i;
      mi = fabs(A-(1.*T-H[i]*0.006));
    }
  }
  cout << (ind+1) << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}



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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

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

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	string A, B;

	cin >> A >> B;
	int N = A.length();
	A = A + A + A;
	B = B + B + B;

	if( A == B ){
		cout << 0 << endl;
		return 0;
	}

	if( B == string(B.length(), '0') ){
		cout << -1 << endl;
		return 0;
	}

	int nr[6005], nl[6005];
	reps(i,1,3*N) nl[i] = (B[i] == '1' ? i : nl[i-1]);
	rrep(i,3*N)   nr[i] = (B[i] == '1' ? i : nr[i+1]);

	//rep(i,3*N) cout << nl[i] << " "; cout << endl;
	//rep(i,3*N) cout << nr[i] << " "; cout << endl;

	int ans = INF;
	rep(k,2) rep(d,N){
		int XY=INF;
		vector<pii> v;
		rep(i,N) if( A[i] == '1' ){
			if( k == 0 && nr[i] - i > d ){
				v.emplace_back(N+i - nl[N+i], nr[i] - i - d);
			}
			if( k == 1 && N+i - nl[N+i] > d ){
				v.emplace_back(N+i - nl[N+i] - d, nr[i] - i);
			}
		}
		sort(all(v));
		int maxY = 0, bf = -1;
		rrep(i,v.size()) if(bf != v[i].X){
			chmin(XY, v[i].X + maxY);
			bf = v[i].X;
			chmax(maxY, v[i].Y);
		}
		chmin(XY, maxY);
		int sum = 0;
		if(k == 0) rep(i,N) sum += (A[i] != B[i+d]);
		if(k == 1) rep(i,N) sum += (A[N+i] != B[N+i-d]);
		chmin(ans, XY*2 + d + sum);
		//cout << v.size() << " " << sum << " " << ans << endl;
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
	long long N, T = 0;
	bool check = true;
	static pair<long long, long long> P[200000];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> P[i].second >> P[i].first;
	sort(P, P + N);
	for (int i = 0; i < N; i++) {
		T += P[i].second;
		if (T > P[i].first) check = false;
	}
	if (check) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (int)(a); v < (int)(b); ++v)
#define FORE(v, a, b) for(int v = (int)(a); v <= (int)(b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
using namespace std;

void split(string str, char chr, vector< string > *res){
	stringstream ss(str);
	string itm;
	while(getline(ss, itm, chr)){
		(*res).PB(itm);
	}
}

double Heron(double a, double b, double c){
	double s = (a + b + c) / 2;
	return sqrt(s * (s - a) * (s - b) * (s - c));
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int a, l, x;
	double area;
	
	while(cin >> a >> l >> x){
		area = Heron(a, l, l) + Heron(l, (double)(l + x) / 2, (double)(l + x) / 2) * 2;
		cout << setprecision(15) << area << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main(int argc, char* argv[])
{
  int N, M;
  cin >> N >> M;
  
  queue<int> starts;  // nodes with no incoming node
  vector< vector<int> > children(N);
  vector< vector<int> > parents(N);
  vector<int> num_parent(N, 0);

  for (int i=0; i<M; i++) {
    int x, y;
    cin >> x >> y;
    children[x-1].push_back(y-1);
    parents[y-1].push_back(x-1);
    num_parent[y-1]++;
  }
  
  for (int i=0; i<N; i++) {
    if (num_parent[i] == 0) starts.push(i);
  }
  
  vector<int> v(N, 0);
  while (!starts.empty()) {
    int x = starts.front();
    starts.pop();
    //cout << "starter: " << x << "\n";
    
    for (vector<int>::iterator it = parents[x].begin(); it != parents[x].end(); ++it) {
      v[x] = max(v[x], 1 + v[*it]);
    }
    //cout << "value of " << x+1 << " = " << v[x] << "\n";
    
    for (vector<int>::iterator it = children[x].begin(); it != children[x].end(); ++it) {
      num_parent[*it]--;
      if (num_parent[*it] == 0) starts.push(*it);
    }
  }
  
  int best = 0;
  for (int i=0; i<N; i++) best = max(best, v[i]);
  cout << best << "\n";
  return 0;
}


Measured memory_bytes: 11904
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	var t string
	s := wordScanner(100001)
	scanStrings(s, &t)

	fmt.Println(2 * min(strings.Count(t, "0"), strings.Count(t, "1")))
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func wordScanner(n int) *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	b := make([]byte, n)
	s.Buffer(b, n)
	return s
}

func scanStrings(s *bufio.Scanner, vals ...*string) {
	for i := range vals {
		s.Scan()
		*vals[i] = s.Text()
	}
}


Measured memory_bytes: 768
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String N = sc.next();
      	String N2;
      	if(N.length() >= 3){
          N2 = N.substring(N.length() - 3);
        }
      	else {
          N2 = N;
        }
      	int i = new Integer(N2).intValue();
      	if(i == 0){
          System.out.println(i);
        }
      	else {
        	System.out.println(1000 - i);
        }
    }
}

Measured memory_bytes: 35648
# unionfind:連結成分が欲しい場合などに使用
import sys
sys.setrecursionlimit(10**9)

def get_par(x):
  if x == par_list[x]:
    return x
  else:
    par_list[x] = get_par(par_list[x])
    return par_list[x]
def merge(x,y):
  par_x = get_par(x)
  par_y = get_par(y)
  if par_x != par_y:
    par_list[par_y] = par_x
    siz_list[par_x]+= siz_list[par_y]
def is_same(x,y):
  return get_par(x) == get_par(y)

N,M=map(int,input().split())

par_list = list(range(N+1))
siz_list = [1]*(N+1)

# ここでmergeを繰り返すした後、馴らす
for _ in range(M):
  A,B=map(int,input().split())
  merge(A,B)

for i in range(1,N+1):
  par_list[i]=get_par(i)
  siz_list[i]=siz_list[par_list[i]]
#print(par_list,siz_list)

print(max(siz_list))

Measured memory_bytes: 92120
def main():
    colors = input().split()
    nums = list(map(int, input().split()))
    d = {
        colors[i]: nums[i] for i in range(2)
        }
    colors_rm = input()
    d[colors_rm] -= 1
    print(d[colors[0]], d[colors[1]])

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
N = int( input() )
h_list = list( map( int, input().split() ) )
h_list.append(10**10)
a = 0
new = 0
j = -1
for i in range(N):
    if j + 1 == i: 
        j = i
        while(h_list[j] >= h_list[j + 1]):
            new += 1
            j += 1
        a = max(a,new)
        new = 0
print(a)

Measured memory_bytes: 14252
def get_ints():
    return list(map(int, input().split()))

x, n = get_ints()
ps = get_ints()
ps.sort()
ans = 10000000
d = 1000000
for i in range(102):
    if i in ps:
        continue
    nd = abs(x - i)
    if nd < d:
        ans = i
        d = nd

print(ans)


Measured memory_bytes: 61828
#include <stdio.h>

void InputNumber(int* a, int* b, int* c);
char* Judgment(int a, int b, int c);

int main(void) {
    
    int a;
    int b;
    int c;
    char* msg;
    
    InputNumber(&a, &b, &c);
    msg = Judgment(a, b, c);
    
    printf("%s", msg);
}

void InputNumber(int* a, int* b, int* c) {
    
    do {
        scanf("%d", a);
    } while (*a < 0 || *a > 100);
    
    do {
        scanf(" %d", b);
    } while (*b < 0 || *b > 100);
    
    do {
        scanf(" %d", c);
    } while (*c < 0 || *c > 100);
}

char* Judgment(int a, int b, int c) {
    
    int judge = (b > a) && (c > b);
    char* msg;
    
    if (judge) {
        msg = "Yes\n";
    } else {
        msg = "No\n";
    }
    
    return msg;
}


Measured memory_bytes: 2052
#include<bits/stdc++.h>
#define INF 1000000007
using namespace std;

void count_factor(int n,map<int,int>& m)
{
  for(int i=2;i<=n;i++)if(n%i==0){n/=i;m[i]++;i--;}
}

int main()
{
  int N;unsigned long long ans=1;scanf("%d",&N);map<int,int> m;
  for(int n=N;n>0;n--)count_factor(n,m);
  for(auto p : m){ans=ans*(p.second+1)%INF;}
  printf("%llu\n",ans);
}

Measured memory_bytes: 3772
#include <tuple>
#include <vector>
#include <cstdio>
#include <cstring>
using namespace std;
const int Maxn=2000;
int n;
int a[Maxn*3+5];
int dp[Maxn+5][Maxn+5];
int row_max[Maxn+5];
int zero,all_max;
vector<tuple<int,int,int> > vis;
void update(int i,int j,int k){
	vis.emplace_back(i,j,k);
	vis.emplace_back(j,i,k);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=3*n;i++){
		scanf("%d",&a[i]);
	}
	memset(row_max,-0x3f,sizeof row_max);
	memset(dp,-0x3f,sizeof dp);
	dp[a[1]][a[2]]=row_max[a[1]]=row_max[a[2]]=zero;
	for(int i=3;i<=3*n;i+=3){
		if(a[i]==a[i+1]&&a[i]==a[i+2]){
			zero--;
			continue;
		}
		for(int _=0;_<3;_++){
			swap(a[i],a[i+1]);
			swap(a[i+1],a[i+2]);
			update(a[i],a[i+1],max(all_max,dp[a[i+2]][a[i+2]]+1));
			for(int j=1;j<=n;j++){
				if(a[i+1]==a[i+2]){
					update(j,a[i],dp[j][a[i+1]]+1);
				}
				update(j,a[i],row_max[j]);
			}
		}
		for(tuple<int,int,int>j:vis){
			int e=get<0>(j),f=get<1>(j),g=get<2>(j);
			dp[e][f]=max(dp[e][f],g);
			row_max[e]=max(row_max[e],g);
			all_max=max(all_max,g);
		}
		vis.clear();
	}
	printf("%d\n",all_max-zero);
	return 0;
}


Measured memory_bytes: 19120
#include <stdio.h>

int main(void){
  int a, b, d, r;
  double f;
  scanf("%d %d", &a, &b);
  d = a / b;
  r = a % b;
  f = (double)a / (double)b;
  printf("%d %d %.5lf\n", d, r, f);
  return 0;
}

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

int main(){
    int N, M;  cin >> N >> M;
    vector<int> A(N+1,0);
    for(int i=1; i<=N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    vector<pair<int,int>> P(M); // C,B
    for(int i=0; i<M; i++){
        cin >> P[i].second >> P[i].first;
    }
    sort(P.begin(), P.end());
    int idx = 1;
    for(int i=M-1; i>=0; i--){
        int B = P[i].second;
        int C = P[i].first;
        // cout << "-----" << endl;
        // for(int i=1; i<=N; i++){
        //     cout << A[i] << " ";
        // }cout << endl;
        while(A[idx]<C && B > 0){
            A[idx] = C;
            idx++;
            B--;
        }

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

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

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#define llint long long
#define mod 1000000007

using namespace std;

string s;

bool isDigit(char c)
{
	return c >= '0' && c <= '9';
}
llint parseNumber(int &p)
{
	llint ret = 0;
	while(isDigit(s[p])) ret *= 10, ret += s[p]-'0', p++;
	return ret;
}
llint parseExp(int &p);
llint parseTerm(int &p)
{
	if(s[p] == '['){
		p++;
		llint ret = parseExp(p);
		ret = ret*ret%mod;
		p++;
		return ret;
	}
	if(isDigit(s[p])) return parseNumber(p);
}
llint parseExp(int &p)
{
	llint ret = parseTerm(p);
	while(1){
		if(s[p] == '/'){
			p++;
			llint tmp = parseTerm(p);
			if(tmp > 40) ret = 0;
			else ret >>= tmp;
		}
		else break;
	}
	return ret;
}


int main(void)
{
	while(1){
		getline(cin, s);
		if(s == "#") break;
		s += "=";
		
		string t;
		for(int i = 0; i < s.size(); i++){
			if(s[i] == ' ') continue;
			t += s[i];
		}
		s = t;
		
		t = "";
		for(int i = 0; i < s.size(); i++){
			if(s[i] == 'S'){
				t += '[';
				i++;
			}
			else if(s[i] == '>'){
				if(s[i+1] != '>') t += ']';
				else{
					if(s[i+2] != 'S' && !isDigit(s[i+2])) t += ']';
					else t += '/', i++;
				}
			}
			else t += s[i];
		}
		s = t;
		
		int p = 0;
		cout << parseExp(p) << endl;
	}
	return 0;
}


Measured memory_bytes: 5900
#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;
    int a[n-1];
    map<int,int> mp;
    rep(i,n-1){
        cin >> a[i];
        mp[a[i]-1]++;
    } 
    for(int i=0;i<n;i++){
        cout << mp[i] << endl;
    }
}

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

int main() {
  char b;
  cin >> b;
  if(b == 'A'){
    cout << 'T' << endl;
  }
  if(b == 'C'){
    cout << 'G' << endl;
  }
  if(b == 'G'){
    cout << 'C' << endl;
  }
  if(b == 'T'){
    cout << 'A' << endl;
  }
}


Measured memory_bytes: 256
from collections import defaultdict
def main(h, w, s):
    u = [None] * h
    acc = [None] * (h + 1)
    acc[0] = [0] * (w + 1)
    for i in range(h):
        x = list(map(int, input().split()))
        acc[i + 1] = [0] + x
        u[i] = x
    for i in range(h):
        acci1 = acc[i + 1]
        for j in range(w):
            acci1[j + 1] += acci1[j]
    for i in range(h):
        acci = acc[i]
        acci1 = acc[i + 1]
        for j in range(w):
            acci1[j + 1] += acci[j + 1]
    dp = defaultdict(int)
    allsum = acc[-1][-1]
    def accsum(l, r, d, u):
        return acc[u + 1][r + 1] - acc[u + 1][l] - acc[d][r + 1] + acc[d][l]
    for wm in range(w):
        for hm in range(h):
            for l in range(w - wm):
                r = l + wm
                for d in range(h - hm):
                    u = d + hm
                    ac = accsum(l, r, d, u)
                    res = [1, s - (allsum - ac)]
                    for mw in range(l, r):
                        tmp1 = dp[(l, mw, d, u)]
                        tmp2 = dp[(mw + 1, r, d, u)]
                        if tmp1[1] >= 0 and tmp2[1] >= 0:
                            tmp = [tmp1[0] + tmp2[0], min(tmp1[1], tmp2[1])]
                            if tmp[0] > res[0]:
                                res = tmp
                            elif tmp[0] == res[0] and tmp[1] > res[1]:
                                res = tmp
                    for mh in range(d, u):
                        tmp1 = dp[(l, r, d, mh)]
                        tmp2 = dp[(l, r, mh + 1, u)]
                        if tmp1[1] >= 0 and tmp2[1] >= 0:
                            tmp = [tmp1[0] + tmp2[0], min(tmp1[1], tmp2[1])]
                            if tmp[0] > res[0]:
                                res = tmp
                            elif tmp[0] == res[0] and tmp[1] > res[1]:
                                res = tmp
                    dp[(l, r, d, u)] = res
    print(*dp[(0, w - 1, 0, h - 1)])

if __name__ == '__main__':
    while 1:
        h, w, s = map(int, input().split())
        if h == w == s == 0:
            break
        main(h, w, s)




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

namespace AOJ.Volume2
{
    public class DangerousBridge
    {
        private class Person
        {
            public int Weight { get; set; }
            public int Start { get; set; }
            public int End { get; set; }
        }

        public static int Main()
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) { break; }

                var persons = new List<Person>();
                for(int i = 0; i < n; i++)
                {
                    var input = Console.ReadLine().Split(' ');
                    var p = new Person();
                    p.Weight = int.Parse(input[0]);
                    p.Start = int.Parse(input[1]);
                    p.End = int.Parse(input[2]);
                    persons.Add(p);
                }

                var bridge = new List<Person>();
                bool is_ok = true;
                foreach (var p in persons.OrderBy(x => x.Start))
                {
                    for(int i = bridge.Count - 1; i >= 0; i--)
                    {
                        if (bridge[i].End <= p.Start) { bridge.RemoveAt(i); }
                    }
                    bridge.Add(p);
                    if (bridge.Sum(x => x.Weight) > 150)
                    {
                        is_ok = false;
                        break;
                    }
                }
                Console.WriteLine(is_ok ? "OK" : "NG");
            }
            return 0;
        }
    }
}

Measured memory_bytes: 9904
(defun main ()
  (let ((N (read))
        (A (list nil))
        (tmp nil))
    (dotimes (x N)
      (push (read) A))
    (setq A (cdr (reverse A)))
    (if (= 1 (length A))
        (print (car A))
        (progn
          (setq A (mapcar (lambda (n) (float (/ 1 n))) A))
          (setq tmp (apply #'+ A))
          (print (float (/ 1 tmp)))))))
(main)

Measured memory_bytes: 13160
#include <iostream>
#include <vector>
using namespace std;
const int INF = (1e9);
int main(){
  int N, M;
  cin >> N >> M;
  vector< vector<int> > G(N, vector<int>(N,INF));
  vector<int> A(M), B(M), C(M);
  for(int i = 0; i < M; ++i){
    int a, b, c;
    cin >> a >> b >> c;
    --a;--b;
    G[a][b] = c;
    G[b][a] = c;
    A[i] = a;
    B[i] = b;
    C[i] = c;
  }
  for(int k = 0; k < N; ++k){
    for(int i = 0; i < N; ++i){
      for(int j = 0; j < N; ++j){
        G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
      }
    }
  }
  int ans = 0;
  for(int i = 0; i < M; ++i){
    if(G[A[i]][B[i]] != C[i]) ++ans;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	int h, m;
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		scanf("%d:%d", &h, &m);
		double sh, lh;

		lh = 2 * M_PI * (m / 60.0);
		sh = 2 * M_PI * ((h * 60 + m) / (60.0 * 12));

		if(cos(lh - sh) > cos(M_PI / 6.0))
			cout << "alert" << endl;
		else if(cos(lh - sh) > cos(M_PI / 2.0))
			cout << "warning" << endl;
		else
			cout << "safe" << endl;
	}
}

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

flag = True

for i in range(len(s)):
  if i%2 != 0:
    if s[i] == 'L' or s[i] == 'U' or s[i] == 'D':
      continue
    else :
      flag = False
      break
  else:
    if s[i] == 'R' or s[i] == 'U' or s[i] == 'D':
      continue
    else :
      flag = False
      
if flag:
  print('Yes')
else :
  print('No')

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


int main(){
    ll N,L;
    cin >> N >> L;
    vector<string> str(N);
    for(int i = 0; i < N; i++){
        cin >> str[i];
    }
    sort(str.begin(),str.end());

    string ans = "";

    for(int i = 0; i < N; i++) ans += str[i];

    cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc071.contest.atcoder.jp/tasks/arc071_b>
問題文============================================================
 2 次元平面上に x 軸と平行な直線が m 本と y 軸と平行な直線が n 本引いてあります。
 x 軸と平行な直線のうち下から i 番目は y=yi で表せます。
 y 軸と平行な直線のうち左から i 番目は x=xi で表せます。
 
 この中に存在しているすべての長方形についてその面積を求め、合計を 109+7 で割ったあまりを出力してください。
 
 つまり、1≤i<j≤n と 1≤k<l≤m を満たすすべての組 (i,j,k,l) について、
 直線 x=xi, x=xj, y=yk, y=yl で囲まれる 長方形の面積を求め、
 合計を 10^9+7 で割ったあまりを出力してください。
 
=================================================================

解説=============================================================

 全ての長方形の面積なので、
     ΣΣ(xj-xi) * ΣΣ(yj-yi)
 が答え
 
 xに関して
 ΣΣ(xj-xi) :
     (x2-x1) + (x3-x1) + (x4-x1) + ... + (xn-x1) +
     (x3-x2) + (x4-x2) +  ... + (xn-x2) +
     .....
     (xn - x_n-1)
 
 よって、各 xiに関して出現回数からいえば
     (i-1)*xi - (n-i)*xi
 
 とO(1)で計算できる
 
 よって 面積は O(n+m)で計算できる
 
================================================================
*/

const ll MOD = 1e9+7;
ll solve(){
    ll n,m; cin >> n >> m;
    vector<ll> x(n),y(m);
    for(auto &in:x) cin >> in;
    for(auto &in:y) cin >> in;
    
    ll x_sum = 0, y_sum = 0;
    for(int i = 0; i < n;i++){
        (x_sum += (i*x[i] - (n-1-i)*x[i] + MOD)%MOD)%=MOD;
    }
    for(int i = 0; i < m;i++){
        (y_sum += (i*y[i] - (m-1-i)*y[i] + MOD)%MOD)%=MOD;
    }
    ll ret = x_sum * y_sum %MOD;
    return ret;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cout << solve() << endl;
	return 0;
}


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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    bool check = true;
    rep(i,n){
        cin >> a.at(i);
        if(a.at(i) % 2 == 0){
            if(a.at(i) % 3 != 0){
                if(a.at(i) % 5 != 0){
                    check = false;
                }
            }
        }
    }
    if(check) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
int main(){
    ll d, t; cin >> d;
    vector<ll> ansl(365,-1);
    vector<ll> c(26);
    vector<ll> las(26,0);
    vec2(s,d,26,0);
    REP(i,26) cin >> c[i];
    REP(i,d)REP(j,26) cin >> s[i][j];
    ll con = 0;
    FOR(i,1,d){
        ll max = -1*INF;ll mind = -1;
        REP(j,26)if(max<s[i-1][j]){
            max=s[i-1][j];
            con-=c[j]*(i-las[j]);
            mind=j;
        }
        ansl[i-1]=mind;
        con+=c[mind]*(i-las[mind]);
        las[mind]=i;
    }
    
    REP(i,d) cout << ansl[i]+1 << endl;
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>

using namespace std;
using ll = long long;
const int BIG = 100000007;


int main() {
    ll a;
    cin >> a;
    cout << ((a % 1000 == 0) ? 0 :(1000 - a % 1000)) << endl;
}




Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pow2(x) (ll(1)<<x)
#define pb push_back
#define mp make_pair
#define w(t) int t;scanf("%d",&t);while(t--)
#define For(i,n) for(int i=0;i<n;i++)
#define scan(n) int n;scanf("%d", &n);
using namespace std;
const int sz = 3005;
int n,k;
int main()
{
    scanf("%d", &n);
    int x[n],ans[n];
    k = 1;
    For(i,n)
    {
        ans[i] = 1e9;
        scanf("%d", &x[i]);
    }
    ans[0] = 0;
    for(int i = 0;i<n;i++)
    {
        for(int j = i;j>=max(0,i-2);j--)
            ans[i] = min(ans[i],ans[j] + abs(x[i] - x[j]));
    }
    cout<<ans[n - 1];
}


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

using Graph=vector<vector<int>>;
int main(){
    int n,m;
    cin>>n>>m;
    Graph g(n);
    vector<int> dist(n);
    vector<int> delta(n);
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        x--,y--;
        delta[y]++;
        g[x].push_back(y);
    }
    queue<int> que;
    for(int i=0;i<n;i++){
        if(delta[i]==0) que.push(i);
    }
    while(!que.empty()){
        int v=que.front(); que.pop();
        for(auto &to:g[v]){
            dist[to]=max(dist[to],dist[v]+1);
            if(--delta[to]==0) que.push(to);
        }
    }
    cout<<*max_element(dist.begin(),dist.end())<<endl;
    return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <math.h>
using namespace std;
 
#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
 
typedef long long ll;
typedef long long int lli;
 
int main() {
    int res, S0C, S1C;
    string S; 
    cin >> S;
    S0C = S1C = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S.at(i) == '0') {
            S0C++;
        } else {
            S1C++;
        }
    }
    res = min(S0C, S1C) * 2;
    cout << res << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
   int n,m;
   cin >> n >> m;
    VI x(m);
    rep(i,m)cin >> x.at(i);
   if(n>=m)cout << 0 << endl;
   else{
    sort(x.begin(),x.end());
    ll dif=x.at(m-1)-x.at(0);
    VI y(m);
    rep(i,m-1){
        y.at(i)=x.at(i+1)-x.at(i);
    }
    sort(y.begin(),y.end());
    reverse(y.begin(),y.end());
    rep(i,n-1){
        dif-=y.at(i);
    }
    cout << dif << endl;
   }
}



Measured memory_bytes: 4032
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a*b/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e7

using namespace std;
typedef long long int ll;

int main()
{
    int N,M; cin >> N >> M;
    vector<pair<int,int>>g;
    for(int i = 0; i < M; i++)
    {
        int a,b;cin >> a >> b;
        a--,b--;
        g.push_back(pair(b,a));
    }
    sort(g.begin(),g.end());
    int x = -1;
    int ans = 0;
    for(int i = 0; i < M; i++)
    {
        int a = g[i].second;
        int b = g[i].first;
        if(a <= x) continue;
        x = b - 1;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4264
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b=sc.nextInt();
		String s = sc.next();
		for(int i=0;i<s.length();i++) {
			if(s.charAt(a)!='-') {
				System.out.println("No");
				return;
			}
			if(s.charAt(i)=='-'&& i!=a) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 23764
package main

import (
	"fmt"
)

func main() {

	var n, m int
	fmt.Scanln(&n, &m)

	A := make([][]int, n)
	for i := range A {
		A[i] = make([]int, m)
	}

	for i := range A {
		for j := range A[i] {
			fmt.Scanf("%d", &A[i][j])
		}
	}

	B := make([]int, m)

	for i := range B {
		fmt.Scanf("%d", &B[i])
	}

	C := make([]int, n)

	for i, an := range A {
		for j, anm := range an {
			C[i] += anm * B[j]
		}
		fmt.Println(C[i])
	}

}



Measured memory_bytes: 1752
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <iostream> 
#include <iomanip>  
#include <string>
#include <sstream>  
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <cstring>
#include <cmath>
#include <cassert>


#define INF              (int)1000000007
#define EPS              1e-9
#define pb               push_back
#define mp               make_pair
#define all(c)           c.begin(), c.end()
#define forall(i,a,b)    for(int i=a;i<(b);++i)
#define trav(a,x)        for(auto & a: x)
#define in(a,b)          ((b).find(a) != (b).end())
#define sz(c)            (int)(c).size()
#define input(a)         for(auto & x : a) cin >> x;

using namespace std;

typedef vector<int>      vi;
typedef pair<int,int>    ii;
typedef vector<vi>       vvi;
typedef vector<ii>       vii;
typedef long long        ll;

#ifdef DEBUG
#define debug(args...)   {dbg,args; clog<<endl;}
#define print_( a )      for( auto & x : a ) clog << x << ' '; clog << '\n';
#define printPair_( a )  for( auto & x : a ) clog << '(' << x.first << ',' << x.second << ')' << ' '; clog << '\n';
#else
#define debug(args...)            
#define print_( a )               
#define printPair_( a )           
#endif

struct debugger {
  template<typename T> debugger& operator , (const T& x) {    
    clog << x << " ";    return *this;    
  }
}dbg;

auto ____ =[]() { std::ios::sync_with_stdio(0); cin.tie(0); return nullptr; }();

int main( int argc, char * argv[] ){
  int n; cin >> n; 
  vi v(n); input(v);
  vi u(n); forall(i,0,n) u[i] = i;
  sort(all(u), [&v](int x, int y){ return v[x] < v[y]; });
  forall(i,0,n) cout << u[i]+1 << ' ';
  cout << endl;
  return 0;
}


Measured memory_bytes: 1664
#include <cstdio>
using namespace std;

typedef long long LL;
const int M = 20;
const int N = 32770;
const int Mod = 998244353;
int n, m, s[N], t[N], x[N], r[N], fac[N], inv[N];

inline void swap(int &a, int &b) {int t = a; a = b, b = t;}
inline void red(int &ls, int *a) {
	ls = 0; char ch = getchar();
	for (; ch<'0' || ch>'1';) ch = getchar();
	for (; ch>='0' && ch<='1';) a[++ls] = ch-'0', ch = getchar();
}

namespace FFT {
	int n, L, R[N], wn[N];
	inline int Qow(int A, int B) {
		int S = 1;
		for (; B; B >>= 1, A = 1LL * A * A % Mod)
			if (B & 1) S = 1LL * S * A % Mod;
		return S;
	}
	inline void init(int len) {
		for (n = 1, L = 0; n < len; n <<= 1, ++L);
		for (int i = 1; i < n; ++i)
			R[i] = (R[i >> 1] >> 1) | ((i & 1) << L - 1);
		wn[0] = Qow(3, Mod - 1 >> L);
		for (int i = 1; i < L; ++i)
			wn[i] = 1LL * wn[i - 1] * wn[i - 1] % Mod;
	}
	inline void init_inv() {
		wn[0] = Qow(wn[0], Mod - 2);
		for (int i = 1; i < L; ++i)
			wn[i] = 1LL * wn[i - 1] * wn[i - 1] % Mod;
	}
	inline void Cpy(int *x, int n, int *y, int m) {
		for (int i = 0; i < n; ++i) y[i] = x[i];
		for (int i = n; i < m; ++i) y[i] = 0;
	}
	inline void FFT(int *x) {
		for (int i = 0; i < n; ++i) if (i < R[i]) swap(x[i], x[R[i]]);
		for (int i = 1, l = L - 1; i < n; i <<= 1, --l)
			for (int j = 0; j < n; j += i << 1)
				for (int u, v, k = 0, w = 1; k < i; ++k, w = 1LL * w * wn[l] % Mod)
					u = x[j + k], v = 1LL * w * x[i + j + k] % Mod,
					x[j + k] = (u + v) % Mod, x[i + j + k] = (u + Mod - v) % Mod;
	}
	inline void Mul(int *a, int n, int *b, int m, int *ret) {
		static int x[N], y[N];
		init(n + m - 1);
		Cpy(a, n, x, FFT::n), Cpy(b, m, y, FFT::n);
		FFT(x), FFT(y);
		for (int i = 0; i < FFT::n; ++i)
			x[i] = 1LL * x[i] * y[i] % Mod;
		init_inv(), FFT(x);
		int v = Qow(FFT::n, Mod - 2);
		for (int i = 0; i < FFT::n; ++i)
			ret[i] = 1LL * v * x[i] % Mod;
	}
}

int main() {
	int ls, ret = 0; red(ls, s), red(ls, t);
	for (int i = 1; i <= ls; ++i)
		if (s[i] && t[i]) ++n;
		else if (s[i] && !t[i]) ++m;
	
	r[0] = fac[0] = inv[0] = inv[1] = fac[1] = 1;
	for (int i = 2; i <= n + m + 1; ++i) fac[i] = 1LL * fac[i-1] * i % Mod;
	for (int i = 2; i <= n + m + 1; ++i) inv[i] = 1LL * (Mod - Mod/i) * inv[Mod%i] % Mod;
	for (int i = 2; i <= n + m + 1; ++i) inv[i] = 1LL * inv[i] * inv[i - 1] % Mod;
	for (int i = 0; i <= n; ++i) x[i] = inv[i + 1];
	
	for (int t = m; t; t >>= 1, FFT :: Mul(x, n + 1, x, n + 1, x))
		if (t & 1) FFT :: Mul(x, n + 1, r, n + 1, r);
	for (int i = 0; i <= n; ++i) ret = (ret + r[i]) % Mod;
	
	return printf("%lld\n", 1LL * ret * fac[n] % Mod * fac[m] % Mod * fac[n+m] % Mod), 0;
}

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

int main() {
  int a, r=0;
  cin >> a;
  string n;
  cin >> n;
  for(int i=0;i<a;i++){
    if(n.at(i)=='R'){
      r+=1;
    }
  }
  if(r>a-r){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }
       
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var a = Reads();


            long max = 0;
            for (int i = 0; i < n - 1; i++)
            {
                for (int j = i; j < n; j++)
                {
                    long tmp = Math.Abs(a[i] - a[j]);
                    if (max < tmp)
                        max = tmp;
                }
            }
            Console.WriteLine(max);
            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>

using namespace std;

typedef long long signed int ll;

constexpr ll NIL = -20000000000;

ll a[500010];
int h;

ll rk(int n) {
    if(n*2+1 <= h) return a[n*2+1];
    return NIL;
}
ll lk(int n) {
    if(n*2 <= h) return a[n*2];
    return NIL;
}
ll pk(int n) {
    if(n/2 <= h) return a[n/2];
    return NIL;
}

void print(int n){
    cout << "node " << n << ": key = " << a[n] << ", ";
    pk(n);lk(n);rk(n);
    cout << endl;
}

void heaplify(int n) {
    int l = n;
    if(a[l] < rk(n)) l = n*2+1;
    if(a[l] < lk(n)) l = n*2;
    if(l != n){
        swap(a[l],a[n]);
        heaplify(l);
    }
}

int main() {
    cin >> h;
    for (int i = 1; i <= h; i++) cin >> a[i];
    for(int i = h;i > 0;i--) heaplify(i);
    for(int i = 1;i <= h; i++)cout << " " << a[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 6908
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int MAXN = (int) 1e5 + 10;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

int n;

void work(){
    scanf("%d",&n);
    int mx=-INF,mi=INF;
    LL sum=0;
    for(int i=1;i<=n;i++){
        int x; scanf("%d",&x);
        mx=max(mx,x);
        mi=min(mi,x);
        sum+=x;
    }
    printf("%d %d %lld\n",mi,mx,sum);
}

int main(){
    work();
    return 0;
}












Measured memory_bytes: 2724
/**
*    author:  souzai32
*    created: 13.08.2020 15:01:26
**/

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

int main() {

    long long x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a),q(b),r(c);
    rep(i,a) cin >> p.at(i);
    rep(i,b) cin >> q.at(i);
    rep(i,c) cin >> r.at(i);

    sort(p.begin(),p.end(),greater<>());
    sort(q.begin(),q.end(),greater<>());
    sort(r.begin(),r.end(),greater<>());

    long long ans=0;
    rep(i,x) ans+=p.at(i);
    rep(i,y) ans+=q.at(i);
    // cout << ans << endl;

    x--; y--;
    int xmin=p.at(x),ymin=q.at(y),num;
    // cout << xmin << ' ' << ymin << endl;
    int i=0;
    while(true){
        if(xmin>ymin){
            num=ymin;
            y--;
            if(y<0) ymin=1e9;
            else ymin=q.at(y);
        }
        else{
            num=xmin;
            x--;
            if(x<0) xmin=1e9;
            else xmin=p.at(x);
        }

        // cout << num << ' ' << i << ' '<< r.at(i) << endl;

        if(r.at(i)>num){
            ans+=r.at(i)-num;
            i++;
            // cout << ans << endl;
            // cout << num << endl;
            // cout << r.at(i-1) << endl;
        }
        else break;
        if(i==c) break;
        if(x<0&&y<0) break;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4516
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████   
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬╬╬██╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓▓█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<60
#define fs first
#define sc second
#define pb push_back
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef pair<int,int> P;
typedef vector<vector<P>> Graph;

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

  int a,b,x,c,d,y,z;
  cin >> a >> b >> x >> c >> d >> y >> z;

  int ans = b;
  
  if((c % 2 == 1 && d % 2 == 1) || (a % 2 == 1 && d % 2 == 1) || (c % 2 == 1 && a % 2 == 1)){
    if(a != 0 && c != 0 && d != 0){
      ans += 3;
      a--;
      c--;
      d--;
    }
  }
  
  ans += c/2*2;
  ans += d/2*2;
  ans += a/2*2;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
a = [0 for i in range(n + 1)]
for i in range(m):
    L, R = map(int, input().split())
    L -= 1
    R -= 1
    a[L] += 1
    a[R + 1] -= 1
a_t = [0]
for i in range(n + 1):
    a_t.append(a[i] + a_t[i])
ans = 0
for i in range(n + 2):
    if a_t[i] == m:
        ans += 1
print(ans)

Measured memory_bytes: 8076
import bisect
n,d,a = map(int,input().split())
l = []
for i in range(n):
    x,h = map(int,input().split())
    l.append([x,h])
l.sort(key=lambda x:x[0])
x = [l[0][0]]
c = 1
ans = l[0][1]//a
if l[0][1] % a > 0:
    ans += 1
count = [ans]
y = 0
for i in range(1,n):
    y = bisect.bisect_left(x,l[i][0]-2*d)
    #print(x,y,l[i],count,ans)
    if y > 0 and y < c:
        if (ans-count[y-1])*a < l[i][1]:
            b = (l[i][1] - (ans-count[y-1])*a)//a
            if (l[i][1]-(ans-count[y-1])*a) % a > 0:
                b += 1
            x.append(l[i][0])
            count.append(ans+b)
            ans += b
            c += 1
    else:
        if y == 0:
            if ans*a < l[i][1]:
                    b = (l[i][1] - ans*a)//a
                    if (l[i][1] - ans*a)%a > 0:
                        b += 1
                    x.append(l[i][0])
                    count.append(ans+b)
                    ans += b
                    c += 1
        else:
            b = l[i][1]//a
            if l[i][1]%a > 0:
                b += 1
            x.append(l[i][0])
            ans += b
            count.append(ans)
            c += 1
print(ans)

Measured memory_bytes: 50692
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    public static void Main()
    {
        string[] input = Console.ReadLine().Split();
        long N = long.Parse(input[0]);
        long K = long.Parse(input[1]);
        Console.WriteLine(Math.Min(N % K, -N % K + K));
    }
}

Measured memory_bytes: 13140
n, m = map(int, input().split())
paths = set()

for i in range(m) :
    _a, _b = map(int, input().split())
    paths.add((_a - 1, _b - 1))
    paths.add((_b - 1, _a - 1))

full_mask = "".join(["1" for x in range(n)])
zero_mask = "".join(["0" for x in range(n)])
p_cnt = 0

def dfs(cur_idx, mask) :
    global p_cnt
    
    # set mask and do traverse
    new_mask = list(mask)
    new_mask[cur_idx] = "1"
    new_mask = "".join(new_mask)

    # print("DBG : ", cur_idx, new_mask, full_mask, new_mask == full_mask)
    
    if new_mask == full_mask :
        p_cnt += 1
    else :
        for i in range(n) :
            # if cur_idx -> i in set and i not traversed yet..
            if (cur_idx, i) in paths and mask[i] != "1" :
                dfs(i, new_mask)

dfs(0, zero_mask)
print(p_cnt)
    
            
        

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int d = 0;
  int e = 0;
  int f = 0;
  for(int i = 0;i < a;++i){
    int rrr;
    cin >> rrr;
    if(rrr <= b){d++;}
    else if(rrr <= c){e++;}
    else{f++;}
  }
    cout << min(d,min(e,f)) << endl;
  }

Measured memory_bytes: 256
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;

/**
 * Created by mochizukimasao on 2017/09/22.
 *
 * @author mochizukimasao
 * @since version
 */
public class Main {
	
	static Scanner scanner = getScanner();
	
	public static void main(String[] args) {

		int total = scanner.nextInt();
		int second = scanner.nextInt();

		if (total < second) {
			System.out.println(0);
		} else {
			System.out.println(total - second);
		}
	}


	public static Scanner getScanner() {
		Scanner myScanner = null;
		try {
			myScanner = new Scanner(new FileInputStream("input.txt"));
		} catch (IOException e) {
			myScanner = new Scanner(System.in);
		}
		return myScanner;
	}
}


Measured memory_bytes: 20944
import java.io.*;
import java.util.*;
class Main
{
  public static void main(String args[])
  {
    Scanner Sc=new Scanner(System.in);
    int r=Sc.nextInt();
    int c=Sc.nextInt();
    int r1=Sc.nextInt();
    int c1=Sc.nextInt();
    int a=r-r1;
    int b=c-c1;
    
    System.out.println(a*b);
  }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

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

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    cout << A * B / 2 << endl;

    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int ans[N];
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        ans[a - 1] = i + 1;
    }
    for (int i = 0; i < N; i++) {
        printf("%d ", ans[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 1152
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(m)]

a = []
b = []
for i in l:
    if i[0] == 1:
        a.append(i[1])
    if i[1] == n:
        b.append(i[0])

print("POSSIBLE" if len(set(a)&set(b)) > 0 else "IMPOSSIBLE")

Measured memory_bytes: 61016
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
const int mod = 1e9+7;
const int maxn = 1e5+5;
const double EPS = 1e-6;
using namespace std;
int a[maxn],b[maxn],c[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	rep(i,0,n) scanf("%d",&a[i]);
	rep(i,0,n) scanf("%d",&b[i]);
	rep(i,0,n) scanf("%d",&c[i]);
	sort(a,a+n);sort(b,b+n);sort(c,c+n);
	ll ans = 0;
//	rep(i,0,n) printf("%d ",a[i]);
//	cout<<endl;
//	rep(i,0,n) printf("%d ",b[i]);
//	cout<<endl;
//	rep(i,0,n) printf("%d ",c[i]);
//	cout<<endl;
	rep(i,0,n){
		int pos = lower_bound(a,a+n,b[i])-a;
//		dd(pos);
		int pos1 = upper_bound(c,c+n,b[i])-c;
//		dd(pos1);
//		dd(num);de(num1);
		int num1 = pos;
		int num2 = n-pos1;
		ans+=(ll)num1*(ll)num2;
	}
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
using Int = long long;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.rbegin(), A.rend());
    int alice = 0, bob = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) alice += A[i];
        else            bob += A[i];
    }
    cout << alice - bob << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int m=0, f=0, r=0;
    
    while(1) {
        scanf("%d%d%d",&m,&f,&r);
        if ((m==-1)&&(r==-1)&&(f==-1))
            return 0;
        if((m==-1)||(f==-1)) 
            printf("F\n");
        else if(m+f<30)
            printf("F\n");
        else if(m+f<50) {
            if(r>=50) 
                printf("C\n");
            else
                printf("D\n");
        } else if(m+f<65)
            printf("C\n");
        else if(m+f<80)
            printf("B\n");
        else 
            printf("A\n");
    }
    
    return 0;
}   

Measured memory_bytes: 2692
#include <cstdio>
#include <vector>

std::vector<char> str;

int main(){
  char c;
  while((c=getchar())!='\n'){
    if(str.size()&&(str.back()=='S')&&(c=='T')){
      str.pop_back();
    }else{
      str.push_back(c);
    }
  }
  printf("%d\n",(int)str.size());
  return 0;
}


Measured memory_bytes: 640