akhauriyash/Code-Regression huggingface dataset:
// Charan Sriramula
 
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;
 
const ll lg=22;
const ll N=1e5+5;
const ll M=5e8;
const ll INF=1e18;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;
 
#define is(n) scanf("%d",&n)
#define io(n) printf("%d\n",n)
#define ls(n) scanf("%lld",&n)
#define lo(n) printf("%lld\n",n)
 
#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
 
inline ll mul(ll a, ll b, ll p){ return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b, ll p){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll add(ll a, ll b, ll p){ ll c = a + b; if(c > p) c -= p; return c; }
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

int main()
{
    ll n;
    cin>>n;
    n=n*n;
    cout<<3*n<<endl;
}

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

#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(ll i = (m); i < (n); ++i)

#define INF 1e9

int main(){
  int N;
  cin >> N;
  vector<string> s(N);
  vector<int> t(N);
  REP(i, N){
    cin >> s[i] >> t[i];
  }
  string X;
  cin >> X;
  int ans = 0;
  bool flag = false;
  REP(i, N){
    if(flag){
      ans+=t[i];
    }
    if(X == s[i]){
      flag = true;
    }
  }
  cout << ans << endl;
  return 0;
}


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

string small(string s){
  for(int i=0; i<s.length(); i++)
    if('A' <= s[i] && s[i] <= 'Z') s[i] += 32;
  return s;
}

int main(){
  string w,s;
  cin >> w;
  w = small(w);
  int ans=0;
  while( cin >> s ){
    if(s == "END_OF_TEXT") break;
    if(w == small(s)) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1200
import scala.io.StdIn.{readInt,readLine}

object Main {

  def printStable(l:Array[(Char,Int)],a:Array[(Char,Int)]) = {
    val s = l.groupBy(_._2).filter(_._2.length > 1)
    var stable = true

    for {
      i <- s
      if stable
    }
      if(a.filter(_._2 == i._1).toSeq != i._2.toSeq)
        stable = false

    if(stable)
      println("Stable")
    else
      println("Not stable")
  }

  def swap(a:Array[(Char,Int)],x:Int,y:Int) = {
    val t = a(x)
    a(x) = a(y)
    a(y) = t
  }

  def bubbleSort(a:Array[(Char,Int)]) =
    for(i <- 0 until a.length)
      for(j <- a.length-1 to i+1 by -1)
        if(a(j)._2 < a(j-1)._2)
          swap(a,j,j-1)

  def selectionSort(a:Array[(Char,Int)]) =
    for(i <- 0 until a.length) {
      var mini = i
      for(j <- i until a.length)
        if(a(j)._2 < a(mini)._2) mini = j
      swap(a,i,mini)
    }

  def main(args:Array[String]) = {
    val n = readInt
    val l = readLine.split(" ").map(s => (s(0),s.drop(1).toInt))
    val a = l.clone
    val b = a.clone
    bubbleSort(a)
    selectionSort(b)

    println(a.map((x)=>x._1.toString+x._2).mkString(" "))
    printStable(l,a)
    println(b.map((x)=>x._1.toString+x._2).mkString(" "))
    printStable(l,b)
  }
}

Measured memory_bytes: 44108
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector<ll> t(n);
    vector<ll> a(n);
    rep(i, 0, n)
        cin >> t[i] >> a[i];
    ll currT = t[0], currA = a[0];
    // cout << "K\n";
    rep(i, 1, n)
    {
        if (t[i] >= currT && a[i] >= currA)
        {
            currT = t[i];
            currA = a[i];
        }
        else 
        {
            ll q = max(currT / t[i] + (currT % t[i] == 0?0:1), 
                        currA / a[i] + (currA % a[i] == 0?0:1));
            ll oldT = currT;
            ll oldA = currA;
            currT = t[i] * q;
            currA = a[i] * q;
            // cout << currT << "K" << currA << endl;
            // cout << currA << endl;
            if (currT < oldT || currA < oldA)
            {
                q = max(oldT / currT + (currT % t[i] == 0?0:1), 
                        oldA / currA + (currA % a[i] == 0?0:1));
                currT = t[i] * q;
                currA = a[i] * q;  
            }
            // cout << oldA << " " << currA << endl;
            // cout << q << endl;
            // cout << q << endl;
            // cout << currT << " " << oldT << endl;
            // cout << currA << " " << oldA << endl;
            // while (currT < oldT || currA < oldA)
            // {
            //     // cout << "?" << endl;
            //     q++;
            //     currT = t[i] * q;
            //     currA = a[i] * q;
            // }
        }
        // cout << currT << " " << currA << endl;
    }
    cout << currT + currA;
    return 0;
}
// 3
// 2 3 -> 2 3
// 1 1 -> 3 3 // -> 3 2
// 3 2 -> 6 4

// 3 3 -> 3 2

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
char a[111];
int main()
{
    char as;
    int flag=0;
    while(scanf("%c",&as))
    {
        if(as=='\n') break;

        if(as>='A'&&as<='Z'&&!flag)
        {
            cout<<as;
            flag=1;
        }
        if(as==' ') flag=0;

    }cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cstring>
#include <iomanip>
#include <queue>
#include <deque>
#include <cmath>
using namespace std;
#define inf 280201280201280201
#define mn 200005
#define FLN "test"
#define int long long
typedef pair<int, int> ii;
//constance

//common data structures and templates
template<typename T>
struct SegmentTree{
};
//gb
int n;
int a[mn];
//functions here
void input(){
}
void solve(){
}

//#define LOCAL 1

signed main(signed argc, char** argv) {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
#ifdef LOCAL
	   freopen(FLN".inp", "r", stdin);
	   freopen(FLN".out", "w", stdout);
#endif
  cin >> n;
  for(int i=1; i<= n; ++i){
    cin >> a[i];
    a[i] -=i;
  }
  int x = 0;
  sort(a+1, a+n+1);
  if(n&1) x = a[(n+1)>>1];
  else{
    int k = n/2;
    x = (a[k] + a[k+1])>>1;
  }
  int ans = 0;
  for(int i=1; i<= n; ++i) ans += abs(a[i]-x);
  cout << ans;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  vector<bool> vec(100,false);
  vec[a-1] = true;
  vec[b-1] = true;
  vec[c-1] = true;
  int count = 0;
  for(int i = 0; i < 100; i++){
    if(vec[i]){
      count ++;
    }
  }
  cout << count;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define rep(i,n) for(int i = 0; i < (int)(n);i++)
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	a = a - 1;
	ll ans_a = 0;
	ll ans_b = 0;
	ans_b = b / c + b / d - b / lcm(c, d);
	ans_a = a / c + a / d - a / lcm(c, d);
	cout << b - a - ans_b + ans_a << endl;
	return 0;
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, b, e) for (i64 i = (b); i <= (e); ++i)
#define repr(i, b, e) for (i64 i = (b); i >= (e); --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// input
void input() {}
template <class Head, class... Tail>
void input(Head&& head, Tail&&... tail) {
  cin >> head;
  input(forward<Tail>(tail)...);
}

// outs
void outs() {}
template <class Head, class... Tail>
void outs(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  outs(forward<Tail>(tail)...);
}

template <class T>
void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void outs(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// outl
void outl() {}
template <class Head, class... Tail>
void outl(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  outl(forward<Tail>(tail)...);
}

template <class T>
void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// outn
void outn() {}
template <class Head, class... Tail>
void outn(Head&& head, Tail&&... tail) {
  cout << head;
  outn(forward<Tail>(tail)...);
}

template <class T>
void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

// dump
template <class T>
void dump_(const char *s, T&& x) {
  clog << '{';
  while(*s != '\0') clog << *(s++);
  clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void dump_(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  dump_(s, forward<Tail>(tail)...);
}
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  var(i64, a, b);
  outl(b % a == 0 ? a + b : b - a);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define SUBIF(a, b, x) ((x) ? (b) : (a))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using namespace std;


int t, n;


int solve(){
	if(t == 1) return 6000*n;
	if(t == 2) return 4000*n;
	if(t == 3) return 3000*n;
	if(t == 4) return 2000*n;
	return -1;
}


signed main(){
	rep(i, 0, 4){
		cin >> t >> n;
		cout << solve() << endl;
	}

	return 0;
}


Measured memory_bytes: 3084
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str=scan.next();
		int len = 0;
		int point =0;
		String a ="";
		String b ="";
		while(!str.equals("-")){
			int m = scan.nextInt();
			len =str.length();
			for(int i=0;i<m;i++){
				point = scan.nextInt();
				a=str.substring(0,point++);
				b=str.substring(point-1);
				str=b+a;
			}
			System.out.println(str);
			str=scan.next();
		}
	}

}

Measured memory_bytes: 18308
using namespace std;

//#define fileio

#ifndef fileio
#include <iostream>
#endif
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <assert.h>
#include <functional>
#include <math.h>
#include <string>
#include <ctime>

typedef long long ll;

#ifdef fileio
ifstream cin;
ofstream cout;
#endif



int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifdef fileio
    cin.open("Text.txt");
    cout.open("Output.txt");
#endif

    int x;
    cin >> x;
    cout << 1 - x << endl;

}


Measured memory_bytes: 3608
#include <string>
#include <iostream>
#include <vector>

using namespace std;


int main()
{
    int N, K,count,STRSIZE;
    string str;
    vector<char> n_str,tmp;

    cin >> N >> K >> str;

    //cout << str << "\n";
    count = 0;

    for(int i=0; i<(int)str.size(); i++){
        n_str.push_back(str[i]);
    }

    STRSIZE = (int)n_str.size();

    if(n_str[0] != 'R' || n_str[1] != 'R') tmp.push_back(n_str[0]);
    if(n_str[0] == 'R' && n_str[1] == 'R') count++;

    for(int i = 1; i < STRSIZE -1; ++i){
        //cout << "i: " << i << "\n";
        if(n_str[i] == 'R'){
            if(n_str[i+1] == 'R'){
                count++;
                //cout << " count: "  << count << "\n";
                continue;
            }
        }
        if(n_str[i] == 'L'){
            if(n_str[i-1] == 'L'){
                count++;
                //cout << "count: "  << count << "\n";
                continue;
            }
        }
        tmp.push_back(n_str[i]);
    }

    if(STRSIZE >= 2){
        if(n_str[STRSIZE -2] != 'L' || n_str[STRSIZE -1] != 'L') tmp.push_back(n_str[STRSIZE -1]);
        if(n_str[STRSIZE -2] == 'L' && n_str[STRSIZE -1] == 'L') count++;
    }

    n_str = tmp;

    //cout << count << "\n";

    for(int i = 1; i <= K && i <= ((int)n_str.size())/2 ;i++){

        if(i == ((int)n_str.size())/2  && ((int)n_str.size())%2 == 0){
            count++;
            break;
        }
        count = count + 2;
    }

    //for(int i=0; i<(int)n_str.size(); i++){
    //    cout << n_str[i];
    //}
    //cout << "\n";

    cout << count << "\n";
}

Measured memory_bytes: 768
# coding: utf-8

######## 関数の定義 ########
def main():
	""" メインの処理 """	
	input_line = input().rstrip()
	num_rate = int(input_line)  ## 点数
	result = 8  ## 初期値の級数を定義
	if 600 <= num_rate < 800:
		result = 7
	elif 800 <= num_rate < 1000:
		result = 6
	elif 1000 <= num_rate < 1200:
		result = 5
	elif 1200 <= num_rate < 1400:
		result = 4
	elif 1400 <= num_rate < 1600:
		result = 3
	elif 1600 <= num_rate < 1800:
		result = 2
	elif 1800 <= num_rate < 2000:
		result = 1
	print(result)

######## 処理の実行 ########
if __name__ == "__main__":
	main()

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

using namespace std;

main () {
	int n;
	cin>>n;
	string a;
	unordered_set<string> s;
	// vector<string> s;
	for (int i=0;i<n;i++) {
		cin>>a;
		s.insert(a);
	}
	cout<<s.size()<<endl;
}

Measured memory_bytes: 17656
#include<stdio.h>
int main(){
    int a, b;
    scanf("%d%d", &a, &b);
    if (a<b) {
        printf("a < b\n");
    }else if (a>b) {
        printf("a > b\n");
    }else {
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2044
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstring>
#include<algorithm>
using namespace std;

int main(){
  int n,t;
  int a[100000];
  scanf("%d %d",&n,&t);
  for(int i=0;i<n;i++) scanf("%d",a+i);
  priority_queue<int,vector<int>,greater<int> > mi;
  int ans = 0;
  int x = -1;
  for(int i=0;i<n;i++){
    mi.push(a[i]);
    if(i>0&&mi.top()<a[i]){
      if(x<a[i]-mi.top()){
        ans = 1;
        x = a[i]-mi.top();
      }else if(x==a[i]-mi.top()){
        ans++;
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 1276
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    int mn = p[0];
    int cnt = 1;
    repf(i,1,n) {
        if (mn >= p[i]) {
            cnt++;
            chmin(mn, p[i]);
            // cout << p[i] << endl;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	private Scanner sc;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		String p = "A";
		while (sc.hasNextLine()) {
			String[] nico = sc.nextLine().split(",");
			if (nico[0].equals(p)) p = nico[1];
			else if (nico[1].equals(p)) p = nico[0];
		}
		
		System.out.println(p);
	}
}

Measured memory_bytes: 26096
use std::io::stdin;fn main(){let mut t=String::new();stdin().read_line(&mut t).unwrap();let s:Vec<char>=t.trim().chars().collect();let mut f:usize=0;let mut e:usize=1;let mut r:i64=1;for i in 1..(s.len()){if s[f..e]!=s[e..i+1]{f = e;e = i+1;r += 1;};};println!("{}", r)}

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

int n, a, b[110] = {0}, ms = 1e8;
int main() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a;
        b[a]++;
    }
    for(int i = 1; i <= 100; i++) {
        int s = 0;
        for(int j = 0; j <= 100; j++) {
            s += (i - j) * (i - j) * b[j];
        }
        if(s < ms) ms = s;
    }
    cout << ms;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long[] hi;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var Di = Sarray();
            var M = Sarray()[0];
            var Ti = Sarray();
            var Did = new Dictionary<long, long>();
            foreach (var d in Di)
            {
                if (Did.ContainsKey(d))
                    ++Did[d];
                else
                    Did[d] = 1;
            }
            foreach (var t in Ti)
            {
                if (Did.ContainsKey(t))
                {
                    --Did[t];
                    if (Did[t] == 0)
                        Did.Remove(t);
                }
                else
                {
                    WriteLine("NO");
                    return;
                }
            }
            WriteLine("YES");
            //Out.Flush();
        }
    }
}

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

#define ll long long
#define ull unsigned long long
#define openfiles ifstream cin("input10.txt"); ofstream cout("output10.txt");

using namespace std;

string dp[5000];

int main()
{
    string s1, s2;
    cin >> s1 >> s2;
    if(s1.size() > s2.size())
        swap(s1, s2);
    for(int i = 0; i<s1.size(); i++)
    {
        for(int j = s2.size(); j >= 0; j--)
        {
            if(s1[i] == s2[j] && dp[j].size() + 1 > dp[j+1].size())
            {
                dp[j+1] = dp[j] + s1[i];
            }
            if(dp[j].size() > dp[j+1].size())
                dp[j+1] = dp[j];
        }
        for(int j = 0; j < s2.size(); j++)
            if(dp[j].size() > dp[j+1].size())
                dp[j+1] = dp[j];
    }
    cout<<dp[s2.size()];
}


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

using namespace std;

typedef pair<double, int> P;
const int INF = numeric_limits<int>::max() / 2;

struct cell
{
	double x, y, z, r;
};

double calc(cell p, cell q)
{
	double tmp = sqrt((p.x - q.x) * (p.x - q.x) + (p.y - q.y) * (p.y - q.y) + (p.z - q.z) * (p.z - q.z));
	if (tmp <= p.r + q.r)
		return 0;
	else
		return (-p.r - q.r + tmp);
}

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

	while (true)
	{
		int n;
		cin >> n;
		if (n == 0)
			break;
		vector<cell> cells;
		for (int i = 0; i < n; i++)
		{
			cell c;
			cin >> c.x >> c.y >> c.z >> c.r;
			cells.push_back(c);
		}
		vector<vector<double>> dis(n, vector<double>(n, INF));
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if (i == j)
					dis[i][j] = 0;
				else
				{
					dis[i][j] = calc(cells[i], cells[j]);
				}
			}
		}
		vector<bool> used(n, false);
		priority_queue<P, vector<P>, greater<P>> que;
		double res = 0;
		que.push(P(0, 0));
		while (!que.empty())
		{
			P p = que.top();
			que.pop();
			if (used[p.second])
				continue;
			used[p.second] = true;
			res += p.first;
			for (int i = 0; i < n; i++)
			{
				if (!used[i])
				{
					que.push(P(dis[p.second][i], i));
				}
			}
		}
		cout << fixed << setprecision(3) << res << endl;
	}
}


Measured memory_bytes: 3500
#include <bits/stdc++.h>
#define sz              size()
#define pb              push_back
#define Fr              first
#define Sc              second
#define Log2(x)         (31^__builtin_clz(x))
#define endl            "\n"
#define int             ll
using namespace std;
typedef long long ll;
vector<int> v;
int k;
void rec(int i) {
    if(i > 3234566667) return;
    if(i == 3234566667) {
        v.pb(i);
        return;
    }
    v.pb(i);
    for(int j = 0 ; j <= 9 ; j++) {
        if(abs(j - (i % 10)) <= 1) rec(i * 10 + j);
    }
}
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    for(int i = 1 ; i <= 9 ; i++) rec(i);
    sort(v.begin(), v.end());
    cin >> k;
    cout << v[k - 1] << endl;
}


Measured memory_bytes: 1400
#3747518
q=int(input())
from collections import deque
l=deque()
c=0
for _ in range(q):
    *qi,=map(int, input().split())
    if qi[0]==0:
        l.append(qi[1])
    elif qi[0]==1:
        d=qi[1]
        l.rotate(d)
        c-=d
    else:
        l.pop()

l.rotate(c)
l.reverse()
for li in l:
    print(li)
        
        


Measured memory_bytes: 21664
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
 int N;
 cin >> N;
 vector<int> a(N+1, 0);
 for(int i = 1; i < N; i++){
   int t;
   cin >> t;

     a[t]++;
  // }
 }

 for(int i = 1; i <= N; i++){
   cout << a[i] << endl;

 }
 return 0;
}


Measured memory_bytes: 4052
c[100],n,k,a,b,x,y,M,m;Z(){for(x=a=0;a<=n-k;x=x>y?x:y,a++)for(y=1,b=0;b<k;b++)y*=c[a+b];}
main(i,j,t){for(;scanf("%d%d",&n,&k),n;printf("%d\n",m-M)){
	for(i=0;i<n;i++)scanf("%d",c+i);
	Z();M=x;
	for(m=i=0;i<n;i++)for(j=i+1;j<n;j++){
		//t=c[i],c[i]=c[j],c[j]=t;
		c[i]^=c[j],c[j]^=c[i],c[i]^=c[j];
		Z();m=m>x?m:x;
		//t=c[i],c[i]=c[j],c[j]=t;
		c[i]^=c[j],c[j]^=c[i],c[i]^=c[j];
	}
}exit(0);}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> v[m];
    for(int i = 0; i < m; i++){
        int k;
        cin >> k;
        while(k-- > 0){
            int x;
            cin >> x;
            v[i].push_back(--x);
        }
    }
    vector<int> p(m);
    for(int i = 0; i < m; i++)  cin >> p[i];
    int ans = 0;
    for(int i = 0; i < 1<<n; i++){
        vector<int> sw(n, 0);
        for(int j = 0; j < n; j++){
            if((i>>j)&1)    sw[j] = 1;
        }
        bool judge = true;
        for(int j = 0; j < m; j++){
            int sum = 0;
            for(int k = 0; k < v[j].size(); k++)    sum += sw[v[j][k]];
            judge &= ((sum%2)==p[j]);
        }
        if(judge)   ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a=0,b=0,c=0,d=0,e=0,k=0,i=0;
	
	scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&k);
	i=e-a;
	if(i<=k)
	{
		printf("Yay!\n");
	}
	else
	{
		printf(":(\n");
	}
	return 0;
}



Measured memory_bytes: 128
<?php
$n=trim(fgets(STDIN))+1;
$o=array('');
for($i=1;$i<$n;$i++){
  if($i%3==0) $o[]=$i;
  else{
   $x=$i;
   while($x){
      if($x%10==3){
        $o[]=$i;
        break;
      }
      $x=floor($x/10);
    }
  }
}
print implode(' ',$o);
?>

Measured memory_bytes: 16212
#include<iostream>
using namespace std;
char map[101][101];
int sum=0;
int h,w;
void dfs(int x,int y){
	if(x<1||x>h||y<1||y>w) return;
	if(map[x-1][y-1]=='#') sum++;
	if(map[x-1][y]=='#') sum++;
	if(map[x-1][y+1]=='#') sum++;
	if(map[x][y-1]=='#') sum++;
	if(map[x][y+1]=='#') sum++;
	if(map[x+1][y-1]=='#') sum++;
	if(map[x+1][y]=='#') sum++;
	if(map[x+1][y+1]=='#') sum++;
	return;
}
int main(){
	cin>>h>>w;
	for (int i=1;i<=h;i++)
		for (int j=1;j<=w;j++) cin>>map[i][j];
	for (int i=1;i<=h;i++)
		for (int j=1;j<=w;j++){
			if(map[i][j]=='.'){
				dfs(i,j);
				map[i][j]=sum+48;
				//cout<<sum<<endl;
				sum=0;
			}
		}
	for (int i=1;i<=h;i++){
		for (int j=1;j<=w;j++) cout<<map[i][j];	
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  REP(j, k) {
    vector<int> s(n + 1, 0);
    REP(i, n) {
      // 累積和の左右
      int l = max(0, i - a[i]);
      int r = min(i + a[i] + 1, n);
      s[l]++;
      s[r]--;
    }
    // 累積和をとる
    REP(i, n) s[i + 1] += s[i];
    // 末尾のゴミを排除
    s.pop_back();
    // 処理前後で変化がなければ終了
    if (a == s) break;
    // そうでなければ次のステップへ
    a = s;
  }
  REP(i, n) {
    cout << a[i] << " ";
  }
  cout << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


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

int main(){
    int h, w, K;
    cin >> h >> w >> K;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    vector<int> yoko(h);
    vector<int> kireme;
    kireme.pb(-1);
    rep(i, h){
        int p = 0;
        rep(j, w) if (s[i][j] == '#') p++;
        yoko[i] = p;
    }
    vector<vector<int>> ans(h, vector<int>(w));
    int p = 1;
    int judge = 0;
    rep(i, h){
        if (yoko[i]) judge = 1;
        rep(j, w) ans[i][j] = p;
        if (i == h - 1 || yoko[i + 1]){
            if (judge){
                kireme.pb(i);
                p++;
            }
        }
    }
    rep(i, kireme.size() - 1){
        vector<int> tate(w);
        rep(k, w){
            int q = 0;
            for (int j = kireme[i] + 1; j <= kireme[i + 1]; j++){
                if (s[j][k] == '#') q++;
            }
            tate[k] = q;
        }
        judge = 0;
        int judge2 = 0;
        rep(k, w){
            if (tate[k]) judge = 1;
            for (int j = kireme[i] + 1; j <= kireme[i + 1]; j++)
                if (judge2)
                    ans[j][k] = p;
            if (k == w - 1 || tate[k + 1]){
                if (judge){
                    if (judge2) p++;
                    judge2 = 1;
                }
            }
        }
    }
    rep(i, h){
        rep(j, w) cout << ans[i][j] << " ";
        cout << endl;
    }
}

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

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rrep(i,n) for(ll i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)
#define rrep1(i,n) for(ll i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

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

  // n==k
  if(n==k){
    ll result=1;
    for(auto c:a){
      result*=(c+MOD);
      result %= MOD;
    }
    cout<<result<<endl;

    return 0;
  }

  vector<ll> ma, pa, za;
  for(auto c:a){
    if(c<0)ma.push_back(c);
    else if(c>0)pa.push_back(c);
    else if(c==0)za.push_back(0);
  }

  // 0
  if(za.size()>n-k){cout<<0<<endl; return 0; }

  sort(ma.begin(), ma.end());
  sort(pa.begin(), pa.end());

  // -
  if(k%2==1 && pa.size()==0){
    if(za.size()>0){cout<<0<<endl; return 0; }

    ll result = 1;
    rep(i, k){
      ll idx = ma.size()-1-i;
      result *= (ma[idx]+MOD);
      result%=MOD;
    }
    cout<<result<<endl;

    return 0;
  }
  
  // - 
  if(k>pa.size() && (k-pa.size())==1 ){
    if(za.size()>0){cout<<0<<endl; return 0; }

    ll result=ma.back()+MOD;
    for(auto c:pa){
      result *= c;
      result %= MOD;
    }
    cout<<result<<endl;

    return 0;
  }

  // +
  if(ma.size()==0){
    rep(i, za.size())pa.push_back(0);
    sort(pa.begin(), pa.end());

    ll result=1;
    rep(i, k){
      result *= pa.back(); pa.pop_back();
      result %= MOD;
    }
    cout<<result<<endl;

    return 0;
  }


  vector<ll> results;
  rep(i, ma.size())ma[i]=-ma[i];
  sort(ma.begin(), ma.end());

  //for(auto c:ma)cout<<c<<' ';cout<<endl;for(auto c:pa)cout<<c<<' ';cout<<endl;

  while(results.size()<k){
    ll pamax = -1;
    if(pa.size()) pamax = pa[pa.size()-1] * pa[pa.size()-2];
    ll mamax = -1;
    if(ma.size()>=2)mamax = ma[ma.size()-1] * ma[ma.size()-2];

    // maの最大2つの乗算の方がpaの最大2つの乗算よりもデカイ、かつ結果格納先の余裕が2個以上あるなら、負の配列から2つ取り出して格納する、2個以上無いと入らないので。
    if(mamax > pamax && k-results.size()>=2){
      results.push_back(ma.back());
      ma.pop_back();
      results.push_back(ma.back());
      ma.pop_back();
    }else{
      results.push_back(pa.back());
      pa.pop_back();
    }
  }

//  for(auto c: results)cout<<c<<' ';cout<<endl;

  ll result=1;
  for(auto c: results){
    result *= c;
    result %= MOD;
  }
  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 9568
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local l, r = io.read("*n", "*n")

local ret = 2019
local imax = mmi(l + 2018, r - 1)
for i = l, imax do
  local jmax = mmi(i + 1 + 2018, r)
  for j = i + 1, jmax do
    local cand = ((i % 2019) * (j % 2019)) % 2019
    ret = mmi(ret, cand)
  end
end
print(ret)


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int m = sc.nextInt();

		int a[] = new int[n];
		int b[] = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}
		int c[] = new int[m];
		int d[] = new int[m];
		for(int i = 0; i < m; i++){
			c[i] = sc.nextInt();
			d[i] = sc.nextInt();
		}

		for(int i = 0; i < n; i++){
			int index = 0;
			int minDist = Integer.MAX_VALUE;

			for(int j = 0; j < m; j++){
				int tmpDist = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);

				if(tmpDist < minDist){
					index = j;
					minDist = tmpDist;
				}
			}

			System.out.println(index + 1);
		}
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
/*bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}*/

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//




int s[510][510];

int main(){
        int n,m,q;
        cin >> n >> m >> q;
        int l,r;
        for(int i = 0; i < m; i++)
        {
                cin >> l >> r;
                //５００個のテーブルを累積和で作る。
                for(int j = r; j <= 500; j++)
                {
                        s[l][j]++;
                }
        }

        int ans;
        for(int i = 0; i < q; i++)
        {
                //クエリに答えていく。
                cin >> l >> r;
                ans = 0;
                //累積和の答えを出す。
                for(int j = l; j <= r; j++)
                {
                        ans += s[j][r] - s[j][l-1];
                }
                cout << ans << endl;
        }

        return 0;
}


Measured memory_bytes: 1920
S = gets.chomp
K = gets.to_i
ans = 0
if K == 1 || S[0] != S[-1]
    curr = nil
    streak = 1
    S.chars.each do |s|
        if curr == s
            streak += 1
        else
            ans += streak / 2
            streak = 1
        end
        curr = s
    end
    ans += streak / 2
    ans = ans * K 
elsif S.chars.uniq.size == 1
    ans = S.length * K / 2
else
    curr = nil
    streak = 1
    streaks = []
    S.chars.each do |s|
        if curr == s
            streak += 1
        else
            streaks << streak if !curr.nil?
            streak = 1
        end
        curr = s
    end
    streaks << streak
    streaks[1..-2].each{|st| ans += (st / 2) *  K}
    ans += streaks[0] / 2
    ans += streaks[-1] / 2
    ans += (streaks[0] + streaks[-1]) / 2 * (K - 1)
end
p ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n,q;
    ll k;
    cin >> n >> k >> q;
    vector<int>data(n);
    rep(i,q){
        int a;
        cin >> a;
        a--;
        data[a] += 1;
    }
    rep(i,n){
        if(q-data[i] >= k)cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    return 0;
}

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

int main() {
  int i, N, count=0;
  vector<int> d(110);
  
  cin >> N;
  rep(i,N) cin >> d[i];
  
  sort(d.begin(),d.begin()+N);
  
  rep(i,N-1){
    if(d[i]!=d[i+1])count+=1;
  }
  
  cout << count+1;
  
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

struct edge {
    int to, cost;
};
typedef vector<vector<edge> > AdjList;
AdjList graph;

typedef pair<int, int> P;

const int INF = 10000000;

vector<int> dist; 
vector<int> prever;

void dijkstra(int n, int s){
    dist = vector<int>(n,INF);
    prever = vector<int>(n,-1);
    dist[s] = 0;

    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0,s));

    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(dist[v] < p.first){
            continue;
        }
        for(int i=0;i<graph[v].size();i++){
            edge e = graph[v][i];
            if(dist[e.to] > dist[v] + e.cost){
                dist[e.to] = dist[v] + e.cost;
                prever[e.to] = v;
                que.push(P(dist[e.to],e.to));
            }
        }
    }
}

vector<int> get_path(int t){ //頂点tへの最短路
    vector<int> path;
    int sum=0;
    for(; t != -1;t=prever[t]){
        path.push_back(t);
        sum++;
        if(sum==2){
            break;
        }
    }

    return path;
}

int main(void){
    int n, m;
    cin >> n >> m;
    graph = AdjList(n);
    for(int i=0;i<m;i++){
        int from, to;
        cin >> from >> to;
        from--;
        to--;
        graph[from].push_back((edge){to,1});
        graph[to].push_back((edge){from,1});
    }
    dijkstra(n,0);
    vector<int>anss;
    bool ok=true;
    for(int i=1;i<n;i++){
        vector<int>ans=get_path(i);
        if(ans.size()<2){
            ok=false;
            break;
        }
        anss.push_back(ans[1]);
        
    }
    if(ok){
        cout<<"Yes"<<endl;
        for(int i=0;i<n-1;i++){
            cout<<anss[i]+1<<endl;
        }
    }else{
        cout<<"No"<<endl;
    }

    
    
    
}

Measured memory_bytes: 13736
#include <iostream>
#include <list>
#include <string>
#include <tuple>
using namespace std;

string target;

bool search(string s,int index) {
	int length = s.size();
	if (s != target.substr(index, length)) return false;
	if (index + length == target.size()) return true;
	return (search("dream", index + length) || search("erase", index + length) || search("eraser", index + length) || search("dreamer", index + length));
}

int main()
{
	cin >> target;
	if (search("dream",0)|| search("dreamer", 0)|| search("erase", 0)|| search("eraser", 0)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 4608
#include <stdio.h>
#include <string.h>

int main(void)
{
	int n, i, len;
	char fi4[256], ans[256];
	
	while (1){
		
		scanf("%d", &n);
		
		if (n == -1){
			break;
		}
		i = 0;
		
		if (n == 0){
			printf("0\n");
			continue;
		}
		
		while (n != 0){
			
			fi4[i++] = n % 4 + '0';
			n /= 4;
			
			if (n == 0){
				fi4[i] = '\0';
				break;
			}
		}
		
		len = strlen(fi4);
		
		for (i = 0; i < len; i++){
			ans[i] = fi4[len - 1 - i];
		}
		ans[len] = '\0';
		
		printf("%s\n", ans);
	}
	return (0);
}
		

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=4e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

int n;
int a[MAXn],b[MAXn];
int aa[MAXn],bb[MAXn];
int f[MAXn];
void build(){
    int cur = f[0] = -1;
    REP1 (i,n-2) {
        while (cur != -1 && aa[cur+1] != aa[i]) cur = f[cur];
        if (aa[cur+1] == aa[i]) cur++;
        f[i] = cur;
    }
}
int main(){
    IOS();
    cin >> n;
    REP (i,n) cin >> a[i];
    REP (i,n) {
        cin >> b[i];
        b[i+n] = b[i];
    }
    REP (i,n-1) {
        aa[i] = a[i] ^ a[i+1];
        bb[i] = b[i] ^ b[i+1];
    }
    for (int i=n-1;i<2*n-1;i++) bb[i] = b[i] ^ b[i+1];
    pary(aa,aa+2*n-1);
    pary(bb,bb+2*n-1);
    build();
    int cur = -1;
    vector<ii> ans;
    REP (i,2*n-2) {
        while (cur != -1 && aa[cur+1] != bb[i]) cur = f[cur];
        if (aa[cur+1] == bb[i]) cur++;
        if (cur == n-2) {
            debug(cur,i);
            int move = i-cur;
            debug(move);
            ans.eb((n-move)%n,(a[0] ^ b[i-cur]));
            cur = f[cur];
        }
    }
    sort(ALL(ans));
    REP (i,SZ(ans)) cout << ans[i].X << ' ' << ans[i].Y << endl;
}


Measured memory_bytes: 10840
n,k=map(int,input().split())
ans=["1 "+str(i) for i in range(2,n+1)]
c=(n-1)*(n-2)//2
if k>c:
	print(-1)
	exit()
for i in range(2,n):
	for j in range(i+1,n+1):
		if c==k:
			break
		ans+=["{} {}".format(i,j)]
		c-=1
	else:
		continue
	break
print(len(ans))
print(*ans,sep="\n")

Measured memory_bytes: 3716
import java.io.*;
  
class Main
{
    public static void main (String args[]) throws IOException
{
    BufferedReader br =
    new BufferedReader(new InputStreamReader(System.in));
  
    String str = br.readLine();
    int x = Integer.parseInt(str);
  
   
        System.out.println((int)Math.pow(x,3));
     }
      
}

Measured memory_bytes: 24392
while set = gets()
  if (set.nil? or set == "\n" or set == "\n\r") then break end
  a, b = set.split().map{|x| x.to_i}
  yakusu = Array.new()

  (2..9).each do |n|
    while a % n == 0 and b % n == 0 
      yakusu.push(n)
      a = a / n
      b = b / n
    end
  end
  saidai = 1
  yakusu.each do |y|
    saidai = saidai * y
  end
  puts "#{saidai} #{saidai * a * b}"
end

Measured memory_bytes: 6100
// CPP program for finding number of divisor
#include <iostream>
#include<algorithm>
// #include <bits/stdc++.h>
using namespace std;
#define ll long long

// driver program
int main()
{
    int n, k, i, ans;
    cin >> n >> k;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    sort(a, a+n);
    ans = 0;
    for(i=0;i<k;i++)
    {
        ans += a[i];
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=105;
const ll inf=1ll<<60;
int cnt=1,head[N],Head[N],n,dis[N],S,T,x;
ll ans,tmp;
queue<int> q;
struct node{int to,next;ll w;}num[N*N*2];
void add(int x,int y,ll w)
{num[++cnt].to=y;num[cnt].next=head[x];num[cnt].w=w;head[x]=cnt;
num[++cnt].to=x;num[cnt].next=head[y];num[cnt].w=0;head[y]=cnt;}
int bfs()
{ 
   memset(dis,0,sizeof(dis));dis[S]=1;
   q.push(S);
   while (!q.empty())
   {
     int now=q.front();q.pop();
     for (int i=head[now];i;i=num[i].next)
       if (num[i].w&&!dis[num[i].to])
          q.push(num[i].to),dis[num[i].to]=dis[now]+1;
    }
    return dis[T];
}
ll dfs(int x,ll mm)
{ 
  ll tmp=mm;
  if (x==T) return mm;
  for (int &i=Head[x];i&&tmp;i=num[i].next)
    if (dis[num[i].to]==dis[x]+1)
    {
       ll t=dfs(num[i].to,min(num[i].w,tmp));
       tmp-=t;num[i].w-=t;num[i^1].w+=t;
    }
  return mm-tmp;
}
void dinic()
{
   while (bfs())
   {
     memcpy(Head,head,sizeof(head));
     while (tmp=dfs(S,inf)) ans-=tmp;
   }
}
int main()
{
  scanf("%d",&n);S=n+1;T=S+1;
  for (int i=1;i<=n;i++) 
  {
     scanf("%d",&x);
     if (x<0) add(S,i,-x);else add(i,T,x),ans+=x;
  }
  for (int i=1;i<=n;i++)
    for (int j=i+i;j<=n;j+=i) add(i,j,inf);
  dinic();
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<long long, long long>
#define plll pair<long long, pll>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss

using namespace std;

vector<pii> gph[101010];
bool vst[101010];
bool color[101010];
int edge[202020];

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

    int n, m; cin >> n >> m;
    int tar[n]; for(auto &i : tar) cin >> i;
    for(int i = 0; i < m; ++i)
    {
        int s, e; cin >> s >> e; --s; --e;
        gph[s].push_back({e, i});
        gph[e].push_back({s, i});
    }

    int ord[n]; for(int i = 0; i < n; ++i) ord[i] = i;
    sort(ord, ord + n, [&tar](int x, int y){return tar[x] < tar[y];});

    for(auto x : ord)
    {
        if(vst[x]) continue;

        for(auto y : gph[x])
        {
            if(vst[y.ff])
            {
                vst[x] = true;
                color[x] = !color[y.ff];
                edge[y.ss] = tar[x];
                break;
            }
        }

        if(vst[x]) continue;

        for(auto y : gph[x])
        {
            if(tar[x] == tar[y.ff])
            {
                vst[x] = true;
                vst[y.ff] = true;
                color[x] = true;
                color[y.ff] = false;
                edge[y.ss] = tar[x];
                break;
            }
        }

        if(vst[x]) continue;

        cout << -1;
        return 0;
    }

    for(int i = 0; i < n; ++i) cout << (color[i] ? 'B' : 'W'); cout << '\n';
    for(int i = 0; i < m; ++i) cout << (edge[i] == 0 ? (int)1e9 : edge[i]) << '\n';
    return 0;
}


Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
string s;
inline int read()
{
	int n_d=0,o_d=1;
	char c_d=getchar();
	while(c_d<'0'||c_d>'9')
	{
		if(c_d=='-')
			o_d=-1;
		c_d=getchar();
	}
	while(c_d>='0'&&c_d<='9')
	{
		n_d=n_d*10+c_d-'0';
		c_d=getchar();
	}
	return n_d*o_d;
}
int main()
{
    cin>>s;
   	int len=s.size();
    bool(s[0]==s[len-1])?(bool(len%2)?cout<<"Second\n":cout << "First\n"):(bool(len%2)?cout << "First\n":cout << "Second\n");
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
string S,T;
  cin >> S >> T;
  int count = 0;
  for(int a = 0;a < S.length();a++){
   if(S[a] != T[a])count++; 
    
  }
  cout << count << endl;
  
}

Measured memory_bytes: 3916
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[210000];
int f[1100000];
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)  scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int cnt=0;
	for(int i=1;i<=n;++i){
		if(f[a[i]]==0 && (i==n || a[i]!=a[i+1]))  ++cnt;
		for(int j=1;a[i]*j<=a[n];++j)
			f[a[i]*j]=1;
	}
	cout<<cnt<<endl;
	return 0;
}




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

using namespace std;

int main(){
	int N;
	cin >> N;
	int res = N;
	//
	// もし6だけなら...
	// 1,6,36,216,...
	// 
  // いずれも6の倍数
	// 一般化して6を基数Bとする. 
	// NのB進数展開を行い,各桁の数の和を求めれば良い. 
	// まずB^0=1の桁を求める;
	// N = n*B + m = (N/B) * B + (N%B) 
	// より, mが求める数値となる. 
	// 次にB^1=Bの桁を求める;
	// nがB^1の係数となっており, B^1の桁の数であるから、 
	// N <- n と代入すれば, 上と同じ式で求まるmがB^1桁の係数となる. 
	// 従って, n=0となるまで繰り返しmを求めれば, 1桁から順にB進数展開の係数が求まる.
	//
	// 次にNを6と9をそれぞれ6進数, 9進数展開した値の和として表したときの係数の総和を最小にする. 
	// 任意の正整数について, 6, 9いずれかで展開したときの係数の総和は上のように簡単に求めることができる.
	// そこで,a+b=Nとして, Nを6で展開した数aと9で展開した数の和bとして表し,それぞれの係数の総和を求める.
	// N=a+bを満たす全ての(a,b)に対して展開係数の総和を求め, 最小となるものを求めれば良い.
	//
	for (int i=0; i<=N; ++i) {
		int sum_of_coeff = 0;
		int t = i;
		while(t>0) {
		 	sum_of_coeff += t%6;
			t /= 6;
		}
		t = N-i;
		while(t>0) {
		 	sum_of_coeff += t%9;
			t /= 9;
		}
		res = res > sum_of_coeff ? sum_of_coeff : res;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256