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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    ll N, M; cin >> N >> M;
    if (N == 1 && M == 1) cout << 1 << endl;
    else if (N == 1) cout << M - 2 << endl;
    else if (M == 1) cout << N - 2 << endl;
    else if (N == 2 || M == 2) cout << 0 << endl;
    else cout << N * M - (ll)(max(N, M) - 2) * (ll)2 - (ll)min(N, M) * (ll)2 << endl;
    return 0;
}

Measured memory_bytes: 3576
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //
const long infty = 1_000_000_000_000_000_100;
void solve(){
	int n = read.to!int;
	
	long[] as;
	foreach(i; 0 .. n) as ~= read.to!long;
	
	long[long[4]] memo;
	long calc(long x, long y, int l, int r){
		if(l + 1 == r) return 0;
//		else if([x, y, l, r] !in memo){
			long res = infty;
			foreach(i; l + 1 .. r){
				long temp = calc(x, x + y, l, i) + (x + y) * as[i] + calc(x + y, y, i, r);
				log("l:", l, "r:", r, "i:", i, "temp:", temp);
				res = min(res, temp);
//			}
//			memo[[x, y, l, r]] = res;
		}
//		else log("Found in memo.");
//		log("x:", x, "y:", y, "l:", l, "r:", r, "res:", memo[[x, y, l, r]]);
//		return memo[[x, y, l, r]];
	return res;
	}
	
	
	long ans = as[0] + calc(1, 1, 0, n - 1) + as[n - 1];
	
	ans.writeln;
}



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

using namespace std;
int a[26];
int main()
{
    int i,n,sum=0,x;
    char s[100];
    cin >> n;
    scanf("%s",s);
    for(i=0;i<n;i++)
    {
        ++a[s[i]-97];
    }
    for(i=0;i<26;i++)
    {
        x=a[i];
        x/=2;
        x*=2;
        sum+=x;
    }
    if(sum==n)
        cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 3760
H,W = list(map(int,input().split()))
A = [list(input()) for _ in range(H)]

q = []
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i,j))
            A[i][j] = 0
ans = 0
k = 0
while k < len(q):
    i,j = q[k]
    v = A[i][j]
    if i>0 and A[i-1][j]==".":
        A[i-1][j] = v + 1
        q.append((i-1,j))
        ans = max(ans,v+1)
    if i<H-1 and A[i+1][j]==".":
        A[i+1][j] = v + 1
        q.append((i+1,j))
        ans = max(ans,v+1)
    if j>0 and A[i][j-1]==".":
        A[i][j-1] = v + 1
        q.append((i,j-1))
        ans = max(ans,v+1)
    if j<W-1 and A[i][j+1]==".":
        A[i][j+1] = v + 1
        q.append((i,j+1))
        ans = max(ans,v+1)
    k += 1
print(ans)

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

using namespace std;

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

    string s, t;
    cin >> s >> t;
    int n = s.length();

    for (int sh = 0; sh < n; sh++) {
        bool ok = true;
        for (int i = 0; i < n; i++) {
            if (s[i] != t[(i+sh)%n]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a;
	b = a / 3600;
	c = (a % 3600) / 60;
	d = a % 60;
	cout << b << ":" << c << ":" << d << endl;
}


Measured memory_bytes: 3104
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

int main(){

    ll N;
    cin >> N;

    map<ll, ll > mp;
    mp[0]++;

    for(ll i = 0; i < N; i++){
        ll t; cin >> t;
        vector<ll > tmp;
        auto begin = mp.begin(), end = mp.end();
        for (auto iter = begin; iter != end; iter++) {
            tmp.push_back(iter->first);
            tmp.push_back(iter->first + t);
        }
        
        for(ll j = 0; j < tmp.size(); j++){
            mp[tmp[j]]++;
        }
    }

    ll ans = 0;
    auto begin = mp.begin(), end = mp.end();
    for (auto iter = begin; iter != end; iter++) {
        if(iter->first % 10 != 0){
            ans = max(ans, iter->first);
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 964
using System;

namespace JKTX_AOJ2015
{
    class Program
    {
        delegate int cuberaise(int val);
        static void Main(string[] args)
        {
            cuberaise cube = val => val * val * val;

            int value = int.Parse(Console.ReadLine());

            Console.WriteLine(cube(value));
        }
    }
}

Measured memory_bytes: 5600
//====================== Author Info ===================
//    Khaled Alam (Ninjo)   ~   khaledalam.net@gmail.com
//======================================================
#include <bits/stdc++.h>
using namespace std;
#define  sz           size()
#define  fi           first
#define  se           second
#define  mp           make_pair
#define  pb           push_back
#define  ll           long long int
#define  ones         __builtin_popcount
#define  all(a)       (a).begin(), (a).end()
#define  iFile(a)     freopen(#a, "r", stdin)
#define  oFile(a)     freopen(#a, "w", stdout)
#define  rep(i,a,z)   for(auto i=(a);i<(z);i++)
#define  ios          ios_base::sync_with_stdio(false)
#define  tm           fprintf(stderr,"%.3f s\n",(float)clock()/1000);

int main() {
	//iFile(input.txt);

	long long a[3];
			cin>>a[0]>>a[1]>>a[2];
			if((a[0]%2==0)||(a[1]%2==0)||(a[2]%2==0))
			{
				cout<<0<<"\n";
				return 0;
			}
			sort(a,a+3);
			long long sum1=a[0]*a[1];
			cout<<sum1<<"\n";


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n;cin>>n;
  vi d(n);
  rep(i,n)cin>>d[i];
  rvisort(d);
  int ans=0;
  int now=101;
  rep(i,n){
    if(now<=d[i])continue;
    now=d[i];
    ans++;
  }
  cout(ans);
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;
int main(){
    int p,q,r;
    cin >> p >> q >> r;
    cout<<min({(p+q),(q+r),(r+p)})<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n;cin>>n;
  int x=log2(n);
  int ans=1<<x;
  cout(ans);
  return 0;
}

Measured memory_bytes: 256
/**************************
  * Writer : Leo101
  * Problem : AT2567 RGB Sequence
  * Tags : Dp
**************************/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#define File(s) freopen(#s".in", "r", stdin); freopen(#s".out", "w", stdout)
#define gi get_int()
const int MOD = 1e9 + 7, Max_N = 302;
int get_int()
{
	int x = 0, y = 1; char ch = getchar();
	while ((ch < '0' || ch > '9') && ch != '-')
		ch = getchar();
	if (ch == '-') y = -1,ch = getchar();
	while (ch <= '9' && ch >= '0') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * y;
}

int Dp[Max_N][Max_N][Max_N], l[Max_N], r[Max_N], x[Max_N];
std :: vector<int> Lim[Max_N];

int main()
{
	int n = gi, m = gi;
	for (int i = 1; i <= m; i++) {
		l[i] = gi, r[i] = gi, x[i] = gi;
		Lim[r[i]].push_back(i);
	}

	Dp[0][0][0] = 1;

	long long Ans = 0;

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (i == j && j != 0) continue;
			for (int k = 0; k <= n; k++) {
				if (k != 0 && (i == k || j == k)) continue;
				int Max = std :: max({i, j, k});
				bool Flag = false;
				for (auto it = Lim[Max].begin(); it != Lim[Max].end(); it++) {
					int Count = 0;
					if (l[*it] <= i) Count++;
					if (l[*it] <= j) Count++;
					if (l[*it] <= k) Count++;
					if (Count != x[*it]) {
						Flag = true;
						break;
					}
				}
				if (Flag == true) continue;
				Dp[Max + 1][j][k] = (Dp[Max + 1][j][k] + Dp[i][j][k]) % MOD;
				Dp[i][Max + 1][k] = (Dp[i][Max + 1][k] + Dp[i][j][k]) % MOD;
				Dp[i][j][Max + 1] = (Dp[i][j][Max + 1] + Dp[i][j][k]) % MOD;
				if (Max == n) Ans = (Ans + Dp[i][j][k]) % MOD;
			}
		}
	}

	printf("%lld", Ans);

	return 0;
}


Measured memory_bytes: 107904
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-6;
const int MOD = 1000000007;

int main(){
	double D;
	while(cin>>D,D){
		double px,py,vx,vy;
		cin>>px>>py>>vx>>vy;
		// (-px,-py) (vx, vy)
		if(abs((-px) * vy - (-py) * vx) < 1e-6){
			double d;
			assert(abs((-px)*vx+(-py)*vy) > EPS);
			if(-px * vx + (-py) * vy > -EPS){
				d = sqrt(px*px + py*py);
			}else{
				d = 2.0 - sqrt(px*px + py*py);
			}
			if(d < D + 1e-6){
				printf("%0.6lf\n", d);
			}else{
				cout<<"impossible"<<endl;
			}
		}else{
			cout<<"impossible"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 3
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	s := getNextString(scanner)
	n := len(s)
	c := 0
	for i := 0; i < n; i++ {
		if s[i] == 'C' {
			c++
			continue
		}
		if s[i] == 'F' && c > 0 {
			fmt.Fprintln(writer, "Yes")
			return
		}
	}
	fmt.Fprintln(writer, "No")
}


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



int main()
{
    int a,b;
    cin>>a>>b;
    cout << (a - 1) * (b - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
mfr = []
while True:
    a, b, c = map(int, input().split())
    if a == -1 and b == -1 and c == -1:
        break
    mfr.append([a, b, c])
res = []
for i in range(len(mfr)):
    tmp = mfr[i][0]+mfr[i][1]
    if mfr[i][0] == -1 or mfr[i][1] == -1:
        res.append('F')
    elif tmp >= 80:
        res.append('A')

    elif 65 <= tmp and tmp < 80:
        res.append('B')

    elif 50 <= tmp and tmp < 65:
        res.append('C')

    elif 30 <= tmp and tmp < 50:
        if 50 <= mfr[i][2]:
            res.append('C')
        else:
            res.append('D')

    elif tmp < 30:
        res.append('F')


for i in range(len(res)):
    print(res[i])    


Measured memory_bytes: 5608
private fun readInts() = readLine()!!.split(" ").map(String::toInt)

private val MOD = 1000000007
private val NOT_YET = -1

fun main(args: Array<String>) {
    val (N, M) = readInts()
    val a = (0 until M).map { readLine()!!.toInt() - 1 } // 0-indexed

    if (N == 1) {
        println(1)
        return
    }

    val ways = Array(N) { NOT_YET }
    for (hole in a) ways[hole] = 0

    if (ways[0] == NOT_YET) ways[0] = 1
    if (ways[1] == NOT_YET) ways[1] = ways[0] + 1

    for (position in 2 until N) {
        if (ways[position] == NOT_YET) {
            ways[position] = (ways[position - 1] + ways[position - 2]) % MOD
        }
    }

    println(ways.last())
}


Measured memory_bytes: 41416
<?php
# 数値の入力
fscanf(STDIN, "%s", $data1);
$array = str_split($data1);
$anser = 'Yes';

for($i=0; $i<count($array); $i++){
    if($i%2==0 and $array[$i]=='L'){
        $anser = 'No';
    }elseif($i%2==1 and $array[$i]=='R'){
        $anser = 'No';
    }else{

    }
}
echo $anser;
?>

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;


int main() {
    int n;
    cin >> n;
    vector<int> balls(n);
    rep(i, n) cin >> balls[i];

    map<int, ll> counts;
    for (int b : balls) counts[b]++;

    ll all = 0;
    for (auto e : counts) {
        all += (e.second * (e.second - 1) / 2);
    }

    for (int i : balls) {
        if (counts.find(i) == counts.end()) {
            cout << all << endl;
            continue;
        }
        ll count = counts[i];
        if (count == 1) {
            cout << all << endl;
            continue;
        }
        ll origi = count * (count - 1) / 2;
        ll next = (count - 1) * (count - 2) / 2;
        ll sub = origi - next;
        cout << all - sub << endl;
    }


}





Measured memory_bytes: 10240
defmodule Main do
  def main() do
    {_, d} = input()
    pile_up(d)
    |> IO.puts()
  end

  def input() do
    n =
      IO.gets("")
      |> String.trim()
      |> String.to_integer()
    d =
      for _ <- 1..n do
         IO.gets("")
         |> String.trim()
         |> String.to_integer()
      end
    {n, d}
  end

  def pile_up(d) when is_list(d) do
    Enum.uniq(d)
    |> Enum.count()
  end
end


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

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

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

  while (n--){
    int k, p;
    cin >> k >> p;
    cout << (k % p == 0 ? p : k % p) << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm> 
using namespace std;



int main() {
	string a, b;
	cin >> a >> b;
	if (a[0] < b[0]) {
		cout << "<" << endl;
	}
	else if (a[0] > b[0]) {
		cout << ">"<<endl;
	}
	else {
		cout << "=" << endl;
	}



	return 0;
}


Measured memory_bytes: 256
def main():
    n, a, b = map(int, input().split())
    if b < (n-1)//a+1 or n-a+1 < b:
        print(-1)
        return 0
    for i in range((n-1)//a+1, n-a+2):
        cnt_a = (i-(n-1)//a)
        cnt_b = b-cnt_a-1
        length = n-cnt_a*a-cnt_b
        if length <= a:
            break
    j = n+1
    ans = []
    for i in range(cnt_a):
        j -= a
        ans += list(range(j, j+a))
    if cnt_b >= 0:
        j -= length
        ans += list(range(j, j+length))+list(range(j-1, 0, -1))
    print(*ans)


main()


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

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
using namespace std;
using ll = long long;
using lld = long long;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

ll gcd(ll a, ll b)
{
  if (a < b)
  {
    return gcd(b, a);
  }
  while (b != 0)
  {
    ll tmp = b;
    b = a % b;
    a = tmp;
  }
  return a;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  ll N;
  cin >> N;
  vector<ll> A(N);

  loop(0, N, i) {
    cin >> A[i];
  }

  ll MOD = 1e9+7;
  vector<ll> B(N);
  B[N-1] = A[N-1];
  for(ll i=N-2; i>=0; --i) {
    B[i] = (A[i] + B[i+1]) % MOD;
  }

  ll sum = 0;
  loop(0, N-1, i) {
    ll m = A[i] * B[i+1];
    sum += m;
    sum %= MOD;
  }
  print(sum);

}

Measured memory_bytes: 6268
S = input()
N = len(S)

for i in range(2**(N-1)):
    tmp = int(S[0])
    sentence = S[0]

    for j in range(N-1):
        flag = (i >> j) & 1

        if flag: # +の場合
            tmp += int(S[j+1])
            sentence += "+" + S[j+1]
        else:
            tmp -= int(S[j+1])
            sentence += "-" + S[j+1]

    if tmp == 7:
        print(sentence + "=7")
        exit()


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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

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

  ll n;
  cin >> n;
  vvP lst(n);
  rep(i, n){
    ll ai;
    cin >> ai;
    rep(j, ai){
      ll x, y;
      cin >> x >> y;
      x--;
      lst[i].emplace_back(x, y);
    }
  }

  ll ans = 0;
  rep(s, 1 << n){
    bool ok = true;
    rep(i, n) {
      if(((s >> i) & 1) == 0) continue;
      rep(j, (ll)lst[i].size()){
        ll x, y;
        tie(x, y) = lst[i][j];
        if(((s >> x) & 1) == y){
          // do nothing
        } else {
          ok = false;
          break;
        }
      }
    }
    if(ok) chmax(ans, (ll)__builtin_popcountll(s));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3592
def burger(i)
  if i == 0
    'P'
  else
    'B' + burger(i-1) + 'P' + burger(i-1) + 'B'
  end
end

def burger_num(level, x)
  return 1 if level == 0
  if @hb.has_key?(level)
    return @hb[level][0..x-1].count('P')
  end

  prev_level_size = @h[level-1]
  if x == 0
    0
  elsif x == prev_level_size + 2
    burger_num(level-1, prev_level_size) + 1
  elsif x == @h[level]
    burger_num(level-1, prev_level_size) * 2 + 1
  elsif x < prev_level_size + 2
    burger_num(level-1, x-1)
  else
    burger_num(level-1, prev_level_size) + 1 + burger_num(level-1, x-2-prev_level_size)
  end
end

n, x = gets.split.map(&:to_i)
q = 1
@h = {0=>q}
@hb = {0=>'P'}
(1..n).each do |i|
  q = 3 + q*2
  @h[i] = q
  @hb[i] = burger(i) if i < 15
end

puts burger_num(n, x)

Measured memory_bytes: 14732
n = int(input())
a = list(map(int, input().split()))
a.sort()
l = a[-1]
def bigger(ind):
    global a, n, l
    if a[ind] > l / 2:
        return True
    else:
        return False
top = n
bottom = -1
while top - bottom > 1:
    mid = (top + bottom) // 2
    if bigger(mid):
        top = mid
    else:
        bottom = mid
if a[top] + a[bottom]> l or a[top] == l:
    print(l, a[bottom])
else:
    print(l, a[top])

Measured memory_bytes: 19948
n, H = map(int, input().split())
a = []
b = []
for i in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)

ans = 0
amax = max(a)
b.sort(reverse=True)
# print(amax, b)
i = 0
while H > 0:
    if i < n:
        if amax < b[i]:
            H -= b[i]
            ans += 1
            i += 1
        else:
            ans += H//amax
            if H%amax != 0:
                ans += 1
            break
    else:
        ans += H//amax
        if H % amax != 0:
            ans += 1
        break

print(ans)


Measured memory_bytes: 17172
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int n; cin >> n;
  vector<int> a(100009,0), b(100009,0);
  int v;
  rep(i,n){
    cin >> v;
    if (i%2) b[v]++;
    else a[v]++;
  }
  
  ll retval;
  int argmax_a = max_element(all(a)) - a.begin();
  int argmax_b = max_element(all(b)) - b.begin();
  if (argmax_a!=argmax_b) retval = n - a[argmax_a] - b[argmax_b];
  else {
    sort(all(a), greater<int>());
    sort(all(b), greater<int>());
    retval = min(n-a[0]-b[1],n-a[1]-b[0]);
  }

  cout <<retval << endl;

  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 4052
import sys
from itertools import starmap
readline = sys.stdin.readline
class Segment(object):
    __slots__ = ('fi', 'se')
    def __init__(self, fi, se):
        self.fi = fi
        self.se = se
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
def norm(base):
    return abs(base) ** 2
def project(s, p2):
    base = s.fi - s.se
    r = dot(p2 - s.fi, base) / norm(base)
    return s.fi + base * r
s = Segment(*list(starmap(complex, zip(*[map(int, readline().split())] * 2))))
n = int(readline())
for _ in [0] * n:
    p2 = complex(*map(float, readline().split()))
    ap = project(s, p2)
    print(ap.real, ap.imag)

Measured memory_bytes: 7924
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int[] points = new int[5];
    int distance = 0;

    for (int i = 0; i < points.length; i++) {
      points[i] = sc.nextInt();
    }
    int upper = sc.nextInt();

    loop: for (int i = 0; i < 5; i++) {
      for (int n = 0; n < 5; n++) {
        distance = points[n] - points[i];
        if (distance > upper) {
          System.out.println(":(");
          break loop;
        }
      }
      if (i == 4) {
        System.out.println("Yay!");
      }
    }
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
bool solve(){
    int arr[100001]={0};
    int N,K;
    scanf("%d%d",&N,&K);
    if(N==0&&K==0)return false;
    for(int i=0;i<N;i++){
        scanf("%d",&arr[i+1]);
        arr[i+1]+=arr[i];
    }
    int ma=INT_MIN;
    for(int i=0;i+K<=N;i++){
        ma=max(ma,arr[i+K]-arr[i]);
    }
    printf("%d\n",ma);
    return true;
}

int main(){
    while(solve());
}

Measured memory_bytes: 1584
#include <iostream>
using namespace std;
#define MAX_N 300000
int pl[MAX_N+2];
char ip[MAX_N+2];
int p=0;

main(){
	int i,n=300000;
	for(i=0;i<=n;i++)ip[i] = 1;
	ip[0]=ip[1]=0;
	for(i=2;i<=n;i++){
		if(i%7!=1&&i%7!=6) ip[i]=0;
		if(ip[i]){
			for(int j=2*i;j<=n;j+=i) ip[j]=0;
			pl[p++] = i;
		}
	}
	while(cin>>n, n!=1){
		printf("%d:", n);
		for(i=0;i<p;i++)if(!(n%pl[i])) printf(" %d", pl[i]);
		puts("");
	}
}

Measured memory_bytes: 1308
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
signed main() {
    int x=0,y=0,z=0,w=0,n=0,m=0;
cin>>x>>y>>z;
if(z>=x&&z<=y)cout << "Yes";
else cout << "No";
}



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

int main() {
  int N;
  cin >> N;
  vector<string> Poll(N);
  for (int i = 0; i < N; i++) cin >> Poll[i];
  int cnt = 1;
  vector<pair<int, string>> res;
  sort(Poll.begin(), Poll.end());
  for (int i = 0; i < N-1; i++) {
    if (Poll[i] == Poll[i+1]) cnt++;
    else {
      res.push_back({cnt, Poll[i]});
      cnt = 1;
    }
  }
  res.push_back({cnt, Poll[N-1]});
  sort(res.begin(), res.end());
  int num = res.size()-1;
  for (int i = res.size()-1; i > 0; i--) {
    if (res[i].first == res[i-1].first) num--;
    else break;
  }
  for (int i = num; i < res.size(); i++) cout << res[i].second << endl;
}


Measured memory_bytes: 19908
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define pi pair<int,int>
#define mp make_pair
#define el cout<<'\n'
#define rc(s) return cout<<s,0
//#define cin fin
//#define cout fout
using namespace std;

#define inf 1000000000

//ifstream fin("input.in");
//ofstream fout("input.out");

const int mod=1e9+7;

int n,m,d[1005][1005],viz[1005][1005];
queue<pi>q;
char a[1005][1005];

void ver(int x,int y){
    if(x-1>=1 && viz[x-1][y]==0){ viz[x-1][y]=1; q.push({x-1,y}); d[x-1][y]=d[x][y]+1;}
    if(x+1<=n && viz[x+1][y]==0){ viz[x+1][y]=1; q.push({x+1,y}); d[x+1][y]=d[x][y]+1;}
    if(y-1>=1 && viz[x][y-1]==0){ viz[x][y-1]=1; q.push({x,y-1}); d[x][y-1]=d[x][y]+1;}
    if(y+1<=m && viz[x][y+1]==0){ viz[x][y+1]=1; q.push({x,y+1}); d[x][y+1]=d[x][y]+1;}
}

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie();cout.tie();
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> a[i][j];
            if(a[i][j]=='#') {q.push({i,j}); viz[i][j]=1;}
        }
    }
    while(!q.empty()){
        int x=q.front().fr;
        int y=q.front().sc;
        ver(x,y);
        q.pop();
    }
    int maxi=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(maxi<d[i][j]) maxi=d[i][j];
        }
    }
    rc(maxi);
}

Measured memory_bytes: 26896
m=10**9+7
i=s=r=f=1
p=input
p()
a=p().split()
for x in a:r+=int(x)*~-s+int(a[-i])*s;f=f*i%m;i+=1;s+=pow(i,m-2,m)
print(~-r*f%m)


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

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

 long long a, b, n;
 cin >> a >> b >> n;

 long long x;
 if(n<b) x = n;
 else x = b-1;

 long long ans = (a*x)/b - a*(x/b);
 cout << ans << "\n";

}


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;

namespace AizuOnlineJudge {
    class Program {
        static void Main() {
            var list = new LinkedList<string>();
            for (var i = int.Parse(Console.ReadLine()); i > 0; --i) {
                var line = Console.ReadLine().Split();
                switch (line[0]) {
                    case "insert":
                        list.AddFirst(line[1]);
                        break;

                    case "delete":
                        list.Remove(line[1]);
                        break;

                    case "deleteFirst":
                        list.RemoveFirst();
                        break;

                    case "deleteLast":
                        list.RemoveLast();
                        break;
                }
            }

            Console.WriteLine(string.Join(" ", list));
        }
    }
}



Measured memory_bytes: 120912
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
map<string,int> mp,mp1;
int main() {
	int n, m;
	string s;
	cin >> n;
	while(n--) {
		cin >> s;
		mp[s]++;
	}
	cin >> m;
	while(m--) {
		cin >> s;
		mp1[s]++;
	}
	int MAX = 0;
	map<string,int>::iterator it = mp.begin();
	for(; it != mp.end(); it++) {
		MAX = max(MAX,(*it).second-mp1[(*it).first]);
	}
	cout << MAX << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INF 999999999
using namespace std;

int main(){
          int n,m;
          cin >> n >> m;
          int a[n],b[n];
          REP(i,n) cin >> a[i] >> b[i];
          int c[m],d[m];
          REP(i,m) cin >> c[i] >> d[i];

          REP(i,n){
                    int ans=INF;
                    int fin=0;
                    REP(j,m){
                              int now=abs(a[i]-c[j])+abs(b[i]-d[j]);
                              if (now<ans) ans = now, fin = j;
                    }
                    cout << fin+1 << endl;
          }
          return 0;
}


Measured memory_bytes: 256
def main():
    N = input()
    right = int(N[-1])
    if right in [2, 4, 5, 7, 9]:
        print("hon")
    elif right in [0, 1, 6, 8]:
        print("pon")
    else:
        print("bon")

if __name__ == "__main__":
    main()

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

Measured memory_bytes: 1720
# -*- coding: utf-8 -*-
# 157c
n, m = map(int, input().split())
s = []
c = []
for _ in range(m):
  _s, _c = input().split()
  s.append(int(_s))
  c.append(_c)

ret = -1
for i in range(1000):
  x = str(i)
  if len(x) != n:
    continue
  isOk = True
  for _s, _c in zip(s, c):
    if len(x) < _s or x[_s - 1] != _c:
      isOk = False
      break
  if isOk:
    ret = i
    break
print(ret)


Measured memory_bytes: 3064
#include <iostream>
 
using namespace std;
 
int main() {
  int n;
  cin >> n;
  string s[n];
  int m[n][26] = {};
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; s[i][j] != '\0'; j++) {
      m[i][s[i][j] - 'a']++;
    }
  }
  for (int i = 0; i < 26; i++) {
    int cn = 50;
    for (int j = 0; j < n; j++) {
      cn = min(cn, m[j][i]);
    }
    cout << string(cn, i + 'a');
  }
  cout << endl;
  return 0;
}

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

int main() {
    int n;
    cin>>n;
    n%=10;
    if(n==3){
        cout << "bon" <<endl;
    }else if(n==0 or n==1 or n==6 or n==8){
        cout << "pon" <<endl;
    }else{
        cout << "hon" <<endl;
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
#define REP(i,x,n) for(int i=x; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()

int main(){
  int n;
  cin >> n;
  vd a(n);
  rep(i,n)  cin >> a[i];

  double p=a[0];
  REP(i,1,n){
    p= (p*a[i])/(p+a[i]);
  }
  cout << p << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if (a%3==0 || b%3==0 || (a+b)%3==0){
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
int main(void)
{
  int n,m,c=0,cm=0;
  double j;
  int a[100];
  for(int i=0;i<100;i++)
    a[i]=0;
  scanf("%d %d",&n,&m);
  for(int i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
    c=c+a[i];
  }
  j=c/(4.0*m);
  for(int i=0;i<n;i++)
  {
    if(a[i]>=j)
      cm++;
  }
  if(cm>=m)
    printf("Yes");
  else
    printf("No");
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define maxn 200010
char str[maxn];
int n,a,b,c,d,i;
int main()
{
	scanf("%d%d%d%d%d%s",&n,&a,&b,&c,&d,str+1);
	for (i=a;i<c;i++)
		if ((str[i]=='#') && (str[i+1]=='#'))
		{
			printf("No\n");
			return 0;
		}
	for (i=b;i<d;i++)
		if ((str[i]=='#') && (str[i+1]=='#'))
		{
			printf("No\n");
			return 0;
		}
	if (c>d)
	{
		for (i=b;i<=d;i++)
			if ((str[i-1]=='.') && (str[i]=='.') && (str[i+1]=='.')) break;
		if (i>d)
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 384
H,W = gets.split.map(&:to_i)
puts (0...H).map{ gets.chomp }
  .reject{ |n| n.match(/^\.+$/) }
  .map{ |n| n.split("") }
  .transpose
  .map{ |ns| ns.join("") }
  .reject{ |n| n.match(/^\.+$/) }
  .map{ |n| n.split("") }
  .transpose
  .map{ |ns| ns.join }


Measured memory_bytes: 2940
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    string S; cin >> S;
    int N = S.size();

    int ng = 0, np = 0;
    int ans = 0;
    REP(i,N){
        if (S[i]=='g') {
            if (ng > np) {
                np++;
                ans++;
            } else ng++;
        } else {
            if (ng > np) np++;
            else {
                ng++;
                ans--;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(void){
  long a,b;

  scanf("%ld%ld",&a,&b);
  if(a<=0 && b>=0)  printf("Zero\n");
  else if(a<0 && b<0){
    if((b-a+1)%2==0)  printf("Positive\n");
    else printf("Negative\n");
  }  else printf("Positive\n");

  return 0;
}


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

int main(){
	int n,lank,s[13],h[13],c[13],d[13];
	string suit;

	for(int i=0;i<13;i++){
		s[i]=0;
		h[i]=0;
		c[i]=0;
		d[i]=0;
	}

	cin >> n;
	for (int i=0;i<n;i++){
		cin >> suit >> lank;
		if(suit=="S"){
			s[lank-1]=1;
		}else if(suit=="H"){
			h[lank-1]=1;
		}else if(suit=="C"){
			c[lank-1]=1;
		}else if(suit=="D"){
			d[lank-1]=1;
		}
	}
	
	for (int i=0;i<13;i++){
		if(s[i]==0){
			cout << "S " << i+1 << endl;
		}
	}
	for (int i=0;i<13;i++){
		if(h[i]==0){
			cout << "H " << i+1 << endl;
		}
	}
	for (int i=0;i<13;i++){
		if(c[i]==0){
			cout << "C " << i+1 << endl;
		}
	}
	for (int i=0;i<13;i++){
		if(d[i]==0){
			cout << "D " << i+1 << endl;
		}
	}

}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K;
  cin>>K;
queue<int64_t>que;
  for(int i=1;i<=9;i++)
    que.push(i);
  for(int i=0;i<K-1;i++){
    int64_t x=que.front();
    que.pop();
    if(x%10==0){
     que.push(10*x);
      que.push(10*x+1);
    }else if(x%10==9){
    que.push(10*x+8);
      que.push(10*x+9);
    }else{
    que.push(10*x+(x%10)-1);
       que.push(10*x+(x%10));
       que.push(10*x+(x%10)+1);
    }
    
  }int64_t ans=que.front();
  cout<<ans<<endl;
  
   return 0;
}

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

int main(){
    int N,M; cin >> N >> M;
    vector <p> P(M);
    rep(i,M) cin >> P[i].first >> P[i].second;
    
    rep(i,1000){
        string S=to_string(i);
        int keta=S.length();
        if (keta!=N) continue;
        
        bool ok=true;
        rep(i,M){
            if(S[P[i].first-1]!=P[i].second+'0') ok=false;
        }
        
        if(ok){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}

//最小公倍数ダヨン
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

bool root(string s){
    int n=s.length();
    if(n==2){
        if(s[0]==s[1]){
            return true;
        }
        else return false;
    }
    if(n==3){
        if(s[0]==s[2]){
            return true;
        }
        else return false;
    }
 
    return false;
}
 

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

    while(1){
        n-=1000;
        if(n==0){
            cout<<0<<endl;
            return 0;
        }else if(n<0){
            cout<<abs(n)<<endl;
            return 0;
        }
    }
}   

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define N 2010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)  for(int i = n - 1; i >= 0; --i)
#define forr1(i, n) for(int i = n; i >= 1; --i)
#define form(l, r, i)   for(int i = l; i <= r; ++i)
#define forv(r, l, i)   for(int i = r; i >= l; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
  
const int inf = 1e9 + 7;
const lld EPS = 0.00000001;
const ll modw = 1e9 + 9;
  
using namespace std;

vector<int> v[N];
int ans[N];

void bfs(int x)
{
	int dis[N];
	forn(i, N)	dis[i] = -1;
	dis[x] = 0;
	queue<int> q;
	q.push(x);
	while(!q.empty())
	{
		int u = q.front();
		q.pop();
		for(auto i:v[u])
		{
			if(dis[i] == -1)
			{
				dis[i] = dis[u] + 1;
				q.push(i);
			}
		}
	}
	forn(i, N)	if(dis[i] != -1)	ans[dis[i]]++;
}

int main()
{
    barnarnar
    int n, x, y;
    cin >> n >> x >> y;
    forn1(i, n - 1)
    {
    	v[i].pb(i + 1);
    	v[i + 1].pb(i);
	}
	v[x].pb(y);
	v[y].pb(x);
	forn1(i, n)	bfs(i);
	forn1(i, n - 1)
	{
		cout << ans[i] / 2 << endl;
	}
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdlib.h>
#include<cmath>
using namespace std;

int main(){
 int N,D,X,Y;
 cin >> N >> D;

 int count=0;
 for(int i=0; i<N; i++){
   cin >>X >> Y;

   if( D >= sqrt(pow(X,2)+pow(Y,2)) ){
     count += 1;
   }

 }

cout<<count<<endl;
return 0;
}


Measured memory_bytes: 3160
import java.util.Scanner;
import java.util.ArrayList;
import java.util.HashMap;
import java.lang.Integer;
import java.lang.StringBuilder;
import java.lang.Math;

public class Main {
  private static char[] DREAMER = new String("dreamer").toCharArray();
  private static char[] DREAM = new String("dream").toCharArray();
  private static char[] ERASE = new String("erase").toCharArray();
  private static char[] ERASER = new String("eraser").toCharArray();

  private static boolean startsWith(char[] s, char[] target, int current) {
    int i = 0;
    while (current + i < target.length && i < s.length) {
      if (s[i] != target[current + i]) {
        return false;
      }

      i++;
    }

    return i == s.length;
  }

  public static boolean isDayDreamInternal(char[] s, int current) {
    if (current == s.length) return true;
    if (current >= s.length - 4) return false;

    if (startsWith(DREAMER, s, current)) {
      if (isDayDreamInternal(s, current + 7)) {
        return true;
      }
    }

    if (startsWith(ERASER, s, current)) {
      if (isDayDreamInternal(s, current + 6)) {
        return true;
      }
    }

    if (startsWith(ERASE, s, current) || startsWith(DREAM, s, current)) {
      if (isDayDreamInternal(s, current + 5)) {
        return true;
      }
    }

    return false;
  }

  public static boolean isDayDream(char[] s) {
    return isDayDreamInternal(s, 0);
  }

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    char[] s = in.next().toCharArray();

    boolean result = isDayDream(s);

    if (result) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
    //System.out.println(s.substring(s.length()));
  }
}

Measured memory_bytes: 14960
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::input;
use std::collections::*;

fn prime_factorization<T: num::PrimInt>(x: T) -> std::collections::BTreeMap<T, i64> {
    let zero = T::zero();
    let one = T::one();
    let two = one + one;
    let three = two + one;
    (std::iter::once(two).chain(num::iter::range_step_inclusive(three, x, two)))
        .scan(x, |state, i| {
            if *state == T::one() {
                None
            } else {
                let divisor = if i * i <= *state { i } else { *state };
                let mut index = 0;
                while *state % divisor == zero {
                    *state = *state / divisor;
                    index += 1;
                }
                Some((divisor, index))
            }
        })
        .filter(|&(_, index)| index > 0)
        .collect()
}

fn main() {
    input! {
        n:i64
    }
    let ans: i64 = prime_factorization(n)
        .iter()
        .map(|(_, &index)| {
            (1..)
                .take_while(|&i| index >= i * (i + 1) / 2)
                .last()
                .unwrap()
        })
        .sum();
    println!("{}", ans);
}

Measured memory_bytes: 2200
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    boolean j1 = false;
    boolean j2 = false;
    boolean j3 = false;
    boolean j4 = false;
    
    int len = s.length();
    if(len%2 == 1){
      j1 = true;
    }

    for(int i = 0 ; i < len/2 ; ++i){
      if(s.charAt(i) == s.charAt(len-1-i)){
        j2 = true;
      }else{
        j2 = false;
        break;
      }
    }
    for(int i = 0 ; i < len/2 ; ++i){
      if(s.charAt(i) == s.charAt(((len-1)/2)-1-i)){
        j3 = true;
      }else{
        j3 = false;
        break;
      }
    }
    for(int i = 0 ; i < len/2 ; ++i){
      if(s.charAt((len+3)/2-1+i) == s.charAt(len-1-i)){
        j4 = true;
      }else{
        j4 = false;
        break;
      }
    }

    if(j1&&j2&&j3&&j4){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }

  }
}

Measured memory_bytes: 35584
#include <cstdio>
#include <complex>

using namespace std;

#define MAX_N 100

typedef complex<double> P;
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))

double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}

int side(P start, P end, P point) {
  double arg = cross(end - start, point - start);
  if (arg > 0) return 1;  // left
  if (arg < 0) return -1; // right
  return 0; // center
}

int n;
P p[MAX_N];

int next_vertex(int start_index) {
  for (int i = 0; i < n; ++i) {
    if (start_index == i) continue;
    bool right = false;
    for (int j = 0; j < n; ++j) {
      if (i == j) continue;
      if (side(p[start_index], p[i], p[j]) == -1) right = true;
    }
    if (!right) return i;
  }
  return start_index;
}

int main() {
  while (1) {
    scanf("%d\n", &n);
    if (!n) break;
    
    for (int i = 0; i < n; ++i) {
      double x, y;
      scanf("%lf,%lf\n", &x, &y);
      p[i] = P(x, y);
    }
    
    int pm = 0;
    for (int i = 0; i < n; ++i) {
      if (p[pm].real() > p[i].real()) pm = i;
    }
    
    int start = pm;
    int current = next_vertex(start);
    int count = 1;
    
    while (start != current) {
      current = next_vertex(current);
      count++;
    }
    printf("%d\n", n - count);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

static const int mod = 1000000007;

int main(void){
    int n;
    cin >> n;
    vector<ll> a(n);

    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
        sum %= mod;
    }

    ll ans = 0;
    for(int i = 0; i < n; i++){
        sum -= a[i];
        if(sum < 0) sum += mod;
        ans += a[i] * sum;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4844