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

using namespace std;

int main(void) {
    int r, c;
    cin >> r >> c;
    
    vector<vector<int>> sheet(r + 1, vector<int>(c + 1));
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cin >> sheet[i][j];
            sheet[i][c] += sheet[i][j];
            sheet[r][j] += sheet[i][j];
            sheet[r][c] += sheet[i][j];
        }
    }

    for (auto row : sheet) {
        ostringstream oss;    
        for (auto col : row) {
            oss << (oss.str() != "" ? " " : "") << col;
        }
        
        cout << oss.str() << endl;
    }

    return 0;
}

Measured memory_bytes: 3176
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
//#define mod2 20071027
//#define MOD 998244353
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a) for(int i=1;i<=a;i++)
#define base 139
//#define mod 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
const ll N=200010,M=1000010;
ll n, a[N], mem[N][4], vis[N][4];
ll dp(ll pos, ll c)
{
    if(pos>n) return 0;
    ll &ret=mem[pos][c];
    if(vis[pos][c]) return ret;
    vis[pos][c]=1;
    ret=a[pos];
    if(c==2)
    {
        ret+=max(dp(pos+2, c), max(dp(pos+3, c-1), dp(pos+4, c-2)));
    }
    else if(c==1)
        ret+=max(dp(pos+2, c),dp(pos+3, c-1));
    else ret+=dp(pos+2, c);
    return ret;
}
int main()
{
    in1(n);
    for(int i=1;i<=n;i++)
        in1(a[i]);
    memz(vis);
    ll c, res=MIN;
    if(n%2) c=2;
    else c=1;
    res= dp(1, c);
    memz(vis);
    res=max(res, dp(2, c-1));
    memz(vis);
    if(n%2) res = max(res, dp(3, c-2));
    printf("%lld\n", res);
    return 0;
}

/*

*/


Measured memory_bytes: 25588
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define mod 1000000000+7
#define rep(i,n) for(int i=0;i<(int) (n);i++)
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a+b+c>=22)cout<<"bust";
  else cout<<"win";
}


Measured memory_bytes: 256
N = int(input())
data = [i for i in input().split()]

number_count = {}
for cmp in data:
    if cmp in number_count:
        number_count[cmp] += 1
        continue
    number_count[cmp] = 1

C_tot = 0
for cmp in number_count:
    C_tot += int(number_count[cmp] * (number_count[cmp] - 1) / 2)

for k in range(N):
    C = C_tot - int(number_count[data[k]] * (number_count[data[k]] - 1) / 2) + int((number_count[data[k]] - 1) * (number_count[data[k]] - 2) / 2)
    print(str(C))


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

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

	int list[100];

	for(int i = 0; i < n; i++) cin >> list[i];


	for(int i = n -1; 0 < i; i--){
		cout << list[i] << " ";
	}

	cout << list[0] << endl;
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int H,A[MAX+1];

int parent(int i) {return i/2;}
int left(int i) {return 2*i;}
int right(int i) {return 2*i+1;}

void maxHeapify(int k){
    int l=left(k);
    int r=right(k);
    int largest;
    if(l<=H&&A[l]>A[k]) largest=l;
    else largest=k;
    if(r<=H&&A[r]>A[largest]) largest=r;
    if(largest!=k){
        swap(A[largest],A[k]);
        maxHeapify(largest);
    }
}

void extract(){
    int maxv;
    maxv=A[1];
    A[1]=A[H--];
    maxHeapify(1);
    cout << maxv << endl;
}

void insert(int key){
    H++;
    A[H]=key;
    int x=H;
    while(x>1&&A[x/2]<A[x]){
        swap(A[x],A[x/2]);
        x=x/2;
    }
}


int main(void){
    int key;
    string str;
    
    while(1){
        cin >> str;
        if(str=="end") break;
        else if(str=="insert"){
            cin >> key;
            insert(key);
        }else if(str=="extract"){
            extract();
        }
    }
    return 0;
}



















Measured memory_bytes: 7044
#include <bits/stdc++.h>
const int INF = 1e9;
const int MODk = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define COUTDOUBLE(v) cout << std::setprecision(10)<<(v)<<endl;
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N,K;cin >> N >> K;
    if(K == 0){
        for(int a = 0;a < pow(2, N+1);a++){
            cout<<a/2<<" ";
        }
        cout<<endl;
    }else{
        if(K > pow(2,N)-1){
            cout<<-1<<endl;
            return 0;
        }
        int Xor = 0;
        for(int a = 1;a <= pow(2,N)-1;a++){
            if(a != K)Xor^= a;
        }
        if(Xor == K){
            for(int a = 0;a <= pow(2,N)-1;a++){
               if(a != K) cout<<a<<" ";
            }
            cout<<K<<" ";
            for(int a = pow(2,N)-1;a >= 0;a--){
                if(a != K)cout<<a<<" ";
            }
            cout<<K<<endl;
        }else{
            cout<<-1<<endl;
        }
    }

}


Measured memory_bytes: 1792
package main

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

func out(x ...interface{}) {
	//	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

// UnionFind高速
type UnionFind struct {
	par []int
	r   []int
}

func newUnionFind(N int) *UnionFind {
	u := new(UnionFind)
	u.par = make([]int, N)
	u.r = make([]int, N)
	for i := 0; i < N; i++ {
		u.par[i] = i
		u.r[i] = 1
	}
	return u
}

func (p *UnionFind) root(x int) int {
	if p.par[x] == x {
		return x
	}
	return p.root(p.par[x])
}

func (p *UnionFind) unite(x, y int) {
	x = p.root(x)
	y = p.root(y)
	if p.r[x] < p.r[y] {
		p.par[x] = y
	} else {
		p.par[y] = x
		if p.r[x] == p.r[y] {
			p.r[x]++
		}
	}
}

func (p *UnionFind) same(x, y int) bool {
	return p.root(x) == p.root(y)
}

type node struct {
	to []int
}

func route(s int, n []node, pass []bool, cnt, N int, ans *int) {
	pass[s] = true
	cnt++
	out("now", s, "pass", pass, cnt)
	if cnt == N {
		*ans++
		out("find....")
	}
	for _, v := range n[s].to {
		//		out(v)
		apass := make([]bool, N)
		copy(apass, pass)
		if pass[v] == true {
			continue
		}
		route(v, n, apass, cnt, N, ans)
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M := getInt(), getInt()
	n := make([]node, N)
	for i := 0; i < M; i++ {
		from, to := getInt()-1, getInt()-1
		out(from, to)
		n[from].to = append(n[from].to, to)
		n[to].to = append(n[to].to, from)
	}

	pass := make([]bool, N)
	var ans int
	route(0, n, pass, 0, N, &ans)

	fmt.Println(ans)
}


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

int main() {
   ll i,j,k;
    ll a,b,n;
    string ans="No";
    cin >>n;
   for(i=1; i<10; i++)
   {
     if(n%i==0 && n/i<10)
     {
      ans="Yes";

     }
   }
   cout<<ans<<endl;
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			System.out.println(kaikyu(sc.nextDouble()));
		}
		sc.close();
	}
	
	public static String kaikyu(double num){
		if(num <= 48.00){
			return "light fly";
		}else if(48.00 < num && num <= 51.00){
			return "fly";
		}else if(51.00 < num && num <= 54.00){
			return "bantam";
		}else if(54.00 < num && num <= 57.00){
			return "feather";
		}else if(57.00 < num && num <= 60.00){
			return "light";
		}else if(60.00 < num && num <= 64.00){
			return "light welter";
		}else if(64.00 < num && num <= 69.00){
			return "welter";
		}else if(69.00 < num && num <= 75.00){
			return "light middle";
		}else if(75.00 < num && num <= 81.00){
			return "middle";
		}else if(81.00 < num && num <= 91.00){
			return "light heavy";
		}else if(91.00 < num){
			return "heavy";
		}
		return null;
	}
}

Measured memory_bytes: 19340
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < (int) n; i++)
#define forin(i, a, b) for(int i = a; i < (int) b; i++) 
#define rofin(i, a, b) for(int i = a; i > b; i--)
#define v vector
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define debug(i) cout << #i << ": " << i << endl
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

int N, W;
const ll INF = 1e18L + 5;

int main() {
    crap;
    cin >> N >> W;
    vi weight(N), value(N);
    forn(i,N) cin >> weight[i] >> value[i];

    int sum_value = 0;
    forn(i,N) sum_value += value[i];


    vector<ll> dp(sum_value+1, INF);
    dp[0] = 0;
    
    forn(i,N) {
        int w = weight[i], v = value[i];
        
        rofin(value_alr, sum_value - v, -1) {
            dp[value_alr+v] = min(dp[value_alr+v],dp[value_alr]+w);
        }
    }
    ll ans = 0;
    forn(i, sum_value+1) {
        if(dp[i]<=W) {
            ans = max(ans, (ll) i);
        }
    }

    cout << ans << endl;
     

}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		// ???????????\???
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input = br.readLine();
		String str[] = input.split(" ");

		int h = Integer.parseInt(str[0]); // ??????
		int w = Integer.parseInt(str[1]); // ??????

		while (true) {
			if (h == 0 && w == 0) {
				// ??¨??????0
				break;
			} else {
				// ????????\???
				for (int i = 0; i < h; i++) {
					if (i == 0 || i == (h - 1)) {
						// ??????or??????
						for (int j = 0; j < w; j++) {
							// ??????(#?????????)
							System.out.print("#");
						}
						// ??????(??????)
						System.out.println();
					} else {
						for (int j = 0; j < w; j++) {// ??????(#?????????)
							if (j == 0 || j == (w - 1)) {
								System.out.print("#");
							} else {
								System.out.print(".");
							}
						}
						// ??????(??????)
						System.out.println();
					}
				} // ?????¬?????????????????????

				System.out.println();
				// ?¬??????\??????????????????
				input = br.readLine();
				str[0] = null;
				str[1] = null;
				str = input.split(" ");
				h = Integer.parseInt(str[0]);
				w = Integer.parseInt(str[1]);
			}
		}
	}

}

Measured memory_bytes: 31388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
ll n,m,q[N],ptr,use[N],deg[N][2],a[N];
string s;
vector<ll> adj[N];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n>>m>>s;
    for(ll i=0;i<n;i++)a[i]=(s[i]=='A');
    for(ll i=0,u,v;i<m;i++){
        cin>>u>>v;
        u--;v--;
        adj[v].push_back(u);
        adj[u].push_back(v);
        deg[v][a[u]]++;
        deg[u][a[v]]++;
    }
    for(ll i=0;i<n;i++)if(deg[i][0]==0||deg[i][1]==0)use[i]=1,q[ptr++]=i;
    for(ll i=0;i<ptr;i++){
        ll u=q[i];
        for(auto &v:adj[u]){
            if(use[v])continue;
            deg[v][a[u]]--;
            if(deg[v][a[u]]==0)use[v]=1,q[ptr++]=v;
        }
    }
    cout<<(ptr==n?"No":"Yes");
}

Measured memory_bytes: 19536
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		sc.close();

		int ans = 0;
		for (int i = 1; i < n; i++) {
			Set<Character> set1 = new HashSet<>();
			for (int j = 0; j < i; j++) {
				set1.add(s.charAt(j));
			}
			Set<Character> set2 = new HashSet<>();
			for (int j = i; j < n; j++) {
				set2.add(s.charAt(j));
			}
			int cnt = 0;
			for (char c = 'a'; c <= 'z'; c++) {
				if (set1.contains(c) && set2.contains(c)) {
					cnt++;
				}
			}
			ans = Math.max(ans, cnt);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
import java.util.*;

public class Main {
public static void main(String[] args){
  Scanner in=new Scanner(System.in);
  int n=in.nextInt();
  int[] a=new int[n+2];
  int ans=0;
  a[0]=0;
  a[n+1]=0;
  for(int i=1;i<=n;i++){
   a[i]=in.nextInt();
  ans+=Math.abs(a[i]-a[i-1]);
}
 ans+=Math.abs(a[n+1]-a[n]);
for(int i=1;i<=n;i++){
int ans1=ans-Math.abs(a[i]-a[i-1])-Math.abs(a[i+1]-a[i])+Math.abs(a[i+1]-a[i-1]);
System.out.println(ans1);
}


}
}

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

int main()
{
    int N;
    while(cin >> N)
    {
        bool flg = false;
        for(int i = 0;i <= 100;i ++)
        {
            for(int j = 0;j <= 100;j ++)
            {
                if(i * 4 + j * 7 == N)
                {
                    cout << "Yes" << endl;
                    flg = true;
                    i = 101;j = 101;
                }
            }
        }
        if(!flg)
        {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=100000;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    map<string,ll> ma;
    for(int i=0;i<n;i++){
        string a;
        cin >> a;
        sort(a.begin(),a.end());
        ma[a]++;
    }
    ll ans=0;
    for(auto it=ma.begin();it!=ma.end();it++){
        ans+=it->second*(it->second-1)/2;
    }
    cout << ans << endl;
}


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

int main() {
  int A, B, C ,X ,Y = 0;
  cin >> A >> B >> C >> X >> Y;
  
  int com = min(X, Y);
  
  int ans = min((A+B) * com, 2*C * com);
  
  int diff;
  if (X >= Y) {
    diff = X - Y;
    ans += min(A * diff, 2*C * diff);
  } else {
    diff = Y - X;
    ans += min(B * diff, 2*C * diff);
  }
  
  cout << ans << endl;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var array = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var min = long.MaxValue;
            var minusCount = 0;
            var total = 0L;

            for (var i = 0; i < N; i++)
            {
                var tmp = Math.Abs(array[i]);
                min = Math.Min(tmp, min);
                total += tmp;

                if (array[i] < 0) minusCount++;
            }

            var isMinusEven = (N - minusCount) % 2 == 0;

            if (N % 2 == 0)
                Console.WriteLine(isMinusEven ? total : total - (min * 2));
            else
                Console.WriteLine(isMinusEven ? total - (min * 2) : total);
        }
    }
}


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

int main(){
    int N,ans;
    cin>>N;
    if(N<105){ ans=0;}
    else if(N<=134){ans=1;}
    else if(N<=164){ans=2;}
    else if(N<=188){ans=3;}
    else if(N<=194){ans=4;}
    else {ans=5;}
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  int kotae=0;
  char a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  if(a==d){kotae++;}
  if(b==e){kotae++;}
  if(c==f){kotae++;}
  cout<<kotae;
}

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

typedef long long ll;

constexpr int MAX_N = 300003;
constexpr ll mod = 1e9 + 7;
ll fact[MAX_N], inv[MAX_N];

ll powm(ll x, ll p) {
	if (p == 0) return 1;
	ll res = powm(x, p / 2);
	res *= res;
	res %= mod;
	if (p % 2LL == 1) {
		res *= x;
		res %= mod;
	}
	return res;
}

void init_fact() {
	fact[0] = inv[0] = 1;
	for (ll i = 1; i < MAX_N; ++i) {
		fact[i] = fact[i - 1] * i;
		fact[i] %= mod;
		inv[i] = powm(fact[i], mod - 2);
	}
}

// aCb
ll C(ll a, ll b) {
	if (a - b < 0) return 0;
	ll res = fact[a];
	res *= inv[b];
	res %= mod;
	res *= inv[a - b];
	return res%mod;
}

// aPb
ll P(ll a, ll b) {
	return fact[a] * inv[a - b] % mod;
}


int main() {
	int H, W, A, B; cin >> H >> W >> A >> B;
	init_fact();
	ll ans = C(W + H - 2, W - 1);
	ll w = 0;
	for (int i = H - A + 1; i <= H; ++i) {
		w += (C(i + B - 2, B - 1)*C(H - i + W - B - 1, W - B - 1))%mod;
		w %= mod;
		if (w < 0) cout << w << endl;
	}
	ans += (mod - w);
	ans %= mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
'use strict'
 
function main(s) {
  s = s.replace(/\r?\n/g,'');
  s = s.split('');
  let kekka = 0;
  for(var i = 0; i < s.length;i++){
    kekka += Number(s[i]); 
  }

  if(kekka % 9 == 0){
    console.log("Yes");
  }else{
    console.log("No");
  }
}
 
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 34728
// I'm a f*cking looser
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define input(A) for(auto &i:A) cin>>i;
signed main()
{
    fasino
    ll n;
    cin>>n;
    if(n>=30){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#define MAX 10000

int pre[MAX],in[MAX],post[MAX],pos=0,n,back=0;
int find(int x){
  int i;
  for(i=0;i<n;i++)if(x==in[i])return i;
}

void rec(int l,int r){
  int root,m;
  if(l>=r)return;
  root=pre[pos++];
  m=find(root);//
  rec(l,m);
  rec(m+1,r);
  post[back++]=root;
}
void solve(){
  int i;
  rec(0,n);
  for(i=0;i<n;i++){
    if(i)printf(" ");
    printf("%d",post[i]);
  }
  printf("\n");
}

int main(){
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&pre[i]);
   for(i=0;i<n;i++)scanf("%d",&in[i]);
   solve();
   
  return 0;
  
}

Measured memory_bytes: 608
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
 
class Program
{
    static void Main()
    {
        int num = int.Parse(Console.ReadLine().Replace(" ", ""));
        Console.WriteLine(num % 4 == 0 ? "YES" : "NO");
    }
}


Measured memory_bytes: 11092
import java.util.*;

public class Main{
	
	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		int num = sc.nextInt();
		int[] a = new int[num];
		int tmp;
		long ans = 0;
		
		for(int i=0; i<num; i++){
			tmp = sc.nextInt();
			//a[i] = tmp;	
			a[i] = tmp-(i+1);	
		}

		Arrays.sort(a);
	
		for(int i=0; i<num; i++){
			ans += (long)Math.abs(a[i] - a[num/2]);
		}
		
		System.out.println(ans);
		
	}

}

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

int main()
{
  int n;
  cin >> n;
  
  int x[n];
  int s = 101,g = -1;
  for(int i = 0; i < n; i++){
    cin >> x[i];
    if(x[i] < s){
      s = x[i];
    }else if(x[i] > g){
      g = x[i];
    }
  }
  
  int64_t ans = 0,minans = 100000000;
  for(int i = s; i <= g; i++){
    for(int j = 0; j < n; j++){
      ans += abs(i - x[j]) * abs(i - x[j]);
    }//for
    if(ans < minans){
      minans = ans;
    }
    ans = 0;
  }//for
  
  if(n == 1){
    minans = 0;
  }
  
  cout << minans << endl;
  
}

Measured memory_bytes: 3628
#include <iostream>
#include <stack>

using namespace std;

int H, W;
char a[2005][2005];
int b[2005][2005];
int h[2005][2005];
int l[2005], r[2005];

int calc(int x)
{
	stack<int> stk;
	stk.push(0);
	h[x][0] = -1;
	for(int i = 1; i <= H; i++){
		while(h[x][stk.top()] >= h[x][i]) stk.pop();
		l[i] = stk.top()+1;
		stk.push(i);
	}
	
	while(stk.size()) stk.pop();
	stk.push(H+1);
	h[x][H+1] = -1;
	for(int i = H; i >= 1; i--){
		while(h[x][stk.top()] >= h[x][i]) stk.pop();
		r[i] = stk.top()-1;
		stk.push(i);
	}
	
	int ret = 0;
	for(int i = 1; i <= H; i++){
		ret = max(ret, (h[x][i] + 1) * (r[i] - l[i] + 2));
	}
	return ret;
}

int main(void)
{
	cin >> H >> W;
	for(int y = 1; y <= H; y++){
		for(int x = 1; x <= W; x++){
			cin >> a[x][y];
		}
	}
	for(int x = 1; x <= W-1; x++){
		for(int y = 1; y <= H-1; y++){
			int cnt = 0;
			if(a[x][y] == '#') cnt++;
			if(a[x+1][y] == '#') cnt++;
			if(a[x][y+1] == '#') cnt++;
			if(a[x+1][y+1] == '#') cnt++;
			if(cnt % 2 == 0) b[x][y] = 1;
		}
	}
	
	H--, W--;
	for(int y = 1; y <= H; y++){
		int cnt = 0;
		for(int x = 1; x <= W; x++){
			if(b[x][y]) cnt++;
			else cnt = 0;
			h[x][y] = cnt;
		}
	}
	
	int ans = max(W+1, H+1);
	for(int x = 1; x <= W; x++){
		ans = max(ans, calc(x));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

int main(){
  int n;
  cin >> n;
  map<int,int>mp;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    mp[a]++;
  }
  for(auto x:mp){
    if(x.second>1){
      cout<< "NO" <<endl;
      return 0;
    }
  }
  cout<< "YES" <<endl;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main() {
  ll n;
  cin>>n ;
  if(n%2==1)
  cout<<0<<endl ;
  else{
  ll ans=0 ;
  ll w=10 ;
  for(int i=1;i<=40;++i){
    ans+= n/w ;
    w *=5 ;
  }
  cout<< ans<< endl;
   } return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun May  3 21:20:12 JST 2020
 **/

signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> a(n);
    REP(i, n) std::cin >> a[i];
    std::map<Int, Int> cnt;
    REP(i, n) cnt[i - a[i]]++;
    Int ans = 0;
    REP(i, n) ans += cnt[a[i] + i];
    std::cout << ans << std::endl;
}


Measured memory_bytes: 27420
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;


int main()
{
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];
    int ans = 0;
    sort(a.begin(), a.end());

    a[0] += a[2] - a[1];
    ans += a[2] - a[1]; //まず二つ選ぶ
    if((a[2] - a[0]) % 2 == 0){
        ans += (a[2] - a[0]) / 2;
    }else{
        ans += (a[2] + 1 - a[0]) / 2 + 1;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const double EPS = 1e-7;
const double MAX = 1000 + 5;



int main() {
	string s;
	cin >> s;
	int n = s.length();

	if (s[0] == '0' || s[n - 1] == '1') {
		cout << -1 << endl;
		return 0;
	}
	

	for (int i = 0; i <= (n-1)/2; i++) {
		if (s[i] !=  s[n-2-i]) {
			cout << -1 << endl;
			return 0;
		}
	}

	s[n - 1] = '1';
	int r = 0;
	
	for (int i = 0; i < n-1; i++) {
		while (r <= i || s[r] == '0') {
			r++;
		}

		cout << i + 1 << " " << r + 1<< endl;
	}
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef pair<long long, long long> P;
int main(){
    long long N, H;
    cin >> N >> H;
    vector<long long> a(N),b(N);
    vector<P> v(N), u(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i] >> b[i];
        v[i] = P(a[i], b[i]);
        u[i] = P(b[i], a[i]);
    }
    sort(v.begin(), v.end());
    sort(u.begin(), u.end());
    P t = v[N - 1];
    long long ans = 0;
    for(int i = N - 1; i >= 0; i--){
        if(t.first <= u[i].first){
            H -= u[i].first;
            ans++;
        }
        if(H <= 0) break;
    }
    if(H <= 0){
        cout << ans << endl;
        return 0;
    }
    cout << ans + (H + t.first - 1) / t.first << endl;
}

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

int main() {
  int A, B, K;
  cin >> K >> A >> B;
  
  if((A % K == 0) || (B % K == 0))cout << "OK" << endl;
  else if(A/K != B/K)cout << "OK" << endl;
  else cout << "NG" << endl;
  //cout << A/K << " " << B/K << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)

int N;
vector<vector<double>> d;
double f(uint v, int par, double sum) {
    if(v == (255 >> (8-N))) return sum;
    double ret = 0;
    for (int i = 0; i < N; ++i) {
        if (((v >> i) & 1) == 0) {
            uint vv = v;
            vv |= (1 << i);
            ret += f(vv, i, sum + (par == -1 ? 0 : d[par][i]));
        }
    }
    return ret;
}

int main() {
    cin >> N;
    vector<double> X(N);
    vector<double> Y(N);
    rep(i, N) cin >> X[i] >> Y[i];
    d.resize(N);
    rep(i, N) {
        d[i].resize(N);
        rep(j, N) {
            d[i][j] = sqrt(((X[i] - X[j]) * (X[i] - X[j])) + ((Y[i] - Y[j]) * (Y[i] - Y[j])));
        }
    }
    double NN = 1;
    repi(i, 1,N+1) NN *= i;
    cout << fixed;
    cout << setprecision(8) << f(0, -1, 0) / NN << endl;
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

struct BinGraph;
struct BinGraph {
    ll val;
    BinGraph *lch, *rch;
    BinGraph(ll val, BinGraph* lch, BinGraph* rch) : val(val), lch(lch), rch(rch) {}
    void out() {
        cout << "(";
        if (lch != NULL) lch->out();
        cout << ")";
        cout << "[";
        cout << val;
        cout << "]";
        cout << "(";
        if (rch != NULL) rch->out();
        cout << ")";
    }
};

BinGraph* merge(BinGraph* g1, BinGraph* g2) {
    if (g1 == NULL) return NULL;
    if (g2 == NULL) return NULL;
    return new BinGraph(g1->val+g2->val, merge(g1->lch, g2->lch), merge(g1->rch, g2->rch));
}

class Perser {
    const string s;
    ll pos;
public:
    Perser(const string& s) : s(s), pos(0) {}
    BinGraph* perse() {
        return G();
    }
    BinGraph* G() {
        assert(pos < s.size());
        if (s[pos] == ')') {
            return NULL;
        }
        else {
            read_char('(');
            BinGraph* lch = G();
            read_char(')');
            read_char('[');
            ll val = number();
            read_char(']');
            read_char('(');
            BinGraph* rch = G();
            read_char(')');
            return new BinGraph(val, lch, rch);
        }
    }
    ll number() {
        string res = "";
        while (pos < s.size() && isdigit(s[pos])) {
            res += s[pos];
            ++pos;
        }
        return stoll(res);
    }
    void read_char(char c) {
        assert(pos < s.size() && s[pos] == c);
        ++pos;
    }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s1, s2; cin >> s1 >> s2;
    BinGraph* G1 = Perser(s1).perse();
    BinGraph* G2 = Perser(s2).perse();
    merge(G1, G2)->out();
    cout << endl;
}

Measured memory_bytes: 3224
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;

int n;
string s[110];
int t[110];
string tg;

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i ++)
		cin >> s[i] >> t[i];
	cin >> tg;
	bool ok = 0;
	int sum = 0;
	for (int i = 1; i <= n; i ++) {
		sum += ok * t[i];
		if (s[i] == tg)
			ok = 1;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
n = int(input())
s = str(input())
tt = [1 if i  == "W" else 0 for i in s]
B = [0] + tt
B = list(accumulate(B))
ans = float('Inf')
#0とn+1にすることで一番左側と一番右側を選べる

for i in range(n+1):
  	#print(s[0:i],s[i:])
    #ここをprintすればどこで文字列を分けているかわかる．
	#左にいるWの数
    w = B[i]
	#右にいるEの数
    #まず右側の個数は n - i
    #次に右側のWはB[-1] - B[i]
    #WとEしかいないから
    e = n - i - B[-1] + B[i]
    ans = min(ans,w+e)
print(ans)


Measured memory_bytes: 20376
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S,T;
    cin >> S >> T;

    if (S == T.substr(0,S.length()) && S.length() == T.length() - 1) {
            cout << "Yes" << endl;
    } else {

            cout << "No" << endl;
    }

 
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>

using namespace std;
int main() {
  int n, k, x, y, price;
  cin >> n >> k >> x >> y;
  if (n <= k)
  {
    price = n * x;
  }
  else
  {
    price = k * x + (n - k) * y;
  }
  cout << price;

  return 0;
}


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

namespace procon
{
    public class Program
    {
        public static void Main(string[] args)
        {
            while (true)
            {
                var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (inputs[0] == 0 && inputs[1] == 0) break;

                for (int j = 0; j < inputs[0]; j++)
                {
                    string str;
                    if (j == 0 || j == inputs[0] - 1)
                    {
                        str = new string('#', inputs[1]);
                    }
                    else
                    {
                        str = "#" + new string('.', inputs[1] - 2) + "#";
                    }

                    Console.WriteLine(str);
                }

                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 9420
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i < n; i++)
#define repv(i,n) for(int i = n-1; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
using namespace std;
typedef long long ll;

char BUF[3500000];
inline void I(int&a){scanf("%d",&a);}
inline void I(int&a,int&b){scanf("%d%d",&a,&b);}
inline void I(int&a,int&b,int&c){scanf("%d%d%d",&a,&b,&c);}
inline void I(int&a,int&b,int&c,int&d){scanf("%d%d%d%d",&a,&b,&c,&d);}
inline void L(ll&a){scanf("%lld",&a);}
inline void L(ll&a,ll&b){scanf("%lld%lld",&a,&b);}
inline void L(ll&a,ll&b,ll&c){scanf("%lld%lld%lld",&a,&b,&c);}
inline void L(ll&a,ll&b,ll&c,ll&d){scanf("%lld%lld%lld%lld",&a,&b,&c,&d);}
inline void S(string&str){str.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)str.pb(BUF[i]);}
inline void SV(vector<int>&v){v.clear();scanf("%s",BUF);int s=strlen(BUF);rep(i,s)if('a'<=BUF[i]&&BUF[i]<='z')v.pb(BUF[i]-'a');else v.pb(BUF[i]-'A');}

const auto EPS = 1e-10;
const auto INF = 100000000;
const auto MOD = 1000000007;
typedef pair<ll,ll> P;

int n;
int x[26];

int main(){
    I(n);
    rep(i,n){
        string str;
        int y[26];
        memset(y,0,sizeof(y));
        cin >> str;
        rep(j,str.size()){
            y[str[j]-'a']++;
        }
        rep(j,26){
            if(i == 0) x[j] = y[j];
            else x[j] = min(x[j],y[j]);
        }
    }
    rep(i,26){
        rep(j,x[i]){
            cout << (char)('a'+i);
        }
    }
    cout << endl;
}
































Measured memory_bytes: 256
s = str(input())
n = len(s)
t = []
for i in range(n-1):
    if s[i] == 'R' and s[i+1] == 'L':
        ir = i
        #il = i+1
        #t.append([ir, il])
        t.append(ir)

from collections import deque
t.append(10**6)
t_ = deque(t)
post = []
ans = [0]*n
for i in range(n):
    ir = t_.popleft()
    if i < ir:
        if s[i] == 'R':
            if i%2 == ir%2:
                ans[ir] += 1
            else:
                ans[ir+1] += 1
        if s[i] == 'L':
            if i%2 == post[-1]%2:
                ans[post[-1]] += 1
            else:
                ans[post[-1]+1] += 1
        t_.appendleft(ir)
    if i == ir:
        ans[ir] += 1
        post.append(ir)
print(*ans)

Measured memory_bytes: 51004
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=105,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
PII a[N],b[N];
int vis[N],s[N];
int find(int x){
	return s[x]==x?x:s[x]=find(s[x]);
}
int main(){
	int n,m,cnt=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++) s[i]=i;
	for(int i=1;i<=m;i++){
		scanf("%d%d",&a[i].fi,&a[i].se);
	}
	int ans=0;
	for(int i=0;i<(1<<m);i++){
		if(__builtin_popcount(i)!=n-1) continue;
		cnt=0;
		for(int j=0;j<m;j++){
			if((i>>j)&1){
				b[++cnt]=a[j+1];
			}
		}
		mst(vis,0);
		for(int j=1;j<=cnt;j++){
			int u=b[j].fi,v=b[j].se;
			vis[u]++,vis[v]++;
			int fu=find(u),fv=find(v);
			if(fu!=fv) s[fu]=fv;
		}
		int ok=1,sum=0,t=0,v=-1;
		if(vis[1]!=1) ok=0;
		for(int j=2;j<=n;j++){
			if(vis[j]==1) sum++,v=j;
			else if(vis[j]==2) t++;
		}
		for(int i=2;i<=n;i++){
			if(find(i)!=find(1)){
				ok=0;
				break;
			}
		}
		if(ok&&sum==1&&t==n-2) ans++;
		for(int i=1;i<=n;i++) s[i]=i;
	}
	printf("%d\n",ans);
}

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

	int kumi[1000][1000][1000] = { 0 };

int main()
{
	int N;
	int count = 0;
	
	int p[3003];

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> p[(3 * i)] >> p[(3 * i) + 1] >> p[(3 * i) + 2];
		sort(p + (3 * i), p + (3 * i) + 3);
		if (kumi[p[3 * i]][p[(3 * i) + 1]][p[(3 * i) + 2]] == 0) {
			kumi[p[3 * i]][p[(3 * i) + 1]][p[(3 * i) + 2]] = 1;
		}
		else {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 7048
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

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

}
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}







int main() {
  int n,m;
  cin >> n ;
  ll t[n+1];
  rep (i,n){
    cin >> t[i];
  }
  cin >> m;
  ll p[m+1],x[m+1];
  rep (i,m){
    cin >> p[i] >> x[i];
    --p[i];
  }
ll sum = 0;
  rep (i,m){
    sum = x[i]; 
    //cout <<sum << endl; 
    rep (j,n){
   sum += t[j];
   //cout << sum << endl;
    }
   sum -= t[p[i]]; 
    cout << sum << endl;
    //cout << endl;
    sum = 0;
  }

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
#define LL long long
#define N 10000
#define Inf 0x7fffffff
int main()
{
    ios::sync_with_stdio(false);
    int a,b;
    while(cin>>a>>b)
      cout<<(a-1)*(b-1)<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();

        if (S.matches("(dream|dreamer|erase|eraser)+?")) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 36424
#--Odds of Oddness
import math

N = int(input())
harf = math.floor(N/2)

if(N % 2 == 0):
  print('{:.10f}'.format(harf/(2*harf)))
elif(N % 2 == 1):
  print('{:.10f}'.format((harf+1)/(2*harf+1)))


Measured memory_bytes: 2940
#include <algorithm>
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define REP(i, a) for (ll i(0), _##i(a); i < _##i; ++i)
#define FOR(i, a, b) for (ll i(a), _##i(b); i <= _##i; ++i)

#ifdef LOCAL
#define _NTH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N
#define _FE_1(_CALL, x) _CALL(x)
#define _FE_2(_CALL, x, ...) _CALL(x) _FE_1(_CALL, __VA_ARGS__)
#define _FE_3(_CALL, x, ...) _CALL(x) _FE_2(_CALL, __VA_ARGS__)
#define _FE_4(_CALL, x, ...) _CALL(x) _FE_3(_CALL, __VA_ARGS__)
#define _FE_5(_CALL, x, ...) _CALL(x) _FE_4(_CALL, __VA_ARGS__)
#define _FE_6(_CALL, x, ...) _CALL(x) _FE_5(_CALL, __VA_ARGS__)
#define FOR_EACH_MACRO(MACRO, ...)                                             \
  _NTH_ARG(__VA_ARGS__, _FE_6, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1)              \
  (MACRO, __VA_ARGS__)
#define watch(x) cerr << "\033[1;32m" #x " = \033[1;34m" << (x) << "\033[0m; ";
#define debug(...)                                                             \
  cerr << "\033[2;31mLine " << __LINE__ << ": \033[0;m";                       \
  FOR_EACH_MACRO(watch, __VA_ARGS__)                                           \
  cerr << endl
#else
#define debug(...)
#endif

using namespace std;

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << '{' << p.first << ", " << p.second << '}';
}

template <class T, class = decltype(begin(declval<T>())),
          class = enable_if_t<!is_same<T, string>::value>>
ostream &operator<<(ostream &os, const T &c) {
  os << '[';
  for (auto it = begin(c); it != end(c); ++it)
    os << (it == begin(c) ? "" : ", ") << *it;
  return os << ']';
}
using ll = long long;

void solve() {
  int n;
  cin >> n;
  vector<vector<int>> a(3, vector<int>(n + 1));
  FOR(i, 1, n){
    cin >> a[0][i] >> a[1][i] >> a[2][i];
  }

  const int INF = 1e9;
  vector<vector<int>> dp(n + 1, vector<int>(3, -INF));
  dp[0].assign(3, 0);
  FOR(i, 1, n){
    REP(j, 3){
      int x = (j + 1) % 3;
      int y = (j + 2) % 3;
      dp[i][j] = a[j][i] + max(dp[i - 1][x], dp[i - 1][y]);
    }
  }
  cout << *max_element(ALL(dp[n])) << "\n";
}

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

  int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
}


Measured memory_bytes: 6908
m, f, r = map(int, input().split())
g = []
while m != -1 or f != -1 or r != -1:
    s = m + f
    if m == -1 or f == -1:
        g.append("F")
    elif s >= 80:
        g.append("A")
    elif 80 > s >= 65:
        g.append("B")
    elif 65 > s >= 50:
        g.append("C")
    elif 50 > s >= 30:
        if r >= 50:
            g.append("C")
        else:
            g.append("D")
    else:
        g.append("F")
    m, f, r = map(int, input().split())

for p in g:
    print(p)



Measured memory_bytes: 5596
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#endif
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n;
int d[1005];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>d[i];
	ll ans=0;
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++){
		ans+=d[i]*d[j]; 
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define ms(a,v) memset(a,v,sizeof(a))
#define mp make_pair
#define write(x) cout<<(x)<<endl
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; }return 0; }
constexpr ll pow2(const int n) { return 1ll << n; }
const int INF = 1 << 28; const ll LINF = 1ll << 60;
const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6;
const int dy[4] = { 0,1,0,-1 }; const int dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;
// 1. 問題よくよめえええええええええええええええええええええええええ
// 2. intオーバーフロー << * + あたり
// 3. 落ち着け

int N;
vll a;

priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> former, latter;
vector<int> lremain; // 0前半1後半で採用されていない2後半採用されてる

ll fsum = 0, lsum = 0;
ll ans = 0;

int main() {
    cin >> N;
    a.assign(3 * N, 0);
    rep(i, 3 * N) cin >> a[i];

    lremain.assign(3 * N, 0);
    rep(i, N) {
        former.emplace(a[i], i);
        fsum += a[i];
    }
    rep(i, N, 3 * N) {
        latter.emplace(a[i], i);
        lremain[i] = 1;
    }
    rep(i, N) {
        auto& p = latter.top();
        lremain[p.second] = 2;
        lsum += p.first;
        latter.pop();
    }

    ans = fsum - lsum;
    rep(i, N, 2 * N) {
        auto ftop = former.top();
        if (ftop.first < a[i]) {
            former.emplace(a[i], i);
            fsum += a[i] - ftop.first;
            former.pop();
        }
        
        if (lremain[i] == 2) {
            while (lremain[latter.top().second] != 1) {
                latter.pop();
            }

            auto& ltop = latter.top();
            lremain[i] = 0;
            lremain[ltop.second] = 2;
            lsum += ltop.first - a[i];
            latter.pop();
        }
        else {
            // lremain[i] == 1
            lremain[i] = 0; // 意味わからん
        }

        chmax(ans, fsum - lsum);
    }

    write(ans);
}

Measured memory_bytes: 6772
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

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

ll mod = 1e9 + 7;


int n;
char s[100005];
ll dp[100005][13];

int main(){
	string s;
	cin >> s;
	int N=s.size();
	vector<int> ans(N);
	
	for(int i=0;i<N;){
		int l=i;
		while(i<N and s[i]=='R') i++;
		int m=i;
		while(i<N and s[i]=='L') i++;
		int r=i;
		ans[m-1] = (m-l+1)/2 + (r-m)/2;
		ans[m] = (m-l)/2 + (r-m+1)/2;
	}

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

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
const ll mod = 1000000007;
 
void testCase() {
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector <pair<ll, int>> val;
    for (int i=0; i<a; i++) {
        ll v;
        cin >> v;
        val.push_back (make_pair(v, 0));
    }
    for (int i=0; i<b; i++) {
        ll v;
        cin >> v;
        val.push_back (make_pair(v, 1));
    }
    for (int i=0; i<c; i++) {
        ll v;
        cin >> v;
        val.push_back (make_pair(v, 2));
    }
    sort (val.begin(), val.end());
    reverse (val.begin(), val.end());
    ll ans1 = 0;
    ll ans2 = 0;
    ll val1 = 0;
    int cnt = 0;
    for (int i=0; i<val.size(); i++) {
        pair<ll, int> p = val[i];
        if (p.second == 0) {
            if (ans1 < x) {
                ans1++;
                val1+=p.first;
            }
            else if (ans2 < y) {
                if (cnt) {
                    cnt--;
                    val1 += p.first;
                    ans2++;
                }
            }
        }
        else if (p.second == 1) {
            if (ans2 < y) {
                ans2++;
                val1 += p.first;
            }
        }
        else {
            if (ans1 < x) {
                cnt++;
                val1 += p.first;
                ans1++;
            } 
            else if (ans2 < y) {
                val1 += p.first;
                ans2++;
            }
        }
    }
    cout << val1 << endl;
}
 
int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 10476