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

int main(){
    int H, W;
    cin >> H >> W;

    string S[51];
    
    for(int i=0; i<H; i++){
        cin >> S[i];
    }
    
    const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
    const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(S[i][j] == '#') continue;
            int num = 0;
            for(int d=0; d<8; d++){
                const int ni = i + dy[d];
                const int nj = j + dx[d];

                if(ni<0 or H <= ni) continue;
                if(nj<0 or W <= nj) continue;
                if(S[ni][nj]=='#') num++;
            }

            S[i][j] = char(num +'0');
        }
    }

    for(int i=0; i<H; i++) cout << S[i] << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		long ans = 1;
		for(int i = 1; i <= n; ++i)
		{
			ans *= i;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 12000
use std::io;


/// https://beta.atcoder.jp/contests/arc079/tasks/arc079_a
fn main() {

    let (n, m) = {
        let i = read::<usize>();
        (i[0], i[1])
    };

    let mut from = vec![false; n + 1];
    let mut to = vec![false; n + 1];
    let mut path = Vec::new();

    for _ in 0..m {
        let (s, t) = {
            let i = read::<usize>();
            (i[0], i[1])
        };
        if s == 1 { from[t] = true; }
        if t == n { to[s] = true; }
        path.push(s);
        path.push(t);
    }

    let mut ans = false;
    for j in path.into_iter() {
        if from[j] && to[j] {
            ans = true;
        }
    }

    if ans { println!("POSSIBLE"); }
    else { println!("IMPOSSIBLE"); }

}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 9284
#include<stdio.h>
#define ull unsigned long long int
#define ll long long
#define rep(x) for(A[x]=A[x-1];A[x]<=M;A[x]++)

ll max(ll a,ll b){
  if(b>a)return b;
  return a;
};

typedef struct quatt{
  int a,b,c;
  long d;
}quat;

ll hyouka(quat q[],int n,int A[]){
  ll sum=0;
  for(int k=0;k<n;k++)
    if(A[q[k].b]-A[q[k].a]==q[k].c)
      sum+=q[k].d;
  return sum;
};
  

int main(){
  int N,M,Q;
  int A[11]={1,1,1,1,1,1,1,1,1,1,1};
  ll ans=0;
  scanf("%d%d%d",&N,&M,&Q);
  quat q[Q];
  for(int j=0;j<Q;j++){
    scanf("%d%d%d%ld",&q[j].a,&q[j].b,&q[j].c,&q[j].d);
  };
  for(A[1]=1;A[1]<=M;A[1]++)
    rep(2)rep(3)rep(4)rep(5)rep(6)rep(7)rep(8)rep(9)rep(10){
    ans=max(hyouka(q,Q,A),ans);
  };
  printf("%lld",ans);      
};

Measured memory_bytes: 1736
a,b=map(int,input().split())
c=0
if(a<b):
  c=a
  a=b
  b=c

x=a
y=b
z=x%y
while(z!=0):
    x=y
    y=z
    z=x%y
d=y
    
print(int(a*b/d))

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int ball[10];
	int tc[10];
	int tc2[10];
	int a, b, c;
	int che, che2, che3;
	
	scanf("%d", &a);
	for (b = 0; b < a; b++) {
		che = 0;
		che2 = 0;
		che3 = 0;
		for (c = 0; c < 10; c++) {
			tc[c] = 0;
			tc2[c] = 0;
			scanf("%d", &ball[c]);
		}
		tc[0] = ball[0];
		for (c = 1; c < 10; c++) {
			if (tc[che] < ball[c]) {
				che++;
				tc[che] = ball[c];
				che3 = 1;
			}
			else if (tc2[che2] < ball[c]) {
				che2++;
				tc2[che2] = ball[c];
				che3 = 1;
			}
			else {
				che3 = 0;
				c = 10;
			}
		}
		if (che3 == 1) {
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 580
n,m,*a=map(int,open(0).read().split())
d=[0]*n*9
for i in range(n):
 for j in a:c=i+int("0255456376"[j]);d[c]=max(d[c],(d[i]*10+j)*(i<1or d[i]>0))###
print(d[n])

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

int main(){
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<ll> A(X);
  vector<ll> B(Y);
  vector<ll> C(Z);
  vector<ll> D(X * Y);
  for(int i = 0; i < X; i++){
    cin >> A[i];
  }
  for(int i = 0; i < Y; i++){
    cin >> B[i];
  }
  for(int i = 0; i < Z; i++){
    cin >> C[i];
  }
 
  sort(C.begin(), C.end(), greater<ll>());
  int iD = 0;
  for(int i = 0; i < X; i++){
    for(int j = 0; j < Y; j++){
      D[iD] = A[i] + B[j];
      iD++;
    }
  }
  sort(D.begin(), D.end(), greater<ll>());
  priority_queue<ll> q;
  int l = min(X * Y, K);
  for(int i = 0; i < l; i++){
    for(int j = 0; j < Z; j++){
      q.push(D[i] + C[j]);
    }
  }
  for(int i = 0; i < K; i++){
    cout << q.top() << "\n";
    q.pop();
  }
  return 0;
}

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

int main (){
        int N;
        long long count= 0;
        cin >> N;

        int *ptr = new int[N+1];

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

        int l =0, r=0;
        int cal=0;
        while (l<N) {
                while ( r<N && (cal ^ptr[r])==(cal +ptr[r]) ) {
                        cal ^= ptr[r++], count++;
                }
                cal ^= ptr[l++];
                count +=  r-l;
        }

        cout << count<<endl;

        delete [] ptr;
        return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

int main() {
    int a;
    cin >> a;
    string s;
    cin >> s;
    if (a >= 3200) {
        cout << s << endl;
    } else {
        cout << "red" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
a, v = [int(x) for x in input().split()]
b, w = [int(x) for x in input().split()]
t = int(input())
if w > v:
    print("NO")
elif w == v:
    if a == b:
        print("YES")
    else:
        print("NO")
else:
    if abs(a - b)/(v - w) <= t:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 9200
#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>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    rep(i,n) {
        int k;
        cin >> k;
        rep(j,k) {
            int x;
            cin >> x;
            x--;
            a[x]++;
        }
    }
    int ans = 0;
    rep(i,m) {
        if (a[i] == n) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#!/usr/bin/ruby                                                                                                                                   
# -*- coding: utf-8 -*-                                                                                                                           

class Node
  attr_accessor :key, :left, :right
  def initialize key
    @key = key
  end

  def inorder
    left.inorder if left
    print " ", key
    right.inorder if right
  end

  def preorder
    print " ", key
    left.preorder if left
    right.preorder if right
  end
end

def insert
  z = Node.new $key.to_i
  x = $root
  while x
    y = x  #???????¨????
    x = z.key < x.key ? x.left : x.right  #?????????????§????/?????????????§????
  end

  unless y  #y???nil?????´???
    $root  = z
  else
    z.key < y.key ? y.left = z : y.right = z  #z???y?????????????????????/z???y?????????????????????
  end
end

n = gets.to_i
n.times do
  command, $key = gets.split
  if command == "insert"
    insert
  else
    $root.inorder
    puts 
    $root.preorder
    puts
  end
end

Measured memory_bytes: 47972
import Control.Monad
import Data.Maybe
import Data.Char
import Data.List (unfoldr)
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined

--Input functions with ByteString
readInt = fst . fromJust . BS.readInt
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntN n = map readInt <$> replicateM (fromIntegral n) BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents


main = do
  _ <- getInt
  s <- getLine

  let countBrackets (x:rest)  bl br | x == '('           =  countBrackets rest (bl+1) br
                                    | x == ')' && bl > 0 =  countBrackets rest (bl-1) br
                                    | otherwise          =  countBrackets rest bl (br+1)
      countBrackets []        bl br = (bl, br)
      (bl,br) = countBrackets s 0 0

  putStr $ replicate br '('
  putStr s
  putStrLn $ replicate bl ')'

Measured memory_bytes: 508
S = input()
T = input()

def solve(S,T):
    # print(W)
    s = len(S)
    t = len(T)
    dp = [[0]*(t+1) for _ in range(s+1)]
    for i in range(s):
        for j in range(t):
            if S[i]==T[j]:
                dp[i+1][j+1] = dp[i][j]+1
            else:
                dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1])
    ans = ''
    i,j = s,t
    while i>0 and j>0:
        if dp[i][j]==dp[i-1][j]:
            i -= 1
        elif dp[i][j]==dp[i][j-1]:
            j -= 1
        else:
            ans = S[i-1]+ans
            i-=1
            j-=1
    return ans
print(solve(S,T))

Measured memory_bytes: 111452
#include<iostream>
#include<string>
using namespace std;
int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int a, b, c, d, e, x;
    int sum = 0;

    for(int i = 1; i <= N; i++){
        a = i / 10000;
        b = (i - 10000*a) / 1000;
        c = (i - 10000*a - 1000*b)/ 100;
        d = (i - 10000*a - 1000*b - 100*c) / 10;
        e = (i - 10000*a - 1000*b - 100*c - 10*d);
        x = a + b + c + d + e;
        if(A<=x && x <= B) {
            sum += i;
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int p[110000];
int q[110000];
pair<int,int> ev[210000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
	}
	for(int i=0;i<a;i++)scanf("%d",q+i);
	for(int i=0;i<a;i++){
		ev[i]=make_pair(p[i],1);
		ev[i+a]=make_pair(q[i],-1);
	}
	std::sort(ev,ev+a*2);
	long long ret=1;
	int L=0;
	int R=0;
	int cur=0;
	for(int i=0;i<a*2;i++){
		int pre=cur;
		cur+=ev[i].second;
		if(ABS(pre)>ABS(cur))ret=ret*ABS(pre)%mod;
	}
	printf("%lld\n",ret);
}

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

void change(int);
char moji[201];

int main(){
  int cnt, i, kazu;

  while(1){
    //input moji
    scanf("%s",moji);
    //- break
    if(strcmp(moji,"-")==0) break;

    //input data size
    scanf("%d",&cnt);

    //do
    for(i=0;i<cnt;i++){
      scanf("%d",&kazu);
      change(kazu);
    }

    //print
    printf("%s\n",moji);
  }
  
  return 0;
}

void change(int kazu){
  char tmp[201];
  int i;
  
  for(i=0;i<strlen(moji);i++) tmp[i]=moji[(i+kazu)%strlen(moji)];
  tmp[i]='\0';
  strcpy(moji,tmp);
}



Measured memory_bytes: 2036
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 1e5 + 10;

vector < int > g[MR];

bool done[MR], match[MR];

bool dfs(int nr)
{
	done[nr] = 1;
	bool childToMatch = 0;
	for (auto v : g[nr])
		if (!done[v])
		{
			if (!dfs(v))
				return 0;
			if (!match[v])
			{
				// spr czy ma wiecej, niz 1 dziecko niezmatchowane
				if (childToMatch)
					return 0;
				childToMatch = 1;
			}
		}

	// odznacz czy matchujesz goscia z dzieckiem
	match[nr] = childToMatch;

	return 1;
}

int main()
{
	int N;
	scanf("%d", &N);

	if (N & 1)
	{
		printf("First\n");
		return 0;
	}

	REP(i, N - 1)
	{
		int a, b;
		scanf("%d%d", &a, &b); a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	if (dfs(0))
		printf("Second\n");
	else
		printf("First\n");

	return 0;
}

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

ll lcm(ll a,ll b){
    if(a<b){
      ll tmp = a;
      a = b;
      b = tmp;
    }
    ll x = a*b,r = a % b,sa=a,sb=b;

    while(r!=0){
      a = b;
      b = r;
      r = a % b;
    }
    ll aa = sa/b;
    if(log10(sa)+log10(sb)<=18)return x/b;
    else return aa*sb;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll ans = 1;
    for(int i = 0;i < n;i ++){
        ll t;
        cin >> t;
        ans = lcm(ans,t);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, w[101], v[101], dp[101][100001], w1;
int main(){
cin >> n >> w1;
for(int i = 1; i <= n ;i++){
    cin >> w[i] >> v[i];
}
for(int i = 1; i <= n; i++){
    for(int j = 0; j <= w1; j++){
        if(j < w[i]){
            dp[i][j] = dp[i - 1][j];
        }
        else{
            //cout << dp[i - 1][j] << " " << (dp[i - 1][j - w[i]] + v[i]);
            dp[i][j] = max(dp[i - 1][j], (dp[i - 1][j - w[i]] + v[i]));
        }
    }
}
/*for(int i = 1; i <= n; i++){
    for(int j = 0; j <= w1; j++){
        cout << dp[i][j] << " ";
    }
    cout << endl;
}*/
cout << dp[n][w1];
}


Measured memory_bytes: 78336
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <map>
using namespace std;
const long long mod=998244353;
long long fac[300010],inv[300010];
long long ai,bi,k;
int n;

long long qp(long long p,long long q)
{
    long long cnt=1;
    while(q>0)
    {
        if(q%2==1) cnt=(cnt*p)%mod;
        q/=2;
        p=(p*p)%mod;
    }
    return cnt%mod;
}

long long C(long long a,long long b)
{
    long long tmp=(fac[a]*inv[b])%mod*inv[a-b];
    return tmp%mod;
}

void init()
{
    int i;
    fac[0]=1;
    inv[0]=1;
    for(i=1;i<=n;i++)
    {
        fac[i]=(fac[i-1]*i)%mod;
        inv[i]=qp(fac[i],mod-2);
    }
}

int main()
{
    int i,j;
    scanf("%d%lld%lld%lld",&n,&ai,&bi,&k);
    init();
    long long ans=0;
    for(i=0;i<=n;i++)
    {
        if((k-ai*i)<0) continue;
        if((k-ai*i)%bi!=0) continue;
        long long num=(k-ai*i)/bi;
        if(num>(long long)n) continue;
        long long tmp=C(n,i)*C(n,num);

        /*else if(num>(long long)(n-i)) tmp=(tmp*C(i,num-n+i))%mod;
        else tmp=(tmp*C(n-i,num))%mod;*/
        ans=(ans+tmp)%mod;
    }
    printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4992
mod = 10**9 +7
n,m = map(int,input().split())
stairs = [1 for _ in range(n)]
memo = [0 for _ in range(n)]
for _ in range(m):
    a = int(input()) - 1
    stairs[a] = 0
memo[0] = stairs[0]
if n ==1:
    print(memo[0])
    exit()
if stairs[1]:
    memo[1] = stairs[1] + memo[0]
if n==2:
    print(memo[1])
    exit()
for i in range(2,n):
    if stairs[i]:
        memo[i] = (memo[i-1] +memo[i-2])%mod
    else:
        memo[i] = 0
print(memo[n-1])


Measured memory_bytes: 7832
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include<map>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;

int main() {
	long long sum = 0;
	int i, j;
	int N, K;
	int H[200005];
	cin >> N >> K;
	for (i = 0; i < N; ++i) {
		cin >> H[i];
	}
	sort(H, H + N, greater<int>());
	/*for (i = 0; i < N; ++i) {
		cout << H[i] << endl;
	}*/
	for (i = K; i < N; ++i) {
		sum += H[i];
	}
	cout << sum << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int k;
    cin>>k;
    long long int sum=0;
    
    
    for(int i=1;i<=k;i++){
      for(int j=1;j<=k;j++){
        for(int l=1;l<=k;l++){
          int mx = gcd(i,j);
          int my = gcd(mx,l);
          
          sum+=my;
        } 
      }
    }
    
    
    cout<<sum<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}

	return d;
}

int main(void) {

	lli n, k;
	cin >> n >> k;

	lli t = n % k;

	cout << min(t, k - t) << endl;

	return 0;
}

Measured memory_bytes: 3632
package main

import (
	"fmt"
	"sort"
)

func main(){
	var (
		n int
		alice = 0
		bob = 0
	)
	fmt.Scan(&n)

	cards := make([]int, n)
	for i:=0; i<n; i++{
		fmt.Scan(&cards[i])
	}

	sort.Sort(sort.Reverse(sort.IntSlice(cards)))

	for m:=0; m<n; m=m+2{
		alice += cards[m]
		if m+1<n{
			bob += cards[m+1]
		}
	}

	fmt.Println(alice-bob)
}

Measured memory_bytes: 512
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll a;
  cin>>a;
  cout << a+a*a+a*a*a << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cctype>
#include <map>
#include <cstring>
#include <typeinfo>
#define REP(i,n) for(int i = 0;i < n ;i++)
#define FOR(i,m,n) for(int i= m ;i<n;i++)
using namespace std;

int main(void){
  int H,W;
  cin >> H >>W;
  string str;
  int i;
  for(i=0;i<H;i++){
    cin >> str;
    cout << str <<endl << str << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#ABC044B
n=input()
a=[]
for i in range(len(n)):
     a.append(n[i])
sum_=0
for i2 in range(len(a)):
    sum_=sum_+a.count(a[i2])%2

if sum_ == 0:
    print("Yes")
else:
    print("No")

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


int main() {
    int n; cin >> n;
    vector<ll> v(n);
    rep(i,n){
        cin >> v.at(i);
    }
    string ans="No";
    reverse(v.begin(),v.end());
    rep2(i,n){
        if(v.at(i-1)<v.at(i)-1){
            break;
        }
        if(v.at(i-1)==v.at(i)-1){
            v.at(i)--;
        }
        if(v.at(i-1)>=v.at(i) && i==n-1){
            ans="Yes";
        }
    }

    if(n==1){
        ans="Yes";
    }

    cout << ans << endl;

}

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

int main(){
  int N,A;
  int cnt=0;
  int swap=30;//制約による最大操作数
  
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> A;
    cnt = 0;
    while(A%2 ==0&&A != 0){
      A /= 2;
      cnt++;
    }
    if(swap >= cnt) swap = cnt;//Aで操作が最も少ない値
  }
  
  cout << swap << endl;
}

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

int main() {
    
    int N;
    int M;
    cin >> N >> M ;
    
    int s[M];
    int c[M];
    for (int i =0; i < M; i++){
        cin >> s[i];
        cin >> c[i];
    }

    //0頭
    for(int i = 0; i < M; i++){
        if (s[i] == 1 ) {
           //0
            if( c[i] == 0 && N > 1) {
                cout << -1 << endl;
                return 0;
            } 
        }
    }
     //same keta different value
    for(int i = 0; i < M; i++){
        for(int j = i + 1 ; j < M; j++ ){
            if(s[i] == s[j] && c[i] != c[j]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    int answer[3];
    for(int j = 0; j < 3; j++){
        answer[j]=0;
    }
    for(int j = 1; j <= N; j++){
        for(int i = 0; i < M; i++){
            if (s[i] == j ){
                answer[N-j]=c[i];
            }
        }      
    }

    if (answer[N-1]==0 && N-1 > 0 ){
        answer[N-1] = 1;
    }
    

    cout << answer[0] + answer[1]*10 + answer[2]*100 << endl;
    return 0;
}


Measured memory_bytes: 384
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200005
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main()
{
	ll s;
	cin>>s;
	vector<ll> dp(s+1,0);
	dp[0]=1;
	for(int i=3; i<=s; i++){
		for(int j=i-3; j>=0; j--)
			(dp[i]+=dp[j])%=MOD;
	}
	cout<<dp[s];
	return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << 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; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

int n, k, a[100010];

void init() {

}

void input() {
	cin >> n >> k;
	REP(i, n) cin >> a[i];
}

void solve() {
	for(int i = 1, res = 0; ; i += k, res++){
		if (i >= n) {
			cout << res << endl;
			return;
		}
		i--;
	}
}

int main() {
	init();
	input();
	solve();
	return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>
int main(){
	int n;
	scanf("%d",&n);
	long long int a[3*n]={};
	for(int i=0;i<3*n;i++){
		scanf("%lld",&a[i]);
	}
	std::sort(a,a+3*n);
	long long int ans=0;
	for(int i=n;i<=3*n-2;i+=2){
		ans+=a[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
//#include <list>
#include <iomanip>
//#include <stdlib.h>
//#include <cctype>

using namespace std;

const int MAX_N = 1000000;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
template <typename T>
void printV(const std::vector<T>& v, const char * const separator = " ")
{
    if(!v.empty())
    {
        std::copy(v.begin(),
                  --v.end(),
                  std::ostream_iterator<T>(std::cout, separator));
        std::cout << v.back() << "\n";
    }
}


Int gcd(Int a, Int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

Int lcm(Int a, Int b) {
    return a / gcd(a, b) * b;
    //a*bは64bit integer overflow
}

int Max(int a, int b, int c) {
    int temp = max(a, b);
    return max(temp, c);
}

int Min(int a, int b, int c) {
    int temp = min(a, b);
    return min(temp, c);
}

bool integer(double num) {
    return floor(num) == num;
}

Int fact(int num) {
    if (num == 0)
        return 1;
    else
        return num * fact(num - 1);
}

void y() {
    cout << "Yes" << endl;
    exit(0);
}

void n() {
    cout << "No" << endl;
    exit(0);
}

void Y() {
    cout << "YES" << endl;
    exit(0);
}

void N() {
    cout << "NO" << endl;
    exit(0);
}

Int yakusu(int n) {
    int cnt = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            cnt++;
            if (i * i != n) cnt++;
        }
    }
    return cnt;
}

/*   kokomade  */

int cnt = 0;
bool is_prime[ 50000 + 1 ];
vector<int> P;
void Eratosthenes( const int N )
{
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;//初期化
    }
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
}

int main() {
    IOS;
    int n,x,t;cin>>n;
    // int a,b,c;cin>>a>>b>>c;
    // string str;cin>>str;
    vector<Int> h(n);
    // vector<string> s(n);
    for (int i = 0; i < n; ++i) {
        cin>>h[i];
    }
    Int now=h[0];
    bool ok=1;
    int cnt=0,ans=0;
    for (int i = 0; i < n-1; ++i) {
        now=h[i];
        if(h[i+1]<=now){
            cnt++;

        }else{
            //ans=max(ans,cnt);

            cnt=0;
        }
        ans=max(ans,cnt);
    }
    cout<<ans;


    cout<<endl;
    return 0;
}

/*
テレビも無ェ ラジオも無ェ
自動車もそれほど走って無ェ
ピアノも無ェ バーも無ェ
巡査 毎日ぐーるぐる
朝起ぎで 牛連れで
二時間ちょっとの散歩道
電話も無ェ 瓦斯も無ェ
バスは一日一度来る
俺らこんな村いやだ 俺らこんな村いやだ
東京へ出るだ 東京へ出だなら
銭コァ貯めで 東京でベコ(牛)飼うだ
*/


Measured memory_bytes: 1024
// 5/9 過去問ガリガリ
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int A[3];
    cin >> A[0] >> A[1] >> A[2];

    sort(A, A + 3);

    if (A[0] == A[1] && A[1] != A[2]) cout << "Yes" << endl;
    else if (A[0] != A[1] && A[1] == A[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	string str; cin >> str;

	ll res{0};
	for (ll i = 0; i+1 < (ll)str.size(); ++i)
		res += (str[i] != str[i+1]);
	std::cout << res << std::endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

//const i64 mod = 1'000'000'000ll + 7;
const i64 smod = 998244353ll;
//const i64 inf = 1'000'000'000'000'000'000ll + 7;
//const i64 inf = 1'000'000'007;

const long double eps = 1e-8;

const i64 MAXN = 200'000 + 5;

i64 n;
string s;
string t;

void gen() {
    srand(time(0));

    i64 MAXN = 1'000'000;
    stringstream ss;
    for (i64 i = 0; i < MAXN; i++) {
        ss << (char)('0' + rand() % 2);
        //ss << (char)('0' + i % 2);
    }
    s = ss.str();

    t = s;
    n = s.size();
    for (i64 i = 0; i < log(MAXN) + 2; i++) {
        i64 k = rand() % n;
        t = t.substr(k) + t.substr(0, k);
    }
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    i64 z;
    cin >> z;

    double pi = acos(0) * 2;

    double a = 0.0;
    double x = 0.0;
    double y = 0.0;

    i64 R = 0;
    while (true) {
        R += 1;

        x += cos(a);
        y += sin(a);

        a += pi * z / 180.0;
        
        if (abs(x) + abs(y) < eps) {
            break;
        }
    }


    cout << R << endl;
    return 0;
}


Measured memory_bytes: 4008
#include<bits/stdc++.h>
using namespace std;
signed main(){
  string a;
  cin>>a;
  for(int i=0;i<3;i++){
    if(a[i]=='9') cout<<"1";
    if(a[i]=='1') cout<<"9";
    if(a[i]!='1'&&a[i]!='9') cout<<a[i];
  }
  cout<<"\n";
}


Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, A, B;
    scan(N, A, B);
    long a = A * (N / (A + B));
    long b = min((N % (A + B)), A);
    writeln(a + b);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

    int A, B;

    scanf("%d %d", &A, &B);

    if(A + B <= 16){
        if(A <= 8 && B <= 8){
            printf("Yay!\n");
        }else{
            printf(":(\n");
        }
    }



    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

template<typename value_type>
class merge_sort_tree
{
public:
	int data_count;

	vector<value_type> data_list;

	vector<vector<value_type>> tree;
	long long swap_count;

public:
	merge_sort_tree(int _data_count)
		: data_count(_data_count), data_list(), tree(), swap_count(0)
	{
		data_list.assign(data_count, 0);

		int height = (int)ceil(log2(data_count));
		int tree_size = (1 << (height + 1));
		tree.assign(tree_size, vector<value_type>());
	}

public:
	void init()
	{
		inner_init(1, 0, data_count - 1);
	}

	void inner_init(int node, int start, int end)
	{
		if (start == end)
		{
			tree[node].push_back(data_list[start]);
		}
		else
		{
			int mid = (start + end) / 2;
			inner_init(node * 2, start, mid);
			inner_init(node * 2 + 1, mid + 1, end);

			int left_idx = 0;
			int right_idx = 0;
			while (left_idx < tree[node * 2].size() && right_idx < tree[node * 2 + 1].size())
			{
				if (tree[node * 2][left_idx] > tree[node * 2 + 1][right_idx])
				{
					swap_count += tree[node * 2].size() - left_idx;
					right_idx++;
				}
				else
				{
					left_idx++;
				}
			}

			merge(tree[node * 2].begin(), tree[node * 2].end(), tree[node * 2 + 1].begin(), tree[node * 2 + 1].end(), back_inserter(tree[node]));
		}
	}

	int query(int left, int right, value_type val)
	{
		return inner_query(1, 0, data_count - 1, left, right, val);
	}

	int inner_query(int node, int start, int end, int left, int right, value_type val)
	{
		if (right < start || end < left) return 0;
		if (left <= start && end <= right)
		{
			return distance(upper_bound(tree[node].begin(), tree[node].end(), val), tree[node].end());
		}

		int mid = (start + end) / 2;
		int left_count = inner_query(node * 2, start, mid, left, right, val);
		int right_count = inner_query(node * 2 + 1, mid + 1, end, left, right, val);

		return left_count + right_count;
	}
};

//merge_sort_tree<long long> ms(N);
//ms.data_list[i] = val;
//ms.init();
//int ret = ms.query(left, right, val);

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

	string S;
	cin >> S;

	merge_sort_tree<int> ms(S.size());

	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == 'B') ms.data_list[i] = 1;
	}

	ms.init();

	cout << ms.swap_count;

	return 0;
}


Measured memory_bytes: 41232
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <stack>

using std::vector;
using std::printf;
using std::cout;
using std::endl;
using std::string;
using std::cin;
using std::pair;
using std::sort;

#define i64t long long int
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

template<typename T>
void dump(vector<T> vec) {
    for (auto x : vec) {
        std::cout << x << " ";
    }
    std::cout << std::endl;
}

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

const i64t MOD = 1000000007;

int main() {
    int N;
    cin >> N;
 
    printf("%d\n", N*N*N);
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(first, second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll, ll, ll>>>;

// MOD確認

ll tableF[200010];
ll tableI[200010];

ll modfact(ll a,ll m){
   if(tableF[a] != -1){
      return tableF[a];
   }
   if(a == 1){
      tableF[a] = 1;
      return tableF[a];
   }
   ll res = 1;
   res = a * modfact(a-1,m);
   res %= m;
   tableF[a] = res;
   return res;
}

ll modpow(ll a,ll n,ll m){//modpow(a,n,m) := a ^ n (mod m)
  ll res = 1;
  while(n > 0){
    if(n & 1)res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a,ll p){//modinv(a,p) := pを法とするaの逆元(※pは素数でなければならない)
    ll res = modpow(a,p-2,p);
    return res;
}

ll modCON(ll n,ll r,ll m){
   if(n < 200010){
   ll res = 1;
   if(n < 0 || r < 0 || n < r){
      return 0;
   }
   res *= tableF[n];
   res %= m;
   res *= tableI[r];
   res %= m;
   res *= tableI[n-r];
   res %= m;
   return res;
   }else{
   ll res = 1;//tableを持ってないときよう
   for(int i = 1;i <= n;i++){
      res *= i;
      res %= m;
   }
   for(int i = 1;i <= r;i++){
      res *= modinv(i,m);
      res %= m;
   }
   for(int i = 1;i <= n-r;i++){
      res *= modinv(i,m);
      res %= m;
   }
   return res;
   }
}

void modfill(ll m){//忘れない　約200ms
   fill(tableF,tableF+200010,-1);
   fill(tableI,tableI+200010,-1);
   tableF[0] = 1;
   tableI[0] = 1;
   for(int i = 1;i < 200010;i++){
      tableF[i] = modfact(i,m);
      tableI[i] = modinv(tableF[i],m);
   }
}

ll P[1010];

int main(){
   ll N,K;
   cin >> N >> K;
   rep(i,N) cin >> P[i];
   sort(P,P+N);
   ll ans = 0;
   rep(i,K) ans += P[i];
   cout << ans << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>
using namespace std;

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define llrp(i,n) for(long long i=0;i<n;i++)
#define llrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define vcin(a); rp(i,a.size()){cin>>a[i];}
#define vcout(a); rp(i,a.size()){cout<<a[i]<<endl;}
#define allchar(c) for(char c='a';c<='z';c++)
#define mp(a,b) make_pair(a,b)
#define bs(a,n) binary_search(a.begin(),a.end(),n)

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;
typedef queue<int> qi;

const int mod=1e9+7;

ll modpow(ll a,ll b,ll p){
    if(b==0){
        return 1;
    }elif(b%2==0){
        return modpow((a*a)%p,b/2,p);
    }else{
        return (a*modpow(a,b-1,p))%p;
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    int ans=0;
    vi x(m),y(m);
    rp(i,m){
        cin >> x[i] >> y[i];
    }
    vi num(n);
    rp(i,n){
        num[i]=1;
    }
    vb pos(n);
    pos[0]=true;
    rep(i,1,n-1){
        pos[i]=false;
    }
    rp(i,m){
        num[x[i]-1]--;
        num[y[i]-1]++;
        if(pos[x[i]-1])    pos[y[i]-1]=true;
        if(num[x[i]-1]==0)  pos[x[i]-1]=false;
    }
    int cnt=0;
    rp(i,n){
        if(pos[i])  cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
const long long INF = 1LL<<60;
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(){
    ll N, K; cin >> N >> K;
    vector<ll> h(N, 0);
    rep(i, N) {
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    // view(h);
    ll ans = 1000000000;
    rep(i, N - K + 1) {
        ll cand = h[i + K - 1] - h[i];
        // cout << cand << endl;
        if (cand < ans) ans = cand;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
using namespace std;

int l,n,m=-1;
 
int main() {
	scanf("%d",&l);
	for (; l>=1<<n; n++)
		if (l&(1<<n)) m++;
	m+=(n-1)*2;
	printf("%d %d\n",n,m);
	for (int i=1; l>1; i++){
		if (l&1) printf("%d %d %d\n",i,n,l-1);
		l>>=1;
		for (int j=0; j<2; j++) printf("%d %d %d\n",i,i+1,j*l);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
	int n;
	int a[100001] = { 0 }, b[100001] = { 0 }, i, j,min,ma=0;
	cin >> n;
	for (i =1 ; i <= n; i++)
	{
		cin >> a[i] >> b[i];
		if (a[i] > a[ma]) ma = i;
	}
	min = a[ma] + b[ma];
	cout << min;
	return 0;
}

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

int main() {
    ll H = 0;
    cin >> H;

    ll k = 0;
    if (H == 1) {
        cout << 1 << endl;
    } else {
        while(1) {
            H /= 2;
            ++k;
            if (H == 1) break;
        }
        ll ans = 1;
        for (ll i = 1; i <= k; i++) {
            ans += pow(2, i);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
class Dictionary
  DNA = [''] + %w(A C G T)

  def initialize n
    @size = n
    @container = Array.new(@size)
  end
  attr_accessor :ret

  def exec command, str = ''
    case command
    when 'insert' then insert str
    when 'find'   then puts(find?(str) ? 'yes' : 'no')
    else raise '??????'
    end
  end

  private

  def insert str
    if @container[hash(str)].nil?
      @container[hash(str)] = LinkList.new str
    else
      group = @container[hash(str)]
      found = group.has? str
      group.insert(str) unless found
    end
  end

  def find? str
    linked_list = @container[hash(str)]
    return false if linked_list.nil?

    linked_list.has?(str)
  end

  def hash str
    return str.hash % @size
    # ?¶??´???´???????£? (????????????)
    # AGCT -> 4?????° -> 10?????°???????????????
    #base = DNA.size
    #size = str.size
    #sum = 0
    #str.chars.each.with_index {|c, index|
    #  # ????????????4?????°??§??¨?????????
    #  n = get_dna_index c
    #  # ?????????????????????10?????°?????????
    #  # (??? ** ??????????????????) * ???
    #  # ?????????????????????10?????°???????????¨????¶????
    #  sum += (base ** (size - index)) * n
    #}
    #sum % @size
  end

  def get_dna_index char
    DNA.index char
  end

  # ??????????????\???????????????????´?????????????????????????
  class LinkList

    def initialize first_value
      @first = Node.new first_value, nil
    end

    def insert key
      new_node = Node.new key, @first
      @first = new_node
    end

    def has? key
      current = @first
      until current.nil?
        if current.key == key
          return true
        else
          current = current.next
        end
      end
      false
    end

    # ????????????????????¨?????¢?????????
    class Node
      def initialize key, next_node
        @key = key
        @next = next_node
      end
      attr_accessor :key, :next
    end
  end
end

def main size, commands
  dic = Dictionary.new size.to_i
  commands.each{|raw_command|
    command, str = raw_command.split ' '
    dic.exec(command, str)
  }
end

array = STDIN.read.split(/\n/)
size = array.shift

main(size, array)

Measured memory_bytes: 178124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
int inf=1000001000;
ll INF=100000000000000000;
ll MOD=1000000007;
//g++ code.cpp   ./a.out 
 
int main() {
    string s; cin >> s;
    deque<char> q;
    for(char c : s) q.push_back(c);
    int a; cin >> a;
    bool cnt=false;
    rep(i,a){
       int f; cin >> f;
       if(f==1) cnt=!cnt;
       if(f==2){
          int a; cin >> a;
          char c; cin >> c;
         if(cnt){
            if(a==2) q.push_front(c);
            else q.push_back(c);
         }
         else{
            if(a==2) q.push_back(c);
            else q.push_front(c);
         }
       }
    }
    if(cnt) reverse(q.begin(), q.end());
    string ans;
    for (char c : q) ans += c;
   cout << ans << endl;
}



Measured memory_bytes: 1412
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  vector<vector<int>> x(n),y(n);
  rep(i,n){
    cin >> a[i];
    x[i].resize(a[i]);
    y[i].resize(a[i]);    
    rep(j,a[i]){
      cin >> x[i][j];
      cin >> y[i][j];
    }
  }

  int res=0;
  rep(S,(1<<n)){
    vector<bool> f(n,false);
    bool ff = true;
    int cnt=0;
    rep(j,n){
      if((S>>j)&1){
	f[j]=true;
	cnt++;
      }
    }
    rep(j,n){
      rep(k,a[j]){
	if(f[j]){
	  if(y[j][k]==1){
	    if(f[x[j][k]-1]==0){
	      ff = false;
	    }
	  }
	  else{
	    if(f[x[j][k]-1]==1){
	      ff = false;
	    }
	  }
	}
      }
    }

    if(ff)res = max(res,cnt);
  }

  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 256
def resolve():
  h, w = map(int, input().split())
  s = []
  for i in range(h):
    s.append(input())

  for i in range(h):
    for j in range(w):
      if s[i][j] == '.':
        continue
      flag = False
      if i > 0 and s[i-1][j] == '#':
        flag = True
      if i < h-1 and s[i+1][j] == '#':
        flag = True
      if j > 0 and s[i][j-1] == '#':
        flag = True
      if j < w-1 and s[i][j+1] == '#':
        flag = True
      if not flag:
        print('No')
        return
  print('Yes')
  return

if __name__ == "__main__":
  resolve()


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

int main(){
  long long N,sum=0;
  cin >> N;
  vector<long long> V(100001,0);
  for(int i=0;i<N;i++){
    long long a;
    cin >> a;
    V[a]++;
    sum += a;
  }
  
  long long Q;
  cin >> Q;
  for(int i=0;i<Q;i++){
    long long b,c;
    cin >> b >> c;
    sum += (c-b) * V[b];
    V[c] += V[b];
    V[b] = 0;
    cout << sum << endl;
  }
  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int tot = 700;
    for(int i = 0; i < s.size(); i ++) if(s[i] == 'o') tot += 100;
    cout << tot << endl;
    return 0;
}


Measured memory_bytes: 256