akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
    string a[3];
    char ans;
    while(true){
    	cin >> a[0];
    	if(a[0][0] == '0'){
    		break;
    	}
    	cin >> a[1] >> a[2];
        ans = '0';
        for(int i = 0; i < 3; i++){
            if(a[i][0] == a[i][1] && a[i][1] == a[i][2]){
                if(a[i][0] != '+'){
                    ans = a[i][0];
                }
            }
            if(a[0][i] == a[1][i] && a[1][i] == a[2][i]){
                if(a[0][i] != '+'){
                    ans = a[0][i];
                }
            }
        }
        if(a[0][0] == a[1][1] && a[1][1] == a[2][2]){
            if(a[0][0] != '+'){
                ans = a[0][0];
            }
        }
        if(a[0][2] == a[1][1] && a[1][1] == a[2][0]){
            if(a[0][2] != '+'){
                ans = a[0][2];
            }
        }
        if(ans == '0'){
            printf("NA\n");
        }else{
            printf("%c\n", ans);
        }
    }
    return 0;
}

Measured memory_bytes: 1180
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final double[] doubles = new double[n];
        double mult = 1;
        for (int i = 0; i < doubles.length; i++) {
            final double v = scanner.nextDouble();
            doubles[i] = v;
            mult *= v;
        }

        double sum = 0;
        for (final double aDouble : doubles) {
            sum += mult / aDouble;
        }

        System.out.println(mult/sum);
    }
}


Measured memory_bytes: 25044
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	a := make([]int, m)
	b := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scanf("%d %d", &a[i], &b[i])
		a[i]--
		b[i]--
	}
	answer, signspots := findSignspots(n, m, a, b)
	if answer {
		fmt.Println("Yes")
		for i, v := range signspots {
			if i == 0 {
				continue // skip for room 1
			}
			v++
			fmt.Println(v)
		}
	} else {
		fmt.Println("No")
	}
}

var spotsigns []int

func findSignspots(n, m int, a, b []int) (bool, []int) {
	route := make(map[int][]int)
	for i := 0; i < m; i++ {
		if _, exist := route[a[i]]; !exist {
			route[a[i]] = []int{}
		}
		route[a[i]] = append(route[a[i]], b[i])
		if _, exist := route[b[i]]; !exist {
			route[b[i]] = []int{}
		}
		route[b[i]] = append(route[b[i]], a[i])
	}

	return bfs(0, n, route)
}

func traceRoom(prevRoom int, routes map[int][]int) {
	currentRooms := []int{0}
	for {
		nextPrevRooms := []int{}
		for _, currentRoom := range currentRooms {
			nextRooms := routes[currentRoom]
			for _, nextRoom := range nextRooms {
				if spotsigns[nextRoom] == -1 {
					// fmt.Println("put spot sign at ", nextRoom)
					spotsigns[nextRoom] = currentRoom
					nextPrevRooms = append(nextPrevRooms, nextRoom)

				}
			}
		}
		// fmt.Println(nextPrevRooms)
		if len(nextPrevRooms) == 0 {
			break
		}
		currentRooms = nextPrevRooms
	}
}

func bfs(entry int, rooms int, route map[int][]int) (bool, []int) {
	signspots := make([]int, rooms)
	for i := range signspots {
		signspots[i] = -1
	}
	queue := []int{entry}
	start := 0
	end := 1
	for {
		for i := start; i < end; i++ {
			v := queue[i]
			for _, next := range route[v] {
				if signspots[next] == -1 {
					signspots[next] = v
					queue = append(queue, next)
				}
			}
		}
		start = end
		end = len(queue)
		if start == end {
			break
		}
	}
	for i := 1; i < rooms; i++ {
		if signspots[i] == -1 {
			return false, signspots
		}
	}
	return true, signspots
}


Measured memory_bytes: 25060
#include<bits/stdc++.h>
using namespace std;
long long int nCr[2003][2003];
int main(){
    
    int N,K,MOD = 1000000007;
    cin >> N >> K;
    for(int i=0;i<2003;i++)
        for(int j=0;j<2003;j++)
            nCr[i][j] = 0;
    nCr[0][0] = 1;
    for(int i=1;i<2003;i++)
        for(int j=0;j<=i;j++){
            if(i == j || j == 0)
                nCr[i][j] = 1;
            else
                nCr[i][j] = (nCr[i-1][j-1]+nCr[i-1][j]) % MOD;
        }
    for(int i=1;i<=K;i++){
        long long int res = 0;
        res += (((nCr[N-K+1][i])*(nCr[K-1][i-1]))%MOD);
        cout << (res%MOD) << endl;
    }
    
    return 0;
}

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

int main(){

	int n;
	cin >> n;

	string t,h;
	int tp=0, hp=0;

	for(int i=0; i<n; ++i){
		cin >> t >> h;
		if (t == h){++tp; ++hp;}
		else {t>h ? tp+=3: hp+=3;}
	}

	cout << tp << ' ' << hp << endl;
	return 0;
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define rint register int
#define gc() getchar()
inline int read(int r=0,int s=0,int c=gc()){for(;c<48||c>57;s=c,c=gc());for(;c>=48&&c<=57;(r*=10)+=c-48,c=gc());return s^'-'?r:-r;}
vector<int> e[1025]; int f[1025][5025], X[1025], n;
void DP(int p){for(auto v:e[p]) for(rint i = (DP(v),X[p]); ~i; f[p][i] = min(i>=X[v]?f[p][i-X[v]]+f[v][X[v]]:INF,i>=f[v][X[v]]?f[p][i-f[v][X[v]]]+X[v]:INF), i--);}
int main(){n = read(); for(rint i = 2; i <= n; e[read()].push_back(i), i++); for(rint i = 1; i <= n; X[i++] = read()); DP(1); puts(f[1][X[1]]<INF?"POSSIBLE":"IMPOSSIBLE"); return 0;}

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

using namespace std;

void solve()
{
	long long x;
	cin >> x;
	
	long long p = 100;
	
	int ans = 0;
	
	while(p < x)
	{
		++ans;
		p += p / 100;
	}
	
	cout << ans << '\n';
}

main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t = 1;

//	cin >> t;

	for(; t; --t)
	{
		solve();
	}
}

Measured memory_bytes: 3664
#include<stdio.h>
int main()
{
    int a[2]={0},n[3]={0},i;
    for(i=0;i<2;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<2;i++){
        n[a[i]-1]=1;
    }
    for(i=0;i<3;i++){
        if(n[i]==0) printf("%d\n",i+1);
    }
    return 0;
}

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

public class Main {
	static ArrayList<ArrayList<Integer>> edges = new ArrayList<>();
	static long nodes[];

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

		String str[] = br.readLine().split(" ");
		int n = Integer.parseInt(str[0]);
		int q = Integer.parseInt(str[1]);

		nodes = new long[n];
		for (int i = 0; i < n; i++) {
			edges.add(new ArrayList<>());
		}

		for (int i = 0; i < n - 1; i++) {
			str = br.readLine().split(" ");
			int a = Integer.parseInt(str[0]) - 1;
			int b = Integer.parseInt(str[1]) - 1;

			edges.get(a).add(b);
			edges.get(b).add(a);
		}

		for (int i = 0; i < q; i++) {
			str = br.readLine().split(" ");
			int index = Integer.parseInt(str[0]) - 1;
			int add = Integer.parseInt(str[1]);

			nodes[index] += add;
		}
		dfs(n, 0);
		System.out.print(nodes[0]);
		for (int i = 1; i < nodes.length; i++) {
			System.out.print(" " + nodes[i]);
		}
		System.out.print("\n");
	}

	static void dfs(int n, int s) {
		boolean[] used = new boolean[n];
		Deque<Integer> q = new ArrayDeque<>();
		q.add(0);
		used[0] = true;
		while (q.size() != 0) {
			int now = q.poll();
			for (int next : edges.get(now)) {
				if (!used[next]) {
					nodes[next] += nodes[now];
					q.add(next);
					used[next] = true;
				}
			}
		}
	}
}


Measured memory_bytes: 117544
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
//#define int ll
#define xx first
#define yy second
#define pb push_back
#define all(x) begin(x), end(x)
#define OUT(x) { cout << x; exit(0); }
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const db eps = 1e-9;
const db pi = acos(-1.0);
const db dinf = 1e250;
const ll INF = (ll)(2e18);
const int inf = (int)(1e9 + 7);
//------------------------------------------//

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

#ifdef _MY
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    string s;
    cin >> s;
    int cnt = 0;

    string cur;
    vector<string> vs;
    vs.pb(s.substr(0, 1));
    for (int i = 1; i < s.size(); ++i)
    {
        cur += s[i];
        if (cur != vs.back()) vs.pb(cur), cur = "";
    }
    if (cur.size() && cur != vs.back()) vs.pb(cur);

    cur = "";
    int res = vs.size();
    vs.clear();
    vs.pb(s.substr(0, 2));

    for (int i = 2; i < s.size(); ++i)
    {
        cur += s[i];
        if (cur != vs.back()) vs.pb(cur), cur = "";
    }
    if (cur.size() && cur != vs.back()) vs.pb(cur);


    res = max(res, (int)vs.size());
    cout << res;


    return 0;
}

Measured memory_bytes: 11016
#include<stdio.h>

int main()
{
    long long a,b,c,d,res=0x8000000000000000;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    if(a*c>res)res=a*c;
    if(a*d>res)res=a*d;
    if(b*c>res)res=b*c;
    if(b*d>res)res=b*d;
    printf("%lld\n",res);

    return 0;
}


Measured memory_bytes: 1736
N = int(input())
if N == 3:
    print(2)
    print(1,3)
    print(2,3)
    exit()

if N == 4:
    print(4)
    print(1,2)
    print(1,3)
    print(4,2)
    print(4,3)
    exit()

if N%2 == 1:
    n = int((N+1)/2)
    group = [[0] * 2 for i in range(n-1)]
    M = n*4 - 4
    edge = []
    for i in range(n-1):
        group[i][0] = i+1
        group[i][1] = N-i-1
    for i in range(n-1):
        if i == n-2:
            edge.append([group[i][0],N])
            edge.append([group[i][1],N])
            edge.append([N,group[0][0]])
            edge.append([N,group[0][1]])
            #edge.append([group[i][1],group[i+1][0]])
            #edge.append([group[i][1],group[i+1][1]])    
        else:
            edge.append([group[i][0],group[i+1][0]])
            edge.append([group[i][0],group[i+1][1]])
            edge.append([group[i][1],group[i+1][0]])
            edge.append([group[i][1],group[i+1][1]])

if N%2 == 0:
    n = int(N/2)
    group = [[0] * 2 for i in range(n)]
    M = n*4
    edge = []
    for i in range(n):
        group[i][0] = i+1
        group[i][1] = N-i
    for i in range(n):
        if i == n-1:
            edge.append([group[i][0],group[0][0]])
            edge.append([group[i][0],group[0][1]])
            edge.append([group[i][1],group[0][0]])
            edge.append([group[i][1],group[0][1]]) 
        else:
            edge.append([group[i][0],group[i+1][0]])
            edge.append([group[i][0],group[i+1][1]])
            edge.append([group[i][1],group[i+1][0]])
            edge.append([group[i][1],group[i+1][1]])

print(M)
#print(group)
for m in range(M):
    print(edge[m][0],edge[m][1])

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

using namespace std;

const int N = 1e5 + 9, OO = 0x3f3f3f3f;

int n, points[N][3], dp[N][4];

int solve(int i, int prev){
    if(i == n)  return 0;

    int &ret = dp[i][prev];
    if(~ret)    return ret;

    ret = 0;
    for(int j = 0;j < 3;j++)
        if(prev != j)   ret = max(ret, points[i][j] + solve(i + 1, j));


    return ret;
}

int main(){

    cin >> n;
    for(int i = 0;i < n;i++)
        cin >> points[i][0] >> points[i][1] >> points[i][2];

    memset(dp, -1, sizeof dp);

    cout << solve(0, 3);
}


Measured memory_bytes: 10752
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();		
        int k = sc.nextInt();
        int ans = n;
        int [] in = new int [n];
        for(int i=0;i<k;i++){int a = sc.nextInt();
                             for(int j=0;j<a;j++){int b = sc.nextInt();
                                                 if(in[b-1]==0){in[b-1]++;}
                                                 }
                            }
        for(int i=0;i<n;i++){ans-=in[i];
                            }
		System.out.println(ans);
	}
}


Measured memory_bytes: 46272
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n; cin >> n;
	ll k; cin >> k;
	vector<ld>a(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	ld ans = 0;
	ld sm = 0;
	for (ll i = 0; i < k; i++) {
		sm += (a[i] + 1) / 2.0;
	}
	ans = sm;
	for (ll i = k; i < n; i++) {
		sm -= (a[i - k] + 1) / 2.0;
		sm += (a[i] + 1) / 2.0;
		ans = max(ans, sm);
	}
	cout << fixed; cout.precision(10); 
	cout << ans << endl;
	return 0;
}

/*
3
0 1
3 0
1 0
*/

Measured memory_bytes: 3456
import java.io.{BufferedReader, InputStream, InputStreamReader}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.ArrayBuffer

object Main {
  val MOD = 1000000007
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val M = sc.nextInt()

    val E = Array.ofDim[Int](N, N)

    (0 until M) foreach { _ =>
      val a = sc.nextInt() - 1
      val b = sc.nextInt() - 1
      val c = sc.nextInt()
      E(a)(b) = c
      E(b)(a) = c
    }

    val used = Array.ofDim[Boolean](N, N)
    val INF = 100001
    def markUsedPath(s: Int): Unit = {
      val d = Array.fill[Int](N)(INF)

      type Edge = (Int, Int)
      val q = mutable.PriorityQueue[(Int, Edge)]()(Ordering.by[(Int, Edge), Int](_._1).reverse)
      val pre = Array.ofDim[Int](N)

      d(s) = 0
      addEdges(s)
      def addEdges(v: Int): Unit = {
        (0 until N) foreach { u =>
          if (E(v)(u) > 0) q.enqueue((E(v)(u) + d(v), v -> u))
        }
      }

      while(q.nonEmpty) {
        val (c, (v0, v)) = q.dequeue()
        if (c < d(v)) {
          d(v) = c
          pre(v) = v0
          addEdges(v)
        }
      }

      def trace(v: Int, path: List[Int]): List[Int] = v match {
        case `s` => v :: path
        case _ =>
          val u = pre(v)
          trace(u, v :: path)
      }

      (0 until N) filterNot (_ == s) foreach {t =>
        val path = trace(t, Nil)
        (0 until path.length - 1) foreach { k =>
          val l = k + 1
          used(path(k))(path(l)) = true
          used(path(l))(path(k)) = true
        }
      }
    }

    for {
      i <- 0 until N
    } {
      markUsedPath(i)
    }

    val ans = (for {
      i <- 0 until N - 1
      j <- i + 1 until N
    } yield E(i)(j) > 0 && !used(i)(j)).count(identity)

    println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

}


Measured memory_bytes: 69932
#include<iostream>
#include<algorithm>
using namespace std ;
struct abc
{
    string s ;
    int a,b;
};
abc arr[150];
bool fun(abc aa,abc bb)
{
    if(aa.s==bb.s){return aa.a>bb.a ;}
    else{return aa.s<bb.s ;}
}
int main()
{
    int n ;
    cin >> n ;
    for(int i=1;i<=n;i++)
    {
        string s1;
        int a1 ;
        cin >> s1 >> a1 ;
        arr[i-1].a=a1;
        arr[i-1].s=s1;
        arr[i-1].b=i;
    }
    sort(arr,arr+n,fun);
    for(int i=0;i<n;i++)
    {
        cout << arr[i].b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int r, c, sum,x;
    cin >> r >> c;
    int a[r + 1][c + 1];
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> x;
            a[i][j] = x;
        }
    }
    for(int i = 0; i < r; i++){
        sum = 0;
        for(int j = 0; j < c; j++){
            sum += a[i][j];
        }
        a[i][c] = sum;
    }
    for(int i = 0; i <= c; i++){
        sum = 0;
        for(int j = 0; j < r; j++){
            sum += a[j][i];
        }
        a[r][i] = sum;
    }
    for(int i = 0; i <= r; i++){
        for(int j = 0; j <= c; j++){
            if(j == c){
                cout << a[i][j];
            } else {
                cout << a[i][j] << ' ';
            }
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <queue>

using namespace std;

int main(){
    int n; cin >> n;
    int ans=0;
    for(int i=1; i<=n; ++i){
        if(i<10 || (100 <= i && i <= 999) || (10000 <= i && i <= 99999)) ++ans;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int  // ranges from (0 - twice of long long int)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define mod 1000000007LL
#define llpair pair<ll,ll>
#define INF 1000000000000000000ll
#define np next_permutation
#define PI acos(-1)
#define deb(x) cout<<#x<<" "<<x<<endl;
//ALWAYS USE ll DATA TYPE FOR INTEGER(FASTER THAN INTEGER AS WELL AS SOMETIMES WITHOUT USE LONG UR ANSWER WILL NOT ACCEPTED) && DOUBLE FOR DECIMAL VALUE
template<typename T> // for removing front element from the vector
void pop_front(std::vector<T> &v)
{
    if (v.size() > 0) {
        v.erase(v.begin());
    }
}
template<typename R> // for removing back element from the vector or can directly
void pop_back(std::vector<R> &v) // use vec.pop_back() function...
{
    if (v.size() > 0) {
        v.erase(v.begin()+v.size()-1);
    }
}

bool isprime(ll n)  //IN  O(sqrt(n))
{
    if(n<=1) return false;
    for(ll i=2;i*i<=n;i++)
        if(n%i==0)
            return false;

    return true;
}

vector<ll> factors(ll n){    //IN  O(sqrt(n))

    vll v;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            v.pb(i);
            if((n/i)!=i)
            v.pb(n/i);
        }
    }
    return v;
}

ll power(ll a, ll n)  // using Binary Exponential in TC O(logn)
{                     // Self Written By </ME> :)
    ll res=1;
    while(1)
    {
        if(n%2){
            res=res*a; n--;
        }
        if(n==0) break;
        a=a*a; n/=2;
    }
    return res;
}

ll ts(ll arr[],int l,int r,int x) // ternary search to find x in sorted array arr
{
    
    while(l<=r)
    {
        ll mid1= l+(r-l)/3;
        ll mid2= r -(r-l)/3;
        if(arr[mid1]==x || arr[mid2]==x)
            return 1;
        if(x<arr[mid1])
            r=mid1-1;
        else if(x>arr[mid2])
            l=mid2+1;
        else
        {
            l=mid1+1;
            r=mid2-1;
        }
    }

    return -1;
}


bool f(string s,ll start,ll end)
{
    while(start<=end)
    {
        if(s[start]!=s[end])
            return false;

        start++; end--;
    }

    return true;
}


int main() {
    auto start = chrono::high_resolution_clock::now();
    fio;
    ll T=1;
    //cin>>T;
    while(T--)
    {
      string s; cin>>s;
      ll n=s.length();
    bool b1 =f(s,0,n-1);
    bool b2 =f(s,0,(n-2)/2);
    bool b3 =f(s,(n+2)/2,n-1);

    if(b1 && b2 && b3)
    cout<<"Yes"<<"\n";
    else
    cout<<"No"<<"\n";
    }
    
    auto finish = chrono::high_resolution_clock::now();
    cerr << "Time elapsed: " << (chrono::duration<long double>(finish-start)).count() << "s\n";
    return 0;
}





Measured memory_bytes: 256
# -*- coding:utf-8 -*-
from math import gcd

def solve():
    K = int(input())
    ans = 0

    # 3つ同じ値のとき
    for i in range(1, K+1):
        ans += i

    # 2つ同じ値のとき
    for i in range(1, K+1):
        for j in range(1, K+1):
            if i==j: continue
            ans += gcd(i, j)*3

    # すべて異なる値のとき
    for i in range(1, K+1):
        for j in range(i+1, K+1):
            for k in range(j+1, K+1):
                ans += gcd(gcd(i,j),k)*6

    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 9200
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int M=stdIn.nextInt();
		int X[]=new int[M];
		int len[]=new int[M-1];
		int z=0,max1=0;
		while(z<M){
			X[z]=stdIn.nextInt();
			z++;
		}z=1;
		Arrays.sort(X);
		while(z<M){
			len[z-1]=X[z]-X[z-1];
			z++;
		}z=0;
		Arrays.sort(len);
		if(M-1-(N-1)>0)
			while(z<M-1-(N-1)){
				max1+=len[z];
				z++;
			}
		System.out.println(max1);
	}
}

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

int main(){

int a,b,c;
cin >> a >>b>>c;
cout << endl;
if(a==b ? (a!=c ? 1 : 0) : (a==c || b==c ? 1 : 0))
cout << "Yes";
else
cout<<"No";

return 0;
}

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

int main()
{
    ll n,x;
    cin>>n>>x;
    ll a;
    ll val=0;
    ll cnt=0;
    if(val<=x) cnt++;
    for(int i=0;i<n;i++){
        cin>>a;
        val+=a;
        if(val<=x) cnt++;
        
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define llu unsigned long long
#define loop(i,a,b) for (long long int i=a; i<b; i++)
#define loopr(i,a,b) for(long long int j=a-1;j>b;j--)
#define st string
#define sz size()
#define maxe *max_element
#define mine *min_element
#define gt greater<ll>()
#define F first
#define S second
#define R return
#define B break
#define C continue
#define pb push_back
#define tc ll t; cin>>t; while(t--)
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define ROG ios::sync_with_stdio(0); cin.tie(0);
#define sortA(v)   sort(v.begin(), v.end())
#define sortD(v)   sort(v.begin(), v.end(), greater<auto>())
#define next cout<< "\n"
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<long long int> vll;
typedef vector<char> vc;
typedef long double ld;
#define mem(a,b)     memset(a, b, sizeof a)
 
const int q = 1e6 + 1;
const int mod = 1e9+7;
 
 
ll n, a[q][2][2];
ll solve(ll i, bool flag, bool temp)
{
	if(i == n)
    {
		return ((flag)&&(temp));
	}
	if(a[i][flag][temp]!=-1)
    {
      return a[i][flag][temp];
    }
	ll c1 = solve(i+1, 1, temp)%mod;
	ll c2 = solve(i+1, flag, 1)%mod;
	ll c3 = (8 * solve(i+1, flag, temp))%mod;
 
	return a[i][flag][temp] = (c1 + c2 + c3)%mod;
}
 
 
 
int main()
{
    ROG
    mem(a, -1);
	cin >> n;
	cout << solve(0, 0, 0);
        
        
    
}
 
 

Measured memory_bytes: 112948
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000000000000



int main(){
	
	long long X,Y;
	cin>>X>>Y;
	
	int ans = 0;
	
	while(X<=Y){
		ans++;
		X*=2;
	}
	
	cout<<ans<<endl;
	
	
    return 0;
}


Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    string s;
    vector<string>ss;
    R(s);
    REP(i,SZ(s)){
        REPP(j,1,6){
            if(i+j>SZ(s))break;
            ss.PB(s.substr(i,j));
        }
    }
    SORT_UNIQUE(ss);
    int K; R(K);
    W(ss[K-1]);
    return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = s; i > (int)(n); i--)
#define all(obj) obj.begin(), obj.end()
#define db(x) cerr << #x << ":" << x << " "
#define dbl(x) cerr << #x << ":" << x << "\n"
#define dbv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
/*
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
*/

int main() {
	int N; cin >> N;
	vector<int> A(N); rep(i, N) cin >> A.at(i);
	map<int, long long> m;
	for (int i = 0; i < N; i++) {
		if (!m.count(A[i])) m[A[i]] = 1;
		else m[A[i]]++;
	}
	long long ans = 0;
	for (pair<int, long long> p : m) {
		ans += p.second * (p.second - 1) / 2;
	}
	for (int i = 0; i < N; i++) {
		cout << ans - (m[A[i]] - 1) << endl;		
	}
}

Measured memory_bytes: 10240
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end()
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){ 
    int  n, m, ans = 0 ; 
    cin >> n >> m ; 
    vector < pair<int, int> > ab(n) ; 
    vector <int>  ocupy ; 
    for (int  i = 1 ; i <= m; i++) ocupy.pb(i); 
    for (int  i = 0 ; i < n ; i++) cin >> ab[i].ss >> ab[i].ff ; 
    sort(all(ab)) ; 
    for (int  i = n-1 ; i >= 0 ; i--) { 
        int k = ab[i].ss ; 
        auto  it = lower_bound(ocupy.begin(), ocupy.end(), k ) ; 
        if (it != ocupy.end()) {
            int in =  it - ocupy.begin() ; 
            ocupy.erase( ocupy.begin() + in ) ; 
            ans += ab[i].ff ; 
        }
    }
    co (ans) ; 
}
// https://atcoder.jp/contests/abc137/tasks/abc137_d 

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 5820
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
using pi = pair<int, int>;

const int M=1e9+7;
bool sortbysec(const pair<int,int> &a,
                   const pair<int,int> &b)
{
       return a.second<b.second;
}

long long mod(long long x){
    return ((x%M + M)%M);
}

long long add(long long a, long long b){
    return mod(mod(a)+mod(b));
}

long long mul(long long a, long long b){
    return mod(mod(a)*mod(b));
}

long long minu(long long a, long long b){
    return mod(mod(a)-mod(b));
}

ll modPow(ll a, ll b){
    if(b==0)
        return 1LL;
    if(b==1)
        return a%M;
    ll res=1;
    while(b){
        if(b%2==1)
            res=mul(res,a);
        a=mul(a,a);
        b=b/2;
    }
    return res;
}

int cnt[1000100];
int main()
{
    ll t = 1;
    //cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j+=i)
                ++cnt[j];
        }
        for(int i = 3; i <= n; i++){
                cnt[i] += cnt[i-1];
        }
        //ll ans = (n-1)*2 + cnt + 1;
        cout << cnt[n] << endl;
    }
}


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int N, M;
int a[310][310];
bool t[310];
int num[310];
int id[310];

int main() {
	cin >> N >> M;

	rep(i, N) {
		rep(j, M) {
			cin >> a[i][j];
			--a[i][j];
		}
	}

	rep(i, M) t[i] = 1;

	int zan = M;
	int ret = N;

	while (zan) {
		memset(num, 0, sizeof(num));

		rep(i, N) {
			while (!t[a[i][id[i]]]) {
				++id[i];
			}
			++num[a[i][id[i]]];
		}

		pii p = mp(-1, -1);

		rep(i, M) {
			p = max(p, mp(num[i], i));
		}

		if (p.fi == 0) {
			break;
		}

		int c = p.fi;
		ret = min(ret, c);

		t[p.se] = 0;
		--zan;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main() {
	int a, b;
	while (cin >> a ) {
		b = 0;
		for (int i = 0; i < 10; i++){
			for (int j = 0; j < 10; j++){
				for (int k = 0; k < 10; k++){
					for (int l = 0; l < 10; l++){
							if (i + j + k + l == a){
								b = b + 1;
						}
					}
				}
			}
		}
		cout << b << endl;
	}
}

Measured memory_bytes: 3068
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep2(i,a,b)for(int i=a;i<b;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
//#define ll long long

int n;
int a[210000];
int b[210000];
int ta[210000];
int tb[210000];
int main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	//sort(a,a+n);
	//sort(b,b+n);
	int ans=0;
	
	rep(k,29){
		int cnt=0,m=(1<<k);
		int mo=m*2;
		rep(i,n)ta[i]=a[i]%mo;
		rep(i,n)tb[i]=b[i]%mo;
		sort(ta,ta+n);
		sort(tb,tb+n);
		rep(i,n){//各aiとbjの和のkbit目の数を数える
			cnt+=upper_bound(tb,tb+n,2*m-ta[i]-1)-lower_bound(tb,tb+n,m-ta[i]);
			cnt+=upper_bound(tb,tb+n,3*m-ta[i]-1)-lower_bound(tb,tb+n,4*m-ta[i]);
		}
		if(cnt&1)ans+=(1<<k);
	}

	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a(n),copy(n);
  int i;
  for(i=0;i<n;i++){
    cin >> a.at(i);
    copy.at(i)=a.at(i);
  }
  sort(copy.begin(),copy.end());
  reverse(copy.begin(),copy.end());
  int p_1=copy.at(0),p_2=copy.at(1);
  for(i=0;i<n;i++){
    if(a.at(i)!=p_1){
      cout << p_1<<endl;
    }else{
      cout << p_2 <<endl;
    }
  }
}
  

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

int main(){
  int A,B;
  cin >> A >> B;
  
  for (int i = 1; i <= 1009 ; i++) {
    if (i*8/100 == A && i/10 == B) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(;;){
        ll n;
        cin>>n;
        if(!n) return 0;
        int e=0;
        ll m=1;
        rep(i,0,52){
            char c;
            cin>>c;
            m=2*m+(c-'0');
        }
        ll res=m;
        while(n&&res>=(1LL<<e)){
            if(n>=((1LL<<53)-res+(m>>e)-1)/(m>>e)){
                n-=((1LL<<53)-res+(m>>e)-1)/(m>>e);
                res+=((1LL<<53)-res+(m>>e)-1)/(m>>e)*(m>>e);
                e++;
                res>>=1;
            }
            else{
                res+=(m>>e)*n;
                n=0;
            }
        }
        rer(i,12,0){
            cout << (1LL&e>>i?1:0);
        }
        rer(i,52,0){
            cout << (1LL&res>>i?1:0);
        }
        cout <<"\n";
    }
}


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

const int N = 3e5 + 9;

int W, H, n, tag[N << 2], ans, mx[N << 2], t1, t2;
struct Py { int x, y; }s1[N], s2[N];

#define L (x<<1)
#define R (x<<1|1)

void Modify (int x, int l, int r, int ql, int qr, int t) {
	if (l == ql && r == qr) return void((mx[x] += t, tag[x] += t));
	int mid = (l + r) >> 1;
	if (qr <= mid) Modify(L, l, mid, ql, qr, t);
	else if (ql > mid) Modify(R, mid + 1, r, ql, qr, t);
	else Modify(L, l, mid, ql, mid, t), Modify(R, mid + 1, r, mid + 1, qr, t);
	mx[x] = max(mx[L], mx[R]) + tag[x];
}

int Query (int x, int l, int r, int ql, int qr) {
	if (l == ql && r == qr) return tag[x];
	int mid = (l + r) >> 1;
	if (qr <= mid) return Query(L, l, mid, ql, qr) + tag[x];
	if (ql > mid) return Query(R, mid + 1, r, ql, qr) + tag[x];
	return max(Query(L, l, mid, ql, qr), Query(R, mid + 1, r, ql, qr)) + tag[x];
}

void Max (int &x, int y) { if (x < y) x = y; }

struct Point {
	int x, y;
	bool operator < (const Point &rhs) const { return y < rhs.y; }
}p[N];

void Solve () {
	sort(p + 1, p + n + 1); memset(tag, 0, sizeof tag); memset(mx, 0, sizeof mx); t1 = t2 = 0;
	int mid = W >> 1;
	Modify(1, 0, n, 0, 0, W); s1[++t1] = Py{0, 0}; s2[++t2] = Py{W, 0};
	for (int i = 1, j; i <= n; ++i) {
		Max(ans, (mx[1] + p[i].y) << 1);
		if (p[i].x <= mid) {
			for (j = 0; t1 && s1[t1].x <= p[i].x; --t1, j = 1) {
				Modify(1, 0, n, s1[t1 - 1].y + 1, s1[t1].y, s1[t1].x - p[i].x);
			}
			if (j) s1[++t1] = Py{p[i].x, i - 1};
		} else {
			for (j = 0; t2 && s2[t2].x >= p[i].x; --t2, j = 1) {
				Modify(1, 0, n, s2[t2 - 1].y + 1, s2[t2].y, p[i].x - s2[t2].x);
			}
			if (j) s2[++t2] = Py{p[i].x, i - 1};
		}
		s1[++t1] = Py{0, i};
		s2[++t2] = Py{W, i};
		Modify(1, 0, n, i, i, W - p[i].y);
	}
	Max(ans, (mx[1] + H) << 1);
}

int main () {
//	freopen("F.in", "r", stdin);
	scanf("%d%d%d", &W, &H, &n); s2[0].y = s1[0].y = -1;
	for (int i = 1; i <= n; ++i) scanf("%d%d", &p[i].x, &p[i].y);
	Solve();
	for (int i = 1; i <= n; ++i) swap(p[i].x, p[i].y); swap(W, H);
	Solve();
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 16640
#include <stdio.h>

int main(void)
{
	int H, W, 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++) {
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
//cout << std::fixed << std::setprecision(15);
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e9;
const long long MOD = 1e9+7;
signed main(){
    /*
    int n; cin >> n;
    set<int> set;
    rep(i,n){
        int add; cin >> add;
        set.insert(add);
    }
    if(n==set.size()) coutY;
    else coutN;
    */
    int n; cin >> n;
    vint a(n); rep(i,n) cin >> a[i];
    sort(all(a));
    bool can=true;
    rep(i,n-1){
        if(a[i]==a[i+1]) can=false;
    }
    if(can) coutY;
    else coutN;

}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	int x = a+b;
	if( x < (a-b) ){
		x = a-b;
	}
	if( x < (a*b) ){
		x=a*b;
	}
	printf("%d",x);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long  long
using namespace std;
int main()
{	ll x=1;
	ll h;
	ll sum=0;
	cin>>h;
	while(h)
	{
		h=h/2;
		sum+=x;
		x=x*2;
	 } 
	 cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

int main()
{
    int N;
    cin >> N;
    
    map<int, int> pf;
    for (int i = 2; i <= N; i++) {        
        int n = i;
        for (int j = 2; j <= n; j++) {
            while (n % j == 0) {
                ++pf[j];
                n /= j;
            }
        }
    }
    
    long long res = 1;
    constexpr long long MOD = ((1e9) + 7);
    
    for (auto& v : pf) {
        res *= (v.second + 1);
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int i;
  int N,A[110];
  double a,b;
  scanf("%d",&N);
  for(i=0;i<N;i++)
    scanf("%d",&A[i]);
  for(i=0;i<N;i++)
    a += (double)1/A[i];
  b = 1/a;
  printf("%.5lf\n",b);
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>

int main(){
    int n,a,b;
    scanf("%d%d%d",&n,&a,&b);
    if(n==1){
        if(a==b)
            printf("1");
        else
            printf("0");
    }
    else{
        if(a>b)
            printf("0");
        else if(a==b){
            printf("1");
        }
        else
            printf("%lld",(long long)(b-a)*(n-2)+1);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
ll mod = 1000000007;
ll N, K;
ll dp[305][305];
ll factor[305][305];

void Precalc() {
    for(int i = 0; i <= 300; i++) factor[0][i] = 1;
    for(ll beforelen = 0; beforelen <= 300; beforelen++) {
        for(ll beforenum = 0; beforenum <= 300; beforenum++) {
            ll tmp = 1;
            for(ll num = 0; num + beforenum <= 300; num++) {
                factor[beforelen+1][beforenum+num] += factor[beforelen][beforenum] * tmp;
                factor[beforelen+1][beforenum+num] %= mod;
                tmp *= beforelen + 2;
                tmp %= mod;
            }
        }
    }
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K >> mod;
    Precalc();
    /*
    for(int i = 0; i <= 5; i++) {
        for(int j = 0; j <= 5; j++) {
            cerr << i << " " << j << " " << factor[i][j] << endl;
        }
    }
    */
    dp[0][0] = 1;
    for(ll val = 1; val <= K; val++) {
        for(ll before = 0; before <= N; before++) {
            for(ll num = 0; before + num <= N; num++) {
                dp[val][before+num] += factor[before][num] * dp[val-1][before];
                dp[val][before+num] %= mod;
            }
        }
    }
    /*
    for(int i = 0; i <= K; i++) {
        for(int j = 0; j <= N; j++) {
            cerr << i << " " << j << " " << dp[i][j] << endl;
        }
    }
    */
    cout << dp[K][N] << endl;
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>

int ans[7]={};
int n,x,m,l[11]={},r[11]={},s[11]={};

int cntlion(int ll, int rr, int lion[]){
  int res=0;
  for(int i=ll-1;i<=rr-1;++i){
    res+=lion[i];
  }
  return res;
}

void dfs(int now, int lion[]){
  if(now==n){

    for(int i=0;i<m;++i){
      if(cntlion(l[i],r[i],lion) != s[i])return ;
    }
    int cnt=0;
    cnt=cntlion(1,n,lion);
    /*for(int i=0;i<n;++i){
      cnt+=lion[i];
    }
    lion[6]=cnt;*/
    if(cnt>=cntlion(1,n,ans)){

      for(int i=0;i<n;++i){
        ans[i]=lion[i];
      }
      //std::cout<<std::endl;
      //ans[6]=cnt;
    }
    return ;
  }else{
    for(int i=0;i<=x;++i){
      lion[now]=i;
      dfs(now+1,lion);
    }
  }
}

int main(){

  std::cin>>n>>x>>m;
  for(int i=0;i<m;++i){
    std::cin>>l[i]>>r[i]>>s[i];
  }
  int lion[11];
  ans[0]=-1;
  dfs(0,lion);
  if(ans[0]==-1){
    std::cout<<-1<<std::endl;
    return 0;
  }
  for(int i=0;i<n;++i){
    std::cout<<ans[i];
    if(i<n-1)std::cout<<" ";
  }
  std::cout<<std::endl;
  return 0;
}



Measured memory_bytes: 3068
from heapq import heappush, heappop
from collections import defaultdict

INF = float('inf')
def dijkstra(V, E, s):
    '''
    Input:
        V = list(range(N))
        E = defaultdict(dict)
        s (in V) : start vertex
    Output:
        dist: the list of the minimum cost from s to arbitrary vertex v in the given graph
    '''
    dist = {v: INF for v in V}
    heap = []
    dist[s] = 0; rem = len(V);
    heappush(heap, (0, s))
    while heap and rem:
        d, v = heappop(heap)
        # don't need to check when the stored value is greater than provisional distance
        if d > dist[v]: continue
        rem -= 1;
        for u, c in E[v].items():
            temp = d + c
            if temp < dist[u]:
                dist[u] = temp
                heappush(heap, (temp, u))
    return dist

N, M = map(int, input().split())
V = list(range(N))
E = defaultdict(dict)
for i in range(N):
    E[i+1][i] = 0
for _ in range(M):
    l, r, c = map(int, input().split())
    l, r = l-1, r-1
    E[l][r] = min(c, E[l].setdefault(r, INF))
dist = dijkstra(V, E, 0)
print(dist[N-1] if dist[N-1] != INF else -1)

Measured memory_bytes: 67288
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int n, m, c, a, b[101];

int main(){
	cin >> n >> m >> c;
	for(int i = 0; i < m; i++) cin >> b[i];
	int cnt = 0;
	for(int i = 0; i < n; i++){
		int d = c;
		for(int j = 0; j < m; j++){
			cin >> a;
			d += a*b[j];
		}
		if(d > 0) cnt++;
	}
	
	cout << cnt << endl;
	
	return 0;
}

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

vector<int> color;

void dfs(vector<vector<pair<int, int>>> &g, int v, int c = 0) {
  color[v] = c;
  for (auto a : g[v]) {
    if (color[a.first] != -1) {
      continue;
    }
    if (a.second % 2 == 0) dfs(g, a.first, c);
    else dfs(g, a.first, 1 - c);
  }
}

int main() {
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> g(n);
  rep(i, n - 1) {
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    g[u].push_back(make_pair(v, w));
    g[v].push_back(make_pair(u, w));
  }
  color.assign(n, -1);
  rep(i, n) {
    if (color[i] != -1) continue;
    dfs(g, i);
  }
  rep(i, n) cout << color[i] << endl;
  return 0;
}


Measured memory_bytes: 11116
class Combination:
    def __init__(self, n, mod):
        self.n = n
        self.mod = mod
        self.fac = [1 for i in range(self.n + 1)]
        self.finv = [1 for i in range(self.n + 1)]
        for i in range(2, self.n+1):
            self.fac[i] = (self.fac[i - 1] * i) % self.mod
            self.finv[i] = (self.finv[i-1] * pow(i, -1, self.mod)) % self.mod

    def comb(self, n, m):
        return self.fac[n] * (self.finv[n-m] * self.finv[m] % self.mod) % self.mod
def iparse():
    return list(map(int, input().split()))

if __name__ == "__main__":
    n, a = iparse()
    x = iparse()

    dp = [[[0 for i in range(sum(x) + 10)] for j in range(n + 10)] \
        for k in range(n + 10)]
    dp[0][0][0] = 1
    for i in range(n):
        for j in range(n + 1):
            for k in range(sum(x) + 1):
                if j >= 1 and k - x[i] >= 0:
                    dp[i + 1][j][k] = dp[i][j][k] + dp[i][j - 1][k - x[i]]
                else:
                    dp[i+1][j][k] = dp[i][j][k]
    ans = 0
    for i in range(n):
        if (i + 1) * a >= sum(x) + 10:
            break
        ans += dp[n][i + 1][(i+1)*a]
    print(ans)
    


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    string s, t;
    cin >> s >> t;

    int N = s.size(), M = t.size();

    vector<vector<int>> dp(N + 1, vector<int>(M + 1));
    rep(i, N) {
        rep(j, M) {
            if (s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j] + 1);
            else chmax(dp[i+1][j+1], max(dp[i+1][j], dp[i][j+1]));
        }
    }

    string ans = "";
    int i = N, j = M;
    while (ans.size() < dp[N][M]) {
        if (s[i-1] == t[j-1]) {
            ans.push_back(s[i-1]);
            i--, j--;
        } else {
            if (dp[i-1][j] < dp[i][j-1]) j--;
            else i--;
        }
    }

    reverse(ans.begin(), ans.end());

    cout << ans << endl;
}

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

int main() {
    string s;
    cin >> s;
    rep(i, 0, s.size()) {
        if (s[i] == 'C') {
            rep(j, i, s.size()) {
                if (s[j] == 'F') {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256