akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(n), c(m), d(m);
	for (int i = 0; i < n; i++)
		cin >> a[i] >> b[i];
	for (int i = 0; i < m; i++)
		cin >> c[i] >> d[i];
	for (int i = 0; i < n; i++) {
		int ans = -1, dist = 1e9;
		for (int j = 0; j < m; j++) {
			if (i == 1 && j == 2) {
				int a = 0;
				i += a;
			}
			if (abs(a[i] - c[j]) + abs(b[i] - d[j]) < dist) {
				ans = j;
				dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			}
		}
		cout << ans + 1 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
using namespace std;

class UnionFind {
private:
  vector<int> par;              // 親
  vector<int> rank;             // 木の深さ

public:
  // n 要素で初期化
  UnionFind(int n) {
    par.resize(n);              // or MAX_N
    rank.resize(n);
    REP(i,0,n) {
      par[i] = i;
      rank[i] = 0;
    }
  }

  // 木の根を求める
  int find(int x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = find(par[x]);
    }
  }

  // xとyの属する集合を併合
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }

  // xとyが同じ集合に属するか否か
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

typedef pair<int, int> P;
int N,K,L;

int main()
{
  cin >> N >> K >> L;
  // 道路
  UnionFind uf1(N);
  REP(i,0,K) {
    int p,q;
    cin >> p >> q;
    // 都市番号は 0-indexed に
    uf1.unite(p-1,q-1);
  }

  // 鉄道
  UnionFind uf2(N);
  REP(i,0,L) {
    int r,s;
    cin >> r >> s;
    uf2.unite(r-1,s-1);
  }

  // 全ての都市iについて，グループ番号 (UF木の根) を計算
  vector<P> vec;
  REP(i,0,N) {
    // (道路に関するグループ番号, 鉄道に関するグループ番号)
    P p = P(uf1.find(i), uf2.find(i));
    vec.push_back(p);
    //printf("(%d, %d)\n", p.first, p.second);
  }

  // ペアとして一致していれば，道路でも鉄道でも繋がっている
  // 同じペアがいくつ出てくるか
  map<P, int> mp;
  REP(i,0,N) {
    P p = vec[i];
    mp[p]++;                    // 初期値0を期待
  }

  // 都市i
  REP(i,0,N) {
    if (i > 0) cout << " ";
    cout << mp[vec[i]];
  }
  cout << endl;

  return 0;
}


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

#define ll long long
#define ar array

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    for (int i = 1; i <= 1e4; i++) {
        int a1 = i * 8 / 100, b1 = i / 10;
        if (a1 == a && b1 == b) {
            cout << i << "\n";
            return 0;
        }
    }
    cout << -1 << "\n";
}


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

int main(){
  string S;
  int K;
  cin >> S >> K;

  for(int i=0;i<S.size();i++){
    if(S.at(i)=='a')  continue;
    int tmp=26-(S.at(i)-'a');
    if(tmp<=K){
      S.at(i)='a';
      K-=tmp;
    }
  }
  S.at(S.size()-1)=((S.at(S.size()-1)-'a')+K%26)%26+'a';
  cout << S << endl;

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string S, T;
  cin >> S >> T;
  vector<int> seq(26, -1);
  vector<int> vec(26, -1);
  REP(i, S.size()) {
    int a = S[i] - 'a';
    int b = T[i] - 'a';
    if (vec[b] > -1 && vec[b] != a) {
      cout << "No" << endl;
      return 0;
    }
    if (seq[a] > -1 && seq[a] != b) {
      cout << "No" << endl;
      return 0;
    }

    seq[a] = b;
    vec[b] = a;
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 776
N, T = map(int,input().split())
CT = [list(map(int,input().split())) for x in range(N)]
c = [i[0] for i in CT]
t = [i[1] for i in CT]

if min(t) > T:
    print("TLE")
else:
    l = [i for i in range(N) if t[i]<=T]
    ca = 10000
    for i in l:
        if ca >= c[i]:
            ca = c[i]
    print(ca)


Measured memory_bytes: 3064
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

class UnionFindTree {
public:
    this(size_t n) {
        parent = iota(n).array();
        rank = new size_t[](n);
    }
    size_t find(size_t n) {
        if(n == parent[n]) {
            return n;
        } else {
            parent[n] = find(parent[n]);
            return parent[n];
        }
    }
    void unite(size_t n, size_t m) {
        auto p1 = find(n);
        auto p2 = find(m);
        if(n == m) {
            return;
        }
        if(rank[p1] < rank[p2]) {
            swap(p1, p2);
        }
        if(rank[p1] == rank[p2]) {
            ++rank[p1];
        }
        parent[p2] = p1;
    }
private:
    size_t[] parent;
    size_t[] rank;
}
unittest {
    auto uft = new UnionFindTree(10);
    foreach(i; iota(10)) {
        assert(uft.find(i) == i);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0).drop(1)) {
        uft.unite(i, i-3);
    }
    foreach(i; iota(10).filter!(a => a%3 == 0)) {
        assert(uft.find(0) == uft.find(i));
    }
    foreach(i; iota(10).filter!(a => a%3 != 0)) {
        assert(uft.find(0) != uft.find(i));
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

void main(){
    long x, y;
    readlnTo(x, y);
    BigInt X = x;
    BigInt Y = y;
    long ans;
    while(X <= Y) {
        ++ans;
        X *= 2;
    }
    writeln(ans);
}



Measured memory_bytes: 256
#create date: 2020-06-29 13:18

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    a, b, t = na()
    print(b  * (t // a))

if __name__ == "__main__":
    main()

Measured memory_bytes: 9176
N, A , B = map(int, input().split())
S = input()


kaigai = 0
Sankasya = 0

for i in range(1,N+1):
    if S[i-1] == "c":
        print("No")

    if S[i-1] == "a":
        if (Sankasya) < A+B:
            Sankasya = Sankasya + 1
            print("Yes")
        else:
            print("No")
    
    if S[i-1] == "b":
        kaigai = kaigai + 1
        if (Sankasya) < A+B and  B >= kaigai:
            Sankasya = Sankasya + 1
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 4016
from math import gcd
from functools import reduce

N, *A = map(int, open(0).read().split())

def f():
    t = [0] * (10 ** 6 + 1)
    for a in A:
        t[a] += 1

    c = 0
    for j in range(2, 10 ** 6 + 1, 2):
        c += t[j]
    if c > 1:
        return False

    for i in range(3, 10 ** 6 + 1, 2):
        c = 0
        for j in range(i, 10 ** 6 + 1, i):
            c += t[j]
        if c > 1:
            return False

    return True

if f():
    print('pairwise coprime')
elif reduce(gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')


Measured memory_bytes: 121816
#include<stdio.h>
int main()
{
  int a,i,j;
  while(~scanf("%d",&a))
   {
    i=a/100;
    j=a%10;
    if(i==j)
      {
          printf("Yes");
      }
    else
    printf("No");
   }
    return 0;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static StringBuilder sb = new StringBuilder();
        static int cnt;

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] A = new int[n];

            for(int i= 0; i < n; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
            }

            ShellSort(A, n);

            foreach (var num in A)
            {
                sb.AppendLine(num.ToString());
            }

            Console.Write(sb);
        }

        static void ShellSort(int[] A, int n)
        {
            cnt = 0;

            List<int> G = new List<int>();
            int h = 1;

            do
            {
                G.Insert(0, h);
                h = h * 3 + 1;

            } while (h < n);

            int m = G.Count;

            for(int i = 0; i < m; i++)
            {
                InsertionSort(A, n, G[i]);
            }
            
            string temp = "";
            foreach (var num in G)
            {
                temp += num + " ";
            }
            sb.AppendLine(m.ToString());
            sb.AppendLine(temp.Trim());
            sb.AppendLine(cnt.ToString());
        }

        static void InsertionSort(int[] A, int n, int g)
        {
            for(int i = g; i < n; i++)
            {
                int v = A[i];
                int j = i - g;

                while (j >= 0 && A[j] > v)
                {
                    A[j + g] = A[j];
                    j = j - g;
                    cnt++;
                }

                A[j + g] = v;
            }
        }
    }
}

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

int main() {
	double a[100], sum = 0;
	int n;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		a[i] = 1.0 / a[i];
	}

	for (int i = 0; i < n; ++i)
		sum += a[i];

	printf("%.10f\n", 1.0 / sum);

	return 0;
}

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

int main(void){
    long long int n,a,b,i,blue,red,ans,set,r;

    cin >> n >> a >> b;

    set = n / (a + b);
    blue = a * set;


    if(n - (a + b) * set == 0){
        cout << blue << endl;
    }else if(n - (a + b) * set >= a ){
        cout << blue + a << endl;
    }else if(n - (a + b) * set <= a){
        cout << blue + (n - (a + b) * set )<< endl;
    }

    return 0;
}

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

#define Debug(x) x
typedef int regular_int;
// #define int ll
typedef long long ll;

int A[50], B[50], C[50];

regular_int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(12) << fixed;
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i) {
		cin >> A[i];
		--A[i];
	}
	for(int i = 0; i < n; ++i) {
		cin >> B[i];

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

	}
	ll res = 0;
	for(int i = 0; i < n; ++i) {
		res += B[A[i]];
		if(i + 1 < n && A[i + 1] == A[i] + 1) {
			res += C[A[i]];

		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)     for(long long int i=a; i<n; i++)
#define loop(i,a,n)     for(long long int i=a; i>=n; i--) 

int main()
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL);
	
	int a, b, c, ans=-1;
	cin>>a>>b>>c;
	int x[c], y[c], m2x=-1, m1x=-1;
	map<int,int> m2, m1;
	map<pair<int,int>, int> m;
	forr(i, 0, c)
	{
		cin>>x[i]>>y[i];
		m[{x[i], y[i]}]++;
		m1[x[i]]++;
		m2[y[i]]++;
		m2x=max(m2x, m2[y[i]]);
		m1x=max(m1x, m1[x[i]]);
	}
	vector<int> v, w;
	for(auto const x: m1)
	{
		if(x.second==m1x)
			v.push_back(x.first);
	}
	for(auto const x: m2)
	{
		if(x.second==m2x)
			w.push_back(x.first);
	}
	forr(i, 0, v.size())
	{
		forr(j, 0, w.size())
		{
			int xx=m1[v[i]]+m2[w[j]]-m[{v[i] ,w[j]}];
			ans=max(ans, xx);
			if(m[{v[i], w[j]}]==0)
				break;
		}
	}
	cout<<ans<<'\n';
	//cout<<m1[5]<<' '<<m2[3]<<' '<<m[{5, 3}]<<' '<<m[{3, 5}];
	
	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    string s;
    cin >> s;
    int res = 0;
    for (int i = 0; i < s.length()/2; ++i) {
        if (s[i] != s[s.length()-1-i]) ++res;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int h = a/3600;
        int m = (a%3600)/60;
        int s = (a%3600)%60;



        System.out.println( h + ":" + m + ":" + s);
    }

}


Measured memory_bytes: 26164
#include <iostream>
#include <stdio.h>
using namespace std;
bool v[200];
int main()
{
    int n,c1=0,i;char c;
    cin>>n;c=getchar();
    while(n!=0)
    {
        c=getchar();
        v[c]=1;
        c=getchar();
        --n;
    }
    for(i=1;i<='Z';++i)
        if(v[i])
            ++c1;
    if(c1==3)
        cout<<"Three";
    else
        cout<<"Four";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int a[101];

int binarysearch(int tar,int l,int r)
{
	if(l>r)	return 0;

	int m=(l+r)/2;
	if     (a[m]==tar)	return 1;
	else if(a[m]<tar)	return 1+binarysearch(tar,m+1,r);
	else				return 1+binarysearch(tar,l,m-1);
}

int main()
{
	for(int n;scanf("%d",&n),n;){
		for(int i=0;i<n;i++)	scanf("%d",a+i);
		int tar;	scanf("%d",&tar);
		printf("%d\n",binarysearch(tar,0,n-1));
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
 

int main(){
    string s; cin >> s;
    int l=s.length();
    rep(i,l) printf("%c",'x');
return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        
        int min = Integer.MAX_VALUE;
        int max = -1 * Integer.MAX_VALUE;
        long sum = 0;
        
        for (int i = 0; i < n; i++) {
            int k = sc.nextInt();
            if (k < min) { min = k; }
            if (k > max) { max = k; }
            sum += k;
        }
        
        System.out.println(min + " " + max + " " + sum);
    }
}


Measured memory_bytes: 42396
import math


def main():
    N, K = map(int, input().split())
    print((max(0, N - K + 1) + sum(
        max(0, N - (math.ceil(K * (1 / 2) ** i)) + 1) * (1 / 2) ** i
        - max(0, N - (math.ceil(K * (1 / 2) ** (i - 1))) + 1) * (1 / 2) ** i
        for i in range(1, len(bin(K)) - 2 + 1))) / N)
    return


main()


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static boolean isPrime(int num) {
		for (int i = 2; i <= Math.sqrt(num); i++) {
			if (num%i == 0) {
				return false;
			}
		}
		
		return true;
	}
	
	public static int getNumPrimes(int[] list) {
		int result = 0;
		
		for (int i = 0; i < list.length; i++) {
			if (isPrime(list[i])) {
				result++;
			}
		}
		
		return result;
	}
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int inputSize = scanner.nextInt();
		int[] input = new int[inputSize];
		for (int i = 0; i < inputSize; i++) {
			input[i] = scanner.nextInt();
		}
		scanner.close();
		
		System.out.println(getNumPrimes(input));
	}
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n;
    cin >> n;
    vector<vector<ll>> cnt(10, vector<ll>(10));
    for (int i=1; i<=n; ++i) {
        string s = to_string(i);
        char head = s.front(), tail = s.back();
        ++cnt.at(head-'0').at(tail-'0');
    }
    ll res = 0;
    for (int i=1; i<10; ++i) {
        for (int j=1; j<10; ++j) {
            res += cnt.at(i).at(j) * cnt.at(j).at(i);
        }
    }
    cout << res << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3640
package main

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

func main() {
	scan_init()
	k := scanInt()
	a := scanInt()
	b := scanInt()
	min := k+1
// 	count := 1
	flow := (k+1)/(a+2)
	amari := (k+1)%(a+2)
	ans := flow*b+amari
	// fmt.Println(ans)
	if min > ans {
		ans = min
	}
	nextans := 0
	get:= (k+1) - (a+2)// 残りの数がわかる
	nextans = (get/2) * (b-a)
	if get%2 != 0 {
		nextans+= 1
	}
	if get > 0 {
		nextans += b
	}
	if nextans > ans {
		ans = nextans
	}
	fmt.Println(ans)
}

var sc = bufio.NewScanner(os.Stdin)

func scan_init() {
	sc.Split(bufio.ScanWords)
}
func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func scan() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 200000)

func readLine() string {
	buf := make([]byte, 0, 200000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
func readLineToNumber() int {
	S := readLine()
	number, _ := strconv.Atoi(S)
	return number
}
func readLineToSlice() []string {
	S := readLine()
	list := strings.Split(S, "")
	return list
}
func readLineToNumberSlice(memo map[string]int) []int {
	// err時は-1を代入
	S := readLine()
	intList := make([]int, len(S))
	for i := 0; i < len(S); i++ {
		if val, ok := memo[string(S[i])]; ok {
			intList[i] = val
		} else {
			intList[i] = -1
		}
	}
	return intList
}

Measured memory_bytes: 1784
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int[] age = new int[7];
			int n = sc.nextInt();
			if(n == 0) break;
			for(int i = 0 ; i < n ; i++){
			int a = sc.nextInt();
			if(a < 10){
				age[0]++;
			} else if(a >= 10 && a < 20){
				age[1]++;
			}else if(a >= 20 && a < 30){
				age[2]++;
			}else if(a >= 30 && a < 40){
				age[3]++;
			}else if(a >= 40 && a < 50){
				age[4]++;
			}else if(a >= 50 && a < 60){
				age[5]++;
			}else if(a >= 60){
				age[6]++;
			}
			}
			for(int i : age){
				System.out.println(i);
			}
		}

		sc.close();
	}

}

Measured memory_bytes: 209956
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
s = input()
t = input()
#dp[i][j]...sのi文字目まで、tのj文字目までを考えた時の共通する部分文字列の最長の長さ
dp = [[0] * (len(t) + 1) for _ in range(len(s) + 1)]
ans = ''

for i in range(len(s) + 1):
	for j in range(len(t) + 1):
		if i == 0 or j == 0:
			dp[i][j] = 0
		elif s[i - 1] == t[j - 1]:
			dp[i][j] = dp[i - 1][j - 1] + 1
		else:
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])

i = len(s)
j = len(t)

while i > 0 and j > 0:
	if dp[i][j] > dp[i - 1][j] and dp[i][j] > dp[i][j - 1]:
		ans = s[i - 1] + ans
		i -= 1
		j -= 1
	elif dp[i][j] > dp[i - 1][j]:
		j -= 1
	else:
		i -= 1
		
print(ans)
	

Measured memory_bytes: 112220
using System;

class PG{
    static void Main(string[] args){
        int n;
        int i=1;
        while(true){
            n=int.Parse(Console.ReadLine());
            if(n==0){
                break;
            }
            Console.WriteLine("Case {0}: {1}",i,n);
            i++;
        }
    }
}


Measured memory_bytes: 17900
N = int(input())
AC, WA, TLE, RE = 0, 0, 0, 0
for i in range(N):
    S = input()
    if S == "AC":
        AC += 1
    elif S == "WA":
        WA += 1
    elif S == "TLE":
        TLE += 1
    elif S == "RE":
        RE += 1
print("AC x {}".format(AC))
print("WA x {}".format(WA))
print("TLE x {}".format(TLE))
print("RE x {}".format(RE))




Measured memory_bytes: 9208
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1000000007;
const long long INF = 1LL << 55;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n, m;
int a[10];
string dp[100004];
int cost[10] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

string Max(string s1, string s2)
{
	if (s1.size() > s2.size()) {
		return s1;
	}

	if (s1.size() < s2.size()) {
		return s2;
	}

	if (s1.size() == 0) return "";

	if (s1 > s2) return s1;
	else return s2;

}

int main()
{
	cin >> n >> m;
	for (int i = 0;i < m;i++) cin >> a[i];

	for (int i = 0;i < n + 100;i++) dp[i] = "";
	sort(a, a + m);
	for (int j = 0;j < m;j++) {
		dp[cost[a[j]]] = char(a[j] + '0');
	}

	for (int i = 0;i <= n;i++) {
		if (dp[i] == "") continue;

		for (int j = 0;j < m;j++) {
			dp[i + cost[a[j]]] = Max(dp[i + cost[a[j]]], dp[i] + char(a[j] + '0'));
			dp[i + cost[a[j]]] = Max(dp[i + cost[a[j]]], char(a[j] + '0') + dp[i]);
		}
		//if (i - 8 > 0) dp[i - 8].clear();
	}

	cout << dp[n] << endl;

	return 0;
}


Measured memory_bytes: 39936
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
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 DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vll a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vvll dp(n, vll(n, -HIGHINF));
    
    auto memo = [&](auto && self, int l, int r) -> ll {
        if (dp[l][r] != -HIGHINF) return dp[l][r];
        if (l == r) return dp[l][r] = a[l];
        else return dp[l][r] = max(a[l] - self(self, l + 1, r), a[r] - self(self, l, r - 1));
    };
    cout << memo(memo, 0, n - 1) << '\n';
    return 0;
}


Measured memory_bytes: 73888
#include <iostream>

using namespace std;
string S;
int main() {
    cin >> S;
    int L = S.size()/2;
    int R = S.size()/2;
    if(S.size() % 2 != 1) {
        L--;
    }
    // Special case when even and not the same
    if(S[L] != S[R]) {
        cout << S.size()/2;
        return 0;
    }
    char thingy = S[L];
    while(L != 0 && S[L-1] == thingy && S[R+1] == thingy) {
        L--; R++;
    }
    cout << R+1 << "\n";
    return 0;
}

Measured memory_bytes: 512
n,m=map(int,input().split())
a=[]
b=[]
c=n-m+1
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())
ans='No'
for i in range(c):
    for j in range(c):
        flag=0
        for k in range(m):
            if b[k]==a[i+k][j:j+m]:
                flag+=1
        if flag==m:
            ans='Yes'
            break
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <limits>
#include <cassert>

#define seq(i, n) for (int i = 0; i < (n); i++)
#define seq2(i, f, t) for (int i = (f); i < (t); i++)
#define rev(i, n) for (int i = (n); i >= 0; i--)
#define rev2(i, f, t) for (int i = (f); i >= (t); i--)
#define all(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;

void solve(vector<int> v) {
  vector<int> v2 = v;
  sort(all(v2), greater<int>());
  int mx=v2[0];
  int mx2=v2[1];
  for(const auto& a: v){
    if(a==mx){
      cout<<mx2<<endl;
    }else{
      cout<<mx<<endl;
    }
  }
}

int main() {
  #ifdef TEST
    solve();
  #else
    int n;
    vector<int> v;
    cin>>n;
    seq(i,n){
      int a;
      cin>>a;
      v.push_back(a);
    }
    solve(v);

  
  #endif

  return 0;
}


Measured memory_bytes: 4084
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
lint mo=1000000007;
string s[1919];
map<lint,vector<vector<lint> > > me;
vector<lint> cl(2,0);
vector<vector<lint> > tmp(2,cl);
lint zyo(lint x,lint y){
    lint ret=1,a=x;
    while(y>0){
    	if(y%2==1) ret=(ret*a)%mo;
    	a=(a*a)%mo;y/=2;
    }
    return ret;
}
vector<vector<lint> > rec(lint n){
	if(me[n].size()) return me[n];
	vector<vector<lint> > mae=rec(n/2),ato=rec(n-n/2),ret=tmp;
	rep(i,2) rep(j,2) rep(k,2){
		ret[i][j]+=mae[i][k]*ato[k][j];
		ret[i][j]%=mo;
	}
	return me[n]=ret;
}
lint cal(lint z,lint t,lint k,lint c){
	//cerr<<z<<' '<<t<<' '<<c<<endl;
	vector<vector<lint> > one=tmp,ze=tmp;
	one[0][0]=t;one[1][0]=c;one[1][1]=z;ze[0][0]=ze[1][1]=1;
	me[0]=ze;me[1]=one;
	vector<vector<lint> > mat=rec(k-1);
	lint x=mat[0][0],y=mat[1][0];
	return ((x-y)%mo+mo)%mo;
}
int main()
{
	int h,w,a=0,b=0,t=0,c=0;lint k;
	cin>>h>>w>>k;
	rep(i,h) cin>>s[i];
	if(k<1){
		cout<<1<<endl;return 0;
	}
	rep(i,w) if(s[0][i]==s[h-1][i] && s[0][i]=='#') a++;
	rep(i,h) if(s[i][0]==s[i][w-1] && s[i][0]=='#') b++;
	rep(i,h) rep(j,w){if(s[i][j]=='#') t++;}
	if(a<1 && b<1){
		cout<<zyo(t,k-1)<<endl;return 0;
	}
	if(a>0 && b>0){
		cout<<1<<endl;return 0;
	}
	if(k<2LL){
		cout<<1<<endl;return 0;
	}
	if(a>0){
		rep(i,h-1) rep(j,w){
			if(s[i+1][j]==s[i][j] && s[i][j]=='#') c++;
		}
		cout<<cal(a,t,k,c)<<endl;
	}
	else{
		rep(i,w-1) rep(j,h){
			if(s[j][i+1]==s[j][i] && s[j][i]=='#') c++;
		}
		cout<<cal(b,t,k,c)<<endl;
	}
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define ll long long
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int n, a, b, h[114514];
int mi = 0, ma = 1000000000;
int ans;

signed main() {
	cin >> n >> a >> b;
	rep(i, n)cin >> h[i];
	while (1) {
		int d = (mi + ma) / 2;
		int cnt = 0;
		rep(i, n) {
			cnt += (max((int)0, h[i] - d * b) + (a - b - 1)) / (a - b);
		}
		if (cnt <= d) {
			ans = d;
			ma = d;
		}
		else {
			mi = d;
		}
		if (d == (mi + ma) / 2)break;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
N = int(input())
dict = {}
max = 0 
for _ in range(N):
    s = input()
    if s in dict:
        dict[s] = dict[s] + 1
    else: 
        dict[s] = 1
    if max < dict[s]:
        max = dict[s] 
       
for x in sorted(dict.keys()):
    if dict[x] == max:
        print(x)


Measured memory_bytes: 85592
from sys import stdin
import math

class Vector:
    def __init__(self, x=None, y=None):
        self.x = x
        self.y = y

    def __add__(self, other):
        return Vector(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vector(self.x - other.x, self.y - other.y)

    def __mul__(self, k):
        return Vector(self.x * k, self.y * k)

    def __truediv__(self, k):
        return Vector(self.x / k, self.y / k)

    def __gt__(self, other):
        return self.x > other.x and self.y > other.yb

    def __lt__(self, other):
        return self.x < other.x and self.y < other.yb

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y

    def dot(self, other):
        return self.x * other.x + self.y * other.y

    # usually cross operation return Vector but it returns scalor
    def cross(self, other):
        return self.x * other.y - self.y * other.x

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        return math.sqrt(self.norm())

class Point(Vector):
    def __init__(self, *args, **kargs):
        return super().__init__(*args, **kargs)

class Segment:
    def __init__(self, p1=Point(0, 0), p2=Point(1, 1)):
        self.p1 = p1
        self.p2 = p2

class Line(Segment):
    def __init__(self, *args, **kargs):
        return super().__init__(*args, **kargs)

class Circle:
    def __init__(self, c=Point(0, 0), r=1):
        self.c = c
        self.r = r

def project(s, p):
    base = s.p2 - s.p1
    hypo = p - s.p1
    r = hypo.dot(base) / base.norm()
    return s.p1 + base * r

def get_cross_point(c, l):
    pr = project(l, c.c)
    e = (l.p1- l.p2) / (l.p2 - l.p1).abs()
    base = math.sqrt( c.r * c.r - (pr - c.c).norm() )
    return pr + e * base, pr - e * base

def read_and_print_results(n, c):
    for _ in range(n):
        line = stdin.readline().strip().split()
        p0 = Vector(int(line[0]), int(line[1]))
        p1 = Vector(int(line[2]), int(line[3]))
        l = Line(p0, p1)
        p2, p3 = get_cross_point(c, l)
        x1, y1 = min((p2.x, p2.y), (p3.x, p3.y))
        x2, y2 = max((p2.x, p2.y), (p3.x, p3.y))
        print("{0:0.8f} {1:0.8f} {2:0.8f} {3:0.8f}".format(x1, y1, x2, y2))

x, y, r = [ int(i) for i in input().split() ]
c = Circle(Point(x, y), r)
n = int(input())
read_and_print_results(n, c)


Measured memory_bytes: 5752
import math

n,k = map(int,input().split())

if n>=k:
    pro1 = (n-k+1) / n

    pro2 = 0
    for i in range(1,k):
        tmp_pro = 1 / n
        x = math.log(k/i, 2)
        if x!=int(x):
            x = int(x) + 1
        elif x==int(x):
            x = int(x)
        y = (1/2)**x
        tmp_pro *= y
        pro2 += tmp_pro

    pro = pro1 + pro2

else:
    pro = 0

    for i in range(1,n+1):
        tmp_pro = 1 / n
        x = math.log(k/i, 2)
        if x!=int(x):
            x = int(x) + 1
        elif x==int(x):
            x = int(x)
        y = (1/2)**x
        tmp_pro *= y
        pro += tmp_pro

print(pro)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;

const int N = (int)1e5+5;
int n, a[N];
bool vis[N];

int main() {
	scanf("%d", &n);
	int x = 0;
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), x ^= a[i];
	if (!x) return puts("0"), 0;
	int res = 0;
	for (int i = 30; i >= 0; --i) if ((x >> i) & 1) {
		bool ok = false;
		for (int j = 1; j <= n; ++j)
			if (!vis[j] && (ll)(a[j] ^ (a[j] - 1)) == (1ll << (ll)(i + 1)) - 1ll)
			{ ok = vis[j] = true, x ^= (a[j] ^ (a[j] - 1)), ++res; break; }
		if (!ok) return puts("-1"), 0;
	}
	return printf("%d", res), 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 1000000;
const ll INF = (1LL << 31) - 1;
const double pi=acos(-1);

int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll>a(n);
  rep(i,n)cin >> a[i];
  ll ans=0;
  rep(i,n){
    ll cnt1=0,cnt2=0;
    rep(j,i){
      if(a[j]>a[i]){
        cnt1++;
      }
    }
    rep(j,n){
      if(a[j]>a[i]){
        cnt2++;
      }
    }
    ans+=cnt1*k+(cnt2%MOD)*((k*(k-1)/2)%MOD);
    ans%=MOD;
  }
  
  cout << ans<< endl;
  
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define nyan "(=^･ω･^=)"
using namespace std;

const int mod = 1e9 + 7;
const long long INF = 1LL<<60;
using ll = long long;
using P = pair<int,int>;

// https://qiita.com/1natsu172/items/b951aa33451dad36bd7c
// atcoddr-cli用
// [URL]/tasks_print
// acc new  
// cd 
// cd 
// code -n main.cpp


int main(){
    int A, B, M;
    cin >> A >> B >> M;

    vector<long long> a(A), b(B);
    for (int i = 0; i < A; i++) cin >> a[i];
    for (int i = 0; i < B; i++) cin >> b[i];
    vector<long long> c = a;
    vector<long long> d = b;

    long long ans;

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    ans = a[0] + b[0];
    //cout << ans << endl;
    
    for (int i = 0; i < M; i++){
        long long x, y, C;
        cin >> x >> y >> C;
        x--, y--;
        long long temp = c[x] + d[y] - C;

        ans = min(ans, temp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
import sys
N,M=map(int,input().split())
d=[set()for _ in range(N+1)]
def f(v,h,q):
 if d[v]&q:
  l=[]
  for x in h[::-1]:
   l=[x]+l
   if x in d[v]:break
  L=[]
  while v!=x:
   for y in l:
    if v in d[y]:
     L=[v]+L
     v=y
     break
  print("\n".join(str(x)for x in[len(L)+1,x]+L[::-1]));sys.exit()
 for u in d[v]:f(u,h+[u],q|{u})
for _ in range(M):a,b=map(int,input().split());d[a].add(b)
v=0;exec("v+=1;f(v,[v],{v});"*N)
print(-1)

Measured memory_bytes: 87536
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<iomanip>
#include<map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = 1e9 + 7;
int dx[8] = { 1,0,-1,0,1,1,-1,-1 };
int dy[8] = { 0,1,0,-1,1,-1,1,-1 };

int h, w;
int sy, sx, gy, gx;
int n;
int s[105][105] = { 0 };
int color;

void dfs(int y, int x) {

	s[y][x] = 10;

	for (int i = 0; i < 4; i++) {
		int ny = y + dy[i];
		int nx = x + dx[i];

		if (0 <= ny && ny < h && 0 <= nx && nx < w && s[ny][nx] == color) {
			dfs(ny, nx);
		}
	}

	return;
}



int main() {

	while (cin >> w >> h) {
		if (w == 0)break;


		cin >> sx >> sy >> gx >> gy;
		sx--, sy--, gx--, gy--;

		cin >> n;

		int c[200], d[200], x[200], y[200];

		for (int i = 0; i < n; i++) {
			cin >> c[i] >> d[i] >> x[i] >> y[i];
			x[i]--, y[i]--;
		}

		for (int i = 0; i < n; i++) {
			if (d[i] == 0) {
				for (int j = 0; j < 4; j++) {
					for (int k = 0; k < 2; k++) {
						s[y[i] + k][x[i] + j] = c[i];
					}
				}
			}
			else {
				for (int j = 0; j < 2; j++) {
					for (int k = 0; k < 4; k++) {
						s[y[i] + k][x[i] + j] = c[i];
					}
				}

			}
		}

		color = s[sy][sx];

		dfs(sy, sx);


		

		if (s[gy][gx] == 10) {
			cout << "OK" << endl;
		}

		else {
			cout << "NG" << endl;
		}

		for (int i = 0; i < 105; i++) {
			for (int j = 0; j < 105; j++) {
				s[i][j] = 0;
			}
		}
	}

	return 0;
}



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

int main() {
  int H, W;
  cin >> H >> W;


  // ここにプログラムを追記
  // (ここで"試合結果の表"の2次元配列を宣言)
  vector<vector<char>> a(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>a[i][j];
    }
  }
  vector<bool> b(W,false);
  vector<bool> c(H,false);
  //b
for (int j = 0; j < W; j++) {
  int flag=0;
  for(int i=0;i<H;i++){
    if(a.at(i).at(j)=='#'){flag=1;break;}
  }
  if(flag==1){
    b[j]=true;
    }
  }

for (int i = 0; i < H; i++) {
  int flag=0;
  for(int j=0;j<W;j++){
    if(a.at(i).at(j)=='#'){flag=1;break;}
  }
  if(flag==1){
    c[i]=true;
    }
  }
for(int i=0;i<H;i++){
  if(c[i]){
  for(int j=0;j<W;j++){
    if(b[j]){
      cout<<a[i][j];
    }
  }  
    cout<<endl;
  }

}
  
}


Measured memory_bytes: 256
#include <random>
#include <string>
#include <iostream>
using namespace std;
string s, t;
int main() {
	cin >> s >> t;
	mt19937 mt(1812191250);
	int N = s.size();
	uniform_int_distribution<int> p(0, N - 1);
	bool ok = true;
	for (int i = 0; i < 10000000; ++i) {
		int a = p(mt), b = p(mt);
		if ((s[a] == s[b]) != (t[a] == t[b])) {
			ok = false;
			break;
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 776
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
int main() {
	int n,zen=0;
	cin >> n;
	vector<int>d(n);
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			zen += d[i] * d[j];
		}
	}
	cout << zen << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n, b, r, f,v;
	int oh[4][3][10] = {};
	int i, j, k;
	
	scanf("%d", &n);
	
	while (n--){
		scanf("%d %d %d %d", &b, &r, &f, &v);
		b--;
		r--;
		f--;
		
		oh[b][r][f] += v;
	}
	
	for (i = 0; i < 4; i++){
		for (j = 0; j < 3; j++){
			for (k = 0; k < 10; k++){
				printf(" %d", oh[i][j][k]);
			}
			printf("\n");
		}
		if (i < 3){
			for (j = 0; j < 20; j++){
				printf("#");
			}
			printf("\n");
		}
	}
	
	return 0;
}

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

int main() {
  int n, t = 0, m = 0;
  cin >> n;
  vector<int> h(n);
  for(int i = 0; i < n; i++) {
    cin >> h.at(i);
    if(i) {
      if(h.at(i - 1) >= h.at(i))
        t++;
      else {
        m = max(m, t);
        t = 0;
      }
    }
  }
  cout << max(m, t) << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int count = sc.nextInt();
		boolean flag = false;
		int breakCount = 0;
		int index = 1;
		for(int i=0;i < count;i++) {
			if(index > count) {
				break;
			}
			if(breakCount == count) {
				break;
			}
			if(sc.nextInt() == index) {
				index++;
				flag = true;
				continue;
			}else {
				breakCount++;
				continue;
			}
		}
		if(flag) {
			System.out.println(breakCount);
		}else {
			System.out.println("-1");
		}
	}
}

Measured memory_bytes: 63448
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	long n; cin >> n;
	
	int mi = 1e9;
	for(long i = 1; i * i <= n; i++){
		if(n % i) continue;
		
		std::string s = std::to_string(i);
		std::string w = std::to_string(n / i);
		mi = std::min(mi, std::max<int>(s.size(), w.size()));
	}
	
	cout << mi << endl;
	return 0;
}


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

int main() {
	int N;
	int count = 0;
	cin >> N;
	int a[100];
	for (int i = 0; i < N;i++) {
		cin>>a[i];
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (i!=j) {
				count += a[i] * a[j];
			}
		}
	}
	cout << count/2;
}

Measured memory_bytes: 256
import sys
sum_n,kazu,c=0,0.0,0.0
for line in sys.stdin:
    line=map(int,line.strip().split(","))
    sum_n+=line[0]*line[1]
    kazu+=line[1]
    c+=1
print "{}\n{}".format(sum_n,int(round(kazu/c)))

Measured memory_bytes: 4244
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

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

int main(){
	int h,w;
	cin>>h>>w;
	vector<vector<char>> m(h,vector<char>(w));
	vector<vector<int>> ans(h,vector<int>(w,inf));
	ans[0][0] = 0;
	rep(i,h)rep(j,w)cin>>m[i][j];
	rep(i,h){
		rep(j,w){
			if(j) chmin(ans[i][j], ans[i][j-1] + (m[i][j] != m[i][j-1]));
			if(i) chmin(ans[i][j], ans[i-1][j] + (m[i][j] != m[i-1][j]));
		}
	}
	int res = ans[h-1][w-1];
	if(m[0][0] == '#')++res;
	if(m[h-1][w-1] == '#')++res;
	cout<<res/2<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
using namespace std;

//common
typedef long long i64,ll;

#define BR "\n"
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,r) for(int i=(l);i<(int)(r);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

//debug
#ifdef NDEBUG
#define DUMP(x)
#define DUMPLN(x)
#define DEBUG(x)
#define DEBUGLN(x)
#define LINE()
#define LINELN()
#define CHECK(exp,act)
#define STOP(e)
#else
#define DUMP(x)  cerr << #x << " = " << (x)
#define DUMPLN(x)  DUMP(x) <<endl
#define DEBUG(x) DUMP(x) << LINE() << " " << __FILE__
#define DEBUGLN(x) DEBUG(x)<<endl
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl
#define CHECK(exp,act)  if(exp!=act){DUMPLN(exp);DEBUGLN(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}

template<class T> inline string toString(const vector<vector<T> >& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

string BITtoString(int bit){
    stringstream ss;
    while(bit!=0){ss<<(bit%2);bit/=2;}
    string res=ss.str();reverse(ALL(res));
    return res;
}

template<typename T,typename V> inline T pmod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}

class Main{
public:
	
	void run(){
		int b1,b2,b3;cin >> b1 >> b2 >> b3;
		if(b1&b2&!b3)cout <<"Open"<<endl;
		else if(!b1&!b2&b3)cout <<"Open"<<endl;
		else cout <<"Close"<<endl;
	}
};

 int main(){
	//ios::sync_with_stdio(false);
 	Main().run();
 	return 0;
 }

Measured memory_bytes: 1156
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a == 0 && b == 0) {
				break;
			}
			int tmp;
			if(a > b) {
				tmp = a;
				a = b;
				b = tmp;
			}
			System.out.printf("%d %d\n",a,b) ;
		}

	};
}



Measured memory_bytes: 39416
### ABC107 B - Grid Compression
h, w = map(int, input().split())
grid = [[x for x in str(input())] for _ in range(h)]

del_h = [False] * h
del_w = [False] * w

for i in range(h):
  if grid[i].count('#') == 0:
    del_h[i] = True

for j in range(w):
  del_w[j] = True
  for i in range(h):
    if grid[i][j] == '#':
      del_w[j] = False
      break

for i in range(h):
  if del_h[i]: continue
  row = ''.join([grid[i][j] for j in range(w) if not del_w[j]])
  print(row)


Measured memory_bytes: 3188
n = int(input())
s = list(input())
BITs = [[0]*(n+1) for _ in range(26)]

def c_idx(c):
    return ord(c) - 97

def query(pos):
    ret = [0]*26
    for i in range(26):
        tmp = 0
        p = pos
        while p > 0:
            tmp += BITs[i][p]
            p -= p & (-p)
        ret[i] = tmp
    return ret

def update(pos, a, x):
    while pos <= n:
        BITs[a][pos] += x
        pos += pos & (-pos)

for i in range(n):
    update(i+1, c_idx(s[i]), 1)
#print(BITs)

q = int(input())
for _ in range(q):
    a, b, c = input().split()
    b = int(b)
    if a == "1":
        if s[b-1] == c:
            continue
        update(b, c_idx(s[b-1]), -1)
        update(b, c_idx(c), 1)
        s[b-1] = c
    else:
        c = int(c)
        count1 = query(c)
        count2 = query(b-1)
        ans = 0
        for i in range(26):
            if count1[i] - count2[i] > 0:
                ans += 1
        print(ans)

Measured memory_bytes: 204304
fun main(args: Array<String>) {
    var (L, R) = listOfLong()
    R = Math.min(R, L + 2019)
    var ans = Long.MAX_VALUE
    for (i in L .. R-1) {
        for (j in i+1 .. R) {
            ans = Math.min(ans, (i * j) % 2019)
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong(delta: Long = 0L) = listOfString().map { it.toLong() + delta }


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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

typedef long long ll;

int main(){
  ios::sync_with_stdio(0), cin.tie(0);
  
  int n;  cin >> n;
  unordered_map<int, int> cnt1, cnt2;
  ll ans = 0;
  for (int i = 0; i < n; ++i){
    int ai; cin >> ai;
    int one = i-ai, two = i+ai;
    ans += cnt2[one] + cnt1[two];
    cnt1[one]++, cnt2[two]++;
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 34040
from itertools import accumulate
from bisect import bisect_left, bisect_right

n = int(input())
a = list(map(int, input().split()))

ts = list(accumulate(a))+[0]
r = 0

def calc(st, ed):
    t0 = ts[ed-1] - ts[st-1]
    i1 = bisect_left(ts, (ts[ed-1]+ts[st-1])/2, st+1, ed-1)
    t11 = ts[i1-1] - ts[st-1]
    t12 = t0 - t11
    t21 = ts[i1] - ts[st-1]
    t22 = t0 - t21
    if abs(t22-t21) > abs(t12-t11):
        return t11, t12
    else:
        return t21, t22

ans = 10**18
for i in range(2, n-1):
    r1, r2 = calc(0, i)
    r3, r4 = calc(i, n)
    # print(r1, r2, r3, r4)
    diff = max([r1, r2, r3, r4]) - min([r1, r2, r3, r4])
    ans = min(ans, diff)

print(ans)
    



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

int main(){
  int M, D;
  cin >> M >> D;
  int Ans=0;
  for(int i=1; i<=M; i++){
    for(int j=1; j<=D; j++){
      int D10=j/10;
      int D1=j-10*D10;
      if(D10>=2 && D1>=2 && D10*D1==i){
        Ans++;
      }
    }
  }
  cout << Ans << endl;
}

Measured memory_bytes: 256