akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;

ll solve(vector<int> &wt, vector<int> &val, int w)
{
    int n = val.size();
    vector<vector<ll>> dp(w+1, vector<ll>(n+1));
    for(int i=1; i<=w; i++){
        for(int j=1; j<=n; j++){
            if(wt[j-1]>i) dp[i][j] = dp[i][j-1];
            else{
                dp[i][j] = max(val[j-1] + dp[i-wt[j-1]][j-1], dp[i][j-1]);
            }
        }
    }
    return dp[w][n];
}

void print(vector<int> &a)
{
    for(auto &x: a)
        cout << x << " ";
    cout << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n, w;
    cin >> n >> w;
    vector<int> wt(n);
    vector<int> val(n);
    for(int i=0; i<n; i++){
        cin >> wt[i];
        cin >> val[i];
    }
    cout << solve(wt, val, w) << '\n';
    return 0;
}

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

using int64 = long long;

int64 pow5(int64 x) {
  return x * x * x * x * x;
}

int main() {
  int64 x;
  cin >> x;
  for (int64 a = -200; a <= 200; ++a) {
    for (int64 b = -200; b <= 200; ++b) {
      if (pow5(a) - pow5(b) == x) {
        cout << a << " " << b << "\n";
        return 0;
      }
    }
  }
  return 0;
}


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

int main() {
    long long N, M;
    cin >> N >> M;

    if (N == 1 && M == 1) cout << 1 << endl;
    else if (N == 1) cout << M - 2 << endl;
    else if (M == 1) cout << N - 2 << endl;
    else cout << (N - 2) * (M - 2) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    System.out.println(100 + " " + 100);
    for(int i = 0; i < 100; i++) {
      String s = "";
      if(i < 50) {
        if((i % 2) == 0) {
          for(int j = 0; j < 100; j++) {
            s += ".";
          }
        } else {
          for(int j = 0; j < 100; j++) {
            if((b > 1) && ((j % 2) == 0)) {
              s += "#";
              b--;
            } else {
              s += ".";
            }
          }          
        }
      } else {
        if((i % 2) == 0) {
          for(int j = 0; j < 100; j++) {
            s += "#";
          }
        } else {
          for(int j = 0; j < 100; j++) {
            if((a > 1) && ((j % 2) == 0)) {
              s += ".";
              a--;
            } else {
              s += "#";
            }
          }           
        }
      }
      System.out.println(s);
    }
  }
}

Measured memory_bytes: 29012
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define dup(x) x.erase(unique(x.begin(), x.end()),x.end())
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;
// https://atcoder.jp/contests/abc172/tasks/abc172_c
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n,m,k;
    cin >> n >> m >> k;
    vector<ll> A(n);
    vector<ll> B(m);
    vector<ll> sA(n+1);
    vector<ll> sB(m+1);
    for(int i = 0;i<n;i++){
        cin >> A[i];
        sA[i+1] = sA[i] + A[i];
    }
    for(int i = 0;i<m;i++){
        cin >> B[i];
        sB[i+1] = sB[i] + B[i];
    }
    ll ans = 0;
    ll j = m;
    for(int i = 0;i<n+1;i++){
        ll temp = sA[i];
        ll t = k - temp;
        if(t < 0) continue;
        while(temp + sB[j] > k)
            j--;
        ans = max(ans, i+j);
    }

    cout << ans;

	return 0;
}

Measured memory_bytes: 9532
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N;

signed main(){
    cin >> N;
    for(int i=1; i<=9; i++){
        if(N%i == 0 && N/i <= 9){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

template <typename T> inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T> inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const int N = 305;

int n, m, a[N], per[N];
LL sum, cnt, f[N][35];

inline LL Solve() {
  for (int i = 0; i <= n * m; ++i) {
    for (int j = 0; j < 1 << n - 1; ++j) {
      f[i][j] = 0;
    }
  }
  f[n * a[n - 1]][0] = 1;
  for (int i = 0; i < n * m; ++i) {
    for (int j = i; j <= n * m; ++j) {
      for (int k = 0; k < 1 << n - 1; ++k) {
        if (i % n && !(k >> per[i % n - 1] & 1)) {
          f[min(n * m, max(j, i + n * a[per[i % n - 1]]))][k | 1 << per[i % n - 1]] += f[j][k];
        }
      }
    }
  }
  return f[n * m][(1 << n - 1) - 1];
}

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  Read(n), Read(m);
  for (int i = 0; i < n; ++i) {
    Read(a[i]);
  }
  sort(a, a + n);
  for (int i = 0; i < n - 1; ++i) {
    per[i] = i;
  }
  do {
    sum += Solve();
    ++cnt;
  } while (next_permutation(per, per + n - 1));
  for (int i = 0; i < n - 1; ++i) {
    cnt = cnt * m;
  }
  printf("%.12lf\n", (double)sum / cnt);
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}


Measured memory_bytes: 384
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    writeln("ABC" ~ sread());
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc =new Scanner(System.in);
		int n=sc.nextInt();
		String S=sc.next();
		int e[]=new int[n];
		char[] c=S.toCharArray();
		for(int i=1;i<n;i++) {
			if(c[i]=='E')e[0]++;
		}
		int ans=e[0];
		for(int i=1;i<n;i++) {
			e[i]=e[i-1];
			if(c[i]=='E')e[i]--;
			if(c[i-1]=='W')e[i]++;
			if(ans>e[i])ans=e[i];
		}
		System.out.println(ans);
 
	}
 
}

Measured memory_bytes: 30660
N = int(input())
XY = sorted([list(map(int,input().split())) for _ in range(N)])

PQ = []
# 2点を選びp,q仮決め
for i in range(N):
    prev = XY[i]
    for j in range(N):
        if i!=j:
            next = XY[j]
            p = next[0] - prev[0]
            q = next[1] - prev[1]
            PQ.append((p,q))

ans = 1
for pq in PQ:
    ans = max(ans, PQ.count(pq))
print(N - ans if N>1 else 1)

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<iomanip>
#include<vector>
using namespace std;
#define int long long
#define INF 1245678912346
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_VAL 0

signed main(){
	bool flag = true;
	string S, T;
	int size;
	int temp[40] = {}, tempb[40] = {};
	
	rep(i,30){
		temp[i] = 30;
		tempb[i] = 30;
	}
	
	cin>>S>>T;
	
	size = S.size();
	
	rep(i,size){
		// cout<<S[i]<<" "<<(char)(temp[S[i]-'a']+'a')<<" "<<T[i]<<endl;
		
		if(temp[T[i]-'a'] == 30){
			temp[T[i]-'a'] = S[i] - 'a';
		} else if(temp[T[i]-'a'] != S[i] - 'a'){
			flag = false;
			break;
		}
		if(tempb[S[i]-'a'] == 30){
			tempb[S[i]-'a'] = T[i] - 'a';
		} else if(tempb[S[i]-'a'] != T[i] - 'a'){
			flag = false;
			break;
		}
	}

	cout<<(flag?"Yes":"No")<<endl;
	
	return 0;
}

Measured memory_bytes: 776
const main = (txt: any): void => {
  const input = txt.split('\n')
  for (const i in input) {
    if (Number(i) > 0) {
      console.log(input[i] + '\n' + input[i])
    }
  }
}



main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7500
#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>;
#define chmin(a,b) a = min(a,b);

int dp[1005][10005];
const int INF = 1001001001;

int main() {
    int h, n;
    cin >> h >> n;
    rep(i,1005)rep(j,10005) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,n) {
        int a, b;
        cin >> a >> b;
        rep(j,h+1) {    
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][min(j+a, h)], dp[i+1][j] + b);
        }
    }
    cout << dp[n][h] << endl;
    return 0;
}

Measured memory_bytes: 42836
n = int(input())
x = int(input(),2)
# b = int(2**(n-1))
pc = 0
d = []
c = x
for i in range(n):
    d.append(c&1)
    if c&1 == 1:
        pc += 1
    c=c>>1

mp =  x%(pc+1)
if pc == 1:
    mm = -1
else:
    mm = x%(pc-1)
# print(x,pc,mp,mm)
for i in range(n):
    if d[-i-1]==0:
        m = 1
        temp = (mp+pow(2,n-i-1,pc+1)) % (pc+1)
        ans = 1
    else:
        if mm == -1:
            temp = 0
            ans = 0
        else:    
            m = -1
            temp = (mm-pow(2,n-i-1,pc-1)) % (pc-1)
            ans = 1
    # temppc = pc+m
    # temp = x^b
    # ans = 1
    # print(temp)
    # print(temp,mm,pc,pow(2,n-i,pc+1),(mm-pow(2,n-i-1,pc+1)) % (pc-1))
    while temp:
        
        c = temp
        temppc = 0
        while c:
            if c&1 == 1:
                temppc += 1
            c=c>>1
        # print(temp)
        # print(i,temp,ans,temppc)
        # print(temp)
        # s = str(bin(temp))
        # print(temp,popcount(temp))
        if temppc == 0:
            break
        temp = temp % temppc
        ans += 1
        # c = temp
        # temppc = 0
        # while c:
        #     if c&1 == 1:
        #         temppc += 1
        #     c=c>>1
        # print(temp,s)
        # break
    # b=b>>1
    print(ans)

Measured memory_bytes: 109976
n = int(input())
s = input()
red = []
green = []
blue = [False for _ in range(n)]
b = 0
for i,x in enumerate(s):
    if x == "R":
        red.append(i)
    if x == "G":
        green.append(i)
    if x == "B":
        blue[i] = True
        b += 1

ans = 0
for i in red:
    for j in green:
        p = 0
        if 0<=2*j-i<n and blue[2*j-i]:
            p += 1
        if 0<=2*i-j<n and blue[2*i-j]:
            p += 1
        if (i+j)%2 == 0 and blue[(i+j)//2]:
            p += 1
        ans += b-p
print(ans)

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

typedef long long lli;

lli gcd(lli a, lli b) { return b == 0 ? a : gcd(b, a%b);}

int main(){
  lli a,b;
  while(cin >> a >> b)
    cout << gcd(a,b) << ' ' << a * b / gcd(a,b) << endl;
}

Measured memory_bytes: 1160
N,M,C= map(int,input().split())
le = list(map(int, input().split()))
a = [0]*N


for i in range(N):
    a[i]=input().rstrip().split()



count = 0
for i in range(N):
    sum = 0
    for j in range(M):
        sum += int(a[i][j])*le[j]

    if sum+C >0:
        count += 1

print(count)

Measured memory_bytes: 3064
def resolve():
    n,q = map(int, input().split())
    s = input()
    num = [0]*n
    k = 0
    for i in range(n):
        if i > 0:
            if s[i-1] == "A" and s[i] == "C":
                k += 1
            num[i] = k
    for i in range(q):
        l,r = map(int, input().split())
        test = num[r-1]-num[l-1]
        print(test)
resolve()

Measured memory_bytes: 51160
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    vector<int> w(100);
    cin>>N;
    int ans = 0;
    rep(i,N){
        cin>>W;
        ans += W;
        w.at(i) = ans;
    } 
    ans = 100000;
    rep(i,N){
        int temp = abs(w.at(N-1) - w.at(i)*2);
        ans = min(temp,ans);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void){
  int N, K, x, i, sum=0;
  scanf("%d",&N);
  scanf("%d",&K);
  for(i=0;i<N;i++){
    scanf("%d",&x);
    if(2*x>K) sum+=K-x;
    else sum+=x;
  }
  printf("%d\n",sum*2);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <set>
#include <map>
#include <string> 
using namespace std;
int main() {
	
	
	int n;
	string str;
	while (cin >> n) {
		set<string> st;
		for (int i = 0; i < n; i++) {
			cin >> str;
			st.insert(str);
		}
		cout << st.size() << endl;
	}
	
	
	
	
    return 0;
}


Measured memory_bytes: 19236
#include <stdio.h>

int main(void)
{
  int n;

  scanf("%d", &n);

  if (n / 100 == 7) 
    printf("Yes");
  else if ((n % 100) / 10 == 7)
    printf("Yes");
  else if (n % 10 == 7)
    printf("Yes");
  else
    printf("No");

  return 0;
}


Measured memory_bytes: 1732
from itertools import permutations
n = int(input())
xy = [tuple(map(int, input().split())) for _ in range(n)]

ans = 0
t = 0
for i in permutations(xy, n):
  t += 1
  for j in range(n-1):
    ans += ((i[j][0] - i[j+1][0])**2 + (i[j][1] - i[j+1][1])**2)**0.5
print(ans/t)

Measured memory_bytes: 9452
<?php
$list = array();
    while(true)
    {
        $list = trim(fgets(STDIN));
        if ($list === '')
        {
            //var_dump($stdins);
            break;
        }
        $array[] = $list;
    }
//$list = explode("\n",$array);
$list = $array;
$count = array_count_values($list);
$max = max($count);
$num = array_keys($count,$max);
$getans = array();

foreach($num as $value){
  $getans[] = $value;
}
asort($getans);
$ans = implode("\n", $getans);
echo $ans;
?>

Measured memory_bytes: 15308
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long res;

        res = Math.max(Math.max(Math.max(a*c,a*d),b*c),b*d);

        
        
        System.out.println(res);
        
        }
    }

Measured memory_bytes: 35660
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Main {
    int N;
    vector<ll> A;
    void input() {
        cin >> N;
        A.resize(N);
        REP(i, N) { cin >> A[i]; }
    }
    void output() {
        if (A[0] > 0) {
            cout << -1 << endl;
            return;
        }
        ll res = 0;
        REP(i, N - 1) {
            if (A[i + 1] >= A[i] + 2) {
                cout << -1 << endl;
                return;
            }
            if (A[i + 1] > A[i]) {
                ++res;
            } else if (A[i + 1] > 0) {
                res += A[i + 1];
            }
        }
        cout << res << endl;
    }

public:
    Main() {
        input();
        output();
    }
};

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

    Main();

    return 0;
}


Measured memory_bytes: 4784
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <string.h>
#include <cstdio>
using namespace std;
void deleteAllMark(string &s, const string &mark)
{
    size_t nSize = mark.size();
    while(1)
    {
        size_t pos = s.find(mark);
        if(pos == string::npos)
        {
            return;
        }
        s.erase(pos, nSize);
    }
}
int main(void)
{
    string input;
    cin >> input;
    //cout << input[input.length()-1] << endl;
    string screen="";
    for(int i=0;i<input.length();i++)
    {
        if(input[i]=='B')
        {
            deleteAllMark(screen," ");
            screen[screen.length()-1]=' ';
            deleteAllMark(screen," ");
            //cout << screen << endl;
        }
        else
        {
            screen+=input[i];
            //cout << screen << endl;
        }
    }
    cout << screen << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
	Scanner sc = new Scanner(System.in);
	String S = sc.nextLine();

	if(S.equals("ABC")) {
		System.out.println("ARC");
	}else if(S.equals("ARC")) {
		System.out.println("ABC");
	}

}
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
#define int long long

signed main(){
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    vector<vector<int>> d(n, vector<int>(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
            d[i][j] = a[i][j];
        }
    }

    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int res = 0;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if(d[i][j] < a[i][j]){
                cout << -1 << endl;
                return 0;
            }
            res += d[i][j];
        }
    }

    for (int i = 0; i < n-1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            bool flag = false;
            for (int k = 0; k < n; ++k) {
                if(k == i || k == j) continue;
                if(d[i][j] == d[i][k] + d[k][j]) flag = true;
            }
            if(flag) res -= d[i][j];
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 1664
import sys
input = sys.stdin.readline
N, T = map(int, input().split())
D = []
for _ in range(N):
    a, b = map(int, input().split())
    D.append((a,-b))

D.sort()

dp = [[0] * (T) for _ in range(N)]
for i in range(1, N):
    a, b = D[i-1]
    b = -b
    for t in range(T):
        dp[i][t] = dp[i-1][t]
        if t >= a:
            dp[i][t] = max(dp[i][t], dp[i-1][t-a]+b)

print(max(-D[i][1] + dp[i][-1] for i in range(1,N)))

Measured memory_bytes: 112860
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

aa = inputs[0][0]
bb = inputs[0][1]

# body
if $debugFlag
end

if aa >= 13
  puts bb
elsif aa >= 6
  puts bb/2
else
  puts 0
end


Measured memory_bytes: 1788
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int S[1000], top;

void push(int x){
	S[++top] = x;
}

int pop(){
	top--;
	return S[top + 1];
}

int main(){
	int a, b;
	char s[200];
	top = 0;
	while (scanf("%s", s) != EOF){
		if (s[0] == '+'){
			a = pop();
			b = pop();
			push(a + b);
		}else if(s[0] == '-'){
			b = pop();
			a = pop();
			push(a - b);
		}else if (s[0] == '*'){
			b = pop();
			a = pop();
			push(a * b);
		}
		else{
			push(atoi(s));
		}
	}
	printf("%d\n", pop());
	return 0;
}

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

#define pq priority_queue
#define mp make_pair
#define cauto const auto &

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

typedef long long int64;
typedef long long lint;
typedef long long lli;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

typedef pair<int, int> pint;
typedef pair<long, long> plong;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T = int> T in() {
    T x;
    cin >> x;
    return (x);
}
template <class T> void print(T &x) {
    cout << x << '\n';
    return;
}

template <class T> ll sized_subset(T &comb) {
    T x = comb & -comb, y = x + comb;
    return ((comb & ~y) / x) >> 1 | y;
}

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

int main() {
    ll a = in(), b = in(), q = in();
    vector<ll> s(a), t(b), x(q);
    REP(i, a) { cin >> s[i]; }
    REP(i, b) { cin >> t[i]; }
    REP(i, q) { cin >> x[i]; }
    REP(i, q) {
        auto shrineid = lower_bound(s.begin(), s.end(), x[i]);
        auto templeid = lower_bound(t.begin(), t.end(), x[i]);
        ll sl,sr,tl,tr;
        if (shrineid  > s.begin()) {
            sl = *(shrineid - 1) - x[i];
        } else {
            sl = -linf;
        }
        if (shrineid < s.end()) {
            sr = *shrineid - x[i];
        } else {
            sr = linf;
        }
        if (templeid  > t.begin()) {
            tl = *(templeid - 1) - x[i];
        } else {
            tl = -linf;
        }
        if (templeid < t.end()) {
            tr = *templeid - x[i];
        } else {
            tr = linf;
        }
        cout<<min({sr+min(abs(tr-sr),abs(tl-sr)),abs(sl)+min(abs(tr-sl),abs(tl-sl)),abs(tl)+min(abs(sr-tl),abs(sl-tl)),abs(tr)+min(abs(sl-tr),abs(sr-tr))})<<endl;
    }
    return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<string.h>

#define MAX_SIZE 298

using namespace std;

int main(void) {
  int table[MAX_SIZE];
  int x, n;

  while(true) {
    cin >> n;
    cin >> x;
    if(n == 0 && x == 0) {
      break;
    }
    else {
      memset(table, 0, sizeof(table));
      for(int i = 1; i <= n - 2; i++) {
        for(int j = i + 1; j <= n - 1; j++) {
          for(int k = j + 1; k <= n; k++) {
            table[i + j + k]++;
          }
        }
      }
      cout << table[x] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
<?php
      fscanf(STDIN, "%i", $x);
      if ($x > pow(10, 15) + pow(10, 14) * 5) throw null;
      $d = (int)ceil($x / 11);
      $m = $x % 11;
      echo ($d * 2 - (($m >= 1 && $m <= 6) ? 1 : 0)).PHP_EOL;
    ?>

Measured memory_bytes: 2812
#include <iostream>
using namespace std;
typedef long long ll;

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

ll gcdm(ll i, ll j, ll k) {
    return gcd(gcd(i, j), k);
}

int main() {

    ll n;
    cin >> n; 
    ll sum = 0;
    for (ll i = 1; i <= n; i++) 
        for (ll j = 1; j <= n; j++) 
            for (ll k = 1; k <= n; k++)
                sum += gcdm(i, j, k);

    cout<<sum<<" ";  
    return 0;
}

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

#define int long long

int n;
string s, s0, s1;

void check(string &t) {
	if (t == "Vacant")
		exit(0);
}

int32_t main() {
	cin >> n;
	cout << 0 << endl;
	cin >> s0;
	check(s0);
	cout << n - 1 << endl;
	cin >> s1;
	check(s1);
	
	int l = 0, r = n - 1;
	while (r - l > 2) {
		int mid = (l + r) / 2;
		if ((mid - l) & 1) {
			if (mid < r - 1)
				mid++;
			else
				mid--;
		}
		cout << mid << endl;
		cin >> s;
		check(s);
		
		if (s == s0)
			l = mid;
		else
			r = mid;
	}
	cout << r - 1 << endl;
}

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

map<int,int> mapa;
vector<int> vet;

int main(){
  long long int ans = 0;
  int n;
  int val;

  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> val;
    
    ans += mapa[i-val];

    mapa[i + val]++;
  }

  cout<<ans<<endl;
}

/*
-1 -2 0 3
2 3 3 1 3 1
3 5 6 5 8 7

*/

Measured memory_bytes: 20560
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a=0,b=0;
    cin>>a>>b;
    cout<<(a*b)<<endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
int main(){	
	cin>>n;
	ll m=sqrt(n);
	for(ll i=m;i>=1;i--){
		if(n%i==0){
			cout<<i+n/i-2<<endl;
			return 0;
		}
	}
	return 0;
} 

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

int main(){
	int N; cin >> N;
	vector<int> a(N);
	int ans = 0;
	for(int i = 0; i < N; i++)
	{
		cin >> a[i];
		while(a[i] % 2 == 0){
			a[i] /= 2;
			ans++;
		}
	}

	cout << ans << endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S , T;
  cin >> S >> T ;
  int A , B ;
  cin >> A >> B;
  string U;
  cin >> U;
  
  if(S == U){
    cout << A - 1 << " " << B << endl;
  }
  else{
    cout << A << " " << B - 1 << endl;
  }

}

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

int main()
{
	string s1,s2,s3;
	cin >> s1 >> s2 >> s3;
	char c1 = s1[0] - 0x20, c2 = s2[0] - 0x20,c3 = s3[0] - 0x20;
	cout << c1 << c2 << c3 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
#include <cstring>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
using Graph = vector<vector<ll>>;
/* 4 方向への隣接頂点への移動を表すベクトル */
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
ll H, W;
ll sX, sY, gX, gY;
ll N, M;
bool graph[8][8];
int dfs(ll v,bool visited[8]) {
	bool all_visited = true;
	rep(i,N) {
		if (visited[i]==false) {
			all_visited = false;
		}
	}

	if (all_visited)return 1;

	int ret = 0;
	rep(i,N) {
		if (graph[v][i] == false)continue;
		if (visited[i])continue;

		visited[i] = true;
		ret += dfs(i,visited);
		visited[i] = false;
	}
	return ret;
}


int main() {

	cin >> N >> M;
	rep(i, M) {
		ll tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		tmp1--; tmp2--;
		graph[tmp1][tmp2] = graph[tmp2][tmp1] = true;
	}
	bool visited[8];
	rep(i,N) {
		visited[i] = false;
	}
	visited[0] = true;
	cout << dfs(0, visited) << endl;

	return 0;
}

Measured memory_bytes: 3600
#include<cstdio>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;

int n,f=1;
vector<int>x(n+10),y(n+10);


double dist(int i,int j){
	double dx=x[i]-x[j];
	double dy=y[i]-y[j];
	return pow(dx*dx+dy*dy,0.5);
}

int main(){
	scanf("%d",&n);	
	vector<int>v(n);
	for(int i=0;i<n;i++){
		v[i]=i;
		scanf("%d%d",&x[i],&y[i]);
	}
	double dis=0.0;
	do{
		for(int i=0;i<n-1;i++)dis+=dist(v[i],v[i+1]);
	}while(next_permutation(v.begin(),v.end()));
	for(int i=2;i<=n;i++){
		f*=i;
	}
	printf("%.10lf\n",dis/(double)f);
	return 0;
}

Measured memory_bytes: 256
n=int(input())
nmb=21
r_m=0
for i in range(n):
    a,v=map(int,input().split())
    if r_m<v:
        nmb,r_m=a,v
    elif r_m==v:
        nmb=min(nmb,a)
print(nmb,r_m)


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

int main() {
	int a, b;
	cin >> a >> b;
	if (a % 2 == 1&&b % 2 == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main() {
    int n, k;
    cin >> n >> k;
    ll ans = 0;
    rep (b, k + 1, n + 1) {
        ll sum = (b - k);
        ll amari = n % b;
        if (amari >= k && amari < b) {
            sum += (n - amari) / b * (amari - k + 1) +
                   ((n - amari) / b - 1) * (b - amari - 1);
        } else {
            sum += (b - k) * ((n - k) / b);
        }
        if (k == 0) sum--;
        /*
        rep (i, k, b) {
            sum2 += (n - i) / b + 1;
            // cout << b << " " << sum << "\n";
        }
        cout << sum2 << " " << sum << "\n";
*/
        ans += sum;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
n= int(input())
A = list(map(int, input().split()))
q = int(input())
Mi = map(int, input().split())
PS={}
def solve(i,m):
 if m == 0:
  return True
 if (i,m) in PS:
  return PS[(i,m)]
 if i >= n:
  return False
 res = solve(i+1, m) or solve(i + 1, m - A[i])
 PS[(i,m)] = res
 return res

for m in Mi:
 if solve(0, m):
  print("yes")
 else:
  print("no")

Measured memory_bytes: 11808
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,v,p;
    cin>>n>>m>>v>>p;
    ll a[n];
    for(int i=0;i<n;i++){
    	cin>>a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    ll le=p-1,ri=n,mid,sum;
    while(ri-le>1LL){
    	mid=(ri+le)/2;
    	ll num=a[mid]+m;//mid_count
    	ll nes=v-(n-mid);//pain
    	sum=0;
    	nes-=(p-1);
    	nes=max(0LL,nes);
    	for(int i=p-1;i<mid;i++){
    		sum+=min(m,max(0LL,num-a[i]));
    	}
    	//cout << mid<<" "<<nes<<" "<<sum<<endl;
    	if(nes*m<=sum&&a[p-1]<=num){
    		le=mid;
    	}else{
    		ri=mid;
    	}
    }
    cout << le+1<<endl;
    return 0;
}


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

int main() {
    int i;
	bool flag;
	char a[10];
	while(scanf("%s",a)!=EOF) {
		flag = 0;
		for(i=0;i<strlen(a);i++) {
			if(a[i]=='A'&&a[i+1]=='C') {
				flag = 1;
				break;
			}
		}
		if(flag) printf("Yes\n");
		else printf("No\n");
	}
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
  int N,K,X,Y,ans;
  cin >> N >> K >> X >> Y;
  for (int i=1;i<=N;i++){
    if (i<=K)
      ans += X;
    if (i>K)
      ans += Y;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin>>N;
    vector<int>vec(N);
    for(int i=0;i<N;i++){
        cin >>vec.at(i);
    }
    int count=0;
    for(int i=0;i<N;i++){

        if(vec.at(vec.at(i)-1)==i+1){
           count++;
        }
    }
    cout<<count/2<<endl;
    }

Measured memory_bytes: 3768
N, K, Q = map(int, input().split())
A = list()
for n in range(Q):
	A.append(int(input()))
P = [K-Q for x in range(N)]
for a in A:
	P[a-1] += 1
for x in P:
	if x > 0:
		print("Yes")
	else:
		print("No")


Measured memory_bytes: 11784
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int x,y,a,b,c; cin>>x>>y>>a>>b>>c;
    vector<ll> p(a),q(b),r(c);
    rep(i,a) cin>>p[i];
    rep(i,b) cin>>q[i];
    rep(i,c) cin>>r[i];

    sort(p.begin(), p.end(), greater<>());
    sort(q.begin(), q.end(), greater<>());
    sort(r.begin(), r.end());
    priority_queue<ll,vector<ll>, greater<ll>> red,green;
    rep(i,x) red.push(p[i]);
    rep(i,y) green.push(q[i]);

    rep(i,c) {
        if (red.top() > green.top()) {
            int n = green.top();
            if (n >= r[i]) continue;
            green.pop();
            green.push(r[i]);
        }
        else  {
            int n = red.top();
            if (n >= r[i]) continue;
            red.pop();
            red.push(r[i]);
        }
    }

    ll ans = 0;
    while (!red.empty()) {
        ans += red.top();
        red.pop();
    }
    while (!green.empty()) {
        ans += green.top();
        green.pop();
    }

    cout << ans << '\n';
    return 0;
}

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

int n,cnt;

long long a[200005],b[200005];

long long ans;

long long cha(long long *s){
    long long minn,maxn;
    minn=maxn=s[1];
    for(int i=1;i<=n;i++){
        maxn=max(maxn,s[i]);
        minn=min(minn,s[i]);
    }
    return maxn-minn;
}
long long mx,mi=1e18,mxx,mix;

struct ha{
    long long a,b;
}u[200005];

bool operator < (const ha &aa,const ha &bb){
    return aa.a<bb.a;
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld%lld",&a[i],&b[i]);
        if(b[i]<a[i])swap(a[i],b[i]);
        if(mx<b[i]){mxx=i,mx=b[i];}
        if(mi>a[i]){mi=a[i],mix=i;}
    }
    ans=cha(a)*cha(b);

    if(mix==mxx){
        printf("%d\n",ans);
        return 0;
    }

    for(int i=1;i<=n;i++){
         if(i==mix||i==mxx)continue;
         cnt++;
         u[cnt].a=a[i];u[cnt].b=b[i];
    }
    sort(u+1,u+1+cnt);

    long long nmax=max(a[mxx],b[mix]),nmin=min(a[mxx],b[mix]);

    long long d,x;
    d=max(u[cnt].a,nmax);
    x=min(u[1].a,nmin);

    long long maxb,minb;
    maxb=minb=u[1].b;

    ans=min(ans,(d-x)*(mx-mi));
    for(int i=1;i<cnt;i++){
        maxb=max(maxb,u[i].b);
        minb=min(minb,u[i].b);

        d=max(max(u[cnt].a,maxb),nmax);
        x=min(min(minb,u[i+1].a),nmin);

        ans=min((d-x)*(mx-mi),ans);
        //cout<<ans<<endl;
    }


    d=max(maxb,nmax);
    x=min(minb,nmin);

    //cout<<d<<"  -  "<<x<<"  "<<mx-mi<<endl;

    ans=min((d-x)*(mx-mi),ans);

    printf("%lld\n",ans);

    return 0;
}


Measured memory_bytes: 6528
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = float('inf')
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    K = NI()
    S = SI()

    f = [1]
    r = [1]
    c = 1
    for i in range(1, K + len(S)+1):
        c = (c * i) % MOD
        f.append(c)
        r.append(pow(c, MOD - 2, MOD))

    def comb(n, k):
        return (f[n] * r[k] * r[n - k]) % MOD

    ans = 0
    for i in range(K+1):
        ans = (ans + pow(25,i,MOD) * pow(26,K-i,MOD) * comb(i+len(S)-1,len(S)-1)) % MOD
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 219948
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

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

  ll sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  ll dx = tx - sx, dy = ty- sy;
  string ans = "";
  for(ll i = 0; i < dy; i++) ans += "U";
  for(ll i = 0; i < dx; i++) ans += "R";
  for(ll i = 0; i < dy; i++) ans += "D";
  for(ll i = 0; i < dx; i++) ans += "L";
  ans += "L";
  for(ll i = 0; i < dy + 1; i++) ans+= "U";
  for(ll i = 0; i < dx + 1; i++) ans += "R";
  ans += "D";
  ans += "R";
  for(ll i = 0; i < dy + 1; i++) ans += "D";
  for(ll i = 0; i < dx + 1; i++) ans += "L";
  ans += "U";

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define regi register int
int n,p,a,b;
int n1,n2,n3,n4;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>a>>b;
    n1=n/3;
    for (regi i=1;i<=n;i++)
    {
        cin>>p;
        if (p<=a) n2++;
        if (a<p&&p<=b) n3++;
        if (p>b) n4++;
    }
    cout<<min(n1,min(n2,min(n3,n4)))<<endl;
    return 0;
}

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

struct edge{ int u,v,cost; };
bool comp(const edge& e1,const edge& e2){
  return e1.cost < e2.cost;
}

vector<edge> es;
int V,E; //頂点数、辺数
const int N = 1e5+10;

struct UF{
  const int N = 1e5+10;
  vector<int> par; //親
  vector<int> depth; //木の深さ

  void init(){
    par.resize(N);
    depth.resize(N);
    for(int i = 0; i < N; i++){
      par[i] = i;
      depth[i] = 0;
    }
  }

  //木の根を求める
  int root(int x){
    if(par[x] == x){
      return x;
    }
    else {
      return par[x] = root(par[x]);
    }
  }

  //xとyの属する集合を併合
  void unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x == y) return;

    if(depth[x] < depth[y]) par[x] = y;
    else {
      par[y] = x;
      if(depth[x] == depth[y]) depth[x]++;
    }
  }
}uf;

int kruskal(){
  sort(es.begin(),es.end(),comp);
  uf.init();
  int min_cost = 0;
  for(int i = 0; i < es.size(); i++){
    edge e = es[i];
    if(e.cost == -1) continue;
    if(uf.root(e.u) != uf.root(e.v)){
      min_cost += e.cost;
      uf.unite(e.u,e.v);
    }
  }
  return min_cost;
}

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

  cin >> V;
  for(int i = 0; i < V; i++){
    for(int j = 0; j < V; j++){
      int cost; cin >> cost;
      es.push_back({i,j,cost});
    }
  }
  cout << kruskal() << endl;

  return 0;
}



Measured memory_bytes: 4852
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

ll n,a,b,c,d;


bool search(){
  for(ll m=0;m<n;m++){
    if(c*(n-1-m)-d*m<=b-a&&b-a<=-c*m+(n-1-m)*d)
      return true;
  }

  return false;
}

int main(){
  cin>>n>>a>>b>>c>>d;

  if(search()){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }

  return 0;
}


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

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
const int N = 1e5 + 10;
const int D = 1e2 + 1;

ll dp[N][D][2];

ll solve(int n, int curD, string &k, int d, bool lower)
{
    if(n == k.length())
        return curD == 0;

    ll &ans = dp[n][curD][lower];

    if(ans != -1)
        return ans;

    ans = 0;

    if(lower)
    {
        for(int i = 0; i < 10; i++)
            ans = (ans + solve(n + 1, (curD + i) % d, k, d, 1)) % mod;
    }
    else
    {
        int dig = k[n] - '0';
        ans = solve(n + 1, (curD + dig) % d, k, d, 0);

        for(int i = 0; i < dig; i++)
            ans = (ans + solve(n + 1, (curD + i) % d, k, d, 1)) % mod;
    }

    return ans;
}

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

    memset(dp, -1, sizeof(dp));

    string k;
    int d;
    cin >> k >> d;

    ll ans = (solve(0, 0, k, d, 0) - 1 + mod) % mod;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 158976
/*
@ author:pyyyyyy/guhl37
-----思路------

-----debug-------

*/
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	if(n%1000!=0) cout<<((n+1000)/1000)*1000-n<<'\n';
	else cout<<0<<'\n';
	return 0;
}



Measured memory_bytes: 3672
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

ans, ans_abs = -1, float("inf")
H = [(i+1, T - h*0.006) for i, h in enumerate(H)]
for i, h in H:
    if ans_abs > abs(A - h):
        ans = i
        ans_abs = abs(A - h)
print(ans)


Measured memory_bytes: 3188
#![allow(unused_imports, dead_code, unused_variables, unused_mut)]
use std::cmp;
use std::mem::swap;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use permutohedron::LexicalPermutation;
use text_io::{read, scan};
use proconio::{input, marker::*, fastout};
const INF: i32 = std::i32::MAX;
const MOD: i32 = 1e9 as i32 + 7;

#[fastout]
fn main() {
    input! {s: String, t: String};

    let s: Vec<char> = s.chars().collect();
    let t: Vec<char> = t.chars().collect();

    let mut ans = 9999999;
    for i in 0..s.len() - t.len() + 1 {
        let mut cnt = 0;
        for j in 0..t.len() {
            if s[i + j] != t[j] {
                cnt += 1;
            }
        }
        ans = cmp::min(ans, cnt);
    }

    if ans == 9999999 {
        println!("0");
    }else{

    println!("{}", ans);
    }
}

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

int main(){
	int n;
	cin >> n;
	int d[n];
	for(int i=0;i<n;i++) cin >> d[i];
	int num[110] = {0};
	for(int i=0; i<n; i++) num[d[i]]++;
	int res = 0;
	for(int i=1; i<=100; i++){
		if(num[i]){
			res++;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{

    int a,b;
    cin >> a >> b;
    if (a==1 && b!=1){
        cout << "Alice";
    }else if (b==1 && a!=1){
        cout << "Bob";
    }else{
        if (a==b){
            cout << "Draw";
        }else if (a>b){
            cout << "Alice";
        }else{
            cout << "Bob";
        }
    }
    return 0;
}


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

#define int             long long int
#define ld              long double
#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define endl            "\n"

#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpii            vector <pii>
#define mii             map <int, int>
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))


#define M               1000000007
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 2e3 + 7;
vector <vi > adj;
bool vis[N];

int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
void solve()
{
	int k;
	cin >> k;
	cout << a[k - 1];
	cout << endl;




	return;
}

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



	cout << setprecision(9) << fixed;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}


	return 0;
}

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

const ll INF = 1001001001;

const double PI=3.141592653;

const ll MOD = 1000000007;//大きい素数


//提出のときに言語がc＋＋似合っていることを確認する

//絶対値の関数
int z(int a,int b){
  if(a>b) return a-b;
  else return b-a;
}



int main(){
    int n;cin>>n;
    int a=0;
    if(n%2==0){
      a=n/2;
    }else{
      a=(n+1)/2;
    }
    cout<<fixed<<setprecision(8);
    cout<<(double)a/n<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) { REP(i, a.size()) {cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	ll N, D;
	cin >> N >> D;

	mat X(N, vec(D));

	REP(i, N) {
		REP(j, D) {
			cin >> X[i][j];
		}
	}

	ll ans = 0;

	REP(i, N) {
		FOR(j, i + 1, N) {
			// debug(i);
			// debug(j);
			ll dsq = 0;
			REP(k, D) {
				dsq += pow(X[i][k] - X[j][k], 2);
				// debug(dsq);
			}

			for (ll k = (ll)sqrt((double)dsq); k * k <= dsq; k++) {
				if (k * k == dsq) {
					ans++;
				}
			}
		}
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256