akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

//B
public class Main {


	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N=sc.nextInt();
		int[]d=new int[N];
		for(int i=0;i<N;i++) {
			d[i]=sc.nextInt();
		}
		Arrays.sort(d);
//		for(int i=0;i<N;i++)
//		System.out.println(d[i]);System.out.println();
		int a=d[N/2-1];
		int b=d[N/2];
//		System.out.println("a,b\t"+a+" "+b);
		System.out.println(Math.abs(a-b));
	}

}


Measured memory_bytes: 50864
S = input()
ch = ["dream", "dreamer", "erase", "eraser"]
while S:
  N = len(S)
  if S[N-5:N] == ch[0] or S[N-5:N] == ch[2]:
    S = S[:N-5]
  elif S[N-6:N] == ch[3]:
    S = S[:N-6]
  elif S[N-7:N] == ch[1]:
    S = S[:N-7]
  else:
    print("NO")
    exit()
print("YES")

Measured memory_bytes: 3188
#include<iostream>
#include<fstream>
#include<complex>

#define fin cin

using namespace std;

int r, n;
int building[41];

void init() {
	for (int i = 20 - r; i < 20 + r; i++) {
		building[i] = 0;
	}
}

double toSec(int x, int y) {
	return (double)(r + y) - sqrt(pow(r, 2) - pow(x, 2));
}

int main() {
	//ifstream fin("in.txt");

	while (true) {
		r = n = 0;

		fin >> r >> n;
		if (r == 0 && n == 0)break;

		init();

		for (int i = 0; i < n; i++) {
			int left, right, h;
			fin >> left >> right >> h;

			for (int j = left + 20; j < right + 20; j++) {

				if (building[j] < h)building[j] = h;
				
			}

		}


		for (int i = 20 - r; i < 20 + r; i++) {
		//	cout << building[i] << " ";
		}

		double min = 30.0;
		int x, y;
		for (int i = 20 - r; i < 20 + r; i++) {
			double tmp = (i < 20 ? toSec(i - 19, building[i]) : toSec(i - 20, building[i]));
			if (tmp < min) {
				min = tmp;
				x = i;
				y = building[i];
			}
		}

		cout << min << endl;// << " :: " << x << ":" << y << endl;

	}

	return 0;

}

Measured memory_bytes: 1240
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    
    ll n,r;
    cin >> n >> r;
    if(n >= 10){
        cout << r << endl;
    }else{
        cout << r + 100 * (10-n) << endl;
    }
}

Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        s: Chars,
        t: Chars,
    }
    let mut result = INF;
    for i in 0..=s.len() - t.len() {
        let mut count = 0;
        for j in 0..t.len() {
            if s[i + j] != t[j] {
                count += 1;
            }
        }
        result = min(result, count);
    }
    println!("{}", result);
}


Measured memory_bytes: 2112
//04
#include<iostream>
#include<map>

using namespace std;

int main(){
  for(int w,q;cin>>w>>q,w|q;){
    bool o[100]={};
    int c[100]={};
    while(q--){
      char ws;
      cin>>ws;
      if(ws=='s'){
	int id,h;
	cin>>id>>h;
	int i;
	for(i=0;i<w-h+1;i++){
	  if(!o[i]){
	    int j;
	    for(j=0;j<h;j++){
	      if(o[i+j])break;
	    }
	    if(j==h)break;
	  }
	}
	if(i<w-h+1){
	  for(int j=0;j<h;j++){
	    o[i+j]=true;
	    c[i+j]=id;
	  }
	  cout<<i<<endl;
	}else{
	  cout<<"impossible"<<endl;
	}
      }else{
	int id;
	cin>>id;
	for(int i=0;i<w;i++){
	  if(c[i]==id){
	    o[i]=false;
	  }
	}
      }
    }
    cout<<"END"<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

char a[1001][1001];
pair<int,int> src,dest;
int n,m,i,j,vis[1001][1001],steps;
vector<pair<int,int>> back_up;
int x[4]={1,-1,0,0};
int y[4]={0,0,1,-1};

bool isValid(int x,int y)
{
	if(x<0 || y<0 || x>=n || y>=m)
		return false;
	if(vis[x][y]==1 || a[x][y]=='#')
		return false;
	return true;	
}

int zeroOneBFS()
{
	queue<pair<int,int>> q;	
	q.push(src);
	vis[src.first][src.second]=1;
	while(!q.empty())
	{
		while(!q.empty())
		{
			pair<int,int> cur=q.front();
			q.pop();
			back_up.pb(cur);
			for(i=0;i<4;i++)
			{
				if(isValid(cur.first+x[i],cur.second+y[i]))
				{
					q.push({cur.first+x[i],cur.second+y[i]});
					vis[cur.first+x[i]][cur.second+y[i]]=1;
					if(cur.first+x[i]==dest.first && cur.second+y[i]==dest.second)
						return steps;	
				}
			}
		}
		for(auto p : back_up)
		{
			for(i=-2;i<=2;i++)
			{
				for(j=-2;j<=2;j++)
				{
					if(isValid(p.first+i,p.second+j))
					{
						q.push({p.first+i,p.second+j});
						vis[p.first+i][p.second+j]=1;
						if(p.first+i==dest.first && p.second+j==dest.second)
							return ++steps;
					}
				}
			}
		}
		steps++;
		back_up.clear();
	}
	return -1;
}

int main()
{
	fastio;
	int x1,y1;
	cin>>n>>m;
	cin>>x1>>y1;
	src={x1-1,y1-1};	
	cin>>x1>>y1;
	dest={x1-1,y1-1};
	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			cin>>a[i][j];
	cout<<zeroOneBFS();
	return 0;
}


Measured memory_bytes: 8608
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  char s[20];
  int max=0,l,i,a=0;
  scanf("%s",s);
  for(l=0;s[l];l++);
  for(i=0;i<l;i++){
    max=MAX(max,a+(s[i]-'0'-1)+(l-i-1)*9);
    a+=s[i]-'0';
  }
  printf("%d\n",MAX(max,a));
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s; cin >> s;
  string ans = "Yes";
  for(int i = 0; i < s.length(); i++){
    if(i%2 == 0 && s[i] == 'L') ans = "No";
    else if(i%2 == 1 && s[i] == 'R') ans = "No";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int ans=0;
    int maki;
    int index=0;
    cin>>n;
    for(int i=n;i>=1;i--){
        maki=i;
        while(maki){
            maki/=10;
            index++;
        }
        if(index%2){
            ans++;
        }
        index=0;
    }
    cout << ans<<endl;
    return 0;
}



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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

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

int main(){
    int n;
    cin >> n;
    cout << 180*(n-2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
#define lld long double
#define F first
#define S second
#define f(i,a,b) for(int i=a;i<=b;i++)
#define g(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mh make_heap
#define ph push_heap
#define pq priority_queue
#define bits(x) __builtin_popcountll(x)
#define op(x) cout<<"Case #"<<x<<": "
#define op1(x) cout<<"Scenario #"<<x<<": "
#define endl "\n"
using namespace std;
const ll mod = 1000000007;
const ll INF = LLONG_MAX;
const int N = 18;


void solve(int t)
{
	ll n;
	cin >> n;
	ll a[n];

	for (int i = 0; i < n; i++) cin >> a[i];

	ll ans = 0;

	ll sum = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		ans = (ans % mod + (a[i] * sum) % mod) % mod;
		sum = (sum + a[i]) % mod;
	}

	cout << ans % mod << endl;



}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);




	int t = 1;
	//cin >> t;



	for (int i = 1; i <= t; i++)
	{
		solve(i);

	}
}

Measured memory_bytes: 5200
N = int(input())
A = [int(i) for i in input().split()] 

list.sort(A, reverse=True)

if A[-1] == 0:
  print(0)
  exit()

mul = 1
for a in A:
  mul *= a
  if mul > 10 ** 18:
    print(-1)
    exit()

print(mul)
  

Measured memory_bytes: 21648
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;

int gcd_euclid(int u, int v) {
	int r;
	while (0 != v) {
		r = u % v; u = v; v = r; /* swap */
	}
	return u;
}

int main()
{
	long n, s,ans,x_max,temp;
	vector<long> x(1);
	x[0] = 0;

	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		cin >> temp;
		x.push_back(abs(temp-s));
	}

	sort(x.begin(), x.end());
	x_max = x[n];
	
	//debug
	//cout << "x_max : " << x_max << endl;
	//for (int i = 1; i < n+1;i++) {
	//	cout << x[i] << ", ";
	//}
	//cout << endl;


	//x内の最大公約数を求める
	if (x.size() == 2) {
		cout << x[1] << endl;
		return 0;
	}

	ans = x[1];
	for (int i = 2; i < x.size(); i++) {
			ans = gcd_euclid(ans,x[i]);
	}


	//for (int i = 1; i <= x_max; i++) {
	//	//cout << "d:" << d << endl;
	//	for (int j = 1; j <= n; j++) {
	//		if (x[j] % i == 0) {
	//			//cout << "OK : "<< j << endl;
	//		}
	//		else {
	//			//cout << "NG : " << j << endl;
	//			break;
	//		}
	//		if (j == n) {
	//			ans = i;
	//		}
	//	}
	//}

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

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

int main(){
  int n;
  cin >> n;
  
  long long Max_Diff = -1000000000;
  long long Min_Num;
  cin >> Min_Num;
  for(int i = 1; i < n; i++){
    long long X;
    cin >> X;
    Max_Diff = max(X - Min_Num, Max_Diff);
    Min_Num = min(X, Min_Num);
  }
  cout << Max_Diff << endl;
}



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

struct{
	char s[10];
	int d[6];
} map[6]={
{"North",{1,5,2,0,4,3}},
{"East" ,{2,1,5,3,0,4}},
{"West" ,{4,1,0,3,5,2}},
{"South",{3,0,2,5,4,1}},
{"Right",{0,2,3,4,1,5}},
{"Left" ,{0,4,1,2,3,5}}
};

int main(){
	int n;
	for(;cin>>n,n;){
		string s;
		int i,j,dice[6]={1,5,3,2,4,6},t[6],sum=1;
		for(;n--;){
			cin>>s;
			for(i=0;i<6;i++)t[i]=dice[i];
			for(i=0;i<6;i++)
				if(s==map[i].s)
					for(j=0;j<6;j++) dice[map[i].d[j]]=t[j];
			sum+=dice[0];
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 0
N = int(input())
A = []
B = []

for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N%2 == 1:
    print(B[N//2]-A[N//2]+1)
else:
    x = A[N//2-1]+A[N//2]
    y = B[N//2-1]+B[N//2]
    print(y-x+1)


Measured memory_bytes: 104500
h, w = gets.split.map(&:to_i)
c = []
10.times do
  c << gets.split.map(&:to_i)
end
a = []
h.times do
  a << gets.split.map(&:to_i)
end

g = Hash.new{|hash, key| hash[key] = []}
0.upto(9) do |i|
  0.upto(9) do |j|
    g[i] << [j, c[i][j]] 
  end
end

p = Array.new(10, 0)
0.upto(9) do |i|
  p[i] = c[i][1]
end

dfs = -> (seen, s, v, w) {
  if v == 1
    p[s] = w if w < p[s]
    return
  end
  t = seen + [v]
  g[v].each do |j|
    next if t.include?(j[0])
    next if w + j[1] > p[s]
    dfs.call(t, s, j[0], w + j[1])
  end
}

0.upto(9) do |i|
  next if i == 1
  dfs.call([], i, i, 0)
end

ans = 0
a.each do |ai|
  ai.each do |a|
    ans += p[a] if a != -1 && a != 1
  end
end
puts ans



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

using namespace std;

#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pii pair<int, int>
#define vii vector<pii>
#define vs vector<string>
#define vb vector<bool>
#define vi vector<int>
#define vd vector<double>
#define vvi vector< vector<int> >
#define vvii vector< vector< pii > >
#define ld long double
#define mapii map<int, int>
#define mapsi map<string, int>
#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define INF  LLONG_MAX
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define pie  acos(-1)
#define mod(n,m) ((n % m + m) % m)
#define eps (1e-8)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'
#define output freopen("output.txt", "w", stdout)
#define mp(x, y, z) {x, {y, z}}

using namespace std;

int main() {
	int n;
	cin >> n;
	vll vec(n);
	
	ll mn = INT_MAX, mx = INT_MIN;
	rep(i, 0, n)
	{
		cin >> vec[i];
		mn = min(mn, vec[i]);
		mx = max(mx, vec[i]);
	}
	vii temp;
	if (abs(mn) > abs(mx))
	{
		int idx = -1;
		rep(i, 0, n)
			if (vec[i] == mn)
				idx = i;
		rep(i, 0, idx)
		{
			vec[i] += mn;
			temp.push_back({idx, i});
		}
		rep(i, idx + 1, n)
		{
			vec[i] += mn;
			temp.push_back({idx, i});
		}
		vec[idx] += mn;
		temp.push_back({idx, idx});
		
		for(int i = n-2; i>=0; i--)
		{
			vec[i] += vec[i+1];
			temp.push_back({i+1, i});
		}
		
	}
	else
	{
		int idx = -1;
		rep(i, 0, n)
			if (vec[i] == mx)
				idx = i;
		
		rep(i, 0, idx)
		{
			vec[i] += mx;
			temp.push_back({idx, i});
		}
		rep(i, idx + 1, n)
		{
			vec[i] += mx;
			temp.push_back({idx, i});
		}
		vec[idx] += mx;
		temp.push_back({idx, idx});
		rep(i, 1, n)
		{
			vec[i] += vec[i-1];
			temp.push_back({i-1, i});
		}
	}
	
	cout << sz(temp) << endl;
	for(auto i : temp)
		cout << i.first + 1 << " " << i.second + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
fn main() {
    let n = read::<usize>();
    let v = read_vec2::<u32>(n);
    let mut dp: Vec<Vec<u32>> = Vec::new();
    for _ in 0..n {
        let tmp = vec![0; 3];
        dp.push(tmp);
    }

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

    for i in 1..n {
        for j in 0..3 {
            let mut max = 0;
            if j == 0 {
                max = std::cmp::max(dp[i-1][1], dp[i-1][2]);
            } else if j == 1 {
                max = std::cmp::max(dp[i-1][0], dp[i-1][2]);
            } else {
                max = std::cmp::max(dp[i-1][0], dp[i-1][1]);
            }
            dp[i][j] = max + v[i][j];
        }
    }

    let mut ret = 0;
    if dp[n-1][0] < dp[n-1][1] {
        if dp[n-1][1] < dp[n-1][2] {
            ret = dp[n-1][2];
        } else {
            ret = dp[n-1][1];
        }
    } else {
        if dp[n-1][0] < dp[n-1][2] {
            ret = dp[n-1][2];
        } else {
            ret = dp[n-1][0];
        }
    }
    println!("{}", ret);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    let mut v2 = Vec::new();
    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let v = s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
        v2.push(v);
    }
    v2
}


Measured memory_bytes: 16632
#include <stdio.h>
#include <string.h>


int main(void) {
	int  t,h,hh, m, s;
	scanf("%d", &t);

	h = t / 3600;
	hh = h * 3600;
	s = t % 60;
	m = (t - hh - s)/60;
	printf("%d:%d:%d\n", h, m, s);

	
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
char a[100][101], b[102][102];
int main(){
    int H, W;
    cin >> H >> W;
    for (int i = 0; i < H; i++){
        cin >> a[i];
    }
    for (int i = 0; i < H + 2; i++){
        for (int j = 0; j < W + 2; j++){
            b[i][j] = '#';
        }
    }
    for (int i = 0; i < H; i++){
        for (int j = 0; j < W; j++){
            b[i+1][j+1]=a[i][j];
        }
    }
    for(int i=0; i<H+2; i++){
        for(int j=0; j<W+2;j++){
            cout << b[i][j];
        }
        cout << endl;
    }

}




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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	// debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, left, right)  (a).begin()+(left),(a).begin()+(right)	// left to (right-1)

int main() {
	int n;
	cin >> n;
	string c;
	cin >> c;
	int lpos = 0, rpos = n - 1, res = 0;
	while (1) {
		while (c[lpos] == 'R') {
			lpos++;
			if (lpos >= rpos) goto owari;
		}
		while (c[rpos] == 'W') {
			rpos--;
			if (lpos >= rpos) goto owari;
		}
		res++;
		lpos++;
		rpos--;
		if (lpos >= rpos) goto owari;
	}
owari:
	pv(res);
	return 0;
}

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

long nCr(int n,int r){
  int h = r,w = n-r,inf = 1000000007;
  long dp[h+1][w+1];
  dp[0][0] = 1;
  //cout << dp[0][2] << endl;
  for(int i = 1;i <= h;i++){
    dp[i][0] = 1;
  }
  for(int i = 1;i <= w;i++){
    dp[0][i] = 1;
  }
  for(int i = 1;i <= h;i++){
    for(int j = 1;j <= w;j++){
      dp[i][j] = dp[i][j-1] + dp[i-1][j];
      //cout << dp[i][j] << " " << i << " " << j << endl;
    }
  }
  return dp[h][w];
}


int main(){
  long n,a,b;
  bool equal = true;
  cin >> n >> a >> b;
  double v[n];
  for(int i = 0;i < n;i++){
    cin >> v[i];
  }
  sort(v,v+n);
  double ave = 0;
  for(int i = n-1;i >= n-a;i--){
    ave += v[i];
    if(i != 0 && v[i] != v[i-1]){
      equal = false;
    }
  }
  ave /= a;
  long c = 0,d = 0;
  for(int i = 0;i < n;i++){
    if(v[i] == v[n-a]){
      c++;
    }
    else if(v[i] > v[n-a]){
      d++;
    }
  }
  long num = 0;
  if(equal == true){
    for(int i = a;i <= min(c,b);i++){
      num += nCr(c,i);
    }
  }
  else{
    num = nCr(c,a-d);
    //cout << num << endl;
  }
  printf("%lf\n", ave);
  cout << num << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def bubble_sort(seq, l):
    cnt = 0

    for max_size in range(l, 0, -1):
        for left in range(1, max_size):
            if seq[left-1] > seq[left]:
                seq[left-1], seq[left] = seq[left], seq[left-1]
                cnt += 1

    print(' '.join([str(i) for i in seq]))
    print(cnt)


def to_int(v):
    return int(v)


def to_seq(v):
    return [int(c) for c in v.split()]


if __name__ == '__main__':
    l = to_int(input())
    seq = to_seq(input())

    bubble_sort(seq, l)

Measured memory_bytes: 7756
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M, R; cin >> N >> M >> R;
	vector<int> r(R); rep(i, 0, R) { cin >> r[i]; r[i]--; }
	vector<vector<int>>g(N, vector<int>(N, INF));
	rep(i, 0, N)g[i][i] = 0;
	rep(i, 0, M) {
		int a, b, c; cin >> a >> b >> c;
		a--, b--;
		g[a][b] = c;
		g[b][a] = c;

	}
	rep(k, 0, N) {
		rep(i, 0, N) {
			if (g[i][k] == INF)continue;
			rep(j, 0, N) {
				if (g[k][j] == INF)continue;
				g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
			}
		}
	}
	int ans(INF);
	vector<int>p(min(8ll, R));
	rep(i, 0, p.size()) {
		p[i] = i;
	}
	dump(g, p);
	do {
		int cur = r[p[0]];
		int tmp(0);
		rep(i, 1, p.size()) {
			tmp += g[cur][r[p[i]]];
			cur = r[p[i]];
		}
		chmin(ans, tmp);
	} while (next_permutation(all(p)));

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

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
    int A, B, C1, C2, C3, check1, check2, check3, flg;
    //cout << "A, Bを入力してください" << endl;
    cin >> A >> B;

    C1 = 1;
    C2 = 2;
    C3 = 3;

    check1 = A * B * C1;
    check2 = A * B * C2;
    check3 = A * B * C3;

    if (check1 % 2 != 0){
        flg = 1;
    }else{
        flg = 0;
    }
    if (check2 % 2 != 0){
        flg = 1;
    }else{
        flg = 0;
    }
    if (check3 % 2 != 0){
        flg = 1;
    }else{
        flg = 0;
    }
    if (flg == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int,int> tiiii;
const ll mod=1e9+7;
const int inf=1<<30;

int n,m,q;
ll ans;
tiiii putt[51];
void dfs(vector<int> x,int last){
  if(x.size()==n){
    ll sum=0;
    rep(i,q){
      int a,b,c,d;
      tie(a,b,c,d)=putt[i];
      if(x[b]-x[a]==c) sum+=d;
    }
    chmax(ans,sum);
    return;
  }
  else{
    for(int i=last;i<=m;i++){
      x.push_back(i);
      dfs(x,i);
      x.pop_back();
    }
    return;
  }
}

int main(){
  ans=0;
  cin >> n >> m >> q;
  rep(i,q){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    a--; b--;
    putt[i]=tiiii(a,b,c,d);
  }
  vector<int> x(0);
  dfs(x,1);
  cout << ans << endl;
}

Measured memory_bytes: 3644
#!/usr/bin/env python3
import sys

def solve(H: int, W: int, a: "List[List[int]]"):
    answer = []
    for y in range(H):
        if y%2 == 0:
            for x in range(W):
                if a[y][x]%2 ==1:
                    if x+1 < W:
                        a[y][x+1] += 1
                        answer.append((y+1,x+1,y+1,x+2))
                    elif y+1 < H:
                        a[y+1][x] += 1
                        answer.append((y+1,x+1,y+2,x+1))                       
        else:
            for x in range(W-1,-1,-1):
                if a[y][x]%2 ==1:
                    if x-1 >= 0:
                        a[y][x-1] += 1
                        answer.append((y+1,x+1,y+1,x))
                    elif y+1 < H:
                        a[y+1][x] += 1
                        answer.append((y+1,x+1,y+2,x+1))                       
 
    
    print(len(answer))
    for aa in answer:
        print(" ".join(map(str,aa)))


    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    a = [[int(next(tokens)) for _ in range(W)] for _ in range(H)]  # type: "List[List[int]]"
    solve(H, W, a)

if __name__ == '__main__':
    main()


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

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int n;
V<int> a;

int main(){
    INIT;
    cin >> n;
    REP(i,n) {
        int x; cin >> x; a.push_back(x);
    }
    std::sort(ALL(a), DESC(int));

    int alice = 0;
    int bob = 0;
    REP(i,n) {
        if(i % 2 == 0) alice += a[i];
        else bob += a[i];
    }
    cout << alice - bob << "\n";
}

Measured memory_bytes: 256
n, k = map(int, input().split())

mod = 10 ** 9 + 7
ans = 0
begin = 0
end = 0
a = 0
b = n
for i in range(k):
    begin += a
    end += b
    a += 1
    b -= 1

ans += end - begin + 1

for i in range(k + 1, n + 2):
    begin += a
    end += b
    a += 1
    b -= 1
    ans += end - begin + 1

if k == n + 1:
    ans = 1
    
print(ans % mod)

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

int main(){
	int t;
	scanf("%d",&t);
	int fg=0;
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(i * j == t){
				cout << "Yes" << endl;
				fg=1;
				break;
			}
		}
		if(fg)
			break;
	}
	if(fg==0)
		cout << "No" << endl;
	return 0;
} 

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sN = System.Console.ReadLine().Trim();
            string sA = System.Console.ReadLine().Trim();
            string sB = System.Console.ReadLine().Trim();
            string sC = System.Console.ReadLine().Trim();
            int iN = int.Parse(sN);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = 0;
            for (int i = 0; i < iN; i++)
            {
                string sA1 = sA.Substring(i, 1);
                string sB1 = sB.Substring(i, 1);
                string sC1 = sC.Substring(i, 1);
                if      (sA1 == sB1 && sB1 == sC1)               { iOut += 0; }     // 3つ共同じ
                else if (sA1 == sB1 || sB1 == sC1 || sA1 == sC1) { iOut += 1; }     // どれか2つ同じ
                else                                             { iOut += 2; }     // どれも違う
            }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13268
#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 ctoi(const char c){
  int n = -1;
  sscanf(&c, "%1d", &n);
  return n;
}

int main() {
    string n;
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n.length(); i++)
    {
        sum += ctoi(n.at(i));
    }
    if (sum%9==0)
    {
        cout << "Yes" << endl;
    } else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3792
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>
#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222





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


  cin >> n;
  cin >> s;

  ll le = 0, ri = n / 2 + 1;
  while (ri - le > 1) {
    ll mid = (le + ri) / 2;
    bool ok = false;
    unordered_map<string, ll> mp;
    FOR(i, mid, n - mid + 1) {
      mp[s.substr(i, mid)]++;
    }
    rep(i, n - mid + 1) {
      if (mp[s.substr(i, mid)] > 0) ok = true;
      if (i + 2 * mid <= n) mp[s.substr(i + mid, mid)]--;
    }
    if (ok) le = mid;
    else ri = mid;
  }

  cout << le << endl;



  return 0;
}


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

int main() {
    int n, q;
    cin >> n;
    vector<int> A(n);
    for(int i = 0; i < n; i++) {
        cin >> A.at(i);
    }
    cin >> q;
    vector<int> m(q);
    for(int i = 0; i < q; i++) {
        cin >> m.at(i);
    }
    set<int> value;
    for(int bit = 0; bit < (1 << n); bit++) {
        int sum = 0;
        for(int i = 0; i < n; i++) {
            if(bit & (1 << i)) {
                sum += A[i];
            }
        }
        value.insert(sum);
    }
    for(int i = 0; i < q; i++) {
        string messages = "yes";
        int now = m[i];
        if(value.count(now) == 0) {
            messages = "no";
        }
        cout << messages << endl;
    }
    return 0;
}


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


int main() {
    int s,w;
    cin >> s >> w;
    if(s > w) cout << "safe" << endl;
    else cout << "unsafe" << endl;
    return 0;
}



Measured memory_bytes: 3636
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
int main(void){
    ll N;cin>>N;
    ll dp[N+1];dp[0]=dp[1]=1;
    FORS(i,2,N){
        dp[i]=dp[i-1]+dp[i-2];
    }
    cout<<dp[N]<<"\n";
}



Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    string X;
    cin >> X;

    int N=X.size();
    int Tnum=N/2;

    int ans=N,tct=0,sct=0,sumt=Tnum;
    for(int i=0;sumt>0;i++){
        if(X[i]=='S'){
            sct++;
            ans-=2;
            sumt--;
        }
        else{
            if(sct>0){
                sct--;
            }
            else sumt--;
        }
    }
    cout << ans << endl;
    
}

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

using namespace std;

int main(void){
  int A, B, C;
  cin >> A >> B >> C;
  if(A == B){
    if(A == C){
      cout << "No" << endl;
      return 0;
    }else{
      cout << "Yes" << endl;
      return 0;
    }
  }else{
    if(B == C){
      cout << "Yes" << endl;
      return 0;
    }else{
      if(A == C){
        cout << "Yes" << endl;
      }else{
        cout << "No" << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdlib>
#include<algorithm>
#include<climits>
#include<queue>
#include<stack>
#include<cmath>
#include<iterator>
#include<iomanip>
typedef long long ll;
using namespace std;
#define rep(x, y)   for (ll i = x; i <= y; i ++)
#define repi(x, y)  for (ll i = x; i >= y; i --)
priority_queue< ll > cancel;
long double arr[200005];
ll brr[200005];
long double dp[3005][3005];
int main()
{
    ll test=1;
    // cin>>test;
    for(ll z=0;z<test;z++)
    {
        ll n,k;
        cin>>n;
        for(ll i=1;i<=n;i++)
        {
            cin>>arr[i];
        } 

        dp[1][0]=(long double)(1-arr[1]);
        dp[1][1]=arr[1];
        for(ll i=2;i<=n;i++)
        {
            for(ll j=0;j<=i;j++)
            {
                if(j>=1)
                dp[i][j]=(long double)(dp[i-1][j-1]*arr[i])+(long double)(dp[i-1][j]*(1-arr[i]));
                else
                {
                    dp[i][j]=(long double)dp[i-1][j]*(1-arr[i]);
                }     
            }
        }
        // long double ans=0.00000000;
        for(ll i=n-1;i>=(n/2+1);i--)
        {
            dp[n][n]+=dp[n][i];
        }

        // for(ll i=1;i<=n;i++)
        // {
        //     for(ll j=0;j<=n;j++)
        //     {
        //         cout<<dp[i][j]<<" ";
        //     }
        //     cout<<endl;
        // }

        // ans=0.3456781*0.0011231;
        cout << setprecision(11) << dp[n][n] << endl;;
    }
}

Measured memory_bytes: 85632
#include<iostream>
#include<vector>
#include<string>

int main(){
    int n, q;
    std::cin >> n >> q;
    std::string S;
    std::cin >> S;
    std::vector<int> sum(n, 0);
    for(int i = 1; i < n; i++){
        if(S[i - 1] == 'A' && S[i] == 'C'){
            sum[i] = sum[i - 1] + 1;
        }else{
            sum[i] = sum[i - 1];
        }
    }

    for(int i = 0; i < q; i++){
        int l, r;
        std::cin >> l >> r;
        l--; r--;
        std::cout << sum[r] - sum[l] << std::endl;
    }
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
int main(){
  int n,i,j;
  int minv=0,maxv=0;
  scanf("%d",&n);
  int R[n];
  for(i=0;i<n;i++){
    scanf("%d",&R[i]);
  }
  minv=R[0];
  maxv=R[1]-R[0];
  for(j=1;j<n;j++){
    if(maxv<R[j]-minv)maxv=R[j]-minv;
    if(minv>R[j])minv=R[j];
  }
  printf("%d\n",maxv);
  return 0;
}

Measured memory_bytes: 1376
local n = io.read("*n")
local a = {{}}
for i = 1, n do
    local raw = io.read("*n")
    if raw % 2 == 1 then
        print(0); os.exit()
    else
        a[1][i] = raw / 2
    end
end

local count = 1
while true do
    a[count + 1] = {}
    for i = 1, n do
        if a[count][i] % 2 == 1 then
            print(count); os.exit()
        else
            a[count + 1][i] = a[count][i] / 2
        end
    end
    a[count] = nil
    count = count + 1
end

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> l(m), r(m);
  rep(i, m) {
    cin >> l[i] >> r[i];
    --l[i]; --r[i];
  }

  int left = 0, right = n - 1;

  for (int i = 0; i < m; ++i) {
    int a = l[i], b = r[i];
    if (a > left) left = a;
    if (b < right) right = b;
  }

  ll ans = 0;
  if (left > right) {
    ans = 0;
  } else {
    ans = right - left + 1;
  }

  cout << ans << endl;
}


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

int main() {

	string res;
	string s; cin >> s;
	int mylen = (int)s.length() - 2;

	res = s[0] + to_string(mylen) + s[mylen + 1];

	cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <list>
#include <string>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <iomanip> // setprecisionを使用するのに必要 cout << fixed << setprecision(15) << p でpを小数点以下15桁表示
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
/*

*/
int main()
{
    ll N;
    unsigned long long ans=1,anstemp;
    cin >> N;
    ll A[N];
    ll thresh = 1000000000000000000;
    bool overflg = 0;
    bool zeroflg = 0;
    REP(i,N){
        cin >> A[i];
    }
    sort(A,A+N);
    if(A[0] == 0){
        zeroflg = 1;
        goto END;
    }
    //ビットの最大値が幾つになるかをとって、Aとansの合計が64を超えたらover
    for(int i = N-1; i >= 0; i--){
        int abit = 0, ansbit = 0;
        unsigned long long temp = ans;
        while(temp != 0){
            temp >>= 1;
            ansbit++;
        }
        temp = A[i];
        while (temp != 0)
        {
            temp >>= 1;
            abit++;
        }
        //cout << ansbit + abit << endl;
        ans *= A[i];
        if (ansbit + abit >= 64 || ans > thresh)
        {
            overflg = 1;
            break;
        }

    }

    END:
    if(zeroflg) fin(0);
    else if(overflg) fin(-1);
    else fin(ans);
    return 0;
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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; }
int main(){
    ios::sync_with_stdio(false);
    int n,m,k;
    cin >> n >> m >> k;
    vector<vector<int>> f(n), b(n);
    rep(i,m) {
        int A,B;
        cin >> A >> B;
        A--;B--;
        f[A].push_back(B);
        f[B].push_back(A);
    }
    rep(i,k) {
        int C,D;
        cin >> C>> D;
        C--;D--;
        b[C].push_back(D);
        b[D].push_back(C);
    }
    int num = 0;
    vector<int> grp(n);
    vector<bool> seen(n,false);
    rep(i,n) {
        if(seen[i] == true) continue;
        grp[i] = num;
        stack<int> st({i});
        while(!st.empty()){
            int now = st.top();
            st.pop();
            if(seen[now] == true) continue;
            seen[now] = true;
            grp[now] = num;
            for(int next: f[now]) {
                st.emplace(next);
            }
        }
        num++;
    }

    vector<int> grp_size(grp.size(),0);
    rep(i,n) grp_size[grp[i]]++;
    rep(i,n) {
        int cand = grp_size[grp[i]] - 1 - f[i].size();
        for(int j : b[i]) {
            if(grp[j] == grp[i]) cand--; 
        }
        cout << cand;
        if(i != n-1) cout << " ";
        else cout << endl;
    }
}


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

int main(){
    int a,b,c,d;
    d=0;
    cin>>a>>b>>c;
    for(int x=a;x<=b;x++){
        if (c%x==0){
            d=d+1;
        }
    }

    cout<<d<<endl;
    
}




Measured memory_bytes: 3076
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N,Q;
    cin >> N >> Q;
    fenwick_tree<ll> fw(N);
    rep(i,N){
        ll a;
        cin >> a;
        fw.add(i,a);
    }
    rep(i,Q){
        ll t,p,x;
        cin >> t >> p >> x;
        if (t == 0){
            fw.add(p,x);
        }
        if (t == 1){
            ll ans = fw.sum(p,x);
            cout << ans << endl;
        }
    }
}

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

int main() {
  	long long N, c, d;
  	long long count = 0;
  	cin >> N;
    vector<long long> vec(N);
  	for (long long i = 0; i < N; i++) {
          cin >> vec[i];
    }
  	for (long long i = 0; i < N-1 ; i++) {
      	c = vec[i];
        d = vec[i+1];
		while (c > d) {
          	d++;
          	count++;
        }
        vec[i+1] = d;
        
    }
    cout << count << endl;
}

Measured memory_bytes: 4800
#include<cstdio>
#include<cstdlib>

int a[20];

int main()
{
	int n;
	int h=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		h+=a[i];
	}
	bool p=1;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=h-a[i])
		{
			p=0;break;
		}
	}
	if(p) printf("Yes\n");
	else printf("No\n");
	return 0;
}


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

using namespace std;

int main () {
	int n, k;
	scanf("%d%d", &n, &k);
	int a[10086];
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	int ans = 0;
	for (int i = 1; i <= k; i++)
		ans += a[i];
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 3828
from sys import stdin
N,T = [int(x) for x in stdin.readline().rstrip().split()]
data = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
for i in range(N-1):
    if data[i+1] - data[i] >= T:
        ans += T
    else:
        ans += (data[i+1]-data[i])
ans += T
print(ans)

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1,
    x=-x;
  }
  while(x){
    f[s++]=x%10,
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int a[100000], b[100000];
int main(){
  int ans=0, h, i, n;
  rd(n);
  rd(h);
  {
    int lhxun_Zi;
    for(lhxun_Zi=0;lhxun_Zi<n;lhxun_Zi++){
      rd(a[lhxun_Zi]);
      rd(b[lhxun_Zi]);
    }
  }
  sort(a, a+n);
  reverse(a, a+n);
  sort(b, b+n);
  reverse(b, b+n);
  for(i=0;i<n;i++){
    if (h > 0 && a[0] < b[i]){
      ans++;
      h -= b[i];
    }
  }
  chmax(h, 0);
  ans += (h+a[0]-1)/a[0];
  wt_L(ans);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20170910-1

// --- original code ---
// int a[100000], b[100000];
// {
//   int n, h;
//   rd(n, h, (a,b)(n));
//   sort(a, a+n); reverse(a, a+n);
//   sort(b, b+n); reverse(b, b+n);
//   int ans = 0;
//   rep(i,n) {
//     if (h > 0 && a[0] < b[i]) {
//       ans++;
//       h -= b[i];
//     }
//   }
//   h >?= 0;
//   ans += (h+a[0]-1)/a[0];
//   wt(ans);
// }

Measured memory_bytes: 1024
use std::collections::VecDeque;
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() {
    type Graph = Vec<Vec<usize>>;
    let n: usize = read();
    let m: usize = read();
    let mut G: Graph = vec![Vec::new(); n];
    for _i in 0..m {
        let a: usize = read();
        let b: usize = read();
        G[a-1].push(b-1);
        G[b-1].push(a-1);
    }

    
    let mut dist = vec![-1; n];
    let mut mark = vec![-1; n];
    let mut queue: VecDeque<usize> = VecDeque::new();
    //dist[0] = 0;
    //queue.push_back(0);

    for i in 0..n {
        if dist[i] != -1 {
            continue;
        }
        dist[i] = 0;
        queue.push_back(i);
        while !queue.is_empty() {
            let v = queue.pop_front().unwrap();
            for nv in G[v].iter() {
                if dist[*nv] == -1 {
                    dist[*nv] = dist[v] + 1;
                    queue.push_back(*nv);
                    mark[*nv] = v as i32;
                }
            }
        }
    }
    println!("Yes");
    for i in 1..mark.len(){
        println!("{}",mark[i]+1);
    }
}


Measured memory_bytes: 11812
from operator import itemgetter

n = int(input())
r = [tuple(map(int, input().split())) for i in range(n)]
b = [tuple(map(int, input().split())) for i in range(n)]

r = sorted(r, key=itemgetter(1), reverse=True)
b.sort()

pair = [False]*n

for i in range(n):
    for j in range(n):
        if b[i][0] > r[j][0] and b[i][1] > r[j][1] and pair[j] == False:
            pair[j] = True
            break

print(sum(pair))

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

int abs(int a){
if(a>753)return a-753;
else return 753-a;
}

int si(char a,char b,char c){
return (a-'0')*100+(b-'0')*10+(c-'0');
}

int main(){
int i;
int ans=1919114514;
string s;
cin>>s;
for(i=0;i<s.length()-2;i++){
if(ans>abs(si(s[i],s[i+1],s[i+2])))ans=abs(si(s[i],s[i+1],s[i+2]));
}
cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 256
package main

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

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

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

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

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

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

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

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

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

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

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

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

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

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

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

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	a, b, c := sc.nextInt(), sc.nextInt(), sc.nextInt()

	fmt.Fprintln(wtr, min(a+b, a+c, b+c))
	wtr.Flush()
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
typedef long long ll;
const int MOD = 1000000007;
using namespace std;

int main(){
    int n; cin >> n;
    cout << ((n-1)/ 111 + 1) * 111 << "\n";
    return 0;
}


Measured memory_bytes: 256