akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using P = pair<int,int>;

int main(){
  long ans=0;
  int b,n;
  vector<vector<int>> a(10, vector<int>(10, 0));
  cin >>n;
  for(int i=1;i<=n;i++){
    b = i;
    while (b/10 > 0) b/=10;
    a[b][i%10]++;
  }
  rep(i,10) rep(j,10) ans+=a[i][j]*a[j][i];
  cout << ans << endl;
}

Measured memory_bytes: 256
import numpy as np

N,M = list(map(int,input().split()))
arr = [[] for i in range(N)]

for i in range(M):
    a,b = map(int,input().split())
    arr[a-1].append(b-1)
    arr[b-1].append(a-1)

for i in range(len(arr)):
    arr[i].sort


def dfs(array,point,cnt):
    
    if(array[point]==[]):
        return cnt

    tmparr = array.copy()
    ps = tmparr[point]
    tmparr[point] = []
    
    if sum(map(len,tmparr)) == 0:
        return cnt+1
    
    for p in ps:
        #print(tmparr, p)
        cnt = dfs(tmparr,p,cnt)
    
    return cnt

print(dfs(arr,0,0))

Measured memory_bytes: 18596
object Main {
  def main(args:Array[String]) = {
   // val seq = readLine.split("")
    val input=io.Source.stdin.getLines().mkString("\n")
    println(solve(input).trim())
  }

def solve(aaa:String): String={
  val seq = aaa.split(" ").map(_ .toInt)
  if(seq(0) < seq(1)){"0"} else {"10"}
}
}


Measured memory_bytes: 27324
from collections import deque

h, w = map(int, input().split())
sy, sx = 1, 1
gy, gx = h, w
map = [input() for _ in range(h)]

cnt = 0
for s in map:
    cnt += s.count(".")

f_inf = float('inf')
maze = [[f_inf] * w for _ in range(h)]
maze[sy-1][sx-1] = 0
que = deque([[sy-1, sx-1]])
while que:
    y, x = que.popleft()
    for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        next_y, next_x = y + i, x + j
        if next_y > -1 and next_x > -1 and next_y < h and next_x < w and map[next_y][next_x] == ".":
            if maze[next_y][next_x] > maze[y][x] + 1:
                maze[next_y][next_x] = maze[y][x] + 1
                que.append([next_y, next_x])

if maze[gy - 1][gx - 1] != f_inf:
    print(cnt - (maze[gy - 1][gx - 1] + 1))
else:
    print(-1)

Measured memory_bytes: 3316
a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i
e = gets.to_i
k = gets.to_i

arr = [a, b, c, d, e].sort!

first = arr.first
last = arr.last

if (last - first) > k
  puts ':('
else
  puts 'Yay!'
end


Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        Dice dice = new Dice(str);
        str = br.readLine();    //??¢???????????????????????????

        for(int i = 0; i < str.length(); i++){
            char c = str.charAt(i);
            switch(c){
            case 'E':
                dice.moveE();
                break;

            case 'N':
                dice.moveN();
                break;

            case 'S':
                dice.moveS();
                break;

            case 'W':
                dice.moveW();
                break;
            }
        }
        System.out.println(dice.getTop(0));
    }
}

class Dice{
    private String[] str;
    private String tmp;

    Dice(String str){
        this.str = new String[6];
        this.str = str.split(" ");
    }
    public String getTop(int n){
        return this.str[n];

    }
    public void moveE(){
        tmp = this.str[0];
        this.str[0] = this.str[3];
        this.str[3] = this.str[5];
        this.str[5] = this.str[2];
        this.str[2] = tmp;
    }
    public void moveN(){
        tmp = this.str[0];
        this.str[0] = this.str[1];
        this.str[1] = this.str[5];
        this.str[5] = this.str[4];
        this.str[4] = tmp;
    }
    public void moveS(){
        tmp = this.str[0];
        this.str[0] = this.str[4];
        this.str[4] = this.str[5];
        this.str[5] = this.str[1];
        this.str[1] = tmp;
    }
    public void moveW(){
        tmp = this.str[0];
        this.str[0] = this.str[2];
        this.str[2] = this.str[5];
        this.str[5] = this.str[3];
        this.str[3] = tmp;
    }
}

Measured memory_bytes: 24444
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  int N,M,X,Y;cin >> N >> M >> X >> Y;
  int x[N],y[M];
  rep(i,N) cin >> x[i];
  rep(i,M) cin >> y[i];
  sort(x,x+N);
  sort(y,y+M);
  bool ans = false;
  for(int i=X+1;i<=Y;i++){
    if(x[N-1]<i&&y[0]>=i) ans = true;
  }
  cout << (ans?"No War":"War") << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
#debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    n = II()
    print(n*n*n)
solve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, ss, ee) for (int i = (ss); i < (ee); ++i)

void solve() {
  int N;
  cin >> N;

  vector<int> x(N), y(N);
  rep(i, 0, N) cin >> x[i] >> y[i];

  vector<int> p(N);
  rep(i, 0, N) p[i] = i;

  double sum = 0;
  int cnt = 0;

  do {
    rep(i, 1, N) sum += hypot(x[p[i - 1]] - x[p[i]], y[p[i - 1]] - y[p[i]]);
    cnt++;
  } while (next_permutation(p.begin(), p.end()));

  double ans = sum / cnt;
  cout << fixed << setprecision(12) << ans << endl;
}

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

Measured memory_bytes: 3768
while n = gets.chomp.to_i
  if n == 0 then break end

  a = []
  n.times do |i|
    a << gets.to_i
  end

=begin

これでも可能
  a = []
  n.times do
    a.push(gets.chomp.to_i)
  end
  
array << obj
<<演算子（メソッド）は、左辺の配列（レシーバ）の末尾に右辺のオブジェクトを要素として加えます。

animals = ["dog", "cat", "mouse"]
animals << "pig"
p animals
["dog", "cat", "mouse", "pig"]

array.push(obj, ...)
pushメソッドは、配列の末尾に引数を要素として追加します。

animals = ["dog", "cat", "mouse"]
animals.push("duck", "parrot")
p animals
["dog", "cat", "mouse", "pig", "duck", "parrot"]

=end

 
  max = -100_000
  n.times do |i|
    sum = 0
    a[i..-1].each do |j|
      sum += j
      max = sum if sum > max
    end
  end
 
  puts max
end


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

int main()
{
  int n, b, f, r, v, i, j, k, a[4][3][10]={};
  cin >> n;

  for(i=0;i<n;i++)
    {
      cin >> b >> f >> r >> v;
      a[b-1][f-1][r-1] += v;
    }

  for(i=0;i<4;i++)
    {
      for(j=0;j<3;j++)
	{
	  for(k=0;k<10;k++)
	    cout << " " << a[i][j][k];

	  cout << endl;
	}
      if(i != 3) cout <<"####################"<<endl;
    }
}

Measured memory_bytes: 1160
open System

let inp = stdin.ReadLine().Split(' ') |> Array.map int
let N = inp.[0]
let Y = inp.[1]

let res = seq {
    for i in 0 .. N do
        for j in 0 .. N-i do
            let k = N - i - j
            if i * 10000 + j * 5000 + k * 1000 = Y then yield (i,j,k)
}


if Seq.isEmpty res then 
    printfn "-1 -1 -1"
else
    let (a,b,c) = Seq.head res
    printfn "%d %d %d" a b c 


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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    ll n;
    cin >> n;
    ll a, b;
    cin >> a >> b;

    OP(a * (n / (a + b)) + min(n - (a + b) * (n / (a + b)), a));

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<double> v(n);
    for(int i=0;i<n;i++)    cin >> v[i];
    sort(v.begin(),v.end());
    while(v.size()!=1){
        v.push_back((v[0]+v[1])/2);
        v.erase(v.begin()+1);
        v.erase(v.begin());
        sort(v.begin(),v.end());
    }
    cout << v[0];
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    int n;
    cin >> n;
    VI a(n);
    REP(i,n){
        scanf("%d", &a[i]);
        a[i]--;
    }

    int ans = 0;

    REP(i,n){
        if (a[i] == i){
            ans++;
            if (i < n-1) swap(a[i], a[i+1]);
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 640
//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    static long TIME_START, TIME_END;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(System.out);
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
        System.out.println("Memory increased:" + (usedMemoryAfter - usedMemoryBefore) / 1000000);
        System.out.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    public static class Task {

        public int GCD(int a, int b) { return b==0 ? a : GCD(b, a%b); }


        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int n = sc.nextInt();
            int x = sc.nextInt();
            int g = -1;
            for (int i = 0; i < n; i++) {
                int a = sc.nextInt();
                if (a != x) {
                    int b = Math.abs(x - a);
                    if (g == -1) {
                        g = b;
                    } else {
                        g = GCD(g, b);
                    }
                }
            }
            pw.println(g);
        }

    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader s) throws FileNotFoundException {
            br = new BufferedReader(s);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}

Measured memory_bytes: 37108
/*
      Bismillahir Rahmanir Rahim

    * @Author: SajidZakaria
    * @Date:   2018-02-05 13:37:49
    * @Last Modified by:   SajidZakaria
    * @Last Modified time: 2018-02-05 13:45:28
*/


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

int main(){
    long long x, y;
    cin >> x >> y;

    if(x%y==0)cout << -1;
    else cout << x;
}

Measured memory_bytes: 256
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    
    let s = get().as_bytes();
    
    let mut ans = 0;
    
    // 交換を眺めてみたら転倒数ぽい
    // 転倒数の求め方ググってもよく分からん
    
    let mut c = 0_i64;
    for &ch in s.iter() {
    	if ch == b'B'  {
        	c += 1;
        } else if ch == b'W' {
        	ans += c;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-4;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,m;cin>>n>>m;
	cout<<n*m<<endl;
	return 0;
}
//1000
//100
//10
//1


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

using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define all(v) v.begin(),v.end()
#define ve vector
#define vi vector<int>
#define vi2 vector<vi>
#define vl vector<long long>
#define vl2 vector<vl>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

int main(){
    int n, ans = 0;
    cin >> n;
    vl l(n);
    rep(i,n) cin >> l[i];
    sort(all(l));
    rep(i, n){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n; k++){
                if(l[i] == l[j] || l[j] == l[k]) continue;
                if(l[i] + l[j] > l[k]) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int tot=26+26+10;
char enc(int t){
	if(t<10)return '0'+t;
	t-=10;
	if(t<26)return 'a'+t;
	t-=26;
	return 'A'+t;
}

string s[tot];
int sum=tot;

// string Ans="Atcod3rIsGreat";
int ttm=0;
int query(string s){
	if(s.length()>128)return 0x3f3f3f3f;
	++ttm;
	if(ttm>=850)while(1);
	cout << "?" << " " << s << endl;
	fflush(stdout);
	int ans=0;
	// int t=0;
	// for(size_t q=0;q<Ans.length();q++){
	// 	if(t<s.length()&&s[t]==Ans[q]){
	// 		++t;
	// 	}
	// }
	// return t==s.size()?Ans.length()-t:Ans.length()-t+1;
	cin >> ans;
	return ans;
}


int len=0x3f3f3f3f;
int q[tot];

string merge(string a,string b){
	int i=0,j=0;
	int la=a.length(),lb=b.length();
	string fir=string();
	// int qTime=query(b+a);
	while(i<la&&j<lb){
		string qr=fir;
		qr+=a[i];
		for(int k=j;k<lb;k++){
			qr+=b[k];
		}
		if(query(qr)+qr.length()==len){
			fir+=a[i++];
		}else {
			fir+=b[j++];
		}
	}
	while(i<la)fir+=a[i++];
	while(j<lb)fir+=b[j++];
	// assert(query(fir)+fir.length()==len);
	return fir;
}

int main()
{
	for(int i=0;i<tot;i++){
		s[i]+=enc(i);
		q[i]=query(s[i])+1;
		len=min(len,q[i]);
	}
	for(int i=0;i<tot;i++){
		if(q[i]==len){
			while(query(s[i]+enc(i))+s[i].length()+1==len)s[i]+=enc(i);
		}else s[i]=string();
	}
	while(1){
		for(int i=0;i<tot;i++)for(int j=i+1;j<tot;j++)if(s[i].length()>s[j].length())swap(s[i],s[j]);
		int t=0;
		while(!s[t].length())++t;
		if(t+1==tot){
			break ;
		}
		string nw=merge(s[t],s[t+1]);
		s[t+1]=nw;
		s[t]=string();
		// cout << s[t+1] << "!" << endl;
	}
	assert(query(s[tot-1])==0);
	cout << "! "<< s[tot-1] << endl;
	fflush(stdout);
	// cerr << ttm << endl;
}

Measured memory_bytes: 3800
#include <iostream>

 
using namespace std;
 
int N, K, A[5000];
bool dp1[5002][5001];
int dp2[5002][5001];
 
 
int main()
{
  cin >> N >> K;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] = min(A[i], K);
  }
 
  dp1[0][0] = true;
  for(int i = 0; i < N; i++) {
    for(int j = K; j >= A[i]; j--) {
      dp1[i + 1][j] |= dp1[i][j - A[i]];
    }
    for(int j = K; j >= 0; j--) {
      dp1[i + 1][j] |= dp1[i][j];
    }
  }
 
  dp2[N][0] = true;
  for(int i = N - 1; i >= 0; i--) {
    for(int j = K; j >= A[i]; j--) {
      dp2[i][j] |= dp2[i + 1][j - A[i]] > 0;
    }
    for(int j = K; j >= 0; j--) {
      dp2[i][j] |= dp2[i + 1][j] > 0;
    }
  }
  for(int i = 0; i <= N; i++) {
    for(int j = 1; j <= K; j++) {
      dp2[i][j] += dp2[i][j - 1];
    }
  }
 
  int ret = N;
  for(int i = 1; i <= N; i++) {
    bool flag = false;
    for(int j = 0; j < K; j++) {
      if(dp1[i - 1][j]) {
        int x = K - A[i - 1] - j; // 以上
        int y = K - j; // 未満
        if(dp2[i][y - 1] - (x <= 0 ? 0 : dp2[i][x - 1]) > 0) {
          flag = true;
        }
      }
    }
 
    ret -= flag;
  }
 
  cout << ret << endl;
}

Measured memory_bytes: 122368
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	char c; cin>>c;
	++c;
	cout<<(char)c<<endl;

}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  string s,t;
  cin>>s>>t;
  int n,m;
  n=s.size();
  m=t.size();
  int ans=m;
  for(int i=0;i<n-m+1;i++){
    int x=0;
    for(int j=0;j<m;j++){
      if(s[i+j]!=t[j]) x++;
    }
    ans=min(ans,x);
  }
  cout<<ans<<endl;
}

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

int main() {
  int N;
  cin >> N;
  int A, B, C, D;
  A = N / 1000;
  N %= 1000;
  B = N / 100;
  N %= 100;
  C = N / 10;
  D = N % 10;
  
  if (A + B + C + D == 7) cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
  else if (A + B + C - D == 7) cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
  else if (A + B - C + D == 7) cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
  else if (A + B - C - D == 7) cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
  else if (A - B + C + D == 7) cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
  else if (A - B + C - D == 7) cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
  else if (A - B - C + D == 7) cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
  else cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
}


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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
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;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    double n;
    cin >> n;
    int x = n;
    double ans = 0.5;
    
    if(x%2!=0){
        double y = x/2;
        y++;
        ans = y/n;
    }
    cout << setprecision(10) << ans << endl;
}

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

int main()
{
	int n;
	long long sum=0;
	cin>>n;
	
	for(int i=1;i<=n;i++)
		if(i%3!=0 && i%5!=0)
			sum+=i;
	
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;

//Princess, a Cryptanalyst
public class Main{

	int n, INF = 1<<29, len;
	int[][] cut, dp;
	String[] s;
	String INFS = "?", res;
	boolean[] u;
	
	void dfs(int k, String str, int pre){
		if(len<str.length()||comp(str, res)>0)return;
		if(k==n){
			res = str; return;
		}
		for(int i=0;i<n;i++){
			if(u[i])continue;
			u[i] = true;
			String nx = "";
			if(pre==-1)nx = s[i];
			else nx = str+s[i].substring(cut[pre][i]);
			dfs(k+1, nx, i);
			u[i] = false;
		}
	}
	
	int get(int S, int last){
		if(dp[S][last]!=INF)return dp[S][last];
		int ns = S-(1<<last);
		if(ns==0)return dp[S][last] = s[last].length();
		int res = INF;
		for(int k=0;k<n;k++){
			if(((ns>>k)&1)==0)continue;
			int r = get(ns, k)+s[last].length()-cut[k][last];
			res = Math.min(res, r);
		}
		return dp[S][last] = res;
	}
	
	int comp(String a, String b){
		if(INFS.equals(a))return 1;
		if(INFS.equals(b))return -1;
		int m = Math.min(a.length(), b.length());
		for(int i=0;i<m;i++)if(a.charAt(i)!=b.charAt(i))return a.charAt(i)-b.charAt(i);
		return 0;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int N = sc.nextInt();
			if(N==0)break;
			String[] t = new String[N];
			for(int i=0;i<N;i++)t[i]=sc.next();
			boolean[] del = new boolean[N];
			for(int i=0;i<N;i++)for(int j=i+1;j<N;j++)if(t[i].equals(t[j]))del[j] = true;
			for(int i=0;i<N;i++)for(int j=0;j<N;j++){
				if(i==j||del[i]||del[j])continue;
				if(t[i].contains(t[j]))del[j] = true;
			}
			n = 0;
			for(boolean f:del)if(!f)n++;
			s = new String[n];
			int id = 0;
			for(int i=0;i<N;i++)if(!del[i])s[id++] = t[i];
			cut = new int[n][n];
			for(int i=0;i<n;i++)for(int j=0;j<n;j++){
				if(i==j)continue;
				for(int k=0;k<s[i].length();k++){
					if(s[j].startsWith(s[i].substring(k))){
						cut[i][j] = s[i].length()-k; break;
					}
				}
			}
			dp = new int[1<<n][n];
			for(int[]a:dp)Arrays.fill(a, INF);
			len = INF;
			for(int i=0;i<n;i++)len = Math.min(len, get((1<<n)-1, i));
			res = INFS;
			u = new boolean[n];
			dfs(0, "", -1);
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int> P;
char grid[10][10];
int step[10][10];
int h, w;
int dx[4] = {1, 0};
int dy[4] = {0, 1};
bool Check()
{
    int cnt = 0;
    for(int i = 1; i <= h; ++i)
        for(int j = 1; j <= w; ++j)
            if(grid[i][j] == '#')
                ++cnt;
    memset(step, -1, sizeof(step));
    step[1][1] = 1;
    queue<P> que;
    que.push({1, 1});
    while(!que.empty())
    {
        P now = que.front();
        que.pop();
        if(step[now.first][now.second] == cnt)
            return true;
        for(int i = 0; i < 2;++i)
        {
            int nx = now.first + dx[i];
            int ny = now.second + dy[i];
            if(grid[nx][ny] == '#')
            {
                que.push({nx, ny});
                step[nx][ny] = step[now.first][now.second] + 1;
            }
        }
    }
    return false;
}
int main()
{
    scanf("%d%d", &h, &w);
    for(int i = 1; i <= h; ++i)
        scanf("%s", grid[i] + 1);
    if(Check())
        puts("Possible");
    else
        puts("Impossible");
    return 0;
}

Measured memory_bytes: 256
# 0-indexed
class SegTree:
    def __init__(self, vals, seg_f, ide_ele):
        n = len(vals)
        self.seg_f = seg_f
        self.ide_ele = ide_ele
        self.leaf_n = 1 << (n-1).bit_length()
        self.tree = [ide_ele]*(2*self.leaf_n-1)
        for i in range(n):  # init leaf
            self.tree[i+self.leaf_n-1] = vals[i]
        for i in range(self.leaf_n-2, -1, -1):  # bottom-up
            self.tree[i] = self.seg_f(self.tree[2*i+1], self.tree[2*i+2])

    def update(self, i, x):
        i += (self.leaf_n-1)
        self.tree[i] = x
        while i > 0:
            i = (i-1)//2
            self.tree[i] = self.seg_f(self.tree[2*i+1], self.tree[2*i+2])

    # [l,r)
    def query(self, l, r):
        v_l = self.ide_ele
        v_r = self.ide_ele
        l += (self.leaf_n-1)
        r += (self.leaf_n-1)
        while l < r:
            if l&1 == 0:
                v_l = self.seg_f(v_l, self.tree[l])
            if r&1 == 0:
                v_r = self.seg_f(v_r, self.tree[r-1])
                r -= 1
            l >>= 1
            r >>= 1
        return self.seg_f(v_l ,v_r)


'''
memo:
GCD... INFをide_eleに設定して、片方がINFの場合はもう片方を返す
def gcd2(a,b):
    if a >= INF: return b
    elif b >= INF: return a
    else return gcd(a,b)


vl = [1,4,6,8,9]

def add(a,b): return a+b
st = SegTree(vl,add,0)
st = SegTree(vl,(lambda a,b: a+b),0)
st = SegTree(vl,min,10**10)

print(st.query(2,4))
st.update(4,-4)
print(st.query(2,5))
st.update(0,-10)
print(st.query(0,5))
'''

def main():
    vl = [0]*300001
    n,k = map(int, input().split())
    st = SegTree(vl,max,0)
    for _ in range(n):
        a = int(input())
        l = max(0,a-k)
        r = min(300001,a+k+1)
        curr_max = st.query(l,r)
        st.update(a,curr_max+1)

    ans = st.query(0,300001)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 84356
use std::io::stdin;

fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let (a, b) = {
        let mut ab = st.split_whitespace().map(|x| x.parse::<i64>().unwrap());
        (ab.next().unwrap(), ab.next().unwrap())
    };
    let mut result = -1;
    for i in 1..1001 {
        if i*8/100 == a && i/10 == b {
            result = i;
            break;
        }; 
    };
    println!("{}", result);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std ;
void Read ( int &x, char c = getchar(), bool f = 0 ) {
	for ( x = 0 ; !isdigit(c) ; c = getchar() ) if (c == '-') f = 1 ;
	for ( ; isdigit(c) ; c = getchar() ) x = 10*x + c - '0' ;
	if (f) x = -x ;
}
const int maxn = 2005 ;
int n, m ;
bitset <maxn*maxn> bt ;
int main() {
	int i, x, sum = 0 ;
	Read(n) ;
	sum = 0 ;
	bt.set(0) ;
	for ( i = 1 ; i <= n ; i ++ ) {
		Read(x) ;
		bt |= bt<<x ;
		sum += x ;
	}
	sum = (sum+1)>>1 ;
	for ( i = sum ; !bt[i] ; i ++ ) ;
	printf ( "%d\n", i ) ;
	return 0 ;
}

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

int main() {
    int n, t; cin >> n;
    vector<int> rec(n+1, 0);
    for (int i=1; i<n; i++) {
        cin >> t;
        rec[t]++;
    }
    for (int i=1; i<=n; i++) {
        cout << rec[i] << endl;
    }
    return 0;
}


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

// 0:42-0:05 20min
int main(void){
    char s[101], t[101]; 

    scanf("%s%s", s, t);

    // 何個ずらすか
    for(int i = 0; i < strlen(s); i++){
        // 回転させて一致する時があるか
        for(int j = 0; j < strlen(s); j++){
            int cnt = 0;
            cnt = j - i;
            if(cnt < 0){
                cnt = strlen(s) + cnt;
            }
//            fprintf(stderr, "s[%d] = %c t[%d] = %c\n", cnt, s[cnt], j, t[j]);
            if(s[cnt] != t[j]){
                break;
            }else if(j == strlen(s) - 1){
                printf("Yes\n");
                return 0;
            }
        }
    }

    printf("No\n");

    return 0;

} 



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
#define INF 0x3f3f3f3f
using namespace std;
typedef unsigned long long LL;
const int maxn=1e5+7;
const int mod=1e9+7;
int read(){        
    int s = 0, f = 1;        
    char ch = getchar();        
    while(!isdigit(ch)) {        
        if(ch == '-') f = -1;        
        ch = getchar();        
    }        
    while(isdigit(ch)) {        
        s = s * 10 + ch - '0';        
        ch = getchar();        
    }        
    return s * f;        
}        
int main(){
	int n,m;
	cin>>n>>m;
	cout<<n*(n-1)/2+m*(m-1)/2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
const int MOD=1000000007;
int inv[100001];
long long qpow(long long a,int b)
{
    long long ret=1;
    while (b)
    {
        if (b&1)
            (ret*=a)%=MOD;
        (a*=a)%=MOD;
        b>>=1;
    }
    return ret;
}
int main()
{
    int n;
    scanf("%d",&n);
    int init=1;
    for (int i=1;i<=n;++i)
        init=(long long)init*i%MOD;
    for (int i=1;i<=n;++i)
        inv[i]=qpow(i,MOD-2);
    for (int i=1;i<=n;++i)
    {
        inv[i]+=inv[i-1];
        if (inv[i]>=MOD)
            inv[i]-=MOD;
    }
    int ans=0;
    for (int i=1;i<=n;++i)
    {
        int x;
        scanf("%d",&x);
        ans+=((long long)inv[i]+inv[n-i+1]-inv[1])%MOD*x%MOD;
        if (ans>=MOD)
            ans-=MOD;
    }
    ans=(long long)ans*init%MOD;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 512
stdin.ReadLine()
|> fun x -> x.Split(' ')
|> Array.map int
|> fun x -> (x.[0], x.[1], x.[2])
|> fun (a, b, c) ->
    [1..a]
    |> Seq.tryFind (fun y -> (b * y + c) % a = 0)
    |> fun x ->
        match x with
        | Some(_) -> "YES"
        | None -> "NO"
|> printfn "%s"


Measured memory_bytes: 14160
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



template< typename T >
struct SparseTable {
  vector< vector< T > > st;
  vector< int > lookup;

  SparseTable(const vector< T > &v) {
    int b = 0;
    while((1 << b) <= v.size()) ++b;
    st.assign(b, vector< T >(1 << b));
    for(int i = 0; i < v.size(); i++) {
      st[0][i] = v[i];
    }
    for(int i = 1; i < b; i++) {
      for(int j = 0; j + (1 << i) <= (1 << b); j++) {
        st[i][j] = __gcd(st[i - 1][j], st[i - 1][j + (1 << (i - 1))]);
      }
    }
    lookup.resize(v.size() + 1);
    for(int i = 2; i < lookup.size(); i++) {
      lookup[i] = lookup[i >> 1] + 1;
    }
  }

  inline T query(int l, int r) {
    int b = lookup[r - l];
    return __gcd(st[b][l], st[b][r - (1 << b)]);
  }
};

int main(){
    int n;cin >> n;
    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    SparseTable<LL> st(a);
    LL ans = max(st.query(1,n),st.query(0,n-1));
    for (int i = 0; i < n; i++) {
        ans = max(ans,__gcd(st.query(0,i),st.query(i+1,n)));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 19584
use std::cmp::max;
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let _ = scan!(usize);
    let s = scan!();
    let mut ans = 0;
    let mut x = 0;
    for c in s.chars() {
        if c == 'I' {
            x += 1
        } else {
            x -= 1
        }
        ans = max(ans, x)
    }
    println!("{}", ans)
}


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

int main() {
  int H, N;
  cin >> H >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  
  int Asum = 0;
  
  for (int i =0; i < N; i++){
    Asum += A.at(i);
      }
  
  if ( Asum >= H ){
    cout << "Yes" << endl;
    }  
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  ll N,K;
  cin >> N >> K;
  ll cnt = 0;
  pair<int,int> p[N];
  for(int i=0;i<N;i++) cin >> p[i].first >> p[i].second;

  sort(p,p+N);

  for(int i=0;i<N;i++){
    if(cnt + p[i].second < K){
      cnt += p[i].second;
    }
    else{
      cout << p[i].first << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 1024
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  cin >> A;
  vector<ll> zip;
  //   for (int i = 0; i < N; i++) {
  //     zip.push_back(i - A[i]);
  //     zip.push_back(A[i] + i);
  //   }
  //   sort(all(zip));
  //   zip.erase(unique(all(zip)), zip.end());
  //   auto idx = [&](ll x) { return lower_bound(all(zip), x) - zip.begin(); };
  map<ll, ll> m;
  ll ans = 0ll;
  for (int i = 0; i < N; i++) {
    ans += m[i - A[i]];
    m[A[i] + i]++;
  }
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 27432
#include <cstdio>
#include <algorithm>

int main()
{
  int n, m, x;
  scanf("%d%d%d", &n, &m, &x);
  int t[2] = {0, 0};
  for (int i = 0; i < m; ++i)
  {
    int a;
    scanf("%d", &a);
    t[a < x ? 0 : 1]++;
  }
  printf("%d\n", std::min(t[0], t[1]));
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
typedef long long lint;

int n;
multiset<int> ms;

int main(){
	cin >> n;
	for(int i=0; i<n; i++){
		int x;
		cin >> x;
		ms.insert(x);
	}
	int r = *ms.rbegin();
	for(int i=0; i<=r; i++){
		int w = max(i, r-i);
		auto it = ms.find(w);
		if(it == ms.end()){
			puts("Impossible");
			return 0;
		}
		ms.erase(it);
	}
	for(auto &i : ms){
		if((r + 1) / 2 + 1 > i){
			puts("Impossible");
			return 0;
		}
	}
	puts("Possible");
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {

	int N;
	ll a[11234], b[11234];
	ll suma=0, sumb=0;

	scanf("%d", &N);

	rep(i, N) {
		scanf("%lld", &a[i]);
		suma += a[i];
	}
	rep(i, N) {
		scanf("%lld", &b[i]);
		sumb += b[i];
	}
	if (suma > sumb) {
		printf("No\n");
		return 0;
	}
	ll da = sumb - suma, db = da;

	rep(i, N) {
		if (!da) break;
		if (i < N - 1) {
			ll t = (b[i] - a[i] + 1) / 2;
			t = min(t, da);
			t = max(t, 0ll);
			a[i] += 2 * t;
			da -= t;
		}
		else {
			a[i] += 2 * da;
			da = 0;
		}
	}

	rep(i, N) {
		if (!db) break;
		if (i < N - 1) {
			ll t = a[i] - b[i];
			t = min(t, db);
			t = max(t, 0ll);
			b[i] +=  t;
			db -= t;
		}
		else {
			b[i] += db;
			db = 0;
		}
	}

	rep(i, N) {
		if (a[i] != b[i]) {
			printf("No\n");
			return 0;
		}
	}

	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 384
import sys
input=lambda: sys.stdin.readline().rstrip()
n,m=map(int,input().split())
def find(x):
  if par[x]<0:
    return x
  else:
    par[x]=find(par[x])
    return par[x]

def unite(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return False
  else:
    if par[x]>par[y]:
      x,y=y,x
    par[x]+=par[y]
    par[y]=x
    return True

def same(x,y):
  return find(x)==find(y)

def size(x):
  return -par[find(x)]

AB=[]
for i in range(m):
  AB.append(tuple(int(i) for i in input().split()))
ans=0
for i in range(m):
  par=[-1]*n
  for j in range(m):
    if j==i:
      continue
    else:
      a,b=AB[j]
      unite(a-1,b-1)
  for i in range(n):
    find(i)
  if -min(par)<n:
    ans+=1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << a+b+c-max(a,max(b,c));
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace::std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define endl "\n"
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/io.hpp>
#include <boost/any.hpp>
using namespace::std;
namespace mp = boost::multiprecision;
typedef mp::number<mp::cpp_dec_float<32,int64_t>> cfloat;
typedef mp::cpp_int cint;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
typedef vector<pair<lint,lint>> pvec;
typedef vector<vector<pair<lint,lint>>> pmat;
typedef vector<vector<vector<pair<lint,lint>>>> pmat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<"\n";}while(0)
#define output2(v) for(auto j:v)output(j);
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define SUM(v) accumulate(all(v),0LL)
#define INF (1LL<<60)
#define IINF (1<<30)
#define LINF 9223372036854775807
#define MOD 1000000007
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
inline lint mex(vector<lint> s){
    lint res=0;
    sort(all(s));
    while(binary_search(all(s),res))res++;
    return res;
}
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};

int main(){
    lint n;
    cin>>n;
    cout<<n*(n-1)/2;
}

Measured memory_bytes: 256
n = int(input())
i = 1
a = [[[0 for k in range(10)] for j in range(3)] for i in range(4)]
while i <= n:
    b,f,r,v = map(int,input().split())
    if a[b-1][f-1][r-1] + v < 0:
        a[b-1][f-1][r-1] = 0
    elif a[b-1][f-1][r-1] + v > 9:
        a[b-1][f-1][r-1] = 9
    else:
        a[b-1][f-1][r-1] = a[b-1][f-1][r-1] + v
    i+=1
for ridge in range(4):
    for floor in range(3):
        for room in range(10):
            print(" {}".format(a[ridge][floor][room]),end="")
        print()
    if ridge == 3:
        break
    print("####################")    



Measured memory_bytes: 5628
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	//数値の入力
		String s = sc.next();
      	String t = sc.next();
      
		for(int i = 0; i < s.length(); i++){
        	if(s.equals(t)){
              System.out.println("Yes");
              return;
            }else{
              s = s.charAt(s.length()-1) + s.substring(0, s.length()-1);
            }
        }
      System.out.println("No");
     }
}

Measured memory_bytes: 38992
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;
const int INF=1000000007;

int main (void){
    long long int n,x,i,ps=0;
    cin >> n >> x;
    for(i=n;i>=0;i--){
    	if(x==0) break;
    	if(i==0){
    		ps++;
    		break;
    	}
    	if(x==pow(2,i+2)-3) x=x-1;
    	if(x>=pow(2,i+1)-1){
    		ps+=pow(2,i);
    		x=x-pow(2,i+1)+1;
    	} else {
    		x=x-1;
    	}
    }
    cout << ps << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) = p5()

fun p5() {
    val (a, b, c, x, y) = readLine()!!.split(' ').map { it.toLong() }

    var needA = x
    var needB = y
    var answer = 0L

    if (c * 2 <= a) {
        answer += c * 2 * needA
        needB = Math.max(needB - needA, 0)
        needA = 0
    }

    if (c * 2 <= b) {
        answer += c * 2 * needB
        needA = Math.max(needA - needB, 0)
        needB = 0
    }

    if (c * 2 <= a + b) {
        val ab = Math.min(needA, needB)
        answer += c * 2 * ab
        needA = Math.max(needA - ab, 0)
        needB = Math.max(needB - ab, 0)
    }

    answer += needA * a + needB * b

    println(answer)
}


Measured memory_bytes: 38244
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> L(N);
    int res = 0;
    for(int i = 0; i < N; i++){
        cin >> L[i];
    }
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            for(int k = j + 1; k < N; k++){
                int num1 = L[i];
                int num2 = L[j];
                int num3 = L[k];
                int maxnum = max(num1, max(num2, num3));
                if(maxnum < (num1 + num2 + num3) - maxnum){
                    res += 1;
                }
            }
        }
    }
    cout << res;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(long long N, std::vector<long long> A) {
  function<LL(LL, LL)> gcdlambda = [](LL n, LL m) { return __gcd(n, m); };
  vector<LL> front = {0}, back = {0};
  partial_sum(A.begin(), A.end(), back_inserter(front), gcdlambda);
  reverse(A.begin(), A.end());
  partial_sum(A.begin(), A.end(), back_inserter(back), gcdlambda);
  LL maxim = 0;
  for (int i = 0; i < N; i++) {
    chmax(maxim, gcdlambda(front[i], back[N - i - 1]));
  }
  cout << maxim << endl;
}

int main() {
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 3316
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a), q(b), r(c);
  for (int i = 0; i < a; i++) cin >> p[i];
  for (int i = 0; i < b; i++) cin >> q[i];
  for (int i = 0; i < c; i++) cin >> r[i];
  sort(p.rbegin(), p.rend());
  sort(q.rbegin(), q.rend());
  sort(r.rbegin(), r.rend());
  vector<int> v;
  for (int i = 0; i < x; i++) v.push_back(p[i]);
  for (int i = 0; i < y; i++) v.push_back(q[i]);
  for (int i : r) v.push_back(i);
  sort(v.rbegin(), v.rend());
  long long ans = 0;
  for (int i = 0; i < x + y; i++) ans += v[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3572