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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	string s;
	int k; cin>>s>>k;

	int n=s.length();
	int pre=0;
	vector<int> A;
	rep(i,n) if(i==n-1 || s[i]!=s[i+1]) {
		A.emplace_back(i-pre+1);
		pre=i+1;
	}

	if(k==1 || s[0]!=s[n-1]){
		int cnt=0;
		for(int a:A) cnt+=a/2;
		cout<<1LL*cnt*k<<endl;
	}
	else{
		int m=A.size();
		if(m==1){
			cout<<1LL*n*k/2<<endl;
		}
		else{
			int cnt=0;
			for(int i=1;i<m-1;i++) cnt+=A[i]/2;
			cout<<1LL*cnt*k+1LL*(A[0]+A[m-1])/2*(k-1)+A[0]/2+A[m-1]/2<<endl;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int Check(int N){
  char S[N];
  int i;
  scanf("%s", S);
  if(N % 2 != 0) return 0;
  for(i = 0;i < N / 2;i++) if(S[i] != S[N/2+i]) return 0;
  return 1;
}

int main(void){
  int N;
  scanf("%d", &N);
  if(Check(N) == 1) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 128
# https://atcoder.jp/contests/abc088/tasks/abc088_b
# B - Card Game for Two

n = int(input().split()[0])
a_list = list(map(int, input().split()))

a_list = sorted(a_list, reverse=True)
p_alice = sum(a_list[::2])
p_bob = sum(a_list[1::2])
ans = p_alice - p_bob
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;cin>>n>>m;
    int k;cin>>k;
    for(int x=0;x<=n;++x){
        for(int y=0;y<=m;++y){
            if(m*x+n*y-2*x*y==k){
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";
    return 0;
}

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

using namespace std;

int main(){
    int N,K;
    cin >> N >> K;
    vector<long long int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }

    for(int i=K;i<N;i++){
        if(A[i-K]<A[i]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 4836
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define ll long long
#define l long
#define all(x) x.begin(),x.end()
#define pb push_back
#define len(x) x.len
int main()
{
string s;
cin>>s;
cout<<s[0]<<s[1]<<s[2];






return 0;}

Measured memory_bytes: 3596
n = int(input())
s = input()
ans = 0
for i in range(1000):
    key = "0" * (3 - len(str(i))) + str(i)
    j = 0
    flag = True
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[0]:
            j += 1
            break
        j += 1
    if not flag:
        continue
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[1]:
            j += 1
            break
        j += 1
    if not flag:
        continue
    while True:
        if j == n:
            flag = False
            break
        if s[j] == key[2]:
            j += 1
            break
        j += 1
    if flag:
        ans += 1
print(ans)


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

ll inf=9223372036854775806,ans=0;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll i,j,n,a[100002],t=0,d=0;
	cin>>n;
	a[0]=0;
	for (i=1;i<=n;i++){
		cin>>a[i];
		d+=abs(a[i]-a[i-1]);
	}
	a[n+1]=0;
	d+=abs(a[n+1]-a[n]);
	for (i=1;i<=n;i++){
		cout<<d-(abs(a[i]-a[i-1])+abs(a[i+1]-a[i])-abs(a[i+1]-a[i-1]))<<"\n";
	}
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pll pair<long long, long long >
#define ll long long
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define maxn 10000000000000
#define endl '\n'
#define trace(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;
int mod(int x,int y)
{
  int s;
  s = abs(x)/y;
  if(x<0)s--;
  return x-y*s;
}
int dir8[2][8] = {{1,-1,0,0,1,-1,1,-1},{0,0,1,-1,1,-1,-1,1}};
int dir4[2][4] = {{1,-1,0,0},{0,0,1,-1}};
ll m,n,row,col,k;
ll memo[105][100005];
ll cost[105],weight[105];
ll maxVal = 0;
void solve()
{
  scanf("%lld%lld",&n,&m);
  for(int w=0;w<n;w++)
  {
    scanf("%lld%lld",&weight[w],&cost[w]);
    maxVal += cost[w];
  }
  for(int w=0;w<=maxVal;w++)memo[n-1][w] = (cost[n-1]>=w) ? weight[n-1]:maxn;
  for(int i=n-2;i>=0;i--)
  {
    for(ll j = 0; j <= maxVal;j++)
    {
      if(cost[i] >= j)
      {
        memo[i][j] = min(memo[i+1][j],weight[i]);
      }
      else
      {
        memo[i][j] =min( weight[i] + memo[i+1][j-cost[i]],memo[i+1][j]);
      }
    }
  }
  ll ans = 0;
  for(int i=0;i<=maxVal;i++)
  {
  //  cout << memo[0][i] << " " << i << endl;
    ans = (memo[0][i]<=m) ? i:ans;
  }
  printf("%lld\n",ans);


}
void test()
{
  int t;
  //scanf("%d",&t);
  t=1;
  for(int test=1;test<=t;test++)
  {
    //memset(memo,-1,sizeof memo);
    solve();
  }
}
int main()
{
  test();
  return 0;
}


Measured memory_bytes: 80128
// 解説のDP
// y + (y ^ xor) = sum, y <= sup を満たすyの最大値を求める
// 下からやっていく
// [i桁目][i桁目まで見たとき以下である][carry] = 最大値
fn solve(sum: usize, xor: usize, sup: usize) -> Option<usize> {
    let mut dp = vec![vec![None; 2]; 2];
    dp[1][0] = Some(0);
    for i in 0..41 {
        let mut next = vec![vec![None; 2]; 2];
        for (cond, dp) in dp.iter().enumerate() {
            for (carry, v) in dp.iter().enumerate().filter(|v| v.1.is_some()) {
                let v = v.unwrap();
                let x = sum >> i & 1;
                let y = xor >> i & 1;
                let z = sup >> i & 1;
                for a in 0..2 {
                    if (a + (y ^ a) + carry) & 1 != x || v + (a << i) > sup {
                        continue;
                    }
                    let carry = (a + (y ^ a) + carry) >> 1;
                    let cond = ((cond == 1 && a <= z) || (a == 0 && z == 1)) as usize;
                    let v = v + (a << i);
                    let p = next[cond][carry].get_or_insert(v);
                    *p = std::cmp::max(*p, v);
                }
            }
        }
        dp = next;
    }
    if dp[1][0].map_or(false, |p| p != 0) {
        Some(sup - dp[1][0].unwrap())
    } else {
        None
    }
}

fn run() {
    proconio::input! {
        n: usize,
        a: [usize; n],
    }
    let xor = a.iter().skip(2).fold(0, |s, a| s ^ *a);
    let sum = a[0] + a[1];
    if let Some(ans) = solve(sum, xor, a[0]) {
        println!("{}", ans);
    } else {
        println!("-1");
    }
}

fn main() {
    run();
}


Measured memory_bytes: 2168
import java.text.ParseException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws ParseException {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String[] lines = sc.nextLine().split("[., ]");
            int c = 0;
            for (int i = 0; i < lines.length; i++) {
                if (lines[i].length() > 2 && lines[i].length() < 7) {
                    System.out.print((c++ == 0 ? "" : " ") + lines[i]);
                }
            }
        }
        System.out.println();
    }
}


Measured memory_bytes: 25720
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
 
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn xx(i:usize) -> i32 {
    if i % 2 == 0 && i != 0 {
        return xx(i / 2) + 1;
    } else {
        return 0;        
    }
}
fn main() {
    /*     input! {
        n: usize,
        mut plan: [(i32, i32, i32); n],  // Vec<(i32, i32, i32)>
    }
 */
    input! {
        n:usize,
    }
    let mut ans = 0;
    let mut cnt = 0;
    if n == 1 {
        println!("1");
        return;
    }
    for i in (1..n+1).filter(|x|x % 2 == 0){
        let cur_cnt = xx(i);
        if cnt < cur_cnt {
            ans = i;
            cnt = cur_cnt;
        }
    }
    println!("{}",ans);
}    


Measured memory_bytes: 4352
n, *v = map(int, open(0).read().split())
o, e = v[::2], v[1::2]
o.sort();e.sort()

on = []
prev = 0
cnt = 0
for i in o:
  if i==prev: cnt += 1
  else: on.append([prev,cnt]);cnt=1
  prev = i
on.append([prev,cnt])
on.sort(key=lambda x:x[1])


en = []
prev = 0
cnt = 0
for i in e:
  if i==prev: cnt += 1
  else: en.append([prev,cnt]);cnt=1
  prev = i
en.append([prev,cnt])
en.sort(key=lambda x:x[1])

if on[-1][0]==en[-1][0]:
  o=list(zip(*on))[1]
  e=list(zip(*en))[1]
  ans = sum(o)+sum(e)
  print(ans-max(o[-2]+e[-1],o[-1]+e[-2]))
else:
  o=list(zip(*on))[1]
  e=list(zip(*en))[1]
  print(sum(o)+sum(e)-o[-1]-e[-1])

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n+1);
	rep(d,n+1) scanf("%d",&a[d]);

	lint sum=0;
	rep(d,n+1) sum+=a[d];

	lint ans=0,f=1;
	rep(d,n+1){
		if(f-a[d]<0){
			return puts("-1"),0;
		}
		ans+=f;
		sum-=a[d];
		f=min(2*(f-a[d]),sum);
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 3856
n = input().rstrip()
if len(n) == 1:
  print(n)
else:
  flg = True
  for i in range(1,len(n)):
    if n[i] != '9':
      flg = False
  if flg:
    print(9*(len(n)-1)+int(n[0]))
  else:
    print(9*(len(n)-1)+int(n[0])-1)

Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

type Point struct {
	X int
	Y int
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	var res string
	var pointA Point
	var pointB Point
	pointA.X = nextInt()
	pointA.Y = nextInt()
	pointB.X = nextInt()
	pointB.Y = nextInt()

	for i := 0; i < pointB.Y-pointA.Y; i++ {
		res += "U"
	}
	for i := 0; i < pointB.X-pointA.X; i++ {
		res += "R"
	}
	for i := 0; i < pointB.Y-pointA.Y; i++ {
		res += "D"
	}
	for i := 0; i < pointB.X-pointA.X; i++ {
		res += "L"
	}
	res += "L"
	for i := 0; i < pointB.Y-pointA.Y+1; i++ {
		res += "U"
	}
	for i := 0; i < pointB.X-pointA.X+1; i++ {
		res += "R"
	}
	res += "D"
	res += "R"
	for i := 0; i < pointB.Y-pointA.Y+1; i++ {
		res += "D"
	}
	for i := 0; i < pointB.X-pointA.X+1; i++ {
		res += "L"
	}
	res += "U"
	fmt.Fprint(out, res)
}


Measured memory_bytes: 7680
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int get(int lx, int ly, int rx, int ry, const vector<vector<int>>& table)
{
	int ret = 0;
	ret += table[ry][rx];
	ret -= table[ry][lx-1];
	ret -= table[ly-1][rx];
	ret += table[ly-1][lx-1];

	return ret;
}

int main(void)
{
	int N, M, Q;
	cin >> N >> M >> Q;

	vector<int> L(M), R(M);
	for(int i=0; i<M; i++)
		cin >> L[i] >> R[i];

	vector<int> p(Q), q(Q);
	for(int i=0; i<Q; i++)
		cin >> p[i] >> q[i];

	const int size = 510;
	vector<vector<int>> imos(size, vector<int>(size, 0));
	for(int i=0; i<M; i++)
		imos[R[i]][L[i]]++;
	
	for(int i=1; i<size; i++){
		for(int j=1; j<size; j++){
			imos[i][j] += imos[i-1][j];
			imos[i][j] += imos[i][j-1];
			imos[i][j] -= imos[i-1][j-1];
		}
	}

	for(int i=0; i<Q; i++)
		cout << get(p[i], p[i], q[i], q[i], imos) << endl;

	return 0;
}


Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int a,b;
    string s;
    cin >> a >> b >> s;
    bool ans=true;
    for(int i=0;i<a;i++){
        int code = s.at(i) - '0';
        if(0 > code || code > 9) ans = false;
    }
    if(s.at(a) != '-') ans = false;
    for(int i=a+1;i<a+b+1;i++){
        int code = s.at(i) - '0';
        if(0 > code || code > 9) ans = false;
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stack>

using namespace std;
static const int MAX=100000;
static const int NIL=-1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r,int c){
  stack<int> S;
  S.push(r);
  color[r]=c;
  while(!S.empty()){
    int u=S.top();
    S.pop();
    for(int i=0;i<G[u].size();i++){
      int v=G[u][i];
      if(color[v]==NIL){
	color[v]=c;
	S.push(v);
      }
    }
  }
}

void assignColor(){
  int id=1;
  for(int i=0;i<n;i++)
       color[i]=NIL;
  for(int u=0;u<n;u++){
    if(color[u]==NIL)
          dfs(u,id++);
  }
}

int main(){
  int s,t,m,q;

  cin>>n>>m;

  for(int i=0;i<m;i++){
    cin>>s>>t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  assignColor();

  cin>>q;

  for(int i=0;i<q;i++){
    cin>>s>>t;
    if(color[s]==color[t]){
      cout<<"yes"<<endl;
    }
    else{
      cout<<"no"<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 8992
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(void) {
    stack<int> S1;
    stack<pair<int, int>> S2;

    int pos = 0, sum = 0;
    char ch;
    while (cin >> ch) {
        if (ch == '\\') {
            S1.push(pos);
        } else if (ch == '/' && S1.size() > 0) {
            int ppos = S1.top(); S1.pop();
            sum += pos - ppos;
            int div = pos - ppos;
            while (S2.size() > 0 && S2.top().first > ppos) {
                div += S2.top().second; S2.pop();
            }
            S2.push(make_pair(ppos, div));
        }
        pos++;
    }

    vector<int> divs;
    while (!S2.empty()) {
        divs.push_back(S2.top().second);
        S2.pop();
    }
    reverse(divs.begin(), divs.end());
    cout << sum << endl;
    cout << divs.size();
    for (auto i = 0; i < divs.size(); i++) {
        cout << " " << divs[i];
    }
    cout << endl;

    return 0;
}

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

int main(){
	int N;
	cin>>N;
	int K[N],P[N];
	for(int i=0; i<N; i++){
		cin>>K[i]>>P[i];
	}
	for(int i=0; i<N; i++){
		int ans=K[i]%P[i];
		if(ans==0){
			cout<<P[i]<<endl;
		}
		else{
			cout<<ans<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

ll dp[110][100010];
ll sum[110][100010];

int main(){
    int n, k; cin>>n>>k;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    for(int i=0; i<=a[0]; i++){
        dp[1][i] = 1;
        sum[1][i+1] = sum[1][i] + dp[1][i]; 
    }

    ll ub=a[0];
    for(int i=1; i<n; i++){
        for(ll j=0; j<=100000; j++){

            dp[i+1][j] += (sum[i][min(j+1, ub+1)] - sum[i][max(0LL, j-a[i])]);
            dp[i+1][j] += MOD;
            dp[i+1][j] %= MOD;

            sum[i+1][j+1] = sum[i+1][j] + dp[i+1][j];
            sum[i+1][j+1] %= MOD;

        }
        ub += a[i];
    }

    /*
    for(int i=0; i<=n; i++){
        cout << i << " : ";
        for(int j=0; j<=k; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
    
    cout << dp[n][k] << endl;
}

Measured memory_bytes: 159232
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char s[] = br.readLine().toCharArray();
		char t[] = br.readLine().toCharArray();
		br.close();

		int row = t.length;
		int col = s.length;
		int tb[][] = new int[row + 1][col + 1];

		for ( int r = 0; r < row; r++ ) {
			for ( int c = 0; c < col; c++ ) {
				if ( t[r] == s[c] ) {
					tb[r + 1][c + 1] = tb[r][c] + 1;
				} else {
					tb[r + 1][c + 1] = Math.max(tb[r + 1][c], tb[r][c + 1]);
				}
			}
		}

		int r = row;
		int c = col;
		ArrayDeque<Character> stack = new ArrayDeque<Character>();
		stack.add(' ');
		while ( tb[r][c] != 0 ) {

//			// 左上に行けるとき
//			if ( tb[r - 1][c - 1] == tb[r][c] ) {
//				r -= 1;
//				c -= 1;
//			} else
			// 上
			if ( tb[r - 1][c] == tb[r][c] ) {
				r -= 1;
			} else
			// 左
			if ( tb[r][c - 1] == tb[r][c] ) {
				c -= 1;
			} else
			// 行き止まり
			{
				stack.addFirst(s[c - 1]);
				r -= 1;
				c -= 1;
			}
		}

		StringBuilder sb = new StringBuilder();
		while ( stack.size() > 0 ) {
			sb.append(stack.pollFirst());
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 80340
#include <stdio.h>

int main()
{
    long long A[101][101];
    long long B[101][101];
    long long C[101][101];
    int i,j;
    for(i=0;i<101;i++){
        for(j=0;j<101;j++){
            A[i][j]=0;
            B[i][j]=0;
            C[i][j]=0;
        }
    }
    int n,m,l;
    scanf("%d %d %d\n",&n,&m,&l);
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            if(j==m-1){
                scanf("%lld\n",&A[i][j]);
            }else{
                scanf("%lld ",&A[i][j]);
            }
        }
    }
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            if(j==l-1 && i!=m-1){
                scanf("%lld\n",&B[i][j]);
            }else{
                scanf("%lld ",&B[i][j]);
            }
        }
    }
    
    int k;
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            for(k=0;k<m;k++){
                C[i][j] += A[i][k]*B[k][j];
            }
        }
    }

    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            if(j!=l-1){
                printf("%lld ",C[i][j]);
            }else{
                printf("%lld\n",C[i][j]);
            }
        }
    }
    return 0;
}


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

int main(void){
	int N;
	long int a[100];
	
	cin >> N;
	for (int i = 0; i < N; i++) cin >> a[i];
	long int min_num = a[0], max_num = a[0];
	for (int i = 1; i < N; i++){
		min_num = min(min_num, a[i]);
		max_num = max(max_num, a[i]);
	}
	cout << max_num - min_num << endl;
	return 0;
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)
N, M = map(int, input().split())
X = list(map(int, input().split()))
UF = UnionFind(N)
for i in range(M):
    a, b = map(int, input().split())
    UF.union(a, b)
ans = 0
for i in range(N):
    if UF.same_check(X[i], i+1):
        ans += 1
print(ans)

Measured memory_bytes: 93548
#include<bits/stdc++.h>
using namespace std;
#define ll int
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vs vector<string>
#define vii vector<pii>
#define mi map<ll,ll>
#define mii map<pii,ll>
#define mc map<char,ll>
#define itr ::iterator
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fe(i,a,b) for(ll i=a;i<=b;i++)
#define fn(i,a,b) for(ll i=a;i>b;i--)
#define fne(i,a,b) for(ll i=a;i>=b;i--)
#define fm(it,m) for(it = m.begin();it != m.end();++it)
#define all(v) v.begin(),v.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define M 1000000007
#define pi 3.14159265358979323846
int dp[100005][3] = {0};
int a[100005][3];

int main()
{  
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
   IOS;
   
   // int T=1;
   // cin>>T;
   // f(t,0,T)
   //  { 
      ll n=0,i=0,j=0,k=0,ans=INT_MIN;
      cin>>n;
      
      f(i,0,n)
       cin>>a[i][0]>>a[i][1]>>a[i][2];

      dp[0][0] = a[0][0];
      dp[0][1] = a[0][1];
      dp[0][2] = a[0][2];

      ans = max(dp[0][0],max(dp[0][1],dp[0][2]));

      f(i,0,n-1)
       { 
         f(j,0,3)
          {
            dp[i+1][(j+1)%3] = max(dp[i+1][(j+1)%3],dp[i][j] + a[i+1][(j+1)%3]);
            dp[i+1][(j+2)%3] = max(dp[i+1][(j+2)%3],dp[i][j] + a[i+1][(j+2)%3]);

            ans = max(ans,dp[i+1][(j+1)%3]);
            ans = max(ans,dp[i+1][(j+2)%3]);
          }
       }
       
      cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 5964
import itertools
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    a=tuple(map(int, input().split()))
    b=tuple(map(int,input().split()))
    l=list(itertools.permutations(range(1,n+1)))
    aa=l.index(a)
    bb=l.index(b)
    print(abs(aa-bb))
resolve()

Measured memory_bytes: 8052
X = int(input())
if X == 2:
    print(2)
    exit()
while True:
    N = int(X**0.5)
    for i in range(1,N):
        if X % (i+1) == 0:
            break
        else:
          if i == N - 1:
            print(X)
            exit()
    X += 1

 


 
      
    



Measured memory_bytes: 38512
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    string in;
    cin>>in;
    for(long long a=0;a<=in.length()-1;a++)
    {
        if(in[a]!=',')
        {
            cout<<in[a];
        }
        else
        {
            cout<<" ";
        }
    }
    cout<<endl;
} 

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

using namespace std;

void solve(void)
{
	int a, b;
	string s;
	cin >> a >> b >> s;
	s[b - 1] -= 'A' - 'a';
	cout << s << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
n, k = [0] * 2

def format_input(filename = None):
	global n, k
	if filename == None:
		n, k = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		n = rng(0, 10**18)
		k = rng(1, 10**18)
		print(n, k)

def get_answer():
	mod = n % k
	answer = min(mod, k - mod)
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
using namespace std;
int N, H, amax = 0, b[100001], ans;
int main() {
  scanf("%d %d", &N, &H);
  for(int i = 1, a; i <= N; ++i) {
    scanf("%d %d", &a, &b[i]);
    amax = max(amax, a);
  }
  sort(b+1, b+N+1);
  for(int i = N; i > 0; --i) {
    if(b[i] <= amax) break;
    H -= b[i]; ++ans;
    if(H <= 0) break;
  }
  if(H > 0) ans += (H+amax-1)/amax;
  printf("%d\n", ans);
}

Measured memory_bytes: 640
#include <stdio.h>

int main(){
    int i,k,j,n,a,num;
    int data[200][3];
    int sum[200] = {};
    scanf("%d",&n);
    for(k = 0;k<n;k++){
        for(i = 0;i<3;i++){
            scanf("%d",&data[k][i]);
        }
    }
    for(i = 0;i<3;i++){
        for(j = 0;j<n;j++){
            a = j;
            num = data[a][i];
            for(k = j+1;k<n;k++){
                if(data[k][i] == num){
                    data[k][i] = 0;
                    data[a][i] = 0;
                }
            }
        }
    }
    for(k = 0;k<n;k++){
        for(i = 0;i<3;i++){
            sum[k] = sum[k] + data[k][i];
        }
    }
    for(k = 0;k<n;k++){
        printf("%d\n",sum[k]);
    }
    return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()){

			int num1 = sc.nextInt();
			int num2 = sc.nextInt();

			int total = num1 + num2;
			String str = Integer.toString(total);

			System.out.println(str.length());

		}
	}
}

Measured memory_bytes: 26224
#include <iostream>

using namespace std;

int main()
{
	int N, K;
	bool num[10] = {};
	cin >> N >> K;
	
	for (int i = 0; i < K; i++) {
		int d;
		cin >> d;
		num[d] = true;
	}
	int ans = 0;
	for (int i = 0; i < 100000; i++) {
		int tmp = N + i;
		bool isAns = true;
		while (tmp > 0) {
			int d = tmp % 10;
			if (num[d]) {
				isAns = false;
				break;
			}
			tmp /= 10;
		}
		if (isAns) {
			ans = N + i;
			break;
		}
	}
	cout << ans << endl;

}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.BigInteger;
 
public class Main {
	public static long twoCount(long a){
		long count = 0;
		while(a%2 == 0){
			a = a/2;
			count++;
		}
		return count;
	}

	private static long calcGcd(long m, long n) {
        if (m <= 0 || n <= 0) {
            throw new IllegalArgumentException("Arguments must be 1 and over.");
        }
        if(m < n) {
            long tmp = m;
            m = n;
            n = tmp;
        }
        long remainder = 0;
        while ((remainder = m % n) != 0) {
            m = n;
            n = remainder;
        }
        return n;
    }

    private static long calcLcm(long m, long n) {
        return m * n / calcGcd(m, n);
    }
	
	public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	int N = s.nextInt();
	int M = s.nextInt();
	long[] A = new long[N];
	for(int i = 0; i < N; i++){
		A[i] = s.nextInt()/2;
	}

	boolean isExist = true; 
	for(int i = 0; i < N-1; i++){
		if(twoCount(A[i]) != twoCount(A[i+1])) isExist = false;
	}
	

	if(isExist){
		long maxLcm = A[0];
		boolean swi = false;
		for(int i = 0; i < N; i++){
			maxLcm = calcLcm(A[i], maxLcm);
			if(maxLcm > M){
				swi = true;
				break;
			}
		}
		if(swi){
			System.out.println(0);
		}else{
			System.out.println((M/maxLcm+1)/2);
		}
	}else{
		System.out.println(0);
	}
    
  }
}

Measured memory_bytes: 60220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin >>a>>b;
  c=a*b;
  if(c%2 == 0){
      cout <<"Even"<<endl;
  }
   else{
     cout <<"Odd"<<endl;
   }
  }

Measured memory_bytes: 256
import itertools
import math
import fractions
import functools
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = []
for i in range(m):
    ai, bi = map(int, input().split())
    ab.append([ai-1,bi-1])

v = [True]*n
for i in range(m):
    if h[ab[i][0]] > h[ab[i][1]]:
        v[ab[i][1]] = False
    elif h[ab[i][0]] < h[ab[i][1]]:
        v[ab[i][0]]= False
    else:
        v[ab[i][0]]= False
        v[ab[i][1]]= False

print(v.count(True))

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

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

    if(N==1){
        if(M==1){
            cout << 1 << endl;
        }
        else
        {
            cout << M-2 << endl;
        }
    }
    else{
        if(M==1){
            cout << N-2 << endl;
        }
        else{
            cout << (N-2)*(M-2) << endl;
        }
    }

    return 0;
}

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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 10e-10;

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

    ll ans = LLONG_MAX;
    rep(n-k+1){
        ll tmp_ans;
        if(a[i] * a[i+k-1] > 0LL){
            tmp_ans = max(abs(a[i]), abs(a[i+k-1]));
        }else{
            if(abs(a[i]) < abs(a[i+k-1])){
                tmp_ans = abs(a[i]) * 2LL + abs(a[i+k-1]);
            }else{
                tmp_ans = abs(a[i+k-1]) * 2LL + abs(a[i]);
            }
        }
        ans = min(ans, tmp_ans);
    }
    cout << ans << endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d,e,k,j;
  cin >> a >> b >> c >> d >> e >> k;
  j = max({b-a,c-a,d-a,e-a,c-b,d-b,e-b,d-c,e-c,e-d});
  if(j<=k){
    cout << "Yay!" << endl;
  }
  else{
    cout << ":(" << endl;
  }
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

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


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;


ll f(ll b, ll n) {
    if (n < b) return n;
    return f(b, n / b) + n % b;
}


int main() {
    stack<char> stack;

    string s;
    cin >> s;
    for (char c : s) {
        if (c == 'B') {
            if (!stack.empty()) {
                stack.pop();
            }
        } else {
            stack.push(c);
        }
    }

    string ans = "";
    while (!stack.empty()) {
        ans += stack.top();
        stack.pop();
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;


}

Measured memory_bytes: 256
n, y = gets.split(' ').map(&:to_i)

(0..n).each do |i|
        nj = n - i
        (0..nj).each do |j|
                k = n - i - j
                if i * 10000 + j * 5000 + k * 1000 == y
                        puts "#{i} #{j} #{k}"
                        exit
                end
        end
end

puts '-1 -1 -1'

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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


	int n;
	cin >> n;

	int tmp_n = n;
	int odd_scale = 10;
	int res = 0;

	while (1) {
		if ((tmp_n - odd_scale) >= 0) {
			if (odd_scale == 10)
				res += 9;
			else
				res += (odd_scale - odd_scale / 10);
			odd_scale *= 100;
			continue;
		}

		if (tmp_n - (odd_scale / 10) >= 0)
			res += tmp_n - (odd_scale / 10) + 1;
		break;
	}

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

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

int main(void){
    int x, y, max_x, max_y, num_cannot_pass;
    while(std::cin >> max_x >> max_y >> num_cannot_pass){
        if(max_x == 0 && max_y ==0)
            break;
        std::vector<std::vector<int> > crossing(max_x + 1, std::vector<int>(max_y + 1, 0));
        
        crossing[1][1] = 1;
        for(int i = 1; i <= num_cannot_pass; ++i){
            std::cin >> x >> y;
            crossing[x][y] = -1;
        }
        for(int i = 1; i <= max_x; ++i){
            for(int j = 1; j <= max_y; ++j){
                if(i !=1 || j != 1){
                    if(crossing[i][j] == -1){
                        crossing[i][j] = 0;
                        continue;
                    }
                    crossing[i][j] = crossing[i - 1][j] + crossing[i][j - 1];
                }
            }
        }
        std::cout << crossing[max_x][max_y] << std::endl;
    }
}

Measured memory_bytes: 1220
#ifdef __GNUC__
#include <bits/stdc++.h>
#else
#include "bits/stdc++.h"
#define scanf scanf_s
#endif
#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define WHL(i) while(i)
#define putn printf("\n")
using namespace std;


template<class T> istream& operator >> (istream &is, vector<T> &vec) {
	for (T &x : vec)is >> x;
	return is;
}

int main ()
{
	int num, searched = 0, maxval = 0;

	scanf ("%d", &num);
	vector<int> nums (num);
	cin >> nums;

	sort (nums.begin (), nums.end ());
	cout << nums[num - 1] - nums[0] << endl;

}



Measured memory_bytes: 256
<?php
$a = array('a'=>'A','b'=>'B','c'=>'C','d'=>'D','e'=>'E','f'=>'F','g'=>'G','h'=>'H','i'=>'I','j'=>'J','k'=>'K','l'=>'L','m'=>'M','n'=>'N','o'=>'O','p'=>'P','q'=>'Q','r'=>'R','s'=>'S','t'=>'T','u'=>'U','v'=>'V','w'=>'W','x'=>'X','y'=>'Y','z'=>'Z');
fscanf(STDIN, "%s %s %s", $s1, $s2, $s3);
echo $a[$s1[0]] . $a[$s2[0]] . $a[$s3[0]];

Measured memory_bytes: 3828
#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;

const ll mod = 1e9+7;

int main(){  
  string s;
  cin>>s;
  int n = s.size();
  
  vector<vector<ll>> dp(100002,vector<ll>(13));
  if(s[0] == '?') rep(i,10) dp[0][i] = 1;
  else dp[0][(s[0]-'0')] = 1;
  
  rep(i,n-1){
    if(s[i+1]=='?'){
      rep(j,13)rep(k,10){
        dp[i+1][(10*j+k)%13] += dp[i][j]; 
        dp[i+1][(10*j+k)%13] %= mod;
      }
    }else{
      rep(j,13){
        dp[i+1][(10*j+(s[i+1]-'0'))%13] += dp[i][j];
        dp[i+1][(10*j+(s[i+1]-'0'))%13] %= mod;
      }
    }
  }
  cout << dp[n-1][5];
}

Measured memory_bytes: 13568
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007
#define mp(a,b) make_pair(a,b)

ll N,Q;
string s;
char t[200010];
char d[200010];
char Move[200010];

bool checkleft(ll a){
    if (a < 0 || a > N-1) return false;
    ll active = a;
    rep(i,Q){
        if (Move[active] == t[i]){
            if (d[i] == 'R'){
                active++;
            }
            else active--;
            if (active > N-1) return false;
            if (active < 0) return true;
        }
    }
    return false;
}

bool checkright(ll a){
    if (a < 0 || a > N-1) return false;
    ll active = a;
    rep(i,Q){
        if (Move[active] == t[i]){
            if (d[i] == 'R'){
                active++;
            }
            else active--;
            if (active < 0) return false;
            if (active > N-1) return true;
        }
    }
    return false;
}

int main() {
    cin >> N >> Q;
    cin >> s;
    rep(i,Q) cin >> t[i] >> d[i];
    rep(i,N){
        Move[i] = s[i];
    }
    ll left = -1;
    ll right = N;
    
    ll le1=0;
    ll ri1 = N;
    while(le1+1<ri1){
        ll mid = (le1+ri1)/2;
        if (checkleft(mid)){
            le1 = mid;
        }
        else ri1 = mid;
    }
    if (checkleft(ri1)) left = ri1;
    else if(checkleft(le1)) left = le1;
    
    ll le2=0;
    ll ri2 = N;
    while(le2+1<ri2){
        ll mid = (le2+ri2)/2;
        if (checkright(mid)){
            ri2 = mid;
        }
        else le2 = mid;
    }
    if (checkright(le2)) right = le2;
    else if(checkright(ri2)) right = ri2;
    ll ans = right-left-1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1156
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  int p,q,r;
  cin>>p>>q>>r;
  ou(min(min(p+q,p+r),q+r));
}

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

using namespace std;

int n;

int main()
{
  cin >> n;

  int ds[] = {2,3,4,6};
  unordered_set<int> result;
  if (n == 3) {
    result.insert({2, 5, 63});
  } else if (n == 4) {
    result.insert({2, 5, 20, 63});
  } else if (n == 5) {
    result.insert({2, 5, 20, 30, 63});
  } else {
    int s = 0;
    int last = 0;
    for (int k = 0; result.size() < n; k++) {
      for (int d = 0; d < 4 && result.size() < n; d++) {
        last = 6*k+ds[d];
        result.insert(last);
        s += last;
      }
    }

    if (s % 6 == 2) {
      result.erase(8);
      result.insert((last / 6 + 1) * 6);
    } else if (s % 6 == 3) {
      result.erase(9);
      result.insert((last / 6 + 1) * 6);
    } else if (s % 6 == 5) {
      result.erase(9);
      result.insert(last / 6 * 6 + 4);
    }
  }

  for (int v : result)
    cout << v << " ";
  cout << endl;

  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
char a[100050];
int c[100050];
int main()
{
	cin>>(a+1);
	int n=strlen(a+1);
	for(int i=1;i<=n;i++)c[i]=1;
	for(int i=1;i<n;i++)
	{
		if(a[i]=='R'&&a[i+1]=='R')c[i+1]+=c[i],c[i]=0;
	}
	for(int i=n;i>1;i--)
	{
		if(a[i]=='L'&&a[i-1]=='L')c[i-1]+=c[i],c[i]=0;
	}
	for(int i=1;i<n;i++)
	{
		if(a[i]=='R'&&a[i+1]=='L')
		{
			int x=c[i]/2,y=c[i]-x,z=c[i+1]/2,w=c[i+1]-z;
			c[i]=y+z;
			c[i+1]=x+w;
		}
	}
	for(int i=1;i<=n;i++)printf("%d ",c[i]);
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,k;
vector<P> edge;

void solve(){
    cin >> n >> k;
    if (((n-1)*(n-2))/2<k){
        cout << -1 << endl;
        return;
    }
    Rep(i,1,n){
        edge.push_back(P(0,i));
    }
    int a = ((n-1)*(n-2))/2;
    Rep(i,1,n){
        Rep(j,1,i){
            if (a==k) break;
            edge.push_back(P(j,i));
            a-=1;
        }
    }
    cout << edge.size() << endl;
    rep(i,edge.size()){
        int p=edge[i].first,q=edge[i].second;
        cout << p+1 << " " << q+1 << endl;
    }
}

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

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

template<typename T>
void eraseAt(vector<T>& v,unsigned int idx){
  v.erase(v.begin()+idx);
}

int main(){ _;
  int n,k,m;
  while(cin>>n>>k>>m,(n|k|m)!=0){
    m--;
    vector<int> v;
    v.reserve(n);
    REP(i,n)v.push_back(i+1);
    for(int i=n-1;i>0;i--){
      eraseAt(v,m);
      m+=i-1;
      m+=k;
      m%=i;
    }
    cout<<v[0]<<endl;
  }
}

Measured memory_bytes: 1256
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

int main(){
	ll n;
	scanf("%lld",&n);
	if( n&1 ){
		printf("0\n");
		return 0;
	}
	n/=2;
	ll ans=0, now=5;
	while( now<=n ){
		ans+= n/now;
		now*=5;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include "stdio.h"

int sort(int a[], int x){
  int box;

  for(int i = 0; i < x; i++){
    for(int j = x-1; j > i; j--){
      if(a[j] < a[j-1]){
        box =a[j];
        a[j] = a[j-1];
        a[j-1] = box;
      }
    }
  }

  return 0;
}

int main(void){
   int N;
   int count = 1;
   int d[120];

   scanf("%d", &N);

   for(int i = 0; i < N; i++){
     scanf("%d", &d[i]);
   }

   sort(d,N);

   for(int j = 0; j < N-1; j++){
     if(d[j] != d[j+1]){
       count++;
     }
   }

   printf("%d\n",count);

   return 0;
}


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

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int N,D,A,seg_len;
vector<pair<ll,ll>> enemy;
ll seg[1000000];

void init(int _n){
	seg_len = 1;
	while(seg_len <= _n)seg_len *= 2;
	rep(i,_n){
		seg[i+seg_len] = enemy[i].second;
	}
}

void add(int l, int r, ll x){
	l += seg_len;
	r += seg_len;
	while(l<r){
		if(l%2 == 1){seg[l] += x; ++l;}
		if(r%2 == 1){seg[r-1] += x; --r;}
		l /= 2; r /= 2;
	}
}

ll get(int k){
	k += seg_len;
	ll res = 0;
	while(k>0){
		res += seg[k];
		k /= 2;
	}
	return res;
}

int main(){
	cin>>N>>D>>A;
	enemy.resize(N);
	rep(i,N)cin>>enemy[i].first>>enemy[i].second;
	sort(all(enemy));
	vector<ll> enemy_dist(N); rep(i,N)enemy_dist[i] = enemy[i].first; 
	ll ans = 0;
	init(N);
	rep(i,N){
		ll now = get(i);
		if(now<0)continue;
		ll attack = now/A + (now%A != 0);
		ll dist = enemy[i].first + 2*D;
		int r = upper_bound(enemy_dist.begin(), enemy_dist.end(), dist)-enemy_dist.begin();
		add(i,r, -attack*A);
		ans += attack;
		// cout<<line<<endl;
		// REP(i,seg_len*2-1){printf("[%d]:%lld\n",i,seg[i]);}
		// cout<<line<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 8576
a = list(map(int, input().split()))
x = abs(a[0]-a[1])
y = abs(a[1]-a[2])
z = abs(a[2]-a[0])
m = max(x, y, z)
if m == x:
  print(y+z)
elif m == y:
  print(x+z)
else:
  print(x+y)

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

int main( )
{
    string s;
    int i, j, k, l;
    cin >> s;
    l = (int) s.size();
    for (k = 0; k < l; k++) {
        if (s[k] == 'A') { i = k; break; }
    }
    for (k = l - 1; k >= 0; k--) {
        if (s[k] == 'Z') { j = k; break; }
    }
    cout << (j - i + 1) << '\n';
    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define FastRead  ios_base::sync_with_stdio(0);cin.tie(0);
int main()
{
    string inp;
    FastRead
    cin>>inp;
    int len = inp.size()-8;
    for(int i=0; i<len; i++)
        cout<<inp[i];
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
//-----------------------------B-I-G------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define what_is(x) cerr << #x << " is " << x << endl;
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
string binary(ll n){if(n==0) return "0"; string s; while(n>0){ if(n&1) s+='1'; else s+= '0'; n>>=1;}  reverse(s.begin() , s.end()); return s; }

const ll M = 1000000007;

void solve(){
	ll n, m, x, i, j, ok, k;
	cin >> n >> m >> x;
	ll a[n][m];
	ll c[n];
	for( i = 0 ; i < n ; i++ ){
		cin >> c[i];
		for( j = 0 ; j < m ; j++ )
			cin >> a[i][j];
	}

	ll val = (1LL<<n);
	ll ans = 1e15, sum;
	for( ll i = 0 ; i < val ; i++ ){
		ok = i;
		vector<ll> v(n,0);
		sum = 0;
		for( j = 0 ; ok > 0 ; ok >>= 1, j++ ){
			if( ok&1 ){
				sum += c[j];
				for( k = 0 ; k < m ; k++ )
					v[k] += a[j][k];
			}
		}
		bool f = true;
		for( j = 0 ; j < m ; j++ ){
			if( v[j] < x ){
				f = false;
				break;
			}
		}
		if( f )
			ans = min( ans, sum );
	}
	cout << ( ans != 1e15 ? ans : -1 ) << endl;
}

signed main(){
        fast;
        ll t=1;
        // cin >> t;
        while( t-- )
        solve();
        return 0;
}
//-----------------------------B-I-G------------------------------------------------

Measured memory_bytes: 3660
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 19;
ll i,j,k,n,d,ans;;
long double s,g,a[N][N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n>>d;
    rep(i,0,n) rep(j,0,d) cin>>a[i][j];
    rep(i,1,n) rep(j,0,i){
        s = 0;
        rep(k,0,d) s += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
        g = sqrt(s);
        if(g == (ll) g) ans += 1;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256