akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        
        String strStdIn = in.readLine();
        int n = Integer.parseInt(strStdIn);
        String[] data = in.readLine().split(" ");
        
        int sum = Integer.parseInt(data[0]);
        for(int i = 1; i < n - 1; i++) {
            int a = Integer.parseInt(data[i-1]);
            int b = Integer.parseInt(data[i]);
            if(a < b) {
                sum += a;
            } else {
                sum += b;
            }
        }
        if (n > 0) { sum += Integer.parseInt(data[n-2]); }
        
        System.out.println(sum);
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
	ll x, k, d, ans = 0;
	cin >> x >> k >> d;
	if ((x / k) / d == 0) {
		ll p = (abs(x) + abs(d) - 1) / abs(d);
		if (p % 2 == k % 2) ans = abs(x) - abs(d * p);
		else ans = abs(x) - abs(d * (p - 1));
	}
	else {
		ll p = k * d;
		ans = abs(x) - abs(p);
	}
	cout << abs(ans) << endl;
	return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, n) for (int i = 1; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    if (A + B - 1 > N || (lint)A * B < N) {
        cout << -1 << "\n";
        return 0;
    }
    if (B == 1) {
        rep(i, N) {
            cout << i + 1;
            if (i == N - 1) cout << "\n";
            else cout << " ";
        }
        return 0;
    }
    vector<int> ans(N, -1);
    rep(i, (N - A) / (B - 1)) {
        rep(j, B) {
            ans[i * B + j] = (i + 1) * B - (j + 1);
        }
    }
    if ((N - A) % (B - 1)) {
        int x = (N - A) / (B - 1) * B;
        rep(i, (N - A) % (B - 1) + 1) {
            ans[x + i] = x + (N - A) % (B - 1) - i;
        }
    }
    rep(i, N) {
        if (ans[i] == -1) ans[i] = i;
    }
    rep(i, N) {
        cout << ans[i] + 1;
        if (i == N - 1) cout << "\n";
        else cout << " ";
    }
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll h,w,k;
  cin >> h >> w >> k;
  vector<vector<char>> s(h,vector<char> (w));
  rep(i,h){
    rep(j,w){
      cin >> s[i][j];
    }
  }
  vvl a(h,vl(w));
  vector<bool> B(h,false);
  ll x=1;
  ll cnt=0;
  rep(i,h){
    rep(j,w){
      if(s[i][j]=='#'){
        B[i]=true;
      }
    }
  }
  rep(i,h){
    if(B[i]){
      cnt=0;
      rep(j,w){
        if(s[i][j]=='#'){
          cnt++;
        }
        if(cnt==2){
          cnt=1;
          x++;
        }
        a[i][j]=x;
      }
      x++;
    }
  }
  rep(i,h){
    if(!B[i]){
      ll y=i;
      bool c=false;
      while(B[y]==false&&c==false){
        if(y==h-1){
          c=true;
        }
        y++;
      }
      while(B[y]==false){
        y--;
      }
      rep(j,w){
        a[i][j]=a[y][j];
      }
    }
  }
  rep(i,h){
    rep(j,w){
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 1536
#include <stdio.h>

int main() {
	int N,D;
	scanf("%d %d",&N,&D);
	int observe = D*2 + 1, cnt = 0;
	int sum = 0;
	while (sum < N) {
		cnt++;
		sum += observe;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		String n = in.nextLine();
		if("ARC".equals(n)) {
			System.out.println("ABC");
		}else {
			System.out.println("ARC");
		}
		
		
		in.close();
	}
}


Measured memory_bytes: 35624
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)
#define FORR(i,n,m) for(ll i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 100000000
#define MOD 100000007
#define SIZE 100005
#define pi  3.14159265358979323846
 
int main(){
    while(1){
        ll a,b;
        ll ans = 0;
        cin >> a >> b;
        if(a==0 && b==0){break;}
        FOR(i,1,a-1){
            FOR(j,i+1,a){
                FOR(k,j+1,a+1){
                    if(i+j+k==b){
                        ans++;
                        //cout << i << " ";
                        //cout << j << " ";
                        //cout << k << endl;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int data[] = new int [n];
		int a,ans = 0;
		for(int i = 0;i < n;i++)data[i]=sc.nextInt();
		for(int i = 0;i < n;i++) {
			for(int j = i+1;j < n;j++) {
				if(data[i] >data[j]) {
					a = data[i];
					data[i] = data[j];
					data[j] = a;
				}
			}
		}
		
		for(int i = n-1;i > n-k-1;i--) {
			ans += data[i];
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 24020
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main(){
    int N;
    cin >> N;
    int upper = N/100;
    int lower = N%100;
    bool yymm = (1 <= lower && lower <= 12);
    bool mmyy = (1 <= upper && upper <= 12);
    if(yymm && mmyy){
        cout << "AMBIGUOUS" << endl;
    }else if(yymm){
        cout << "YYMM" << endl;
    }else if(mmyy){
        cout << "MMYY" << endl;
    }else{
        cout << "NA" << endl;
    }
    cerr << upper << "," << lower << endl;
    return 0;
}



Measured memory_bytes: 256
import sys
import numpy as np

num_data = sys.stdin.readlines()
str_num_list = num_data[1].split()
num_list = [int(s) for s in str_num_list]
ans = 1
if 0 in num_list:
  ans = 0
else:
  for i in range(int(num_data[0])):
    ans *= num_list[i]
    if ans > pow(10, 18):
      ans = -1
      break

print(ans)

Measured memory_bytes: 42456
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
int main()
{
	int a, p;
	cin >> a >> p;
  	a = ((a * 3) + p) / 2;
	cout << a << endl;
	return(0);
}

Measured memory_bytes: 256
import * as fs from 'fs';

namespace AtCoder {
    export interface Paramable {
        readonly args: string[][];
    }

    export interface Task {
        main(this: Task): void;
    }
}

namespace AtCoder.abc086 {
    export class TaskA implements AtCoder.Task, AtCoder.Paramable {
        public constructor(public readonly args: string[][]) {
        }

        public main(this: TaskA): void {
            const [a, b]: number[] = this.args[0].map(Number);
            const ab: number = parseInt(a.toString() + b.toString(), 10);
            console.log(Math.sqrt(ab) % 1 === 0 ? 'Yes' : 'No');
        }
    }

    const args: string[][] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(r => r.split(' '));
    const task: TaskA = new TaskA(args);
    task.main();
}

Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define D(x) cerr << #x << " = " << (x) << '\n'
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	vector<vector<bool>> dp(2, vector<bool>(k + 1, true));
	for(int i = 0; i < n; ++ i) cin >> a[i];
	for(int i = 0; i <= k; ++ i) {
		for(auto x:a) {
			if(x > i) continue;
			dp[0][i] = dp[0][i] & dp[1][i - x];
			dp[1][i] = dp[1][i] & dp[0][i - x];
		}
		dp[0][i] = !dp[0][i];
		dp[1][i] = !dp[1][i];
	}
	cout << (dp[0][k] ? "First\n":"Second\n");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define mkp make_pair
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<<endl;}}
#define print1d(mat,n){for(int i=0;i<(int)(n);i++)cout<<mat[i]<<" ";cout<<endl;}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<endl;
#define init(v,x) for (auto &itr:v){itr=x;}
#define ln length()
#define sz size()
int dsu[200005];
int size1[200005];
int find1(int x){
    while(dsu[x]!=x){
        dsu[x]=dsu[dsu[x]];
        x=dsu[x];
    }
    return x;
}
void union1(int x,int y){
    x=find1(x);
    y=find1(y);
    if(x==y){
        return;
    }
    if (size1[x]>size1[y]){
        dsu[y]=x;
        size1[x]+=size1[y];
    }
    else{
        dsu[x]=y;
        size1[y]+=size1[x];
    }
}
void solve(){
   int n,m,a,b;
   cin>>n>>m;
   rep(i,0,n+1){
       dsu[i]=i;
       size1[i]=1;
   }
   rep(i,0,m){
       cin>>a>>b;
//       cout<<a<<" "<<b<<endl;
       union1(a,b);
   }
   int ans=0;
   rep(i,1,n+1){
       ans=max(ans,size1[i]);
   }
//   print1d(size1,n+1)
//   print1d(dsu,n+1)
   cout<<ans<<endl;

}

int32_t main(){
    fastIO
  
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

int n;
const ll mod = 998244353;
int a[100010];
int cnt[100010];

ll powe(ll x, ll y)
{
    if(!x && !y) return 1;
    if(!x) return 0;
    if(!y) return 1;
    ll ret = powe(x, y>>1);
    ret = ret * ret % mod;
    if(y&1) ret = ret * x % mod;
    return ret;
}

int main()
{
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> n;
    Forn(i, n)
    {
        int x;
        cin >> x;
        a[i] = x;
        cnt[x]++;
    }
    if(a[1]!=0)
    {
        cout << 0 << endl;
        return 0;
    }
    if(cnt[0]>=2)
    {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    for(int i=1; i<=n+1; i++)
    {
        ans = ans * powe(cnt[i-1], cnt[i]);
        ans %= mod;
    }
    cout << ans << endl;
}


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

int main() {
  
  	int a,b;
  	cin >> a >> b;
  
  	if((a*b)%2==1){
    	cout << "Odd" << endl;
    }
  	else{
    	cout << "Even" << endl;
    }
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut d: Vec<isize> = (0..n).map(|_| read()).collect();

    d.sort();
    println!("{}", d[n / 2] - d[n / 2 - 1]);
}

Measured memory_bytes: 4352
//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())

priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


void solve(){
    int n,m,x;
    cin >> n >> m >> x;
    vector<llint>mp(n+1,0);
    for(int i=0;i<m;i++){
        int a;
        cin >> a;
        mp[a]=1;
    }
    int res1=0,res2=0;
    for(int c=x;c>0;c--)res1+=mp[c];
    for(int c=x;c<n;c++)res2+=mp[c];
    cout << min(res1,res2) << endl;


}

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




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

int main()
{
    int n;
    while(cin>>n){
        double temp, sum = 0.0;
        for(int i=0;i<n;i++){
            cin>>temp;
            sum+= 1.0 / temp;
        }
        printf("%.6f\n", 1.0/sum);
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define queue QQQ
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RAnK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
const int maxn = 2e6+233; 
const int mod = 1e9+7;
int fac[maxn],inv[maxn],f[maxn],n;
inline int qpow(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1) ans=1ll*ans*a%mod;
	return ans;
}
inline int C(int n,int m){
	return 1ll * fac[n] * inv[m] % mod * inv[n-m] % mod;
}
int main(){
	n=rd();
	fac[0] = 1;
	Rep(i,1,n) fac[i] = 1ll * fac[i-1] * i % mod;
	inv[n] = qpow(fac[n],mod-2);
	Dep(i,n-1,0) inv[i] = 1ll * inv[i+1] * (i+1) % mod;
	Dep(i,n-1,(n+1)/2){
		f[i] = 1ll * C(i-1,n-1-i) * fac[i] % mod * fac[n-1-i] % mod;
		f[i+1] = (f[i+1] - f[i] + mod) % mod;
	}
	int ans = 0;
	Dep(i,n-1,(n+1)/2) ans = (ans + 1ll * i * f[i] % mod) % mod;
	writeln(ans);
}
//f[i]表示答案小于等于i的方案数：i步可以完成
//也就是相当于有i个变量 


Measured memory_bytes: 15104
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include <bitset>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<string>
typedef long long ll;
using namespace std;
int arr[200];
int main() {
	int n;
	int res = 0;
	cin >> n;
	for (int i = 0; i < 2 * n; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + 2 * n);
	for (int i = 0; i < 2 * n;i=i+2){
		res += arr[i];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
int N;
char s[110];
int main(){
  std::cin>>N;
  rep(i,N) std::cin>>s[i];
  int max=0,x=0;
  rep(i,N){
    if(s[i]=='I') x++;
    else x--;
    max=std::max(max,x);
  }
  std::cout<<max<<"\n";
  return 0;
}


Measured memory_bytes: 256
input()
a = list(map(int,input().split()))
former = []
latter = []
difference = 1000
for i in range(1,len(a)):
    former = []
    latter = []
    for j in range(len(a)):
        if j <= i:
            former.append(a[j])
        else:
            latter.append(a[j])
    if abs(sum(former) - sum(latter)) < difference:
        difference = abs(sum(former) - sum(latter))
print(difference)

Measured memory_bytes: 9096
#include <cstdio>

int main() {
    int W, H, x, y, r;
    scanf(" %d %d %d %d %d", &W, &H, &x, &y, &r);

    if( ( r <= x && x <= W-r ) && ( r <= y && y <= H-r ) ) printf("Yes\n");
    else printf("No\n");

    return 0;
}



Measured memory_bytes: 2696
H,W,K = gets.split.map &:to_i

C = H.times.map{ gets.chomp.chars.map{ _1=="#"}}

ans = 0
(2**H).times do |h|
    rows = H.times.select{|i| (h & 1<<i)==0}.map{C[_1]}
    next if rows.empty?

    (2**W).times do |w|
        idxs = W.times.select{|i| (w & 1<<i)!=0}
        next if idxs.empty?

        ans += 1 if K == rows.sum{|row| idxs.select{row[_1]}.count }
    end
end

p ans

Measured memory_bytes: 14312
#include<stdio.h>
int main(void)
{
  int x, a=0, b=0, c=0, d=0, e=0;

  while(scanf("%d", &x)!=EOF)
    {
      for (a=0;a<=x && a<=9;a++){
        for (b=0;a+b<=x && b<=9;b++){
          for (c=0;a+b+c<=x && c<=9;c++){
            for (d=0;a+b+c+d<=x && d<=9;d++){
              if(a+b+c+d==x)e+=1;}}}}
            printf("%d\n", e);
            e=0;
    }
  return 0;

}

Measured memory_bytes: 596
require 'matrix'
ERROR = 1e-5
include Math
class Line
	#ax+by = c   (a > 0 or (a == 0 && b > 0))
	def self.through_two_points(x1, y1, x2, y2)
		a = y1 - y2
		b = x2 - x1
		c = a * x1 + b * y1
		new(a, b, c, x1, y1, x2, y2)
	end

	def cross_point(l)
		m = Matrix[
			[@a, @b],
			[l.a, l.b],
		];
		v = Vector[@c, l.c]
		(m.inv * v).to_a
	end

	private_class_method :new

	def initialize(*args)
		@a, @b, @c, @x1, @y1, @x2, @y2 = args	
	end

	attr_reader :a, :b, :c, :x1, :y1, :x2, :y2
end

n = gets.to_i
points = (1..n).map{ gets.split.map(&:to_i) }
vecs = (points + [points[0]]).each_cons(2).map do |(x1, y1), (x2, y2)|
	Vector[x2 - x1, y2 - y1]
end

R = vecs.map(&:r).inject(:+)

lines = []

get_bisection = -> do
	org = Vector[*points[0]]
	halfs = []
	r = 0
	until r >= R / 2
		halfs << vecs[halfs.size]
		r += halfs[-1].r
	end
	d = halfs[-1].r
	halfs[-1] *= (d - (r - R / 2)) / d
	vecs << vecs.shift
	points << points.shift
	Line.through_two_points(*org.to_a, *halfs.inject(org, &:+))
end

cx, cy = get_bisection[].cross_point(get_bisection[])
ok = (1..n).all? do
	l = get_bisection[]
	hypot(cx - (l.x1 + l.x2) / 2, cy - (l.y1 + l.y2) / 2) < ERROR
end

puts ok ? sprintf("%.6f %.6f", cx, cy) : 'NA'

Measured memory_bytes: 9312
import sys
input = sys.stdin.readline
H,W= map(int,input().split())
mod=10**9+7
chk=[[0] for f in range(H)]
ans=[[0 for e in range(W)] for f in range(H)]
ans[0][0]=1
for i in range(H):
 chk[i]=[d for d in input()]
for i in range(1,W):
 if chk[0][i]==".":
  ans[0][i]=ans[0][i-1]
for i in range(1,H):
 if chk[i][0]==".":
  ans[i][0]=ans[i-1][0]
for i in range(1,H):
 for j in range(1,W):
  if chk[i][j]==".":
   ans[i][j]=ans[i-1][j]+ans[i][j-1]
   ans[i][j]%=mod
print(ans[H-1][W-1])


Measured memory_bytes: 90460
def get_(i):
    zero_len = 6-len(str(i))
    return '0'*zero_len+str(i)

def get_idx(n,L):
    if len(L)<100:
        left=0
        right=len(L)
    else:    
        left=0
        right=len(L)

        i=0
        while i < 50:
            half=int((left+right)/2)
            if n <= L[half]:
                right = half
            else:
                left = half
            i+=1
        
    if left >= 1:
        left -= 1
        
    for i in range(left,right+1):
        if L[i]==n:
            return i

N,M = list(map(int,input().split()))
N_list=[[] for n in range(N)]
M_list=[]

for m in range(M):
    P,Y=list(map(int,input().split()))
    N_list[P-1].append(Y)
    M_list.append([P,Y])
    
for n in N_list:
    n.sort()
    
for m in M_list:
    p=get_(m[0])
    
    i=get_idx(m[1],N_list[m[0]-1])+1
    i=get_(i)
    
    print(p+i)

Measured memory_bytes: 99504
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, const map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
constexpr int MOD = 1e9 + 7;

signed main() {
  int n, m; cin >> n >> m;
  VVI rev(n);
  REP (i, n - 1 + m) {
    int u, v; cin >> u >> v;
    u--;
    v--;
    rev[v].push_back(u);
  }
  VI length(n, 0);
  VI ans(n, -1);
  function<void(int, int)> dfs = [&](int v, int p) {
    if (length[v] > 0) return;
    for (int s: rev[v]) {
      dfs(s, v);
      if (length[s] + 1 > length[v]) {
        ans[v] = s;
        length[v] = length[s] + 1;
      }
    }
  };
  REP (i, n) {
    dfs(i, -1);
  }
  REP (i, n) {
    cout << ans[i] + 1 << endl;
  }
}


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

using namespace std;
vector<vector<char>>theval(30,vector<char>(30,'.'));
int n,m;
int output=0;
int hey(int a,int b,int c){
     vector<vector<int>>visited(n+1,vector<int>(m+1,0));
     queue<pair<pair<int,int>,int>>wow;//inseeert
     wow.push({{a,b},c});
     visited[a][b]=1;
     while(wow.size()>0){
         int start=wow.front().first.first;
         int last=wow.front().first.second;
         int val=wow.front().second;
         if(start-1>=0&&theval[start-1][last]!='#'&&visited[start-1][last]==0){
             wow.push({{start-1,last},val+1});
             output=max(output,val+1);
             visited[start-1][last]=1;
         }
         if(start+1<n&&visited[start+1][last]==0&&theval[start+1][last]!='#'){
             wow.push({{start+1,last},val+1});
             output=max(output,val+1);
             visited[start+1][last]=1;
         }
         if(last-1>=0&&theval[start][last-1]!='#'&&visited[start][last-1]==0){
             wow.push({{start,last-1},val+1});
             output=max(output,val+1);
             visited[start][last-1]=1;
         }
         if(last+1<m&&visited[start][last+1]==0&&theval[start][last+1]!='#'){
              wow.push({{start,last+1},val+1});
             output=max(output,val+1);
             visited[start][last+1]=1;
         }
         wow.pop();
     }
     
     
}
int main()
{
    
    cin>>n>>m;
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>theval[i][j];
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            if(theval[i][j]!='#'){
            hey(i,j,0);}
        }
    }
    cout<<output<<endl;
}


Measured memory_bytes: 256
import java.util.*
import kotlin.comparisons.compareByDescending
import kotlin.comparisons.thenByDescending

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val jobs = Array(n) {
        readLine()!!.split(" ").map { it.toInt() }.let { Job(it[0], it[1]) }
    }
    jobs.sortWith(compareByDescending<Job> { it.b }.thenByDescending { it.a })
    val jobShift = Array(m) {
        false
    }
    val set: TreeSet<Int> = TreeSet((0 until n).toList())
    var ans = 0
    jobs.forEachIndexed { index, job ->
        val insertP = m - job.a
        var i = insertP
//        while (i >= 0) {
//            if (jobShift[i]) {
//                i--
//            } else {
//                jobShift[i] = true
//                ans += job.b
//                break
//            }
//        }
        val ret = set.floor(insertP)
        if(ret != null) {
            set.remove(ret)
            ans += job.b
        }
    }
    println(ans)
}

class Job(val a: Int, val b: Int)

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

const int MAX_N = 100005;

int main() {
  int n;
  int h[MAX_N];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> h[i];

  int tmp = h[0] - 1;

  for (int i = 1; i < n; i++) {
    if (tmp > h[i]) {
      cout << "No" << endl;
      return 0;
    }
    else {
      tmp = max(tmp, h[i] - 1);
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 640
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,m,s,g1,g2;
	while(cin>>n>>m>>s>>g1>>g2,n){
		s--,g1--,g2--;
		int a,b,c,d[n][n];
		rep(i,n)rep(j,n)d[i][j]=1<<20;
		rep(i,m){
			cin>>a>>b>>c;a--,b--;
			d[a][b]=c;
		}
		rep(i,n)d[i][i]=0;
		rep(k,n)rep(i,n)rep(j,n)if(d[i][j]>d[i][k]+d[k][j])d[i][j]=d[i][k]+d[k][j];
		
		int ans=d[s][g1]+d[s][g2];
		rep(i,n)if(ans>d[s][i]+d[i][g1]+d[i][g2])ans=d[s][i]+d[i][g1]+d[i][g2];
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 904
// https://atcoder.jp/contests/agc031/tasks/agc031_b

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

ll N, M, C, l[200001], r, m;
int main()
{
  r = 1;
  m = -1;
  M = 1e9 + 7;

  cin >> N;

  REP(i, N)
  {
    cin >> C;
    if (m == C)
      continue;
    m = C;
    r += l[C];
    r %= M;
    l[C] = r;
  }

  cout << r << '\n';

  return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	string s, r;
	cin >> s >> r;
	int a, b;
	cin >> a >> b;
	string c;
	cin >> c;
	if (c == s) {
		cout << a - 1 << " " << b << endl;
	} else {
		cout << a << " " << b - 1 << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define REP(i,n) for(int i=2;i<=int(n);i++)
#define M 1000000007
using namespace std;

int main()
{
  int N;
  cin >> N;
  long long int ans = 1;
  REP(i,N){
    ans *= i;
    ans %= M;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

ll MOD = 1e9 + 7;

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

    vector<string> v(h);

    for(int i = 0; i < h; ++i)
        cin >> v[i];

    vector<vector<ll> > dp(h, vector<ll>(w));
    dp[0][0] = 1;

    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            if(v[i][j] == '#' || (i == 0 && j == 0))
                continue;

            ll left = 0;
            if(j - 1 >= 0)
                left = dp[i][j - 1];
            ll up = 0;
            if(i - 1 >= 0)
                up = dp[i - 1][j];

            dp[i][j] = (left + up) % MOD;
        }
    }

    cout << dp[h - 1][w - 1] << endl;

    return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

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

	for (int i = 0; i < M; ++i) {
		int B, C;
		cin >> B >> C;

		while (B > 0) {
			auto it = m.begin();
			if (C <= it->first) {
				break;
			}
			int x = min(it->second, B);
			it->second -= x;
			if (it->second == 0) {
				m.erase(it);
			}
			m[C] += x;
			B -= x;
		}
	}

	long long ans = 0;
	for (auto &e : m) {
		ans += e.first * e.second;
	}
	cout << ans << endl;
}


Measured memory_bytes: 6528
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll h, w, k;
        cin >> h >> w >> k;

        ll dp[h + 1][w];
        rep(i, h + 1) rep(j, w) dp[i][j] = 0;
        dp[0][0] = 1;
        rep(i, h) {
            rep(j, w) {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= mod;
                repone(l, (1LL << (w - 1)) - 1) {
                    if (l & (l >> 1)) continue;
                    if (j > 0 && l >> (j - 1) & 1) {
                        dp[i + 1][j - 1] += dp[i][j];
                        dp[i + 1][j - 1] %= mod;
                    }else if (j < w - 1 && l >> j & 1) {
                        dp[i + 1][j + 1] += dp[i][j];
                        dp[i + 1][j + 1] %= mod;
                    } else {
                        dp[i + 1][j] += dp[i][j];
                        dp[i + 1][j] %= mod;
                    }
                }
            }
        }
        cout << dp[h][k - 1] << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K,X; cin >> K >> X;
    if (500*K>=X) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
s = []
t = []

for i in range(N):
    s_a, t_a = input().split()
    s.append(s_a)
    t.append(int(t_a))
X = input()

time = 0
flag = False
for j in range(N):
    if flag == True:
        time += t[j]
    if s[j] == X:
        flag = True
print(time)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //ATTENTION: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/
string s;
/**********************************/

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

    int len = s.size();
    FORD(i, len-1, 2) {
        if(i%2==1) continue;
        bool flg = true;
        REP(j, i/2) {
            if(s[j]!=s[j+i/2]) {
                flg = false;
                break;
            }
        }
        if(flg) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let n = line.trim().parse::<i32>().unwrap();
    println!("{}", n * (n + 1) / 2);
}


Measured memory_bytes: 4352
using System;
class Participants
{
	static void Main(string[] args)
	{
		while (true)
		{
			int n = int.Parse(Console.ReadLine());
			if (n == 0) break;
			string[] s = Console.ReadLine().Split(' ');
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = int.Parse(s[i]);
			}
			Array.Sort(a);
			int dif_min = 1000000;
			for (int i = 0; i < n - 1; i++)
			{
				int dif = a[i + 1] - a[i];
				if (dif < dif_min) dif_min = dif;
			}
			Console.WriteLine(dif_min);
		}
	}
}


Measured memory_bytes: 13884
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define mp make_pair
#define np next_permutation
#define pb push_back
#define all(x) (x.begin(),x.end())
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
using namespace std; 
const int maxn=500+5;

vector <int> v[maxn]; 
bool vis[maxn];

void init(){
	rep(i,0,maxn) v[i].clear();
	memset(vis,0,sizeof(vis));
}


void addedge(int l,int r){
	int len=r-l;
	v[l].pb(len);
}

int  checkedge(int l,int len){
//	if(v[l].begin()!=v[l].end()) 
//		 cout<<*v[l].begin()<<endl; 
	int ans=upper_bound(v[l].begin(),v[l].end(),len)-v[l].begin();
//	cout<<"ans="<<ans<<endl;
	return ans;
}
int n,m,q,li,ri,pi,qi;

int main(){
	ios::sync_with_stdio(false);
	while(cin>>n>>m>>q){
		init(); 
		rep(i,0,m){
			cin>>li>>ri;
			addedge(li,ri);
			vis[li]=1;
		}
		rep(i,0,maxn){
			if(vis[i])	sort(v[i].begin(),v[i].end()); 
		} 
		rep(i,0,q){
			cin>>pi>>qi;
			int cnt=0;
			for(int i=pi;i<=qi;i++){
				int plen=qi-i;
//				cout<<"plen="<<plen<<endl;
				cnt+=checkedge(i,plen);
			}
			cout<<cnt<<endl;
		}
	} 
} 


Measured memory_bytes: 2176
#include "bits/stdc++.h"
using namespace std;

string order;
priority_queue<int> Q;
int num;

int main() {
	while (order != "end") {
		cin >> order;
		if (order == "insert") {
			cin >>num;
			Q.push(num);
		}
		else if (order == "extract") {
			int cur = Q.top();
			Q.pop();
			cout << cur << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 7056
h, w = gets.chomp.split(" ").map(&:to_i)
s = []
flag = Array.new(h).map{Array.new(w, false)}

h.times do
    s << gets.chomp.split("")
end

s.each_with_index do |line, i|
    isContinuous = false
    line.each_with_index do |color, j|
        if color == "." then
            flag[i][j] = true
            isContinuous = false
        else
            if isContinuous then
                flag[i][j-1] = true
                flag[i][j] = true
            end
            isContinuous = true
        end
    end
end

s = s.transpose
flag = flag.transpose

s.each_with_index do |line, i|
    isContinuous = false
    line.each_with_index do |color, j|
        if color == "." then
            flag[i][j] = true
            isContinuous = false
        else
            if isContinuous then
                flag[i][j-1] = true
                flag[i][j] = true
            end
            isContinuous = true
        end
    end
end

ans = true

flag.each do |line|
    if line.include?(false) then
        ans = false
        break
    end
end

puts ans ? "Yes" : "No"

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

tuple<int, int, int> gather_counts(const vector<int> &xs) {
    vector<int> ans(4, 0);
    for (const auto x : xs) ++ans[x];
    return {ans[1], ans[2], ans[3]};
}

double expected_operations_count(const vector<int> &xs) {
    const int n = xs.size();

    vector<vector<vector<double>>> memo(
        n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1, -1)));
    memo[0][0][0] = 0.0;

    function<double(int, int, int)> recur;

    recur = [&recur, &memo, n](const int i, const int j, const int k) {
        if (i < 0 || j < 0 || k < 0) return 0.0;

        if (memo[i][j][k] < 0) {
            memo[i][j][k] =
                (n + i * recur(i - 1, j, k) + j * recur(i + 1, j - 1, k) +
                 k * recur(i, j + 1, k - 1)) /
                (i + j + k);
        }

        return memo[i][j][k];
    };

    const auto [ones, twos, threes] = gather_counts(xs);
    return recur(ones, twos, threes);
}

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

    int sz = 0;
    cin >> sz;
    vector<int> xs(sz, 0);
    for (auto &x : xs) cin >> x;

    cout.precision(17);
    cout << expected_operations_count(xs) << '\n';

    return 0;
}


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

using namespace std;

const int SIZE = 1e5 + 10;

long long n[SIZE] = {0};

void init()
{
    for (long long i = 0; i < SIZE; i++)
        n[i] = i * i;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long k;
    init();
    cin >> k;
    for (long long i = 0; i < SIZE; i++)
    {
        if (k == n[i])
        {
            cout << k << endl;
            break;
        }
        else if (k > n[i] && k < n[i + 1])
        {
            cout << n[i] << endl;
            break;
        }
    }
    return 0;
}

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

const int N = 100000;

char buf[N + 1];

int main()
{
#ifdef LOCAL_JUDGE
    freopen("B.in", "r", stdin);
#endif
    while (scanf("%s", buf) == 1) {
        int cnt[] = {0, 0, 0};
        for (int i = 0; buf[i]; ++ i) {
            cnt[buf[i] - 'a'] ++;
        }
        std::sort(cnt, cnt + 3);
        bool ok = false;
        ok |= cnt[0] == cnt[1] && cnt[0] == cnt[2];
        ok |= cnt[0] == cnt[1] && cnt[0] + 1 == cnt[2];
        ok |= cnt[0] + 1 == cnt[1] && cnt[0] + 1 == cnt[2];
        puts(ok ? "YES" : "NO");
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
long long n, a[10000], b[10000], c[10000], cnt;
int main() {
	long long H, W, K; cin >> H >> W >> K >> n; cnt = 2LL * (H*W + W*K + K*H);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i]; long long c1 = 0;
		if (a[i] == 0)c1++; if (a[i] == H - 1)c1++;
		if (b[i] == 0)c1++; if (b[i] == W - 1)c1++;
		if (c[i] == 0)c1++; if (c[i] == K - 1)c1++;
		cnt += (3 - c1) * 2;
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int S = abs(a[i] - a[j]) + abs(b[i] - b[j]) + abs(c[i] - c[j]);
			if (S == 1)cnt -= 2;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3156
S = input()
if S[0] != 'A':
    print('WA')
    exit()
elif S[2:-1:].count('C') != 1:
    print('WA')
    exit()
S2 = S.replace('A','',1).replace('C','',1)
if S2.islower():
    print('AC')
else:
    print('WA')

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

using namespace std;
typedef long long ll;

#define out(ans) cout << ans << endl
#define in(n) cin >> n
#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define floopi(i, j, N) for (ll j = i + 1; j < N; j++)

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;
}

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

void solve();

int main()
{
    solve();
}

void solve()
{
    int n;
    in(n);
    int x[n], y[n];
    floop(i, n)
    {
        in(x[i]);
        in(y[i];)
    }
    long double sum = 0;
    floop(i, n)
    {
        floop(j, n)
        {
            long double xd = x[i] - x[j];
            long double yd = y[i] - y[j];
            sum += sqrt(xd * xd + yd * yd);
        }
    }
    long double ans = sum / n;
    cout << fixed << setprecision(10) << ans << endl;
}

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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

int f(int n) {
	int s = 0;
	while (n) {
		s += n % 10;
		n /= 10;
	}
	return s;
}

int main() {
	int n = nxt();
	int ans = 1e9;
	for (int a = 1; a <= n - a; ++a) {
		ans = min(ans, f(a) + f(n - a));
	}
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int a[n+1]={0};
  for (int i=0;i<=n;i++)  a[i]=0;
  while (k--)
  {
    int d;
    cin>>d;
    while (d--)
    {
      int tem;
      cin>>tem;
      a[tem]++;
    }
  }
  int count=0;
  for (int i=1;i<=n;i++)
    if (a[i]==0)
      count++;
  cout<<count;
}

Measured memory_bytes: 3540
p = [(-1, 2, 4, 1, 3, -1), (3, -1, 0, 5, -1, 2), (1, 5, -1, -1, 0, 4),
(4, 0, -1, -1, 5, 1), (2, -1, 5, 0, -1, 3), (-1, 3, 1, 4, 2, -1)]

def is_equal(d, a):
  ts = [i for i, x in enumerate(d) if x == a[0]]
  fs = [i for i, x in enumerate(d) if x == a[1]]
  b = 0
  for t in ts:
    for f in fs:
      if t == f: continue
      r = p[t][f]
      if r == -1: continue
      l = [d[t], d[f], d[r], d[5-r], d[5-f], d[5-t]]
      if a == l: b += 1; break
  return 1 if b > 0 else 0

l = []
b = 0
for _ in range(int(input())):
  l += [input().split()]
for i in range(0, len(l)):
  for j in range(i+1, len(l)):
    b += is_equal(l[i], l[j])
    if b > 0: break
print("No") if b > 0 else print("Yes")


Measured memory_bytes: 5616
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int count = 0;
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i) != t.charAt(i)) {
				count++;
			}
		}
		System.out.println(count);
		sc.close();
	}
}

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



int main(){
	int N,M;
	cin >> N >> M;
	
	if (M == 0){
		cout << 0 << " " << 0 << endl;
		return 0;
	}
	int ac = 0;
	int wa = 0;
	vector<pair<int,string>> v(M);
	
	rep(i,M){
		int x;
		string s;
		cin >> x >> s;
		v[i] = make_pair(x,s);
	}
	
	vector<bool> flag(N);
	rep(i,N){
		flag[i] = false;
	}
	//何回目でACしたかを表す配列を持っておく。
	vector<int> count(N);
	rep(i,N){
		count[i] = 0;
	}
	
	//pairのFirstを基準にソートする。
	rep(i,M){
		if(flag[v[i].first]) continue;
		if(v[i].second == "AC"){
			flag[v[i].first] = true;
			count[v[i].first] = i;
			ac++;
		}
	}
	
	//acを出してかつ、acを出す前だったらwaをインクリメント
	rep(i,M){
		if(flag[v[i].first] == true && i < count[v[i].first]){
			wa++;
		}else{
			continue;
		}
	}
	
	cout << ac << " " << wa << endl;
	
}



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

const int N = 26;

int cnt[N];
char s[N + 10];

int main(){
	scanf("%s", s);
	int len = strlen(s);
	for (int i = 0; i < len; ++ i){
		++ cnt[s[i] - 'a'];
	}
	for (int i = 0; i < N; ++ i){
		if (cnt[i] >= 2){
			return printf("no\n"), 0;
		}
	}
	return printf("yes\n"), 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    using ull = unsigned ll;

    set<ull> hs;

    vector<string> s;
    int n;
    cin >> n;
    s.resize(n);
    vector<vector<int>> cnt(n, vector<int>(26));
    rep(i, n) {
        cin >> s[i];
        reverse(ALL(s[i]));
        ull a = 0;
        for(auto &&c : s[i]) {
            a *= mod;
            a += c;
            cnt[i][c - 'a']++;
        }
        hs.insert(a);
    }

    ll ans = 0;
    rep(i, n) {
        ull a = 0;
        rep(j, s[i].size()) {
            rep(c, 26) if(cnt[i][c]) ans += hs.count(a * mod + c + 'a');
            a *= mod;
            a += s[i][j];
            cnt[i][s[i][j] - 'a']--;
        }
    }

    cout << ans - n << endl;

    return 0;
}

Measured memory_bytes: 45380
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int X = sc.nextInt();
		int a[] = new int[N];
		for(int i = 0;i < N;i++) {
			a[i] = sc.nextInt();
			if(D - 1/a[i] == 0) {
				a[i] = 1;
			}else {
				a[i] = (D - 1)/a[i];
			}
		}
		for(int i = 0;i < N;i++) {
			X = X + a[i];
		}
		System.out.println(X + N);
		sc.close();
	}
}

Measured memory_bytes: 21076
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int A, B, C;
    std::cin >> A >> B >> C;

    if (A <= B) {
        if (B <= C) {
            std::cout << 10*C + B + A << std::endl;
        } else {
            std::cout << 10*B + C + A << std::endl;
        }
    } else {
        if (A <= C) {
            std::cout << 10*C + B + A << std::endl;
        } else {
            std::cout << 10*A + C + B << std::endl;
        }
    }
    return 0;
}

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

int	selection_sort(vector<int> &A, int n)
{
	int		sw;
	bool	flag;

	flag = true;
	sw = 0;
	for (int i = 0; flag; i++)
	{
		int	j;

		j = n - 1;
		flag = false;
		while (j > i)
		{
			if (A.at(j) < A.at(j - 1))
			{
				swap(A.at(j), A.at(j - 1));
				flag = true;
				sw++;
			}
			j--;
		}
	}
	return (sw);
}

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

	vector<int>	A(n);
	rep(i, n)
		cin >> A.at(i);

	int	sw;

	sw = selection_sort(A, n);
	rep(i, n)
	{
		if (i)
			cout << ' ';
		cout << A.at(i);
	}
	cout << endl;
	cout << sw << endl;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define mp make_pair
#define sqr(x) (x)*(x)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=100007;
const ll inf=0x3f3f3f3f;
const int mod=998244353;
#define rep(i,x,y) for(auto i=(x);i<=(y);++i)
#define dep(i,x,y) for(auto i=(x);i>=(y);--i)
int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
ll s(ll x){return x*x*x*x*x;}
map<ll,int> aa;
int main(){
    ll n;cin>>n;
    for(ll i=0;s(i)<=1e18;i++) aa[s(i)]=i;
    for(ll i=0;-s(i)<=1e18;i--) aa[s(i)]=i;
    for(ll i=0;s(i)<=1e18;i++){
        if(aa[n+s(i)]){
            cout<<aa[n+s(i)]<<" "<<i;return 0;
        }
    }
    for(ll i=0;-s(i)<=1e18;i--){
        if(aa[n+s(i)]){
            cout<<aa[n+s(i)]<<" "<<i;return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 4424