akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  ll ans=0;
  ans+=(n/(a+b))*a;
  n-=(n/(a+b))*(a+b);
  ans+=min(n,a);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int N;
	char S[100];
	int A[30];
	int max = -1, buff = 0;
	scanf("%d", &N);
	scanf("%s", S);
	for (int i = 1; i < N; i++) {
		for (int j = 0; j < 30; j++) {
			A[j] = 0;
		}
		buff = 0;
		for (int j = 0; j < i; j++) {
			if (A[S[j] - 97] == 0)A[S[j] - 97] = 1;
		}
		for (int j = i; j < N; j++) {
			if (A[S[j] - 97] == 1) {
				buff++;
				A[S[j] - 97] = 2;
			}
		}
		if (max < buff)max = buff;
	}
	printf("%d\n", max);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
p = list(map(float, input().split()))

# i-1 まで見たときに表が j 枚出る確率
dp = [[0]*(N+1) for _ in range(N+1)]
dp[0][0] = 1
for i in range(1, N+1):
    for j in range(N+1):
        dp[i][j] += (1-p[i-1])*dp[i-1][j]
        if j >= 1:
            dp[i][j] += p[i-1]*dp[i-1][j-1]

print(sum([dp[N][j] for j in range((N+1)//2, N+1)]))

Measured memory_bytes: 252168
package main

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

func main() {
	scanInit()

	x := nextInt()
	y := nextInt()

	if x%y == 0 {
		fmt.Println("-1")
		return
	}

	fmt.Println(x)

}

// ---- readfunc
var sc = bufio.NewScanner(os.Stdin)

func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

int main() {
 int N;
  cin >> N;
  // breakがなければこのループは i == 4 まで繰り返す
  for (int i = 0; i <= N; i++) {
    string s;
    cin >> s;

    if (s == "Y") {
      cout << "Four" << endl;
      break; // s == Y の時点でループから抜ける
    }

   if (i == N){
     cout << "Three" << endl;
   }
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N =1e5;
ll x,n;
inline ll get(ll a){
	return a*(a+1)/2;
}
int main(int argc, char** argv) {
	cin>>x;
	ll i,ans;
	for(i=1;i<=N;i++){
		if(get(i)<x)continue;
		if(get(i)>=x){
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import heapq
import re
from heapq import heapify, heappop, heappush
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# ここから書き始める
n = int(input())
ans = ""
cnt = 0
if n == 0:
    print(0)
else:
    while True:
        if n == (-2) ** cnt:
            ans += "1"
            break
        if n % (-2) ** (cnt + 1) == 0:
            ans += "0"
        else:
            ans += "1"
            n -= (-2) ** cnt
        cnt += 1
        # if cnt == 4:
        #     break
    print(ans[::-1])

Measured memory_bytes: 64620
s=input()
l=[chr(i) for i in range(97,97+26)]
if len(s)!=26:
  for i in l:
    if i not in s:
      print(s+i)
      break
else:
  for j in range(26):
    S=s[j:26]
    c=0
    for k in range(len(S)-1):
      if S[k]>S[k+1]:c+=1
    if c==len(S)-1:
      x=j
      break
  if x==0:print(-1)
  else:
    for m in range(l.index(s[x-1])+1,26):
      if l[m] not in s[0:x-1]:
        y=l[m]
        break
    print(s[0:x-1]+y)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define N 10050
using namespace std;
clock_t st;
int n, m, K, e = 2, head[N], dfn[N], low[N], tot, tim, bo[N * 20], ok[N * 20], be[N], Dp[N];
int fa[N][18], rt[N], dep[N], pp[N], a[N], b[N], dta[N], dtb[N];
struct edge{int u, v, next;}ed[N * 20];
void add(int u, int v){ed[e].u = u; ed[e].v = v; ed[e].next = head[u]; head[u] = e++;}
vector<pair<int, int> > V[N];
vector<int> vr;
int cnt = 0;
void tarjan(int x, int fa){
	++cnt;
	if(cnt > 100000) assert(0);
	dfn[x] = low[x] = ++tim;
	for(int i = head[x]; i; i = ed[i].next){
		int v = ed[i].v;
		if(!dfn[v]){
			tarjan(v, x);
			low[x] = min(low[x], low[v]);
			if(low[v] > dfn[x]) bo[i] = bo[i ^ 1] = 1;
		}
		else if(dfn[v] < dfn[x] && v != fa)
			low[x] = min(low[x], dfn[v]);
	}
}
void dfs(int x, int d, int fa){
	be[x] = tot; Dp[x] = d;
	for(int i = head[x]; i; i = ed[i].next){
		if(bo[i]) continue;
		int v = ed[i].v;
		if(!be[v]) {ok[i] = 1; dfs(v, d + 1, x);}
		else if(v != fa && Dp[v] < Dp[x]) {ok[i] = 1;}
	}
}
void dfs(int x, int root){
	rt[x] = root;
	for(int i = 1; (1 << i) <= dep[x]; i++)
		fa[x][i] = fa[fa[x][i - 1]][i - 1];
	for(int i = 0; i < (int)V[x].size(); i++){
		int v = V[x][i].first;
		if(v == fa[x][0]) continue;
		pp[v] = V[x][i].second;
		fa[v][0] = x;
		dep[v] = dep[x] + 1;
		dfs(v, root);
	}
}
int getlca(int x, int y){
	if(dep[x] < dep[y]) swap(x, y);
	for(int i = 14; ~i; i--)
		if(dep[fa[x][i]] >= dep[y]) x = fa[x][i];
	if(x == y) return x;
	for(int i = 14; ~i; i--)
		if(fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
	return fa[x][0];
}
void dfs(int x){
	a[x] = dta[x];
	b[x] = dtb[x];
	for(int i = 0; i < (int)V[x].size(); i++){
		int v = V[x][i].first;
		if(v == fa[x][0]) continue;
		dfs(v);
		a[x] += a[v];
		b[x] += b[v];
	}
	if(a[x] && b[x]){puts("No"); exit(0);}
	else if(a[x]) ok[pp[x] ^ 1] = 1;
	else ok[pp[x]] = 1;
}
int main(){
	st = clock();
	scanf("%d%d", &n, &m);
	for(int i = 1, u, v; i <= m; i++){
		scanf("%d%d", &u, &v);
		add(u, v); add(v, u);
	}
	for(int i = 1; i <= n; i++)
		if(!dfn[i]) tarjan(i, 0);
	for(int i = 1; i <= n; i++){
		if(!be[i]){
			++tot;
			dfs(i, 1, 0);
		}
	}
	for(int i = 2; i < e; i++) if(bo[i])
		V[be[ed[i].u]].push_back(make_pair(be[ed[i].v], i));
	for(int i = 1; i <= tot; i++){
		if(!rt[i]){
			fa[i][0] = 0;
			dep[i] = 1;
			dfs(i, i);
			vr.push_back(i);
		}
	}
	scanf("%d", &K);
	for(int i = 1, s, t, lca; i <= K; i++){
		scanf("%d%d", &s, &t);
		s = be[s]; t = be[t];
		if(rt[s] != rt[t]) {puts("No"); return 0;}
		lca = getlca(s, t);
		dta[s]++; dta[lca]--;
		dtb[t]++; dtb[lca]--;
	}
	for(int i = 0; i < (int)vr.size(); i++)
		dfs(vr[i]);
	puts("Yes");
	for(int i = 2; i < e; i++) if(ok[i])
		printf("%d %d\n", ed[i].u, ed[i].v);
	return 0;
}


Measured memory_bytes: 6848
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  cin >> S;
  ;
}
void solve() {
  int ans = 0;
  int red = 0, blue = 0;
  rep(i, 0, S.size() - 1) {
    if (S[i] == '0') {
      red++;
    } else
      blue++;
  }
  cout << S.size() - abs(red - blue) << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

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

public class Main {
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n=0;
        String s="";
        try {
            String str = reader.readLine();
            n = Integer.parseInt(str);
            s = reader.readLine();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if(n % 2 == 1){
            System.out.println("No");
        } else{
            int r = n / 2;
            String s1 = s.substring(0,r);
            String s2 = s.substring(r,n);
            if(s1.equals(s2)){
                System.out.println("Yes");
            } else{
                System.out.println("No");
            }
        }
    }
}

Measured memory_bytes: 21076
#include <iostream>

using namespace std;

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


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

int main(){
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  for(int i=0; i<n; i++){
    for(int j=0; j<d; j++){
      cin >> x[i][j];
    }
  }
  int ans=0;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      int sum=0;
      for(int k=0; k<d; k++){
        int sa;
        sa = abs(x[i][k] - x[j][k]);
        sum += sa*sa;
      }
      bool seisu = false;
      for(int k=0; k<=sum; k++){
        if(sum == k*k){
          seisu = true;
        }
      }
      if(seisu){
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner


object Main {
  def read() = {
    val sc = new Scanner(System.in)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val k = sc.nextInt()
    (a, b, k)
  }


  def solve(a: Int, b: Int, k: Int)= {
    def isDevidedByAandB(n:Int) = a%n ==0 && b%n==0

    val cmList = (1 to 100).filter(isDevidedByAandB) // 小さい順で並んだaとbの公約数
    cmList.reverse(k-1)
  }


  def main(args: Array[String]): Unit = {
    val (a, b, k) = read()
    println(solve(a, b, k))
  }
}

Measured memory_bytes: 25688
#include<stdio.h>

int main() {
	int h, w;
	int i, j;

	while (1) {
		scanf("%d %d" ,&h ,&w);

		if (h == 0 && w == 0) {
			break;
		}

		for (i = 0; i < h ;i++) {
			for (j = 0; j < w; j++) {
				if (i % 2 == 0) {
					if (j % 2 == 0) {
						printf("#");
					}
					else {
						printf(".");
					}
				}
				else {
					if (j % 2 == 0) {
						printf(".");
					}
					else {
						printf("#");
					}
				}
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}


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

int main()
{

	int n,x,t;
	cin >> n >> x >> t;

	if (n%x==0)
	{
		cout << t*(n/x) << endl;
	}
	else
	{
		cout << t*((n/x)+1) << endl;
	}
}






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

const int maxn=2e5+10;

int n;
int ans;

int a[maxn];
int f[maxn];

int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(register int i=n;i>=1;i--){
		int sum=0;
		for(register int j=i*2;j<=n;j+=i)
			sum+=f[j];
		if(sum%2==a[i])
			f[i]=0;
		else{
			f[i]=1;
			ans++;
		}
	}
	printf("%d\n",ans);
	for(register int i=1;i<=n;i++)
		if(f[i])
			printf("%d ",i);
	return 0;
}

Measured memory_bytes: 2432
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int dp[100000+10];
int v[100000+10];
vector<int> from[100000+10];
int dfs(int now){
	if(v[now]) return dp[now];
	v[now]=1;
	int SZ=from[now].size();
	if(SZ==0){
		return dp[now]=0;
	}
	rep(i,SZ){
		dp[now]=max(dp[now],dfs(from[now][i])+1);
	}
	return dp[now];
}
int main(){
	int n,m;
	cin>>n>>m;
	rb(i,1,m){
		int xi,yi;
		cin>>xi>>yi;
		from[yi].PB(xi);
	}
	rb(i,1,n){
		if(!v[i]){
			dfs(i);
		}
	}
	int res=-INF;
	rb(i,1,n)
		res=max(res,dp[i]);
//	cout<<dp[2]<<endl;
	cout<<res<<endl;
	return 0;
}

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

using namespace std;

struct edge {
	int to, cost;
};
typedef pair<int, int> P;

const int INF = 10e8;

void dijkstra(int s, int V, vector<vector<edge>>& G, vector<int>& d)
{
	priority_queue<P, vector<P>, greater<P> > que;
	d.resize(V);
	fill(d.begin(), d.end(), INF);
	d[s] = 0;
	que.push(P(0, s));

	while (!que.empty()) {
		P p = que.top();
		que.pop();

		int v = p.second;
		if (d[v] < p.first)
			continue;

		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
	
}

int main(void)
{
	int n, x, y;
	cin >> n >> x >> y;
	vector<vector<edge>> G(n);
	for (int i = 0; i < n; i++) {
		if (i-1>= 0)
			G[i].push_back(edge{i-1, 1});
		if (i+1 < n)
			G[i].push_back(edge{i+1, 1});
		if (i == x-1) {
			G[i].push_back(edge{y-1, 1});
			G[y-1].push_back(edge{x-1, 1});
		}
	}
	vector<vector<int>> d(n);
	for (int i = 0; i < n; i++) {
		dijkstra(i, n, G, d[i]);
	}
	vector<set<pair<int, int>>> s(2000);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j)
				continue;
			if (d[i][j] > 0 && d[i][j] < INF)
				s[d[i][j]].insert(make_pair(min(i, j), max(i, j)));
		}
	}
	for (int k = 1; k <= n-1; k++) {
		cout << s[k].size() << endl;;
	}

	return 0;
}

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

int main(){
    long long x;
    cin >> x;

    for(long long a = -1000; a <= 1000; a++){
        for(long long b = -1000; b <= 1000; b++){
            if(a*a*a*a*a - b*b*b*b*b == x){
                printf("%lld %lld\n", a, b);
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3752
const SieveOfEratosthenes = (n) => {
    let flg = (new Array(n)).fill(0)/* set flg[i] to true when it is seived */
    let primes = []/* list of prime numbers */
    for(let i=2; i*i<=n; i++) {
        if(!flg[i]) {
            primes.push(i)
            for(let j=i; j*j<=n; j+=i) {
                flg[j] = 1
            }
        }
    }
    return primes
}

const factorizationBySoE = (n, primes) => {
    //const primes = SieveOfEratosthenes(n)
    let factors = {}
    primes.some(p => {
        if(n < p) return true
        while(n%p===0) {
            if(!factors[p])factors[p]=1
            else factors[p]++
            n/=p
        }
    })
    if(n>1)factors[n]=1
    return factors
}


const getGCD = (a,b) => {
    if(b===0)return a
    else if(a===0)return b
    return getGCD(b, a%b)
}

const main = (arg) => {
    const N = Number(arg.split("\n")[0])
    const a = arg.split("\n")[1].split(" ").map(Number)
    
    const MAX_A = 10**6+100
  //  const A = Math.max(...a)
    
    //  check if p is in {a} (paircoprime)
    //const primes = SieveOfEratosthenes(A)
//    return
    let set = [...new Array(MAX_A)].fill(0)
    isPairCoprime = true
  /*
    for(let i=0; i<N; i++) {
        const factors = Object.keys(factorizationBySoE(a[i], primes))
        for(let j=0; j<factors.length; j++ ) {
            // console.log(`i=${i}, j=${j}, ${factors[j]}`)
            // console.log(factors)
            if(set[factors[j]] === 1) {
                isPairCoprime = false
            }
            set[factors[j]] = 1
        }
    }
*/
//  return
    for(let i=0; i<N; i++) {
        set[a[i]]++
    }
//  return
    for(let i=2; i<MAX_A; i++) {
         let cnt=0
         for(let j=i; j<MAX_A; j+=i) {
             cnt+=set[j]
         }
        if(cnt>1) {
             isPairCoprime = false
         }
     }
    
    if(isPairCoprime) {
        console.log("pairwise coprime")
        return
    }
     // return
    // setcoprime
    // let gcd = getGCD(a[0], a[1])
    let gcd = 0
    for(let i=0; i<a.length; i++) {
        gcd = getGCD(gcd, a[i])
        // console.log(gcd)
    }
    
    if(gcd===1) {
        console.log("setwise coprime")
        return
    }
    
    console.log("not coprime")
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 109648
use proconio::input;
use std::collections::HashSet;


fn main() {
    input! {
        a: [[i32; 3]; 3],
        n: i32,
        b: [i32; n],
    };

    let mut rs = Vec::new();
    let mut cs = Vec::new();

    let mut xs = vec![std::collections::HashSet::<i32>::new(); 2];
    xs[0] = [a[0][0], a[1][1], a[2][2]].iter().cloned().collect();
    xs[1] = [a[2][0], a[1][1], a[0][2]].iter().cloned().collect();

    for _ in 0..3 {
        rs.push(HashSet::<i32>::new());
        cs.push(HashSet::<i32>::new());
    }

    for i in 0..3 {
        for j in 0..3 {
            rs[i].insert(a[i][j]);
            cs[j].insert(a[i][j]);
        }
    }

    let mut scores = vec![vec![0; 2]; 3];

    for b_i in &b {
        for t in 0..3 {
            if rs[t].contains(b_i) {
                scores[t][0] += 1;
            }
            if cs[t].contains(b_i) {
                scores[t][1] += 1;
            }
        }
    }

    let mut scores_x = vec![0; 2];
    for b_i in &b {
        if xs[0].contains(b_i) {
            scores_x[0] += 1;
        }
        if xs[1].contains(b_i) {
            scores_x[1] += 1;
        }
    }


    // print!("{:?}\n", rs);
    // print!("{:?}\n", cs);
    // print!("{:?}\n", scores);
    // print!("{:?}\n", scores_x);

    for _scores in scores {
        for _score in _scores {
            if _score == 3 {
                println!("Yes");
                return;
            }
        }
    }

    for _score in scores_x {
        if _score == 3 {
            println!("Yes");
            return;
        }
    }

    println!("No");
}


Measured memory_bytes: 2180
#include <iostream>
#include <algorithm>
#include <cstring>
#include <fstream>
#include <cmath>

using namespace std;
typedef pair<int,int> pii;

#define EPS (1e-10)
#define EQ(a,b) ((abs((a)-(b))<EPS))


int n;
int times[101];
int places[101];
int dp[101][4];
const int INF=1000000000;
int missNum;

int dfs(int pos,int k){
	if(dp[pos][k]!=-1)return dp[pos][k];
	else if(pos==n-1)
		return places[pos];
	int res=INF;
	int dist=abs(places[pos]-places[pos+1]);
	int difft=abs(times[pos]-times[pos+1]);
	// ±ÌÜÜÆèÉ¢­ê
	if(k<=2){
		// ÔÉ¤ÈçÄA
		if(((double)difft/(k+1))>dist||EQ((double)difft/(k+1),dist))
			res=min(res,dfs(pos+1,k+1)+dist);
	}
	// u«É¢ÁÄ©çÆèÉ¢­ê
	double backTime=(double)places[pos]*(k+1);
	double procTime=(double)places[pos+1];
	double totalTime=backTime+procTime;
	if(totalTime<difft||EQ(totalTime,difft))
		res=min(res,dfs(pos+1,1)+places[pos]+places[pos+1]);
	return dp[pos][k]=res;
}

int main(){

	while(cin>>n&&n){
		memset(dp,-1,sizeof(dp));
		missNum=-1;
		for(int i=0;i<n;i++)cin>>places[i]>>times[i];
		if(places[0]>times[0])
			cout<<"NG 1"<<endl;
		else{
			int res=min(INF,dfs(0,1)+places[0]);
			if(res==INF){
				bool ok=false;
				for(int i=n-1;i>=0;i--){
					ok=true;
					bool isINF=false;
					for(int j=0;j<4;j++){
						if(!(dp[i][j]==INF||dp[i][j]==-1))
							ok=false;
						else if(dp[i][j]==INF)isINF=true;
					}
					if(ok&&isINF){
						missNum=i+2;
						break;
					}
				}
				cout<<"NG "<<missNum<<endl;
			}
			else cout<<"OK "<<res<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(){
    int n,m,l;
    cin >> n >> m >> l;
    long long a[n][m],b[m][l],c[n][l];
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            c[i][j] = 0;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> a[i][j];
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<l;j++){
            cin >> b[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            for(int k=0;k<m;k++){
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            if(j==l-1) cout << c[i][j] <<endl;
            else cout << c[i][j] << " ";
                }
    }
    return 0;
}

Measured memory_bytes: 1396
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace std;
using namespace __gnu_pbds;  
 
#define pb push_back
#define ll long long int
#define db double
#define SORTA(v) sort(v.begin(),v.end())
#define SORTD(v) sort(v.begin(),v.end(),greater<>())
#define endl '\n'
#define nod(N) floor(log10(N)) + 1
#define LB(a) lower_bound(a)
#define UB(a) upper_bound(a)
#define F first
#define S second
#define FOR(i,n) for(long long int i = 0;i<n;i++)
#define FOR1(i,n) for(long long int i=1;i<=n;i++)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define REVERSE(s) reverse(s.begin(),s.end())
#define LBV(v,a) lower_bound(v.begin(),v.end(),a)
#define UBV(v,a) upper_bound(v.begin(),v.end(),a)
#define GCD(a,b) __gcd(a,b)
#define ITX(it,x1) for(auto it = x1.begin();it!=x1.end();it++)
#define I insert
#define VFIND(v1,val) find(v1.begin() , v1.end() , val )
#define VFILL(v1 , val)   std::fill(v1.begin(), v1.end(), val);
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define all(x) x.begin() , x.end() 
 
// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }
ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }
 
const int MOD = 1e9 + 7;
long long int powxy(long long int x, long long int y) 
{
    if (y == 0) return 1;if (y%2 == 1) return (x*powxy(x, y-1))%MOD;
    long long int t = powxy(x, y/2);return (t*t)%MOD;
}
void DPM(map<ll,ll>m1)
{
    for(auto it = m1.begin();it!=m1.end();it++)
    {
        cout<<it->first<<" "<<it->second<<endl;
    }
    cout<<endl;
}
void DPV(vector<ll>v)
{
    FOR(i,v.size())cout<<v[i]<<" ";cout<<endl;
}
void DPS(set<ll>s1)
{
    for(auto it =s1.begin();it!=s1.end();it++)cout<<*it<<" ";cout<<endl;
}
void DPA(ll arr[],ll n){FOR(i,n)cout<<arr[i]<<" ";cout<<endl;}
 
 
 
ll dx[4] = { 0,0,1,-1 };
ll dy[4] = { 1,-1,0,0 };
string pos = "RLDU";
 
 
int main()
{
    FAST;
    ll i ,j , T = 1;
    // cin>>T;
    while(T--)
    {
        i=0;j=0;
        
        ll n; cin>>n;
 
        ll ans = 1;
        bool out = true;
 
        FOR1(i,n)
        {
            ll j; cin>>j;
            // ans *= j;
 
            if( j > 0 && ans > (ll)  1e18 / j || ans < 0)
            {
                out = false; ans = 0;
            }
            else ans = ans * j;
            if(j == 0)
            {
                out = true; ans = 0; break;
            }
            
 
        }
 
        if(out)cout<<ans;
        else cout<<"-1";
        
        
    }
}  

Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    string s;
    cin >> s;

    if (a >= 3200) {
        cout << s << endl;
    } else {
        cout << "red" << endl;
    }

    return 0;
}

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

int main() {
  ll x;
  cin >> x;
  ll now = 100;
  ll ans = 0;
  while (now < x) {
    now += now / d2;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
def main():
    N = int(input())

    ma = 0
    tot = 0
    while tot < N:
        ma += 1
        tot += ma

    skip = tot - N
    ans = {x for x in range(1, ma + 1) if x != skip}

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


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

signed main(){
  string S;
  cin>>S;
  int N=S.size();
  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=i;j<N;j++){
      if(j!=N-1)ans+=pow(2,N+i-j-2)*((char)S[i]-48)*pow(10,j-i);
      else ans+=pow(2,N+i-j-2+1)*((char)S[i]-48)*pow(10,j-i);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=0;
    while(1){
        int count=0;
        for(int j=0;j<n;j++){
            if(a[j]%2==0){
                count++;
            }
        }
        if(count==n){
            for(int j=0;j<n;j++)a[j]/=2;
            ans++;
        }else break;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
def f(a, b):
    d = abs(a-b)
    return min(d, 24-d)

N = int(input())
D = list(map(int, input().split())) + [0]
D.sort()
for i in range(N+1):
    if i%2:
        D[i] = 24 - D[i]
D.sort()
ans = f(D[0], D[-1])
for i in range(N):
    ans = min(ans, f(D[i], D[i+1]))
print(ans)


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

int main() {
	
	int n;
	cin>>n;
	int k;
	cin>>k;
	int arr[n];
	for(int i=0;i<n;i++)
	{
	    cin>>arr[i];
	}
	
	int dp[n];
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	
	
	for(int i=2;i<n;i++)
	{
	    dp[i]=INT_MAX;
	     for(int j=1;j<=k;j++)
	     {
	         int togo=i-j;
	         if(togo<0)
	         {
	             break;
	         }
	         else
	         {
	             dp[i]=min(dp[i],dp[togo]+abs(arr[i]-arr[togo]));
	         }
	         
	     }
	 
	}
	
	cout<<dp[n-1];
	
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main()
{
    int h, w, n;
    cin >> h >> w >> n;

    int sr, sc;
    cin >> sr >> sc;

    string s, t;
    cin >> s >> t;

    int lr = 0, rr = h + 1;
    int lc = 0, rc = w + 1;
    rrep(i, n)
    {
        if (t[i] == 'U') {
            rr = min(rr + 1, h + 1);
        } else if (t[i] == 'D') {
            lr = max(lr - 1, 0);
        } else if (t[i] == 'R') {
            lc = max(lc - 1, 0);
        } else {
            rc = min(rc + 1, w + 1);
        }

        if (s[i] == 'U') {
            lr = lr + 1;
        } else if (s[i] == 'D') {
            rr = rr - 1;
        } else if (s[i] == 'R') {
            rc = rc - 1;
        } else {
            lc = lc + 1;
        }

        if (lc + 1 >= rc || lr + 1 >= rr) {
            cout << "NO" << endl;
            return 0;
        }
    }

    if (sr <= lr || sr >= rr || sc <= lc || sc >= rc) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }

    return 0;
}

Measured memory_bytes: 776
#include<cstdio>
#include<algorithm>
const int N=5005;
typedef long long LL;
int n,m;
LL s[N][N],ans,A[N];
int L[N],R[N],sta[N],top;
struct data{
	int B[N];
	void work(){
		L[1]=1,R[n]=n,sta[top=1]=1,sta[0]=0;
		for(int i=2;i<=n;++i){
			while(top&&B[sta[top]]<=B[i])--top;
			L[i]=sta[top]+1;
			sta[++top]=i;
		}
		sta[top=1]=n,sta[0]=n+1;
		for(int i=n-1;i;--i){
			while(top&&B[sta[top]]<B[i])--top;
			R[i]=sta[top]-1;
			sta[++top]=i;
		}
		for(int i=1;i<=n;++i){
			int r1=L[i],c1=i,r2=i,c2=R[i];
			s[r1][c1]+=B[i],s[r1][c2+1]-=B[i];
			s[r2+1][c1]-=B[i],s[r2+1][c2+1]+=B[i];
		}
	}
}d[202];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=2;i<=n;++i)scanf("%lld",A+i),A[i]+=A[i-1];
	for(int i=1;i<=n;++i)
	for(int j=1;j<=m;++j)scanf("%d",&d[j].B[i]);
	for(int i=1;i<=m;++i)d[i].work();
	for(int i=1;i<=n;++i)
	for(int j=1;j<=n;++j){
		s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
		if(i<=j&&s[i][j]-A[j]+A[i]>ans)ans=s[i][j]-A[j]+A[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 199808
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 0;
		List<Integer> a = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			int s = sc.nextInt();
			ans += s;
			if(s % 10 != 0)
				a.add(s);
		}
		Collections.sort(a);
		if(ans % 10 == 0 && a.size() == 0) {
			System.out.println(0);
			return;
		}
		System.out.println(ans%10==0?ans-a.get(0):ans);
	}

}

Measured memory_bytes: 23764
#include <cstdio>
#define REP(i,n) for (int i=0;i<(n);i++)
int main(){
int N;
int count=1;
int v=0;
int A[114514]={};
scanf("%d\n",&N);
REP(i,N){scanf("%d",&A[i]);}
if(N==1){printf("1");return 0;}

REP(i,N-1){
if(A[i]<A[i+1]){
if(v==-1){
//printf("%d\n",i);
count++;
//i++;
v=0;
}else{
v=1;
}
}

else if(A[i]>A[i+1]){
if(v==1){
//printf("%d\n",i);
count++;
//i++;
v=0;
}else{
v=-1;
}
}


}
printf("%d\n",count);
return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
//#define local
#ifdef local
    #include "dbg-macro/dbg.h"
#endif
//#define hacks
#ifdef hacks
    #include <boost/multiprecision/cpp_int.hpp>
#endif
#define p std::pair
#define ll long long
#define ld long double
#define ull unsigned long long
#define pi std::pair<int, int>
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
#define oreq |=
#define npm next_permutation
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
ll extgcd(ll a, ll b, ll& x, ll& y);
ll nCr(ll n, ll r);
void stat();
template <typename T> T fact(T num);
constexpr ll mod = 1000000000 + 7;

int a, b, c;
int main()
{
    stat();
    cin >> a >> b >> c;
    int m = max(a, max(b, c));int sum=a+b+c;
    for (int i = m; i != 50 * 50; ++i) {
        if ((3 * m) % 2 == (a + b + c) % 2) {m=i;break;}
    }
    if(((3*m)-sum)%2==0){
cout<<(m*3-sum)/2<<endl;
    }else{
	    cout<<((m+1)*3-sum)/2<<endl;
    }
    return 0;
}
ll extgcd(ll a, ll b, ll& x, ll& y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) {
        is_prime[i] = true;
    }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++) {
        if (is_prime[i]) {
            for (unsigned ll j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}

void stat(){
#ifdef local
    rep(i, 2){std::cout << "local enable" << std::endl;
}
#endif
#ifdef hacks
rep(i, 2) { std::cout << "boost enable" << std::endl; }
#endif
}

ll nCr(ll n, ll r)
{
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

template <typename T> T fact(T num)
{
    if (num == 1) { return 1; }
    return num * fact(num - 1);
}


Measured memory_bytes: 3624
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

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

ll N, W;
vector<ll> v[4];

ll first;

int main()
{
	cin >> N >> W;
	for (int i = 0; i < N; i++) {
		ll w_, v_;
		cin >> w_ >> v_;
		if (i == 0)first = w_;
		ll a = w_ - first;
		v[a].push_back(v_);
	}

	for (int i = 0; i < 4; i++) {
		sort(v[i].begin(),v[i].end());
		v[i].push_back(0);
		reverse(v[i].begin(),v[i].end());
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < v[i].size(); j++) {
			if (j == 0)continue;
			v[i][j] += v[i][j - 1];
		}
	}

	ll ans = 0;

	for (int i = 0; i < v[0].size(); i++) {
		for (int j = 0; j < v[1].size(); j++) {
			for (int k = 0; k < v[2].size(); k++) {
				for (int l = 0; l < v[3].size(); l++) {
					if ((i + j + k + l)*first + j + 2 * k + 3 * l <= W) {
						ans = max(ans,v[0][i]+v[1][j]+v[2][k]+v[3][l]);
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const ll mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceilDiv(T n, T d) {return (n+d-1)/d;}

void solve() {
    int x, y; cin >> x >> y;
    if (2*x <= y && y <= 4*x && y % 2 == 0) Yes();
    else No();
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>

using namespace std;

typedef long long ll;

ll myxor(ll a)
{
    if(a % 4 == 1)
        return 1;
    else if(a % 4 == 2)
        return a + 1;
    else if(a % 4 == 3)
        return 0;
    else
        return a;
}

int main()
{
    ll a, b;
    cin>>a>>b;
    if(a == 0)
        cout<<b<<endl;
    else
        cout<<((myxor(b))^(myxor(a-1)))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<ll> w(N);
  for (auto &it : w)
    cin >> it;

  vector<ll> sum(N + 1);
  for (int i = 0; i < N; i++)
    sum[i + 1] = sum[i] + w[i]; // [l, r)

  vector<vector<ll>> dp(N + 10, vector<ll>(N + 10));
  vector<vector<ll>> K(N + 10, vector<ll>(N + 10));

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

  for (int w = 1; w <= N; w++)
  {
    for (int i = 0; i < N; i++)
    {
      int j = i + w;
      if (j >= N)
        continue;
      int a = K[i][j - 1];
      int b = K[i + 1][j];
      ll m = INF;
      ll idx = -1;
      for (int l = a; l <= b; l++)
      {
        if (i > l || l >= j)
          continue;
        ll now = dp[i][l] + dp[l + 1][j];
        if (now <= m)
        {
          idx = l;
          m = now;
        }
      }
      dp[i][j] = m + sum[j + 1] - sum[i];
      K[i][j] = idx;
    }
  }
  cout << dp[0][N - 1] << endl;
  return 0;
}


Measured memory_bytes: 254480
// Charan Sriramula

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll logx=30;
const ll N=1e4+5;
const ll INF=1e18+5;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%intd",&n)
#define longp(n) printf("%intd\n",n)

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1ll;x=(x*x)%m;}return ans%m;}

#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

ll cur,d;
vector<ll> dig[2];
ll dp[N][105][2];

void len(string n)
{
  for(ll i=0;i<n.length();i++){dig[cur].pb(n[i]-'0');}
  //while(n){dig[cur].pb(n%10);n/=10;}
  //reverse(all(dig[cur]));
}

ll F(ll idx,ll rem,ll f)
{
	ll res=0;
	if(idx==dig[cur].size()){return rem%d==0;}
	if(dp[idx][rem][f]!=-1){return dp[idx][rem][f];}
  if(f)
  {
		for(ll i=0;i<dig[cur][idx];i++){res=add(res,F(idx+1,(rem+i)%d,0));}
		res=add(res,F(idx+1,(rem+dig[cur][idx])%d,1));
  }
  else
  {
    for(ll i=0;i<=9;i++){res=add(res,F(idx+1,(rem+i)%d,0));}
  }
	return dp[idx][rem][f]=res;
}

int main()
{
	string k;
	cin>>k>>d;
	len(k);
	ms(dp,-1);
	ll val=F(0,0,1);
	val=sub(val,1LL);
	cout<<val<<endl;
}


Measured memory_bytes: 17664
n = int(input())
s = input()

nums = [s[1:].count('E')]
for i in range(1,n):
  tmp = nums[i-1]
  if s[i-1] == 'W':
    tmp  += 1
  if s[i] == 'E':
    tmp -= 1
  nums.append(tmp)

print(min(nums))

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll ans = 0;
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  for (ll i = 0; i < N; ++i) {
    for (ll j = i + 1; j < N; ++j) {
      ans += A.at(i) * A.at(j);
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int N;
	cin>>N;
	vector<string> S(N);
	vector<int> P(N);
	rep(i,0,N) cin>>S[i]>>P[i];
	
	vector<int> res(N);
	rep(i,0,N) res[i]=i;
	sort(res.begin(),res.end(),[&S,&P](int a,int b) {
		if (S[a]!=S[b]) return S[a]<S[b];
		return P[a]>P[b];
	});
	
	rep(i,0,N) cout<<res[i]+1<<"\n";
}


Measured memory_bytes: 256
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {

int main(void) {
  string S;cin>>S;
  if(S[2]==S[3]&&S[4]==S[5]) {
    p("Yes");
  } else {
    p("No");
  }
  return 0;
}




Measured memory_bytes: 256
n = gets.chomp.to_i
xy = [ gets.chomp.split(" ").map(&:to_f), gets.chomp.split(" ").map(&:to_f) ].transpose
maxval = 0

(1..3).each do | p |
  dist = 0
  xy.each do | x, y |
    maxval = [ maxval, ( x - y ).abs ].max
    dist += ( x - y ).abs ** p
  end
  puts dist ** ( 1.0 / p )
end
puts maxval

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

int main() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll c = C;
    ll d = D;
    if(c < d){
        ll tmp = c;
        c = d;
        d = tmp;
    }
    ll r = c % d;
    while(r!=0){
        c = d;
        d = r;
        r = c % d;
    }

    ll min = (A-1) / C + (A-1) / D - (A-1) / (C * D / d);
    min = A-1 - min;
    ll ans = B / C + B / D - B / (C * D / d);
    ans = B - ans;
    ans -= min;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	string S;
	cin >> S;
	int Z = S.size();
	vector<char>A(Z);
	rep(i, Z) {
		if (i % 2 == 0) {
			A[i] = 'g';
		}
		else if(i%2==1){
			A[i] = 'p';
		}
	}
	int ans = 0;
	rep(i, Z) {
		if (S[i] == 'g' && A[i] == 'p') {
			ans++;
		}
		else if (S[i] == 'p' && A[i] == 'g') {
			ans--;
		}
		//cout << i << ' ' << ans << endl;
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
#include<string>
#include<iostream>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
#define ll unsigned long long

ll mypow(int a,int b)
{
	ll s=1;
	while(b--)
	{
		s*=a;
	}
	return s;
}

int main()
{
	int k;
	vector<int>v(3);
	cin>>v[0]>>v[1]>>v[2]>>k;
	int m = *max_element(v.begin(),v.end());
	m = m*(mypow(2,k)-1);
	cout<<m+v[0]+v[1]+v[2];
	system("pause");
	return 0;
}


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

#define FOR(a, b, c) for (int a = (b), _for = (c); a < _for; ++a)
#define REP(a, n) FOR(a, 0, n)
#define x first
#define y second
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define lf double

using namespace std;

const int MAX = (int)1e6 + 5;

int n;
int p[MAX];

int main(){
	scanf ("%d",&n);
	REP(i,n){
		scanf ("%d",p+i);
	}
	int sol=0;
	int last=0;
	REP(i,n){
		if (p[i]==last+1){
			last++;
		}
		else{
			sol++;
		}
	}
	if (sol==n) puts ("-1");
	else printf ("%d\n",sol);
	
	
	return 0;
}


Measured memory_bytes: 1024
class Dice:
    diceNum = []
    pos = 0
    def setNum(self,i):
        self.pos = i[0]
        self.diceNum.append(i[0])
        self.diceNum.append(i[2])
        self.diceNum.append(i[5])
        self.diceNum.append(i[3])
        self.diceNum.append(i[4])
        self.diceNum.append(i[1])
    def showPos(self):
        print (self.pos)
    def move(self,d):
        if (d == "E"):
            i0=self.diceNum[3]
            i1=self.diceNum[0] 
            i2=self.diceNum[1] 
            i3=self.diceNum[2]
            i4=self.diceNum[4]
            i5=self.diceNum[5]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
            self.pos = self.diceNum[0]
        if (d == "W"):
            i0=self.diceNum[1]
            i1=self.diceNum[2] 
            i2=self.diceNum[3] 
            i3=self.diceNum[0]
            i4=self.diceNum[4]
            i5=self.diceNum[5]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
            self.pos = self.diceNum[0]
        if (d == "S"):
            i0=self.diceNum[4]
            i1=self.diceNum[1] 
            i2=self.diceNum[5] 
            i3=self.diceNum[3]
            i4=self.diceNum[2]
            i5=self.diceNum[0]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
            self.pos = self.diceNum[0]
        if (d == "N"):
            i0=self.diceNum[5]
            i1=self.diceNum[1] 
            i2=self.diceNum[4] 
            i3=self.diceNum[3]
            i4=self.diceNum[0]
            i5=self.diceNum[2]
            self.diceNum =[i0,i1,i2,i3,i4,i5]
            self.pos= self.diceNum[0]

l = list(map(int,input().split()))
dice = Dice()
dice.setNum(l)
for i in str(input()):
    dice.move(i)
dice.showPos()


Measured memory_bytes: 5616
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <string>
using namespace std;
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
const int N=2005,M=10000,D=N+1500+N;
map<int,int> S;
vector<int> ep[D],Prm;
int b[M+5],a[N],ans[N],mmj,n;
int vis[D],vis0[D],xm[N],cm[N];

int GetP()
{
    Prm.pb(0);
    for (int i=2;i<=M;i++)
    {
        if (b[i]) continue;
        Prm.pb(i);
        for (int j=i+i;j<=M;j+=i) b[j]=1;
    }
    return Prm.size();
}
void dfs(int x)
{
    int i,tot=ep[x].size();vis[x]=1;if (x<=n) {if (xm[x]<=cm[x]) mmj=min(mmj,x);}
    for (i=0;i<tot;i++) if (!vis0[ep[x][i]]&&!vis[ep[x][i]]) dfs(ep[x][i]);
}
int Copm(int x,int y)
{
    int i,j,t1=ep[x].size(),t2=ep[y].size();
    for (i=0,j=0;i<t1&&j<t2;)
    {
        if (ep[x][i]==ep[y][j]) return 0;
        if (ep[x][i]<ep[y][j]) i++; else j++;
    }
    return 1;
}
int main()
{
  //  freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    int i,j,tot=GetP()-1;
    scanf("%d",&n);
    for (i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for (i=1;i<=n;i++)
    {
        int x=a[i];
        for (j=1;j<=tot;j++)
        {
            if (x%Prm[j]) continue;
            ep[i].pb(n+j);ep[n+j].pb(i);
            while (x%Prm[j]==0) x/=Prm[j];
        }
        if (x>1)
        {
            map<int,int>::iterator i1=S.find(x);
            if (i1!=S.end()) j=(*i1).sc;
             else {Prm.pb(x);S.insert(mp(x,Prm.size()-1));j=Prm.size()-1;}
            ep[i].pb(n+j);ep[n+j].pb(i);
        }
    }
    tot=Prm.size()-1;
    for (i=1;i<=n;i++)
    {
        int mj=0;
        memset(vis,0,sizeof(vis));
        for (j=1;j<=n;j++)
         if (!vis0[j])
         {
               if (ans[i-1]<j) xm[j]=i-1;
               if (!Copm(ans[i-1],j)) cm[j]=i-1; 
         }
        for (j=1;j<=n;j++) if (!vis0[j]&&!vis[j]) {mmj=n;dfs(j);mj=max(mj,mmj);}
        ans[i]=mj;vis0[mj]=1;
    }
    printf("%d",a[ans[1]]);for (i=2;i<=n;i++) printf(" %d",a[ans[i]]);
    puts("");
    
    return 0;
}


Measured memory_bytes: 896
S = input()
N = len(S)
# Rなら右隣, Lなら左隣のindexを格納
X = [i-1 if S[i] == "L" else i+1 for i in range(N)]

# ループを何度行ってもi番目の元はi+偶数番目にしか移動しない.
# RLの部分は互換の後, 恒等写像なので不変.
# RRRやLLLの部分は 1ループで2の冪乗で精度が上がる.
# ex.) RRRRRRR だと, k回ループで index i の元が i + 2**kに移動する.
# log(2**20)=6.01より10**5程度なら20回ループで十分.
for _ in range(20):
    X = [X[x] for x in X]
# はじめにi番目のマスにいた子どもがX[i]番目のマスに移動した.
A = [0]*N
for x in X:
    A[x] += 1
print(*A)

Measured memory_bytes: 10324
package main

import (
	"fmt"
)


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

func getPow(x int, y int) int {
	ans := 1
	for i := 0; i < y; i++ {
		ans *= x
	}
	return ans
}
func main() {
	var a, b, c, k int
	fmt.Scan(&a, &b, &c, &k)
	fmt.Println(a + b + c + getMaxInt(a, b, c) * (getPow(2, k) - 1))
}


Measured memory_bytes: 512
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    if ( m >= 2 * n ) {
        ans += n;
        ll minus_num = 2 * n;
        n = 0;
        m -= minus_num;
    }
    else {
        ans += m / 2;
        ll minus_num = m / 2;
        m -= minus_num * 2;
        n -= minus_num;
    }
    if ( m >= 4 ) {
        ans += m / 4; 
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
n = int(input())
ans = 0

for i in range(1, n+1):
  counter = 0
  
  if i%2==0:
    continue
  
  for i_i in range(1, i+1):
    if i%i_i == 0:
      counter += 1
  
  if counter == 8:
    ans += 1
    
print(ans)

Measured memory_bytes: 9120
n = gets.to_i
x = gets.chomp.split(' ').map(&:to_i)

sum = 0
ans = []

(1..x.max).each do |np|
	x.each do |j|
		sum += (j - np) **2
	end
	ans << sum
	sum = 0
end

#最小値を出力
puts ans.min

Measured memory_bytes: 1788