akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000;
char s[maxn];
set<string> st;
int k, n;
int main() {
	scanf("%s%d", s + 1, &k); n = strlen(s + 1);
	for (int i = 1; i <= n; ++i) {
		string str = "";
		for (int j = i; j <= n && j <= i + 5; ++j) {
			str += s[j]; st.insert(str);
		}
	}
	set<string>::iterator it = st.begin();
	for (int i = 1; i < k; ++i) ++it;
	printf("%s", it->data());
}

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

#define M 1046527
#define L 14

char H[M][L];

int getChar(char ch)
{
	if (ch == 'A') return 1;
	else if (ch == 'C') return 2;
	else if (ch == 'G') return 3;
	else if (ch == 'T') return 4;
	return 0;
}

long long getKey(char str[])
{
	long long sum = 0;
	long long p = 1;
	for (int i = 0; i < strlen(str); i++)
	{
		sum += p * getChar(str[i]);
		p *= 5;
	}
	return sum;
}

// 最初の位置
int h1(long long key)
{
	return key % M;
}

// 衝突したときの移動分
int h2(long long key)
{
	return key % (M - 1) + 1;
}

int insert(char str[])
{
	int h;
	long long key;
	for (int i = 0;; i++)
	{
		key = getKey(str);
		int h = (h1(key) + h2(key) * i) % M;
		if (strcmp(H[h], str) == 0)
		{
			return 0;
		}
		if (strlen(H[h]) == 0)
		{
			strcpy(H[h], str);
			return 1;
		}
	}
}

int find(char str[])
{
	int h;
	long long key;
	for (int i = 0;; i++)
	{
		key = getKey(str);
		int h = (h1(key) + h2(key) * i) % M;
		if (strcmp(H[h], str) == 0)
		{
			return 1;
		}
		if (strlen(H[h]) == 0)
		{
			return 0;
		}
	}
}

int main()
{
	for (int i = 0; i < M; i++)
	{
		H[i][0] = '\0';
	}

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

	char com[10];
	char str[10];
	for (int i = 0; i < n; i++)
	{
		scanf("%s%s", com, str);
		if (com[0] == 'i')
		{
			insert(str);
		}
		else
		{
			if (find(str) == 1)
			{
				printf("yes\n");
			}
			else
			{
				printf("no\n");
			}
		}
	}
}


Measured memory_bytes: 17044
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int;
using namespace std;
#define ll long long int
#define F first
#define S second
//#define endl "\n"
//#define nl cout<<endl;
#define pb push_back
#define ull unsigned long long 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define Knucklehead ios_base::sync_with_stdio(false);cin.tie(NULL);
//#define mod 100000007
#define mat vector<vector<ll>>
mat cn(ll n, ll m){return vector< vector<ll> >(n, vector<ll>(m));}
bool compare(char &s1,char &s2){return s1 > s2;} 
bool sortmahstyle(const pair<ll,ll> &a,  const pair<ll,ll> &b) 
{ 
    if(a.second > b.second )
        return true;
    if( a.second==b.second && a.first > b.second )
       return true;
    return false;
}
bool cmp(int n, pair<int, int> const& p)
{
    return (p.first < n);
}
//me
ll const mod = 1e9+7;//998244353;
ll const inf = 1e18;
ll const maxn = 1e5+1;

void solve()
{    
     
     ll n,a,b; 
     cin >> n >> a >> b;
     cout << min(n*a,b);  
}

int main() {
Knucklehead 
//*
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
/**/ 
          
          ll t;
          /**/t=1;
          /*/cin>>t;/**/
          f(testcases,0,t){
               //cout << "Case #" <<testcases+1<<": ";
               solve();
          }
 
 
    return 0;
}

Measured memory_bytes: 3636
n,q=map(int,input().split())
s=list(input())
#print(s)
i=1
a=[0]
x=0
while i!=n:
    if s[i-1]=="A":
        if s[i]=="C":
            x=x+1
    i=i+1
    a.append(x)

#print(a)
i=0
while i!=q:
  try:
    l,r=map(int,input().split())
    i=i+1
    s=a[r-1]-a[l-1]
    print(s)
  except:
      break

Measured memory_bytes: 6372
import collections
 
#文字列を一文字ずつ取得したいとき
def inputStrOnebyOne():
    s = list(input())
    return s
 
#整数を一つずつリストに入れる
def inputOnebyOne_Int():
    a = list(int(x) for x in input().split())
    return a
 
def main():
    A = inputStrOnebyOne()
    B = inputStrOnebyOne()
    C = inputStrOnebyOne()

    check = "a"
    while True:
        if check == "a":
            if len(A) == 0:
                break
            check = A.pop(0)
        elif check == "b":
            if len(B) == 0:
                break
            check = B.pop(0)
        elif check == "c":
            if len(C) == 0:
                break
            check = C.pop(0)
    print(check.upper())
 
if __name__=='__main__':
    main()

Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        in.lines().forEach((String input) -> {
            char lastChar = input.charAt(input.length() - 1);

            switch (lastChar) {
                case '2':
                case '4':
                case '5':
                case '7':
                case '9':
                    System.out.print("hon");
                    break;
                case '0':
                case '1':
                case '6':
                case '8':
                    System.out.print("pon");
                    break;
                case '3':
                    System.out.print("bon");
                    break;
                default:
                    break;
            }
        });
    }
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  int ans=1;
  
  for(int i=0;i<N-1;i++){
    if(S.at(i)!=S.at(i+1)){
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 512
N,K=gets.split.map(&:to_i)

points=N.times.map{gets.split.map(&:to_i)}
points.sort!


ans=Float::INFINITY

(0...N).each do |l|
    (l...N).each do |r|
        width=points[r][0]-points[l][0]
        include_points=points[l..r]
        include_points.sort_by!{|point| point[1]}
        height=Float::INFINITY
        (0...(r-l+1-K+1)).each do |i|
            temp=include_points[i+K-1][1]-include_points[i][1]
            height=temp if temp<height
        end
        #p [l,r,width,height] if width*height<ans
        ans=width*height if width*height<ans
    end
end

p ans

Measured memory_bytes: 2044
n,k=map(int,input().split())
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

mod=10**9+7
f=[1]
for i in range(n):f+=[f[-1]*(i+1)%mod]
def comb(a,b):
    return f[a]*pow(f[b],mod-2,mod)*pow(f[a-b],mod-2,mod)%mod

a=list(map(int,input().split()))
a.sort()
b=a[::-1]
#print(a,b)
ans=0
for i in range(k-1,n):
    ans+=((a[i]-b[i])*(comb(i,k-1)))%(10**9+7)
print(ans%(10**9+7))


Measured memory_bytes: 68428
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a<b)printf("a < b\n");
    if(a>b)printf("a > b\n");
    if(a==b)printf("a == b\n");
    return 0;
}


Measured memory_bytes: 3064
S = gets.chomp

S.each_char.with_index do |s, i|
    if i % 2 == 0
        unless ["R", "U", "D"].include?(s)
            puts "No"
            exit
        end
    else
        unless ["L", "U", "D"].include?(s)
            puts "No"
            exit
        end
    end
end

puts "Yes"

Measured memory_bytes: 1788
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) {
        cin >> p[i];
        p[i]--;
    }
    int cnt = 0, ans = 0;
    rep(i, n) {
        if (p[i] == i) {
            cnt++;
            continue;
        }
        ans += (cnt+1)/2;
        cnt = 0;
    }
    ans += (cnt+1)/2;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int length[3];
	int rectangle, diamond;
	
	rectangle = diamond = 0;
	while (scanf("%d,%d,%d", &length[0], &length[1], &length[2]) != EOF){
		if ((length[0] * length[0]) + (length[1] * length[1]) == (length[2] * length[2])){
			rectangle++;
		}
		else if (length[0] == length[1]){
			diamond++;
		}
	}
	printf("%d\n%d\n", rectangle, diamond);
	
	return (0);
}

Measured memory_bytes: 596
import bisect
from itertools import *
n=range(50001);a=list(n);a[1]=0
for i in range(2,224):a[i*2::i]=[0]*len(a[i*2::i])
p=list(compress(n,a))
for x in iter(input,'0'):x=int(x);print(sum(1 for d in p[:bisect.bisect(p,x//2)]if a[x-d]))


Measured memory_bytes: 7800
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bits//stdc++.h>
using namespace std;
struct P{
	int x,y;
};
bool operator<(P a,P b){
	if(a.x<b.x)return true;
	else if(a.x>b.x) return false;
	else{
		if(a.y<b.y) return true;
		else return false;
	}
}
bool operator>(P a,P b){
	if(a.x<b.x)return false;
	else if(a.x>b.x) return true;
	else{
		if(a.y<b.y) return false;
		else return true;
	}
}
bool operator==(P a,P b){
	return a.x==b.x&&a.y==b.y;
}
int main() {
	int n;
	while(cin>>n&&n!=0){
		P a[3000];
		for(int i=0;i<n;i++){
			cin>>a[i].x>>a[i].y;
		}
		int sum=0;
		sort(a,a+n);
		for(int i=0;i<n;i++){
		int x1=a[i].x,y1=a[i].y;
		for(int j=0;j<n;j++){
			if(i!=j&&a[j].x>=x1&&a[j].y>=y1){
				  int x2=a[j].x,y2=a[j].y;  
				  int x3=x2-x1,y3=y2-y1;
				  int x4=x2-y3,y4=y2+x3;
				  P b={x4,y4};
				  int s=lower_bound(a,a+n,b)-a;
				  if(!(s<n&&a[s]==b))continue;
				  int x5=(x4-x3),y5=(y4-y3);
				  s=0;
				  b={x5,y5};
				  s=lower_bound(a,a+n,b)-a;
				  if(!(s<n&&a[s]==b))continue;
				  int sum2=((x2-x5)*(y4-y1));
				  sum2-=((x3*y3)*2);
				  sum=max(sum,sum2);
			  }
			}
		}
		cout<<sum<<endl;
	}
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main() {

	FAST;

	int n, x;
	cin >> n >> x;
	for (int i = 0; i <= n; i ++) {
		for (int j = 0; j <= n; j ++) {
			int sum = i * 10000 + j * 5000;
			if (x - sum >= 0 && (x - sum) % 1000 == 0 && (x - sum) / 1000 + i + j == n) {
				cout << i << ' ' << j << ' ' << (x - sum) / 1000 << '\n';
				return 0;
			}
		}
	}
	cout << -1 << ' ' << -1 << ' ' << -1 << '\n';
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = sorted(map(int, input().split()))
F = sorted(map(int, input().split()), reverse=True)

ng = -1
ok = 0
for i in range(N):
  ok = max(A[i]*F[i], ok)

def is_ok(arg):
  cnt = 0
  for i in range(N):
    cnt += max(A[i] - arg//F[i], 0)
  return cnt <= K

def m_bisect(ng, ok):
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid):
      ok = mid
    else:
      ng = mid
  return ok

print(m_bisect(ng, ok))

Measured memory_bytes: 116188
#include<iostream>

/*三平方の定理*/
int main() {
	int N,array[3];
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		std:: cin >> array[0] >> array[1] >> array[2];
		for (int l = 0; l < 2; l++) {
			if (array[l] >= array[l + 1]) {
				int tmp;
				tmp = array[l];
				array[l] = array[l + 1];
				array[l + 1] = tmp;
			}
		}
		if (array[2] * array[2] == array[0] * array[0] + array[1] * array[1]) {
			std::cout << "YES" << std::endl;
		}
		else {
			std::cout << "NO" << std::endl;
		}
	}
}



Measured memory_bytes: 3072
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const ll inf=1000000007;
const ll MOD=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

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

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

int main(){
	ll n,k,a[M];
	ll ans=0;
	cin>>n>>k;
	rep(i,0,n)cin>>a[i];
	ll x=0;
	ll y=0;
	rep(i,0,n-1){
		rep(j,i+1,n){
			if(a[i]>a[j])x++;
		}
	}
	rep(i,0,n)rep(j,0,n){
		if(a[i]>a[j])y++;
	}
	if(k==1)print(x);
	else{
		ans=((k*x)%MOD+((k*(k-1)/2)%MOD)*y)%MOD;
		print(ans);
	}



}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

ll dp[105][10005];
void solve(){
  int n,W;
  cin>>n>>W;
  memset(dp,0,sizeof(dp));
  vector<ll>v(n),w(n);
  rep(i,n)cin>>v[i]>>w[i];
  rep(i,n){
    rep(j,W+1){
      if(j-w[i]>=0)dp[i+1][j]=max(dp[i][j],dp[i+1][j-w[i]]+v[i]);
      chmax(dp[i+1][j],dp[i][j]);
    }
  }
  cout<<dp[n][W]<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}



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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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 ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n);
  rep(i,n){
    cin>>a[i];
  }
  ll ans=0;
  rep(i,60){
    ll one=0;
    rep(j,n) if(a[j]>>i&1) one++;
    ll zero=n-one;
    ll x=(one*zero)%MOD;
    rep(j,i) (x*=2)%=MOD;
    (ans+=x)%=MOD;
  }
  cout<<ans<<endl;
}

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

using namespace std;

int a[10005], b[105][105];

int main()
{
    int h, w, n;
    cin>>h>>w>>n;
    for(int i=1; i<=n; ++i)
        cin>>a[i];
    int now = a[1], next = 2;
    for(int i=0; i<h; ++i){
        if(i%2){
            for(int j=w-1; j>=0; --j){
                if(now == 0){
                    now = a[next];
                    ++next;
                }
                b[i][j] = next - 1;
                --now;
            }
        }
        else{
            for(int j=0; j<w; ++j){
                if(now == 0){
                    now = a[next];
                    ++next;
                }
                b[i][j] = next - 1;
                --now;
            }
        }
    }
    for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                cout<<b[i][j]<<" \n"[j == w-1];
            }
        }
    return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define eb emplace_back
#define pb push_back
#define mk make_pair
#define mt make_tuple

#define Umap unordered_map
#define graph vector<vector<int>>

#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl

#define INF 1e9+5
#define N 40001
#define MAXN   100001


bool sortbysec(const tuple<int, int, int>& a,  
               const tuple<int, int, int>& b) 
{ 
    return (get<1>(a) < get<1>(b)); 
}



int spf[0];
void sieve(){
	spf[1] = 1;
	for(int i=2;i<MAXN;i++) spf[i] = i;

	for(int i=4;i<MAXN;i+=2) spf[i] = 2;

	for(int i=3; i*i<MAXN;i++){
		if(spf[i]==i){
			for(int j=i*i;j<MAXN;j+=i){
				if(spf[j]==j) spf[j] = i;
			}
		}
	}
}
bool custom(const pair<int, int>& a,  
               const pair<int, int>& b) 
{ 
    if(a.first==b.first) return a.second < b.second;
	return a.first > b.first; 
}

// A.reize(unique(A.begin(),A.end())- A.begin());
#define int long long
void solve(){
	int a,b; cin>>a>>b;
	cout<<a*b<<endl;
}
signed main() {
IOS;
	int t=1; 
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}




vector<int> getFactorization(int x){

	vector<int> primeFactors;
	while(x>1){
		primeFactors.pb(spf[x]);
		x /= spf[x];
	}
	return primeFactors;
}


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

int main() {
  string L[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string s;
  cin >> s;
  rep(i, 7) {
    if (s == L[i]) {
      cout << 7-i << endl;
    }
  }
  return 0;
}

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

using namespace std;


int main() {
    string s; cin >> s;
    if(s.length() == 1) {
        cout << 0 << endl;
        return 0;
    }

    long long n0 = count_if(s.begin(), s.end(), [](char c) { return c == '0';});
    long long n1 = s.length() - n0;

    cout << 2*min(n1, n0) << endl;

    return 0;
}


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

 
int main()
{
  int h, w, sh, sw, th, tw;
  cin >> h >> w >> sh >> sw >> th >> tw;
  --sh; --sw; --th; --tw;
  vector<string> s(h);
  //入力がh行のstring 
  rep(i,h) cin >> s[i];
  
  vector<vector<int>> dist(h,vector<int>(w,INT_MAX));
  
  deque<P> q;
  
  vector<int> mx = {0, 0, -1, 1};
  vector<int> my = {1, -1, 0, 0}; 
  
  dist[sh][sw] = 0;
  q.emplace_back(sh,sw);
  while(!q.empty()){
    int i = q[0].first;
    int j = q[0].second;
    int d = dist[i][j];
    q.pop_front();
    //歩きでの移動
    rep(k,4){
      int ni = i + mx[k];
      int nj = j + my[k];
      //枠外に飛び出さないかの判定
      if(ni < 0 || h-1 < ni || nj < 0 || w-1 < nj) continue;
      //壁かの判定
      if(s[ni][nj] == '#') continue;
      //更新可能、到達済みかの判定
      if(dist[ni][nj] <= d) continue;
      dist[ni][nj] = d;
      q.emplace_front(ni,nj);
    }
    //魔法での移動
    for(int wx = -2; wx <= 2; ++wx){
      for(int wy = -2; wy <= 2; ++wy){
        int ni = i + wx;
        int nj = j + wy;
        //枠外に飛び出さないかの判定
        if(ni < 0 || h-1 < ni || nj < 0 || w-1 < nj) continue;
        //壁かの判定
        if(s[ni][nj] == '#') continue;
        //更新可能、到達済みかの判定
        if(dist[ni][nj] <= d+1) continue;
        dist[ni][nj] = d+1;

        q.emplace_back(ni,nj);
      }
    }
  }
    
  int ans = dist[th][tw];
  if(ans == INT_MAX) ans = -1;
  
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 9548
#include<stdio.h>
/// http://www5d.biglobe.ne.jp/~tomoya03/shtml/algorithm/Hougan.htm
/// http://www.sousakuba.com/Programming/gs_hittest_point_triangle.html
struct Vector2D{
    double x;
    double y;
};

Vector2D sub(const Vector2D a, const Vector2D b){
    Vector2D ret;
    ret.x = a.x-b.x;
    ret.y = a.y-b.y;
    return ret;
}

bool hittest_point(Vector2D A, Vector2D B, Vector2D C, Vector2D P){
    Vector2D AB = sub(B, A);
    Vector2D BP = sub(P, B);

    Vector2D BC = sub(C, B);
    Vector2D CP = sub(P, C);

    Vector2D CA = sub(A, C);
    Vector2D AP = sub(P, A);

    // Cross Product
    double c1 = AB.x * BP.y - AB.y * BP.x;
    double c2 = BC.x * CP.y - BC.y * CP.x;
    double c3 = CA.x * AP.y - CA.y * AP.x;

    if((c1>=0 && c2>=0 && c3 >=0) || (c1<0 && c2 <0 && c3<0)){
        return true;
    }else{
        return false;
    }
}

int main(){
    Vector2D A, B, C, P;
    while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &A.x, &A.y,&B.x, &B.y, &C.x, &C.y,&P.x, &P.y)){
        if(hittest_point(A, B,C,P)){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2568
def  fenec(N,K,H):
    H.sort()
    try :
        for i in range (K):
            H.pop()
    except:
        return 0
    rest_hp  = sum(H)
    
    return rest_hp        
8 


inp = input().split()
inp_ = input().split()
N = int(inp[0])
K = int(inp[1] )
H= [int(i) for i in inp_]

print(fenec(N,K,H))

Measured memory_bytes: 26552
// AOJ 1296: Repeated Substitution with Sed
// 2017.10.20 bal4u@uu

#include <stdio.h>
#include <string.h>

typedef struct { char x[11], s, k; } Q;
Q que[10002]; int top, end;
char a[10][11], sa[10];
char b[10][11], sb[10];
char g[11], sg;

int main()
{
	int n, i, s, k, w, f, ans;
	char *p, *q;

	while (scanf("%d", &n) && n > 0) {
		for (i = 0; i < n; i++) {
			scanf("%s%s", a[i], b[i]);
			sa[i] = strlen(a[i]), sb[i] = strlen(b[i]);
		}
		scanf("%s%s", que[0].x, g), sg = strlen(g);

		ans = -1, que[0].k = 0, que[0].s = strlen(que[0].x), top = 0, end = 1;
		while (top < end) {
			for (i = 0; i < n; i++) {
				p = que[top].x, s = que[top].s, k = que[top].k + 1, q = que[end].x, f = 0;
				while (*p) {
					if ((p-que[top].x) + sa[i] <= s && !memcmp(p, a[i], sa[i])) {
						if ((q-que[end].x) - sa[i] + sb[i] > sg) goto next;
						memcpy(q, b[i], sb[i]);
						p += sa[i], q += sb[i], f = 1;
					} else *q++ = *p++;
				}
				if (!f) continue;
				*q = 0;	if ((w = q - que[end].x) == sg) {
					if (memcmp(que[end].x, g, sg) == 0) { ans = k; goto done; }
				} else que[end].s = w, que[end++].k = k;
next:			;
			}
			top++;
		}
done:	printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1820
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, X;
  cin >> N >> X;
  int D = 0;
  int L;
  int ans = 0;
  while (D <= X){
    ans++;
    cin >> L;
    D += L;
  }
  cout << min(ans, N+1) << endl;
}

Measured memory_bytes: 256
//ABC129C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	long long int num = 1e9+7;
	long long int n, m;
	cin >> n >> m;
	vector<long long int> a(n);
	long long int x;
	if(n == 1){
		cout << 1 << endl;
		return 0;
	}
	for(long long int i=0;i<n;i++){
		a.at(i) = 1;
	}
	for(long long int i=0;i<m;i++){
		cin >> x;
		a.at(x-1) = 0;
	}
	vector<long long int> c(n);
	if(a.at(0) == 0){
		c.at(0) = 0;
	}else{
		c.at(0) = 1;
	}
	if(a.at(1) == 0){
		c.at(1) = 0;
	}else{
		c.at(1) = c.at(0) + 1;
	}
	for(long long int i=2;i<n;i++){
		if(a.at(i) == 0){
			c.at(i) = 0;
		}else{
			c.at(i) = (c.at(i-2) + c.at(i-1))%(num);
		}
	}
	cout << c.at(n-1) << endl;
	return 0;
}

Measured memory_bytes: 1792
n = input().split()
N = int(n[0])
M = int(n[1])
C = int(n[2])

B = input().split()

tmp = 0
for i in range(N):
    A = input().split()
    ans = 0
    for j in range(M):
        ans += int(B[j])*int(A[j])
    ans += C
    if ans > 0:
        tmp += 1

print(str(tmp))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
 
int main(void){
    int n, k;
    cin>>n>>k;
    vector<int> v(n);
    rep(i, n) cin>>v[i];
    vector<int> imo(n+1);
    /*いもす法*/
    rep(j, min(k, (int)log2(n)+100)){
        imo = vector<int>(n+1);
        rep(i, n){
            imo[max(0, i-v[i])]++;
            imo[min(i+(v[i]+1), n)]--;
        }
        int bef = 0;
        rep(i, n){
            bef+=imo[i];
            v[i] = bef;
        }
    }
    rep(i, n) cout<<v[i]<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 5860
def main():
    N = int(input())
    L = sorted(list(map(int, input().split())))
    ans = 0
    for ia in range(N-2):
        a = L[ia]
        ic = ia + 2
        for ib in range(ia+1, N-1):
            b = L[ib]
            while ic < N and L[ic] < a+b:
                ic += 1
            ans += ic - (ib + 1)
    print(ans)
main()

Measured memory_bytes: 73880
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
int main(){
	while(cin>>n,n){
		vector<pii> dia;
		dia.clear();
		for(int i = 0;i < n;i++){
			string str;
			int h,m,s;
			cin>>str;
			h = ((str[0]-'0')*10+(str[1]-'0'))*60*60;
			m =((str[3]-'0')*10 +(str[4]-'0'))*60;
			s =(str[6]-'0')*10+(str[7]-'0');
			int dep = h+m+s;
			dia.push_back(pii(dep,1));
			cin>>str;
			h = ((str[0]-'0')*10+(str[1]-'0'))*60*60;
			m =((str[3]-'0')*10 +(str[4]-'0'))*60;
			s =(str[6]-'0')*10+(str[7]-'0');
			int arr = h+m+s;
			dia.push_back(pii(arr,-1));
		}
		sort(dia.begin(),dia.end());
		int ans = 0;
		int cnt = 0;
		for(int i = 0;i <dia.size();i++){
			cnt +=dia[i].second;
			ans =max(ans,cnt);
		}
		cout <<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1464
import sys, math

def input():
    return sys.stdin.readline()[:-1]

def main():
    N = int(input())
    D = [k for k in range(N+1)]
    for d in range(10):
        for k in range(N-6**d+1):
            D[k+6**d] = min(D[k+6**d],D[k]+1)
    for d in range(10):
        for k in range(N-9**d+1):
            D[k+9**d] = min(D[k+9**d],D[k]+1)
    print(D[N])
if __name__ == '__main__':
    main()


Measured memory_bytes: 44784
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function mkgraph(n::Int,m::Int)
  g=Array{Int64,1}[Int[] for i=1:n]
  for i=1:m
    a,b=pM(split(readline()))
    push!(g[a],b); push!(g[b],a)
  end
  return g
end
function bfs(g,f::Int)
  n=length(g)
  q=Int[f]
  dist=zeros(Int,n)
  goto=zeros(Int,n)
  while !isempty(q)
    v=popfirst!(q);
    for nv=g[v];
      if dist[nv]!=0; continue; end
      dist[nv]=dist[v]+1
      goto[nv]=v
      push!(q,nv)
    end
  end
  dist[f]=0;goto[f]=0
  return dist,goto
end
function main()
  println("Yes")
  foreach(println,(bfs(mkgraph(pM(split(readline()))...),1)[2][2:end]))
end
main()
if isdefined(Base, :mystdin);close(mystdin);end


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

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

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

int main() {
  int n;
  cin >> n;
  vector<int> to[n], deg(n);
  vector<P> edge;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    to[a].push_back(b);
    to[b].push_back(a);
    ++deg[a], ++deg[b];
    edge.push_back({a, b});
  }

  int mx = 0;
  rep(i, n) mx = max(mx, deg[i]);

  vector<int> ng[n];
  map<P, int> color;
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int u = q.front();
    q.pop();

    vector<bool> ok(mx, true);
    for (auto v : ng[u]) ok[v] = false;

    int c = 0;
    for (auto v : to[u]) {
      P p1 = P(u, v), p2 = P(v, u);
      if (color.count(p1) == 1 || color.count(p2) == 1) continue;
      while (ok[c] == false) ++c;
      color[p1] = color[p2] = c;
      ok[c] = false;
      ng[v].push_back(c);
      q.push(v);
    }
  }

  cout << mx << endl;
  for (auto p : edge) cout << color[p] + 1 << endl;

  return 0;
}


Measured memory_bytes: 25204
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li n, m;
    cin >> n >> m;
    vector<li> pows(n);
    for (int i = 0; i < n; ++i) {
        cin >> pows[i];
    }
    sort(pows.begin(), pows.end());


    auto count = [&](li minh) {
        li ans = 0;
        for (int i = 0; i < n; ++i) {
            ans += pows.end() - lower_bound(pows.begin(), pows.end(), minh - pows[i]);
        }
        return ans;
    };

    li p = 0, q = pows.back() * 2 + 1;
    while (q - p > 1) {
        li r = (p + q) / 2;
        if (count(r) < m) {
            q = r;
        } else {
            p = r;
        }
    }

    vector<li> accum(1, 0);
    for (int i = 0; i < n; ++i) {
        accum.push_back(accum.back() + pows[n - 1 - i]);
    }
    li pcount = count(p);
    li ans = -(pcount - m) * p;
    for (int i = 0; i < n; ++i) {
        li c = pows.end() - lower_bound(pows.begin(), pows.end(), p - pows[i]);
        ans += accum[c] + c * pows[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	if (k == 0) {
		cout << (ll) n * n << endl;
		return 0;
	}
	ll ans = 0;
	for (int b = 1; b <= n; b++) {
		if (b - k <= 0) continue;
		ll num = n / b;
		ans += (ll)num * (b - k);
		ans += max(0, n % b - k + 1);
	}

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

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
char s[30];
bool vis;
int main(){
	scanf("%s",s);
	int len = strlen(s);
	for(int i = len - 1; i >= 0; i--){
		for(int j = i - 1; j >= 0; j--){
			if(s[i] == s[j]){ 
				printf("no\n");
				return 0;
			}
		}
	}
	printf("yes\n");
	return 0;
}

Measured memory_bytes: 128
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

count = 0
(0..a).each do |i|
    (0..b).each do |j|
        (0..c).each do |k|
            money = 500 * i + 100 * j + 50 * k
            count += 1 if money == x
        end
    end
end

puts count

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

int main(){
  int n,t,a=100000,b,c;
  cin>>n>>t;
  for(int i=0;i<n;i++){
    cin>>c>>b;
    if(b<=t && c<=a) a=c;
  }
  
  if(a==100000) cout<<"TLE"<<endl;
  else cout<<a<<endl;
  return 0;
}
  

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#define MN 55

typedef long long ll;

char cnt[400000000];
ll C[MN][MN], ans = 0;
bool ok[MN]; int N = 0;
int n, m, S, T;
int a[MN], tot = 0; 

int main()
{
	scanf("%d%d%d%d", &n, &m, &S, &T);
	if((S & T) != S) return 0 * puts("0");
	for(int i = 0; i <= n; i++) C[i][0] = C[i][i] = 1;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j < i; j++)
			C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
	for(int i = 1; i <= n; i++)
		for(int j = 2; j <= m; j++)
			C[i][j] += C[i][j - 1];
			
	for(int i = 0; i < 18; i++) if(((S >> i) & 1) != ((T >> i) & 1)) N++, ok[i] = 1;
	for(int i = 1; i <= n; i++)
	{
		int x; scanf("%d", &x);
		if((x & S) != S || (x | T) != T) continue;
		++tot;
		for(int j = 17; j >= 0; j--)
			if(ok[j]) a[tot] = a[tot] * 2 + ((x >> j) & 1);
		for(int S = 0; S < (1 << N); S++)
		{
			int T = 0, w = 0;
			for(int j = N - 1; j >= 0; j--)
			{
				T *= 3;
				if((S >> j) & 1) w++, T += (a[tot] >> j) & 1;
				else T += 2;
			}
			ll v = 0;
			v -= C[cnt[T]][m];
			cnt[T]++;
			v += C[cnt[T]][m];
			if(w & 1) ans -= v;
			else ans += v;
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 190624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <tuple>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG

int main(void){

    int A, B;

    cin >> A >> B;
    int C;
    C = A*B;

    cout << C << endl;

}

Measured memory_bytes: 3640
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
	int key;
	Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
	Node *cur = nil->next;
	while( cur != nil && cur->key != key ){
		cur = cur->next;
	}
	return cur;
}

void init(){
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void printList(){
	Node *cur = nil->next;
	int isf = 0;
	while( 1 ){
		if( cur == nil ) break;
		if( isf++ > 0 ) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t){
	if( t == nil ) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	deleteNode(listSearch(key));
}

void insert(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

int main(){
	int key, n, i;
	int size = 0;
	char com[20];
	int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for( i = 0; i < n; i++ ){
		scanf("%s%d", com, &key);
		if( com[0] == 'i' ){ insert(key); np++; size++; }
		else if( com[0] == 'd' ){
			if( strlen(com) > 6 ){
				if( com[6] == 'F' ) deleteFirst();
				else if( com[6] == 'L' ) deleteLast();
			} else {
				deleteKey(key); nd++;
			}
			size--;
		}
	}
	
	printList();
	
	return 0;
}

Measured memory_bytes: 34012
import java.util.Map.Entry;
import java.util.*;
 
//import org.w3c.dom.css.Counter;
 
public class Main {
//public class App {
 
    public static void main(final String[] args){
     //スキャン
     final Scanner s = new Scanner(System.in);
      //String N = Integer.parseInt(s.next());
      //int X = Integer.parseInt(s.next());
      //int T = Integer.parseInt(s.next());
      //int ans = N /X;
      String hoge = s.next();
      int huge = hoge.length();
      int hage = 0;
    for(int i =0;i<huge;i++){
        hage += Integer.parseInt(hoge.substring(i, i+1));
    }


      String ans ="Yes";
      if(hage%9 !=0){ans = "No";}
      System.out.println(ans);
      
    }
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int main(){

	int n;
	string s;
	cin>>n>>s;
	
	string s1="",s2="";
	int l=0;
	rep(i,n){
		if(s[i]=='(')l++;
		else {
			if(l>0)l--;
			else s1+='(';
		}
	}
	rep(i,l)s2+=')';

	cout<<s1<<s<<s2<<endl;;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  int h, n;
  cin >> h >> n;
  // vector<int> a(n);

  // for (int& ai : a) {
  //   cin >> ai;
  // }

  // sort(a.begin(), a.end(), greater<>());
  // int m = 0;
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ret += a;
    if (ret >= h) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

typedef long long ll;
typedef pair<int,int>P;
#define INF 99999999
#define MOD (ll)(1e9+7)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

/*--------------------------------------------*/
/*ll factorial(ll);
void list_Prime(ll);
ll divisor(ll);*/
/*--------------------------------------------*/


int main(){
    int n;cin>>n;
    //int digit;
    int cnt=0;
    int tmp=n;
    while(tmp>0){
        int d=tmp%10;
        cnt+=d;
        tmp/=10;
    }
    cout<<((n%cnt!=0)?"No":"Yes")<<endl;
}



/*--------------------------------------------*/
/*
ll factorial(ll n){
    if(n==1)return 1;
    return n*factorial(n-1);
}


void list_Prime(ll n){//n以下の素数を全て見つける
    ll Limit=(int)sqrt((double)n);
    for(ll i=2;i<=n;i++)prime[i]=1;//最初はみんな素数かも
    //素数の整数倍を消していく(ルートnまで)
    for(ll i=2;i<=Limit;i++){
        if(prime[i]){
            for(ll j=2*i;j<=n;j++){
                if(j%i==0){
                    prime[j]=0;                
                }
            }
        }
    }
}

ll divisor(ll n){
    for(ll i=2;i<=n;i++){
        ll d=1;
        ll tmp=i;
        while(tmp>0){
            d++;
            while(tmp%d==0){
                prime[i]++;
                tmp/=i;
            }
        }
    }
    ll sum=1;
    for(ll i=2;;i<=n;i++){
        sum*=(prime[i]+1)/MOD;
    }    
    cout<<"sum="<<sum<<endl;

    return sum%MOD;
}
*/


Measured memory_bytes: 256
#include<cmath>
#include<iostream>
#include<cstdio>
#include<iomanip>
using namespace std;



int main() {
	int b, f, r, v,n;
	int a[4][3][10] = {};
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> b >> f >> r >> v;
		a[b - 1][f - 1][r - 1] += v;
	}
	for (int j = 0; j < 4; j++) {
		for (int k = 0; k < 3; k++) {
			for (int p = 0; p < 10; p++) {
				cout << ' ' << a[j][k][p];
			}
			cout << endl;
		}

		if (j < 3) {
			for (int w = 0; w < 20; w++)cout << '#';

			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
a, b, c = map(int, input().split())
if a + b < b + c:
  if a + b < a + c:
    print(a + b)
    exit()
  else :
    print(a + c)
    exit()
else :
  if b + c < a + c:
    print(b + c)
    exit()
  else :
    print(a + c)


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    set<int> S;
    rep(i, N) {
        int d; cin >> d; S.insert(d);
    }
    cout << sz(S) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
#define MAX_H 50
#define MAX_W 50
typedef pair<int, int> P;
const int INF = 1000000000;
char field[MAX_H][MAX_W + 1];
int d[MAX_H][MAX_W + 1];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int h, w;

int bfs() {
    queue<P> que;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            d[i][j] = INF;
        }
    }
    que.push(P(0, 0));
    d[0][0] = 0;

    while (!que.empty()) {
        P p = que.front(); que.pop();
        if (p.first == h - 1 && p.second == w - 1) break;

        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (0 <= nx && 0 <= ny && nx < h && ny < w && field[nx][ny] == '.' && d[nx][ny] == INF) {
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    return d[h-1][w-1];
}

int main() {
    cin >> h >> w;
    for (int i = 0; i < h; i++) cin >> field[i];
    int sum = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (field[i][j] == '.') sum++; 
        }
    }
    int ans = sum - bfs() - 1;
    if (bfs() == INF) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,c) for(__typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define F first
#define S second
using namespace std;

const LL mod = 1e9 + 7;

template<typename T> T gcd(T a, T b) { return b == 0?a: gcd(b, a % b); }
template<typename T> T LCM(T a, T b) { return a*(b/gcd(a, b)); }
template<typename T, typename S> T expo(T b, S e, const T &m){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b)%m, e>>1, m): (b*expo((b*b)%m, e>>1, m))%m;}
template<typename T, typename S> T expo(T b, S e){if(e <= 1)return e == 0?1: b;\
	return (e&1) == 0?expo((b*b), e>>1): (b*expo((b*b), e>>1));}
template<typename T, typename S> T modinv(T a, S mod) { return expo(a, mod-2, mod); }
template<class T, class S> std::ostream& operator<<(std::ostream &os, const std::pair<T, S> &t) {
	os<<"("<<t.first<<", "<<t.second<<")";
	return os;
}
template<class T> std::ostream& operator<<(std::ostream &os, const std::vector<T> &t) {
	os<<"["; FOR(it,t) { if(it != t.begin()) os<<", "; os<<*it; } os<<"]";
	return os;
}

const int MAXN = 1e6 + 3;
int arr[MAXN], n, m;

int l[MAXN], r[MAXN];
int ans[MAXN];
int bit[MAXN];
int P[MAXN];

struct event {
  int x, type, idx;
  bool operator<(const event &other) const {
    return x == other.x ? type < other.type : x < other.x;
  }
} es[2*MAXN];

void update(int idx, int val) {
  for(; idx > 0; idx -= idx & -idx) bit[idx] += val;
}
int query(int idx) {
  int res = 0;
  for(; idx < MAXN; idx += idx & -idx) res += bit[idx];
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  int sz = 0;
  for(int i = 1; i <= n; i++) {
    cin >> l[i] >> r[i];
    es[sz++] = {l[i], -1, i};
    es[sz++] = {r[i], 1, i};
  }
  sort(es, es + sz);
  int iter = 0;
  for(int i = 1; i <= m; i++) {
    while(iter < sz and es[iter].x == i and es[iter].type == -1) {
      update(es[iter].x, 1);
      iter++;
    }
    for(int d = 1; d*d <= i; d++) {
      if(i % d == 0) {
        ans[d] += query(P[d] + 1);
        P[d] = i;
        if(i != d*d) {
          ans[i/d] += query(P[i/d] + 1);
          P[i/d] = i;
        }
      }
    }
    while(iter < sz and es[iter].x == i and es[iter].type == 1) {
      update(l[es[iter].idx], -1);
      iter++;
    }
  }
  for(int i = 1; i <= m; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}


Measured memory_bytes: 11648
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
inline int Rand(){return rand()*32768+rand();}
int n;
int a[100005]; 
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	vector<int>len;
	len.push_back(1);
	for(int i=1;i<=n;i++){
		if(i>1&&len.back()==1){
			len.pop_back();
			len.push_back(a[i]-a[i-1]+2);
		}else len.push_back(a[i]-a[i-1]+1);
	}
	int cur=0;
	for(int i=0;i<len.size();i++){
//		cerr<<i<<" "<<len[i]<<endl;
		cur+=len[i];
		if(cur>n){
			cout<<((cur-n)%2?"First":"Second")<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 4312
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  vector<int> v;
  int n = s.length();
  for(int i = 0; i < n; i++) v.push_back(s[i]-'0');
  long long ans = 0;
  for(int i = 0; i < (1 << n-1); i++){
    int k = 1;
    long long cnt = v[0];
    long long res = 0;
    for(int j = 0; j < n-1; j++){
      if(i >> j & 1){
        res += cnt;
        cnt = v[k];
        k++;
      }
      else{
        cnt = cnt*10+v[k];
        k++;
      }
    }
    res += cnt;
    ans += res;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
K = int(input())

ans = 1
a = 7
i = K
while i > 0:
    m = a % K
    if m == 0:
        print(ans)
        break
    else:
        ans += 1
        a = m * 10 + 7
        i -= 1
if m != 0:
    print(-1)


Measured memory_bytes: 9168
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
typedef long long ll;
const int INF = 1e9;
const ll LLINF = 1e18;

struct edge { int from, to, cost; };
vector<edge> G;
int d[1009][1009];

void warshallFloyd(int n){
    
    int range=n;
    
    for(int k=1; k<=range; k++ ){
        for(int i=1; i<=range; i++ ){
            if(d[i][k]==INF) continue;
            for(int j=1; j<=range; j++ ){
                if(d[k][j]==INF) continue;
                if(d[i][j] > d[i][k]+d[k][j] ) d[i][j] = d[i][k]+d[k][j];
            }
        }
    }
}

int main() {
    int N, M;
    cin>>N>>M;
    
    rep1(i,N)rep1(j,N) d[i][j] = INF;
    
    rep(i,M){
        int a,b,c; scnd3(a,b,c);
        d[a][b] = c;
        d[b][a] = c;
        G.push_back({a,b,c});
    }
    
    warshallFloyd(N);
    
    int cnt=0;
    rep(i,M){
        if( d[G[i].from][G[i].to] < G[i].cost ) cnt++;
    }
    cout1(cnt);
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    vector<vector<int>> a_b(n);
    vector<vector<int>> b_a(n);
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        a_b[a].push_back(b);
        b_a[b].push_back(a);
    }
    int ans = 0;
    rep(i, n)
    {
        bool temp = true;
        rep(j, a_b[i].size())
        {
            if (h[i] <= h[a_b[i][j]])
            {
                temp = false;
                break;
            }
        }
        rep(j, b_a[i].size())
        {
            if (h[i] <= h[b_a[i][j]])
            {
                temp = false;
                break;
            }
        }
        if (temp == true)
            ans += 1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 12232