akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    N, K = map(int, input().split())
    print(N - K + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
def distance(x1,y1,x2,y2)
  dx, dy=x1-x2, y1-y2
  Math.sqrt(dx**2 + dy**2)
end
N=gets.to_i
XY=N.times.map{gets.split.map(&:to_i)}

sum = 0.0
cnt = 0
(0..N-1).to_a.permutation.to_a.each do |n|
  cnt += 1
  now = n.shift
  n.each do |i|
    nextt = i
    x1, y1 = XY[now]
    x2, y2 = XY[nextt]
    sum += distance(x1,y1,x2,y2)
  end
end

puts sum/cnt

Measured memory_bytes: 6780
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using P = pair <int, int>;
 
int sumdigit(int x){
  if(x/10==0) return x;
  return sumdigit(x/10)+x%10;
  }

int main(){
    
   int n,a,b;
   cin >>n >>a>>b;
   int cnt=0;
   for(int i = 1 ; i<=n;++i){
      if(a<=sumdigit(i)&&sumdigit(i)<=b) cnt+=i; 
   }
   cout << cnt << endl;
}

Measured memory_bytes: 256
def f(x,y,z):
    return max(x,y,z)-min(x,y,z)

h, w = map(int, input().split())
l = []
ans1, ans2 = h*w, h*w
for i in range(1,h//2+1):
        s1 = i*w
        s2 = w*((h-i)//2)
        s3 = h*w-s1-s2
        s4 = (h-i)*(w//2)
        s5 = h*w-s1-s4
        ans1 = min(ans1, f(s1,s2,s3),f(s1,s4,s5))

for i in range(1,w//2+1):
        s1 = i*h
        s2 = h*((w-i)//2)
        s3 = h*w-s1-s2
        s4 = (w-i)*(h//2)
        s5 = h*w-s1-s4
        ans2 = min(ans2, f(s1,s2,s3),f(s1,s4,s5))
print(min(ans1,ans2))


Measured memory_bytes: 3064
def count_sum_generated_biscuit():
  generation_interval_sec,\
  biscuit_per_generation,\
  initial_target_sec = [int(x) for x in input().split()]
  
  target_sec = initial_target_sec + 0.5
  sum_generated_biscuit\
  = (target_sec // generation_interval_sec) * biscuit_per_generation
  
  return int(sum_generated_biscuit)
  
if __name__ == '__main__':
  print(count_sum_generated_biscuit())

Measured memory_bytes: 2940
N, M = map(int, input().split())

d = 1
ds = []
while d ** 2 <= M:
    if M % d == 0:
        ds.append(d)
        ds.append(M // d)
    d += 1
ds.sort(reverse=True)
for d in ds:
    if N * d <= M:
        print(d)
        break

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

class hoge{
public:
	hoge(int x,int y,int cost){this->x=x;this->y=y;this->cost=cost;}
	int x,y,cost;
	bool operator<(const hoge h)const{return this->cost<h.cost;}
	bool operator>(const hoge h)const{return this->cost>h.cost;}
};

string str[1010];
int di[1010][1010];
priority_queue<hoge,vector<hoge>,greater<hoge> > d;
int h,w,n;

int dis(int ax,int ay,int bx,int by){
	while(!d.empty())d.pop();
	memset(di,-1,sizeof(di));
	hoge tmp(ax,ay,0);
	d.push(tmp);
	while(!d.empty()){
		hoge top=d.top();
		int x=top.x;
		int y=top.y;
//cout<<x<<" "<<y<<" "<<top.cost<<endl;
		d.pop();
		if(x<0||w<=x||y<0||h<=y)continue;
		if(di[y][x]!=-1&&di[y][x]<=top.cost)continue;
		if(str[y][x]=='X')continue;
		di[y][x]=top.cost;
		top.cost++;
		top.x++;
		d.push(top);
		top.x--;
		top.x--;
		d.push(top);
		top.x++;
		top.y++;
		d.push(top);
		top.y--;
		top.y--;
		d.push(top);
	}
	return di[by][bx];
}

int main() {
	cin>>h>>w>>n;
	int i,j,k;
	for(i=0;i<h;i++){
		cin>>str[i];
	}
	int ax,ay,bx,by,res=0;
	for(i=1;i<=n;i++){
		if(i==1){
			for(j=0;j<h;j++){
				for(k=0;k<w;k++){
					if(str[j][k]=='S'){
						ax=k;
						ay=j;
					}
					if(str[j][k]=='0'+i){
						bx=k;
						by=j;
					}
				}
			}
			res+=dis(ax,ay,bx,by);
		}else{
			for(j=0;j<h;j++){
				for(k=0;k<w;k++){
					if(str[j][k]=='0'+i-1){
						ax=k;
						ay=j;
					}
					if(str[j][k]=='0'+i){
						bx=k;
						by=j;
					}
				}
			}
			res+=dis(ax,ay,bx,by);
		}
	}
	cout<<res<<endl;
	return 0;
}

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

#include <bits/stdc++.h>
#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF 1e9
#define INFL 1e18
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

class BPapersPlease {
public:
	void solve(std::istream& in, std::ostream& out) {
        int N;
        in >> N;
        int A[N];
        string ans = "APPROVED";
        REP(i, N) {
            int a;
            in >> a;
            if (a % 2 != 0) continue;
            if (a % 3 != 0 && a % 5 != 0) {
                ans = "DENIED";
                break;
            }
        }
        out << ans << '\n';
    }
};


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


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

using namespace std;

int main()
{
    int n;
    string s;
    cin>>s;
    n=s.length();
    stack<char>ss;
    for(int i=0;i<n;i++)
    {
    	if(ss.empty())
    		ss.push(s[i]);
    	else
    	{
    		//cout<<ss.top()<<" "<<s[i]<<endl; 
    		if((ss.top()=='0' && s[i]=='1') || (ss.top()=='1' && s[i]=='0'))
    			ss.pop();
			else
				ss.push(s[i]);
		}
	}
    cout<<n-ss.size()<<endl;
	return 0;
}

Measured memory_bytes: 512
sub f{
	for(grep$$a{$_},keys%{$a=$_}){
		if(!$v[$_]){
			$v[$_]=1;
			++$c;
			&f
		}
	}
}
($N,$M)=glob<>;
/ /,${$`}{$'+0}=${$'+0}{$`}=1for@ab=<>;
for(@ab){
	/ /;
	${$`}{$'+0}=${$'+0}{$`}=0;
	@v=();
	$c=1;
	$v[1]=1;
	f$_=1;
	$x+=$c<$N;
	${$`}{$'+0}=${$'+0}{$`}=1
}
print$x


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

using namespace std;

typedef long long ll;
typedef long double ld;
long double MAX = 10000009.0;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n,m;
    cin>>n>>m;
    ll a[m]={0};
    ll sum = 0;
    for(ll i=0;i<m;i++)
    {
        cin>>a[i];
        sum = sum + a[i];
    }
    if(sum<=n)
        cout<<n-sum<<endl;
    else
        cout<<-1<<endl;
    return 0;
}


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

#define lli long long int
#define ld long double
#define DEFO(n) lli n = 0;
#define MAX_L lli max = 9000000000000000000;
#define MIN_L lli min = 9000000000000000000;
#define MAX_D ld max = 4500;
#define MIN_D ld min = -4500;
#define LLI(n) \
  lli n;       \
  cin >> n;
#define LD(n)  \
  ld n;        \
  cin > n;
#define LLIV(a, n)            \
  vector<lli> a(n);           \
  for (lli i = 0; i < n; i++) \
  {                           \
    cin >> a.at(i);           \
  };
#define LLIV2(a, b, n)            \
  vector<lli> a(n), b(n);           \
  for (lli i = 0; i < n; i++) \
  {                           \
    cin >> a.at(i) >> b.at(i);           \
  };
#define LDV(a, n)            \
  vector<ld> a(n);           \
  for (lli i = 0; i < n; i++) \
  {                           \
    cin >> a.at(i);           \
  };
#define STR(n) \
  string n;    \
  cin >> n;
#define SUM(n) accumulate(n.begin(), n.end(), 0);
#define SORT(n) sort(n.begin(), n.end());
#define REVE(n) reverse(n.begin(), n.end());
#define yes cout << "Yes" << endl; return 0;
#define no cout << "No" << endl; return 0;
#define C45(n) (n + 1) / 2
#define OUT(n) cout << n << endl;
#define SRC(n, c)                    \
  for (lli i = 0; i < s.size(); i++) \
  {                                  \
    if (s.at(i) == c)                \
    {                                \
      n++;                           \
    }                                \
  };
//こぴー
/*#define ZISYO(s, S)                  \
  for (lli i = 0; i < s.size(); i++) \
  {                                  \
    S.at(i) = s.at(i);               \
  }                                  \
  Sort(S) Reve(S) for (lli i = 0; i < s.size(); i++) { s.at(i) = S.at(i); };
*/

//素数
bool IsPrime(lli num)
{
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  long double sqrtNum = sqrt(num);
  for (lli i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)
      return false;
  }
  return true;
}
//各桁の和
lli KSum(lli n)
{
  lli sum = 0;
  if (n < 0)
    return 0;
  while (n > 0)
  {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

//数値反転
bool KReve(lli n)
{
  int reverse = 0;
  int remaind;
  int tmp = n;
  while (tmp != 0)
  {
    remaind = tmp % 10;
    reverse = reverse * 10 + remaind;
    tmp /= 10;
  }
  if (reverse == n) 
    return true;
  else
    return false;
}

int main(void)
{
  ios::sync_with_stdio(false);
  LLI(N) LLI(K) LLIV(a, N) SORT(a) REVE(a) DEFO(sum)
  for(lli i = 0;i < K;i++) {
    sum += a[i];
  }
  OUT(sum)
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps=1e-8;
int main() {
	int n, m; cin >> n >> m;
	int out[200000];
	fill(out, out + n, 1);
	vector<P> machine; int d, x;
	rep(i, m) {
		cin >> d >> x; x--;
		machine.push_back({ d,x });
	}
	sort(machine.begin(), machine.end());
	int memo[200000] = {};
	rep(i, m) {
		int loc = machine[i].second;
		int r = out[loc] + out[loc+1]-2*memo[loc];
		out[loc] = out[loc + 1] = r+memo[loc];
		memo[loc] += r;
	}
	rep(i, n) {
		cout << out[i];
		if (i < n - 1) {
			cout << " ";
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 5108
#include <iostream>

using namespace std;


void insertion_sort(int *seq, int length) {
  int key, j;
  for (int i = 1; i < length; i ++) {
    key = seq[i];
    j = i - 1;
    while (j >= 0 && seq[j] > key) {
      seq[j + 1] = seq[j];
      j --;
    }
    seq[j + 1] = key;
  }
}


int main() {
  int n, q;
  int S[100000], T[50000];
  int count;

  cin >> n;
  for (int i = 0; i < n; i ++) {
    cin >> S[i];
  }
  cin >> q;
  for (int i = 0; i < q; i ++) {
    cin >> T[i];
  }
  insertion_sort(S, n);
  insertion_sort(T, q);

  for (int i = 0, j = 0; i < q && j < n; i ++) {
    if (i != 0 && T[i] == T[i-1]) continue;
    while (T[i] >= S[j]) {
      if (T[i] == S[j]) {
        count += 1;
        j++;
        break;
      }
      j++;
    }

  }
  cout << count << endl;

  return 0;
}



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

int bitcount(int n) {
    int cnt = 0;
    for ( ; n; n >>= 1) if (n & 1) cnt++;
    return cnt;
}

int main() {
    int n, k; cin >> n >> k;
    for (int b = 0; b < 1 << n; b++) {
        if (bitcount(b) != k) continue;
        cout << b << ":";
        for (int i = 0; i < n; i++) if (b >> i & 1) cout << " " << i;
        cout << endl;
    }
    return 0;
}


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

long long int n,a,b;
long long int v[100001];

bool check(long long int x){
    long long int c = 0;
    for(long long int i=0; i<n; i++){
        long long int h = v[i] - x * b;
        if(h <= 0){
            continue;
        }
        c += h / (a-b);
        if(h%(a-b)) c++;
    }
    return c <= x;
}

int main() {

    cin >> n >> a >> b;

    for(long long int i=0; i<n; i++){
        cin >> v[i];
    }

    long long int under = 0,ans = 1e9 + 1;

    while(under + 1 != ans){

        long long int x = (under + ans) / 2;
        if(check(x)){
            ans = x;
        }
        else{
            under = x;
        }

    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
applyBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
applyBin op f g x = op (f x) $ g x
applyUni :: (a -> b -> c) -> (a -> b) -> a -> c
applyUni op f x = op x $ f x
applyTuple :: (a -> b, a -> c) -> a -> (b, c)
applyTuple (f,g) a = (f a, g a)
-- end of templete

magicsq n = runST $ do
    arr <- newArray ((0,0),(n-1,n-1)) 0 :: ST s (STUArray s (Int,Int) Int)
    forM_ (zip [1..] (take n (iterate next' start) >>= take n . iterate next)) $ \(i, p) -> do
        writeArray arr p i
    sequence [concat <$> sequence [show' <$> readArray arr (x,y) | x <- [0..n-1]] | y <- [0..n-1]]
  where
    start = (div n 2, div n 2 + 1)
    next (x,y) = (mod (x+1) n, mod (y+1) n)
    next' (x,y) = (mod (x-1) n, mod (y+1) n)
    

show' n = replicate (4-length s) ' ' ++ s
  where
    s = show n

main = takeWhile (/=0) . map readInt . lines <$> getContents >>= mapM_ (mapM_ putStrLn . magicsq)

Measured memory_bytes: 4164
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }




int main() {

	ll N;
	cin >> N;
	vll A(N);
	rep(i, N) cin >> A[i];
	ll ans = 0;
	while (true) {
		bool flag = true;
		rep(i, N) {
			if (A[i] % 2 == 0) A[i] /= 2;
			else flag = false;
		}
		if (flag) ++ans;
		else break;
	}
	cout << ans << endl;
}

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;

int N, A, B, C, D;
bool ans = true;
string S;

void dfs(int posS, int posH){
  if(posS == C && posH == D){
    ans = true;
    return;
  }
  if(posS < C){
    if(S[posS+1] != '#' && posS + 1 != posH){
      dfs(posS+1, posH);
    }
    if(S[posS+2] != '#' && posS+2 != posH){
      dfs(posS + 2, posH);
    }
  }
  if(posH < D){
    if(S[posH+1] != '#' && posH+1 != posS){
      dfs(posS, posH + 1);
    }
    if(S[posH+2] != '#' && posH+2 != posS){
      dfs(posS, posH+2);
    }
  }
}

int main(){
  cin >> N >> A >> B >> C >> D;
  cin >> S;
  A--, B--, C--, D--;
  
  if(S[A] == '#' || S[B] == '#' || S[C] == '#' || S[D] == '#'){
    ans = false;
  }
  int cnt = 0;
  FOR(i, A, C+1){
    if(cnt == 2){
      ans = false;
    }
    if(S[i] == '#')
      cnt++;
    else{
      cnt = 0;
    }
  }
  cnt = 0;
  FOR(i, B, D+1){
    if(cnt == 2){
      ans = false;
    }
    if(S[i] == '#')
      cnt++;
    else{
      cnt = 0;
    }
  }

  cnt = 0;
  if(D < C){
    bool flag = false;
    FOR(i, B-1, D+2){
      if(cnt == 3){
        flag = true;
      }
      if(S[i] == '#'){
        cnt = 0;
      }
      else{
        cnt++;
      }
    }
    if(cnt == 3){
      flag = true;
    }
    if(!flag){
      ans = false;
    }
  }

  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 640
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Preparing Boxes
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

/* global variables */

int as[MAX_N + 1], bs[MAX_N], cs[MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", as + i);

  int m = 0;
  for (int i = n; i >= 1; i--) {
    int d = 0;
    for (int j = i * 2; j <= n; j += i) d ^= cs[j];
    cs[i] = d ^ as[i];
    if (cs[i]) bs[m++] = i;
  }

  printf("%d\n", m);
  if (m) {
    for (int i = m - 1; i >= 0; i--) {
      printf("%d", bs[i]);
      if (i) putchar(' ');
    }
    putchar('\n');
  }
  return 0;
}


Measured memory_bytes: 2944
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
   int flag=0,i=0;
   string s;
   cin>>s;
   while(i<=200){
      if(s[i] == 'C' && flag == 0) { flag ++; }
      if(s[i] == 'F' && flag == 1) { printf("Yes"); return 0; }
      i++;
   }
   printf("No");
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

// アルファベットの何番目であるか求めたあと，それにNを加えて26で割った余りが再び番号になる
int main() {
    int n; string s; cin >> n >> s;
    rep(i,s.size()) {
        int x = s[i]-'A';
        x = (x+n) % 26;
        putchar('A'+x);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll N;
	int a[100];
	ll i;
	ll ans=0;
	cin>>N;
	for(i=0;i<N;i++){
		cin>>a[i];
	}
	for(i=1;i<N;i++){
		if(a[i-1]==a[i]){
			a[i]=a[i+1]+1;
			if(a[i+1]==10000&&a[i-1]!=1) a[i]=1;
			ans++;
		}
	}
	cout<<ans<<endl;
}

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

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

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;

int main() {
	string s;
	int k;
	cin >> k >> s;
	if (SZ(s) <= k) {
		pv(s);
		return(0);
	}
	else {
		FOR(i,0,k-1){
			cout << s[i];
		}
		cout << "...\n";
		return(0);
	}
	return(0);
}

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

using namespace std;

using dijkstra_cost = double;
template<class V, class E>
struct Graph
{
	int sz;
	vector<V> v;
	vector<vector<E>> e;
	Graph(int n) : sz(n), v(n), e(n) {}
	template<class... Args>
	void assign_vertex(int pos, Args... args) {
		v[pos] = V(args...);
	}
	template<class... Args>
	void add_edge(int pos, Args... args) {
		e[pos].emplace_back(args...);
	}
	inline int size() {
		return sz;
	}
};

template<class T>
struct Vertex_Cost
{
	T cost;
	Vertex_Cost(T v1) : cost(v1) {}
	Vertex_Cost() {}
	bool operator<(const Vertex_Cost r) const {
		return cost < r.cost;
	}
	bool operator>(const Vertex_Cost r) const {
		return r < *this;
	}
	bool operator>=(const Vertex_Cost r) const {
		return !(*this < r);
	}
	bool operator<=(const Vertex_Cost r) const {
		return !(r < *this);
	}
	bool operator==(const Vertex_Cost r) const {
		return !(r < *this) && !(*this < r);
	}
	bool operator!=(const Vertex_Cost r) const {
		return (r < *this) || (*this < r);
	}
};
using vertex = Vertex_Cost<dijkstra_cost>;

template<class T>
struct Edge_Cost
{
	int to;
	T cost;
	Edge_Cost(int t, T c) : to(t), cost(c) {}
	Edge_Cost() {}
	inline bool operator<(const Edge_Cost rhs) const {
		return cost < rhs.cost;
	}
	inline bool operator>(const Edge_Cost rhs) const {
		return rhs < *this;
	}
	inline bool operator>=(const Edge_Cost rhs) const {
		return !(*this < rhs);
	}
	inline bool operator<=(const Edge_Cost rhs) const {
		return !(*this > rhs);
	}
	inline bool operator==(const Edge_Cost rhs) const {
		return *this <= rhs && *this >= rhs;
	}
	inline bool operator!=(const Edge_Cost rhs) const {
		return !(*this == rhs);
	}
};
using edge = Edge_Cost<dijkstra_cost>;
using graph = Graph<vertex, edge>;

template<class T, class V, class E>
void Dijkstra(Graph<V, E>& G, int s, T INF_COST)
{
	auto &v = G.v;
	auto &e = G.e;
	for (auto& vv : v) vv.cost = INF_COST;
	priority_queue<E, vector<E>, greater<E>> q;
	q.emplace(s, 0);
	while (!q.empty()) {
		auto a = q.top();
		q.pop();
		if (a.cost >= v[a.to].cost) continue;
		v[a.to].cost = a.cost;
		for (auto& p : e[a.to]) {
			if (p.cost == INF_COST) continue;
			if (a.cost + p.cost < v[p.to].cost) q.emplace(p.to, a.cost + p.cost);
		}
	}
}

int main()
{
	int N;
	vector<long long> x, y, r;
	{
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		x.push_back(a);
		y.push_back(b);
		r.push_back(0);
		x.push_back(c);
		y.push_back(d);
		r.push_back(0);
	}
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		x.push_back(a);
		y.push_back(b);
		r.push_back(c);
	}
	graph G(N+2);
	for (int i = 0; i < N + 2; i++) {
		for (int j = 0; j < N + 2; j++) {
			double dx = x[i] - x[j];
			double dy = y[i] - y[j];
			dx *= dx;
			dy *= dy;
			G.add_edge(i, j, max<double>(0, sqrt(dx + dy) - r[i] - r[j]));
		}
	}
	Dijkstra(G, 0, 1e18);
	cout << fixed << setprecision(12) << G.v[1].cost << endl;
}

Measured memory_bytes: 26624
A,B,C,D = map(int, input().split())


def gcd(a,b):
  if (a%b==0):
    return(b)
  else:
    return(gcd(b,a%b))

def lcm(m, n):
	if ( ( 0 == m ) or ( 0 == n ) ):
		return 0;
	return ((m // gcd(m, n)) * n); 


ans = (B-A+1)
ans = ans - (B//C - (A-1)//C)
ans = ans - (B//D - (A-1)//D)
lcmnum = lcm(C, D)
ans = ans + (B//lcmnum - (A-1)//lcmnum)
print(ans)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int m = in.nextInt();
		long[][] t = new long[8][n];
		for (int i = 0; i < n; i++) {
			long x = in.nextLong();
			long y = in.nextLong();
			long z = in.nextLong();
			t[0][i] = x + y + z;
			t[1][i] = -x + y + z;
			t[2][i] = x - y + z;
			t[3][i] = x + y - z;
			t[4][i] = -x - y + z;
			t[5][i] = -x + y - z;
			t[6][i] = x - y - z;
			t[7][i] = -x - y - z;
		}
		Arrays.sort(t[0]);
		Arrays.sort(t[1]);
		Arrays.sort(t[2]);
		Arrays.sort(t[3]);
		Arrays.sort(t[4]);
		Arrays.sort(t[5]);
		Arrays.sort(t[6]);
		Arrays.sort(t[7]);
		long[] st = new long[8];
		for (int i = 0; i < 8; i++)
			for (int j = n - 1; j >= n - m; j--)
				st[i] += t[i][j];
		Arrays.sort(st);
		System.out.println(st[7]);
		in.close();
	}

	private static int solve(int[] a) {
		int r = 0;
		for (int i = 0; i < a.length; i++)
			for (; a[i] % 2 == 0; a[i] /= 2)
				r++;
		return r;
	}
}

Measured memory_bytes: 27076
#include <cstdio>
#include <algorithm>

using namespace std;


const int MAX_N = 105;
const int MAX_W = 100005;

int n,W;
long long dp[MAX_N][MAX_W];

int main()
{
	scanf("%d %d",&n,&W);
	for (int i=1; i<=n; i++)
	{
		int w,v;
		scanf("%d %d",&w,&v);
		for (int j=0; j<=W; j++)
			if (j-w>=0)
				dp[i][j]=max(dp[i-1][j],v+dp[i-1][j-w]);
			else
				dp[i][j]=dp[i-1][j];
	}
	printf("%lld\n",dp[n][W]);
	return 0;
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef double dl;
#define pb push_back
#define ins insert
#define pll pair<ll,ll>
#define fi first
#define se second
#define mpr make_pair
#define vtr vector
#define itor iterator 
#define N ll(1e9+7)
#define endl '\n'
#define cont continue
using namespace std;
//ll power(ll a,ll b,ll mod)
//{
//	if(b==0)return 1;
//	ll ans=1;
//	while(b>0)
//	{
//		if(b&1)ans=(ans*a)%mod;
//		a=(a*a)%mod;
//		b>>=1;
//	}
//	return ans;
//}

int main()
{
	ios;
	ll r,c,k;
	cin>>r>>c>>k;
	vtr<vtr<char> > mat(r,vtr<char>(c));
	ll i,j;
	ll cnt=0;
	for(i=0;i<r;i++)
	{
		for(j=0;j<c;j++)
		{
			cin>>mat[i][j];
			if(mat[i][j]=='#')cnt++;
		}
	}
	if(cnt<k)cout<<0;
	else
	{
		ll ans=0,row,col;
		for(row=0;row<=((1<<r)-1);row++)
		{
			for(col=0;col<(1<<c);col++)
			{
				ll ct=0;
				for(i=0;i<r;i++)
				{
					for(j=0;j<c;j++)
					{
						if(((row&(1<<i))==0) and ((col&(1<<j))==0))
						{
							if(mat[i][j]=='#')ct++;
						}
					}
				}
				if(ct==k)ans++;
			}
		}
		cout<<ans;
	}
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,D; cin>>N>>D;
    int ans=0;
    rep(i,N){
        ll x,y; cin>>x>>y;
        if (x*x+y*y<=D*D) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second

using namespace std;

const double INF = 1e9;

int N, M, P, A, B;
double t[10], road[35][35], dp[35][(1<<8)];
int testCnt = 0;

double dfs(int nowNode, int ticketState){
  if(nowNode == B-1) return 0;
  if(ticketState == 0) return INF;
  if(dp[nowNode][ticketState] != -1.0) return dp[nowNode][ticketState];
  double ret = INF;
  //bool flag = false;
  REP(nextNode, 0, M){
    if(road[nowNode][nextNode] == INF) continue;
    REP(ticket, 0, N){
      if(!(ticketState & (1<<ticket))) continue;
      ret = min(ret, dfs(nextNode, ticketState^(1<<ticket) ) + road[nowNode][nextNode]/t[ticket] );
    }
  }
  testCnt++;
  return dp[nowNode][ticketState] = ret;
}

int main() {
  while(1){
    cin>>N>>M>>P>>A>>B;
    if(N==0) break;
    REP(i,0,N) cin>>t[i];
    REP(i,0,M)REP(j,0,M) road[i][j] = INF;
    REP(i,0,P){
      int x, y;
      double z;
      cin>>x>>y>>z;
      x--; y--;
      road[x][y] = road[y][x] = z;
    }
    REP(i,0,M)REP(j,0,(1<<N)) dp[i][j] = -1.0;
    double ans = dfs(A-1,(1<<N)-1);
    if(ans < INF) printf("%.5lf\n", ans);
    else cout<<"Impossible"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3192
import sys
x,n=map(int,input().split())
if n==0:
    print(x)
    sys.exit()
p=list(map(int,input().split()))
ans=1000
for i in range(0,102):
    if i not in p:
        tmp=abs(x-i)
        if tmp<ans:
            ans=tmp
            ansa=i
print(ansa)

Measured memory_bytes: 9136
#include <bits/stdc++.h>
typedef long long ll; 
 
using namespace std;
using P = pair<ll, ll>;

int main() {
	int N;
	cin >> N;
	vector<P> pos(N);
	for (int i = 0; i < N; i++) {
		cin >> pos[i].first >> pos[i].second;
	}

	int par = (abs(pos[0].first) + abs(pos[0].second)) % 2;
	for (int i = 0; i < N; i++) {
		ll x = pos[i].first, y = pos[i].second;

		int par2 = (abs(x) + abs(y)) % 2;
		pos[i] = P(x + y, x - y);

		if (par2 != par) {
			cout << -1 << endl;
			return 0;
		}
	}

	vector<ll> d;
	for (int i = 30; i >= 0; i--) {
		d.push_back(1LL<<i);
	}
	if (par % 2 == 0) d.push_back(1);
	cout << d.size() << endl;
	for (int i = 0; i < d.size(); i++) {
		cout << d[i];
		if (i != d.size() - 1) cout << " ";
		else cout << endl;
	}

	for (int i = 0; i < N; i++) {
		int xdir, ydir;
		ll xsum = 0, ysum = 0;
		for (int j = 0; j < d.size(); j++) {
			if (xsum <= pos[i].first) {
				xdir = 1;
				xsum += d[j];
			} else {
				xdir = -1;
				xsum -= d[j];
			}
			if (ysum <= pos[i].second) {
				ydir = 1;
				ysum += d[j];
			} else {
				ydir = -1;
				ysum -= d[j];
			}

			if (xdir == 1) {
				if (ydir == 1) cout << "R";
				else cout << "U";
			} else {
				if (ydir == 1) cout << "D";
				else cout << "L";
			}
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 256
# N, W = 3, 8
# ARR = [
#     [3, 30],
#     [4, 50],
#     [5, 60],
# ]
# #
N, W, = 6, 15
ARR = [
    [6, 5],
    [5, 6],
    [6, 4],
    [6, 6],
    [3, 5],
    [7, 2],
]



N,W = map(int,input().split())
ARR = []

for i in range(N):
    ARR.append(list(map(int,input().split())))


def calculate(n, w, arr):
    srr = [[0] * (w+1) for i in range(n+1)]

    for i in range(1, n + 1):
        for j in range(1, w + 1):
            if j - arr[i - 1][0] >= 0:
                s1 = srr[i - 1][j]
                s2 = srr[i - 1][j - arr[i - 1][0]] + arr[i - 1][1]
                srr[i][j] = max(s1, s2)
            else:
                srr[i][j] = srr[i-1][j]

    print(srr[-1][-1])


calculate(N, W, ARR)


Measured memory_bytes: 119404
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
#define mod 1000000007
using namespace std;

ll minimax(ll i, ll j, ll n, vector< vector<ll> > & dp, vector<ll> &a)
{
    if(j<0 || i>=n || i>j)
        return ll_MAX;
   
    if(dp[i][j] != -1)
        return dp[i][j];
     if(i==j)
        return a[i];
    ll v1 = minimax(i + 1, j - 1, n, dp, a);
    ll v2 = minimax(i + 2, j, n, dp, a);
    ll v3 = minimax(i + 1, j - 1, n, dp, a);
    ll v4 = minimax(i, j - 2, n, dp, a);
    
    v1 = min(v1, v2);
    if(v1 == ll_MAX)
        v1 = ll_MIN;
    v3 = min(v3, v4);
    if(v3 == ll_MAX)
        v3 = ll_MIN;

    dp[i][j] = max(a[i] + v1, a[j] + v3);
    return dp[i][j];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    ll n;
    cin>>n;
    vector<ll> a;
    ll sum = 0;
    for (ll i = 0; i < n; i++)
    {
        /* code */
        ll x;
        cin>>x;
        sum += x;
        a.push_back(x);
    }
    vector< vector<ll> > dp(n, vector<ll>(n, -1));
    ll val = minimax(0, n - 1, n, dp, a);
    // cout<<val<<" "<<2*val<<'\n';
    cout<<2*val - sum<<'\n';
}

Measured memory_bytes: 73888
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string.h>
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%I64d",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
#define INF                         (int)1e9
#define EPS                         1e-9
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
#define MOD                         1000000007
typedef long long ll;
/*For you see , each day i love you
 more.Today more than yesterday
  less than tomorrow.*/
using namespace std;

int main()
{
	int n;cin>>n;
	vector<ll> vec;
	ll sum = 0;
	
	for(int i = 0;i<n;i++)
	{
		ll x;cin>>x;
		vec.push_back(x);
		sum+=x;
	}
	
	ll ans = 0;
	
	for(int i = 0;i<n;i++)
	{
		sum-=vec[i];
		ll val = (sum)%MOD;
		val = (vec[i]*val)%MOD;
		ans = (ans + val)%MOD;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

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

using namespace std;
using ll = long long;

int main(void)
{
  int n;
  cin >> n;
  vector<vector<int>> d(n);
  for (int i = 0; i < n; ++i) {
    int tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    d[i].push_back(tmp1);
    d[i].push_back(tmp2);
  }

  int count = 0;
  for (int i = 0; i < n; ++i) {
    if (d[i][0] == d[i][1]) {
      ++count;
    } else {
      if (count < 3) {
        count = 0;
      }
    }
  }
  cout << (count >= 3 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3632
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;


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

  ll ans = 0;
  for (ll i = 1; i <= 50000; i++) {
    double nc = (ll)(i * 1.08);
    if (N == nc) {
      ans = i;
    }
  }
  if(ans == 0){
    puts(":(");
    return 0;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>

#define MOD 1000000007
#define ll long long

using namespace std;

ll gcf(ll a, ll b){
  if(a < b){ll temp = a; a = b; b = temp;}

  if(b == 0) return a;
  else return gcf(b,a%b);
}

ll N,K;
vector<ll> A;

int main(){
  ll inp;
  ll cf;
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin >> N >> K;
  for(ll i = 0 ,l = N; i<l ; i++){
    cin >> inp;
    if(inp == 0) N--;
    else A.push_back(inp);
  }

  sort(A.begin(), A.end());
  if(K>A[N-1]){
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  cf = gcf(A[0],A[1]);
  for(ll i = 2; i< A.size();i++){
    cf = gcf(cf,A[i]);
    if(cf == 1){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  if(!(K%cf)) cout << "POSSIBLE" << endl;
  else  cout << "IMPOSSIBLE" << endl;

  return 0;
}


Measured memory_bytes: 1400
/*
 * =template=.cpp
 * Copyright (C) 2017 hzw <hzw@huzhenweideMacBook.local>
 *
 * Distributed under terms of the MIT license.
 */

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<cstring>
#include<sstream>
#include<unordered_map>
#define FR first
#define SC second
#define MP make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
inline int pow(int a,int b,int c)
{
    if (a==0)return 0;
	b=(b%(c-1)+c-1)%(c-1);
	int d=1;
    while (b)
    {
        if (b&1) d=(1LL*d*a)%c;
        a=1LL*a*a%c;b>>=1;
    }
    return d;
}
inline void read(int &x)
{
	char ch;
	while ((ch=getchar())<=32);
	x=ch-48;
	while ((ch=getchar())>32) x=x*10+ch-48;
}
inline int random(int n) { return 1LL*rand()*rand()%n+1;}
//-------------template------------
const int N=1000010,M=600000,p=1000000007,inf=100000000;
const int inv2=(p+1)/2;
inline void up(int &x,int y) { x+=y;if (x>=p) x-=p;if (x<0) x+=p;}
struct Edge{int y,ne;};
int cas;
//void add(int x,int y) { e[++num]=(Edge){y,last[x]};last[x]=num;}
int main()
{
	int a,b,c;LL k;
	cin>>a>>b>>c>>k;
	if (k%2==0) cout<<a-b<<endl;else
		cout<<b-a<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
using namespace std;

int N, M, Z;

typedef vector<vector<int> > matrix;

matrix mult(matrix lhs, matrix rhs){
    int n = lhs.size();
    matrix r(n, vector<int>(n));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            for(int k = 0; k < n; ++k){
                r[i][j] += rhs[i][k] * lhs[k][j];
            }
        }
    }
    return r;
}

matrix pow(matrix A, int p){
    if (p == 1) {
        return A;
    } else if (p % 2) {
        matrix T = pow(A, p-1);
        return mult(A, T); 
    } else {
        matrix T = pow(A, p/2);
        return mult(T, T); 
    }
}


int main(){
    while(cin >> N >> M >> Z && N>0){
        vector<pair<int, int> > edges;
        matrix a(2*M+1, vector<int>(2*M+1));
        edges.push_back(make_pair(0, 1));
        for(int i = 0; i < M; ++i){
            int s, d;
            cin >> s >> d;
            edges.push_back(make_pair(s, d));
            edges.push_back(make_pair(d, s));
        }
        for (int i = 0; i < edges.size(); ++i){
            for (int j = 0; j < edges.size(); ++j){
                if(i != j && edges[i].second == edges[j].first && edges[i].first != edges[j].second){
                    a[i][j] = 1;
                }else{
                    a[i][j] = 0;
                }
            }
        }
        
        a = pow(a, Z);
        bool ans = false;
        for (int i = 0; i < edges.size(); ++i){
            if(edges[i].second == N and a[0][i] != 0){
                ans = true;
            }
        }
        if(ans){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}

Measured memory_bytes: 5704
#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() {
    ll n, k;
    cin >> n >> k;
    
    n = n % k;
    while (1) {
        if (n <= abs(n-k) ) break;
        n = abs(n-k);
    }
    cout << n << endl;
 
}

Measured memory_bytes: 3592
h,w = map(int,input().split())
ss = [input() for _ in [0]*h]
for i in range(h):
  ans = ''
  for j in range(w):
    if ss[i][j] == '#':
      ans += '#'
      continue
    n = 0
    if i > 0:
      n += ss[i-1][max(0,j-1):j+2].count('#')
    n += ss[i][max(0,j-1):j+2].count('#')
    if i != h-1:
      n += ss[i+1][max(0,j-1):j+2].count('#')
    ans += str(n)
  print(ans)

Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include<iostream>
#include<numeric>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  int X=0,Y=0;
  cin >> X >> Y;
  cout << X + Y/2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll H, W, x, y;
    cin >> W >> H >> x >> y;
    if (W != 2 * x && H != 2 * y) {
        cout << fixed << setprecision(15) << H * W / 2.0 << " " << 0 << endl;
    } else {
        ll a1 = min((W - x) * H, x * H);
        ll a2 = min((H - y) * W, y * W);
        cout << max(a1, a2) << " " << (a1 == a2) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <fstream>
#include <set>
#include <stack>
#include <queue>
#include <list>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define qr queries();
void solve();
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
int64 q, n;

void solve(){
    
    return;
}


int main(){
    int n, k;
    cin >> n >> k;
    vec arr (n);
    for( int i = 0; i <n; i++){
        cin >> arr[i];
    }
    sort(arr.begin(), arr.end());
    int64 rs = 0;
    for (int i = 0; i < k; i++){
        rs+=arr[i];
    }
    ctn(rs);
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int

struct edge
{
  int to, cost;
};
typedef std::vector<std::vector<edge>> graph;
const ll MOD = 1000000007;
using namespace std;

ll l[87] = {};

ll calcL(int n)
{
  if (n == 0)
  {
    return 2LL;
  }
  if (n == 1)
  {
    return 1LL;
  }
  if (l[n - 1] == 0)
  {
    l[n - 1] = calcL(n - 1);
  }
  if (l[n - 2] == 0)
  {
    l[n - 2] = calcL(n - 2);
  }
  return l[n - 1] + l[n - 2];
}

int main()
{
  int n;
  cin >> n;
  cout << calcL(n) << endl;
}


Measured memory_bytes: 256
def dfs(now,depth):
    ans=0
    if vis[now]:
        return 0
    if depth==n:
        return 1
    vis[now]=1
    for i in range(n):
        if graph[now][i]:
            ans+=dfs(i,depth+1)
    vis[now]=0
    return ans
n,m=map(int,input().split())
edge=[[int(i) for i in input().split()]for i in range(m)]
graph=[[0 for i in range(n)]for i in range(n)]
for i in range(m):
    graph[edge[i][0]-1][edge[i][1]-1]=1
    graph[edge[i][1]-1][edge[i][0]-1]=1
vis=[0]*n
print(dfs(0,1))


Measured memory_bytes: 3064
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};
int main(){
	int n,m;
	cin>>n>>m;
	vs in(n);
	rep(i,n)cin>>in[i];
	vvi out(n,vi(m));
	out[0]=vi(m,1);
	rep(i,n)rep(j,m)if(in[i][j]!='-'){
		out[i][j]=1;
		rep(k,8){
			int nx=i+dx[k],ny=j+dy[k];
			if(nx<0||ny<0||nx>=n||ny>=m)continue;
			if(in[i][j]=='o'&&k!=0&&k!=2)continue;
			out[nx][ny]=1;
		}
	}
	int co=0;
	rep(i,n)rep(j,m)co+=!out[i][j];
	cout<<co<<endl;
}













Measured memory_bytes: 3280
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fr(n) for(int i=0;i<n;i++)
#define mod 1000000007


int32_t main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	int n;
	cin>>n;
	string s;
	map<string,int> m;
	while(n--){
		cin>>s;
		m[s] = 1;
	}
	int ans = 0;
	for(auto j:m) ans++;
		cout<<ans;


	return 0;
}

Measured memory_bytes: 19060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define loop(i,a,b) for(ll i=a;i<b;i++)
const int inf=1e9+7;

int main()
{	
    ll N,W;
    cin>>N>>W;
    ll wt[N],v[N],vmax=0;
    loop(i,0,N)
    {
    	cin>>wt[i]>>v[i];
    	vmax+=v[i];
	}
    
    vector< vector<ll> > dp(N+1,vector<ll>(vmax+1,1e9+5) );
    loop(i,0,N+1)
     dp[i][0]=0;
     loop(i,1,N+1)
     {
     	loop(j,1,vmax+1)
     	{
     		if(v[i-1]>j) dp[i][j]=dp[i-1][j];
     		else
     		 dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i-1]]+wt[i-1]);
		 }
	 }
	 ll ans=0;
	 loop(j,0,vmax+1)
	 {
	 	if(dp[N][j]<=W)
	 	ans=j;
	 }
	 cout<<ans;
    return 0;
}


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

int main() {
	int x,y;
	cin >> x >> y;
	if (y % 2)
	{
		cout << "No";
		return 0;
	}
	if (y <= 4 * x && y >= 2 * x)
	{
		cout << "Yes";
		return 0;
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int W,H,x,y,r;

		do{
			W = scan.nextInt();
		}while(!(0 < W && W <= 100));

		do{
			H = scan.nextInt();
		}while(!(0 < W && H <= 100));

		do{
			x = scan.nextInt();
		}while(!(-100 <= x && x <= 100));

		do{
			y = scan.nextInt();
		}while(!(-100 <= y && y <= 100));

		do{
			r = scan.nextInt();
		}while(!(0 < r && r <= 100));

		if((0 <= x-r && x+r <= W) && (0 <= y-r && y+r <= H))	System.out.println("Yes");
		else							System.out.println("No");
	}
}

Measured memory_bytes: 17304