akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#include <unordered_set>

#define _USE_MATH_DEFINES
#include <math.h>


#include <vector>
#include <list>

#include <set>
#include <map>

#include <unordered_map>

#include <queue>
#include <stack>

#include <string>

#include <vector>

#define sqr(x) (x) * (x)

#include <algorithm>
#include <functional>

#include <bitset>

#include <functional>

#include <chrono>

typedef unsigned int u32;
typedef int i32;

typedef unsigned long long int u64;
typedef long long int i64;

typedef uint16_t u16;
typedef int16_t i16;

typedef uint8_t u8;
typedef int8_t i8;


using namespace std;
using namespace std::chrono;

struct less_key
{
    bool operator() (pair<i64, i64> p1, pair<i64, i64> p2)
    {
        return p1.first > p2.first || (p1.first == p2.first && p1.second < p2.second);
    }
};

struct pair_hash {
public:
    std::size_t operator()(const std::pair<u64, u64> &x) const
    {
        return std::hash<u64>()(x.first) ^ std::hash<u64>()(x.second);
    }
};
#include <random>

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

// del

const i64 MAXN = 100005;

i64 n, m;
i64 k[MAXN];
vector<i64> s[MAXN];
i64 p[MAXN];

bool check(vector<i64> q) {
    for (auto e : q) {
        cerr << e << " ";
    }
    cerr << endl;

    for (i64 i = 1; i <= m; i++) {
        i64 t = 0;

        for (auto e : s[i]) {
            t += q[e];
        }

        if (t % 2 != p[i]) {
            return false;
        }
    }

    return true;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n >> m;

    for (i64 i = 1; i <= m; i++) {
        cin >> k[i];
        for (i64 j = 0; j < k[i]; j++) {
            i64 t;
            cin >> t;
            s[i].push_back(t);
        }
    }

    for (i64 i = 1; i <= m; i++) {
        cin >> p[i];
    }

    vector<i64> q;
    q.resize(n + 1);

    i64 R = 0;

    cerr << "------" << endl;

    for (i64 i = 0; i < (1ll << n); i++) {
        i64 t = i;

        for (i64 j = 1; j <= n; j++) {
            q[j] = t % 2;
            t /= 2;
        }

        if (check(q)) {
            R += 1;
        }
    }

    cout << R << endl;


    return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 1000003;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  string S;
  cin >> S;
  for(auto &c : S) cout << "x";
  cout << endl;

}

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

int main()
{
	ll N, W, i, j, maxv = 0, ans = -1;
	cin >> N >> W;
	vector<ll> w(N), v(N);
	for (i = 0; i < N; i++)
	{
		cin >> w[i] >> v[i];
		maxv += v[i];
	}
	ll infi = 1e15;
	vector<ll> dp(maxv + 10, infi);
	dp[0] = 0;

	for (i = 0; i < N; i++)
	{
		for (j = maxv - v[i]; j >= 0; j--)
		{
			dp[j+v[i]] = min(dp[j + v[i]], w[i] + dp[j]);
		}
	}

	for (i = 0; i < dp.size(); i++)
	{
		//cout << dp[i] << ' ';
		if (dp[i] != infi && dp[i] <= W)
			ans = max(ans, i);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int n, m;
  cin >> n >> m;
  int a[n], b[n], c[m], d[m];
  for(int i = 0; i < n; i++){
    cin >> a[i] >> b[i];
  } 
  for(int i = 0; i < m; i++){
    cin >> c[i] >> d[i];
  } 
  
  for(int i = 0; i < n; i++){
    int number;
    int min_dis = 1e9;
    for(int j = 0; j < m; j++){
      int dis = abs(a[i]- c[j]) + abs(b[i]- d[j]);
      if(dis < min_dis){
        min_dis = dis;
        number = j + 1;
      }
    }
    cout << number << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b,int c)
{
	return __gcd(a,__gcd(b,c));
}
int main()
{
	int n,ans=0;
	cin>>n;
	for(int a=1;a<=n;a++)
	{
		for(int b=1;b<=n;b++)
		{
			for(int c=1;c<=n;c++)
			{
				ans+=gcd(a,b,c);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
#

import sys
input=sys.stdin.readline

def main():
    N=int(input())
    X=input().strip("\n")
    cnt=[0]*N
    for i in range(1,N):
        n=i
        while(n>0):
            pc=0
            for j in range(19):
                if (n>>j)&1==1:
                    pc+=1
            n%=pc
            cnt[i]+=1
    pc=X.count("1")
    if pc==0:
        for i in range(N):
            print(1)
        exit()

    rp=[0]*N
    rn=[0]*N
    for i in range(N):
        rp[i]=pow(2,i,pc+1)
        if pc!=1:
            rn[i]=pow(2,i,pc-1)
    rp=rp[::-1]
    rn=rn[::-1]
            
    Xrp=0
    Xrn=0
    for i in range(N):
        if X[i]=="1":
            Xrp=(Xrp+rp[i])%(pc+1)
            if pc!=1:
                Xrn=(Xrn+rn[i])%(pc-1)
            
    for i in range(N):
        if X[i]=="1":
            if pc==1:
                print(0)
                continue
            r=Xrn-rn[i]
            print(cnt[r%(pc-1)]+1)
        else:
            r=Xrp+rp[i]
            print(cnt[r%(pc+1)]+1)
    
    
    
if __name__=="__main__":
    main()

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

int main() {
  int N;
  cin >> N;
  vector<string> str_N(120);

  for(int i = 0 ; i < N ; ++i){
    cin >> str_N.at(i);
  }

  int M;
  cin >> M;
  vector<string> str_M(120);

  for(int i = 0 ; i < M ; ++i){
    cin >> str_M.at(i);
  }

  int ans = 0;
  int score = 0;

  for(int i = 0 ; i < N ; ++i){
    for(int j = 0 ; j < N ; ++j){
      if(str_N.at(i) == str_N.at(j)) ++score;
    }
    for(int j = 0 ; j < M ; ++j){
      if(str_N.at(i) == str_M.at(j)) --score;
    }
    ans = max(ans,score);
    score = 0;
  }
  
  cout << ans << endl;

}


Measured memory_bytes: 256
n=int(input())
def div(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
ans=div(n)
ans.sort()
m=len(ans)
if(m%2==1):
    a=ans[m//2]
    b=ans[m//2]
else:
    a=ans[m//2-1]
    b=ans[m//2]
print(a+b-2)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;

int main() {
  ll a;
  string b;
  cin >> a >> b;
  int nb = (b[0] - '0') * 100 + (b[2] - '0') * 10 + (b[3] - '0');
  printf("%lld\n", a * nb / 100);
  return 0;
}


Measured memory_bytes: 3732
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

string a,b,c;
int d;

int main(){
    cin>>a>>b;
    c=a+b;
    d=stoi(c);
    for(int i=1;i*i<=d;i++){
        if(i*i==d){
            out("Yes");
            return 0;
        }
    }
    out("No");
}


Measured memory_bytes: 256
///Atcoder
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000

#define ll long long
#define sc scanf
#define pf printf
//#define pi 2*acos(0.0)

#define ft first
#define se second
#define Max 10001000
#define st(s) s.size();
#define r(input) freopen("input.txt","r",stdin)
#define w(output) freopen("output.txt","w",stdout)
#define maxall(v) *max_element(v.begin(),v.end())
#define minall(v) *min_element(v.begin(),v.end())
#define Sort(v) sort(v.begin(),v.end())
#define un(v) Sort(v), v.erase(unique(v.begin(),v.end()),v.end())
#define cover(a,d) memset(a,d,sizeof(a))

using namespace std;


int main()
{
    ll a,b;
    cin>>a>>b;
    cout<<max((a+b),max(a-b,a*b))<<endl;


    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
long long sum_(long long x)
{
	long long sum = 0;
	while (x>0)
	{
		sum += x % 10;
		x /= 10;
	}
	return sum;
}
int main()
{
	long long temp,num;
	long long sum1 = 0,sum2=1,sum=0;
	scanf("%lld", &num);
	sum1=sum_(num);
	temp = num;
	while (temp >= 10)
	{
		temp /= 10;
		sum2 *= 10;
	}
	sum = max(sum1, sum_(num / sum2 * sum2 - 1));
	printf("%lld\n", sum);
	return 0;
}

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

int main() {
  int h,n;
  cin >> h >> n;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> a.at(i);
    sum += a.at(i);
  }
  if(sum>=h){
    cout << "Yes";
  }else{
    cout << "No";
  }
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line;
        while ((line = br.readLine()) != null && !line.isEmpty()) {
            List<Integer> inputs = Stream.of(line.split(" ")).map(v->Integer.valueOf(v)).collect(Collectors.toList());
            System.out.println(String.valueOf(inputs.get(0)+inputs.get(1)).length());
        }
    }
}

Measured memory_bytes: 30928
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>

using namespace std;

int main(){
    int d,phi;
    int tot_phi = 90;
    float tot_dcos,tot_dsin;
    while(d || phi){
        scanf("%d,%d",&d,&phi);
        tot_dcos += d*cos(tot_phi*M_PI/180);
        tot_dsin += d*sin(tot_phi*M_PI/180);
        tot_phi -= phi;
    }
    cout << (int)tot_dcos << endl << (int)tot_dsin << endl;
}

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

int32_t main()
{
    string s;
    cin >> s;
    int n = s.length();
    unordered_map<int, int> ump;

    ump[0] = 1;
    int ans = 0;
    int powerOfTen = 1;
    int currentValue = 0;
    for(int i=n-1; i>=0; i--)
    {
        int curDigit = s[i] - '0';
        currentValue = (currentValue + curDigit * powerOfTen ) % mod;
        powerOfTen = (powerOfTen * 10 ) % mod;
        ans += ump[currentValue];
        ump[currentValue]++;
    }
    
    cout << ans << endl;
    return 0;
}

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

int main(){
    long long a,b,c;
    cin >> a >> b >> c;

    if( c-a-b <= 0 ){
        printf("No\n");
        return 0;
    }

    long long u = (c-a-b)*(c-a-b);
    long long v = a*b;
    long long k = u / v;

    if( k > 4 ){
        printf("Yes\n");
    }else if( k*v != u && k == 4 ){
        printf("Yes\n");
    }else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
#define maxn 100000
long long ans[maxn*2+10]={0},tot=0;
char s[maxn+10];
int main()
{
    int sum=0;
    scanf("%s",s);
    int len=strlen(s);
    ans[maxn]++;
    for(int i=0;i<len;i++)
    {
        if(s[i]=='(')
            sum++;
        else
            sum--;
        ans[maxn+sum]++;
    }
    for(int i=0;i<=maxn*2;i++)
        tot+=(ans[i]*(ans[i]-1))/2;

    printf("%lld\n",tot-1);
    return 0;
}

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(b*2==a+c){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>

using namespace std;

int main() {
  vector<bool> S(13);
  vector<bool> H(13);
  vector<bool> C(13);
  vector<bool> D(13);

  int i;
  for(i = 0; i < 13; i++) {
    S[i] = false;
    H[i] = false;
    C[i] = false;
    D[i] = false;
  }

  int n;
  scanf("%d", &n);

  char t, nl;
  int r;

  i = 0;
  while(true) {
    scanf("%c %d%c", &t, &r, &nl);
    if(t == 'S') S[r - 1] = true;
    else if(t == 'H') H[r - 1] = true;
    else if(t == 'C') C[r - 1] = true;
    else if(t == 'D') D[r - 1] = true;
    i++;
    if(i > n + 1) break;
  }

  for(i = 0; i < 13; i++) {
    if(!S[i]) printf("S %d\n", i + 1);
  }
  for(i = 0; i < 13; i++) {
    if(!H[i]) printf("H %d\n", i + 1);
  }
  for(i = 0; i < 13; i++) {
    if(!C[i]) printf("C %d\n", i + 1);
  }
  for(i = 0; i < 13; i++) {
    if(!D[i]) printf("D %d\n", i + 1);
  }
  return 0;
}

Measured memory_bytes: 2564
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

#include <inttypes.h>
using namespace std;

static int32_t c[10][10];
static int32_t memo[10][2000];

static int32_t dfs(int32_t index, int32_t used)
{
	if (memo[index][used] > -1)
		return memo[index][used];

	int32_t res = numeric_limits<int32_t>::max();
	for (int32_t i = 0; i < 10; i++) {
		if ((used & (1 << i)) == 0) {
			res = min(res, dfs(i, used | (1 << i)) + c[index][i]);
		}
	}

	memo[index][used] = res;
	return res;
}

int main()
{
	int32_t H, W;
	scanf("%d%d", &H, &W);

	for (int32_t row = 0; row < 10; row++) {
		for (int32_t col = 0; col < 10; col++) {
			scanf("%d", &c[row][col]);
		}
	}

	int32_t A[200][200];
	for (int32_t row = 0; row < H; row++) {
		for (int32_t col = 0; col < W; col++) {
			scanf("%d", &A[row][col]);
		}
	}

	for (int32_t i = 0; i < 10; i++) {
		if (i == 1) {
			for (int32_t j = 0; j < 2000; j++)
				memo[i][j] = 0;
		} else {
			for (int32_t j = 0; j < 2000; j++)
				memo[i][j] = -1;
		}
	}

	int32_t dist_to_1[10];
	dist_to_1[1] = 0;
	for (int32_t i = 0; i < 10; i++) {
		if (i == 1)
			continue;
		dist_to_1[i] = dfs(i, 0);
	}

	int32_t res = 0;
	for (int32_t row = 0; row < H; row++) {
		for (int32_t col = 0; col < W; col++) {
			if (A[row][col] == -1)
				continue;
			res += dist_to_1[A[row][col]];
		}
	}

	printf("%d\n", res);

	return 0;
}


Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

ll expo(ll a, ll b){
    ll ex = 1;
    rep(i, b){
        ex *= a;
    }
    return ex;
}

ll fact(ll a){
    ll fc = 1;
    REP(i, 1, a+1){
        fc *= i;
    }
    return fc;
}

int main() {
    str s;
    cin >> s;
    ll pls = 0, mn = 0;
    rep(i,4) {
        if(s[i] == '+') {
            pls++;
        }
        else {
            mn++;
        }
    }
    cout << pls - mn << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
//#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}
template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

signed main() {
  //https://atcoder.jp/contests/agc036/tasks/agc036_a
  ll s; cin >> s;
  const ll a = 1000000000;
  cout << "0 0 1000000000 1 ";
  ll b = (s + a-1) / a;
  cout << a*b-s << " " << b << endl;
}


Measured memory_bytes: 3612
#include<stdio.h>

int main(void){
    
    int N;
    scanf("%d",&N);
    int A[N];
    for(int i=0; i<N; i++){
        scanf("%d",&A[i]);
    }
    while(1){
        int min_iter=0;
        while(A[min_iter] == 0){
            min_iter++;
        }
        for(int i=0; i<N; i++){
            if(A[i] < A[min_iter] && A[i] != 0)
                min_iter = i;
        }
        for(int i=0; i<N; i++){
            if(i != min_iter)
                A[i] = A[i]%A[min_iter];
        }
        int count = 0;
        for(int i=0; i<N; i++){
            if(A[i] != 0)
                count++;
        }
        if(count == 1)
            break;
    }
    for(int i=0; i<N; i++){
        if(A[i] != 0)
            printf("%d\n",A[i]);
    }
    return 0;

}


Measured memory_bytes: 512
/****************************
 * ×÷Õß£ºzxf
 * ÈÕÆÚ£º2017/8/8
 * ±êÌâ£ºShorten Diameter
 * ÌâºÅ£ºAGC001C(Atcoder 1981)
 * ×öÌâ·½·¨£º...
 * ½á¹û£º...
 * Time used£º...
 * Memory used£º...
 ****************************/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define LL long long
#define pb push_back
#define pob pop_back
#define mp make_pair
#define FILL(a,v) memset((void*)a,v,sizeof(a))
#define FILL0(a) FILL(a,0)
#define FILL1(a) FILL(a,-1)
#define ALL(a) (a).begin(),(a).end()
#define Inf 1e9
#define Mod 1000000007
#define foreach(it,x) for(typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define FOR(i,x) for(int i=1;i<=x;i++)
#define RFOR(i,x) for(int i=x-1;i>=0;i--)
#define FFOR(i,a,b) for(int i=a;i<b;i++)
#define FRFOR(i,a,b) for(int i=a-1;i>=b;i--)
#define SZ(a) ((int)(a).size())
#define FI first
#define SE second
#define OVER(a) return puts(a),0
#define fastio ios::sync_with_stdio(0)
#define filei(f) freopen(f,"r",stdin)
#define fileo(f) freopen(f,"w",stdout)
using namespace std;
typedef pair<int,int> pii;
typedef unsigned long long UINT;
typedef unsigned int Uint;
typedef long long INT;
typedef pair<INT,INT> PII;
typedef stringstream sst;
typedef istringstream iss;
typedef vector<int> vint;
typedef vector<INT> VINT;
typedef vector<pii> vpii;
typedef vector<PII> VPII;
typedef priority_queue<int> pqi;
typedef priority_queue<INT> PQI;
typedef priority_queue<pii> pqp;
typedef priority_queue<PII> PQP;
typedef priority_queue<int,vint,greater<int> > xqi;
typedef priority_queue<INT,VINT,greater<INT> > XQI;
typedef priority_queue<pii,vpii,greater<pii> > xqp;
typedef priority_queue<PII,VPII,greater<PII> > XQP;

int n,k,a,b,maxn=0;
vector<int> nei[2007];

int dfs(int t,int s,int djg,int mx)
{
	int ans=1;
	if(djg!=mx)
	{
		for(int i=0;i<SZ(nei[t]);i++)
			if(nei[t][i]!=s)
				ans+=dfs(nei[t][i],t,djg+1,mx);
	}
	return ans;
}

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n-1;i++)
	{
		scanf("%d%d",&a,&b);
		a--,b--;
		nei[a].push_back(b);
		nei[b].push_back(a);
	}
	if(k%2==0)
	{
		for(int i=0;i<n;i++)
			maxn=max(maxn,dfs(i,-1,0,k/2));
	}
	else
	{
		for(int i=0;i<n;i++)
			for(int j:nei[i])
				maxn=max(maxn,dfs(i,j,0,k/2)+dfs(j,i,0,k/2));
	}
	printf("%d\n",n-maxn);
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

char s1[15], s2[15], s3[15], t[5];

int main ()
{
	scanf ("%s", s1);
	scanf ("%s", s2);
	scanf ("%s", s3);
	t[0] = s1[0] - 32;
	t[1] = s2[0] - 32;
	t[2] = s3[0] - 32;
	puts(t);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, X;
    cin >> N >> X;
    int m[N];
    for (int i = 0; i < N; i++) cin >> m[i];

    int summ = 0;
    int minm = 1000;

    for (int i = 0; i < N; i++)
    {
        summ += m[i];
        if (m[i] < minm)
        {
            minm = m[i];
        }
    }

    int res = N + (X - summ) / minm;
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>//ok
using namespace std;
int n,k,ans,p;
int map[12][6]={
    {4,2,0,9,7},
    {1,10,8,6,4},
    {9,7,5,3,1},
    {6,4,2,0,9},
    {3,1,10,8,6},
    {0,9,7,5,3},
    {8,6,4,2,0},
    {5,3,1,10,8},
    {2,0,9,7,5},
    {10,8,6,4,2},
    {7,5,3,1,10}};
int main()
{
    scanf("%d%d",&n,&k);n-=2;
    p=n%11;n/=11;
    ans=n*5;
    for(int i=0;i<p;i++)
     for(int j=0;j<5;j++)
      if(map[i][j]==k)ans++;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
//PseudoName

    #pragma GCC optimize("O3")
    #include <bits/stdc++.h>
/*
	#include <ext/pb_ds/assoc_container.hpp>
	#include <ext/pb_ds/tree_policy.hpp>
	using namespace __gnu_pbds;
	template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/
    #define FOR(i,n) for(i=0;i<n;i++)
    #define FOR1(i,n) for(i=1;i<=n;i++)
    #define FOR2(I, A, B) for (int I = (A); I <= (B); ++I)
    #define pb push_back
    #define unique_sort(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
    #define print(v) for(auto it:v)cout<<it<<" ";cout<<endl
    #define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define endl "\n"
    #define min3(a,b,c) min(a,min(b,c))
    #define forr(n) for(int i=0;i<n;i++)
    #define frr(n) for(int i=1;i<=n;i++)
    #define MAX 200005
    #define inf 200008

    using namespace std;

    typedef long long ll;
    typedef long li;
    typedef vector<int> vi;
    typedef vector<ll> vli;
    typedef vector<vi> vvi;
    typedef vector<vli> vvli;
    typedef pair<int,int> pi;
    typedef pair<ll,ll> pli;
    typedef vector<pi> vpi;
    typedef vector<pli> vpli;


    int ab(int n)
    {
        if(n<0)return -n;
        else
            return n;
    }

    int main() {
        fast();
        int n;
        cin>>n;
        int a[n];
        int dp[n+1]={0};
        forr(n)
        {
            cin>>a[i];
        }

        dp[0]=0;
        dp[1]=abs(a[1]-a[0]);
        if(n==2){cout<<dp[1]<<endl;exit(0);}
        for(int i=2;i<n;i++)
        {
          //  cout<<a[i]<<"    "<<dp[i-1]+abs(a[i]-a[i-1])<<"   possible for "<<dp[i-2]<<"\n";
            dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
        }
        //forr(n)cout<<dp[i]<<" ";
        //cout<<endl;
        cout<<dp[n-1]<<endl;


    }


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int k,n;
  cin>>k>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a,a+n);
  int temp=0;
  for(int i=0;i<n-1;i++) temp=max(temp,a[i+1]-a[i]);
  int ans=min(a[n-1]-a[0],k-temp);
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Integer[] K = {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};
        Scanner scan = new Scanner(System.in);
        Integer num = Integer.parseInt(scan.nextLine());

        System.out.println(K[num - 1]);
    }
}


Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main(){
  int h, n, a=0, tmp;

  cin>> h >> n;
  
  for(int i=0;i<n;i++){
    cin>> tmp;
    a+=tmp;
  }

  if(h<=a) cout<< "Yes" <<endl;
  else cout<< "No" <<endl;
  
  return 0;
}





Measured memory_bytes: 256
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())

edge = [[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

inf=float("inf")

prv=[inf]*n
prv[0]=-1
depth=[inf]*n
depth[0]=0
stack=[0]
while stack:
  cur=stack.pop()
  for next in edge[cur]:
    if prv[next]==inf:
      prv[next]=cur
      depth[next]=depth[cur]+1
      stack.append(next)
e,o=0,0
for i in range(n):
  if depth[i]%2:
    o+=1
  else:
    e+=1
Ans=[0]*n
if e<=n//3:
  ct1,ct2,ct3=0,0,0
  for i in range(n):
    if not depth[i]%2:
      Ans[i]=3*ct3+3
      ct3+=1
    else:
      if 3*ct2+2<=n:
        Ans[i]=3*ct2+2
        ct2+=1
      elif 3*ct1+1<=n:
        Ans[i]=3*ct1+1
        ct1+=1
      else:
        Ans[i]=3*ct3+3
        ct3+=1
elif o<=n//3:
  ct1,ct2,ct3=0,0,0
  for i in range(n):
    if depth[i]%2:
      Ans[i]=3*ct3+3
      ct3+=1
    else:
      if 3*ct1+1<=n:
        Ans[i]=3*ct1+1
        ct1+=1
      elif 3*ct2+2<=n:
        Ans[i]=3*ct2+2
        ct2+=1
      else:
        Ans[i]=3*ct3+3
        ct3+=1
else:
  ct1,ct2,ct3=0,0,0
  for i in range(n):
    if not depth[i]%2:
      if 3*ct1+1<=n:
        Ans[i]=3*ct1+1
        ct1+=1
      else:
        Ans[i]=3*ct3+3
        ct3+=1
    else:
      if 3*ct2+2<=n:
        Ans[i]=3*ct2+2
        ct2+=1
      else:
        Ans[i]=3*ct3+3
        ct3+=1

print(*Ans)


Measured memory_bytes: 107200
N=int(input())
h=list(map(int, input().split()))
history=[0,abs(h[1]-h[0])]

for x in range(2,N):
    here=min(history[0]+abs(h[x]-h[x-2]), history[1]+abs(h[x]-h[x-1]))
    history[0]=history[1]
    history[1]=here
print(history[1])

Measured memory_bytes: 13980
#include<stdio.h>
#include<stdlib.h>

main() {
 
  int top=-1; /* スタックの最後尾 */
  int stack[100];

  char input[7];


  while(scanf("%s", input)!=EOF) {
    switch(input[0]) {
    case '+':
      stack[top-1] += stack[top];
      top--;
      break;
    case '-':
      stack[top-1] -= stack[top];
      top--;
      break;
    case '*':
      stack[top-1] *= stack[top];
      top--;
      break;
    default:
      stack[top+1] = atoi(input);
      top++;
    }
  }
  
  printf("%d\n", stack[top]);

  return 0;

}

Measured memory_bytes: 548
import heapq
INF = 10**10
n = int(input())
a = [[int(item) for item in input().split()] for _ in range(n)]
b = [[INF for _ in range(n)] for _ in range(n)]

ans = 0
for i in range(n):
    ans += sum(a[i])
    a[i][i] = INF
ans //= 2

for i in range(n):
    for j in range(i):
        bipas = min(map(sum, zip(a[i], a[j])))
        if a[i][j] > bipas:
            print(-1)
            exit()
        if a[i][j] == bipas:
            ans -= a[i][j]
print(ans)

Measured memory_bytes: 7412
//#pragma comment(linker, "/STACK:134217728")

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair

int main()
{
	int n;
	scanf("%d", &n);
	vector<PII> v(n, PII(0, 0));
	int i;
	FOR(i, 0, n) scanf("%d", &v[i].first);
	sort(ALL(v));
	int res = 0;
	RFOR(i, n, 0)
		if(v[i].second == 0)
		{
			v[i].second = 1;
			int two = 1;
			while (two <= v[i].first) two <<= 1;
			int need = two - v[i].first;
			auto it = lower_bound(ALL(v), PII(need, 1));
			if (it == v.begin()) continue;
			--it;
			if (it->first != need || it->second != 0) continue;
			++res;
			it->second = 1;
		}

	printf("%d\n", res);
	return 0;
};


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define N 100010
#define M 110

using namespace std;
int x, n;
int a[M];

int read() {
	int s = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) s = s * 10 + (ch ^ 48), ch = getchar();
	return f ? -s : s;
}

int main() {
	x = read(), n = read();
	for (int i = 1, c; i <= n; i++)
		c = read(), a[c] = 1;
	int minn = 1000, ans = 0;
	for (int i = 0; i <= 110; i++)
		if (a[i] == 0) 
			if (minn > abs(x - i)) 
				ans = i, minn = abs(x - i);
	cout << ans;
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<stdlib.h>
void insertionSort(int*,int,int*);
void ShellSort(int,int *);
int count = 0;
int temp = 0; 
int temp_temp;
int h[14];
int main(void){
	int num,*arr,i,j;
	scanf("%d",&num);
	arr = (int *)malloc(sizeof(int) * num);
	for(i=0;i<num;i++) scanf("%d",&arr[i]);
	ShellSort(num,arr);
	printf("%d\n",temp_temp+1);
	for(i=temp;i!=-1;i--)  i==0 ? printf("%d\n",h[i]):printf("%d ",h[i]);
	printf("%d\n",count);
	for(i=0;i<num;i++){
		printf("%d\n",arr[i]);
	}
	return 0;
	
}
void ShellSort(int num,int *arr){
	int i,j,n,m;//temp = 0;
	h[0]=1;
	for(i=0;i<14;i++){
		h[i+1] = 3 * h[i] +1;
	//	if(11==i) printf("%d\t%d\n",h[i],i);
     //		printf("%d\n",h[i+1]);
		}
	for(i=0;i<14;i++){
		if(num < h[i]){temp = i-1;break;}
		}
//	printf("%d\n",h[temp]);
/*	for(i=0;i<h[temp];i++){	
		printf("%d!!\n",i);
		insertionSort(arr,num,&h[i]);
	}
*/
	for(i=temp;i!=-1;i--){
		if(i==temp){/*printf("%d\n",temp+1);*/temp_temp = temp;}
		//i==0 ? printf("%d\n",h[i]):printf("%d ",h[i]);
		insertionSort(arr,num,&h[i]);
	}
}
void insertionSort(int *arr,int num,int *h){
	int i,j,v;
//	printf("!%d\n",*h);
//	printf("!!\n");
	for(i=(*h);i<num;i++){
	//	printf("%d\n",i);
	//	printf("%d\n",arr[i]);
		v = arr[i];
		j = i - (*h);
	//	printf("!!\n");
		while(j >= 0 && arr[j] > v){
			arr[j+(*h)] = arr[j];
			j = j - (*h);
			count++;
	//		printf("!!\n");
		}
		arr[j+(*h)] = v;	
	//		printf("abc\n");
	}
}

Measured memory_bytes: 4508
N = int(input())
A = list(map(int, input().split()))

num_dic = {}

ans = 0
for i, a in enumerate(A):
    if (i - a) in num_dic:
        ans += num_dic[i-a]
    if a + i in num_dic:
        num_dic[a+i] += 1
    else:
        num_dic[a+i] = 1
print(ans)


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

#define watch(x) cerr << (#x) << ": " << (x) << endl

struct DSU {
    vector<int> parents;
    vector<int> sizes;

    DSU(int n) {
        parents.resize(n+1);
        for(int i = 1; i <= n; ++i) parents[i] = i;
        sizes.resize(n+1);
        for(int i = 1; i <= n; ++i) sizes[i] = 1;
    }

    int root(int i) {
        while(parents[i] != i) {
            parents[i] = parents[parents[i]];
            i = parents[i];
        }
        return i;
    }

    bool find(int a, int b) {
        return root(a) == root(b);
    }

    void join(int a, int b) {
        int root_a = root(a);
        int root_b = root(b);
        if(root_a == root_b) return;
        
        if(sizes[root_a] < sizes[root_b]) {
            parents[root_a] = parents[root_b];
            sizes[root_b] += sizes[root_a];
        } else {
            parents[root_b] = parents[root_a];
            sizes[root_a] += sizes[root_b];
        }
    }
};

struct edge {
    int x, y, z;
};

int32_t main() {

    int n, m; cin >> n >> m;

    vector<edge> edges(m);

    for(int i = 0; i < m; ++i) {
        cin >> edges[i].x >> edges[i].y >> edges[i].z;
    }

    DSU dsu(n);

    for(edge e : edges) {
        dsu.join(e.x, e.y);
    }

    unordered_set<int> roots;
    for(int i = 1; i <= n; ++i) {
        roots.insert(dsu.root(i));
    }

    cout << roots.size() << endl;
    
    return 0;
}


Measured memory_bytes: 6308
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

vector<int> G[1010];
int a[2010], b[2010];

bool f[1010];
int cnt[1010];
int root;
vector<int> tmp, ans;

void dfs(int v){
    if(ans.size()) return;
    bool g = false, h = true;
    for(auto u : G[v]){
        cnt[u]++;
        if(u == root){
            g = true;
            continue;
        }
        if(f[u]){
            h = false;
            continue;
        }
    }
    if(g && h){
        ans = tmp;
        return;
    }
    if(h){
        for(auto u : G[v]){
            if(ans.size()) return;
            if(cnt[u] > 1) continue;
            tmp.push_back(u);
            f[u] = true;
            dfs(u);
            if(ans.size()) return;
            tmp.pop_back();
        }
    }
    for(auto u : G[v]){
        cnt[u]--;
    }
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    rep(i, 0, m){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        G[a[i]].push_back(b[i]);
    }
    rep(i, 0, n){
        root = i;
        rep(j, 0, n) f[j] = false;
        rep(j, 0, n) cnt[j] = 0;
        f[i] = true;
        tmp.clear();
        tmp.push_back(i);
        dfs(i);
        if(ans.size()){
            cout << ans.size() << endl;
            for(int ii = 0; ii < ans.size(); ii++){
                cout << ans[ii] + 1 << endl;
            }
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int x,a,b;
	cin>>x>>a>>b;
	if(a>x&&b>x)
	{if(a>b)
	cout<<"B";
	else
	cout<<"A";
	}
	if(a<x&&b<x)
	{if(a<b)
	cout<<"B";
	else
	cout<<"A";
	}
	if(a<x&&x<b)
	{if(x-a>b-x)
	cout<<"B";
	else
	cout<<"A";
	}
	if(a>x&&x>b)
	{if(x-b>a-x)
	cout<<"A";
	else
	cout<<"B";
	}
    return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut ws = s.trim().split_whitespace();
    let a: i32 = ws.next().unwrap().parse().unwrap();
    let op = ws.next().unwrap();
    let b: i32 = ws.next().unwrap().parse().unwrap();

    println!("{}", if op == "+" {a + b} else {a - b});
}



Measured memory_bytes: 4352
from math import pi, cos, sqrt
A, B, H, M = map(int, input().split())
hour = ((H + M / 60) % 12) / 12 * 2 * pi
minute = (M % 60) / 60 * 2 * pi
theta = abs(hour - minute)
theta = min(360 - theta, theta)
print(sqrt(A ** 2 + B ** 2 - 2 * A * B * cos(theta)))

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
struct Edge {
    int to;
    int weight;
    Edge(int t, int w)
        : to(t)
        , weight(w)
    {
    }
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

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

// 負の数にも対応した % 演算
long long mod(long long val, long long m)
{
    long long res = val % m;
    if (res < 0)
        res += m;
    return res;
}

// a^n modを計算する
long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    // nを2進数表示して1が埋まっている桁に関してはa^mをかけていく
    while (n > 0) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod)
{
    return modpow(a, mod - 2, mod);
}

int main()
{
    int N;
    cin >> N;
    vector<int> P(N);
    rep(i, N) cin >> P.at(i);

    int min = INF_32;
    int ans = 0;
    rep(i, N)
    {
        if (P.at(i) < min) {
            min = P.at(i);
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();

        var x = 0;
        var ans = 0;
        for (int i = 0; i < n; i++)
        {
            if (s[i] == 'I') x++;
            else x--;
            ans = Math.Max(ans, x);
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

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

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	vl v(n);
	for (ll i = 0; i < n; i++)
		cin >> v[i];
	sort(all(v));
	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		for (ll j = i + 1; j < n; j++) {
			for (ll k = j + 1; k < n; k++) {
				if (v[i] == v[j] || v[j] == v[k])
					continue;
				if (v[i] + v[j] > v[k])
					ans++;
			}
		}
	}
	cout << ans << "\n";
}


Measured memory_bytes: 3636
package main

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

func main() {
	scanInit()
	n := scanInt()
	s := scan()
	rgbs := strings.Split(s,"")
	r := 0
	g := 0
	b := 0
	for i:= 0; i<n;i++ {
		switch rgbs[i] {
		case "R":
			r +=1
			break
		case "G":
			g +=1
			break
		case "B":
			b += 1
		}
	}
	sum := r*g*b
	for i:= 0; i<n-2; i++ {
		for j:= i+1; j<n-1; j++ {
			d:= 2*j-i
			if d>=n {
				continue
			}
			a := rgbs[i]
			b := rgbs[j]
			c := rgbs[d]
			// ここで結局 i-j == k-i  -> k == 2*i-j がもとまってる
			if a !=b && b!=c && c!=a {
				// どれかが同じモノの場合sum計算ですでに弾かれている
				sum -= 1
			}
		}
	}
	fmt.Println(sum)
}
var sc = bufio.NewScanner(os.Stdin)
func scanInit () {
	sc.Split(bufio.ScanWords)
}
func scanInt () int{
sc.Scan()
	i,_ := strconv.Atoi(sc.Text())
	return i
}
func scan () string{
 sc.Scan()
	return sc.Text()
}


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

int main() {
	int N;
	cin >> N;
	vector<ll> p(N);
	for (int i = 0; i < N; ++i) { cin >> p[i]; }

	sort(p.begin(), p.end());
	ll sum = 0;
	for (int i = 0; i < N; ++i) {
		if (i == N - 1) {
			sum += (p[i] / 2);
		} else {
			sum += p[i];
		}
	}

	cout << sum << endl;

	return 0;
}


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

int main(void){
    ll n,a,b;
    cin >> n >> a >> b;
    ll sub_a = (n/(a+b))*a;
    ll sub_b = (n/(a+b))*b;
    ll dub = n - (sub_a+sub_b);
    if(dub >= a)cout << sub_a+a << endl;
    else cout << sub_a + dub % a << endl;
}


Measured memory_bytes: 256
k, n = (int(x) for x in input().split())
a = list([int(x) for x in input().split()])

dist_betweenHomes = list()
for i in range(len(a)):
    if i + 1 == len(a):
        d = (k - a[i]) + a[0]
    else:
        d = a[i + 1] - a[i]
    dist_betweenHomes.append(d)

maxDist = max(dist_betweenHomes)
result = k - maxDist
print(result)


Measured memory_bytes: 26444
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <utility>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
using namespace std;
static const int maxn = 3 * 1e5 + 5;
int sum[maxn];
int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	for(int i = 0;i < n; ++i)
	{
		char x;
		cin>>x;
		if(i > 0)
		{
			sum[i] = sum[i - 1] + (x == 'W' ? 0 : 1);
		}
		else
		{
			sum[i] = (x == 'W' ? 0 : 1);
		}
	}
	int ans = maxn + 1;
	for(int i = 0;i < n; ++i)
	{
		int cnt1 = 0,cnt2 = 0,p = 0;
		if(i > 0 && i < n - 1)
		{
			cnt1 = i - (sum[i - 1]);
			cnt2 = sum[n - 1] - sum[i];
			// printf("%d\n",cnt2);
			p = cnt1 + cnt2;
			// printf("p = %d\n",p);
		}
		else if(i == 0)
		{
			p = sum[n - 1];
		}
		else
		{
			cnt1 = sum[n - 2];
			p = n - 1 - cnt1;
		}
		ans = min(p,ans);
	}
	printf("%d\n",ans);
	return 0;
}

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


int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a+b >= c) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int c;
	int end;
	
	c = end = 0;
	
	while (1) {
		scanf("%d %d", &a, &b);
		
		if ((a == 0) && (b == 0)){
			break;
		}
		
		if (end != 0){
			printf("\n");
			end = 0;
		}
		
		for (; a <= b; a++){
			if ((a % 4 == 0) && (a % 100 != 0) || (a % 400 == 0)){
				printf("%d\n", a);
				c++;
				end++;
			}
		}
		if (c == 0){
			printf("NA\n");
			end++;
		}
		
		c = 0;
	} 
	
	return (0);
}

Measured memory_bytes: 616
<?php
$n = trim(fgets(STDIN));
$a = trim(fgets(STDIN));
$as = explode(' ', $a);

$res=[];
foreach($as as $k => $v) {
    $res[] = $v - ($k+1);
}

$m = median($res);

$ans=0;
foreach($res as $v) {
    $ans += abs($v - $m);
}

echo $ans;

function median($list){
    sort($list);
    if (count($list) % 2 == 0){
        return (($list[(count($list)/2)-1]+$list[((count($list)/2))])/2);
    }else{
        return ($list[floor(count($list)/2)]);
    }
}

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

const int N=2e5+2;
int ar[N];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,i,j,k,l,mod,lef,rig,mid,ans=0;
    cin>>n>>mod;
    lef=0;
    rig=n;
    for(i=1;i<=n*2;i++){
        cin>>ar[i];
    }
    sort(ar+1,ar+1+2*n);
    while(rig>lef){
        mid=(lef+rig)/2;
        i=2*mid+1;
        j=2*n;
        bool cac=true;
        while(j>i){
            if(ar[j]+ar[i]<mod){
                cac=false;
                break;
            }
            j--;
            i++;
        }
        if(cac){
            rig=mid;
        }
        else{
            lef=mid+1;
        }
    }
    i = 2 * rig;
    j = 1;
    
    while(i > j){
        ans = max(ans, ar[j] + ar[i]);
        j++;
        i--;
    }

    i = 2 * rig + 1;
    j = 2 * n;
    
    while(j > i){
        ans = max(ans, ar[j] + ar[i] - mod);
        j--;
        i++;
    }

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



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

int main()
{
    ll n;
    cin >> n;
    int l = 0;
    bool all9 = true;
    while(n >= 10){
        if(n % 10 != 9) all9 = false;
        n /= 10;
        l++;
    }
    if(!all9) n--;
    cout << n + l * 9 << endl;
}

Measured memory_bytes: 256
from math import factorial
def comb (x,y):
	return factorial(x)//factorial(x-y)//factorial(y)

w,h,ax,ay,bx,by=map(int,input().split())
dx=abs(ax-bx)
dx=min(dx,w-dx)
dy=abs(ay-by)
dy=min(dy,h-dy)
an=1
if dx*2==w:an*=2
if dy*2==h:an*=2
an*=comb(dx+dy,dx)
print(an%int(1E8+7))

Measured memory_bytes: 7804
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> x(5);
  for (int i = 0; i < 5; i++)
  {
    cin >> x.at(i);
  }
  for (int i = 0; i < 5; i++)
  {
    if (x.at(i) == 0)
    {
      cout << i+1 <<endl;
    }
    
  }
  return 0;
  
 
}

Measured memory_bytes: 3628
def main():
  n = int(input())

  def get_divisors(num):
    divisors = []
    for i in range(1, int(num ** 0.5) + 1):
      if num % i == 0:
        divisors.extend([i, num // i])

    return set(divisors)

  ans = len(get_divisors(n - 1)) - 1

  for k in get_divisors(n):
    if k == 1: continue

    num = n
    while num % k == 0:
      num = num // k

    if num % k == 1:
      ans += 1

  print(ans)

main()


Measured memory_bytes: 3828
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ULL;
inline ULL read()
{
	ULL l = 0, f = 1;
	char a = getchar();
	for (; a < '0' || a > '9'; a = getchar())
		if (a == '-') f = -1;
	for (; a >= '0' && a <= '9'; a = getchar())
		l = l*10+a-48;
	return l*f;
}
ULL n, ans = 1e18;
ULL getw(ULL x)
{
	ULL num = 0;
	while(x)
	{
		++num;
		x /= 10;
	}
	return num;
}
int main(int argc, char const *argv[])
{
	n = read();
	for (ULL i = 1; i <= (int)sqrt(n)+1; ++i)
	{
		if (n%i != 0) continue;
		ans = min(ans, max(getw(i), getw(n/i)));
	}
	printf("%llu\n", ans);
	return 0;
}

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

using namespace std;

#define MAX 300000

int main()
{
	bool is_prime[MAX+1] = {false};
	for(int i = 6; i <= MAX; i += 7) {
		is_prime[i] = true;
	}
	for(int i = 8; i <= MAX; i += 7) {
		is_prime[i] = true;
	}
	for(int i = 6; i <= MAX; i++) {
		if(!is_prime[i]) continue;
		for(int j = i * 2; j <= MAX; j += i) {
			is_prime[j] = false;
		}
	}

	while(1) {
		int n;
		set<int> p_factors;

		scanf("%d", &n);
		if(n == 1) break;

		for(int i = 6; i <= MAX; i++) {
			if(!is_prime[i] || n % i != 0) continue;
			p_factors.insert(i);
		}

		printf("%d:", n);
		for(set<int>::iterator it = p_factors.begin(); it != p_factors.end(); it++) {
			printf(" %d", *it);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 1332
#include <bits/stdc++.h>
using namespace  std;
#define f(i,n) 		for(i=0;i<n;i++)
#define fr(i,n,a) 	for(i=n;i>=a;i--)
#define fa(i,a,n) 	for(i=a;i<n;i++)
#define deb(x)		cout<<#x<<" "<<x<<endl;
#define deb2(x,y)	cout<<#x<<","<<#y<<" "<<x<<","<<y<<endl;
#define buf(x)		cout<<"Check"<<x<<endl;
#define ll			long long int 
#define ft			first
#define s			second
#define pb			push_back
#define mp			make_pair
#define d			double
#define all(v)		v.begin(),v.end()	
#define et(v)		for(auto itr:v)
inline void p(int x[],int n)	{	int i;f(i,n)cout<<x[i]<<" ";cout<<endl; }


 


void solve()
{  	
	ll N,K,D,i,j,k,a=0,b=0;
	cin>>N>>K>>D;
	N=abs(N);
	ll optmoves,optpos;
	if(N%D==0)
	{	optmoves=(N/D);
		optpos=0;
	}
	else
	{
		if(2*(N%D)>D)
		{	
			optmoves=(N/D)+1;
			optpos=((N%D)-D);
		}
		else
		{	
			optmoves=(N/D);
			optpos=N%D;
		}
	}

	if(K<optmoves)
	{		
		cout<<(N-K*D);
		return;
	}
	else
	{
		if((K-(optmoves))%2==0)
		{	
			cout<<abs(optpos);
			return;
		}
		else
		{
			if(2*(N%D)>D)
			{	
				cout<<(optpos+D);
				return;
			}
			else
			{	
				cout<<abs(optpos-D);
				return;
			}
			
		}
		
	}

}
int main()
{	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll t=1,c=1;
	//cin>>t;
	while(t--)
	{
		

		//cout<<"Case #"<<c++<<": "<<endl;
		solve();
		cout<<endl;
		
	}
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int a, b, c; cin >> a >> b >> c;
    cout << a << ' ' << b << ' ' << 3*c-(a+b) << endl;
    cout << 4*c-2*a-b << ' ' << c << ' ' << 2*a+b-2*c << endl;
    cout << a+b-c << ' ' << 2*c-b << ' ' << 2*c-a << endl;
}

Measured memory_bytes: 3660