akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int w, h;
		while ((w = in.nextInt()) != 0 && (h = in.nextInt()) != 0) {
			int xs = in.nextInt();
			int ys = in.nextInt();
			int xg = in.nextInt();
			int yg = in.nextInt();
			char[][] b = new char[200][200];
			int n = in.nextInt();
			while (n-- > 0) {
				setBlock(b, in.next().charAt(0), in.nextInt(), in.nextInt(),
						in.nextInt());
			}
			String ans;
			if (b[xs][ys] == b[xg][yg] && b[xs][ys] != '0') {
				solid(b, b[xs][ys], xs, ys, xg, yg);
				ans = b[xs][ys] == b[xg][yg] ? "OK" : "NG";
			} else {
				ans = "NG";
			}
			System.out.println(ans);
		}

	}

	public static void setBlock(char[][] b, char c, int d, int x, int y) {
		b[x][y] = b[x + 1][y] = b[x][y + 1] = b[x + 1][y + 1] = c;
		if (d == -1) {
			return;
		} else if (d == 0) {
			setBlock(b, c, -1, x + 2, y);
		} else if (d == 1) {
			setBlock(b, c, -1, x, y + 2);
		}
	}

	public static void solid(char[][] b, char c, int x, int y, int xg, int yg) {
		if (b[x][y] == c) {
			b[x][y] = '*';
			if (x == xg && y == yg) {
				return;
			}
			solid(b, c, x + 1, y, xg, yg);
			solid(b, c, x - 1, y, xg, yg);
			solid(b, c, x, y + 1, xg, yg);
			solid(b, c, x, y - 1, xg, yg);
		}
	}
}

Measured memory_bytes: 24280
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n;
    scanf("%d", &n);
    
    int f[10001]={0};
    
    for(int x=1;x<100;x++){
      for(int y=1;y<100;y++){
     for(int z=1;z<100;z++){
        if(x*x+y*y+z*z+x*y+y*z+z*x<10001){
            f[x*x+y*y+z*z+x*y+y*z+z*x]++;
        }
    }   
    }  
    }
    
    for(int i=1;i<=n;i++){
       printf("%d\n",f[i]);
    }
}


Measured memory_bytes: 1752
#include <stdio.h>

int board[10][10];

int main(void)
{
    int i, j, size, x, y, count = 0, max = 0;
    int dx[12] = {-1, 0, 1, 0, -1, -1, 1, 1, -2, 0, 2, 0};
    int dy[12] = {0, 1, 0, -1, 1, -1, 1, -1, 0, -2, 0, 2};
    for (i = 0; i < 10; i++) {
        for (j = 0; j < 10; j++) {
            board[i][j] = 0;
        }
    }
    while (scanf("%d,%d,%d", &x, &y, &size) != EOF) {
        board[x][y]++;
        if (size == 1) {
            for (i = 0; i < 4; i++) {
                if (0 <= x + dx[i] && x + dx[i] < 10 
                        && 0 <= y + dy[i] && y + dy[i] < 10) {
                    board[x+dx[i]][y+dy[i]]++;
                }
            }
        } else if (size == 2) {
            for (i = 0; i < 8; i++) {
                if (0 <= x + dx[i] && x + dx[i] < 10 
                        && 0 <= y + dy[i] && y + dy[i] < 10) {
                    board[x+dx[i]][y+dy[i]]++;
                }
            }
        } else if (size == 3) {
            for (i = 0; i < 12; i++) {
                if (0 <= x + dx[i] && x + dx[i] < 10 
                        && 0 <= y + dy[i] && y + dy[i] < 10) {
                    board[x+dx[i]][y+dy[i]]++;
                }
            }
        }
    }
    for (i = 0; i < 10; i++) {
        for (j = 0; j < 10; j++) {
            if (!board[i][j]) {
                count++;
            }
            if (board[i][j] > max) {
                max = board[i][j];
            }
        }
    }
    printf("%d\n%d\n", count, max);
    return 0;
}

Measured memory_bytes: 600
// 
// 
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(),(x).end()
#define outl(x) cout<<x<<endl
#define outsp(x) cout<<x<<" "
typedef long long ll;
typedef pair<int,int> P;


#define MAX_N 1000000005


int main() {
	string s;
	int k;
	cin >> k;
	cin >> s;
	if(s.size()<=k){
		outl(s);
	}else{
		outl(s.substr(0,k) + "...");
	}

    return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

vector<i64> strongly_connected_components(const vector<vector<i64>>& g) {
  i64 n = g.size();
  vector<vector<i64>> rg(n);
  for(int i = 0;i < n;i++) {
    for(auto j: g[i]) {
      rg[j].push_back(i);
    }
  }

  vector<bool> vis(n,false);
  vector<i64> vs;
  vector<i64> res(n,-1);
  function<void(int)> dfs = [&](int v) {
    vis[v] = true;
    for(auto& t : g[v]) {
      if(!vis[t]) dfs(t);
    }
    vs.push_back(v);
  };

  function<void(int,int)> rdfs = [&](int v,int k) {
    vis[v] = true;
    res[v] = k;
    for(auto to : rg[v]) {
      if(!vis[to]) rdfs(to,k);
    }
  };

  for(int i = 0;i < n;i++) {
    if(!vis[i]) dfs(i);
  }

  vis.assign(n,false);
  int k = 0;
  for(int i = n - 1;i >= 0;i--) {
    if(!vis[vs[i]]) rdfs(vs[i] , k++);
  }
  return res;
}

int main() {
  i64 N;
  cin >> N;
  vector<i64> a(N);
  rep(i,0,N) cin >> a[i];

  vector<vector<i64>> g(N);
  i64 ans = 0;
  rep(i,0,N) {
    g[i].push_back((i + a[i]) % N);
    if(i == (i + a[i]) % N) { ans++; }
  }
  auto res = strongly_connected_components(g);
  map<i64, i64> mp;
  for(auto x: res) {
    mp[x]++;
  }
  for(auto p: mp) {
    if(p.second >= 2) {
      ans += p.second;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 22600
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s, a, b;   cin >> s;
    int q;  cin >> q;
    int c = 1, t, f;

    for (int i = 0; i < q; i++) {
        cin >> t;
        if (t == 1)
            c *= -1;
        else {
            char h; cin >> f >> h;
            if (c == 1 && f == 1) {
                a.push_back(h);
            }
            else if (c == 1 && f == 2) {
                b.push_back(h);
            }
            else if (c == -1 && f == 1) {
                b.push_back(h);
            }
            else {
                a.push_back(h);
            }
        }
    }

    if (c == 1) {
        int al = a.length() - 1;
        for (int i = al; i >= 0; i--)
            cout << a[i];
        cout << s << b << endl;
    }

    else {
        int bl = b.length() - 1;
        for (int i = bl; i >= 0; i--)
            cout << b[i];
        for (int i = s.length() -1; i >= 0; i--)
            cout << s[i];
        cout << a << endl;
    }

    return 0;
}

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

int n, m;
int p[1005][1005] = {0};

int solve();

int main() {
  while(1) {
    cin >> n >> m;
    if(n + m == 0) break;
    for(int i = 0; i < m; ++i)
      for(int j = 0; j < n; ++j) cin >> p[i][j];
    cout << solve() << endl;
  }
  return 0;
}

int solve() {
  int ans = 0;
  for(int i = 0; i < n; ++i) {
    int now = 0;
    for(int j = 0; j < m; ++j) now += p[j][i];
    ans = max(now, ans);
  }
  return ans;
}


Measured memory_bytes: 3304
#[allow(unused_imports)]
use std::collections::HashSet;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

//use lazy_static::lazy_static;

//lazy_static! {
//    static ref MOD :usize = 10usize.pow(9) + 7;
//}

use std::collections::HashMap;

static MOD: usize = 1000_000_007;

fn main() {
    let l: Vec<char> = read::<String>().chars().collect::<Vec<char>>();

    let mut pow3: HashMap<usize, usize> = HashMap::new();
    
    prepare(&l, &mut pow3);
    let answer = solve(&l, &pow3);
    println!("{}", answer);
}

fn prepare(l: &[char], m3: &mut HashMap<usize, usize>) {
    let n = l.len();
    let mut pos_of_one = n - 1;
    let mut x3 = 1;

    m3.insert(0, 1);

    for i in (0..n).rev() {
        if l[i] == '0' {
            continue;
        }

        let r = pos_of_one - i;
        for j in 0..r {
            x3 = x3 * 3 % MOD;
        }
        m3.insert(n-i - 1, x3);
        pos_of_one = i;
        //println!("m3 {}, {}", r, x3);
    }
}

fn solve(l: &[char], m3: &HashMap<usize, usize>) -> usize {
    let n = l.len();

    let mut count = 0;
    let mut c1 = 0;
    for i in 0..n {
        if l[i] == '0' {
            continue;
        }
        let remaining = n - i - 1;
        if c1 == 0 {
            c1 = 1;
        } else {
            c1 = c1 * 2 % MOD;
        }
        
        let c2 = m3[&remaining];
        let c3 = c1 * c2 % MOD;

        count = (count + c3) % MOD;
    }
    c1 = c1 * 2 % MOD;
    count = (count + c1) % MOD;
    return count;
}

Measured memory_bytes: 12540
import java.util.LinkedList;
import java.util.Scanner;
import java.util.ArrayList;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] array = new int[n][2];
        for (int i  = 0; i < n; i++){
            array[i][0] = sc.nextInt();
            array[i][1] = sc.nextInt();
        }

        int result = 0;
        for (int i = 0; i < n; i++){
            double temp = Math.sqrt(Math.pow(array[i][0],2) + Math.pow(array[i][1], 2));
            if (temp <= d){
                result ++;
            }
        }
        System.out.println(result);

    }
}


Measured memory_bytes: 64948
N, K = map(int, input().split())
A = list(map(int, input().split()))

# import random
# N = 100
# K = 10**5
# A = [K] * N

if sum(A) < K:
  print(0)
  exit(0)

t0 = [0] * (K+1)
t0[0] = 1

M = 10**9 + 7
for i in range(N):
    a = A[i]
    t1 = [0] * (K+1)
    st0 = [0]
    for t in t0:
        st0.append((t + st0[-1]) % M)
    for k in range(K+1):
        l = max(0, k-a)
        t1[k] = (st0[k+1] - st0[l]) % M
    t0 = t1

print(t0[K])


Measured memory_bytes: 123784
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s;
	cin >> s;
	if (s == "SAT")cout << 1 << endl;
	if (s == "FRI")cout << 2 << endl;
	if (s == "THU")cout << 3 << endl;
	if (s == "WED")cout << 4 << endl;
	if (s == "TUE")cout << 5 << endl;
	if (s == "MON")cout << 6 << endl;
	if (s == "SUN")cout << 7 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main(void) {
    u64 N, D;
    cin >> N >> D;

    u64 ans = 0;

    for(u64 i=0; i<N; i++) {
        s64 X, Y;
        cin >> X >> Y;

        if(X*X + Y*Y <= D*D) {
            ans++;
        }
    }

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

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r1 = ReadSplit();
            var n = r1[0].Int();
            var k = r1[1].Int();
            var l = new int[n];
            for (int i = 0; i < k; i++)
            {
                var d = Read().Int();
                var r2 = ReadSplit();
                for (int j = 0; j < d; j++)
                {
                    var a = r2[j].Int();
                    l[a - 1] = 1;
                }
            }
            WriteRead(l.Where(x => x == 0).Count());
        }
        
        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 19288
import copy

n = int(input())
x = list(map(int,input().split()))
lst = copy.deepcopy(x)
lst.sort()
med_l = lst[n//2-1]
med_r = lst[n//2]

for i in range(len(x)):
    if x[i]<=med_l: print(med_r)
    else: print(med_l)

Measured memory_bytes: 26864
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

int main(int argc, char** argv) {
  int n;
  cin >> n;
  int d[n];
  rep(i, n) {
    cin >> d[i];
  }

  sort(d, d + n);
  int left = d[(n/2) - 1];
  int right = d[(n/2)];

  cout << right - left;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] A = new long[n + 1];
		long[] B = new long[n];
		for (int i = 0; i < A.length; i++) {
			A[i] = sc.nextLong();
		}
		for (int i = 0; i < B.length; i++) {
			B[i] = sc.nextLong();
		}
		long ans = 0;
		for (int i = 0; i < B.length; i++) {
			if (B[i] > A[i]) {
				ans += A[i];
				long diff = B[i] - A[i];
				if (diff > A[i + 1]) {
					ans += A[i + 1];
					A[i + 1] = 0;
				} else {
					A[i + 1] -= diff;
					ans += diff;
				}

			} else {
				ans += B[i];
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 89012
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const int INF = 1 << 25;
const LL MOD = 1000000007LL;
using namespace std;
typedef pair<int, int> P;
vector<int> pos[26];
int main() {
	string s;
	cin >> s;
	rep(i, s.size()) {
		pos[s[i] - 'a'].push_back(i);
	}
	rep(i, 26) {
		for (int j = 0; j+1 < pos[i].size(); j++) {
			if (pos[i][j + 1] - pos[i][j] <= 2) {
				cout << (pos[i][j] + 1) << " " << (pos[i][j + 1] + 1) << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1" << endl;
}

Measured memory_bytes: 1148
<?php
fscanf(STDIN, '%d %d', $k, $x);
$ran = $k - 1;
$min = $x - $ran;
$max = $x + $ran;
$answer = [];
for ($i=$min; $i <= $max; $i++) { 
    $answer[] = $i;
}
echo implode(' ', $answer);

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

int array[11],cnt,ans,data[11];
map<int,int>m;

void dfs(int n){
  if(n == 10){
    //    cout << "n = " << n << endl;
    int modulo = (array[0] + array[1] + array[2]) % array[9];
    int sum = 0,rcd = 0;

    //row
    for(int i=1; i<=9; i++){
      sum += array[i-1];
      if(i % 3 == 0){
	if(sum % array[9] == modulo)rcd++;
	else return;
	sum = 0;
      }
    }

    sum = 0;
    //column
    for(int i=0; i<3; i++){
      for(int j=i; j<9; j+=3){
	sum += array[j];
      }
      if(sum % array[9] == modulo) rcd++;
      else return;
      sum = 0;
    }

    //diagonal
    if((array[0] + array[4] + array[8]) % array[9] == modulo) rcd++;
    else return;

    if((array[2] + array[4] + array[6]) % array[9] == modulo) rcd++;
    else return;


    if(rcd == 8){
     
      /*       for(int i=0; i<9; i++){
	cout << array[i];
	if((i+1) % 3 == 0) cout << endl;
      }
      cout << endl;
      */
      ans++;
      }
    return;
  }

  for(int i=0; i<10; i++){
    map<int,int>::iterator it = m.begin();
    if(!array[i]){
      for(it=m.begin(); it != m.end(); it++){
	if(it->second == 1){
	  m[it->first] = 0;
	  array[i] = it->first;
	  dfs(n+1);
	  m[it->first] = 1;
	  array[i] = 0;
	}
      }
      return;
    }
  }
 
}

int main(){
  while(1){
    m.clear();
    ans = 0;
    cnt = 0;
    fill(array,array+11,0);
    fill(data,data+11,0);
    int sum = 0;

    for(int i=1; i<=10; i++){
      m[i] = 1;
    }

    for(int i=0; i<10; i++){
      cin >> array[i];
      sum += array[i];
      m[array[i]] = 0;
      if(array[i] != 0) cnt++;
    }
    if(sum == -10)break;

    dfs(cnt);

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

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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

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

  int mx = (n-1)*(n-2)/2 ;
  if (mx < k) {
    puts("-1");
    return 0;
  }
  vector<P> ans;
  rep(i, n-1) {
    ans.push_back(P(i+1, n));
  }
  int add = mx-k;
  vector<P> edge;
  rep(i, n-1) rep(j, i) edge.push_back(P(i+1, j+1));
  rep(i, add) ans.push_back((edge[i]));
  cout << ans.size() << endl;
  rep(i, ans.size()) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}


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

int main() {
    int s;
    scanf("%d", &s);
    int a[10000000];
    a[s] = 1;
    int pref = s, now;
    for (int i = 2; i <= 10000000; i++) {
        if ((pref % 2) == 0) {
            now = pref / 2;
        } else {
            now = pref * 3 + 1;
        }
        if (a[now] == 1) {
            printf("%d\n", i);
            break;
        } else {
            a[now] = 1;
//            printf("%d %d\n", pref, now);
            pref = now;
        }
    }
    return 0;
}

Measured memory_bytes: 256
var input= require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.split(" ").map(Number);
var a=arr[0];
var b=arr[1];
var c=arr[2];
var tasu=0;
for(var i=a;i<=b;i++){
   if(c%i===0)tasu++;
}
console.log(tasu);

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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}


ll gcd(ll a, ll b) {
    return b != 0 ? gcd(b, a % b) : a;
}

signed main() {
    //my-code
    ll K; cin >> K;
    ll ans = 0;
    REPS(i, 1, K+1) REPS(j, 1, K+1) REPS(k, 1, K+1) {
        ans += gcd(i, gcd(j, k));
    }

    cout << ans << endl;

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

Measured memory_bytes: 3652
from collections import deque
s = map(str,input().split())
stack = deque([])
for i in s:
    if i == "+" or i == "-" or i == "*":
        stack.append(i)
    else:
        stack.append(int(i))
ans = deque([])
while stack:
    p = stack.popleft()
    if p == "+":
        p_1 = ans.pop()
        p_2 = ans.pop()
        ans.append(p_1+p_2)
    elif p == "*":
        p_1 = ans.pop()
        p_2 = ans.pop()
        ans.append(p_1*p_2)
    elif p == "-":
        p_1 = ans.pop()
        p_2 = ans.pop()
        ans.append(p_2 - p_1)
    else:
        ans.append(p)
print(*ans)


Measured memory_bytes: 6000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main {

    public static void main(String[] args) throws IOException {
        ReaderC.init(System.in);
        int n = ReaderC.nextInt();
        System.out.println(0);
        System.out.flush();
        String gLeft = ReaderC.next();
        if (gLeft.equals("Vacant")) return;
        System.out.println(n - 1);
        System.out.flush();
        String gRight = ReaderC.next();
        if (gRight.equals("Vacant"))return;
        query(0, n - 1, gLeft, gRight);
    }

    private static void query(int l, int r, String genderLeft, String genderRight) throws IOException {
        int m = (r + l)/2;
        boolean matchLeft = false;
        boolean matchRight = false;
        if (m % 2 == l % 2) matchLeft = true;
        if (m % 2 == r % 2) matchRight = true;
        System.out.println(m);
        System.out.flush();
        String g = ReaderC.next();
        if (g.equals("Vacant")) return;
//        System.out.println(matchLeft + " " + matchRight + " " + g + " " + genderLeft + " " + genderRight);
        if (matchLeft && !genderLeft.equals(g) || !matchLeft && genderLeft.equals(g)) query(l, m, genderLeft, g);
        else if (matchRight && !genderRight.equals(g) || !matchRight && genderRight.equals(g)) query(m, r, g, genderRight);
    }
}

/**
 * Reader class based on the article at "https://www.cpe.ku.ac.th/~jim/java-io.html"
 */
class ReaderC {
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    static void init(InputStream inputStream) {
        reader = new BufferedReader(new InputStreamReader(inputStream));
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

//    //    Get a whole line.
//    static String line() throws IOException {
//        return reader.readLine();
//    }
//
//    static double nextDouble() throws IOException {
//        return Double.parseDouble(next());
//    }
}



Measured memory_bytes: 22180
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;

struct BinaryIndexedTree
{
  vector< int64 > data;
  int curr;
  
  BinaryIndexedTree(int sz)
  {
    data.assign(++sz, 0);
    curr = 1;
    while(curr < data.size()) curr <<= 1;
  }
  inline int64 sum(int k)
  {
    int64 ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return(ret);
  }
  inline int upper_bound(int64 w)
  {
    int i = 0;
    for(int k = curr; k > 0; k >>= 1) {
      if(i + k < data.size() && data[i + k] <= w) {
        w -= data[i + k];
        i += k;
      }
    }
    return(i);
  }
  inline void add(int k, int64 x)
  {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
 
int N, Q;
int X[200000], D[200000], L[200000];
char buff[32];

int main()
{
  fgets(buff, sizeof(buff), stdin);
  sscanf(buff, "%d %d", &N, &Q);
  for(int i = 0; i < Q; i++) {
    fgets(buff, sizeof(buff), stdin);
    sscanf(buff, "%d %d %d", &X[i], &D[i], &L[i]);
  }
  BinaryIndexedTree xpy(N), xmy(N);
  for(int i = 0; i < N; i++) {
    xpy.add(i, 1);
    xmy.add(i, 1);
  }
  for(int i = Q - 1; i >= 0; i--) {
    if(D[i] == 1) {
      xmy.add(0, -L[i] * 2);
      xmy.add(xpy.upper_bound(X[i]), L[i] * 2);
    } else {
      xpy.add(xmy.upper_bound(X[i]), L[i] * 2);
    }
  }
  for(int i = 0; i < N; i++) {
    printf("%lld\n", (xpy.sum(i) - xmy.sum(i)) / 2);
  }
}

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

struct Man {
	int g, s, b; };

using i64 = long long;

vector<Man> v;
vector<i64> sum_st, sum_dr, best_st, best_dr;

int men, gold, silver, bronze;

int main() {
#ifdef HOME
	freopen("agc18c.in", "r", stdin);
	freopen("agc18c.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	multiset<i64> poper;
	i64 ant(0), sum(0);

	cin >> gold >> silver >> bronze;
	men = gold + silver + bronze;

	v.resize(men), sum_st.resize(men), sum_dr.resize(men);
	for (auto &i: v)
		cin >> i.g >> i.s >> i.b;

	sort(begin(v), end(v), [&](Man a, Man b) {
		return (a.g - a.s) > (b.g - b.s); });

	for (int i = 0; i < men; ++i)
		sum_st[i] = (i ? sum_st[i - 1] : 0) + v[i].b;
	for (int i = men - 1; i >= 0; --i)
		sum_dr[i] = (i == men - 1 ? 0 : sum_dr[i + 1]) + v[i].b;

	best_st = sum_st;
	best_dr = sum_dr;

	for (int i = 0; i < gold; ++i) {
		poper.insert(v[i].g - v[i].b);
		sum+= v[i].g - v[i].b; }
	best_st[gold - 1]+= sum;
	for (int i = gold; i < men; ++i) {
		poper.insert(v[i].g - v[i].b);
		sum+= v[i].g - v[i].b;
		sum-= *poper.begin();
		poper.erase(poper.begin());
		best_st[i]+= sum; }

	poper.clear();
	sum = 0;
	
	for (int i = men - 1; i >= men - silver; --i) {
		poper.insert(v[i].s - v[i].b);
		sum+= v[i].s - v[i].b; }
	best_dr[men - silver]+= sum;
	for (int i = men - silver - 1; i >= 0; --i) {
		poper.insert(v[i].s - v[i].b);
		sum+= v[i].s - v[i].b;
		sum-= *poper.begin();
		poper.erase(poper.begin());
		best_dr[i]+= sum; }

	for (int i = gold - 1; i < men - silver; ++i)
		ant = max(ant, best_st[i] + best_dr[i + 1]);

	cout << ant << endl;

	return 0; }


Measured memory_bytes: 8960
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#include <algorithm>
using namespace std;

int main(void){
    
    int x;
    cin>>x;
    
    vector<int> a;
    a.push_back(1);
    for(int i=2; i<sqrt(1000); i++){
        
        int j=2;
        int temp;
        while(1){
            temp=pow(i, j);
            if(temp<=1000){
                a.push_back(temp);
                j++;
            }else{
                break;
            }
        }
    }
    
    sort(a.begin(), a.end());
    a.push_back(1001);
    
    for(int i=1; i<a.size(); i++){
        if(a[i-1]<=x&&a[i]>x){
            cout<<a[i-1]<<endl;
            break;
        }
    }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
string a,b,c;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>a>>b>>c;
    if(b[0]==a[a.length()-1] && c[0]==b[b.length()-1])puts("YES");
    else puts("NO");
    return 0
    ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N,C,K;cin>>N>>C>>K;
  vector<long>T(N);for(int i=0;i<N;i++)cin>>T[i];
  sort(T.begin(),T.end());
  
  long ans=1;long c=C-1;long next=T[0]+K;
  for(long i=1;i<N;i++){
    //乗り切れるか
    if(c>0 && T[i]<=next && next-T[i]<=K)c--;
    else {
      c=C-1;
      next=T[i]+K;
      ans++;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 1024
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
field = [[0 for j in range(w)] for i in range(h)]
#[y, x]
d = [[0, 1], [1, 0], [0, -1], [-1, 0]]
y, x = 0, 0
if h == 1 and w == 1:
    print(1)
else:
    for i in range(n):
        cnt = a[i]
        while cnt > 0:
            for j in range(len(d)):
                if 0 <= y + d[j][0] and y + d[j][0] < h and 0 <= x + d[j][1] and x + d[j][1] < w:
                    if field[y+d[j][0]][x+d[j][1]] == 0: 
                        dy, dx = d[j][0], d[j][1]
                        break
            field[y][x] = i+1
            y += dy
            x += dx
            cnt -= 1
    for i in range(h):
        for j in range(w):
            print(field[i][j], end=' ')
        print()

Measured memory_bytes: 46440
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;

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

const ll INF = 1e15;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int H, W;
char A[1010][1010];

int bfs() {
	int ret = 0;
	queue<PP> que;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (A[i][j] == '#') {
				que.push({ { i,j }, 0 });
			}
		}
	}

	while (!que.empty()) {
		PP now = que.front(); que.pop();
		int x = now.first.first, y = now.first.second, depth = now.second;
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i], ny = y + dy[i];
			if (0 <= nx && nx < H && 0 <= ny && ny < W && A[nx][ny] == '.') {
				A[nx][ny] = '#';
				que.push({ { nx,ny }, depth + 1 });
				ret = depth + 1;
			}
		}
	}
	return ret;
}


int main(void) {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A[i][j];
		}
	}
	cout << bfs() << endl;
}


Measured memory_bytes: 13328
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int m1, d1;
    int m2, d2;
    cin >> m1 >> d1;
    cin >> m2 >> d2;
    if (m1!=m2){
        cout << '1' << endl;
    }else{
        cout << '0' << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int h, w, d;
	cin >> h >> w >> d;
	vector<pair<int, int>> v(h*w);
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			int a;
			cin >> a;
			a--;
			v[a] = { i,j };
		}
	}
	vector<vector<pair<int, int>>> k(d);
	for (int i = 0; i < h*w; ++i) {
		k[i%d].push_back(v[i]);
	}
	
	vector<vector<long long >> ac(d);
	for (int i = 0; i < d; ++i) {
		ac[i].resize(k[i].size() + 1);
		ac[i][0] = 0;
		for (int j = 0; j < k[i].size() - 1; ++j) {
			ac[i][j + 1] = ac[i][j] + abs(k[i][j + 1].first - k[i][j].first) + abs(k[i][j + 1].second - k[i][j].second);
		}
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		int l, r;
		cin >> l >> r;
		
		l--; r--;
		int c = l % d;
		cout << ac[c][r / d] - ac[c][l / d] << endl;
	}

}


Measured memory_bytes: 11008
#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;
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
 
int main()
{
	int n, m;
	cin >> n >> m;
	int a[n];
	int current = 0;
	REP(i, n) cin >> a[i];

	REP(i, m){
		REP(j, n-1){
			int tmp1 = a[j] % (i+1);
			int tmp2 = a[j+1] % (i+1);
			if (tmp1 > tmp2){
				int tmp = a[j];
				a[j] = a[j+1];
				a[j+1] = tmp;
			}
		}
	}

	for (auto x : a) cout << x << endl;

}



Measured memory_bytes: 3120
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
   int n, k;
   cin >> n >> k;
   vector<int> d(k);
   vector<int> s(n, 0);
   rep(i, k){
      cin >> d.at(i);
      rep(j, d.at(i)){
         int tmp;
         cin >> tmp;  
         tmp--;
         s.at(tmp)++;
      }
   }

   int cnt = 0;
   rep(i, n){
      if(s.at(i)==0){
         cnt++;
      }
   }

   cout << cnt << endl;
   return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;


int main() {
	ll A, B;
	cin >> A >> B;
	if ((A == 1 && B == 2) || (A == 2 && B == 1)) cout << 3 << endl;
	else if ((A == 2 && B == 3) || (A == 3 && B == 2)) cout << 1 << endl;
	else cout << 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  ll w,h;cin>>w>>h;
  ll i,j,k;
  ll p[w],q[h];
  priority_queue<P,vector<P>,greater<P> > qu;
  ll ans=0;
  for(i=0;i<w;i++){
    cin>>p[i];
    qu.push(P(p[i],0));
  }
  for(i=0;i<h;i++){
    cin>>q[i];
    qu.push(P(q[i],1));
  }
  while(!qu.empty()){
    P p=qu.top();qu.pop();
    if(p.second){
      ans+=p.first*(w+1);
      h--;
    }else{
      ans+=p.first*(h+1);
      w--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5488
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <list>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/

bool check(vector<char>t, vector<char>d, int m, int q, string s) {
	int x = m;
	bool ok = false;
	rep(i, q) {
		if (t[i] == s[x]) {
			if (d[i] == 'L') x--;
			else x++;
		}
		if (x < 0) {
			ok = true;
			break;
		}
	}
	return ok;
}

bool checkR(vector<char>t, vector<char>d, int m, int q, string s) {
	int x = m;
	bool ok = false;
	rep(i, q) {
		if (t[i] == s[x]) {
			if (d[i] == 'L') x--;
			else x++;
		}
		if (x >= (int)s.size()) {
			ok = true;
			break;
		}
	}
	return ok;
}

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

	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<char>t(q), d(q);
	rep(i, q) cin >> t[i] >> d[i];

	// 2分探索で境界線を探す
	int left = 0;
	int right = n - 1;
	int mid = (left + right) / 2;

	while (left <= right) {
		// mid番目のマスが条件を満たすか考える
		bool ok = check(t, d, mid, q, s);
		if (!ok) {
			// もっと左のやつを試す
			right = mid - 1;
			mid = (left + right) / 2;
		}
		else {
			left = mid + 1;
			mid = (left + right) / 2;
		}
	}

	// 正確な位置を探す
	if (check(t, d, mid, q, s)) {
		// 一つ右を見る
		if (mid < n - 1) {
			if (check(t, d, mid + 1, q, s)) mid++;
		}
	}
	else {
		mid--;
	}

	// 右から見る
	left = 0; right = n - 1;
	int midR = (left + right) / 2;
	while (left <= right) {
		// mid番目のマスが条件を満たすか考える
		bool ok = checkR(t, d, midR, q, s);
		if (ok) {
			// もっと左のやつを試す
			right = midR - 1;
			midR = (left + right) / 2;
		}
		else {
			left = midR + 1;
			midR = (left + right) / 2;
		}
	}

	// 正確な位置を探す
	if (checkR(t, d, midR, q, s)) {
		// 一つ左を見る
		if (midR > 0) {
			if (checkR(t, d, midR + 1, q, s)) midR--;
		}
	}
	else {
		midR++;
	}

	//cout << mid << " " << midR << endl;

	if (mid >= midR) cout << 0 << endl;
	else cout << midR - mid - 1 << endl;

	return 0;
}


Measured memory_bytes: 1556
N = int(input())
C=[]
S=[]
F=[]
for i in range(N-1):
    c,s,f=[int(i) for i in input().split()]
    C.append(c)
    S.append(s)
    F.append(f)
# print(C)
# print(S)
# print(F)

ans=[]
#i駅からの出発
for i in range(N-1):
    time=0
    #j->j+1への移動
    for j in range(i,N-1):
        #電車に乗る時刻を決める
        #始発より早く着いたら始発に合わせる
        if time<S[j]:
            time=S[j]
        else:
            if time%F[j]!=0:
                time+=(F[j]-time%F[j])
        #次の駅に着く時刻を決める
        time+=C[j]
    ans.append(time)
# print(ans)

for i in ans:
    print(i)
print(0)


Measured memory_bytes: 3188
#include <stdio.h>

int main(){
    int i;
    double a, s;
    
    while(scanf("%lf", &a) != EOF){
        s = 0;
        
        for(i = 0; i < 10; ++i){
            s += a;
            a  = i % 2 == 0 ? a * 2 : a / 3;
        }
        
        printf("%.8f\n", s);
    }
    
    return 0;
}



Measured memory_bytes: 1984
n = gets.to_i
s = gets.chomp

total_r = s.count('R')
num_w = 0
num_r = 0
ans = 10**9
(n+1).times do |i|
  left_w = num_w
  right_r = total_r - num_r
  ans = [ans, [left_w, right_r].max].min
  unless i == n
    if s[i] == 'W'
      num_w += 1
    else
      num_r += 1
    end
  end
end

puts ans

Measured memory_bytes: 14780
#include<bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
string s,ans;
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>s;
	ans="";
	for(int i=0;i<sz(s);i++){
		if(s[i]!='B') ans+=s[i];
		else if(sz(ans)) ans=ans.substr(0,sz(ans)-1);
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
     
#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair
     
using namespace std;
     
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <ll> vll;
     
int main () {
  ios::sync_with_stdio(false); cin.tie(0);
  int k, x;
  cin >> k >> x;
  if (k * 500 >= x) cout << "Yes" << '\n';
  else cout << "No" << '\n';
  return (0);
}


Measured memory_bytes: 256
CONST   fi='';
        fo='';
VAR
    f:text;
    n:longint;
    ds:string;
PROCEDURE input;
  begin
    Assign(f,fi);reset(f);
      readln(f,n);
    Close(f);
  end;

PROCEDURE main;
  var i:longint;
  begin
    ds:='';
    while n <> 0 do
      begin
        if ((n mod -2) + 2)mod 2 =1 then ds:='1'+ds else ds:='0'+ds;
        if n mod 2 <> -1 then n:=n div -2 else n:=n div -2 +1;
      end;
    if ds='' then ds:='0';
  end;

PROCEDURE output;
  begin
    Assign(f,fo);rewrite(f);
     writeln(f,ds);
    Close(f);
  end;

BEGIN
   input; main; output;
END.


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    int a,b;cin>>a>>b;
    cout<<a/b<<endl;
    cout<<a%b<<endl;
    double x=(double)a/b;
    printf("%.10lf\n",x);
    return 0;
}


Measured memory_bytes: 3240
import java.util.*;
import java.math.*;
class Main {
    //
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        if(n==1&m==0){
            System.out.println(0);
            return;
        }
        int[] a = new int[m];
        int[] b = new int[m];
        for(int i = 0;i < m;i++){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }
        char[] ans = new char[n];
        for(int i = 0;i < n;i++){
            ans[i] = '*';
        } 
        for(int i = 0;i < m;i++){
            if(ans[a[i]-1]=='*'){
                ans[a[i]-1] = (char)(b[i] + '0');
            }else{
                if(ans[a[i]-1]-'0'==b[i]){
                    continue;
                }else{
                    System.out.println("-1");
                    return;
                }
            }
        }
        for(int i = 0;i < n;i++){
            if(ans[i]=='*'){
                if(i==0){
                    ans[i]='1';
                }else{
                    ans[i]='0';
                }
            }
        }
        if(ans[0]=='0'){
            if(n == 1){
                System.out.println(0);
                return;
            }
            System.out.println(-1);
            return;
        }else{
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 23636
package main

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

func main() {
	fmt.Println(resolve(parseProblem(os.Stdin)))
}

func parseProblem(r io.Reader) int {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines

	return scanInt(sc)
}

func resolve(n int) int {
	r := math.MaxInt32
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			r = min(r, max(digits(i), digits(n/i)))
		}
	}
	return r
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func digits(n int) (d int) {
	return digitsWithBase(n, 10)
}

func digitsWithBase(n int, b int) (d int) {
	tmp := n
	for tmp > 0 {
		d++
		tmp /= b
	}
	return
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 640
a,b,c,d,e,f = map(int, input().split())

anum = f // (100*a)
bnum = f // (100*b)

cp = 0
for ca in range(anum+1):
    for cb in range(bnum+1):
        water = (a*ca + b*cb)*100
        if water > f:
            continue
        cnum = e * (a*ca+b*cb) // c
        dnum = e * (a*ca+b*cb) // d
        for cc in range(cnum+1):
            for cd in range(dnum+1):
                sugar = c*cc + d*cd
                # print(ca, cb, cc, cd, water, sugar)
                if water + sugar <= 0 or water + sugar > f or sugar > e * (a*ca+b*cb):
                    continue
                p = 100 * sugar / (water + sugar)
                if p >= cp:
                    cp = p
                    ans = [str(water + sugar), str(sugar)]
print(' '.join(ans))



Measured memory_bytes: 73680
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

public class Main{

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

        int n = sc.nextInt();
        Triplet<String, Integer, Integer>[] tri = new Triplet[n];
        for (int i = 0; i < n; i++) {
            tri[i] = new Triplet<>(sc.next(),sc.nextInt(),i+1);
        }
        Comparator<Triplet<String, Integer, Integer>> cmpx =  Comparator.comparing(v->v.x);
        Comparator<Triplet<String, Integer, Integer>> cmpy =  Comparator.comparing(v->v.y);
        Arrays.sort(tri, cmpx.thenComparing(cmpy.reversed()));

        for (int i = 0; i < n; i++) {
            System.out.println(tri[i].z);
        }

        sc.close();
    }        
    

    /**
     * Pair_int
     */
    public static class Pair<T1,T2>{
        public T1 x;
        public T2 y;

        public Pair(T1 x, T2 y){
            this.x = x;
            this.y = y;
        }
        
        public String toString() {
            return "(" + x + ", " + y + ")";
        }
    }

    public static class Triplet<T1,T2,T3>{
        public T1 x;
        public T2 y;
        public T3 z;

        public Triplet(T1 x, T2 y, T3 z){
            this.x = x;
            this.y = y;
            this.z = z;
        }
        
        public String toString() {
            return "(" + x + ", " + y + "," + z + ")";
        }
    }
}





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

using namespace std;
typedef long long ll;
#define all(v) ((v).begin()),((v).end())
#define clr(a, b)memset(a,b,sizeof(a))
#define sz(a) (int)(a).size()
#define el '\n';
#define loop(i, n) for(int i = 0;i < int(n);i++)
#define PI acos(-1)
#define pb push_back
#define F first
#define S second

void LOL() {
#ifndef ONLINE_numUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

bool comp(double a, double b) {
    return abs(a - b) < 1e-9;
}

int LCM(int a, int b) {
    return a * b / (__gcd(a, b));
}

bool sortbysec(const pair<int, int> &a,
               const pair<int, int> &b) {
    return (a.second < b.second);
}

const int N = 1e6 + 7, E = 1e5 + 5, OO = 0x3f3f3f3f;
bool vis[E];

int main() {
    //LOL();
    ll x, p = 100, ans = 0;
    cin >> x;
    while (p < x) {
        p += p / 100;
        ans++;
    }

    cout << ans << el;

    return 0;
}

// CHECK THE FOLLOWING ONE MORE TIME BEFORE SUBMIT :
// the vector,arr,etc is redefined in multi cases
// the constraint N M OO etc ,,, The size of the array,vector etc
// the data type of variables ,,, int is enough ?
// the complexity of the code ? O(n)? O(n*n)? will fit ?
// Out of bond ? access an element out of size ? i-1>0 ? i+1 <n?
// CHECK ONE MORE TIME, IT'S OK TO GET WA,BUT NOT OK TO GET TLE OR RTE

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

int main() {
    int n;

    cin >> n;

    int ans=0;
    int tmp;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        if ((tmp % 2 ==0 )&& !((tmp %3 ==0) || (tmp %5 == 0))){
            ans += 1;
        }
    }

    if (ans >0){
        cout << "DENIED" << endl;
    } else {
        cout << "APPROVED" << endl;
    }


}

Measured memory_bytes: 256
import java.util.Scanner;
	public class Main {
	private static Scanner scanner;
	public static void main(String args[]) {

		scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int[] b = new int[a];
		int minj,count = 0;
		for(int i=0;i < a;i++) b[i] = scanner.nextInt();

		for(int i = 0;i < a;i++) {
			minj = i;
			for(int j = i;j < a;j++) {
				if(b[j] < b[minj]) {
					minj = j;
				}
			}
				if(minj != i) {
					int tmp = b[i];
					b[i] = b[minj];
					b[minj] = tmp;
					count++;
				}
		}
		for(int i=0;i < a;i++) {
			System.out.print(b[i]);
			if(i == a-1) System.out.println("");
			else System.out.print(" ");
		}
		System.out.println(count);
	}
	}



Measured memory_bytes: 26284