akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	H, W := sc.nextInt(), sc.nextInt()
	G := make([][]rune, H)
	for i := 0; i < H; i++ {
		G[i] = sc.nextRuneSlice()
	}
	var dp [101][101]int
	for i := 0; i < 101; i++ {
		for j := 0; j < 101; j++ {
			dp[i][j] = INF
		}
	}
	if G[0][0] == '.' {
		dp[0][0] = 0
	} else {
		dp[0][0] = 1
	}
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if i > 0 {
				if G[i-1][j] == '.' && G[i][j] == '#' {
					dp[i][j] = min(dp[i][j], dp[i-1][j]+1)
				} else {
					dp[i][j] = min(dp[i][j], dp[i-1][j])
				}
			}
			if j > 0 {
				if G[i][j-1] == '.' && G[i][j] == '#' {
					dp[i][j] = min(dp[i][j], dp[i][j-1]+1)
				} else {
					dp[i][j] = min(dp[i][j], dp[i][j-1])
				}
			}
		}
	}

	fmt.Fprintln(wtr, dp[H-1][W-1])
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using Tuple = tuple<int, int, int>;


int main() {
    int a,b,c,x; cin >> a >> b >> c >> x;
    int ans = 0;
    erep(i, a) erep(j, b) erep(k, c) {
        int tmp = (500*i) + (100*j) + (50*k);
        if(tmp == x) ans++;
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    ans=0
    now=0
    r=0
    for l in range(n):
        while(r<n and now&A[r]==0):
            now+=A[r]
            r+=1
        ans+=r-l
        now-=A[l]
    print(ans)
resolve()

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


int main(){
    int a=1000000,n;
    cin>>n;
    vector<int> x(n);
    rep(i,n){
        cin>>x[i];
    }
    rep(i,100){
        int b=0;
        rep(j,n){
            b+=(x[j]-i-1)*(x[j]-i-1);
        }
        a=min(a,b);
    }
    cout<<a<<endl;
    return 0;
}

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

int main(){
  char c;
  cin >> c;
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    cout << "vowel";
  }else{
    cout << "consonant";
  }
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)

int main(){
  string s,y,m,d,ans="TBD";
  cin>>s;
  y=s.substr(0,4);
  m=s.substr(5,2);
  d=s.substr(8,2);
  if(y<"2019" || (y=="2019" && m<"04") || (y=="2019" && m=="04" && d<="30")) ans="Heisei";
  cout<<ans;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i, j;
	int a[302][302];
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			scanf("%d", &a[i][j]);
			a[i][j]--;
		}
	}
	int count[302];
	for (i = 0; i < m; i++)
		count[i] = 0;
	int use[302];
	for (i = 0; i < m; i++)
		use[i] = 0;
	int ans = n;
	int l[302];
	for (i = 0; i < n; i++)
		l[i] = 0;
	int max;
	for (i = 0; i < n; i++)
		count[a[i][0]]++;
	for (j = 1; j < m; j++)
	{
		max = 0;
		for (i = 0; i < m; i++)
			if (count[i] > count[max])
				max = i;
		if (ans > count[max])
			ans = count[max];
		use[max] = 1;
		for (i = 0; i < m; i++)
			count[i] = 0;
		for (i = 0; i < n; i++)
		{
			while (l[i] < m && use[a[i][l[i]]]>0)
				l[i]++;
			if (l[i] == m)
			{
				j = m + 10;
				break;
			}
			count[a[i][l[i]]]++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
N=int(input())
H=[int(x) for x in input().split()]
answer=[0,abs(H[1]-H[0])]
for i in range(2,N):
  answer +=[min(answer[i-2]+abs(H[i]-H[i-2]),answer[i-1]+abs(H[i]-H[i-1]))]
print(answer[-1])

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

int main() {
  int s, s1, s2, s3;
  cin >> s;
  s3 = s % 10;
  s2 = (s % 100 - s3) / 10;
  s1 = (s - s2 - s3) / 100;
  cout << s1 + s2 + s3 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> a >> b;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

//  if(a==b) ans = c;
//  else ans = a;
  
  cout << b*2-a << endl;

}

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

using namespace std;

int main() {
  int k, x; cin >> k >> x;
  vector <int> p;
  for(int i = x - 1, cnt = k - 1; (i >= -1000000 and cnt > 0); i--, cnt--) {
    p.push_back(i);
  } p.push_back(x);
  for(int i = x + 1, cnt = k - 1; (i <= 1000000 and cnt > 0); i++, cnt--) {
    p.push_back(i);
  } sort(p.begin(), p.end());
  for(auto q : p) cout << q << ' ';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define rep(i, j, k) for (auto i = j; i < k; i++)
#define rrep(i, j, k) for (auto i = j; i > k; i--)
using namespace std;

int a[100011];

void solve(int &t, int &d, int &l) {
  fill(a, a + 100001, 0);
  rep(i, 0, t) {
    int x; cin >> x;
    if (x >= l) {
      a[i]++;
      if (i + d < 100011) a[i + d]--;
    }
  }
  rep(i, 1, 100001) a[i] = a[i] + a[i - 1];
  int ans = 0; 
  rep(i, 0, t - 1) if (a[i]) ans++;
  cout << ans << endl;
}

int main() {
  int t, d, l;
  while (cin >> t >> d >> l, t) solve(t, d, l);
}



Measured memory_bytes: 3388
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

  private void solve(Scanner in, PrintWriter out) {
    long S = in.nextLong();
    long C = in.nextLong();
    if (S * 2 > C) {
      long c = C / 2;
      out.println(c);
      return;
    }

    long ans = S;
    C -= S * 2;
    ans += C / 4;
    out.println(ans);
  }

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(in, out);
    in.close();
    out.close();
  }
}


Measured memory_bytes: 22612
A,B=input().split(" ")
A=int(A)
B=int(B)



if(A%2==1):
	A_=A+1
else:
	A_=A
if(B%2==0):
	B_=B-1
else:
	B_=B

out=((B_-A_+1)//2)%2
#import numpy as np
if(A%2==1):
	out^=A
if(B%2==0):
	out^=B
print(out)

	





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

int main() {
	long long int n,countr=0,countw=0,anscount=0;
  	string str;
  cin>>n;
  cin>>str;
  	for(int i=0;i<n;i++){
      if(str[i]=='R'){
        countr++;
      }else{
        countw++;
      }
    }
  string ansstr="";
  for(int i=0;i<countr;i++){
    if(str[i]!='R')anscount++;
  }
  printf("%lld\n",anscount);
}

Measured memory_bytes: 3808
N = int(input())
A = [int(x) for x in input().split()]
print(*A)
for i in range(1, len(A)):
    key = A[i]
    j = i-1
    while j >= 0 and A[j] > key:
        A[j+1] = A[j]
        j += -1
        A[j+1] = key
    print(*A)

Measured memory_bytes: 8000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;
   
public class Main {
    LinkedList<Integer> list = new LinkedList<>();
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
     
    public void exec() throws IOException {
        SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.readInt();
         
        for(int i=0; i<n; i++) {
            String[] cmd = in.br.readLine().split(" ");
            if(cmd[0].equals("insert")){
                list.addFirst(new Integer(cmd[1]));
            } else if(cmd[0].equals("delete")){
                list.remove(new Integer(cmd[1]));
            } else if(cmd[0].equals("deleteFirst")){
                list.removeFirst();
            } else {
                list.removeLast();
            }
        }
        boolean first = true;
        StringBuilder sb = new StringBuilder();
        for(Integer i : list) {
            if(first) {
                first = false;
            } else {
                sb.append(" ");
            }
            sb.append(i);
        }
        out.println(sb.toString());
        out.flush();
    }
}
 
class SimpleInputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
    public String[] readStrArray(String delim) throws NumberFormatException, IOException{
        return br.readLine().split(delim);
    }
     
    public int readInt() throws NumberFormatException, IOException{
        return Integer.parseInt(br.readLine());
    }
     
    public int[] readIntArray(int[] a) throws NumberFormatException, IOException{
        int i=0;
        while(i<a.length) {
            for(String s: br.readLine().split(" ")){
                if(i<a.length) {
                    a[i++] = Integer.parseInt(s);
                }
            }
        }
        return a;
    }
 
     
}

Measured memory_bytes: 203864
#include<bits/stdc++.h>
using namespace std;
int n,m;
bool flag=1;
int main() {
	cin>>n>>m;
	for(int x=0; x<=n; x++)
		for(int y=0,z; y<=n-x; y++) {
			z=n-x-y;
			if(x*10000+y*5000+z*1000==m&&x+y+z==n) {
				cout<<x<<' '<<y<<' '<<z<<endl;
				flag=0;
				return 0;
			}
		}
	if(flag)cout<<"-1 -1 -1";
	return 0;
}

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

#define endl '\n'
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

typedef long long llong;
typedef pair<int, int> pii;

int find(vector<int> &parent, int cur) {
	if (cur == parent[cur]) return cur;
	else return find(parent, parent[cur]);
}

void solve() {

	srand(time(0));

	int n;
	cin >> n;

	// coordinate, vertex
	vector<pii> x_coord(n), y_coord(n);
	// x, y coordinate combo
	vector<pii> vertexes(n);

	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		x_coord[i] = mp(x, i);
		y_coord[i] = mp(y, i);
		vertexes[i] = mp(x, y);
	}

	sort(x_coord.begin(), x_coord.end());
	sort(y_coord.begin(), y_coord.end());

	vector< pair<int, pii> > edges;

	// x coordinates
	for (int i = 1; i < n; i++) {
		int u = x_coord[i - 1].ss;
		int v = x_coord[i].ss;
		int weight = x_coord[i].ff - x_coord[i - 1].ff;
		edges.pb(mp(weight, mp(u, v)));
	}

	// y coordinates
	for (int i = 1; i < n; i++) {
		int u = y_coord[i - 1].ss;
		int v = y_coord[i].ss;
		int weight = y_coord[i].ff - y_coord[i - 1].ff;
		edges.pb(mp(weight, mp(u, v)));
	}
	sort(edges.begin(), edges.end());


	// disjoint union set
	vector<int> parent(n), rank(n);
	for (int i = 0; i < n; i++) parent[i] = i;

	int ans = 0;

	for (const auto &edge : edges) {

		int weight = edge.ff;
		int u = edge.ss.ff;
		int v = edge.ss.ss;

		// cout << u << ' ' << v << " : " << weight << endl;

		int up = find(parent, u);
		int vp = find(parent, v);

		// disjoint
		if (up != vp) {

			if (rank[up] > rank[vp]) {
				parent[vp] = up;
			} else if (rank[vp] > rank[up]) {
				parent[up] = vp;
			} else {
				parent[up] = vp;
				rank[vp]++;
			}
			
			ans += weight;
		}
	}

	cout << ans;
}

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

	#ifdef LOCAL
		ifstream in("in");
		cin.rdbuf(in.rdbuf());
	#endif

	solve();
}

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

using namespace std;

int n;

int gr(int k, int n) {
    if (n<k) return 0;
    if (n%k==0) return n/k;
    return gr(k,n-(n%k+n/k)/(n/k+1)*(n/k+1));
}

int main() {
    int i, a, b, x = 0;

    scanf("%d",&n);
    for (i=0;i<n;i++) {
        scanf("%d%d",&a,&b);
        x ^= gr(b,a);
    }
    puts(x?"Takahashi":"Aoki");

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mk make_pair
#define pb push_back
#define mod 1000000007
  
int main(){
    string s,t;
    cin>>s>>t;
    int f=t.length();
    for(int i=0;i<s.length();i++){
        int temp=0;
        if(i+t.length()-1<s.length()){
        int l=i;
        int r=i+t.length()-1;
        for(int j=l;j<=r;j++){
            if(s[j]!=t[j-l])temp++;
        }
        f=min(temp,f);
        }
    }
    cout<<f<<endl;
    return 0;
}

Measured memory_bytes: 3592
#include <math.h>
#include <algorithm>
#include <cmath>
#include <iostream>


using namespace std;


int main()
{
    int bill {1000};
    double n{};

    cin >> n;

    double change{};
    int count{};

    while (n >= 1000)
    {
        n -= 1000;
        count += 1;
    }

    if (bill - n == 1000)
    {
        cout << 0;
    }

    else
    {
        change = bill - n;

        cout << change;
    }
}


Measured memory_bytes: 3748
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;




//ここから編集する

int log(double x,double y){
    return (int)(log(y)/log(x));
}

int main() {
    ll N;
    cin >> N;
    int ans = 100;
    int max_i;
    for(ll i = 1; i * i <= N; i++){
        if(N % i == 0){
//            if(ans > max(log(10.0,(double)N/i),log(10.0,(double)i)) ) max_i = i;
//            ans = min(ans,max(log(10.0,(double)N/i),log(10.0,(double)N/i)));
            ans = min(ans, (const int &) max(to_string(N / i).size(), to_string(i).size() ));
        }
    }
//    cout << log(10.0,1000.0) << endl;
    cout << ans << endl;
//    cout << max_i << endl;
    return 0;
}


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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    int h, w, d;
    cin >> h >> w >> d;

    map<int, pii> mp;
    
    irep(i, h) {
        irep(j, w) {
            int a;
            cin >> a;
            mp[a] = pii(i,j);
        }
    }
    
    v_int dist(h*w, 0);

    for(int i = 1; i <= d; i++) {
        int sum = 0;
        for(int j = i; j <= h*w; j+=d) {
            sum += abs(mp[j].first - mp[j-d].first);
            sum += abs(mp[j].second - mp[j-d].second);
            dist[j] = sum;    
        }
    }

    int q; 
    cin >> q;
    v_int l(q), r(q);
    irep(i, q) {
        cin >> l[i] >> r[i];
    }

    v_int ans(q, 0);
    irep(i, q) {
        cout << dist[r[i]] - dist[l[i]] << endl;
        #if 0
        int a = l[i];
        while(a != r[i]) {
            int x = mp[a].first; 
            int y = mp[a].second; 
            a += d;
            int to_x = mp[a].first; 
            int to_y = mp[a].second; 

            ans[i] += abs(x-to_x) + abs(y-to_y);
        }
        #else 

        #endif
    }

    return 0;
}
/** atcoder **/


Measured memory_bytes: 13184
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

a,b,c=map(int,input().split())

if a==b and b!=c:
    print("Yes")
elif b==c and c!=a:
    print("Yes")
elif c==a and a!=b:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 66156
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));
        int n = Integer.parseInt(br.readLine());
        System.out.println(problem157a(n));
    }

    private static int problem157a(int n) {
        return (n / 2) + (n % 2);
    }
}

Measured memory_bytes: 20436
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const double pi=3.1415926535;
const int MI=2147483647;
const int mod=1e9+7;
const int Max=1e4+25;

int main()
{
    cin.sync_with_stdio(false);
    string s,t;
    cin>>s;
    cin>>t;
    int count=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i]) count++;
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3800
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <math.h>
#include <cstdlib>
#include <cctype>
#include <random>

using namespace std;

int main() {
    int n, max_l=0, sum_l=0;
    cin >> n;
    int l;
    for (int i=0; i<n; i++) {
        cin >> l;
        max_l = max(max_l, l);
        sum_l += l;
    }
    sum_l -= max_l;

    if (max_l < sum_l) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int size = (int)s.size();
    int ans = 0;
    rep(i, size/2) if(s[i] != s[size-1-i]) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100003;
char s[MaxN];

int main() {
    scanf("%s",s);
    int cnt=0;
    for (int i=0;s[i];++i) if (s[i]!=s[i+1]) cnt++;
    printf("%d\n",cnt-1);
    return 0;
}

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

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;
const int N = 100005;

int main() {
	speed;
	int n;
	cin >> n;
	vector<int>p(n);
	vector<int>x;

	rep(i, n) {
		cin >> p[i];
		if (p[i] != i+1) {
			x.push_back(i);
		}
	}
	if (x.size() == 2||x.empty()) {
		c("YES");
	}
	else {
		c("NO");
	}

	ed;
	return 0; 
}



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

using namespace std;

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

int main(){
    int X, Y;
    cin >> X >> Y;
    cout << X + Y / 2;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
#define debug(var) cout << "[" << #var << "] " << var << endl
const ll mod = 1000000007;


int main(){
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    rep(i, m) cin >> x[i];
    sort(x.begin(), x.end());
    if (n>=m) {
        cout << "0" << endl;
        return 0;
    }
    vector<int> dif(m-1);
    rep(i, m-1) {
        dif[i] = x[i+1] - x[i];
    }
    sort(dif.begin(), dif.end());
    int ans = 0;
    rep(i, m-n) {
        ans += dif[i];
    }

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 


int main(){
  ll N;
  cin >> N;
  
  vector <ll> a(N);
  rep(i,N) cin >> a.at(i);
  
  sort(a.begin(), a.end());
  vector<vector<ll>> memo(2, vector<ll>(1e5+1));
  vector<vector<ll>> memo2(2, vector<ll>(1e5+1));
  
  rep(i,1e5) memo.at(0).at(i) = i; 
  rep(i,1e5) memo.at(1).at(i) = 0; //一応初期化
  rep(i,1e5) memo2.at(0).at(i) = i; 
  
  rep(i, N) memo.at(1).at(a.at(i))++;
  
  memo2.at(1).at(0) = memo.at(1).at(0) + memo.at(1).at(1);
  memo2.at(1).at(1e5) = memo.at(1).at(1e5-1) + memo.at(1).at(1e5);
  
  for(int i=1; i<=1e5-1; i++){
    memo2.at(1).at(i) = memo.at(1).at(i+1)+ memo.at(1).at(i)+ memo.at(1).at(i-1);
  }
  
  ll res1=0;
  ll res2=0;
  rep(i,1e5){
    if(res1 < memo2.at(1).at(i)) {
      res1 = memo2.at(1).at(i);
      res2 = i;
    }
  }
  

  cout << res1;
  
   
  
  
}

Measured memory_bytes: 4976
#!python3

iim = lambda: map(int, input().rstrip().split())

from bisect import bisect

def resolve():
    def find(i):
        x = S[i]
        if x < 0:
            return i
        S[i] = find(x)
        return S[i]

    def join(i, j):
        ai = find(i)
        aj = find(j)
        diff = ai - aj
        #print("j", ai, aj)
        if diff == 0:
            return
        elif diff > 0:
            ai, aj = aj, ai
        S[ai] += S[aj]
        S[aj] = ai
    def same(i, j):
        ai = find(i)
        aj = find(j)
        return ai == aj
    def size(i):
        return -S[find(i)]

    N, M, K = iim()
    S = [-1] * N
    T = [1] * N
    for i in range(M):
        ai, bi = iim()
        ai -= 1; bi -= 1
        join(ai, bi)
        T[ai] += 1
        T[bi] += 1
        #print(ai, bi, S)

    U = [set() for i in range(N)]
    for i in range(K):
        ai, bi = iim()
        ai -= 1; bi -= 1
        U[ai].add(bi)
        U[bi].add(ai)
    #print(S)
    #print(T)

    ans = [size(i) - T[i] - sum(same(i, j) for j in U[i]) for i in range(N)]
    print(*ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 42724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define OUT(x) cout << (x) << endl;
#define REP(i, n) for (int i=0; i<n; ++i)

int MAX = 1e5+10;
// int move[][2] = {{1,0}, {0,1},{-1,0},{-1,-1}};

int main(){
    int N;
    int t[MAX], x[MAX], y[MAX];
    cin >> N;
    t[0]=x[0]=y[0]=0;
    REP(i, N) cin >> t[i+1] >> x[i+1] >> y[i+1]; // +1

    bool can = true;
    for(int i=0; i<N; ++i){
        int dt = t[i+1]-t[i];
        int dst = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);
        if(dt < dst) can = false;
        if(dst % 2 != dt %2) can = false;
    }

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


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	/**
	 * Haiku
	 * @param s.length = 19
	 * @param s[5], s[13] = ","
	 */
	public static void main(String... args) {
		try (Scanner sc = new Scanner(System.in)) {
			String s = sc.next();
			String t[] = s.split(",");
			System.out.println(t[0] + " " + t[1] + " " + t[2]);
		}
	}
}

Measured memory_bytes: 21076
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int A, P;
    cin >> A >> P;
    cout << (A*3 + P) / 2 << endl;
    return 0;
}

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

using namespace std;
using LL = long long;

int main() {
    int N, K;
    cin >> N >> K;

    vector<LL> H(N);

    for (int i = 0; i < N; i++) cin >> H[i];

    sort(H.begin(), H.end(), greater<>());

    LL ans = 0;

    if (H.size() > K) ans = accumulate(H.begin() + K, H.end(), 0L);

    cout << ans << endl;
}

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

using namespace std;


int main(){
    int a,b,ans;
    cin >> a >> b; 
    if(a<=9 && b<=9){
        ans=a*b;
    }
    else{
        ans=-1;
    }
    
   
    cout << ans << endl;
    

    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto &i : c)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define fill(a)  memset(a, 0, sizeof (a))
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }
int mul(int a, int b, int c){lli res=(lli)a*b;return (int)(res>=c?res%c:res);}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}


signed main(){
    #ifdef DEBUG
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    int N;
    cin >> N;

    map<int , int> s;
    int ans = 0;
    repA(i, 1, N){
        int a;
        cin >> a;
        int x = i - a;
        if(present(s, x))
            ans += s[x];
        s[a+i]++;
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
 int  a;
  cin >> a ;
 vector<int> vec(a);
  for (int i=0; i<a; i++){
    cin >> vec.at(i);}
  int l=0;
  for  (int i=0; i<a; i++){
    if (l<vec.at(i)){
      l=vec.at(i);}}
  int total =l*l*100;
   for (int i=1; i<l+1; i++){
     int sum =0;
       for (int j=0; j<a; j++){
         int add = (vec.at(j)-i)*(vec.at(j)-i);
         sum +=add;}
        if (sum<total){
         total =sum;}
       else sum =0;
   }
  cout <<total << endl;
}






Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<string.h>
//#include<string>

using namespace std;

#define MAX(x,y) ((x>y)? x:y)


int n;//データセットの数

char str[2][10000];//	入力される整数文字列
int n_str[2];//長さを収納

char answer[85];


int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{

		scanf("%s%s",&str[0],&str[1]);
		n_str[0]=strlen(str[0]);
		n_str[1]=strlen(str[1]);
		int max =0,min=1;
		if(n_str[1]>n_str[0])
		{
			max=1;
			min=0;
		}
		int s = n_str[max]-n_str[min];
		char cha[10000];
		fill(cha,cha+80,'0');
		for(int j=n_str[min];j>=0;j--)
		{
			cha[j+s]=str[min][j];
		}
		strcpy(str[min],cha);
		fill(answer,answer+85,0);
		for(int j=n_str[max]-1;j>=0;j--)
		{
			answer[j]=str[0][j]+str[1][j]-'0';
			if(answer[j]>'9')//繰り上がり時の処理
			{
				answer[j]-=10;
				if(j==0)
				{
					if(n_str[max]>=80)
					{
						n_str[max]=90;
					}

					else printf("1");
				}
				else str[0][j-1]++;
			}
		}
		if(n_str[max]>80)
		{
			printf("overflow\n");
		}
		else printf("%s\n",answer);
	}
	return 0;
}

Measured memory_bytes: 0
def main
  m, d = gets.chop.split.map(&:to_i)
  ans = 0
  1.upto(m) do |_m|
    1.upto(d) do |_d|
      ans += 1 if is_ok(_m, _d)
    end
  end
  puts ans
end

def is_ok(m, d)
  d1 = d % 10
  d2 = d / 10
  (d1 >= 2) and (d2 >= 2) and (m == d1 * d2)
end

if __FILE__ == $0
  main
end


Measured memory_bytes: 1788
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

int N, M;
vector<pair<int, int>> edge_list;
vector<vector<int>> adj;
vector<vector<bool>> reach;

void reach_dfs(int source, int node) {
    if (reach[source][node])
        return;

    reach[source][node] = true;

    for (int neighbor : adj[node])
        if (!reach[source][neighbor])
            reach_dfs(source, neighbor);
}

vector<vector<bool>> reach_without;
vector<int> best_index;

void without_dfs(int index, int node) {
    if (best_index[node] >= 0)
        return;

    best_index[node] = index;

    for (int neighbor : adj[node])
        if (best_index[neighbor] < 0)
            without_dfs(index, neighbor);
}

void solve_reach_without(int source) {
    reach_without[source][source] = true;
    int neighbors = adj[source].size();
    best_index.assign(N, -1);
    best_index[source] = N;

    for (int i = 0; i < neighbors; i++)
        without_dfs(i, adj[source][i]);

    for (int i = 0; i < neighbors; i++) {
        int neighbor = adj[source][i];

        if (best_index[neighbor] >= 0 && best_index[neighbor] != i)
            reach_without[source][neighbor] = true;
    }

    best_index.assign(N, -1);
    best_index[source] = N;

    for (int i = neighbors - 1; i >= 0; i--)
        without_dfs(i, adj[source][i]);

    for (int i = 0; i < neighbors; i++) {
        int neighbor = adj[source][i];

        if (best_index[neighbor] >= 0 && best_index[neighbor] != i)
            reach_without[source][neighbor] = true;
    }
}

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

    cin >> N >> M;
    edge_list.resize(M);
    adj.assign(N, {});

    for (pair<int, int> &edge : edge_list) {
        cin >> edge.first >> edge.second;
        edge.first--; edge.second--;
        adj[edge.first].push_back(edge.second);
    }

    reach.assign(N, vector<bool>(N, false));

    for (int i = 0; i < N; i++)
        reach_dfs(i, i);

    reach_without.assign(N, vector<bool>(N, false));

    for (int i = 0; i < N; i++)
        solve_reach_without(i);

    for (pair<int, int> &edge : edge_list) {
        bool answer1 = reach_without[edge.first][edge.second];
        bool answer2 = reach[edge.second][edge.first];
        cout << (answer1 ^ answer2 ? "diff" : "same") << '\n';
    }
}


Measured memory_bytes: 4608
import java.util.Scanner;

public class Main{
	private static Scanner scan;
	public static void main(String[] args) {
		scan = new Scanner(System.in);
		String str = scan.next();
		int l = str.length();
		for(int i = l -1;i >= 0 ;i--){
			System.out.print(str.charAt(i));
		}
		System.out.println();
		System.exit(0);
	}
}

Measured memory_bytes: 12000
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(i) sort(i.begin(),i.end())
#define rSORT(i) sort(i.rbegin(),i.rend())
#define fSORT(i,a) sort(i.begin(),i.end(),a)
#define all(i) i.begin(),i.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
inline void print() { cout << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    string s; cin >> s;
    int a = stoi(s), b = 0;
    each(i, s)b += i - '0';
    cout << (a % b == 0 ? "Yes" : "No") << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
  char s[101];
  scanf("%s",s);
  int len = strlen(s);
  int last = len-1;
  int cnt=0;
  for(int i=0;i<len/2;i++){
    if(s[i]!=s[last])cnt++;
    last--;
  }
  printf("%d\n",cnt);
  return(0);
}

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

using namespace std;
#define ll long long


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

    int n;
    cin >> n;
    for (int i = 1;; i++) {
        if (i * 1000 >= n) return cout << i * 1000 - n, 0;
    }
    return 0;
}

Measured memory_bytes: 3580
from collections import defaultdict
from functools import lru_cache
from bisect import bisect_right as bir
from collections import Counter
N = int(input())


def prime(n):
    ret = []
    while n % 2 == 0:
        ret.append(2)
        n //= 2

    f = 3
    while f*f <= n:
        if n % f == 0:
            ret.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        ret.append(n)
    return ret


D = Counter(prime(N))

comb = []
m = 0
for i in range(1, 10000):
    m += i
    comb.append(m)


ans = 0
for k, v in D.items():
    ans += bir(comb, v)

print(ans)


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

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

}

Measured memory_bytes: 3180
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def main():
    from math import ceil

    n, m, *a = map(int, open(0).read().split())
    c = 0
    t = a[0]
    while t % 2 == 0:
        c += 1
        t = t // 2

    for x in a[1:]:
        d = 0
        while x % 2 == 0:
            d += 1
            x = x // 2

        if d != c:
            print(0)
            break

        t = lcm(t, x)
    else:
        ans = ceil(m // 2 ** (c-1) // t / 2)
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14220
N, A, B, C = map(int, input().split())
ans = 10**9

def search(a: list, b: list, c: list, yet: list):
    global N, A, B, C, ans
    if len(yet):
        search(a + [yet[0]], b, c, yet[1:])
        search(a, b + [yet[0]], c, yet[1:])
        search(a, b, c + [yet[0]], yet[1:])
        search(a, b, c, yet[1:])
    else:
        if len(a) > 0 and len(b) > 0 and len(c) > 0:
            candidate = 0
            candidate += 10*(len(a) - 1)
            candidate += 10*(len(b) - 1)
            candidate += 10*(len(c) - 1)
            candidate += abs(sum(a) - A)
            candidate += abs(sum(b) - B)
            candidate += abs(sum(c) - C)
            ans = min(ans, candidate)
        
bamboos = []
for i in range(N):
    bamboos.append(int(input()))

search([], [], [], bamboos)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  long long int K;
  cin >> K;
  K--;
  
  long long int pos_non1 = 0;
  char first_non1 = '1';
  
  for (long long int i = 0; i < S.size(); i++) {
    if (S[i] != '1') {
      pos_non1 = i;
      first_non1 = S[i];
      break;
    }
  }
  
  if (K < pos_non1) {
    cout << '1' << endl;
  } else {
    cout << first_non1 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    COMinit();

    ll N;
    cin >> N;

    map<ll, ll> m;
    vector<ll> A(N);
    for(int i = 0; i < N ; i++) {
        cin >> A[i];

        if(m.find(A[i]) == m.end()) m[A[i]] = 1;
        else m[A[i]]++;
    }

    ll ret = 0;
    for(auto i = m.begin(); i != m.end(); i++) {
        ret += i->second * (i->second - 1) / 2;
    }

    for(int i = 0; i < N; i++) {
        cout << ret - (m[A[i]]-1) << endl;
    }

    return 0;
}


Measured memory_bytes: 23040
A, B = map(int, input().split())

if B == 1:
    ans = 0
elif A >= B:
    ans = 1
else:
    if (B - 1) % (A - 1) > 0:
        ans = (B - 1) // (A - 1) + 1
    else:
        ans = (B - 1) // (A - 1)

print(ans)

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

const int INF = 1001001001;
struct grid {int y; int x;};



int main(){
    int h, w;
    cin >> h >> w;
    int dx[2] = {1, 0};
    int dy[2] = {0, 1};
    vector<string> field(h);
    rep(i,h) cin >> field[i];
    vector<vector<int>> graph(h, vector<int>(w,INF));



    deque<grid> deq;
    grid start = {0, 0};
    if(field[0][0]=='#') graph[0][0] = 1;
    else graph[0][0] = 0;
    deq.push_front(start);

    while(!deq.empty()){
        auto now = deq.front(); deq.pop_front();
        int temp = graph[now.y][now.x];
        rep(i,2) {
            grid next = {now.y + dy[i], now.x + dx[i]};

            if(next.y < 0 || next.y >= h || next.x < 0 || next.x >= w) continue;
            if(field[next.y][next.x]=='#') {
                if(field[now.y][now.x]=='.'){
                    if(graph[next.y][next.x]>temp){
                        graph[next.y][next.x] = temp + 1;
                        deq.push_back(next);
                    }
                }
                else{
                    if(graph[next.y][next.x]>temp){
                        graph[next.y][next.x] = temp;
                        deq.push_front(next);
                    }
                

                }
            }
            else{
                if(graph[next.y][next.x]>temp) {
                    graph[next.y][next.x]=temp;
                    deq.push_front(next);
                }
        }
        }
    }
    cout << graph[h-1][w-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <climits>
#include <cmath>
#include <limits.h>
#include <ios>
#include <iomanip>
#include <map> // pair
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b){return b? gcd(b, a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;

  double frac = 1/N;
  double ans = 0.0;
  for(int i = 1; i <= N; i++){
    int tmp = i;
    int count = 0;
    while(tmp < K){
      tmp *=2;
      count++;
    }
    
    ans += 1.0/N * pow(0.5, count);
  }
  std::cout << std::setprecision(12);
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int isprime(int n)
{
  for(int i = 2; i * i <= n; i++)
      if(n % i == 0) return 0;
  return 1;
}

int main(void)
{
  int n,i,t=0,MAX=0;
  while(1)
  {
    scanf("%d",&n);
    if(n==0)  break;
    for(i=n;i>0;i--)
    {
      if(isprime(i)==1 && isprime(i-2) == 1)
        {
          MAX=i;
          printf("%d %d\n",MAX-2,MAX);
          break;
        }
    }
  }
}

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

#define MEM(a, b) memset(a, b, sizeof a);
#define REP(i, k) for(int i = (0); i < (k); i++ )
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)

#define ALL(cont) cont.begin(), cont.end()
#define RALL(cont) cont.begin(), cont.end()
#define FOREACH(it, l) for(auto it=l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define INF (int)INT_MAX
#define EPS (int)1e-9
#define PI acos(-1)
#define MOD 1000000007

#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long L;
typedef unsigned long UL;
typedef long long LL;
typedef unsigned long long ULL;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

int num_ab(string s) {
    int  t = 0;
    REP(i, s.size() - 1) {
        if (s[i] == 'A' && s[i + 1] == 'B') t++;
    }
    return t;
}

void solve(__attribute__((unused)) int tc = 0) {
    int n;
    cin >> n;

    int sum = 0;
    int ba = 0, a = 0, b= 0;
    REP(_, n) {
        string s;
        cin >> s;
        sum += num_ab(s);
        if (s[0] == 'B' && s[s.size() - 1] == 'A') ba++;
        else if (s[0] == 'B') b++;
        else if (s[s.size() - 1] == 'A') a++;
    }
    debug(sum, ba, b, a);

    if (a == b && ba > 0 && a + b < ba) ba--;

    cout << sum + min(a + ba, b + ba) << endl;

    return;
}

int main() {
#ifdef FILE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    /*int TC;
      cin >> TC;
      REP(tc, TC) {
      solve(tc);
      }*/
    solve();
#ifdef TIME
    cout << "Execution time(second) : " << int(clock() * 1000.0 / CLOCKS_PER_SEC) << " ms" << endl;
#endif
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#define int long long
using namespace std;

int k;

double S(int x)
{
	string s = to_string(x);
	int res = 0;
	for (int i=0; i<(int) s.size(); i++)
		res+=(s[i]-'0');
	return (double) res / x;
}

main()
{
	ios_base::sync_with_stdio(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin >> k;
	int cnt = 10;
	int step = 10;
	for (int i=1; i<=k; i++)
	{
		if (i<=9)
			cout << i << '\n';
		else
		{
			cnt+=step;
			cout << cnt-1 << '\n';
			if (S(cnt+step-1)<S(cnt+step*10-1))
				step*=10;
		}
	}
	
	
	return 0;
}


Measured memory_bytes: 256