akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include<set>

using namespace std;

int main()
{
	int N;
	vector <int> d;

	cin >> N;
	for (int i = 0; i < N; i++)
	{
		int val;
		cin >> val;
		d.push_back(val);
	}

	set<int> st;
	for (auto x : d)
	{
		st.insert(x);
	}
	cout << st.size() << endl;

	return 0;
}

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

int main() {
	double n, m, d;
	cin >> n >> m >> d;
	double p = (d == 0 ? 1 : 2) * (n - d) / (n * n);
	cout << fixed << setprecision(15) << p * (m - 1) << endl;
}


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

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

const int MOD = 1000000007;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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


    ll ans=0;

    for(int keta=0;keta<60;keta++){
        ll x=0;
        ll y=0;
        for(int i=0;i<n;i++){
            if( a[i]>>keta & 1 ) x++;
        }
        y = n-x;
        ll now = x*y%MOD;
        ans += now*modpow(2,keta,MOD)%MOD;
        ans %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
use std::io::BufRead;

fn main() {
  let stdin = std::io::stdin();
  let mut lines = stdin.lock().lines();

  loop {
    let word = lines.by_ref().next().unwrap().unwrap();
    let word = word.trim();
    
    if word == "-" {
      break;
    }

    let m = lines.by_ref().next().unwrap().unwrap().parse::<usize>().unwrap();
    let h = lines.by_ref().take(m)
      .map(|x| x.unwrap().parse::<usize>().unwrap()).sum::<usize>() % word.len();

    println!("{}{}", &word[h..], &word[..h]);
  }
}


Measured memory_bytes: 5032
#include<iostream>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int e, f;
	e = a / d;
	if ((a%d) != 0)e++;
	f = c / b;
	if ((c%b) != 0)f++;
	if (e >= f)cout << "Yes" << endl;
	else if (e < f)cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc1 = new Scanner(System.in);

		int x1 = sc1.nextInt();
		int y1 = sc1.nextInt();
		int x2 = sc1.nextInt();
		int y2 = sc1.nextInt();

		int x3 = x2 - (y2 - y1);
		int y3 = y2 + (x2 - x1);
		int x4 = x3 - (y3 - y2);
		int y4 = y3 + (x3 - x2);

		System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);

		sc1.close();

	}

}

Measured memory_bytes: 22612
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

// Scane Standard Input
var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {

	w := nextLine()

	wordCount := 0
	for {
		t := strings.Split(nextLine(), " ")
		if t[0] == "END_OF_TEXT" {
			fmt.Println(wordCount)
			return
		}

		for _, tt := range t {
			if w == strings.ToLower(tt) {
				wordCount++
			}
		}
	}
}



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


int main(){
    string a,b,c;
    char x,y,z;
    cin>>a>>b>>c;
    x=a[0];
    y=b[1];
    z=c[2];
    cout<<x<<y<<z<<endl;
    
    
}

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

int main() {
  int N, Q;
  cin >> N;
  int cnt[100001];
  ll sum = 0, a, b, c;
  fill(cnt, cnt+100001, 0);
  for (int i=0; i<N; i++) {
    cin >> a;
    cnt[a]++;
    sum += a;
  }
  cin >> Q;
  ll ans[Q];
  for (int i=0; i<Q; i++) {
    cin >> b >> c;
    sum += (c-b) * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    ans[i] = sum;
  }
  for (int i=0; i<Q; i++)
    cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 4788
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <list>
#include <stack>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
ld eps = (ld)1 / 1e15;
ll inf = 1e18, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()
{
    //freopen("race.in", "r", stdin), freopen("race.out", "w", stdout);
    fast_io;
    ll n, r;
    cin >> n >> r;
    cout << (n >= 10 ? r : r + 100 * (10 - n));
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

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

int pre_gcd[200 + 3][200 + 3], K;

void pre() {
  for (int i = 1; i <= K; i++) {
    pre_gcd[i][i] = i;
    for (int j = i + 1; j <= K; j++)
      pre_gcd[i][j] = pre_gcd[j][i] = gcd(i, j);
  }
}

int main() {
  //freopen("input.txt", "r", stdin);
  while (~scanf("%d", &K)) {
    pre();
    int ans = 0;
    for (int i = 1; i <= K; i++)
      for (int j = 1; j <= K; j++)
        for (int k = 1; k <= K; k++)
          ans += pre_gcd[pre_gcd[i][j]][k];
    printf("%d\n", ans);
  }
  return 0;
}


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

int main() {
    int n, m; cin >> n >> m;
    vector<int> first;
    vector<set<int>> second(n);
    for (int i=0; i<m; ++i) {
        int a, b; cin >> a >> b;
        a--; b--;
        if (a > b) swap(a, b);
        if (a == 0) first.push_back(b);
        else {
            second[a].insert(b);
            second[b].insert(a);
        }
    }
    bool ans = false;
    for (int i: first) {
        if (second[i].count(n-1)) ans = true;
    }
    cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

Measured memory_bytes: 28416
#include <iostream>

using namespace std;

using ll = long long;

string s;

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	
	ll res = n / (a + b) * a;
	ll rem = n % (a + b);
	res += min(rem, a);
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    a,b = inputMap()
    
    print(-(-(a+b)//2))
            	
if __name__ == "__main__":
	main()


Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

typedef long long int ll;
typedef vector<ll> V;
typedef vector<V> VV;

int main() {
  // Happy hacking!
  double res = 0;
  int n;
  cin >> n;
  for(int i=0; i<n; i++) {
    double x;
    string u;
    cin >> x >> u;
    if(u.compare("JPY") == 0) {
      res += x;
    } else {
      res += x * 380000.0;
    }
  }

  cout << to_string(res) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <string>
#include <bitset>
#include <math.h>
#include <vector>
#include <set>

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; }
const long long INF = 1LL<<60;

using namespace std;

int c[1010];
int t[1010];
int ans = INT16_MAX;

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

    for(int i = 0; i < N; i++){
        cin >> c[i] >> t[i];

        if(t[i] <= T){
            ans = min(ans, c[i]);
        }
    }
    if(ans == INT16_MAX) cout << "TLE" << endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
inf = 10 ** 10
dp = [inf] * n
dp[0] = 0
for i in range(n - 1):
    temp = abs(h[i + 1] - h[i])
    dp[i + 1] = min(dp[i + 1], temp + dp[i])
    if i + 2 < n:
        temp = abs(h[i + 2] - h[i])
        dp[i + 2] = min(dp[i + 2], temp + dp[i])
print(dp[-1])

Measured memory_bytes: 13924
#include <stdio.h>

void swap(int *a,int *b){
  *a^=*b;
  *b^=*a;
  *a^=*b;
  return;
}

int main(){
  int N,S=0;
  scanf("%d",&N);
  int L[200];
  for(int i=1;i<=N;i++)
    scanf("%d",L+i);
  for(int i=1;i<=N;i++){
    for(int j=i+1;j<=N;j++){
      for(int k=j+1;k<=N;k++){
        int A=L[i],B=L[j],C=L[k];
        if(A==B || B==C || C==A) continue;
        if(A>B) swap(&A,&B);
        if(B>C) swap(&B,&C);
        if(C<A+B) S++;
      }
    }
  }
  printf("%d\n",S);
  return 0;
}


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


def gcd(a, b):
    x = max(a, b)
    y = min(a, b)
    mod = x % y
    if mod == 0:
        return y

    return gcd(y, mod)


mx = gcd(A, B)
count = 0

for a in range(mx, 0, -1):
    if A % a == 0 and B % a == 0:
        count += 1
    if count == K:
        ans = a
        break

print(ans)


Measured memory_bytes: 3060
def main():
    nums = input().split()
    n = int(nums[0])
    d = int(nums[1])
    itr = 0
    kanshi = 0
    while kanshi < n:
        kanshi += d + d + 1
        itr += 1
    print(itr)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
using System;
using System.Linq;

namespace Search
{
    class Binary_Search
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var S = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            Console.ReadLine();
            var T = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            var C = Count(S, T);
            Console.WriteLine(C);
        }

        public static int Count(int[] S, int[] T)
        {
            var c = 0;

            for (int i = 0; i < T.Length; i++)
            {
                var left = 0;
                var right = S.Length - 1;
                while (left <= right)
                {
                    var mid = left + (right - left) / 2;
                    if (S[mid] == T[i]) { c++; break; }
                    if (S[mid] < T[i]) left = mid + 1;
                    else right = mid - 1;
                }
            }
            return c;

        }
    }
}

Measured memory_bytes: 22852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    int n,m;
    cin >> n >> m;
    int h[n];
    rep(i,n)cin >> h[i];
    vector<int> ls(n);
    rep(i,n){
        ls[i]=0;
    }
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        chmax(ls[a],h[b]);
        chmax(ls[b],h[a]);
    }
    int ans=0;
    rep(i,n)if(ls[i]<h[i])ans++;
    cout << ans;
    


}

/*



 */



Measured memory_bytes: 3964
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n, k;
    cin >> n >> k;

    if (k == 1) {
        cout << 0 << '\n';
    } else {
        cout << n - k << "\n";
    }

    return 0;
}

Measured memory_bytes: 888
program sample
    implicit none
    
    integer(8) :: a,b,c,i,j,m,n,k,a1,b1,c1
    integer(8), allocatable  ::x(:) 

    read(*,*) n
  
    read(*,*) k
    
    allocate(x(n))
    read(*,*) x
    m=0
    do i=1,n
        m=m+k-abs(k-2*x(i))
    end do
    write(*,*)m
    deallocate(x)
    stop
end program sample
  



Measured memory_bytes: 384
function Main(input) {
	input = input.split("\n");
	tmp = input[0].split(" ");
  
	var tmp2 = [1,2,3,4,5];
	
	for (var i = 0; i < 5; i++) {
	if (tmp[i] != tmp2[i]) {
	var result = i + 1;
	break;
	} else {
	}
    }
	console.log(result);
	}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29692
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int r,c;
    cin>>r>>c;
    int a[r][c];
    int sum=0;
    vector<pair<pair<int,int>, pair<int,int> > > v;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<r;i++){
        if(i%2==0){
            for(int j=0;j<c;j++){
                if(a[i][j]%2){
                    if(j+1<c){
                        a[i][j+1]++;
                        v.push_back(make_pair(make_pair(i,j),make_pair(i,j+1)));
                    }else if(i+1<r){
                        a[i+1][j]++;
                        v.push_back(make_pair(make_pair(i,j),make_pair(i+1,j)));
                    }
                }
            }
        }else{
            for(int j=c-1;j>=0;j--){
                if(a[i][j]%2){
                    if(j-1>=0){
                        a[i][j-1]++;
                        v.push_back(make_pair(make_pair(i,j),make_pair(i,j-1)));
                    }else if(i+1<r){
                        a[i+1][j]++;
                        v.push_back(make_pair(make_pair(i,j),make_pair(i+1,j)));
                    }
                }
            }
        }
    }
    cout<<v.size()<<endl;
    for(int i=0;i<v.size();i++){
        cout<<v[i].first.first+1<<" "<<v[i].first.second+1<<" "<<v[i].second.first+1<<" "<<v[i].second.second+1<<endl;; 
    }
    return 0;
}


Measured memory_bytes: 5104
N = int(input())
ab = [list(map(int, input().split())) for i in range(N)]

al = []
bl = []
for a,b in ab:
  al.append(a)
  bl.append(b)
al.sort()
bl.sort()

if N%2 == 0:
  ans = (bl[N//2] + bl[N//2 -1]) - (al[N//2] + al[N//2 -1]) +1
else:
  ans = bl[N//2] - al[N//2] +1
print(ans)

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

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			var str = Console.ReadLine();
			str = str.Remove(str.Length - 1, 1);
			//while (!(str.LastIndexOf(str.Substring(str.Length / 2)) != str.Length / 2 && str.Length % 2 ==0))
			while(str.Substring(str.Length/2) != str.Remove(str.Length/2))
			{
				str = str.Remove(str.Length - 1, 1);
			}
				Console.WriteLine(str.Length);
		}
	}
}

Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int num;
    vector<int> vc;
    for (int i = 0; i < n; i++)
    {
        cin >> num;
        vc.push_back(num);
    }
    int max = 0;
    int sec_max=0;
    int index1;
    int index2;
    for (int i = 0; i < n; i++)
    {
        if (max<vc[i])
        {
            max = vc[i];
            index2 = index1;
            index1 = i;
        }else if(sec_max<vc[i]){
            sec_max = vc[i];
            index2 = i;
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (vc[i]==max)
        {
            cout << vc[index2] << endl;
        }else{
        cout << vc[index1] << endl;
        }
    }
    
    
    
    
}

Measured memory_bytes: 2548
#include<stdio.h>
int main(void)
{
	char str1[4]={'o','o','o'};
	char str2[4]={'o','o','x'};
	char str3[4]={'o','x','o'};
	char str4[4]={'o','x','x'};
	char str5[4]={'x','o','o'};
	char str6[4]={'x','x','o'};
	char str7[4]={'x','x','x'};
	char str8[4]={'x','o','x'};
	char str[5];
	scanf("%5s",str);
	if(strcmp(str1,str)==0){
		printf("1000");
	}
	else if(strcmp(str2,str)==0){
		printf("900");
	}
	else if(strcmp(str3,str)==0){
		printf("900");
	}
	else if(strcmp(str4,str)==0){
		printf("800");
	}
	else if(strcmp(str5,str)==0){
		printf("900");
	}
	else if(strcmp(str6,str)==0){
		printf("800");
	}
	else if(strcmp(str7,str)==0){
		printf("700");
	}
	else if(strcmp(str8,str)==0){
		printf("800");
	}
	return 0;
}

Measured memory_bytes: 128
/*
 * 2400.cc: You Are the Judge
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_T = 50;
const int MAX_P = 10;

/* typedef */

struct Stat {
  int i, sn, pn;
  bool operator<(const Stat &s) const {
    return sn > s.sn || (sn == s.sn && (pn < s.pn || (pn == s.pn && i < s.i)));
  }
};

/* global variables */

int wns[MAX_T][MAX_P];
Stat ss[MAX_T];

/* subroutines */

/* main */

int main() {
  for (;;) {
    int t, p, r;
    cin >> t >> p >> r;
    if (t == 0) break;

    memset(wns, 0, sizeof(wns));
    for (int i = 0; i < t; i++) ss[i].i = i, ss[i].sn = ss[i].pn = 0;

    for (int i = 0; i < r; i++) {
      int ti, pi, tm;
      string mes;
      cin >> ti >> pi >> tm >> mes;
      ti--, pi--;

      if (mes == "CORRECT") {
	ss[ti].sn++;
	ss[ti].pn += wns[ti][pi] * 1200 + tm;
      }
      else
	wns[ti][pi]++;
    }

    sort(ss, ss + t);

    for (int i = 0; i < t; i++)
      printf("%d %d %d\n", ss[i].i + 1, ss[i].sn, ss[i].pn);
  }

  return 0;
}

Measured memory_bytes: 1248
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)


class WeightedUnionFind:
    def __init__(self, n_nodes):
        self.n_nodes = n_nodes
        self.parent = [i for i in range(n_nodes)]
        self.rank = [1] * n_nodes
        self.size = [1] * n_nodes
        # 重みの管理
        self.weight = [0] * n_nodes

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            y = self.find(self.parent[x])
            # 親までの重みを追加していく
            self.weight[x] += self.weight[self.parent[x]]
            self.parent[x] = y
            return self.parent[x]

    def unite(self, x, y, w):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.rank[px] > self.rank[py]:
            self.parent[py] = px
            self.size[px] += self.size[py]
            self.weight[py] = -w - self.weight[y] + self.weight[x]
        else:
            self.parent[px] = py
            self.size[py] += self.size[px]
            self.weight[px] = w - self.weight[x] + self.weight[y]
            if self.rank[px] == self.rank[py]:
                self.rank[py] += 1

    def check(self, x, y):
        return self.find(x) == self.find(y)

    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

    def get_parent_list(self):
        return [i for i in range(self.n_nodes) if self.find(i) == i]

    def get_n_groups(self):
        return len(self.get_parent_list())

    def get_members(self, x):
        parent = self.find(x)
        return [i for i in range(self.n_nodes) if self.find(i) == parent]

    def get_members_dict(self):
        return {par: self.get_members(par) for par in self.get_parent_list()}


def main():
    N, M = map(int, input().split())
    Tree = WeightedUnionFind(N)
    for _ in range(M):
        L, R, D = map(int, input().split())
        if Tree.check(L - 1, R - 1):
            if Tree.diff(L - 1, R - 1) == D:
                continue
            else:
                print("No")
                return
        else:
            Tree.unite(L - 1, R - 1, D)
    print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 10788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n, d;
  cin >> n >> d;
  vector<vi> x(n, vi(d));
  rep(i, n) {
    rep(j, d) {
      cin >> x[i][j];
    }
  }

  set<int> ans;
  rep(i, n) {
    for (int j = 0; j < i; j++) {
      ll cnt = 0;
      rep(k, d) {
        cnt += abs(x[i][k] - x[j][k]) * abs(x[i][k] - x[j][k]);
      }

      for (int k = 0; k*k <= 200000; k++) {
        if (cnt == k*k) {
          ans.insert(100*(i+1)+(j+1));
        }
      }
    }
  }

  cout << ans.size() << endl;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

using namespace std;

int main(void){
  int n;
  cin>>n;
  vector<int> v(n+1);
  map<int,int> countmp_odd;
  map<int,int> countmp_even;

  int input;
  FOR(i,0,n){
    cin>>input;
    countmp_odd[input]++;
    i++;
    if(i==n) break;
    cin>>input;
    countmp_even[input]++;
  }

  

  set< pair<int,int> > maxset_odd;
  set< pair<int,int> > sec_maxset_odd;
  int max_o = 0;
  int sec_max_o = 0;
  
  for(auto x:countmp_odd){
    if(x.ND>max_o){
      sec_max_o = max_o;
      max_o=x.ND;
    }else if(x.ND>sec_max_o){
      sec_max_o=x.ND;
    }
  }
  
  for(auto x:countmp_odd){
    if(x.ND==max_o) maxset_odd.insert(x);
    if(x.ND==sec_max_o) sec_maxset_odd.insert(x);
  }



  set< pair < int,int > > maxset_even;
  set< pair < int,int > > sec_maxset_even;
  int max_e=0;
  int sec_max_e=0;
  
  for(auto x:countmp_even){
    if(x.ND>max_e){
      sec_max_e = max_e;
      max_e = x.ND;
    }else if(x.ND>sec_max_e){
      sec_max_e=x.ND;
    }
  }
  for(auto x:countmp_even){
    if(x.ND==max_e) maxset_even.insert(x);
    if(x.ND==sec_max_e) sec_maxset_even.insert(x);
  }

  //順序対の集合maxset_oddと集合maxset_evenの元を比較して，それぞれの元の左の要素が相異なるようにそれぞれ一つずつ元を選ぶ

  // cout1<<"max_o :\t"<<max_o<<endl;
  // cout<<"sec_max_o :\t"<<sec_max_o<<endl;
  // cout<<"max_e :\t"<<max_e<<endl;
  // cout<<"sec_max_e :\t"<<sec_max_e<<endl;

  
  int flag=0;
  for(auto x:maxset_even){
    for(auto y:maxset_odd){
      if(x.ST!=y.ST){
        flag=1;
        // cout<<"pattern 1"<<endl;
        cout<<n-x.ND-y.ND<<endl;  return 0; break;
      }
    }
  }


  
  if(flag==0){
    if(max_o==max_e && max_e==n/2){
      // cout<<"pattern 2"<<endl;
      cout<<n/2<<endl;
    }else{
      // cout<<"pattern 3"<<endl;
      cout<<n-max(max_o+sec_max_e,sec_max_o+max_e)<<endl;
    }
  }
  // if(maxset_even.size()==1 && maxset_odd.size()==1 && (*(maxset_even.begin())).ST==(*(maxset_odd.begin())).ND ){
  //   cout<<n/2<<endl;
  // }
  
  return 0;
}


Measured memory_bytes: 14720
icase=0
if icase==0:
    h,w=map(int,input().split())
    dp=[[0]*10 for i in range(10)]
    for i in range(10):
        dp[i]=list(map(int,input().split()))
    a=[]
    for i in range(h):
        a.extend(list(map(int,input().split())))
elif icase==1:
    h,w=2,4
    dp=[[0, 9, 9, 9, 9, 9, 9, 9, 9, 9], 
       [9, 0, 9, 9, 9, 9, 9, 9, 9, 9],
       [9, 9, 0, 9, 9, 9, 9, 9, 9, 9],
       [9, 9, 9, 0, 9, 9, 9, 9, 9, 9],
       [9, 9, 9, 9, 0, 9, 9, 9, 9, 2],
       [9, 9, 9, 9, 9, 0, 9, 9, 9, 9],
       [9, 9, 9, 9, 9, 9, 0, 9, 9, 9],
       [9, 9, 9, 9, 9, 9, 9, 0, 9, 9],
       [9, 9, 9, 9, 2, 9, 9, 9, 0, 9],
       [9, 2, 9, 9, 9, 9, 9, 9, 9, 0]]

    a=[-1, -1, -1, -1, 8, 1, 1, 8]

from collections import Counter
ac=Counter(a)

n=10
for k in range(n):
    for i in range(n):
        for j in range(n):
            dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])

icnt=0
for i in range(10):
    if ac[i]>0:
        icnt+=dp[i][1]*ac[i]  

print(icnt)      


Measured memory_bytes: 9552
# coding: utf-8
n = int(input())
b = list(map(int, input().split()))

if n == 2:
    print(2 * b[0])

else:
    ans = b[0]
    for i in range(n - 2):
        ans += min(b[i], b[i + 1])
    ans += b[-1]
    print(ans)


Measured memory_bytes: 2940
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */

#include <bits/stdc++.h>
//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

/*
PROG:
LANG: C++
*/

class A {
public:
    void solve(std::istream &in, std::ostream &out) {
        string A, B;
        in >> A >> B;
        string res = B + A;
        out << res << "\n";
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    A solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a, bool g){
	if(g){
		if(a[index]<key){
			return true;
		}
	}
	else{
		if(a[index]>key){
			return true;
		}
	}
	return false;
}

ll bin_search(ll key, vector<ll> &a, bool g){
	
	ll l=-1;
	ll r=a.size();

	if(g){
		l=a.size();
		r=-1;
	}

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a, g)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}


//深さ優先探索
void dfs(vector<string> &m,vector<vector<bool>> &seen, ll x, ll y, ll h, ll w){

	seen[y][x]=true;

	
	for(ll i=0;i<4;i++){
		ll nx=x,ny=y;
		if(i==0){ //up
			ny=y-1;
		}
		else if(i==1){ //down
			ny=y+1;
		}
		else if(i==2){ //right
			nx=x+1;
		}
		else{ //left
			nx=x-1;
		}

		if(nx<0 || nx>=w || ny<0 || ny>=h){
			continue;
		}
		if(seen[ny][nx]){
			continue;
		}
		
		if(m[ny][nx]=='#'){
			continue;
		}

		dfs(m,seen,nx,ny,h,w);
	}
}


void solve(){
	ll ans=0;

	ll n,m;
	cin>>n>>m;

	vector<ll> a(m,0);
	for(ll i=0;i<m;i++){
		cin>>a[i];
	}

	ll sum=0;
	for(ll i=0;i<m;i++){
		sum+=a[i];
	}

	ans=n-sum;

	if(ans<0){
		cout<<-1<<endl;
	}
	else{
		cout<<ans<<endl;
	}


}

int main(){
	
	solve();
	
    return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <map>
#include <set>
using namespace std;
int main(){
    int n, max_num = 0;
    cin >> n;
    map<string, int> s_num;
    set<string> s_set;
    string s;
    for(int i = 0; i < n; i++){
        cin >> s;
        auto r = s_set.insert(s);
        if(r.second == true) s_num[s] = 1;
        else s_num[s] += 1;
        if(max_num < s_num[s]) max_num = s_num[s];
    }
    for(auto iter = s_num.begin(); iter != s_num.end(); iter++){
        if(iter->second == max_num) cout << iter->first << endl;
    }
    return 0;
}

Measured memory_bytes: 34560
#include <iostream>
using namespace std;
typedef long long ll;
int main(){
  ll n,xb=0,yb=0;cin>>n;
  ll x[n],y[n],xa[n],ya[n],sum=1,sumx=-1,sumy=-1,ansx=1,ansy=1;
  fill(xa,xa+n,1);fill(ya,ya+n,1);
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  for(int i=0;i<n;i++){
    cin >> y[i];
  }
  for(int i=0;i<n-1;i++){
      for(int j=0;j<x[i];j++){
        sumx+=xa[j];
      }
      for(int j=0;j<y[i];j++){
        sumy+=ya[j];
      }
    xa[x[i]-1]=0;
    ya[y[i]-1]=0;
    for(int j=2;j<n-i;j++){
      sum=sum*j;
    }
    ansx=ansx+sum*sumx;
    ansy=ansy+sum*sumy;
    sum=1;sumx=-1;sumy=-1;
  }
  cout <<abs(ansx-ansy)<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] d = new int[N];
    int total =0;
    for (int i=0; i<N; i++) {
      d[i] = sc.nextInt();
    }
    for (int i=0; i<N; i++) {
      for (int j=i+1; j<N; j++) {
        total += d[i] * d[j];
      }
    }
    System.out.println(total);
  }
}

Measured memory_bytes: 20948
//#pragma GCC optimize("Ofast")   	//Comment optimisations for interactive problems (use endl)
//#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
 
using namespace std;
 
#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  pb             push_back

#define  dline          cout<<"///REACHED///\n";
#define  deb1(x)        cout<<#x<<" = "<<x<<'\n';
#define  deb2(x,y)      cout<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define  deb3(x,y,z)    cout<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;
 
const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   MAXN  =  2e+3+500;
const ll   MAXN1  =  1e+6+8;

string P[100];

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

 	int arr[n+1];
 	for(int i = 1; i <= n; i++)
 		cin >> arr[i];
 	ll curr = 1000;
 	for(int i = 1; i < n;)
 	{
 		if(arr[i]<arr[i+1])
 		{
 			curr = ((curr/arr[i])*arr[i+1]) + curr%arr[i];
 			i++;
 		}
 		else
 			i++;

 	}

 	cout << curr << endl;




}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 
const long long maxn=5*1e5;
string s;
struct st{
	long long count[27];
};
st arr[maxn];
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin>>s;
    
    for(long long i=0;i<s.size();i++){
    	for(long long j=0;j<=26;j++) arr[i].count[j]=0;
    	arr[i].count[s[i]-'a']++;
    	if(i!=0){
    		for(long long j=0;j<=26;j++) arr[i].count[j]+=arr[i-1].count[j];
    	}
    }
 
    long long ans=1;
    for(long long i=1;i<s.size();i++){
    	ans+=(i-arr[i-1].count[s[i]-'a']);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 43540
import java.io.*;
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		for(;;)
		{
			int A=sc.nextInt(),B=sc.nextInt();
			if ((A|B)==0)break;
			
			int n100=0,n500=0,n1000=0;
			
			int ret = B - A;
			
			while (ret - 1000 >= 0)
			{
				ret -= 1000;
				n1000++;
			}
			while (ret - 500 >= 0)
			{
				ret -= 500;
				n500++;
			}
			while (ret - 100 >= 0)
			{
				ret -= 100;
				n100++;
			}
			System.out.println(n100 + " " + n500 + " " + n1000);
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;

  // Disjoint Set DataStructure
  map< ll,ll > parent;     // reserve space for map if n > 10000
  map< ll,ll > urank;

  void create(ll x)
  {
    parent[x] = x ;
    urank[x] = 1 ;     // rank = no. of nodes in its subtree
  }

  ll find(ll x)
  {
    if( parent[x] != x )  //path compression
    {
      parent[x] = find(parent[x]) ;
    }
    return parent[x];
  }

  void merge(ll x, ll y)
  {
    ll xroot = find(x);
    ll yroot = find(y);

    if( urank[xroot] <= urank[yroot] )  // Union by rank
    {
      parent[xroot] = yroot ;
      urank[yroot] = urank[yroot] + urank[xroot] ;
      urank.erase(xroot);
    }
    else
    {
      parent[yroot] = xroot;
      urank[xroot] = urank[xroot] + urank[yroot] ;
       urank.erase(yroot);
    }
  }

void solve()
{
// string s;
  ll n,m,k,x=0,y=0,c=0,q,ans=0;
  cin>>n>>m;
  for (ll i = 1; i <= n; ++i)
  {
    create(i);
  }
  for (int i = 0; i < m; ++i)
  {
    cin>>x>>y>>k;
    if(find(x)!=find(y))
    {
      merge(x,y);
    }
  }
  c(urank.size());
}

signed main(){
   
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 14848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define nl "\n"
#define rep(i,n) for(ll i=0; i<(n); i++)
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sortup(V) sort(V.begin(), V.end())
#define sortdown(V) sort(V.rbegin(), V.rend())
#define MOD 998244353 //1000000007

ll N;
vector<double> x, y;
ll fact(ll n) {
    vl a(n+1);
    a[0]=1;
    for(ll i=1; i<=n; i++) a[i] = a[i-1] * i;
    return a[n];
}

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

    // solution comes here
    cin >> N;
    double xx,yy;
    rep(i, N) {
        cin >> xx >> yy;
        x.PB(xx);
        y.PB(yy);
    }

    double sum=0;
    rep(i, N) {
        rep(j, N) {
            if(i!=j)sum += sqrt(pow(x[i]-x[j],2.0) + pow(y[i]-y[j],2.0));
        }
    }

    printf("%.10f\n", sum/N);
}


Measured memory_bytes: 256
unittest
{
	assert( [ "3 14" ].solve == 2 );
	assert( [ "10 123" ].solve == 3 );
	assert( [ "100000 1000000000" ].solve == 10000 );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto m = 0L;
	input.front.formattedRead!"%s %s"( n, m );
	
	foreach( d; m.divisors.sort!( ( a, b ) => b < a ) )
	{
		if( n <= m / d ) return d;
	}
	return 1L;
}

// 約数列挙
auto divisors( long n )
{
	bool[ long ] ds;
	auto s = cast( long ) n ^^ 0.5L;
	for( auto i = 1L; i <= s; i++ )
	{
		if( n % i != 0 ) continue;
		ds[ i     ] = true;
		ds[ n / i ] = true;
	}
	return ds.keys;
}


Measured memory_bytes: 2868
H, W, D = map(int, input().split())
A = [0] * H
for i in range(H):
  A[i] = list(map(int, input().split()))
dict = {}
for i in range(H):
  for j in range(W):
    dict[A[i][j]] = [i, j]

dp = [0] * (H * W + 1)
for k in range(D + 1, H * W + 1):
  dp[k] = dp[k - D] + abs(dict[k][0] - dict[k - D][0]) + abs(dict[k][1] - dict[k - D][1])

Q = int(input())
for i in range(Q):
  L, R = map(int, input().split())
  print(dp[R] - dp[L])



Measured memory_bytes: 26204
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>
 
// #include <unordered_set>
// #include <unordered_map>
 
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
 
#define pb push_back
#define mp make_pair
 
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
 
typedef std::pair<int, int> P;
typedef long long ll;
typedef long double ld;
 
const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = INF * 1ll * INF;
const ld DINF = 1e200;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
using namespace std;
 
// #define int long long


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cin高速化

    
   

    int n;
    cin>>n;

    int a[n];
    int tmp;
    // int count[]

    std::vector<int> v;
    int v_max=-1;
    int ans=0;

    REP(i,n){
        cin>>tmp;

        v_max=max(v_max,tmp);
        v.pb(tmp);
    }

    sort(v.begin(),v.end());
    v.pb(-1);

    // REP(i,n){
    //     cout<<v[i]<<" ";
    // }cout<<endl;

    int z=0;
    int count=1;
    int now=v[0];


    REP(i,n){
        if(v[i]==v[i+1])count++;

        else{

            // cout<<"now:"<<now<<endl;
            // cout<<"count:"<<count<<endl;
            // cout<<"break"<<endl;
            
            if(count>now){
                ans+=(count-now);
            }else if(count<now){
                ans+=count;
            }


            now=v[i+1];
            count=1;


            


        }
    }
    

    cout<<ans<<endl;


    return 0;
 
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,begin,end) for(int i=(begin),i##_end = (end);i<i##_end;i++)

int main()
{
    int n,sign = 1;
    cin>>n;
    vector<int> dam(n+1);
    for(int i=1;i<=n;i++)
        cin>>dam[i];
    vector<int> mountain(n+1);
    for(int i=1;i<=n;i++)
    {
        mountain[1] = mountain[1] + sign*dam[i];
        sign = -sign;
    }
    mountain[1]>>=1;
    for(int i=2;i<n;i++){
        mountain[i] = dam[i-1] - mountain[i-1];
    }
    mountain[n] = dam[n] - mountain[1];
    for(int i=1;i<=n;i++)
        cout<<mountain[i]*2<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
using namespace std;

int altitute(int x, int y, int cx, int cy,int h){
    return max(h-abs(x-cx)-abs(y-cy),0);
}

int getTh(int cx,int cy, int* c){
    return c[2]+abs(cx-c[0])+abs(cy-c[1]);
}

int main() {
    int N,i,c[101][3],j,ti,k;
    cin>>N;

    for(i=0;i<N;i++){
        cin>>c[i][0]>>c[i][1]>>c[i][2];
        if(c[i][2]!=0)ti=i;
    }
    for(i=0;i<=100;i++){
        for(j=0;j<=100;j++){
            int th=getTh(i,j,c[ti]);
            bool isOkay=true;
            for(k=0;k<N;k++){
                if(ti==k)continue;
                if(altitute(c[k][0],c[k][1],i,j,th)!=c[k][2]){
                    isOkay=false;
                    break;
                }
            }
            if(isOkay){
                cout<<i<<" "<<j<<" "<<th;
                return 0;
            }
        }
    }
    cout<<0<<" "<<0<<" "<<0;
    return 0;
}

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

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define eb          emplace_back
#define	endl		'\n' 
#define max(a,b)	((a)>(b)?(a):(b))
#define min(a,b)	((a)<(b)?(a):(b))
#define vi          vector<int>
#define vii         vector<pair<int, int> >
#define mp          make_pair
#define mem1(a)     memset((a),-1,sizeof(a))
#define all(a)      (a).begin(),(a).end()
#define vs          vector<string>
#define F           first
#define S           second
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    (a)*((b)/gcd((a),(b)))
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mi          map<int,int>
#define sz(x)       (ll)(x).size()
#define rep(i,a,b)  for(int i=(a);i<(b);i++)
#define pii         pair<int,int>

int solve()
{
	int n;
	cin>>n;
	int arr[n][3];
	int ans[n][3];
	rep(i,0,n)
	{
		rep(j,0,3)
		{
			cin>>arr[i][j];
			ans[i][j]=0;
		}
	}
	ans[0][0]=arr[0][0];
	ans[0][1]=arr[0][1];
	ans[0][2]=arr[0][2];
	rep(i,1,n)
	{
		rep(j,0,3)
		{
			rep(k,0,3)
			{
				if (k!=j)
				{
					ans[i][j]=max(ans[i-1][k]+arr[i][j],ans[i][j]);
				}
			}
		}
	}
	cout<<max(max(ans[n-1][0],ans[n-1][1]),ans[n-1][2]);
    return 0;
}
signed main()
{
    FAST
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); 
        freopen("output.txt", "w", stdout); 
    #endif 
    int t=1;
    //cin>>t;
    while(t)
    {
        solve();
        t--;
    }
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}

Measured memory_bytes: 6108
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
      
      
public class Main {		
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			int[][] list = new int[n][n];
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++) {
					list[i][j] = sc.nextInt();
				}
			}
			//?????§????°? ?????§?????§
			boolean[][] R = new boolean[n][n];
			boolean[][] L = new boolean[n][n];
			for(int i = 0; i < n; i++) {
				int MIN = Integer.MAX_VALUE;
				for(int j = 0; j < n; j++) {
					if(list[i][j] < MIN) {
						MIN = list[i][j];
					}
				}
				for(int j = 0; j < n; j++) {
					if(list[i][j] == MIN) {
						R[i][j] = true;
					}
				}
			}
			for(int i = 0; i < n; i++) {
				int MAX = 0;
				for(int j = 0; j < n; j++) {
					if(list[j][i] > MAX) {
						MAX = list[j][i];
					}
				}
				for(int j = 0; j < n; j++) {
					if(list[j][i] == MAX) {
						L[j][i] = true;
					}
				}
				
			}
			int id = 0;
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++) {
					if(L[i][j] && R[i][j] && id < list[i][j]) id = list[i][j]; 
				}
			}
			System.out.println(id);
		}
	}
 }

Measured memory_bytes: 26176
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
	int N, M,i, j, k, count = 0;
	string str;

	cin >> N >> M;
	vector<int> A(M);
	for (i = 0;i < M;++i)
		cin >> A[i];
	for (i = 0;i < M;++i)
	{
		N -= A[i];
		if (N < 0)
		{
			cout << -1;
			return 0;
		}
	}
	cout << N;
	return 0;
}

Measured memory_bytes: 3668
#include<cstdio>
#include<functional>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	char al[27]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	char s[101];
	int i,j,cnt,p,len;
	scanf("%s",s);
	len=strlen(s);
	p=0;
	for(i=0;i<len;i++)	{
		while(1)	{
			p++;
			j=p%26;
			if(al[j]==s[i])	break;
		}
	}
	cnt=p/26;
	printf("%d\n",cnt);
	return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for(int i = a; i <= b; ++i) {
        stringstream ss;
        ss<<i;
        string s;
        ss>>s;
        string r = s;
        reverse(all(r));
        if(s==r) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;
const ll inf = 1e18;


int n;
ll xlo,xhi,ylo,yhi;

ll X[maxn], Y[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    
    cin>>n;
    xlo=ylo=inf;
    xhi=yhi=-inf;
    for (int i=0; i<n; i++) {
	ll x,y;
	cin>>x>>y;
	X[i]=x;Y[i]=y;
	xlo=min(xlo,x);
	ylo=min(ylo,y);
	xhi=max(xhi,x);
	yhi=max(yhi,y);
    }


    vector<pair<ll,ll>> corners;
    corners.push_back({xlo,ylo});
    corners.push_back({xlo,yhi});
    corners.push_back({xhi,ylo});
    corners.push_back({xhi,yhi});


    // for (auto p: corners) {
    // 	cout<<p.first<<","<<p.second<<endl;
    // }


    ll res = -inf;

    for (auto corner: corners) {

	ll lo = inf;
	ll hi = -inf;
	for (int i=0; i<n; i++) {
	    ll dist = abs(corner.first-X[i])+abs(corner.second-Y[i]);
	    lo = min(lo, dist);
	    hi = max(hi, dist);
	}

	for (int i=0; i<n; i++) {
	    ll dist = abs(corner.first-X[i])+abs(corner.second-Y[i]);
	    res = max(res, abs(lo-dist));
	    res = max(res, abs(hi-dist));
	}
    }

    


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


Measured memory_bytes: 6780