akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

int N;
int A[101];

signed main()
{
  cin >> N;
  bool flag = true;
  REP(n,N) {
    cin >> A[n];
    if(A[n]%2 == 0) {
      if(A[n] % 3 != 0 && A[n] % 5 != 0) {
        flag = false;
      }
    }
  }

  if(flag) {
    cout << "APPROVED" << endl;
  } else {
    cout << "DENIED" << endl;
  }

  return 0;
}


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

using namespace std;

const long long MOD = 1000000007;

int main() {
    int N;
    string s1, s2;
    cin >> N >> s1 >> s2;

    vector<char> vt;
    for (int i = 0; i < N; i++) {
        if (s1[i] == s2[i]) {
            vt.push_back('t');
        } else {
            vt.push_back('y');
            i++;
        }
    }

    long long ans = 0;
    ans = (vt[0] == 't') ? 3 : 6;
    for (int i = 1; i < vt.size(); i++) {
        if (vt[i - 1] == 'y' && vt[i] == 'y') {
            ans *= 3;
        } else if (vt[i - 1] == 't') {
            ans *= 2;
        }
        ans = ans % MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <vector>
#include <stack>
#include <string>
#include <iostream>
using namespace std;

const int MaxN = 1e5;
int n, c, k;
int a[MaxN + 5];

int main()
{
	scanf("%d%d%d", &n, &c, &k);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	int tot = 0; int num = 0; int last = 0;
	for(int i = 1; i <= n; i++) {
		if(a[i] > last) last = a[i] + k, tot++, num = 1;
		else if(num == c) last = a[i] + k, tot++, num = 1;
		else num++;
	}
	printf("%d\n", tot);
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1000000007;
const int N = 2010;
ll fact[N], invf[N];

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    return (x * powll(y,mod-2)) % mod;
}

ll nCr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(mul(fact[n], invf[r]), invf[n-r]);
}

ll dp[205][100001];

int main() {
    ll n, x;
    cin >> n >> x;
    VL a(n);
    REP(i,n){
        a[i] = in();
    }
    sort(ALL(a));
    reverse(ALL(a));

    fact[0] = invf[0] = 1;
    FOR(i,1,N-1){
        fact[i] = (fact[i-1] * i) % mod;
        invf[i] = divll(invf[i-1], i);
    }

    dp[0][x] = 1;
    REP(i,n) REP(r,x+1){
        dp[i + 1][r % a[i]] = (dp[i + 1][r % a[i]] + dp[i][r]) % mod;
        dp[i + 1][r] = (dp[i + 1][r] + (n - i - 1) * dp[i][r]) % mod;
    }

    ll ans = 0;
    REP(k,x+1) ans = (ans + k * dp[n][k]) % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 157184
from math import ceil, log

def main():
    n = int(input())
    if n == 0:
        print(0)
        return
    k = 2 * int(log(3 * n, 4)) + 1 if n > 0 else 2 * ceil(log((2 - 3 * n) // 2, 4))
    s = [0] * k
    while n:
        k = 2 * int(log(3 * n, 4)) if n > 0 else 2 * ceil(log((2 - 3 * n) // 2, 4)) - 1
        s[k] = 1
        n -= (-2)**k
    print(*s[::-1], sep="")

if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long ll;
using Graph =vector<int>;
typedef pair<ll,ll> P;

const ll MAX_N=131072;
int dat[MAX_N*2-1];
int n;
void init(int n){
  rep(i,2*n-1) dat[i]=INT_MAX;
}
void update(int i,int x){
  i+=n-1;
  dat[i]=x;
  while(i>0){
    i=(i-1)/2;
    dat[i]=min(dat[i*2+1],dat[i*2+2]);
  }
}
int query(int a,int b,int k,int l,int r){
  if(r<=a||b<=l) return INT_MAX;
  if(a<=l&&r<=b) return dat[k];
  else{
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
}
int main(){
  int q;cin>>n>>q;
  int N=1;
  while(N<n) N*=2;
  n=N;
  init(n);
  rep(i,q){
    int com,x,y;cin>>com>>x>>y;
    if (com==0){
      update(x,y);
    }else{
      int ans=query(x,y+1,0,0,n);
      cout<<ans<<endl;
    }
  }
}



Measured memory_bytes: 4136
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char **argv) {
    int count = 0;
    string s;

    cin >> s;

    int i = 0;
    while (true) {
        if (i > s.size() - 1 || s.empty()) {
            break;
        }

        if (s[i] == '0' && s[i + 1] == '1' || s[i] == '1' && s[i + 1] == '0') {
            s.erase(s.begin() + i + 1);
            s.erase(s.begin() + i);
            count += 2;
            if (i != 0) {
                i--;
            }
        }
        else {
            i++;
        }
    }

    cout << count << endl;

    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int ans = min(B, D) - max(A, C);
  if (ans <= 0)
    cout << 0 << endl;
  else
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long int
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define INF 1e9+7
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp);
void ipgraph(int m);
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
const int mod = 1e9 + 7;
//const int N = 2e5+5, M = N;
//=========================================

const int SZ = 55;

struct matrix{
    int mat[SZ][SZ];

    matrix(int idd = 0){
        for(int i = 0; i < SZ; ++i){
            for(int j = 0; j < SZ; ++j)
                mat[i][j] = (idd ? (i == j) : 0);
        }
    }

    matrix operator*(const matrix& other)const{
        matrix ans;
        for(int i = 0; i < SZ; ++i){
            for(int j = 0; j < SZ; ++j){
                for(int k = 0; k < SZ; ++k){
                    ans.mat[i][j] += mat[i][k] * other.mat[k][j];
                    if(ans.mat[i][j] > mod) ans.mat[i][j] %= mod;
                }
            }
        }

        return ans;
    }
};


matrix exponentiation(matrix base, int K){
    matrix ans(1);

    while(K){
        if(K & 1)
            ans = ans * base;
        base = base * base;
        K >>= 1;
    }

    return ans;
}


int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N, K;
    cin >> N >> K;

    matrix base;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j)
            cin >> base.mat[i][j];
    }
    
    matrix ans = exponentiation(base, K);

    int paths = 0;
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j)
            paths = (paths + ans.mat[i][j]) % mod;
    }

    cout << paths << "\n";

    return 0;
}


Measured memory_bytes: 3664
package main

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

func main() {
	n, m, c := readInt(), readInt(), readInt()
	b := make([]int, m)
	for i := range b {
		b[i] = readInt()
	}
	ans := 0
	for i := 0; i < n; i++ {
		sum := c
		for j := range b {
			sum += readInt() * b[j]
		}
		if sum > 0 {
			ans++
		}
	}

	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
N = int(input())
S = input()
T = list()
for i in range(int(N / 2), N):
    t = S[i]
    T.append(t)
y = 0
n = 0
for i, k in zip(T, S):
    if i == k:
        y += 1
    else:
        n += 1
if N % 2 != 0:
    print('No')
elif y >= int(N / 2):
    print('Yes') 
else:
    print('No')       
   
     


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define M 4001
const int Mod=1e9+7;
int n,k,o;
int dp[M][M];
int mod(int x) {
	while(x>=Mod)x-=Mod;
	return x;
}
int main() {
	scanf("%d%d",&n,&k);
	for(int i=0; i<M; i++)dp[i][i]=dp[0][0]=1;
	for(int i=1; i<M; i++)
		for(int j=1; j<i; j++)dp[i][j]=mod(dp[i-1][j-1]+dp[i-1][j]);
	for(int i=1; i<=k; i++)
		printf("%d\n",1LL*dp[k][i]*dp[n-k+2][i+1]%Mod);
}

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

int main() {
  int n;
  ll y;
  cin>>n>>y;
  rep(i,n+1){
    rep(j,n-i+1){
      if((y-10000*i-5000*j)%1000==0&&(y-10000*i-5000*j)/1000==n-i-j){
        cout<<i<<" "<<j<<" "<<n-i-j<<endl;
      return 0;
      }
    }
  }
  cout<<"-1 -1 -1"<<endl;    
return 0;
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = unordered_set<int32_t>;
using setstr = unordered_set<string>;
using qint = queue<int32_t>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    double a, b, x;
    cin >> a >> b >> x;

    double ans;
    double n = x / a / b * 2;
    if (n <= a)
    {
        // 三角形
        ans = atan(b / n);
    }
    else
    {
        // 台形
        double s = a * b - x / a;
        double m = s / a * 2;
        ans = atan(m / a);
    }
    cout << ans * 180 / M_PI << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <sstream>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
	int t;
	cin >> t;
	double ans = 0;
	while (t--) {
		double x;
		string y;
		cin >> x >> y;
		if (y == "JPY")ans += x;
		else ans += 380000.0*x;

	}
	cout << fixed << setprecision(6) << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

vi G[MAX_N];
vi par[MAX_N];
int ans[MAX_N][2];

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

    rep(i,n-1+m){
        int a_,b_;
        cin >> a_ >> b_;
        G[a_].push_back(b_);
        par[b_].push_back(a_);
    }

    rep(i,MAX_N){
        ans[i][0] = -1;
        ans[i][1] = -1;
    }
    int root = -1;
    srep(i,1,n+1){
        if(par[i].size()==0){
            root = i;
            break;
        }
    }
    queue<P> que;
    ans[root][0] = 0;
    ans[root][1] = 0;
    rep(i,G[root].size()){
        que.push(P(G[root][i],1));
    }
    while(que.size()){
        P p = que.front();
        que.pop();
        if(ans[p.first][0]!=-1)continue;
        int continue_flag = 0;
        rep(i,par[p.first].size()){
            if(ans[par[p.first][i]][1] == -1){
                continue_flag = 1;
                break;
            }
        }
        if(continue_flag)continue;

        rep(i,par[p.first].size()){
            if(ans[par[p.first][i]][1]+1 > ans[p.first][1]){
                ans[p.first][0] = par[p.first][i];
                ans[p.first][1] = ans[par[p.first][i]][1]+1;
            }
        }
        if(ans[p.first][0]!=-1){
            rep(i,G[p.first].size()){
                que.push(P(G[p.first][i], p.second+1));
            }
        }
    }
    
    srep(i,1,n+1){
        cout << ans[i][0] << endl;
    }

    return 0;
}
 
 


Measured memory_bytes: 18048
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int solve(int a, int b){
    int res = 0;
    if(a == 2){
        return res = b-1;
    }else{
        return res = (b-1+a-2) / (a-1);
    }
}

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


    cout << solve(a,b) << endl;
    return 0;
}
 
 


Measured memory_bytes: 256
Q, H, S, D = gets.split.map(&:to_i)
N = gets.to_i
one_min = [Q * 4, H * 2, S].min
two_min = [Q * 8, H * 4, S * 2, D].min
if N.even?
  puts N / 2 * two_min
else
  ans = N / 2 * two_min + one_min
  puts ans
end


Measured memory_bytes: 3836
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int n, k;
	cin >> n;
	cin >> k;
	if(n<=k){
		cout<<0<<endl;
	}else{
		int h[n];
		for(int i=0;i<n;++i){
			cin>>h[i];
		}
		sort(h,h+n);
		int len=n-k;
		long nAt=0;
		for(int i=0;i<len;++i){
			nAt+=h[i];
		}
		cout<<nAt<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int N,i,j,sum=0;
  cin >> N;
  vector<int> d(N);
  for(i=0;i<N;i++)cin >> d.at(i);
  for(i=0;i<N-1;i++){
    for(j=i+1;j<N;j++)sum+=d.at(i)*d.at(j);
  }
  cout << sum << endl;
}

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

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, n, a) for(int i = (a); i >= (n); i--)
#define mod 1e9+7
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  if(k % 2) {
    ans = (n / k) * (n / k) * (n / k);
  }else {
    if(n - (n / k) * k >= k / 2) {
      ans = (n / k) * (n / k) * (n / k);
      ans += ((n / k) + 1) * ((n / k) + 1) * ((n / k) + 1);
    }else {
      ans = (n / k) * (n / k) * (n / k);
      ans *= 2;
    }
  }
  cout << ans << endl;
}


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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int m;
    int temp;
    cin >> m;
    m++;
    vector<int> a(m);
    vector<int> b(m);
    vector<int> c(m);
    int n;
    cin >> n;
    rep(i, n)
    {
        cin >> temp;
        a[temp] = 1;
    }
    cin >> n;
    rep(i, n)
    {
        cin >> temp;
        b[temp] = 1;
    }
    cin >> n;
    rep(i, n)
    {
        cin >> temp;
        c[temp] = 1;
    }
    int ans = 0;
    rep(i, m)
    {
        if ((a[i] == 0 || b[i] == 1) && c[i] == 1)
            ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3120
import sys

N = int(sys.stdin.readline().rstrip())

A = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]

INF = 10 ** 19

answer = 1

for x in A:
	answer *= x
	if answer > INF:
		answer = INF

print(-1 if answer > (10 ** 18) else answer)


Measured memory_bytes: 21592
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    string s;
    ll k;
    cin >> s >> k;
    REP(i,k){
        if (s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << s[k-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a.at(i);
    }

    vector<ll> ans;
    for(int i = n - 1; i >= 0; i -= 2){
        ans.push_back(a.at(i));
    }
    for(int i = n % 2; i < n; i += 2){
        ans.push_back(a.at(i));
    }

    for(int i = 0; i < ans.size(); ++i){
        cout << ans.at(i);
        if(i < ans.size() - 1){
            cout << ' ';
        }else{
            cout << endl;
        }
    }
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


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


bool dp[10000 + 200];

int main2() {
  int N = nextInt();
  vector<int> s(N);
  REP(i, N) s[i] = nextInt();
  CLR(dp, 0);
  dp[0] = 1;
  for (auto x : s) {
    for (int j = 10000; j - x >= 0; j--) {
      if (dp[j - x]) dp[j] = true;
    }
  }
  ll ans = 0;
  for (int j = 0; j <= 10000; j++) if (dp[j] && j % 10 != 0) ans = j;
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int p,q,r,p1,q1,r1;
	scanf("%d%d%d",&p,&q,&r);
	p1=p+q;
	q1=p+r;
	r1=r+q;
	printf("%d\n",min(min(p1,q1),min(p1,r1)));
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() { cin.tie(nullptr); ios_base::sync_with_stdio(false); }
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

signed main()
{
  int a, b;
  scanf("%X%X", &a, &b);

  putchar(a == b ? '=':
      a < b? '<' : '>');
  putchar(LF);

  return 0;
}



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

int main() {
  int n;
  cin>>n;
  vector<int>x(n);
  for(int i=0;i<n;i++) cin>>x[i];
  int ans=1000000;
  for(int i=1;i<=100;i++){
    int a=0;
    for(int j=0;j<n;j++){
      a+=(x[j]-i)*(x[j]-i);
    }
    ans=min(ans,a);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
N = int(input())
S = input().rstrip()
dic = {}

for i in range(len(S)):
    if S[i] in dic.keys():
        dic[S[i]] += 1
    else:
        dic[S[i]] = 2

ans = 1
for key in dic.keys():
    ans *= dic[key]

print((ans - 1) % (10**9 + 7))

Measured memory_bytes: 3188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		String[] line = reader.readLine().split(" ");
		int n = Integer.parseInt(line[0]);
		int q = Integer.parseInt(line[1]);
		Deque<String[]> queue = new ArrayDeque<String[]>(n);
		for (int i = 0; i < n; i++) {
			queue.addFirst(reader.readLine().split(" "));
		}
		String[] work = new String[2];
		int elapse = 0;
		while ((work = queue.pollLast())!=null) {
			int time = Integer.parseInt(work[1]);
			if (time <= q) {
				elapse += time;
				builder.append(work[0]).append(" ").append(elapse).append("\n");
			} else {
				time -= q;
				elapse += q;
				work[1] = String.valueOf(time);
				queue.addFirst(work);
			}
		/*	queue.forEach(a->System.out.println(Arrays.toString(a)));
			System.out.println(Arrays.toString(work) + "  ->  work    " + elapse);
			System.out.println();*/

		}
		System.out.print(builder);
	}
}

Measured memory_bytes: 61976
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <sstream>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <cstdlib>
#include <cmath>

typedef long long ll;

#define reps(i, s, e) for (ll i = s; i < e; ++i)
#define rep(i, n) reps(i, 0, n)
#define rreps(i, s, e) for (ll i = e-1; i >= s; --i)
#define rrep(i, n) rreps(i, 0, n)

// const ll LL_INF = 1LL<<60;

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

using namespace std;


ll n, m;
vector<vector<pair<ll, ll> > > arrow;
vector<ll> dp;

ll inline calc_dp(ll i) {
    if (dp[i] != -1) return dp[i];

    ll res = 0;
    // for (pair<ll, ll> ar: arrow[i]) {
    //     chmax(res, ar.second + calc_dp(ar.first));
    // }
    rep(j, arrow[i].size()) chmax(res, arrow[i][j].second + calc_dp(arrow[i][j].first));
    return dp[i] = res;
}

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

    arrow.assign(n, vector<pair<ll,ll> >());
    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        arrow[a].push_back(make_pair(b, c));
    }
    dp.assign(n, -1);
    ll res = 0;
    rep(i, n) {
        chmax(res, calc_dp(i));
    }
    cout << res << endl;
    
}



Measured memory_bytes: 3120
# -*- coding: utf-8 -*-
# 整数の入力


def main():
    a, b = map(int, input().split())

    if b == 1:
        print(0)
        return

    count = 0
    sum = a
    count += 1
    if sum >= b:
        print(1)
        return

    while sum < b:
        sum = sum + (a - 1)
        count += 1
    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
def main():
    from functools import lru_cache
    import sys

    sys.setrecursionlimit(10 ** 7)

    inf = 2 * 10 ** 14 + 1

    N = int(input())
    *a, = map(int, input().split())

    @lru_cache(maxsize=None)
    def recursion(cur, need):
        """
        cur: pickableなindex
        """
        if cur >= N:
            if need == 0:
                return 0
            else:
                return -inf

        rest = N - cur
        if (rest + 1) // 2 < need:
            return -inf

        return max(
            a[cur] + recursion(cur + 2, need - 1),
            recursion(cur + 1, need)
        )

    ans = recursion(0, N // 2)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 201596
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C (GCC 5.4.1)
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	char str[103];
	scanf("%s",str);

	for (int i = 0; i < strlen(str); ++i)
	{
		// odd
		if(i % 2 == 0 && str[i] == 'L'){
			puts("No");
			return 0;
		}
		else if(i % 2 && str[i] == 'R'){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 128
import bisect

n = int(input())
l = list(map(int, input().split()))
l.sort()

ans = 0
for i in range(n):
    for j in range(i+1, n):
        x = bisect.bisect_left(l, l[i] + l[j])
        ans += x - j - 1
print(ans)

Measured memory_bytes: 45152
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

const int mod=1e9+7;
const int N=1000005;
int c[N],f[N],las[N];
int n;

int main(){
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",&c[i]);
	f[0]=1;
	rep(i,1,n){
		f[i]=f[i-1];
		if(las[c[i]]&&las[c[i]]<i-1)
			f[i]=(f[i]+f[las[c[i]]])%mod;
		las[c[i]]=i;
	}
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 9216
<?php
list($n, $k) = ints();
$ans = 0;
for ($b = $k + 1; $b <= $n; $b++) {
    $ans += intdiv($n, $b) * ($b - $k);
    $ans += max(0, $n % $b - $k + 1);
}
if ($k === 0) $ans -= $n - $k; // a=0の場合を除外
echo $ans;

function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

Measured memory_bytes: 4728
#include<stdio.h>

int main(){
	int a,b,c,num=0;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b||a==c)num++;
	if(b==c)num++;
	if(num==1)printf("Yes");
	else printf("No"); 
	return 0;
} 

Measured memory_bytes: 128
#include <iostream>

int main()
{
  int K, A, B;
  std::cin >> K;
  std::cin >> A >> B;
  if (A/K < B/K) std::cout << "OK" << std::endl;
  else if (A%K==0) std::cout << "OK" << std::endl;
  else std::cout << "NG" << std::endl;
  return 0;
}


Measured memory_bytes: 3636
cin = open(0).read().strip().split('\n')
n = int(cin[0])
p = list(map(int, cin[1].split(' ')))

space = [1]*(n*n)

dist = [0]*(n*n)
for r in range(n):
    for c in range(n):
        dist[r*n+c] = min(r, (n-1)-r, c, (n-1)-c)

ans = 0
for pi in p:
    pi -= 1
    q = [pi]
    ans += dist[pi]
    space[pi] = 0

    while q:
        pp = q.pop()
        for dxi in [-n,-1,1,n]:
            if dxi == 1 and pp % n==n-1: continue
            if dxi == -1 and pp % n ==n: continue
            if 0<=pp+dxi<n*n and dist[pp+dxi] > dist[pp]+space[pp]:
                q.append(pp+dxi)
                dist[pp+dxi] = dist[pp]+space[pp]

print(ans)

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


int main(){
  
  int N;
  int c=0;
  cin>>N;
  
  
  for(int i=1;i<=N;i++){
    if(i!=0&&i/10==0)
      c++;
    else if(i/100!=0&&i/1000==0)
      c++;
    else if(i/10000!=0&&i/100000==0)
      c++;
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n;
    cin>>n;
    int k = 25 - n;
    cout<<"Christmas ";
    for(int i = 0 ; i< k ; i++){
        cout<<"Eve ";
    }
    
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

s = gets.chomp
t = gets.chomp

count = 0
s.length.times do |i|
  if s[i] != t[i]
    count += 1
  end
end

puts count

Measured memory_bytes: 15160
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  vector<vector<int> > a(2,vector<int>(n));
  rep(i,n)cin>>a[0][i];rep(i,n)cin>>a[1][i];
  int sum1 = 0;
  int ans = 0;
  vector<int> sum2(n);
  sum2[0] = a[1][0];
  rep(i,n)if(i)sum2[i] = sum2[i-1] + a[1][i];

  rep(i,n){
    sum1 += a[0][i];
    ans = max(ans,sum1 + sum2[n-1] - ((i)?sum2[i-1]:0));
    //print(ans);
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define pb emplace_back
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
typedef pair<ll,int> pi;
const int N=1e5+5;
struct eg{int v,nx,w;}e[N<<1];int head[N],tot;
inline void add(R int u,R int v,R int w){e[++tot]={v,head[u],w},head[u]=tot;}
inline int min(R int x,R int y){return x<y?x:y;}
ll res;int sz[N],rt,rv,op,mmx,n;
void dfs(int u,int fa,ll dis){
	sz[u]=1;
	R int mx=0;
	go(u)if(v!=fa){
		dfs(v,u,dis+e[i].w),sz[u]+=sz[v];
		res+=1ll*min(sz[v],n-sz[v])*e[i].w<<1;
		if((sz[v]<<1)==n)op=1,rv=e[i].w;
		cmax(mx,sz[v]);
	}
	cmax(mx,n-sz[u]);
	if(cmin(mmx,mx))rt=u;
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n),mmx=n+1;
	for(R int i=1,u,v,w;i<n;++i){
		scanf("%d%d%d",&u,&v,&w);
		add(u,v,w),add(v,u,w);
	}
	dfs(1,0,0);
	if(op&1)res-=rv;
	else{
		R int mn=0x3f3f3f3f;
		go(rt)cmin(mn,e[i].w);
		res-=mn;
	}
	printf("%lld\n",res);
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    long long sum = 0;
    for (int i = 1; i < n + 1; i++)
    {
        if (!(i % 3 == 0 || i % 5 == 0))
        {
            sum += i;
        }
    }
    cout << sum;

    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
const lint MOD = pow(10, 9) + 7;

int main() {
	lint N, K;
	cin >> N >> K;
	lint ans = 1;
	ans *= K;
	rep(i, N - 1) {
		ans *= (K - 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
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;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

//for(i=0; i<N; i++) cin >> a[i];


ll H, W;
ll sx, sy, gx, gy;
ll d[1111][1111];
ll clr[1111][1111];
string s[1111];

void solve() {
  ll i, j, k;
  priority_queue<pair<ll, pll>> q;
  
  for(i=0; i<H; i++) for(j=0; j<W; j++) d[i][j]=INF;
  d[sx][sy]=0;
  q.push(make_pair(0, pll(sx, sy)));
  
  while(q.size()) {
    ll x=q.top().sc.ft;
    ll y=q.top().sc.sc;
    ll u=-q.top().ft;
    q.pop();
    
    if(clr[x][y]) continue;
    clr[x][y]=1;
    
    for(i=-2; i<=2; i++) {
      for(j=-2; j<=2; j++) {
        ll tx=x+i, ty=y+j;
        if(tx<0 || tx>=H || ty<0 || ty>=W) continue;
        if(s[tx][ty]=='#') continue;
        if(clr[tx][ty]) continue;
        
        if(abs(i)<=1 && abs(j)<=1 && abs(i+j)==1) {
          q.push(make_pair(-u, pll(tx, ty)));
          chmin(d[tx][ty], u);
        }else {
          q.push(make_pair(-u-1, pll(tx, ty)));
          chmin(d[tx][ty], u+1);
        }
        
      }
    }
    
  }
  
}


int main(void) {
  ll i, j, k;
  
  
  cin >> H >> W;
  cin >> sx >> sy >> gx >> gy;
  sx--; sy--; gx--; gy--;
  for(i=0; i<H; i++) cin >> s[i];
  
  solve();
  if(d[gx][gy]==INF) pt(-1);
  else pt(d[gx][gy]);
  
}
 
 




Measured memory_bytes: 24012
import collections as c

N = int(input())
A = list(map(int, input().split()))
S = [0]
tmp = 0

for i in range(N):
	tmp += A[i]
	S.append(tmp)

ans = 0
SS = c.Counter(S)
for v in list(SS.values()):
	if v >= 2:
		ans += v * (v-1) // 2

print(ans)

Measured memory_bytes: 41696
#include<cstdio>
int main() {
    int A,B,C;
    scanf("%d%d%d", &A,&B,&C);
    int Ans = 0;
    while(Ans < 99) {
        if(A&1 || B&1 || C&1) break;
        int D=B+C, E=A+C, F=A+B;
        A=D/2, B=E/2, C=F/2;
        ++Ans;
    }
    printf("%d", Ans<99?Ans:-1);
    return 0;
}
//

Measured memory_bytes: 1728
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            map.merge(a, 1, Integer::sum);
        }
        int ans = map.keySet().size();
        if (ans % 2 == 0) {
            System.out.println(ans - 1);
        } else {
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 50452
#include<stdio.h>

#define N 8
#define FREE -1
#define NOTFREE -2
#define FALSE 0
#define TRUE 1

int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
int X[N][N];

void printboard(void);
void recursive(int);

int main(){
  int i,j,n,r,c;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&r,&c);
    X[r][c] = TRUE;
  }

  recursive(0);

  return 0;
}

void printboard(){
  int i,j;

  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      if(X[i][j] == TRUE){
	if(row[i] != j)return;
      }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i] == j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;

  if(i == N){
    printboard();
    return;//配置に成功
  }

  for(j=0;j<N;j++){
    if(NOTFREE == col[j] ||
       NOTFREE == dpos[i+j] ||
       NOTFREE == dneg[i-j+N-1])continue;//(i,j)が他のクイーンの可動域の場合はそのまま
   
    row[i] =j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOTFREE;//(i,j)にクイーンを配置
    
    recursive(i+1); //次の行について再帰
    
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;//配置に失敗したのでfor文でやり直し
  }
}



Measured memory_bytes: 2108
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define fir fisrt
#define sec second

int n, m, a[200050], b[200050];
bool pre[200050], last[200050];

int main(){
	scanf(" %d %d", &n, &m);
	for(int i = 1; i <= m; i ++){
		scanf(" %d %d", &a[i], &b[i]);
		if(a[i] == 1 && b[i] != n) pre[b[i]] = 1;
		if(b[i] == n && a[i] != 1) last[a[i]] = 1;
	}
	bool vis = 0;
	for(int i = 2; i <= n - 1; i ++){
		if(pre[i] == 1 && last[i] == 1){
			vis = 1;
		}
	}
	if(vis == 0) printf("IMPOSSIBLE\n");
	else printf("POSSIBLE\n");
}

Measured memory_bytes: 2176
let cnt = ref 0

let merge a l m r =
  let ni = m - l in
  let ai = Array.make (ni + 1) max_int in
  for i = 0 to ni - 1 do
    ai.(i) <- a.(l + i)
  done;
  let aj = Array.make (r - m + 1) max_int in
  for i = 0 to r - m - 1 do
    aj.(i) <- a.(m + i)
  done;
  let i = ref 0 in
  let j = ref 0 in
  for k = l to r - 1 do
    if ai.(!i) <= aj.(!j) then begin
      a.(k) <- ai.(!i);
      incr i;
    end else begin
      a.(k) <- aj.(!j);
      cnt := !cnt + (ni - !i);
      incr j;
    end
  done

let merge_sort a l r =
  let rec doit l r =
    if (l + 1) < r then begin
      let m = (l + r) / 2 in
      doit l m;
      doit m r;
      merge a l m r
    end in
  doit l r

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  merge_sort a 0 n;
  Printf.printf "%d\n" !cnt

Measured memory_bytes: 11584
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <string>
#include <stack>
#include <set>
#include <vector>

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const double EPS = 1e-10;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
    return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
    os<<'[';
    rep(i,a.size()) os<<(i?" ":"")<<a[i];
    return os<<']';
}

const int MAX_V = 100;
const int INF = 987654321;

typedef int weight;
struct edge { int from, to; weight cost; };
bool operator>(const edge & a, const edge & b) { return a.cost > b.cost; };
int V;
vector<edge> adj[MAX_V];

pair<weight, vector<edge> > prim() {
	priority_queue<edge, vector<edge>, greater<edge> > que;
	que.push((edge){-1, 0, 0});
	bool visited[MAX_V];
    fill(visited, visited + V, false);
	vector<edge> tree;
	weight wgh = 0;
	while (!que.empty()) {
		edge e = que.top();
		que.pop();
		if (visited[e.to]) continue;
		visited[e.to] = true;
		if (e.from >= 0) {
			tree.pb(e);
			wgh += e.cost;
		}
		tr(i, adj[e.to]) que.push(*i);
	}

	return mp(wgh, tree);
}

int main() {
    for(int n, m; cin >> n >> m, (n | m) != 0;) {
        rep(i, MAX_V) adj[i].clear();
        rep(i, m) {
            int a, b, cost; cin >> a >> b >> cost;
            adj[a].pb((edge){a, b, cost});
            adj[b].pb((edge){b, a, cost});
        }
        V = n;
        cout << prim().fst << endl;
    }

    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) (int)s.size()
#define all(v) v.begin(),v.end()
#define mii map<int,int>
#define mr  make_pair

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
//int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
       int n,w;
       cin>>n>>w;
       int val[n],wt[n];
       int sum = 0;
       rep(i,0,n)
       {
           cin>>wt[i]>>val[i];
           sum+= val[i];
       }
       vi dp(sum+1,inf);
       dp[0] = 0;
       for(int i=0;i<n;++i)
       {
           for(int j=sum;j>=val[i];--j)
           {
               dp[j] = min(dp[j],dp[j-val[i]]+wt[i]);
           }
       }
       int ans = 0;
       rep(i,0,sum+1)
       {
           if(dp[i]<=w)
            ans = i;
       }
       cout<<ans<<el;


    }
    return 0;
}


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

class Main{
	public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
for(;;){
	int x =sc.nextInt();
	int h =sc.nextInt();
	if(x==0) break;
	
	double ok = x*x+x*Math.sqrt(x*x+h*h*4.0);
	System.out.println(ok);
}
	}
	}

Measured memory_bytes: 15348
import bisect
import collections
import itertools


def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

n,m=getints()
xs=getints()
xs=list(sorted(xs))

spaces=[]
for i in range(m-1):
    spaces.append(xs[i+1]-xs[i])

spaces = list(sorted(spaces))

for i in range(n-1):
    if spaces: spaces.pop()

print(sum(spaces))


Measured memory_bytes: 59176
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>

#define REP(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;

int main() {
    int n;
    scanf("%d", &n);
    vi a(n);
    REP(i, 0, n) {
        scanf("%d", &a[i]);
    }
    map<int, int> mp;
    int ans=0;
    set<int> isLooked;

    REP(i, 0, n) {
        if (mp.find(a[i]) == mp.end()) {
            mp[a[i]] = 1;
        } else {
            mp[a[i]] = mp[a[i]] + 1;
        }
    }

    REP(i, 0, n) {
        if (isLooked.find(a[i]) == isLooked.end()) {
            if (a[i] <= mp[a[i]]) {
                ans += mp[a[i]] - a[i]; 
            } else {
                ans += mp[a[i]];
            }
            isLooked.insert(a[i]);
        } 
    }
 
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 9600
N = int(input())
h = list(map(int, input().split()))
dp = [0] + [1000000000] * (N-1)

for i in range(N-1):
	if i < N-2:
		dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]))

	dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]))
	
print(dp[N-1])

Measured memory_bytes: 13924