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

using namespace std;

int main() {
	int n,m; scanf("%d %d", &n,&m);

	vector<vector<int>> adjList(n, vector<int>());
	int depth[n];
	memset(depth, -1, sizeof(depth));

	for(int i=0; i<m; i++) {
		int x,y; scanf("%d %d", &x, &y);
		x--; y--;
		adjList[x].push_back(y);
		adjList[y].push_back(x);
	}

	// bfs

	queue<int> q;
	q.push(0);
	depth[0] = 0;

	while(!q.empty()) {
		int node = q.front();
		q.pop();

		for(int child : adjList[node]) {
			if(depth[child] != -1) continue;
			depth[child] = depth[node] + 1;
			q.push(child);
		}
	}
	
	// getting the solution or failing to find it

	vector<int> signposts(n-1);
	bool found = true;

	for(int node=1; node<n; node++) {
		bool ok = false;
		for(int child : adjList[node]) {
			if(depth[node] - depth[child] == 1) {
				signposts[node-1] = child+1;
				ok = true;
				break;
			}
		}
		found &= ok;
	}

	if(found) {
		printf("Yes\n");
		for(int i=0; i<signposts.size(); i++)
			printf("%d\n", signposts[i]);
	}
	else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 10620
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

m = {'p': s, 'r': p, 's': r}

dp = [''] * n
a = 0
for i in range(k):
    a += m[t[i]]
    dp[i] = t[i]
    
for i in range(k, n):
    if t[i] != dp[i-k]:
        a += m[t[i]]
        dp[i] = t[i]

print(a)

Measured memory_bytes: 4212
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
const int MOD = 1e9+7;
const int MOOD = 998244353;
#define PI 3.14159265359
#define mp make_pair
typedef long long ll;
using namespace std;

ll graph[301][301];
int graph2[301][301];

ll llmin(ll x, ll y){
	if (x > y) return y;
	return x;
}

void warshall_floyd(int n){
	for (int k = 1; k <= n; k++){
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				graph[i][j] = llmin(graph[i][j], graph[i][k] + graph[k][j]);
			}
		}
	}
}
void warshall_floyd2(int n){
	for (int k = 1; k <= n; k++){
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= n; j++){
				graph2[i][j] = min(graph2[i][j], graph2[i][k] + graph2[k][j]);
			}
		}
	}
}

int main(){
	int n, m, l;
	cin >> n >> m >> l;
	for (int i = 0; i <= 300; i++){
		for (int j = 0; j <= 300; j++){
			if (i == j) continue;
			graph[i][j] = 1000000000000000000;
			graph2[i][j] = MOD;
		}
	}
	for (int i = 0; i < m; i++){
		int a, b, c;
		cin >> a >> b >> c;
		if (c > l) continue;
		graph[a][b] = c;
		graph[b][a] = c;
	}
	warshall_floyd(n);
	for (int i = 1; i <= 300; i++){
		for (int j = 1; j <= 300; j++){
			if (graph[i][j] != 1000000000000000000){
				if (graph[i][j] <= l){
					graph2[i][j] = 1;
				}
			}
		}
	}
	warshall_floyd2(n);

	int q;
	cin >> q;
	for (int i = 0; i < q; i++){
		int s, t;
		cin >> s >> t;
		if (graph2[s][t] == MOD) cout << -1 << endl;
		else cout << graph2[s][t] - 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 4740
package main

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

var scanner = bufio.NewScanner(os.Stdin)

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

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	q := nextInt()
	A_slices := make([][]int, n)
	for i := 0; i < n; i++ {
		A_slices[i] = make([]int, 0)
	}
	for i := 0; i < q; i++ {
		switch nextInt() {
		case 0:
			t := nextInt()
			x := nextInt()
			A_slices[t] = append(A_slices[t], x)
			// fmt.Println(A_slices)
		case 1:
			t := nextInt()
			if len(A_slices[t]) == 0 {
				fmt.Println()
				continue
			}
			for i := 0; i < len(A_slices[t]); i++ {
				if i == len(A_slices[t])-1 {
					fmt.Printf("%d\n", A_slices[t][i])
				} else {
					fmt.Printf("%d ", A_slices[t][i])
				}
			}
		case 2:
			t := nextInt()
			if len(A_slices[t]) == 0 {
				continue
			}
			A_slices[t] = make([]int, 0)
		default:
			panic("no such operation!")
		}
	}
}


Measured memory_bytes: 22872
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str=sc.nextLine();
         int a =Integer.parseInt(str);
         //int z=a/1000
		// int b = 1;
        if(a%1000==0){
          System.out.println(0);}
        
      else if(a%1000>0){
        int z=1;
        int b= a/1000;
        
            System.out.println((z+b)*1000-a);
       }
      }
        
        
	}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    map<int,int> wwat;
    map<int,int> wsug;
    for(int i = 0; i <= f; i++) {
        for(int j = 0; j <= f; j++) {
            int tw=100*a*i + 100*b*j;
            if(tw>f || tw==0) continue;
            wwat[tw]++;
        }
    }
    for(int i = 0; i <= f; i++) {
        for(int j = 0; j <= f; j++) {
            int ts=c*i + d*j;
            if(ts>f) continue;
            wsug[ts]++;
        }
    }

    int wans=100*a;
    int sans=0;
    for(auto itr = wwat.begin(); itr != wwat.end(); itr++) {
    for(auto jtr = wsug.begin(); jtr != wsug.end(); jtr++) {
        int ts=jtr->first;
        int tw=itr->first + ts;
        if(((100+e)*ts<=e*tw) && (tw<=f)){
            if(sans*tw<wans*ts){
                wans=tw;
                sans=ts;
            }
        }
    }
    }
    cout << wans << " " << sans << "\n";
    return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int inf = 1000000000;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
const ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    bool ans = false;
    int cnt = 0;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        if(a == b){
            cnt++;
        }
        else cnt = 0;
        if(cnt == 3){
            ans = true;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3592
package main

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

var (
	s = bufio.NewScanner(os.Stdin)
	n = 0
	k = 0
	w = []int{}
)

func check(p int) int {
	i := 0
	for j := 0; j < k; j++ {
		s := 0
		for s+w[i] <= p {
			s += w[i]
			i++
			if i == n {
				return n
			}
		}
	}
	return i
}

func binarySearch() int {
	left, mid, right := 0, 0, 100000*100000
	for right-left > 1 {
		mid = (left + right) / 2
		v := check(mid)
		if v >= n {
			right = mid
			continue
		}
		left = mid
	}
	return right
}

func main() {
	s.Split(bufio.ScanWords)

	n = nextInt(s)
	k = nextInt(s)
	w = make([]int, n)

	for i := range w {
		w[i] = nextInt(s)
	}
	fmt.Println(binarySearch())
}

func nextInt(s *bufio.Scanner) int {
	s.Scan()
	n, err := strconv.Atoi(s.Text())
	if err != nil {
		panic(err)
	}
	return n
}



Measured memory_bytes: 2320
N = int(input())
S = input()

def step(queue_l, queue_r, c):
    if c == '(':
        queue_l += 1
    else:
        if queue_l > 0:
            queue_l -= 1
        else:
            queue_r += 1
    return (queue_l, queue_r)


out = []
queue_l = 0
queue_r = 0
for c in S:
    queue_l, queue_r = step(queue_l, queue_r, c)

print('(' * queue_r + S + ')' * queue_l)

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


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

    vector<int64_t> data(n);

    int64_t sum = 1;

    for(int i = 0 ; i < n ; i++){
        cin >> data.at(i);
        if(data.at(i) == 0){
            sum = 0;
        }
    }
    if(sum == 0){
        cout << 0 << endl;
        return 0;
    }

    for(int i = 0 ; i < n ; i++){
        if(sum <= 1000000000000000000.0 / data.at(i)){
            sum *= data.at(i);
        }else{
            cout << -1 << endl;
            return 0;
        }
    }
    if(sum > 1000000000000000000){
        cout << -1 << endl;
    }else{
        cout << sum << endl;
    }
    
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.14159265358979
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;
  bool plus = true;
  bool minus = true;
  deque<ll> A(N);
  for (auto &it : A)
  {
    cin >> it;
    if (it >= 0)
      minus = false;
    if (it < 0)
      plus = false;
  }
  sort(A.begin(), A.end());
  vector<pair<ll, ll>> xy;
  for (int i = 0; i < N - 1; i++)
  {
    if (plus)
    {
      ll fr = A.front();
      A.pop_front();
      ll ba = A.back();
      A.pop_back();
      xy.push_back(make_pair(fr, ba));
      A.push_front(fr - ba);
      plus = false;
    }
    else if (minus)
    {
      ll fr = A.front();
      A.pop_front();
      ll ba = A.back();
      A.pop_back();
      xy.push_back(make_pair(ba, fr));
      A.push_back(ba - fr);
      minus = false;
    }
    else
    {
      ll fr = A.front();
      A.pop_front();
      ll ba = A.back();
      A.pop_back();
      ll fr2 = A.front();
      ll ba2 = A.back();
      if (fr2 > 0 && ba2 > 0)
      {
        xy.push_back(make_pair(fr, ba));
        A.push_front(fr - ba);
      }
      else
      {
        xy.push_back(make_pair(ba, fr));
        A.push_back(ba - fr);
      }
    }
  }
  ll M = A.front();
  cout << M << endl;
  for (auto it : xy)
  {
    cout << it.first << " " << it.second << endl;
  }
  return 0;
}

// +と-が1個ずつになるまで+で-を，-で+を引き続ける．


Measured memory_bytes: 4468
<?php
fscanf(STDIN, "%s", $o);
fscanf(STDIN, "%s", $e);
$x = null;
$l = strlen($o);
for ($i = 0; $i < $l; $i++) {
	$x .= $o[$i];
	if (isset($e[$i])) $x .= $e[$i];
}
echo $x;

Measured memory_bytes: 4728
import math
a,b,n = map(int,input().split())
tmp_max = 0
cnt = 0
if n<b:
    print(math.floor(a*n/b) - a*math.floor(n/b))
else:
    print(math.floor(a*((b-1)/b)) - a*math.floor((b-1)/b))

Measured memory_bytes: 9044
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        a: Chars,
        b: Chars,
    }

    if a.len()>b.len() {
        println!("GREATER");
        return;
    } else if a.len()<b.len() {
        println!("LESS");
        return;
    } else {
        for i in 0..a.len() {
            if a[i].to_digit(10).unwrap() > b[i].to_digit(10).unwrap() {
                println!("GREATER");
                return;
            } else if a[i].to_digit(10).unwrap() < b[i].to_digit(10).unwrap() {
                println!("LESS");
                return;
            }
        }
    }

    println!("EQUAL");

}


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

namespace Contest
{
    class ABC042
    {
        static void Main()
        {
            int[] INPUT = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int go = 0;
            int nana = 0;
            if (INPUT[0] == 5) go++;
            if (INPUT[0] == 7) nana++;
            if (INPUT[1] == 5) go++;
            if (INPUT[1] == 7) nana++;
            if (INPUT[2] == 5) go++;
            if (INPUT[2] == 7) nana++;

            Console.WriteLine((go == 2 && nana == 1)? "YES":"NO");
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 13396
$n = <>;
@a = split/ /,<>;
for($i=0;$i<$n;$i++){
	$sum+=$a[$i];
}
$ans=10000000000;
$partsum = 0;
for($i=0;$i<$n;$i++){
	$partsum += $a[$i];
    $sa = abs($sum-2*$partsum);
    if(($i+1)<$n){
    	if($sa <= $ans){
        	$ans=$sa;
        }
    }
}
print $ans;

Measured memory_bytes: 22348
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	int n; cin >> n;
	std::vector<string> v;
	bool ans = true;
	for (int i = 0; i < n; ++i)
	{
		string s; cin >> s;
		v.push_back(s);
    }

	for (int i = 0; i < n - 1; ++i) if(v[i].back() != v[i + 1].front()) ans = false;
	for (int i = 0; i < n; ++i)
	{
		for (int j = i+1; j < n; ++j) if (v[i]==v[j]) ans = false;
	}

	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	

}

Measured memory_bytes: 256
a, b, c = gets.split.map(&:to_i)
th = c / 360.0 * 2 * Math::PI
puts '%.8f' % (a * b * Math.sin(th) / 2.0)
puts '%.8f' % (a + b + Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(th)))
puts '%.8f' % (b * Math.sin(th))

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

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

    int answer = 0;
    for (int i = 1; i <= A; i++)
    {   
        if (i > K)
        {
            break;
        } else {
            answer += 1;
        }
    }

    for (int i = 1; i <= B; i++)
    {
        if (A + i > K)
        {
            break;
        } else {
            answer += 0;
        }
    }

    for (int i = 1; i <= C; i++)
    {
        if (A + B + i > K)
        {
            break;
        } else {
            answer -= 1;
        }   
    }
    
    cout << answer;
    return 0;
}

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main(){

    int n;
    cin >> n;
    vector<int> a(n);

    rep(i, n){
        cin >> a[i];
    }

    int allgcd = a[0];

    rep(i, n){
        allgcd = __gcd(allgcd, a[i]);
    }

    vector<int> traversed(1000001);
    bool pairwise = true;

    //cerr << "check" << endl;

    rep(i, n){
        traversed[a[i]]++;
    }

    for(int i = 2; i <= 1000000; i++){
        int count = 0;
        for(int j = i; j <= 1000000; j = j + i){
            if(traversed[j] > 0) count += traversed[j];
        }

        //cerr << i << " " << count << endl;
        if(count > 1){
            pairwise = false;
            break;
        }
    }

    if(pairwise){
        cout << "pairwise coprime" << endl;
    }else if(allgcd == 1){
        cout << "setwise coprime" << endl;
    }else{
        cout << "not coprime" << endl;
    }
    
    return 0;

}


Measured memory_bytes: 11088
from collections import deque

N = int(input())
ab = [[int(i)-1 for i in input().split()] for _ in range(N-1)]
c = [int(i) for i in input().split()]
                
c.sort()
d = [0] * N

vector = [[] for _ in range(N)]
for a, b in ab :
    vector[a].append(b)
    vector[b].append(a)

ret = sum(c[:-1]) 
queue = deque([0])
visited = [False] * N
visited[0] = True

while queue :
    q = queue.popleft()
    for v in vector[q] :
        if not visited[v] :
            queue.append(v)
            visited[v] = True
    d[q] = c.pop()
    
print(ret)
print(' '.join(map(str, d)))

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

using namespace std;

int main(int argc, char *argv[])
{
	string s;
	cin >> s;
	int sum = 0;
	for (int i = 0; i < s.size(); i++)
		sum += s[i] - '0';
	cout << (sum % 9 ? "No" : "Yes") << endl;

	return 0;
}


Measured memory_bytes: 3720
import math
arr = [int(input()) for _ in range(5)]
minmod = 10
minidx = -1
time = []
for i, a in enumerate(arr):
  mod = a % 10
  mod = mod if mod > 0 else 10
  if mod < minmod:
    minmod = mod
    minidx = i
  time.append(math.ceil(a / 10) * 10)

ans = 0
for i in range(5):
  if i == minidx:
    ans += arr[i]
  else:
    ans += time[i]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

#define _USE_MATH_DEFINES
#include<math.h>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
int N;

struct Point{ double x, y; };

void render(Point p){
	cout << p.x << " " << p.y << endl;
}

void rec(Point p1, Point p2, int n){
	if (n == N) return;

	Point s, t, u;
	s.x = (2.0 * p1.x + 1.0 * p2.x) / 3.0;
	s.y = (2.0 * p1.y + 1.0 * p2.y) / 3.0;
	t.x = (1.0 * p1.x + 2.0 * p2.x) / 3.0;
	t.y = (1.0 * p1.y + 2.0 * p2.y) / 3.0;

	double th = M_PI * 60.0 / 180.0;
	u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
	u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

	if (n != N) rec(p1, s, n + 1);
	render(s);
	if (n != N) rec(s, u, n + 1);
	render(u);
	if (n != N) rec(u, t, n+1);
	render(t);
	if (n != N) rec(t, p2, n + 1);

}

int main() {

	cin >> N;
	double x1, y1, x2, y2;
	
	Point p1, p2;
	p1.x = 0.0; p1.y= 0.0;
	p2.x = 100.0; p2.y = 0.0;

	render(p1);
	rec(p1, p2, 0);
	render(p2);
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

ll popcount(string x){
    ll ans = 0;
    rep(i, sz(x)){
        if(x.at(i) == '1'){
            ans++;
        }
    }
    return ans;
}

ll popcountl(ll x){
    if(x == 0){
        return 0;
    }
    bitset<200000> s(x);
    ll a = 0;
    rep(i, log2(x)+1){
        if(s.test(i)){
            a++;
        }
    }
    return a;
}

ll f(ll x, ll c){
    if(x == 0){
        return c;
    }
    return f(x % popcountl(x), c+1);
}

int main()
{
    ll N;
    string X;
    cin >> N >> X;
    ll K = popcount(X);
    vector<ll> rem1(N, 0); // 2^iをpopcount(X)+1で割った余り
    vector<ll> rem2(N, 0); // 2^iをpopcount(X)-1で割った余り
    rem1.at(0) = 1 % (K+1);
    if(K != 1){
        rem2.at(0) = 1 % (K-1);
    }
    rep(i, N-1){
        rem1.at(i+1) = (rem1.at(i) * 2) % (K+1);
        if(K != 1){
            rem2.at(i+1) = (rem2.at(i) * 2) % (K-1);
        }
    }
    ll R1 = 0; //Xをpopcount(X)+1で割った余り
    ll R2 = 0; //Xをpopcount(X)-1で割った余り
    rep(i, N){
        if(X.at(i) == '1'){
            R1 += rem1.at(N-1-i);
            R2 += rem2.at(N-1-i);
        }
    }
    rep(i, N){
        if(X.at(i) == '1'){
            if(K == 1){
                cout << 0 << endl;
            }
            else{
                cout << f((R2-rem2.at(N-1-i))%(K-1), 1) << endl;
            }
        }
        else{
            cout << f((R1+rem1.at(N-1-i))%(K+1), 1) << endl;
        }
    }
}

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

int li[10];
int n;
double x[10], y[10];

double sq(double a){
  return a*a;
}

double jarak(int a, int b){
  return sqrt(sq(x[a]-x[b]) + sq(y[a]-y[b]));
}

double compute(){
  double ret = 0;
  for(int i=2;i<=n;i++){
    ret += jarak(li[i],li[i-1]);
  }
  return ret;
}

int main(){
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%lf%lf",&x[i],&y[i]);
    li[i] = i;
  }
  double ans = 0;
  do{
    ans+=compute();
  } while(next_permutation(li+1,li+n+1));
  for(int i=1;i<=n;i++) ans/=(double)i;
  printf("%.9lf\n",ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f 
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long int
#define pi 3.14159265358979
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef vector<int>   vi;
typedef vector<pii>   vpii;
typedef vector<vi>    vvi;

int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ll n,count=0;
    double k;
    cin>>n>>k;
    ll x[n+5],y[n+5];
    for(int i=0;i<n;i++)
        cin>>x[i]>>y[i];
    for(int i=0;i<n;i++)
    {
        double  s=sqrt(x[i]*x[i]+y[i]*y[i]);
        //cout<<s<<endl;
        if(s<=k)
            count++;
    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 6956
#include <stdio.h>

int main(void)
{
    int N,L,j=0,sum=0,min=100;
    scanf("%d%d",&N,&L);
    int taste[N],abso[N];
    for(int i=0;i<N;i++){
        sum+=L+i;
    }
    for(int i=0;i<N;i++){
        taste[i]=L+i;
        if(taste[i]<0)
            abso[i]=-taste[i];
        else
            abso[i]=taste[i];
        if(min>abso[i]){
            min=abso[i];
            j=i;
        }
    }
    printf("%d\n",sum-taste[j]);
    return 0;
}


Measured memory_bytes: 128
S=input()

if 'S' in S and 'N' not in S:
    print('No')
elif 'N' in S and 'S' not in S:
    print('No')
elif 'E' in S and 'W' not in S:
    print('No')
elif 'W' in S and 'E' not in S:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
class UnionFindTree():
    def __init__(self, values=[]):
        self.parent_of = {}
        self.rank_of = {}
        for value in values:
            if value in self.parent_of:
                raise RuntimeError("Dupulicated Value Added")
            self.parent_of[value] = None
            self.rank_of[value] = 0

    def __root(self, value):
        if self.parent_of[value] is None:
            return value
        else:
            self.parent_of[value] = self.__root(self.parent_of[value])
            return self.parent_of[value]

    def unite(self, a, b):
        r1 = self.__root(a)
        r2 = self.__root(b)
        if r1 != r2:
            if self.rank_of[r1] < self.rank_of[r2]:
                self.parent_of[r1] = r2
            else:
                self.parent_of[r2] = r1
                if self.rank_of[r1] == self.rank_of[r2]:
                    self.rank_of[r1] += 1

    def is_same(self, a, b):
        return self.__root(a) == self.__root(b)

    def groups(self):
        groups = {}
        for k in self.parent_of.keys():
            r = self.__root(k)
            if r not in groups:
                groups[r] = []
            groups[r].append(k)
        return [groups[x] for x in groups]


def main():
    N, M = map(int, input().split())
    P = [x-1 for x in map(int, input().split())]
    uft = UnionFindTree(P)
    for _ in range(M):
        p, q = [x-1 for x in map(int, input().split())]
        uft.unite(P[p], P[q])
    ans = 0
    for i in range(N):
        if uft.is_same(i, P[i]):
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 117348
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

Measured memory_bytes: 256
a,b = map(int,input().split())
if a+b > a-b and a+b > a*b:
    print(a+b)
elif a-b > a+b and a-b > a*b:
    print(a-b)
elif a*b > a+b and a*b > a-b:
    print(a*b)
else:
    print(a)


Measured memory_bytes: 2940
n = int(input())
a = list(map(int, input().split()))
res = 0
dict = {}
dict[a[0]+1] = 1
for i in range(1,n):
  res += dict.get(i+1-a[i],0)
  dict[a[i]+i+1] = dict.get(a[i]+i+1,0) + 1
print(res)


Measured memory_bytes: 40444
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

#ifndef MIN
# define        MIN(a,b)        (((a)<(b))?(a):(b))
#endif
#ifndef MAX
# define        MAX(a,b)        (((a) > (b)) ? (a) : (b))
#endif

int
main(void)
{
        int N;

        scanf("%d\n", &N);

        int count = 0;
        int head = 0;
        int tail = 0;
        int both = 0;

        for (int cnt = 0; cnt < N; cnt++) {
                char str[11];
                scanf("%s\n", str);

                if (str[0] == 'B') {
                        if (str[strlen(str) - 1] == 'A')
                                both++;
                        else
                                head++;
                } else if (str[strlen(str) - 1] == 'A') {
                        tail++;
                }

                char *p = str;
                while ((p = strstr(p, "AB")) != NULL) {
                        count++;
                        if (*p++ == '\0')
                                break;
                }
        }

        if (both > 0) {
                count += both - 1;
                if (tail > 0) {
                        count++;
                        tail--;
                }
                if (head > 0) {
                        count++;
                        head--;
                }
        }
        count += MIN(tail, head);

        printf("%d", count);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i, n) for (int i = 0, i##_cond = (n); i < i##_cond; ++i)
#define FOR(i, a, b) for (int i = (a), i##_cond = (b); i < i##_cond; ++i)
#define ROF(i, a, b)                                                           \
  for (int i = (a)-1, i##_cond = (b); i >= i##_cond; --i) // ROF(i,n,0)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend() // sortで降順
#define SUM(a) accumulate(all(a), int(0))
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
constexpr ll inf = 1ll << 61;
constexpr ll mod = 1e9 + 7;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> T add(const T &a, const T &b) { return (a + b) % mod; }

signed main() {
  int n;
  cin >> n;
  vi a(n + 1);
  rep(i, n + 1) cin >> a[i];

  vi b(n + 1);
  b[n] = a[n];
  ROF(i, n, 0) b[i] = a[i] + b[i + 1];
  int ans = SUM(b);
  dump(a, b);
  int tmp = 1;
  rep(i, n + 1) {
    dump(tmp);
    if (tmp > b[i])
      break;
    if ((i != n and a[i] + 1 > tmp) or (i == n and a[i] > tmp)) {
      dump(i);
      cout << -1 << endl;
      return 0;
    }
    ans -= b[i] - tmp;

    tmp = 2 * (tmp - a[i]);
    dump(ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 100;
int n, W;
string a, b;
int dp[maxn], l[maxn][maxn];
stack<char> S;
int main()
{
    cin>>a>>b;
    for(int j = 0; j < max(a.length(), b.length()); j++) for(int i = 0; i < b.length(); i++) l[j][i] = -1;
    for(int i = 0; i < a.length(); i++){
        int maxans = 0, maxi = -1;
        for(int j = 0; j < b.length(); j++){
            int maxans2 = maxans, maxi2 = maxi;
            if(dp[j] > maxans2){
                maxans2 = dp[j];
                maxi2 = j;
            }
            if(a[i] == b[j]){
                if(dp[j] < maxans + 1){
                    dp[j] =  maxans + 1;
                    l[dp[j]][j] = maxi;
                }
            }
            maxans = maxans2; maxi = maxi2;
        }
    }
    int maxans = 0, maxi = -1;
    for(int i = 0; i < b.length(); i++) {
        if(dp[i] > maxans){
            maxans = dp[i];
            maxi = i;
        }
    }
    while(maxi != -1){
        //cout<<maxi<<endl;
        S.push(b[maxi]);
        maxi = l[maxans--][maxi];
    }
    //cout<<maxans<<endl;
    while(!S.empty()){
        cout<<S.top(); S.pop();
    }
    return 0;
}


Measured memory_bytes: 37120
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static StreamWriter sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
        static void Main(string[] args)
        {
            try
            {
                SetOut(sw);
                Solve.Answer();
                Out.Flush();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
                Out.Flush();
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var s = ReadLine();
            long ans = 0;
            for (int i = 0; i < s.Length; i++)
            {
                ans++;
                if (i == s.Length - 1) continue;
                if (s[i] == s[i + 1])
                {
                    if (i == s.Length - 2) ans--;
                    ans++;
                    i += 2;
                }
            }
            WriteLine(ans);
        }
    }

    public class IO
    {
        #region Input
        public static int RInt => int.Parse(ReadLine());
        public static long RLong => long.Parse(ReadLine());
        public static double RDouble => double.Parse(ReadLine());

        public static string[] RSString => ReadLine().Split();
        public static int[] RSInt => ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        public static long[] RSLong => ReadLine().Split().Select(s => long.Parse(s)).ToArray();
        public static double[] RSDouble => ReadLine().Split().Select(s => double.Parse(s)).ToArray();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");
        public static void WriteLineYES_or_NO(bool flag) => WriteLine(flag ? "YES" : "NO");
        #endregion
    }

    public class Mod
    {
        #region
        private readonly static long M = 1000000007;

        public static long Add(long a, long b) => (a * b) % M;
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        public static long Multi(long a, long b) => (a * b) % M;
        #endregion
    }
}

Measured memory_bytes: 17544
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> p(n),q(n);
    rep(i,n){
      cin>>p[i];
      q[p[i]-1]=i;
    }
    int now=1,cnt,ans=0;
    rep(i,n){
      if(i==0){
        cnt=q[i];
        continue;
      }
      if(cnt<q[i]){
        now++;
        cnt=q[i];
      }else{
        ans=max(ans,now);
        now=1;
        cnt=q[i];
      }
    }
    if(ans==0) cout<<0<<endl;
    else cout<<n-ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, k, q, a;
    cin >> n >> k >> q;
    
    vector<int> points(n);
    
    for(int i=0; i<n; i++) points[i] = k-q;
    
    for(int i=0; i<q; i++) {
        cin >> a;
        
        points[a-1]++;
    }
    
    for(int i=0; i<n; i++) {
        if(points[i] <= 0) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
}

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

int main() {
  int N = 0, A = 0, B = 0;
  cin >> N >> A >> B;
  int AT = N * A;
  if( AT < B ){
    cout << AT << endl;
  }
  else{
    cout << B << endl;
  }
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// AtCoder_B
		Scanner sc = new Scanner(System.in);

		int K = sc.nextInt();
		int X = sc.nextInt();

		for(int i=-100; i<=200; i++) {
			if(X-K < i && i < X+K) {
				if(X-K+1 == i) {
					System.out.print(i);
				}else {
					System.out.print(" "+i);
				}
			}
		}

	    // Scannerクラスのインスタンスをクローズ
		sc.close();
	}
}


Measured memory_bytes: 38432
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#include <numeric>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
    string s;
    cin >> s;
    string t="2019/04/30";
    if(s<=t){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,res=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int a;
        scanf("%d",&a);
        res+=(i%2 && a%2);
    }
    return 0*printf("%d\n",res);
}


Measured memory_bytes: 3824
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static final int N = 100000;

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[][] even = new int[N+1][2];
		int[][] odd = new int[N+1][2];
		for(int i=1;i<=n;i++) {
			int v = sc.nextInt();
			if(i%2 == 0) {
				even[v][0] = v;
				even[v][1]++;
			}else {
				odd[v][0] = v;
				odd[v][1]++;
			}
		}
		Arrays.sort(even,(a,b)->Integer.compare(b[1], a[1]));
		Arrays.sort(odd,(a,b)->Integer.compare(b[1], a[1]));
		if(even[0][0] != odd[0][0]) {
			System.out.println(((n/2) + (n%2) - odd[0][1]) + ((n/2) - even[0][1]));
		}else {
			if(odd[0][1] + even[1][1] > odd[1][1] + even[0][1]) {
				System.out.println(((n/2) + (n%2) - odd[0][1]) + ((n/2) - even[1][1]));
			}else {
				System.out.println(((n/2) + (n%2) - odd[1][1]) + ((n/2) - even[0][1]));
			}
		}
	}

}

Measured memory_bytes: 66632
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<lli, lli> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);

lli n, ar[N], pe[N], root, tot, par[N];
vector<lli> v[N];
vector<ii> v2[N];

void dfs(lli x, lli back) {
	par[x] = back;
	lli tot = 0;
	for(auto i : v[x])
		if(i != back) {
			dfs(i, x);
			tot += pe[i];
		}
	if(v[x].size() == 1)
		pe[x] = ar[x];
	else
		pe[x] = ar[x] * 2 - tot;
} 

signed main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> n;
	for(lli i = 1; i <= n; i++)
		cin >> ar[i];
	for(lli i = 1; i <= n - 1; i++) {
		lli a, b;
		cin >> a >> b;
		v[a].pb(b);
		v[b].pb(a);
	}

	if(n == 2) {
		if(ar[1] == ar[2])
			cout << "YES";
		else
			cout << "NO";
		return 0;
	}
	root = 0;
	while(v[++root].size() == 1);
	
	dfs(root, 0);

	if(pe[root] != 0) {
		cout << "NO";
		return 0;
	}

	for(int i = 1; i <= n; i++)
		if(pe[i] < 0) {
			cout << "NO";
			return 0;
		}
	for(int i = 1; i <= n; i++) {
		if(i == root)
			continue;
		v2[i].pb({par[i], pe[i]});
		v2[par[i]].pb({i, pe[i]});
	}

	bool fl = false;

	for(int i = 1; i <= n; i++) {
		if(v[i].size() == 1)
			continue;
		lli t = 0;
		for(auto j : v2[i])
			t += j.se;
		if(t % 2 == 1) {
			cout << "NO";
			return 0;
		}
		for(auto j : v2[i])
			if(j.se * 2 > t)
				fl = true;

	}
	if(fl) {
		cout << "NO";
		return 0;
	}
	cout << "YES";
}

Measured memory_bytes: 69248
//
//  main.cpp
//  codeforces 1
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#define int long long
#define N 1500002
using namespace std;
signed main() {
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    int l=0,r,max=-1;
    for(int i=0;i<n;i++) {
        if(a[i]>max) {
            max=a[i];
        }
    }
    r=max;
    int ans=0;
    while(l<r) {
        int mid=(l+r)/2;
        if(r==1) break;
        ans=0;
        for(int i=0;i<n;i++) {
            ans=ans+(a[i]-1)/mid;
        }
        if(ans<=k) r=mid;
        else l=mid+1;
    }
    cout<<r<<endl;
    return 0;
}


Measured memory_bytes: 4852
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; ++i)
using ll = long long;
using namespace std;
#define P pair<int, int>
using namespace std;
int main(void){
    ll x ;
    cin >> x ;

    ll count=0;
  
  	count+=(x/11)*2;
  	x=x%11;
  	if(x>=7) count+=2;
  	else if(0<x && x<=6) count++;
  	else;
    cout<<count<<endl;
    return 0 ;
}
    
  

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        long k = in.nextLong();
        
        long[] ai = new long[n];
        for(int i=0; i<n; i++) {
            ai[i] = in.nextLong();
        }
        long[] asum = new long[n+1];
        asum[0] = 0;
        int amaxIndex = 0;
        for(int i=0; i<n; i++) {
            asum[i+1] = asum[i] + ai[i];
            if(asum[i+1] <= k) {
                amaxIndex = i+1;
            }
        }
        
        long[] bi = new long[m];
        for(int i=0; i<m; i++) {
            bi[i] = in.nextLong();
        }
        long[] bsum = new long[m+1];
        bsum[0] = 0;
        int bmaxIndex = -1;
        for(int i=0; i<m; i++) {
            bsum[i+1] = bsum[i] + bi[i];
            if(bsum[i+1] <= k) {
                bmaxIndex = i+1;
            }
        }
        
        int maxCount = 0;
        for(int i=0; i<=amaxIndex; i++) {
            // 二分探索　：　机Bで何冊読めるか？
            int l = -1;
            int r = bmaxIndex;
            while(l<r) {
                int mid = (l+r)/2;
                if(l+1==r) {
                    if(asum[i] + bsum[r] > k) {
                        r = l;
                    }
                    break;
                }
                if(asum[i] + bsum[mid] <= k) {
                    l = mid;
                }
                else {
                    r = mid;
                }
            }
            maxCount = Math.max(maxCount, i+r);
        }
        System.out.println(maxCount);
    }
}


Measured memory_bytes: 65724
#include <iostream>
using namespace std;
int main(){
    int N , K;
    int x[105];
    cin >> N >> K ;
    for(int i = 0; i < N;i++){
        cin >> x[i];
    }

    int ans = 0;
    for(int i = 0;i < N;i++){
        if(x[i]< K-x[i]){
            ans += x[i]*2;
        }else{
            ans += (K-x[i])*2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
using namespace std;
template <class code>inline code read(const code &a)
{
    code x=0;short w=0;char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return w?-x:x;
}
void print(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>=10)print(x/10);
	putchar(x%10+48);
}
int gcd(int x,int y){
    if(y==0)return x;
    else return gcd(y,x%y);
}
char s[400005];
long long sum[100][40005];
char p[100]{'R','G','B'};
int main()
{
	int n=read(n);
    scanf("%s",s+1);
    long long ans=0;
    for(int i=n;i>=1;i--){
    	for(int j=0;j<=2;j++)sum[j][i]=sum[j][i+1];
    	if(s[i]=='R')sum[0][i]++;
    	else if(s[i]=='G')sum[1][i]++;
    	else if(s[i]=='B')sum[2][i]++;
	}
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(s[i]!=s[j]){
            	int sj=0;
                for(int k=0;k<=2;k++){
                	if(p[k]!=s[i]&&p[k]!=s[j])sj=k;
				}
				ans+=sum[sj][j];
				if(s[j+j-i]==p[sj])--ans;
            }
        }
    }
    printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 1836
ABCD = list(input())

import itertools

for i in itertools.product(['+', '-'], repeat=3):
    ans = int(ABCD[0])
    # print(i)
    for idx, ii in enumerate(i):
        if ii == '+':
            ans += int(ABCD[idx+1])
        else:
            ans -= int(ABCD[idx+1])
    # print(ABCD[0]+i[0]+ABCD[1]+i[1]+ABCD[2]+i[2]+ABCD[3], ans)
    if ans == 7:
        break
print(ABCD[0]+i[0]+ABCD[1]+i[1]+ABCD[2]+i[2]+ABCD[3]+'=7')

Measured memory_bytes: 38384
#include <cstdio>

template<class T>void fr(T &a) {
    T s=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    a=w*s;
}
template<class T>T fr() {T a;fr(a);return a;}
#define R() fr<int>()

const int N=1e2;
char s1[N+10],s2[N+10];

int main() {
	int n=R();scanf("%s%s",s1+1,s2+1);
	for(int i=1;i<=n;i++) printf("%c%c",s1[i],s2[i]);
	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

a, b, c = [int(i) for i in input().split()]

def cond():
    if a == b and a != c:
        return True
    if a == c and a != b:
        return True
    if b == c and a != b:
        return True
    return False

if cond():
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38672
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
using namespace std;
#define int long long
#define inf 3000000000000
typedef pair<int, int>P;
int dp[160][10][80];
vector<P>s[160];//P(??????,???????????????)

void init(int m) {
	for (int i = 0; i < 160; i++) {
		s[i].clear();
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 80; k++) {
				if (!i&&k==m)dp[i][j][k]=0;
				else if (i == 1 && k == m - 1)dp[i][j][k] = 0;
				else dp[i][j][k] = inf;
			}
		}
	}
	return;
}

signed main() {
	int n, m;
	while (cin >> n >> m) {
		if (!n && !m)break;
		init(m);
		for (int i = 0; i < n; i++) {
			int a;
			cin >> a;
			for (int j = 0; j < a; j++) {
				int b, c;
				cin >> b >> c;
				s[i].push_back(P(b, c));
			}
		}

		for (int i = 1; i < n; i++) {//?¬?????????????
			for (int j = 0; j < s[i].size(); j++) {//??????????????????
				for (int k = m; k >= 0; k--) {//???????????§?????£??????
					for (int l = 0; l < s[i - 1].size(); l++) {
						int dang = (s[i-1][l].second+s[i][j].second)*abs(s[i][j].first-s[i-1][l].first);
						dp[i][j][k] = min(dp[i][j][k], dp[i - 1][l][k] + dang);
					}
					if (i > 1) {
						for (int l = 0; l < s[i - 2].size(); l++) {
							int dang = (s[i - 2][l].second + s[i][j].second)*abs(s[i][j].first - s[i - 2][l].first);
							dp[i][j][k] = min(dp[i][j][k], dp[i - 2][l][k + 1] + dang);
						}
					}
				}

			}
		}
		int ans = inf;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 80; j++) {
				ans = min(ans, dp[n - 1][i][j]);
			}
		}
		for (int i = 0; i < 10; i++) {
			for (int j = 1; j < 80; j++) {
				ans = min(ans, dp[n - 2][i][j]);
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 4016
// 怪文書
// #17080666
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)
 
typedef long long ll;
using namespace std;
int main()
{
  ll n;
  string s[100];
  ll cnt[26];
  cin>>n;
  rep(i,n){
    cin>>s[i];
    sort(s[i].begin(),s[i].end());
  }
  ll min;
  for(char l='a';l<='z';l++){
    min=1000000;
    rep(i,n){
      ll tmp=0;
      rep(j,s[i].length()){
        if(s[i][j]==l)tmp++;
      }
      if(tmp<min)min=tmp;
    }
    cnt[l-'a']=min;
  }
 
  rep(i,26){
    rep(j,cnt[i]){
      printf("%c",'a'+i);
    }
  }
 
  cout<<endl;
 
  return 0;
}

Measured memory_bytes: 3624
import java.io.*;
import java.util.StringTokenizer;

class Main {
	public static void main(String args[]) {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String buf;

		try {
			while ((buf = br.readLine())!=null) {
				int n = Integer.parseInt(buf);
				int count = 0;
				for (int a=0;a<=9;a++) {
					for (int b=0;b<=9;b++) {
						for (int c=0;c<=9;c++) {
							for (int d=0;d<=9;d++) {
								if (a+b+c+d==n) count++;
								else if (a+b+c+d>n) break;
							}
						}
					}
				}
				System.out.println(count);
			}
			
		} catch (Exception e) {
			System.out.println("Exception!");
		}
	}
}

Measured memory_bytes: 18628
#include <bits/stdc++.h>
using namespace std;
#define AC 0
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int h,w,m;
	cin>>h>>w>>m;
	vector<int> hh(h,0),ww(w,0);
	map< pair<int,int>,bool > mp;
	for(int i=0;i<m;i++) {
		int hhh,www;
		cin>>hhh>>www;
		hh[hhh-1]++;
		ww[www-1]++;
		mp[pair<int,int>(hhh-1,www-1)]=1;
	}
	int mxh=0,mxw=0;
	for(int i=0;i<h;i++) mxh=max(mxh,hh[i]);
	for(int i=0;i<w;i++) mxw=max(mxw,ww[i]);
	vector<int>hp,wp;
	for(int i=0;i<h;i++)
		if(hh[i]==mxh)
			hp.push_back(i);
	for(int i=0;i<w;i++)
		if(ww[i]==mxw)
			wp.push_back(i);
	for(int i=0;i<hp.size();i++)
		for(int j=0;j<wp.size();j++)
			if(!mp.count(pair<int,int>(hp[i],wp[j]))) {
				cout<<mxh+mxw;
				return AC;
			}
	cout<<mxh+mxw-1;
	return AC;
}

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

int main() {
  int N, K, a, b, c; 
  cin >>N >>K;
  a = 0;
  for (int i=0; i<N; i++) {
    cin >>b;
    if(b < (K-b) ) {
      a +=2*b;
    }
    else {
      a +=2*(K-b);
    }
  }
  cout << a <<endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 1e5 + 5;

ll n, k, memo[105][nax], arr[105];

ll dp(ll i, ll j){
	if (j == 0){
		return 1;
	}
	if (j < 0){
		return 0;
	}
	if (i == 0){
		return 0;
	}
	if(memo[i][j] != -1){
		return memo[i][j];
	}
	ll ret = ((dp(i-1, j) + dp(i, j-1) % mod) - dp(i - 1, j - arr[i] - 1) + mod) % mod;
	return memo[i][j] = ret;
}

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

	cin >> n >> k;
	for (ll i = 1; i <= n; i++){
		cin >> arr[i];
	}
	memset(memo, -1, sizeof(memo));
	cout << dp(n, k) << '\n';
}
  

Measured memory_bytes: 88576