akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// 素因数分解
vector<pair<ll,ll>> prime_factorize(ll n){
    vector<pair<ll,ll>> res;
    for(ll p=2;p*p<=n;p++){
        if(n%p!=0) continue;
        int num=0;
        while(n%p==0){
            num++;
            n/=p;
        }
        res.push_back(make_pair(p,num));
    }
    if(n!=1) res.push_back(make_pair(n,1));
    return res;
}

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<1000000007>;


int main(){
    int n;
    cin>>n;
    ll a[n];
    rep(i,n) cin>>a[i];

    vector<ll> num(1100000,0);
    rep(i,n){
        auto pf=prime_factorize(a[i]);
        for(auto p : pf) num[p.first]=max(num[p.first],p.second); 
    }

    mint LCM=1;
    for(int v=2;v<1100000;v++){
        LCM*=modpow(mint(v),num[v]);
    }

    mint res=0;
    rep(i,n){
        res+=LCM/a[i];
    }

    cout<<res<<endl;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
#define all(v) v.begin(),v.end()


ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll>a(n);
    vector<ll>rp;
    vector<bool>done(n+1,false);
    vector<bool>ck(n+1,false);
    rep(i,n) cin >> a[i];
    vector<ll>place(310000);
    place[0]=1;
    rep(i,300000){
        place[i+1]=a[place[i]-1];
    }

    rep(i,300000){
        if(done[place[i]]){
            if(ck[place[i]]) break;
            rp.push_back(place[i]);
            ck[place[i]]=true;
        } 
        else done[place[i]]=true;
    }
    if(k<=300000){
        cout << place[k] <<endl;
    }
    else{
        ll cnt=0;
        rep(i,300000){
            if(place[i]!=rp[0]) cnt++;
            else break;
        }
        k-=cnt;
        ll r=k%rp.size();
        cout << rp[r] <<endl;
    }
    return 0;
}



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

using namespace std;

const int maxn=1e5+5,mod=1e9+5;

typedef long long ll;

int main()
{
    int n,r;
    while(scanf("%d%d",&n,&r)!=EOF)
    {
       if(n<10)
        printf("%d\n",r+100*(10-n));
       else
        printf("%d\n",r);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  int n;
  cin >> n;
  vector<vector<int>> a(2, vector<int>(n));
  for (int i = 0; i < n; i++){
    cin >> a[0][i];
  }
  for (int i = 0; i < n; i++){
    cin >> a[1][i];
  }

  int m = 0, sum = 0;

  sum += a[0][0];
  for (int i = 0; i < n; i++){
    sum += a[1][i];
  }

  m = sum;

  for (int i = 1; i < n; i++){
    sum += a[0][i] - a[1][i-1];
    m = max(sum, m);
  }

  cout << m << endl;

  return 0;
}


ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 256
#include<stdio.h>

int m[10][10], 
    dx[13] = {0, 0, 1, 0, -1, 1, 1, -1, -1, 0, 2, 0, -2},
    dy[13] = {0, -1, 0, 1, 0, -1, 1, -1, 1, -2, 0, 2, 0};

void drop(int x, int y)
{
  if(x < 0 || x >= 10 || y < 0 || y >= 10)
    return;
  m[y][x]++;
}

int main()
{
  int x, y, s, i, a1 = 0, a2 = 0;
  while(scanf("%d,%d,%d", &x, &y, &s) != -1)
  {
    for(i = 0; i < 5; i++)
      drop(x + dx[i], y + dy[i]);
    if(s == 1)
      continue;
    for(; i < 9; i++)
      drop(x + dx[i], y + dy[i]);
    if(s == 2)
      continue;
    for(; i < 13; i++)
      drop(x + dx[i], y + dy[i]);
  }
  for(y = 0; y < 10; y++)
  {
    for(x = 0; x < 10; x++)
    {
      if(a1 < m[y][x])
        a1 = m[y][x];
      if(!m[y][x])
        a2++;
    }
  }
  printf("%d\n%d\n", a2, a1);
  return 0;
}

Measured memory_bytes: 600
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


#print(gcd(8, 20))
K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            a = gcd(i, j)
            ans += gcd(a, k)
print(ans)



Measured memory_bytes: 68872
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:usize,
    b:[usize;a],
    }
    let mut v=1;
    for i in 0..a {
        if b[i]%2==0{v*=2}
    }
    println!("{}",3.pow(a as u32)-v)
}

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

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

const long long INF = 1LL << 60;
long long h[100010];

// DP テーブル
long long dp[100010];

int main ()
{
    int n,k;  cin >> n >> k;
    for(int i=1;i<=n;i++){
       cin >> h[i];
       
    }
    for(int i=1;i<=100010;i++) dp[i]=INF;

    dp[1]=0;
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=k;j++){
            
        dp[i+j]=min(dp[i]+abs(h[i]-h[i+j]),dp[i+j]);
        
        }
    }
    cout << dp[n] << endl;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
  
int const INF = 100 + (int) 1e9;
ll const INFL = 100 + (ll) 1e18;
  
int const size = 1e5 + 100;
int co[size];
int a[size];

int main() {
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	cin >> a[i];
    	co[a[i]]++;
    }	
    int maxco = 1;
    for (int i = 0; i < size; i++) {
    	if (i > 0 && co[i] + co[i-1] + co[i+1] > maxco)
    		maxco = co[i] + co[i-1] + co[i+1];
    	else if (i == 0 && co[i] + co[i+1] > maxco)
    		maxco = co[i] + co[i+1];
    }
    cout << maxco << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
  int i,N,A,B;
  cin >> A >> B;
  if (A >=13) {
    cout << B << endl;
  } else if (A>=6) {
    cout << B/2 << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
  string A,B,C; cin >> A >> B >> C;
  int turn=1; char ans;
  while(true){
    if(turn==1){
      if(A[0]=='a') turn=1;
  	  else if(A[0]=='b') turn=2;
  	  else if(A[0]=='c') turn=3;
      else{ans='A'; break;}
      A.erase(A.begin());
    }
    else if(turn==2){
      if(B[0]=='a') turn=1;
  	  else if(B[0]=='b') turn=2;
  	  else if(B[0]=='c') turn=3;
      else{ans='B'; break;}
      B.erase(B.begin());
    }
    else if(turn==3){
      if(C[0]=='a') turn=1;
  	  else if(C[0]=='b') turn=2;
  	  else if(C[0]=='c') turn=3;
      else{ans='C'; break;}
      C.erase(C.begin());
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n;
int a[maxn], b[maxn], A[maxn], B[maxn];
typedef pair<int, int> pii;
#define mp(a, b) make_pair(a, b);
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) 
		scanf("%d%d", &a[i], &b[i]);
	sort(a + 1, a + n + 1);
	sort(b + 1, b + n + 1);
	if(n & 1) cout << b[n / 2 + 1] - a[n / 2 + 1] + 1 << endl;
	else cout << (b[n / 2 + 1] + b[n / 2] - a[n / 2 + 1] - a[n / 2]) + 1 << endl;
	return 0;
}

Measured memory_bytes: 5216
data = $<.map{|l|l.split.map(&:to_i)}

a1 = b1 = 0
a2 = b2 = 1
a3 = b3 = 2

b1_b2_a = data[a1][b1]-data[a1][b2]
b1_b2_b = data[a2][b1]-data[a2][b2]
b1_b2_c = data[a3][b1]-data[a3][b2]
b2_b3_a = data[a1][b2]-data[a1][b3]
b2_b3_b = data[a2][b2]-data[a2][b3]
b2_b3_c = data[a3][b2]-data[a3][b3]

puts b1_b2_a==b1_b2_b && b1_b2_a==b1_b2_c && b2_b3_a==b2_b3_b && b2_b3_a==b2_b3_c ? "Yes" : "No"


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

using namespace std;

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

    vector<int> b(N, 0);
    vector<int> tmp(N, 0);

    for(int i = 0; i < N; i++) {
        cin >> b[i];
    }

    int now = -1;
    for(int i = N-1; i >= 0; i--) {
        for(int j = i; j >= 0; j--) {
            if(b[j] == (j+1) ) {
                //cout << j << ":" << j+1 << endl;
                tmp[i] = j+1;
                //cout << tmp[tmp.size() - 1] << endl;
                b.erase(b.begin() + j);
                break;
            }
            if(j == 0) {
                cout << "-1" << endl;
                return 0;
            }
        }
    }
    for(int i =0 ; i < N; i++) cout << tmp[i] << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using namespace std;

int main() {
    while (true) {
        int n; scanf("%d", &n);
        if (n == 0) break;
        vector<int> a(n); repeat (i, n) scanf("%d", &a[i]);
        whole(sort, a);
        int result = (whole(accumulate, a, 0) - a.front() - a.back()) / (n - 2);
        printf("%d\n", result);
    }
    return 0;
}

Measured memory_bytes: 2628
import scala.io.StdIn

object Main {

  def main(args: Array[String]): Unit = {
    val Array(w, h, x, y, r) = StdIn.readLine.split(" ").map(_.toInt)

    if (h >= y + r && y - r >= 0 && w >= x + r && x - r >= 0) println("Yes")
    else println("No")
  }
}

Measured memory_bytes: 43944
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    cout << a / b << " " << a % b << " ";
    cout << fixed << setprecision(10) << (double)a / b << "\n";

    return 0;
}


Measured memory_bytes: 3284
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,L;
    cin >> N >> L;
    if(L>=1)cout << (L-1)*(N-1)+N*(N+1)/2-1 << endl;
    else{
        int ans=L;
        int sum=(L-1)*N+N*(N+1)/2;
        for(int i=2;i<N+1;i++){
            if(abs(ans)>abs(L-1+i))ans=L-1+i;
        }
        cout << sum-ans << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		Double A = sc.nextDouble();
		Double B = sc.nextDouble();
		Double H = sc.nextDouble();
		Double M = sc.nextDouble();      
		Double R = Math.abs( (H*30+M*0.5) - (M*6) );
		if( R>180 ){
			R = 360-R;          
        }          
		Double ans = A*A + B*B - 2*A*B * Math.cos(Math.toRadians(R));
		System.out.println(Math.sqrt(ans));    
	}
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int X; cin >> X;
    int fh, fv;
    fh = (X - X%500)/500;
    X -= fh*500;
    fv = (X - X%5)/5;
    cout << fh*1000 + fv*5 << endl;
    return 0;
}

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

int main()
{
    int n, i;

    cin >> n;

    int a[n + 5];

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

    int k = 1;

    for(i = 0; i < n; i++){
        if(a[i] == k) k++;
    }

    if(k == 1) cout << -1 << endl;
    else cout << n - k + 1 << endl;

    return 0;
}


Measured memory_bytes: 1024
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;

void main(){
	auto N = readln.chomp.to!int;
	auto tanda = readln.split.to!(int[]);
	auto T = tanda[0];
	auto ideal = tanda[1];
	auto H = readln.split.to!(int[]);
	real X = real.max;
	int count;
	int result;

	foreach(i; H){
		count++;
		auto difference = abs(T - i * 0.006 - ideal);
		if(difference < X){
			X = difference;
			result = count;
		}
	}
	writeln(result);
}

//writeln("滲み出す混濁の紋章　不遜なる狂気の器　湧き上がり　否定し　痺れ　瞬き　眠りを妨げる　爬行する鉄の王女　絶えず自壊する泥の人形　結合せよ　反発せよ　地に満ち己の無力を知れ　破道の九十　黒棺")

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

int main(){
  //cout<<123<<endl;
  int N,A,B;
  cin>>N>>A>>B;
  int p[N+12];
  for(int i=1;i<=N;i++){
    cin>>p[i];
  }
  int cnt1=0;
  int cnt2=0;
  int cnt3=0;
  for(int i=1;i<=N;i++){
    if(p[i]<=A) cnt1++;
    else if(p[i]<=B){
      cnt2++;
    } else cnt3++;
    
   
    
  }
  
   int ans = min(cnt1,min(cnt2,cnt3));
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
#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((a+b+c) >= 22) cout << "bust" << endl;
  	else cout << "win" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Solve{
	public int s[];
	public int t[];
	public int count;
	public void binary(int left,int right,int num){
		int mid = (left + right) / 2;
		if(right - left <= 1) {
			if(s[right] == num || s[left] == num) count++;
		}
		else if(s[mid] == num) count++;
		else if(s[mid] < num) binary(mid,right,num);
		else binary(left,mid,num);
	}
}

class Main{//一部全探索の問題のコードを使用
	public static void main(String[] args) 	{
		Scanner sc = new Scanner(System.in);
		Solve sv = new Solve();
		//prepare s
		int n = sc.nextInt();
		sv.s = new int[n];
		for(int i = 0;i < n;i++) {
			sv.s[i] = sc.nextInt();
		}
		//prepare t
		int q = sc.nextInt();
		sv.t = new int[q];
		for(int i = 0;i < q;i++) {
			sv.t[i] = sc.nextInt();
		}
		//find and count
		sv.count = 0;
		for(int i = 0;i < q;i++) {
			sv.binary(0,n - 1,sv.t[i]);
		}
		//print
		System.out.printf("%d\n",sv.count);
		sc.close();
	}
}


Measured memory_bytes: 68148
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

long long kMod = 1e9 + 7;

void print_matrix(const vector<vector<int>>& matrix)
{
  int h = matrix.size();
  int w = matrix.at(0).size();
  for (int x = 0; x < h; x++) {
    for (int y = 0; y < w; y++) {
      cout << ' ' << matrix.at(x).at(y);
    }
    cout << '\n';
  }
}

int main()
{
  string s;
  cin >> s;
  reverse(s.begin(), s.end());

  vector<vector<long long>> digit(s.size(), vector<long long>(10));
  for (long long i = 0; i < 10; i++) {
    digit.at(0).at(i) = i;
  }
  for (long long i = 1; i < (long long)digit.size(); i++) {
    for (long long d = 1; d < 10; d++) {
      digit.at(i).at(d) = (digit.at(i-1).at(d) * 10) % 13;
    }
  }

  vector<vector<long long>> dp(s.size(), vector<long long>(13));
  if (s.front() == '?') {
    for (long long i = 0; i < 10; i++) {
      dp.at(0).at(i) = 1;
    }
  } else {
    long long x = s.front() - '0';
    dp.at(0).at(x) = 1;
  }
  for (long long i = 1; i < (long long)s.size(); i++) {
    char c = s.at(i);
    if (c == '?') {
      for (long long x = 0; x < 10; x++) {
        for (long long r = 0; r < 13; r++) {
          long long next_r = (r + digit.at(i).at(x)) % 13;
          dp.at(i).at(next_r) += dp.at(i-1).at(r);
          dp.at(i).at(next_r) %= kMod;
        }
      }
    } else {
      long long x = c - '0';
      for (long long r = 0; r < 13; r++) {
        long long next_r = (r + digit.at(i).at(x)) % 13;
        dp.at(i).at(next_r) += dp.at(i-1).at(r);
        dp.at(i).at(next_r) %= kMod;
      }
    }
  }
  cout << dp.back().at(5) << '\n';

  //cout << '\n';
  //print_matrix(digit);
  //cout << '\n';
  //print_matrix(dp);
  return 0;
}


Measured memory_bytes: 25472
x,y=map(int,input().split())
if (x+y)%3:
    print(0)
    exit()
x,y=min(x,y),max(x,y)
sa=y-x
wa=y+x
z=(x+y)//3
if sa>x:
    print(0)
    exit()


mod=10**9+7
fact=[1]
fact_inv=[1]
for i in range(10**6+5):
    new_fact=fact[-1]*(i+1)%mod
    fact.append(new_fact)
    fact_inv.append(pow(new_fact,mod-2,mod))

def mod_comb(n,k,mod):
    return fact[n]*fact_inv[k]%mod*fact_inv[n-k]%mod

print(mod_comb(z,x-z,mod))


Measured memory_bytes: 108056
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define ll long long
#define faltu ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define binary(x) std::string binary = std::bitset<25>(x).to_string(); //to binary
#define inf 1000000007
#define mod 1000000007
#define pi pair<int,int>
#define lpi pair<int,int>
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define lvi vector<long long int>
#define pie 3.14159265358979323846
using namespace std;
ll cost[100005];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; i++) cin >> h[i];
    for (int i = 0; i < n; i++) cost[i] = 2000000000;
    cost[0] = 0;
    for (int i = 1; i < n; i++) {
        cost[i] = min(cost[i], cost[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) cost[i] = min(cost[i], cost[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << cost[n - 1];
    return 0;
}





Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC085B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] dn = new int[n];
            for (int i = 0; i < n; i++)
            {
                dn[i] = int.Parse(Console.ReadLine());
            }

            dn = dn.OrderBy(x => x).ToArray();

            int j = 1;

            for (int i = 0; i < n-1; i++)
            {
                if (dn[i+1]-dn[i]>0)
                {
                    ++j;
                }
            }

            Console.WriteLine("{0}", j);
            Console.Read();
        }
    }
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

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

  int count = 0;
  rep(i, n-2){
    if(s.at(i)=='A'&&s.at(i+1)=='B'&&s.at(i+2)=='C') count++;
  }

  cout << count;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        //bytesのiterを生成
        .bytes()
        //それをas charでchar型に変換したiterを生成
        .map(|c| c.expect("failed to read char") as char)
        //c.is_whitespace()がfalseになるまで（つまり普通の文字が出るまで）iterを進めたiterを生成
        .skip_while(|c| c.is_whitespace())
        // !c.is_whitespace()がtrue, 即ち（普通の文字の間）iterを進め, 進んだところまでのiterを生成
        .take_while(|c| !c.is_whitespace())
        // それをcollect()してiterからStringを作る
        .collect();
    // parse()で任意の型に変換して返す。
    token.parse().ok().expect("failed to parse token")
}

fn read_one_line_to_vec() -> Vec<i32> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let v: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c == &'\x0d' || c == &'\x0a')
        .take_while(|c| !(c == &'\x0d' || c == &'\x0a'))
        .collect();
    v.split_whitespace()
        .map(|c| { let string = c.to_string();
            string.parse::<i32>().unwrap()})
        .collect()
}

fn main() {
    // Bubble Sort

    let _length:i32 = read();
    let mut a = read_one_line_to_vec();
    let mut count = 0;
    for i in 0..a.len() {
        for j in (i+1..a.len()).rev() {
            if a[j] < a[j-1] {
                a.swap(j, j-1);
                count += 1;
            }
        }
    }
    print_vec(a);
    println!("{}", count);
}

fn print_vec(v: Vec<i32>) {
    let mut v_iter = v.iter();
    print!("{}", v_iter.next().as_ref().unwrap());
    for v in v_iter {
        print!(" {}", v)
    }
    println!();
}



Measured memory_bytes: 5028
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//BEGIN CUT HERE
template<typename T>
struct VoronoiMST{
  int n;
  using E = pair<int, T>;
  using P = pair<T, int>;
  vector<vector<E> > G;
  VoronoiMST(vector<T> &x){
    n=x.size();
    G.assign(n<<1,vector<E>());
    for(int i=0;i<n;i++) G[i].emplace_back(n+i,x[i]);
  }
  void add_edge(int u,int v,T c){
    G[u+n].emplace_back(v+n,c);
    G[v+n].emplace_back(u+n,c);
  }  
  vector<vector<E> > build(){
    priority_queue<P, vector<P>, greater<P> > pq;
    const T INF = numeric_limits<T>::max();    
    vector<T> dist(n<<1,INF);
    vector<int> from(n<<1,-1);
    for(int i=0;i<n;i++){
      dist[i]=0;from[i]=i;
      pq.emplace(dist[i],i);
    }
    while(!pq.empty()){
      T d;
      int v;
      tie(d,v)=pq.top();pq.pop();
      if(dist[v]<d) continue;
      for(E e:G[v]){
        int u=e.first;
        T c=e.second;
        if(dist[u]<=dist[v]+c) continue;
        dist[u]=dist[v]+c;
        from[u]=from[v];
        pq.emplace(dist[u],u);
      }
    }
    vector<vector<E> > H(n);
    for(int v=0;v<(n<<1);v++){
      for(E e:G[v]){
        int u=e.first;
        T c=e.second;
        if(from[v]==from[u]) continue;
        int x=from[v],y=from[u];
        T z=dist[v]+dist[u]+c;
        H[x].emplace_back(y,z);
        H[y].emplace_back(x,z);
      }
    }
    return H;
  }
};
//END CUT HERE



template<typename T>
struct Kruskal{
  
  struct edge{
    int from,to;
    T cost;
    int used;
    edge(){}
    edge(int from,int to,T cost):
      from(from),to(to),cost(cost),used(0){}
    bool operator<(const edge& e) const{
      return cost<e.cost;
    }
  };

  int n;
  vector<int> p,r;
  vector<edge> edges;

  Kruskal(){}
  Kruskal(int n):n(n){}

  void init(int n){
    r.assign(n,1);
    p.resize(n);
    iota(p.begin(),p.end(),0);
  }
  
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }

  bool same(int x,int y){
    return find(x)==find(y);
  }

  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }

  void add_edge(int u,int v,T c){
    edges.emplace_back(u,v,c);
  }
  
  T build(){
    sort(edges.begin(),edges.end());
    init(n);
    T res=0;
    for(auto &e:edges){
      if(!same(e.from,e.to)){
        res+=e.cost;
        unite(e.from,e.to);
        e.used=1;
      }
    }
    return res;
  }
};


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE

signed main(){
  int n;
  cin>>n;
  vector<Int> x(n);
  for(int i=0;i<n;i++) cin>>x[i];
  VoronoiMST<Int> vo(x);
  for(int i=1;i<n;i++){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    vo.add_edge(a,b,c);
  }
  auto G=vo.build();
  Kruskal<Int> ks(n);
  for(int v=0;v<n;v++){
    for(auto e:G[v]){
      int u=e.first;
      Int c=e.second;
      ks.add_edge(v,u,c);
    }
  }
  cout<<ks.build()<<endl;
  return 0;
}


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

int main() {
  	int N;
   	cin >> N;
  	long long int count = 0;
  
  	for (int i = 1; i <= N; i++){
      	if (i % 3 == 0) continue;
      	if (i % 5 == 0) continue;
      
      	count += i;
    }
  
  	cout << count << endl;
}

Measured memory_bytes: 3636
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()

print((pow(10,n,mod)-2*pow(9,n,mod)+pow(8,n,mod))%mod)

Measured memory_bytes: 68272
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let h: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut g: Vec<Vec<usize>> = vec![Vec::new(); n + 1];
    for _ in 0..m {
        let a: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let b: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        g[a].push(b);
        g[b].push(a);
    }

    let mut ans = 0;
    for i in 0..n {
        let mut ok = true;
        for &j in g[i].iter() {
            if h[i] <= h[j] {
                ok = false;
            }
        }
        if ok {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 10688
import numpy as np

#A = list(map(int,input().split()))

N = int(input())
A = list(map(int,input().split()))


ans = 0
mod = 10**9 + 7
s = 0

for i in range(N):
    s += A[i]
    s = s%mod

for i in range(N-1):
    s = (s-A[i])%mod
    ans += (A[i] * s)%mod
    ans = ans % mod

print(ans%mod)


Measured memory_bytes: 49668
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

const int64_t MOD = 1000000007;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);

    int n;
    std::string s1, s2;
    cin >> n >> s1 >> s2;
    int64_t result = 0;

    int pos = 0;
    bool is_vert;
    if (s1[0] == s2[0]) {
        result  = 3;
        pos     = 1;
        is_vert = true;
    } else {
        result  = 6;
        pos     = 2;
        is_vert = false;
    }
    while (pos < n) {
        if (s1[pos] == s2[pos]) {
            if (is_vert) {
                result *= 2;
            } else {
                result *= 1;
            }
            pos++;
            result %= MOD;
            is_vert = true;
        } else {
            if (is_vert) {
                result *= 2;
            } else {
                result *= 3;
            }
            pos += 2;
            result %= MOD;
            is_vert = false;
        }
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
w,h,n=map(int,input().split())
i,j=0,0
for _ in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        i=max(i,x)
    elif a==2:
        w=min(w,x)
    elif a==3:
        j=max(j,y)
    else:
        h=min(h,y)
print((w-i)*(h-j) if w>i and h>j else 0)


Measured memory_bytes: 9184
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int H = sc.nextInt();
			int W = sc.nextInt();

			if (H == 0 && W == 0) {
				break;
			}
			
			for(int i=0; i<H; i++) {
				for(int j=0; j<W; j++) {
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
			
		}
	}
}



Measured memory_bytes: 34828
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
//template <class Type>
 
 
void Fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
}
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
 
 
ll MOD=1e9 + 7;
ll OO=1e6;  
const int N=2e3 + 2;
ll arr[N];
bool visit[N];

ll n,m,k,cnt,SU,idx,len,MN,MX,T;
ll l,r,mid;
ll a,b,c,d;

vector<int> adj[N];

void BFS(int u){
	memset(visit,0,sizeof visit);
	visit[u]=true;
	queue<pair<int,int>> q;
	q.push({u,0});
	while(SZ(q)){
		pair<int,int> p=q.front();
		int Node=p.first;
		int len=p.second;
		q.pop();

		for(int i:adj[Node]){
			if(!visit[i]){
				visit[i]=true;
				++arr[len+1];
				q.push({i,len+1});
			}
		}

	}

}



int main(){
	
	cin>>n>>a>>b;
	adj[a].push_back(b);
	adj[b].push_back(a);
	for(int i=1;i<n;++i){
		adj[i].push_back(i+1);
		adj[i+1].push_back(i);
	}
		

	for(int i=1;i<=n;++i)
		BFS(i);
	
		
	
	for(int i=1;i<n;++i)
		cout<<arr[i]/2<<endl;
	
}
 
 
 
 
 
 
 
 


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#ifndef ONLINE_JUDGE
	#define ONLINE_JUDGE
#endif

#define MAX(x,y) ((x)>(y)?(x):(y))
#define MIN(x,y) ((x)<(y)?(x):(y))
#define pb push_back
#define mp make_pair
#define rep(i,n) for(i=0;i<n;i++)
#define repr(i,j,n) for(i=j;i<=n;i++)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<int> > graph;
const ll maxn = (ll) 1e5+9;
const ll mod = (ll) 1e9+7;
//ll a[maxn];
bool d[20];
//ll dp[1024][1024];
string s;
string dig = "0123456789";
int main()
{
	std::ios::sync_with_stdio(0);
	ll i,j,k,t,q,m,l,r,n;
	cin>>s>>k;
	//ans=s;
	repr(i,1,k){cin>>j;d[j]=true;}
	bool f=1;
	for(i=s.size()-1;i>=0;i--) {
		if(f==0) {
			repr(t,(s[i]-'0')+1,9) {
				if(d[t]==false) {
					f=1;
					s[i]=dig[t];
					repr(t,i+1,s.size()-1) {
						repr(q,0,9) {
							if(d[q]==false) {
								s[t]=dig[q];
								break;
							}
						}
					}
					break;
				}
			}
		}
		if(d[s[i]-'0']==true) {
			repr(j,(s[i]-'0')+1,9) {
				if(d[j]==false) {
					f=1;
					s[i]=dig[j];
					repr(t,i+1,s.size()-1) {
						repr(q,0,9) {
							if(d[q]==false) {
								s[t]=dig[q];
								break;
							}
						}
					}
					break;
				}
			}
			if(d[s[i]-'0']==true) {
				repr(j,0,(s[i]-'0')-1) {
					if(d[j]==false) {
						f=0;
						s[i]=dig[j];
						break;
					}
				}
			}
		}
	}
	if(!f) {
		repr(j,1,9) {
			if(d[j]==false) {
				repr(t,0,s.size()-1) {
					repr(q,0,9) {
						if(d[q]==false) {
							s[t]=dig[q];
							break;
						}
					}
				}
				s=dig[j]+s;
				break;
			}
		}
	}
	cout<<s<<endl;
}

Measured memory_bytes: 256
import sys


def solve():
    A, B, C, K = map(int, input().split())
    if A > K:
        print(K)
        sys.exit(0)
    elif A+B >= K:
        print(A)
        sys.exit(0)
    else:
        print(A-(K-A-B))
        sys.exit(0)


solve()


Measured memory_bytes: 61656
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int main(){
    ll N,W;
    cin>>N>>W;
    vector<ll> q1,q2,q3,q4;
    ll w0,v0;
    cin>>w0>>v0;
    q1.push_back(v0);
    for(int i=1;i<N;i++){
        ll w,v;
        cin>>w>>v;
        if(w==w0)   q1.push_back(v);
        if(w==w0+1) q2.push_back(v);
        if(w==w0+2) q3.push_back(v);
        if(w==w0+3) q4.push_back(v);
    }
    sort(ALL(q1),greater<ll>());
    sort(ALL(q2),greater<ll>());
    sort(ALL(q3),greater<ll>());
    sort(ALL(q4),greater<ll>());
    vector<ll> s1,s2,s3,s4;
    s1.push_back(0);s2.push_back(0);
    s3.push_back(0);s4.push_back(0);
    for(int i=0;i<q1.size();i++) s1.push_back(s1[i]+q1[i]);
    for(int i=0;i<q2.size();i++) s2.push_back(s2[i]+q2[i]);
    for(int i=0;i<q3.size();i++) s3.push_back(s3[i]+q3[i]);
    for(int i=0;i<q4.size();i++) s4.push_back(s4[i]+q4[i]);
    ll ans=0;
    for(int i=0;i<s1.size();i++){
        for(int j=0;j<s2.size();j++){
            for(int k=0;k<s3.size();k++){
                for(int l=0;l<s4.size();l++){
                    if(i*w0+j*(w0+1)+k*(w0+2)+l*(w0+3)<=W) ans=max(ans,s1[i]+s2[j]+s3[k]+s4[l]);
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <stack>
#include <cstdint>
typedef long long int llint;

int main(void){
  int n;
  std::string s, t;
  std::cin >> n >> s >> t;

  for(int i=0; i<n; i++){
    std::cout << s[i] << t[i];
  }
  std::cout << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#define LL long long
using namespace std;
const int maxn = 1e5+10;
const double pi=acos(-1.0);

LL read(){
	LL x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}
struct node{
    LL x,y;
    double k;
}a[maxn];

int cmp(node a,node b){
	return a.k<b.k;
}

int main(){
    int m,n,now;
    LL nowx=0,nowy=0,ans=0;
    n=read();
    for(register int i=1;i<=n;i++){
		a[i].x=read();a[i].y=read();
		a[i].k=atan2(a[i].y,a[i].x);
		//cout<<a[i].x<<" "<<a[i].y<<" "<<a[i].k<<endl;
	}
	sort(a+1,a+n+1,cmp);
	for(register int i=1;i<=n;i++){
		a[i+n].x=a[i].x;
		a[i+n].y=a[i].y;
		a[i+n].k=a[i].k+pi*2;
	}
	now=1;
    for(register int i=1;i<=n;i++){
        while(now<i+n && a[now].k-a[i].k<pi){
			nowx+=a[now].x;
			nowy+=a[now].y;
			now++;
			ans=max(ans,nowx*nowx+nowy*nowy);
        }
		nowx-=a[i].x;nowy-=a[i].y;ans=max(ans,nowx*nowx+nowy*nowy);
    }
    printf("%.11lf\n" ,sqrt(ans));
    return 0;
}

Measured memory_bytes: 384
// abc078_a
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
  char x, y;
  cin >> x >> y;
  if(x < y) cout << "<" << endl;
  else if(x > y) cout << ">" << endl;
  else cout << "=" << endl;
  return 0;
}


Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

bool isKai(string S){
    string T = S;
    reverse(S.begin(), S.end());
    return T == S;
}

int main() {
    string S;
    cin >> S;
    int N = S.size();

    bool isOk1 = isKai(S);

    string S2 = S.substr(0, (N - 1) / 2);
    bool isOk2 = isKai(S2);

    string S3 = S.substr((N + 3) / 2 - 1); // 0-index
    bool isOk3 = isKai(S3);

    string ans = isOk1 && isOk2 && isOk3 ? "Yes" : "No";
    
    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;
typedef vector<vl> v2;
typedef vector<v2> v3;
typedef vector<v3> v4;


const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

bool judge(ll m, ll d){
  ll d1 = d%10;
  ll d2 = d/10;
  if(d1 >= 2 && d2 >= 2 && (m == d1*d2)) return true;
  else return false;
}

ll m,d;
ll cnt;

int main(){
  cin >> m >> d;
  for(ll i = 1;i <= m;i++){
    for(ll j = 1;j <= d;j++){
      if(judge(i,j)) cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int n;
    cin >>n;
    int button[n];
    for(int i =0;i<n;i++){
        int a;
        cin>>a;
        button[i] = a;
    }
    int i = 1;
    int cnt = 0;
    while(true){
        cnt++;
        int tmp = button[i-1];
        button[i-1] = 0;
        i = tmp;
        if (i ==0){cout<<-1<<endl;break;}
        if(i==2){cout<<cnt<<endl;break;}
    }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int n, x[MAXN], y[MAXN], h[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> x[i] >> y[i] >> h[i];
    FOR(i,0,100)
        FOR(j,0,100) {
            set<int> s;
            int z;
            FOR(k,1,n) {
                int g = abs(x[k] - i) + abs(y[k] - j);
                if (h[k]) {
                    z = h[k] + g;
                    break;
                }
            }
            int res = 0;
            FOR(k,1,n) 
                if (max(z - abs(x[k] - i) - abs(y[k] - j), 0) == h[k]) res++;
            if (res == n) {
                cout << i << ' ' << j << ' ' << z;
                return 0;
            }
        }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

ans = 0
for i in range(1,N):
    X = list(set(S[:i]))
    Y = list(set(S[i:]))
    kaburi = 0
    for j in range(len(X)):
        for k in range(len(Y)):
            if X[j] == Y[k]:
                kaburi += 1
    if kaburi > ans:
        ans = kaburi

print(ans)

Measured memory_bytes: 9096
#include<bits/stdc++.h>
using namespace std;
bool isprime(int x) {
	if(x<2) return false;
	int t=sqrt(x);
	for(int i=2;i<=t;++i) if(x%i==0) return false;
	return true;
}
int x,cnt=0;
int main() {
	cin>>x;
	while(1) {
		if(isprime(x)==true) {cout<<x<<'\n';return 0;}
		else x++;
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

n = gets.chomp.to_i
h = gets.chomp.split(/ /).map(&:to_i)
dp = []
# dp[n]は最小値
# 0..(n - 1)
dp[0] = 0
dp[1] = 0
dp[2] = (h[1] - h[0]).abs
(3..n).each do |i|
  dp[i] = [dp[i - 1] + (h[i - 1] - h[(i - 1) - 1]).abs, dp[i - 2] + (h[i - 1] - h[(i - 2) - 1]).abs].min
end
#p dp
puts dp[n]


Measured memory_bytes: 11908
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vi dp;
vvi g;

void f(int l,int r,int d){
	int m=r-l;
	if(m==1) return;
	for(int i=1;i<m;i++) if(dp[m]==1+max(dp[i],dp[m-i])){
		for(int x=0;x<i;x++) for(int y=0;y<m-i;y++){
//			cout<<l+x<<' '<<l+i+y<<' '<<d<<endl;
			g[l+x][l+i+y]=g[l+i+y][l+x]=d;
		}
		f(l,l+i,d+1);
		f(l+i,r,d+1);
		break;
	}
}

int main(){
	cin>>n;
	dp=vi(n+1,inf);
	dp[0]=dp[1]=0;
	g=vvi(n,vi(n));
	for(int i=2;i<=n;i++) for(int j=1;j<i;j++) dp[i]=min(dp[i],1+max(dp[j],dp[i-j]));
	f(0,n,1);
	for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) cout<<g[i][j]<<" \n"[j==n-1];
/*	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++) cout<<g[i][j]<<' ';cout<<endl;
	}*/
/*	for(auto i:dp) cout<<i<<' ';
	cout<<endl;*/
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	int n; cin>>n;
	ll a[n+1] = {0};
	for(int i=0;i<n-1;i++)
	{
	    ll p; cin>>p;
	    a[p]++;
	}
	for(int i=1;i<=n;i++) cout<<a[i]<<'\n';
	
	return 0;
}

Measured memory_bytes: 5208
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,k;
ll h[200005];

int main(void){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%lld",&h[i]);
	}
	sort(h,h+n);
	ll ans=0;
	for(int i=0;i<n-k;i++){
		ans+=h[i];
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
long int n,m;
pair<long int,long int> a[100001];
long int b[100002];
bool compare(pair<long int,long int> c,pair<long int,long int> d)
{
    if(c.second==d.second)
    return c.first>d.first;
    return c.second>d.second;
}
long int root(long int x)
{
    while(b[x]!=x)
    {
        b[x]=b[b[x]];
    x=b[x];
    }
    return x;
}
int main() {
    cin>>n>>m;
    m++;
    for(long int i=1;i<=n;i++)
    cin>>a[i].first>>a[i].second;
    for(long int i=0;i<=100001;i++)
    b[i]=i;
    sort(a+1,a+n+1,compare);
    long int f[100002]={0};
    //for(long int i=1;i<=n;i++)
   // cout<<a[i].first<<" "<<a[i].second<<endl;
    for(long int i=1;i<=n;i++)
    {
        long int temp1=m-a[i].first;
        if(temp1>=1)
        {
            long int temp2=root(temp1);
            if(temp2!=0)
            {
            f[temp2]=a[i].second;
            b[temp2]=root(temp2-1);
            }
        }
    }
    long long int ans=0;
    for(long int i=1;i<=m;i++)
    ans+=f[i];
    cout<<ans;
	return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
//https://www.geeksforgeeks.org/dynamic-programming-set-8-matrix-chain-multiplication/
//return the cost
/*int cal(int a[],int i, int j){
    if(i==j) return 0;
    int min = 1<<30;
    //printf("%d\n",min);
    for(int k = i; k<j; k++){
        int count = cal(a, i, k)+cal(a,k+1, j)+a[i-1]*a[k]*a[j];
        if(count<min) min = count;
    }
    
    return min;
}*/

int main()
{
    int n;
    scanf("%d",&n);
    int x[n+2], y[n+2];
    int dp[n+2][n+2];
    for(int i = 1; i<=n; i++){
        scanf("%d %d",&x[i],&y[i]);
        dp[i][i] = 0;
    } x[n+1] = y[n];
    dp[n+1][n+1] = 0;
    int min = 1<<30;
    for(int m = 2; m<=n+1; m++){
        for(int i = 2; i<=n+2-m ; i++){
            int j = i+m-1;
            dp[i][j] = 1<<30;
            for(int k = i; k<j; k++){
                int count = dp[i][k]+dp[k+1][j]+x[i-1]*x[k]*x[j];
                if(count<dp[i][j]) dp[i][j] = count;
            }
        }
        
    }
    
    //printf("%d\n",cal(x, 2,n+1));
    printf("%d\n",dp[2][n+1]);
    return 0;
}



Measured memory_bytes: 2712
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define int long long int
#define ld long double
#define all(x) (x).begin(), (x).end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef pair<int,int> pii;
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ub upper_bound
#define lb lower_bound
#define present(c,x) (c.find(x) != c.end())
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'	
#define fill(s,x,n) vector
 x(n); rep(i,0,n) cin>>x[i];
#define INF 1000000007 
#define MOD 998244353
#define INF64 1e18

int n,K;
vector<vector<int>> adj(50,vector<int> (50));
vector<vector<int>> ans(50,vector<int> (50));

vector<vector<int>> matrix_mul(vector<vector<int>> A,vector<vector<int>> B){
	vector<vector<int>> product(50,vector<int> (50,0));

	rep(i,0,n){
		rep(j,0,n){
			rep(k,0,n){
				product[i][j]+=(A[i][k]*B[k][j])%INF;
				product[i][j]%=INF;
			}
		}
	}

	return product;
}

void binary_exp(int k){
	if(k==1){
		ans=adj;
		return;
	}

	binary_exp(k/2);
	ans=matrix_mul(ans,ans);
	if(k%2)
		ans=matrix_mul(ans,adj);
}
	
void solve(){
	cin>>n>>K;
	rep(i,0,n){
		rep(j,0,n){
			cin>>adj[i][j];
		}
	}

	binary_exp(K);
	int total=0;
	rep(i,0,n){
		rep(j,0,n){
			total+=ans[i][j];
			total%=INF;
		}
	}

	cout<<total;
}	
 
int32_t main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
 
	int T;
	// cin>>T;
	T=1;
	while(T--){
		solve();
	}
}

Measured memory_bytes: 3792