akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
#include <tuple>
using namespace std;

int main() {
    int n, m; cin >> n >> m;
    vector<pair<int, int>> arms(m);
    for (auto &p: arms) cin >> p.first >> p.second;
    sort(arms.begin(), arms.end());
    vector<pair<int, int>> seg(n);
    for (int i = 0; i < n; i++) seg[i] = {i + 1, i + 1};
    for (auto &p: arms) {
        int a = p.second - 1, b = p.second;
        seg[a].second = seg[b].second;
        seg[b].first = seg[a].first;
    }
    for (int i = 0; i < n; i++) {
        int s, t; tie(s, t) = seg[i];
        cout << (t - s + 1) << " \n"[i == n - 1];
    }
    return 0;
}


Measured memory_bytes: 5204
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,a[100000],sum=0,sub;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    sub=n-sum;
    if(sub>=0)
        cout<<sub<<endl;
    else
        cout<<"-1"<<endl;

    return 0;
}



Measured memory_bytes: 3684
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      s: String,
   }
   let mut wt = 0;
   let mut et = 0;
   for c in s.chars() {
      if c == 'E' {
         et += 1;
      }
   }
   let mut ans = n + 1;
   for c in s.chars() {
      if c == 'E' {
         et -= 1;
      }
      ans = std::cmp::min(ans, wt + et);
      if c == 'W' {
         wt += 1;
      }
   }
   println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
	int H, W; cin >> H >> W;
	vector<string> mp;
	string P, s; int Wx[110], Ho=0;
	for(int i=0; i<W; ++i){
	    P += '.';
	    Wx[i]=0;
	}
	for(int i=0; i<H; ++i){
	    cin >> s;
	    if(s!=P){
	        mp.push_back(s);
	        ++Ho;
	    }
	}
	for(int i=0; i<Ho; ++i){
	    for(int k=0; k<W; ++k) if(mp[i][k]=='.') ++Wx[k];
	}
	for(int i=0; i<Ho; ++i){
	    for(int k=0; k<W; ++k) if(Wx[k]<Ho) cout << mp[i][k];
	    cout << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import math

N=int(input())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
    
for j in range(1,4):
    sum=0
    for i in range(N):
        sum+=(abs(X[i]-Y[i]))**j
    D=math.pow(sum,1/j)
    print(D)
    
dist=0
for i in range(N):
    kyori=abs(X[i]-Y[i])
    if dist<=kyori:
        dist=float(kyori)
print(dist)




Measured memory_bytes: 5696
package main

import (
	"bufio"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	k, _ := strconv.Atoi(sc.Text())
	slice := make([]int, n)
	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())
	for i := 0; i < q; i++ {
		sc.Scan()
		An, _ := strconv.Atoi(sc.Text())
		slice[An-1]++
	}

	writer := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		if slice[i]-q <= k*(-1) {
			writer.WriteString("No\n")
		} else {
			writer.WriteString("Yes\n")
		}
	}
	writer.Flush()
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    ll a = 0;
    Scll(a);

    ll ans = 0;


    ans += a/11 * 2;

    if( a % 11 != 0 ){
        if( a % 11 > 6 )
            ans+=2;
        else
            ans+=1;
    }

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

    return 0;
}



Measured memory_bytes: 256
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=998244353;         
const int N=2e5+4;

//dp[i] tells the no. of ways to choose a subset of robots if we had the array from
//[i to n-1].

int dp[N];

int tree[4*N];

void update(int node,int st,int end,int ind,int val)
{
	if(st==end)
	{
		tree[node]=val; return;
	}

	int mid=(st+end)/2;

	if(ind<=mid)
	update(2*node,st,mid,ind,val);
	else
	update(2*node+1,mid+1,end,ind,val);

	tree[node]=max(tree[2*node],tree[2*node+1]);
}

int query(int node,int st,int end,int l,int r)
{
	if(st>r or end<l)
	return 0;

	if(st>=l and end<=r)
	return tree[node];

	int mid=(st+end)/2;

	return max(query(2*node,st,mid,l,r),query(2*node+1,mid+1,end,l,r));
}

int main()
{
	int n;

	scn(n);

	vector<pair<int,int>> v(n);

	rep(i,0,n)
	cin>>v[i].F>>v[i].S;

	sort(v.begin(),v.end());

	dp[n]=1; //1 way for an empty set

	update(1,0,n,n,n);

	for(int i=n-1;i>=0;i--)
	{
		pair<int,int> pp={v[i].F+v[i].S,0};

		int ind=lower_bound(v.begin(),v.end(),pp)-v.begin();

		int reach;

		if(ind>i+1)
		reach=query(1,0,n,i+1,ind-1);
		else
		reach=i+1;

		update(1,0,n,i,reach);

		dp[i]=(dp[i+1]+dp[reach])%mod;

		//cout<<i<<" "<<reach<<" "<<dp[i]<<endl;
	}	

	pri(dp[0]);

    return 0;
}


Measured memory_bytes: 4608
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc=new Scanner(System.in)){
			while(sc.hasNext()) {
				int n=sc.nextInt();
				int m=sc.nextInt();
				if((n|m)==0)	break;
				int[] p=new int[n];
				for(int i=0; i<n; i++) {
					p[i]=sc.nextInt();
				}
				Arrays.sort(p);
				int cost=0, count=0;
				for(int i=n-1; i>=0; i--) {
					count++;
					cost+=(count%m==0)?0:p[i];
				}
				System.out.println(cost);
			}
			
		}
	}	
}


Measured memory_bytes: 59268
#include <stdio.h>

struct road{
  int from;
  int to;
  int distance;
};

int calc_shortestDistance(int, int, int, int, struct road*, int);

int main(void)
{
  int n;
  int a, b, c;
  struct road roads[45];
  int city_size;
  int max_distance;
  int min_amount, amount;
  int min_city;
  int i, j;

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

    city_size=0;
    max_distance=0;
    for(i=0; i<n; i++){
      scanf("%d %d %d", &a, &b, &c);
      roads[i].from=a;
      roads[i].to=b;
      roads[i].distance=c;
      if(a<b && b>=city_size) city_size=b+1;
      else if(a>b && a>=city_size) city_size=a+1;
      if(max_distance<c) max_distance=c;
    }

    min_amount=city_size*(max_distance*n+1);
    for(i=0; i<city_size; i++){
      amount=0;
      for(j=0; j<city_size; j++){
	if(i==j) continue;
	amount+=calc_shortestDistance(i, j, city_size, n, roads, max_distance);
      }
      if(min_amount>amount){
	min_amount=amount;
	min_city=i;
      }
    }
    printf("%d %d\n", min_city, min_amount);
  }
  return 0;
}

int calc_shortestDistance(int from, int to, int city_size, int n, struct road* roads, int max_distance)
{
  int d[10];
  int is_searched[10]; //0:is not searched, 1:is searched.
  int min_d, min_city;
  int i;

  for(i=0; i<city_size; i++) is_searched[i]=0;
  for(i=0; i<city_size; i++) d[i]=max_distance*n+1;
  d[from]=0;

  while(1){
    min_d=max_distance*n+1;
    for(i=0; i<city_size; i++){
      if(!is_searched[i] && d[i]<min_d){
	min_d=d[i];
	min_city=i;
      }
    }
    if(min_city==to) break;

    for(i=0; i<n; i++){
      if(roads[i].from==min_city){
	if(d[roads[i].to]>min_d+roads[i].distance) d[roads[i].to]=min_d+roads[i].distance;
      }
      else if(roads[i].to==min_city){
	if(d[roads[i].from]>min_d+roads[i].distance) d[roads[i].from]=min_d+roads[i].distance;
      }
    }
    is_searched[min_city]=1;
  }

  return d[to];
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<map>
#include<unordered_map>
#define mod 1000000007
using namespace std;
#define LL long long int 
LL dfs(LL src,vector<LL> *adj,vector<bool> &vis)
{
    if(vis[src]==false)
    {
        vis[src]=true;
        LL c=1;
        for(auto it:adj[src])
        {
            if(vis[it]==false)
            {
                c+=dfs(it,adj,vis);
            }
        }
        return c;
    }
    return 0;
}
int main() 
{
    
   
    LL N, M;
    cin >>  N  >> M;
    vector<LL> adj[N+1];
    for(LL i=0;i<M;i++)
    {
        LL x,y;
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    LL ans=0;
    vector<bool> vis(N+1,false);
    for(LL i=1;i<=N;i++)
    {
        if(vis[i]==false)
        {
            LL count=dfs(i,adj,vis);
            ans=max(ans,count);
        }
    }
    cout<<ans;
 
}
 

Measured memory_bytes: 27060
n = gets.chomp.to_i

list = []
n.times do
  list
  command, x = gets.chomp.split
  
  command
  case command
  when "insert"
    list.unshift x
  when "delete"
    list.delete_at(list.index(x)) if list.index(x)
  when "deleteFirst"
    list.shift
  when "deleteLast"
    list.pop
  end
end

(list.size-1).times do |i|
  print "#{list[i]} "
end
print "#{list.last}\n"

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

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

    int ct = 0;
    for (int i=1; i<=N; i++) {
        string s = to_string(i);
        if (s.size() % 2 == 1) ct++;
    }

    cout << ct << endl;

    return 0;
}

Measured memory_bytes: 256
<?php
list($a) = strs();
list($b) = strs();
if (strlen($a) > strlen($b)) exit('GREATER');
if (strlen($a) < strlen($b)) exit('LESS');
for ($i = 0; $i < strlen($a); ++$i) {
    if ((int) $a[$i] > (int) $b[$i]) exit('GREATER');
    if ((int) $a[$i] < (int) $b[$i]) exit('LESS');
}
echo 'EQUAL';
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}


Measured memory_bytes: 4856
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 820000
using namespace std;
int f[N][32],g[N][32];
int tot,sum[N],n,v,a[N],b[N];
int l[N],r[N];
int check(int x,int y){
	x++;
	if(f[x][tot]<y-1)return 0;
	y=f[x][tot];
	x=g[y][tot];
	sum[x]++;
	sum[y+1]--;
}
int cal(){
	memset(r,0x7f,sizeof(r));
	memset(l,0,sizeof(l));
	r[0]=n+1;
	for(int i=0;i<1<<tot;i++){
		for(int j=1;j<=tot;j++){
			if(i&(1<<(j-1)))continue;
			l[i|(1<<(j-1))]=max(l[i|(1<<(j-1))],f[l[i]+1][j]);
			r[i|(1<<(j-1))]=min(r[i|(1<<(j-1))],g[r[i]-1][j]);
			if(l[i]==n)l[i|(1<<(j-1))]=n;
			if(r[i]==1)r[i|(1<<(j-1))]=1;
		}
	}
	int o=(1<<(tot-1))-1;
	for(int i=0;i<=o;i++){
		check(l[i],r[o^i]);
	}
	for(int i=0;i<=n;i++)sum[i]+=sum[i-1];
}
int main(){
	scanf("%d%d",&n,&v);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	while(v)b[++tot]=v,v/=2;
	b[++tot]=v;
	sort(b+1,b+1+tot);
	for(int i=1;i<=tot;i++)f[n][i]=n;
	for(int i=n-1;i>=1;i--){
		for(int j=1;j<=tot;j++){
			if(a[i+1]-a[i]<=b[j])f[i][j]=f[i+1][j];
			else f[i][j]=i;
		}
	}
	for(int i=1;i<=tot;i++)f[n+1][i]=n;
	for(int i=1;i<=tot;i++)g[1][i]=1;
	for(int i=2;i<=n;i++){
		for(int j=1;j<=tot;j++){
			if(a[i]-a[i-1]<=b[j])g[i][j]=g[i-1][j];
			else g[i][j]=i;
		}
	}
	for(int i=1;i<=tot;i++)g[0][i]=1;
	cal();
	for(int i=1;i<=n;i++){
		if(sum[i]>0)printf("Possible\n");
		else printf("Impossible\n");
	}
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll N;
    cin >> N;
    string S;
    cin >> S;

    vec R, G, B;
    REP(i,0,N) {
        if(S[i] == 'R') R.pb(i);
        else if(S[i] == 'G') G.pb(i);
        else B.pb(i); 
    }
    ll ans = SZ(R) * SZ(G) * SZ(B);
    REP(i,0,N-1) {
        REP(k,i+1,N) {
            if((i + k) % 2 == 0) {
                ll j = (i + k) / 2;
                if(S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) --ans;
            }
        }
    }
    _PR(ans);

    return 0;
}

/*



*/

Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;



int main(){

  int n,i;
  cin >> n;
  int a[n];
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  int max1=0;
  int max2=0;
  int b[2] = {-1,-1};
  for(i=0;i<n;i++){
    if(a[i] > max1){
      max1 = a[i];
      b[0] = i;
    }
    else if(a[i] > max2){
      max2 = a[i];
    }
  }

  for(i=0;i<n;i++){
    if(i == b[0]){
      cout << max2 << endl;
    }
    else{
      cout << max1 << endl;
    }
  }

  return 0;

}

Measured memory_bytes: 2432
#!/usr/bin/env python3
import sys

def is_prime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    i = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += 1
    return True

def is_ok(n):
    if n % 2 == 1 and is_prime(n) and is_prime((n + 1) // 2):
        return True
    return False

def solve(Q: int, l: "List[int]", r: "List[int]"):
    N = 100000
    tmp = [0] * (N + 2)
    tmp[0] = 0
    tmp[1] = 0
    for i in range(1, N + 1):
        tmp[i + 1] = tmp[i]
        if is_ok(i):
            #print(i)
            tmp[i + 1] += 1
    #print(tmp[:10])
    for q in range(Q):
        ret = tmp[r[q] + 1] - tmp[l[q]]
        print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    Q = int(next(tokens))  # type: int
    l = [int()] * (Q)  # type: "List[int]" 
    r = [int()] * (Q)  # type: "List[int]" 
    for i in range(Q):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(Q, l, r)

if __name__ == '__main__':
    main()


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

#define sz(s) (int)(s).size()
#define re(i, n) for (int i = 1; i <= n; i ++)
#define pb push_back
#define finish(x) return cout << x << endl, 0
#define MP make_mair
#define trav(x, a) for(auto& x: a)
#define all(x) (x).begin,(x).end()
#define Sor(x) sort(all(x))
#define REV(x) reverse(all(x))
#define F first
#define S second
#define I insert
#define N 222222
#define MOD 100000007

using namespace std;

typedef long long ll;
vector <ll> vll;
template <class T> bool umin(T& a, T b) {if(a>b){a = b; return 1;}return 0;}
template <class T> bool umax(T& a, T b) {if(a<b){a=b; return 1;}return 0;}
template <class T, class TT> bool pal(T a, TT n){int k = 0; for(int i =0; i <= n / 2; i ++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

ll powmod(ll a, ll b, ll m = MOD){ll r = 1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}


int main()
{	
	int n, m;
	cin >> n >> m;
	m *= 2;
	if (n - m < 0)
		cout << "0";
	else
		cout << n - m;









	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9+5;
const int mod = 998244353;

vector<int> fac(300001); //n!(mod M)
vector<int> ifac(300001); //k!^{M-2} (mod M)

long long fpow(long long a,long long n){
  long long ret=1;
  if(n==1) return a;
  if(n%2==0) {
      ret = fpow(a*a%mod, n/2) %mod ;
  }else {
      ret = (a%mod)*fpow(a*a%mod, n/2) %mod;
  }
  return ret %mod;
}
int comb(int a, int b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    int tmp = ifac[a-b]* ifac[b] % mod;
    return tmp * fac[a] % mod;
}
const double PI=3.14159265358979323846;
int dp[3002][3002];
signed main(){
    int n, m;
    cin >> n >> m;

    vector<vector<int>> to(n);
    rep(i, m) {
        size_t a, b;
        cin >> a>>b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    queue<int> que;
    vector<int> arr(n,-1);
    que.push(0);
    int le = 1;
    while(que.size()!=0) {
        int now = que.front();
        que.pop();
        for(auto num: to[now]) {
            if(arr[num]!= -1) continue;
            que.push(num);
            arr[num] = now;
        }
    }
    cout << "Yes" << endl;
    FOR(i, 1, n) cout << arr[i]+1 << endl;
    


}



Measured memory_bytes: 17524
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define pi 3.14159265359
#define INF 1000000000

int main() {
    int N;
    cin >> N;
    float num;
    if (N % 2 == 0) num = N / 2;
    else num = N / 2 + 1;
    cout << num / N << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
 
const int N = 1e5 + 5;
 
int n, m, k;
int x11, y11, x2, y2;
int dx[4]={-1, +1, 0, 0};
int dy[4]={0, 0, +1, -1};
vector<vector<char> > a;
vector<vector<int> > vis, ways, dist;
 
void bfs(int x, int y)
{
	queue<pair<int, int> > q;
	q.push({x, y});
	vis[x][y] = 1;
	dist[x][y] = 0;
	while(!q.empty())
	{
		int x=q.front().first;
		int y=q.front().second;
		q.pop();
		for(int dir=0;dir<4;dir++)
		{
			for(int len = 1; len <= k; len++)
			{
				int nx=x+dx[dir] * len;
				int ny=y+dy[dir] * len;
				if(nx<1 || ny<1 || nx>n || ny>m)
					break;
				if(vis[nx][ny] && dist[x][y] + 1 > dist[nx][ny])
					break;
				if(a[nx][ny] == '@')
					break;
				if(vis[nx][ny])
					continue;
				dist[nx][ny]=dist[x][y]+1;
				vis[nx][ny]=1;
				q.push({nx, ny});
			}
		}
	}
}
 
int32_t main()
{
	IOS;
	cin >> n >> m >> k;
	cin >> x11 >> y11 >> x2 >> y2;
	a = vector<vector<char> > (n + 1, vector<char> (m + 1));
	vis = ways = dist = vector<vector<int> > (n + 1, vector<int> (m + 1, 0));
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			cin >> a[i][j];
	bfs(x11, y11);
	if(!vis[x2][y2])
		cout << -1;
	else
		cout << dist[x2][y2];
	return 0;
}


Measured memory_bytes: 32500
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct modint{
    ll a;
    const ll MOD=1e9+7;
    modint(ll a_=0){
        a=((a_%MOD)+MOD)%MOD;
    }
    modint inv()const{
        ll n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y(n);
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y(a+x.a);
        return y;
    }
    modint operator-(const modint& x){
        modint y(a-x.a);
        return y;
    }
    modint operator*(const modint& x){
        modint y(a*x.a);
        return y;
    }
    modint operator/(const modint& x){
        return *this * x.inv();
    }
    modint& operator+=(const modint& x){
        *this=*this+x;
        return *this;
    }
    modint& operator-=(const modint& x){
        *this=*this-x;
        return *this;
    }
    modint& operator*=(const modint& x){
        *this=*this*x;
        return *this;
    }
    modint& operator/=(const modint& x){
        *this=*this/x;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    ll a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(ll a,ll b){
    modint n(1),A(a);
    while(b){
        if(b&1) n*=A;
        A*=A;
        b>>=1;
    }
    return n;
}

vector<modint> fc;
modint fct(ll x) {
    if(fc.empty()) fc.resize(100010);
    if(x==0) return 1;
    if(fc[x]==0) fc[x]=fct(x - 1)*x;
    return fc[x];
}

vector<modint> ifc;
modint ifct(ll x) {
    if(ifc.empty()) ifc.resize(100010);
    if(x==100010-1) return ifc[x]=fct(x).inv();
    if(ifc[x] == 0) ifc[x]=ifct(x+1)*(x+1);
    return ifc[x];
}

modint perm(ll n, ll r) {
    if (n < 0 || r < 0 || n < r) return 0;
    return fct(n)*ifct(n-r);
}

void bfs(modint& ans,vector<vector<int>>& v,int k,int i=0,int p=-1){
    if(p<0) ans*=perm(k-1,v[0].size());
    else ans*=perm(k-2,v[i].size()-1);
    for(auto j:v[i]) if(j!=p) bfs(ans,v,k,j,i);
}

class EVirusTree2 {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,k,a,b;
        in>>n>>k;
        vector<vector<int>> v(n);
        fr(i,n-1){
            in>>a>>b;
            v[--a].emplace_back(--b);
            v[b].emplace_back(a);
        }
        modint ans(k);
        bfs(ans,v,k);
        out<<ans<<endl;
    }
};

int main() {
    EVirusTree2 solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 15104
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF 1000000000000000007

typedef long long i64;
typedef pair<i64,i64> P;


int n;
string s[101010];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s[i];
		sort(s[i].begin(),s[i].end());
	}
	
	sort(s, s+n);
	i64 ans = 0;
	for(int i = 0; i < n; i++){
		ans += (upper_bound(s+i,s+n,s[i])-lower_bound(s+i,s+n,s[i])) - 1;
	}
	
	cout << ans <<endl;
	
	return 0;
}

Measured memory_bytes: 7296
#include<stdio.h>

int main(void){

 int a,b;

 scanf("%d %d",&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: 580
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
	int q;
	cin>>q;
	ll dif = 0;
	REP(i,q){
		int t,n;
		char c;
		cin>>t>>c>>n;
		if(c=='('){
			dif += n;
		}else{
			dif -= n;
		}
		if(dif==0)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 856
/*
[ ( ^ _ ^ ) ]
*/

// problem: atc/abc161_c

import java.io.*;
import java.util.*;


public class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;


    long min(long a, long b) {return a<=b?a:b;}
    long abs(long a) {return a>=0?a:-a;}

    void solve(InputReader in, PrintWriter out) throws IOException {
        long n = in.nextLong();
        long k = in.nextLong();
        if(n>=k) {
            out.println(min(n%k, k-n%k));
        }
        else {
            out.println(min(n, abs(n-k)));
        }
    }
    

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 22484
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define inf 1e16
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define M 1000010

int main(){
	IOS;
	ll n;cin>>n;
	ll ans=n*(n-1)/2;
	cout<<ans;
	
	return 0;
}



Measured memory_bytes: 256
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let list = input
        .split_whitespace()
        .skip(1)
        .map(|x| x.parse::<i32>().unwrap())
        .fold((0, 0, 0), |(a, b, c), x| {
            if x % 4 == 0 {
                (a + 1, b, c)
            } else if x % 2 == 0 {
                (a, b + 1, c)
            } else {
                (a, b, c + 1)
            }
        });
    let (a, b) = (list.0, list.2 + if list.1 == 0 { 0 } else { 1 });
    if a >= b - 1 { "Yes" } else { "No" }.to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!(super::run($input.to_string()), $output.to_string());
                }
            )*
        }
    }
}

tests! {
    test1: "3
1 10 100" => "Yes",
    test2: "4
1 2 3 4" => "No",
    test3:"3
1 4 1"=>"Yes",
    test4:"2
1 1"=>"No",
test5:"6
2 7 1 8 2 8"=>"Yes",
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    string s;
    cin>>s;
    if (s.compare("Sunny")==0)
    printf("Cloudy\n");
    else if (s.compare("Cloudy")==0)
    printf("Rainy\n");
    else
    printf("Sunny\n");
    return 0;
}

Measured memory_bytes: 3620
N = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = []
sum = 0

for i in range(len(a)):
  if a[i]-b[i] > 0:
    c.append(a[i]-b[i])
  else:
    continue
    

for i in range(len(c)):
  sum = sum + c[i]
  
print(sum)

Measured memory_bytes: 3060
n, k = map(int, input().split())
truck = [0] * k
w = []

for _ in range(n):
    w.append(int(input()))


def is_ok(p):
    truck_index = 0
    w_index = 0
    while w_index < n and truck_index < k:
        load_sum = 0
        while w_index < n and load_sum + w[w_index] <= p:
            load_sum += w[w_index]
            w_index += 1
        truck_index += 1
    return w_index == n


ng = 0
ok = 100000 * 100000

while ok - ng > 1:
    mid = (ng + ok) // 2
    if is_ok(mid):
        ok = mid
    else:
        ng = mid

print("%d" % ok)



Measured memory_bytes: 9592
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

template <class num> struct LST {
private:
	int n;
	vector<num> node, lazy;
	void eval(int k, int l, int r) {
		if (lazy[k] != 0) {
			node[k] += lazy[k];
			if (r - l > 1) {
				lazy[2 * k + 1] += lazy[k] / 2;
				lazy[2 * k + 2] += lazy[k] / 2;
			}
			lazy[k] = 0;
		}
	}
public:
	LST(vector<num> v) {
		int sz = v.size();
		n = 1; while (n < sz)n *= 2;
		node.resize(n * 2 - 1, 0);
		lazy.resize(n * 2 - 1, 0);

		for (int i = 0; i < sz; i++)node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--)node[i] = min(node[2 * i + 1], node[2 * i + 2]);
	}
	void update(int a, int b, num x, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = n;
		eval(k, l, r);

		if (b <= l || r <= a)return;
		if (a <= l && r <= b) {
			lazy[k] += (r - l)*x;
			eval(k, l, r);
		}
		else {
			update(a, b, x, 2 * k + 1, l, (l + r) / 2);
			update(a, b, x, 2 * k + 2, (l + r) / 2, r);
			node[k] = node[2 * k + 1] + node[2 * k + 2];
		}
	}
	num get(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0)r = n;
		if (b <= l || r <= a)return 0;
		eval(k, l, r);
		if (a <= l && r <= b)return node[k];
		return get(a, b, 2 * k + 1, l, (l + r) / 2) + get(a, b, 2 * k + 2, (l + r) / 2, r);
	}
};
int main() {
	int n, q;
	cin >> n >> q;
	LST<ll> lst(vector<ll>(n+1, 0));
	for (int i = 0; i < q; i++) {
		int c;
		cin >> c;
		if (c) {
			int s, t;
			cin >> s >> t;
			cout << lst.get(s, t+1) << endl;
		}
		else {
			int s, t, x;
			cin >> s >> t >> x;
			lst.update(s, t+1, x);
		}
	}
}


Measured memory_bytes: 7584
n = int(input())

ret = sum(list(range(1,n+1)))
sub3 = sum(list(range(3,n+1,3)))
sub5 = sum(list(range(5,n+1,5)))
sub15 = sum(list(range(15,n+1,15)))
ret = ret - sub3 - sub5 + sub15
print(ret)

Measured memory_bytes: 48524
#include<stdio.h>
#include<math.h>


int main(void)
{
	double a,b,c;
	double h,rad;
	
	scanf("%lf %lf %lf",&a,&b,&c);
	
	rad=c*M_PI/180;
	h=b*sin(rad);
	
	
	printf("%lf %lf %lf \n",a*h/2,a+b+sqrt(a*a+b*b-2*a*b*cos(rad)),h);
	
	return 0;
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

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;
}
///////////////////////////////////////////////
int main(){
    int n;
    cin >> n;
    while(true){
        if (n % 111 == 0){
            cout << n << "\n";
            return 0;
        }
        n++;
    }
}



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

#define SIZE 1010
int n, a[SIZE][SIZE], b[SIZE][SIZE], c[SIZE][SIZE];
bool vis[SIZE][SIZE], f = false;

int dfs(int x, int y)
{
    if (y < 0)
        return 0;
    if (c[x][y] >= 0)
        return c[x][y];
    if (vis[x][y])
    {
        f = true;
        return 0;
    }
    vis[x][y] = true;
    int p = a[x][y], q = b[a[x][y]][x];
    return c[x][y] = c[p][q] = max(dfs(x, y - 1), dfs(p, q - 1)) + 1;
}

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

    cin >> n;
    rep(i, n) rep(j, n - 1)
    {
        cin >> a[i][j];
        a[i][j]--;
        b[i][a[i][j]] = j;
        c[i][j] = -1;
    }
    int ans = 0;
    rep(i, n) rep(j, n - 1) if (!vis[i][j]) ans = max(ans, dfs(i, j));
    cout << (f ? -1 : ans) << endl;
}

Measured memory_bytes: 25216
# coding: utf-8
N=int(input())
A=list(map(int,input().split()))

ans=1
flg=True

for i in range(N):
    ans*=A[i]
    if ans>10**18:
        flg=False
        break
for i in range(N):
    if A[i]==0:
        flg=True
        ans=0
        break

if flg:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 21792
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define endl '\n'

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = 1e5;
int n, ans;
int freq[2][N + 5];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int x; scanf("%d", &x);
		freq[i % 2][x]++;
	}
	
	int t[2]{};
	for (int k = 0; k < 2; k++) {
		int mx = 0;
		for (int i = 1; i <= N; i++) {
			if (mx < freq[k][i]) {
				t[k] = i;
				mx = freq[k][i];
			}
		}
		ans += mx;
	}
	
	if (t[0] == t[1]) {
		ans -= freq[0][t[0]];
		freq[0][t[0]] = freq[1][t[1]] = 0;
		ans += max(*max_element(&freq[0][0], &freq[1][0]), *max_element(&freq[1][0], &freq[2][0]));
	}
	
	printf("%d\n", n - ans);
}

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

char S[55][55];
int cnt[55][26];

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

int main(){

	int n;

	scanf("%d",&n);

	int i,j;

	for(i=0;i<n;i++){
		scanf("%s",S[i]);
	}

	for(i=0;i<n;i++){
		int len=strlen(S[i]);
		for(j=0;j<len;j++){
			cnt[i][S[i][j]-'a']++;
		}
	}

	for(i=0;i<26;i++){
		int flag=100;
		for(j=0;j<n;j++){
		flag=min(flag,cnt[j][i]);
		}
		for(j=0;j<flag;j++){
		printf("%c",i+'a');
		}
	}

	printf("\n");

	return 0;
}

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

public class Main {


    public static void main(String[] args) throws Exception {

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] s = in.readLine().split(" ");
        int N = Integer.parseInt(s[0]);
        int M = Integer.parseInt(s[1]);
        s = in.readLine().split(" ");
        int[] h = new int[N];
        for(int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(s[i]);
        }
        HashMap<Integer, HashSet<Integer>> map = new HashMap<>();
        HashSet<Integer> dead = new HashSet<>();
        while(M-- > 0) {
            s = in.readLine().split(" ");
            int A = Integer.parseInt(s[0]);
            int B = Integer.parseInt(s[1]);
            if(h[A - 1] > h[B - 1]) {
                dead.add(B);
            } else if(h[B - 1] > h[A - 1]) {
                dead.add(A);
            } else {
                dead.add(A);
                dead.add(B);
            }
            if(map.containsKey(A)) {
                if(map.get(A).contains(B)) {
                    //dead.add(A);
                    //dead.add(B);
                    map.remove(A);
                    map.remove(B);
                } else {
                    map.get(A).add(B);
                    if(map.containsKey(B)) {
                        map.get(B).add(A);
                    } else {
                        HashSet<Integer> set = new HashSet<>();
                        set.add(A);
                        map.put(B, set);
                    }
                }
            } else {
                HashSet<Integer> set = new HashSet<>();
                set.add(B);
                map.put(A, set);
                set = new HashSet<>();
                set.add(A);
                map.put(B, set);
            }
        }
        System.out.println(N - dead.size());

    }

}


Measured memory_bytes: 85580
//10^N + 8^N - 2*9^N mod 1e9+7
#include <iostream>
using namespace std;
int main() {
    long long n, i = 0,  a = 10, b = 9, c = 8, mod = 1000000007; cin >> n;
    for(; i < n - 1; i++) {
        a *= 10; a %= mod;
        b *= 9;  b %= mod;
        c *= 8;  c %= mod;
    }
    a += c; a %= mod;
  cout << (a - (2 * b) % mod + mod) % mod << endl;
}

Measured memory_bytes: 3564
#include <cstdio>
int main(){
    int S;
    scanf("%d",&S);
    int h = S / 3600;
    int m = (S % 3600) / 60;
    int s = (S % 3600) % 60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2696
#pragma region header
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int x;cin >> x;
    int ans = 0;
    ans += 1000*(x/500);
    x%=500;
    ans+=5*(x/5);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

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

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;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}


int main() {
    int n,tmp;
    cin >> n;
    tmp = n%10;
    if(tmp == 3) cout << "bon" << endl;
    else if(tmp == 0 ||tmp == 1 ||tmp == 6 ||tmp == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
    return 0;
}

Measured memory_bytes: 3592
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] K = new int[N + 1];
		int[][] A = new int[N + 1][M + 1];
		for (int i = 1; i <= N; i++) {
			K[i] = sc.nextInt();
			for (int j = 1; j <= K[i]; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		int ans = 0;

		int[] count = new int[M + 1];

		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= K[i]; j++) {
				count[A[i][j]]++;
			}
		}

		for (int i = 1; i <= M; i++) {
			if (count[i] == N)
				ans++;
		}

		System.out.println(ans);

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define itn int
#define gI gi

using namespace std;

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

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int n, m, x, y, z, a[5], maxx;
string s[200003];
map <string, int> p;
set <string> pp;
vector <string> vv;

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	cin >> n;
	for (int i = 1; i <= n; i+=1) cin >> s[i], p[s[i]] += 1, maxx = max(maxx, p[s[i]]);
	for (int i = 1; i <= n; i+=1)
	{
		if (p[s[i]] == maxx) 
		{
			pp.insert(s[i]);
		}
	}
	for (auto s : pp) vv.push_back(s);
	sort(vv.begin(), vv.end());
	for (int i = 0; i < vv.size(); i+=1) cout << vv[i] << endl;
	return 0;
}


Measured memory_bytes: 37876
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
using namespace std;

int N, R, p, c;

void show(vector<int> v){
    for (int i = 0; i < N; i++){
        cout << v[i] << " ";
    }
    cout << endl;
}

int main(){
    while (cin >> N >> R && N){
        vector<int> card(N);
        for (int i = 0; i < N; i++){
            card[i] = N - i;
        }
        //cout << "初期入力"<< endl;
        //show(card);

        for (int i = 0; i < R; i++){
            cin >> p >> c;
            rotate(card.begin(), card.begin()+p-1, card.begin()+p+c-1);
            //cout << i+1 << "回目のrotate" << endl;
            //show(card);
        }
        cout << card[0] << endl;
    }
}



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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    string f, r;
    int ans = 0;
    for(int i=a;i<=b;i++) {
        f = to_string(i);
        r = to_string(i);
        reverse(r.begin(), r.end());
        if(f==r) ans++;
    }

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


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Test
{
    public static void Main()
    {
        string s = Console.ReadLine();
        string[] ss = s.Split(' ');
        
        List<int> li = new List<int>();
        
        for(int i = 0; i < ss.Length; i++)
        {
            li.Add(int.Parse(ss[i]));
        }
        
        li.Sort();
        
        Console.WriteLine(li[0] + " " + li[1] + " " + li[2]);
    }
}


Measured memory_bytes: 15976