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

int main() {
  int s;
  cin >> s;
  int s1 = s / 100;
  int s2 = s / 10 - s1 * 10;
  int s3 = s - s1 * 100 - s2 * 10;
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
PROGRAM ATCODER

implicit none
integer(16) :: n, w_max, i, j, sum_w
integer(16), allocatable :: w(:), v(:), dp(:,:)

read(*,*) n, w_max
allocate(dp(0:n,0:w_max), w(0:n), v(0:n))

dp = 0

do i = 0, n-1
	read(*,*) w(i), v(i)
end do

do i = 0, n-1
	do sum_w = 0, w_max
    	if (sum_w-w(i) >= 0) then
        	call chmax(dp(i+1,sum_w), dp(i,sum_w-w(i))+v(i))
        end if
		call chmax(dp(i+1,sum_w), dp(i,sum_w))
    end do
end do

write(*,'(i0)') maxval(dp)

END PROGRAM ATCODER

subroutine chmax(dp,x)
implicit none
integer(16) :: dp, x

if (dp < x) then
	dp = x
	return
end if

end subroutine

Measured memory_bytes: 158080
#include<iostream>
#include<string>
using namespace std;
int main() {
  string str;
  cin >> str;
  int n;
  cin >> n;
  for(int i = 0 ; i < n ; i++ ){
    string op;
    cin >> op;
 
    if(op == "replace") {
 
        int a, b;
        string repstr;
        cin >> a >> b >> repstr;
        auto it = str.begin() + a;
        for (int j = 0; j <= b-a; j++){
          *it++ = repstr[j];
        }
 
    } else if (op == "reverse") {
 
        int a, b;
        cin >> a >> b;
        string str2 = str;
        auto it = str.begin() + a;
        auto it2 = str2.begin() + b;
        for (int j = 0; j <= b-a; j ++) {
          *it++ = *it2--;
        }
 
 
    } else if (op == "print") {
        int a, b;
        cin >> a >> b;
        auto it = str.begin() + a;
        for (int j = 0; j <= b-a; j++){
          cout <<  *it++;
        }
        cout << endl;
 
    }
  }
 
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K, result=1, A, B;
  cin >> N >> K;

  while(N > 0){

    A = result * 2;
    B = result + K;

    if(A > B) result = B;
    else result = A;

    N--;
  }

  cout << result << endl;
  

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int n = kb.nextInt();
		int k = kb.nextInt();
		int count =0;
		while(Math.pow(k, count)<=n) {
			count++;
		}
		System.out.println(count);
		kb.close();
		
	}

}


Measured memory_bytes: 21972
#include <iostream>
#define llint long long

using namespace std;

int H, W;
char c[405][405];
bool used[405][405];

int di[] = {1, 0, -1, 0};
int dj[] = {0, -1, 0, 1};

llint odd, even;
llint dfs(int i, int j)
{
	if((i+j)%2) odd++;
	else even++;
	used[i][j] = true;
	
	for(int d = 0; d < 4; d++){
		int ni = i+di[d], nj = j+dj[d];
		if(ni <= 0 || ni > H || nj <= 0 || nj > W) continue;
		if(used[ni][nj]) continue;
		if(c[ni][nj] != c[i][j]) continue;
		dfs(ni, nj);
	}
}

int main(void)
{
	cin >> H >> W;
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= W; j++){
			cin >> c[i][j];
		}
	}
	
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= W; j++){
			if((i+j)%2){
				if(c[i][j] == '#') c[i][j] = '.';
				else c[i][j] = '#';
			}
		}
	}
	
	llint ans = 0;
	for(int i = 1; i <= H; i++){
		for(int j = 1; j <= W; j++){
			if(used[i][j]) continue;
			odd = 0, even = 0;
			dfs(i, j);
			ans += odd*even;
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;
using ll = long long;

int main() {
  ll n, d;
  cin >> n >> d;

  int c = 0;
  
  for (int i = 0; i < n; i++) {
      long long x;
      long long y;
      cin >> x >> y;
      if (x*x+y*y <= d*d) {
          c++;
      }
  }


  cout << c << endl;

}


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

#define ll long long

using namespace std;

ll arr[100005];
ll dp[100005],n,k;
ll func(ll x)
{
    if(x==n-1)
        return 0;
    if(x>=n)
        return 1e18;
    if(dp[x]!=-1)
        return dp[x];
    ll way=1e18;
    for(ll i=1;i<=k;i++)
    {
        way=min(way,abs(arr[x]-arr[x+i])+func(x+i));
    }

    return dp[x]=way;
}

int main()
{
    memset(dp,-1,sizeof(dp));
    ll i,j,l,m;
    cin >> n >> k;
    for(i=0;i<n;i++)
        cin >> arr[i];
    arr[n]=1e18;

    cout << func(0);
}


Measured memory_bytes: 6528
from collections import deque
def main():
    n=int(input())
    x=deque()
    r=False
    for i in map(int,input().split()):
        if r:
            x.appendleft(i)
        else:
            x.append(i)
        r = not r
    if r:
        x.reverse()
    print(*x)

if __name__ == "__main__":
    main()

Measured memory_bytes: 31452
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			scanner.nextInt();
			int m = scanner.nextInt(), x = scanner.nextInt();
			int[] a = new int[m];
			IntStream.range(0, m).forEach(i -> a[i] = scanner.nextInt());
			System.out.println(
					Math.min(Arrays.stream(a).filter(i -> i > x).count(), Arrays.stream(a).filter(i -> i < x).count()));
		}
	}
}


Measured memory_bytes: 28884
//Aizu11A 16D8104015E Nobushige Sen 18.6.22

#include<iostream>
using namespace std;
 
int x[15000][15000],n,q,r,b;
 
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> q >> r;
        for (int j = 0; j < r; j++) {
            cin >> b;
            x[i][b] = true;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < n; j++) {
            if (j) { cout << ' '; }
            cout << x[i][j+1];
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3412
from operator import mul

n, m, c = map(int, input().split())
B = list(map(int, input().split()))
A = []
for _ in range(n):
    A.append(list(map(int, input().split())))
# print(B)
# print(A)
cnt = 0
for i in range(n):
    # print(A[i])
    AB = list(map(mul, A[i], B))
    # print(list(AB))
    if sum(AB) + c > 0:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
INF = 10 ** 9 + 1
MAV_V = 10 ** 5 + 1

def main():
    N, W = map(int, input().split())
    dp = [[INF] * MAV_V for _ in range(N+1)]
    dp[0][0] = 0

    for i in range(1, N+1):
        w, v = map(int, input().split())
        pre_dp = dp[i-1]
        for j in range(v):
            dp[i][j] = min(pre_dp[j], w)
        for j in range(v, MAV_V):
            if pre_dp[j-v] + w <= W:
                dp[i][j] = min(pre_dp[j-v] + w, pre_dp[j])
            else:
                dp[i][j] = pre_dp[j]

    ans = [i for i, v in enumerate(dp[-1]) if v != INF]
    print(max(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 119148
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const int MAX = 210000;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    COMinit();

    ll n, m, k;
    cin >> n >> m >> k;
    ll w = COM(n * m - 2, k - 2);

    ll ans = 0;
    for (ll dx = 1; dx < m; dx++)
    {
        ll a = (n * n * (m - dx)) % MOD;
        ans = (ans + a * dx % MOD) % MOD;
    }

    for (ll dy = 1; dy < n; dy++)
    {
        ll a = (m * m * (n - dy)) % MOD;
        ans = (ans + a * dy % MOD) % MOD;
    }

    cout << (ans * w) % MOD << endl;
}

Measured memory_bytes: 5120
#input
input = int(input())
#b = int(input())
s = [0,0,0]
s[0] = int(input/100)
s[1] = int(input/10 - s[0]*10)
s[2] = int(input%10)

count=0
a=0
for i in range(3):
  #print(str(i) + '\n')
  if s[i] == 1:
    count += 1

print(count)




Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Go_ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e3+100;


int main()
{
    Go_
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    int last=1;
    
    cin>>n;
    if(n & 1ll) cout<<"0"<<endl;
    else{
        n/=2;
        ll ct=0;
        while((n/5))
        {
            ct+=(n/5);
            n/=5;
        }

        cout<<ct<<endl;
    }

}

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

int main() {
	char * str;
	str = malloc(25 * sizeof(char));
	for(int i=0;i<19;++i)
		scanf("%c",&str[i]);
	
	for(int i=0;i<19;++i) {
	if(str[i] == ','){
		printf(" ");
		continue;
	}
	printf("%c",str[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;

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

    ll yen = 100;
    int ans = 0;

    while(yen<x){
        yen *= 1.01;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
data = raw_input().split("T")
x_a, y_a = map(int,raw_input().split(" "))
x = []
y = []

for a in range(len(data)):
   if a % 2 == 0:
      x.append( data[a].count("F") )
   else:
      y.append( data[a].count("F") )

x_now = x[0]
x = x[1:]

x = sorted(x)[::-1]
y = sorted(y)[::-1]

for xx in range(0,len(x)):
  if x_now > x_a:
    x_now -= x[xx]
  else:
    x_now += x[xx]
  
y_now = 0
for yy in range(0,len(y)):
  if y_now > y_a:
    y_now -= y[yy]
  else:
    y_now += y[yy]

if x_now == x_a and y_now == y_a:
  print "Yes"
else:
  print "No"
  

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

int P [10]={0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2};
int Q [10]={1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3};
int R [10]={2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4};
ll d[5];
ll m,a,r,c,h;

int main(){
  int n; cin >>n;
  rep(i,n){
    string s; cin >>s;
    if(s[0]=='M') m++;
    if(s[0]=='A') a++;
    if(s[0]=='R') r++;
    if(s[0]=='C') c++;
    if(s[0]=='H') h++;
  }
  d[0]=m,d[1]=a,d[2]=r,d[3]=c,d[4]=h;
  ll ans = 0;
  rep(i,10){
    ans += d[P[i]]*d[Q[i]]*d[R[i]];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
import sys
input = sys.stdin.readline
N = int(input())
li = [int(i) for i in input().split()]
sum = 0
a = 1
for i in range(N) :
    while(a) :
        if li[i]%2 == 0 :
            sum +=1
            li[i]/=2
        else :
            break
print(sum)

Measured memory_bytes: 4084
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<int> t(N), d(N);
  REP(i, N) cin >> t[i] >> d[i];

  priority_queue<P> q;
  priority_queue<P, vector<P>, greater<P>> qans;
  REP(i, N) q.push(P(d[i], t[i]));

  ll x = 0;
  ll ans = 0, score = 0;
  map<ll, int> mp;
  for (int i = 0; i < K; i++) {
    P p = q.top();
    q.pop();
    if (mp.count(p.second) == 0) x++;
    mp[p.second]++;
    score += p.first;
    qans.push(p);
    ans = max(ans, (score + x * x));
  }

  while (!qans.empty() && !q.empty()) {
    P p = qans.top();
    qans.pop();
    // 一個しかなければ取り除かない
    if (mp[p.second] <= 1) continue;
    score -= p.first;
    mp[p.second]--;

    // 新しいものの中で、初めての種類のものを抽出する
    P pp = q.top();
    q.pop();
    while (!q.empty() && mp[pp.second] != 0) {
      pp = q.top();
      q.pop();
    }
    if (mp[pp.second] != 0) break;
    score += pp.first;
    mp[pp.second]++;
    x++;
    qans.push(pp);
    ans = max(ans, (score + x * x));
  }
  cout << ans << endl;

  return 0;
}


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

#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define int long long
#define endl '\n'

using namespace std;

const int N = 2e5 + 77;
// int A[N];

void sol(){
    int n , m ; cin >> n >> m ;
    priority_queue<int> A;
    for(int i = 0 ; i < n ; ++i){
        int a ; cin >> a;
        A.push(a);
    }
    while(m--){
        int a = A.top();
        A.pop();
        a /= 2;
        A.push(a);    
    }
    int ans =0 ;
    while(!A.empty()){
        ans += A.top();
        A.pop();
    }
    cout << ans << endl;
}

int32_t main(){
    fast;
    int t = 1; 
    // cin >> t; 
    while(t--) sol();    
    return 0;
}

Measured memory_bytes: 4232
#include"bits/stdc++.h"
using namespace std;

int main(){
    int n; cin >> n;
    int h[n]; for(int i=0; i<n; i++) cin >> h[i];
    int flag = 0;
    for(int i=n-1; i>0; i--){
        if(h[i]-h[i-1] == -1){
            h[i-1] = h[i-1]-1;
        }else if(h[i]-h[i-1] < -1){
            flag = 1;
            break;
        }
    }
    if(flag == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cassert>

#include <unordered_set>
#include <unordered_map>
#include <random>
#include <thread>
#include <chrono>

using namespace std;

#define val const auto
#define var auto

#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x) 
#endif

typedef complex<double> point;

template<typename T,std::size_t N>
struct _v_traits {using type = std::vector<typename _v_traits<T,N-1>::type>;};
template<typename T>
struct _v_traits<T,1> {using type = std::vector<T>;};
template<typename T,std::size_t N=1>
using vec = typename _v_traits<T,N>::type;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    for(auto it = v.begin(); it != v.end(); ++it){
        if(it != v.begin()){
            os << ",";
        }
        os << *it;
    }
    return os << "}";
}

template <typename T>
T read_next(){
    T ret; cin >> ret;
    return ret;
}


template<typename T>
void isort(std::vector<T>& v, std::function<bool(T,T)> comp=less<T>()){
    sort(v.begin(), v.end(), comp);
}
template<typename T>
std::vector<T> sort(std::vector<T> v, std::function<bool(T,T)> comp=less<T>()){
    isort(v);
    return v;
}
template<typename T1, typename T2>
std::vector<T2> rmap(const std::vector<T1>& v, std::function<T2(T1)> f){
    std::vector<T2> t; t.reserve(v.size());
    for(const auto& i: v) t.push_back(f(i));
    return t;
}
std::vector<std::string> split(std::string str, char delim){
    std::vector<std::string> res;
    size_t current = 0, found;
    while((found = str.find_first_of(delim, current)) != std::string::npos){
        res.push_back(std::string(str, current, found - current));
        current = found + 1;
    }
    res.push_back(std::string(str, current, str.size() - current));
    return res;
}
string join(const std::vector<string>& v, string delim){
    string ret = "";
    for(auto it = v.begin(); it != v.end(); ++it){
        if(it != v.begin()){
            ret += delim;
        }
        ret += *it;
    }
    return ret;
}


using i64 = int64_t;
using i32 = int32_t;

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

    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];
    sort(all(v));

    int max_diff = -1;
    int k = 0;
    for (int i = 0; i < n-1; i++) {
        int diff = min(v.back() - v[i], v[i]);
        if (diff >= max_diff) {
            k = v[i];
            max_diff = diff;
        }
    }
    cout << v.back() << " " << k << endl;
    return 0;
}


Measured memory_bytes: 640
N = int(input())
v = sorted([int(v) for v in input().split(' ')])

from heapq import heappush, heappop

h = []
for a in v:
    heappush(h, a)

while len(h) > 1:
    v1 = heappop(h)
    v2 = heappop(h)
    heappush(h, (v1 + v2) / 2)

print(h[0])



Measured memory_bytes: 3060
# 0028
array = []
while True:
    try:
        a = input()
        array.append(int(a))
    except EOFError:
        break
s = set(array)
count= list(map(lambda a: array.count(a), s))
mx = max(count)
modes = list(list(s)[i] for i, x in enumerate(count) if x == mx)
print(*sorted(modes), sep = '\n')

Measured memory_bytes: 7764
#include<iostream>
using namespace std;
int main()
{
  char puzzle[52][52];
  int min[52][52];
  for(int i = 0; i < 52 ;i++){
    for(int j = 0; j < 52 ;j++){
      puzzle[i][j] = '#';
      min[i][j] = -1;
    }
  }
  min[1][1] = 0;

  int counter=0;
  char c;
  int h,w;
  cin >> h;
  cin >> w;
  for(int i = 0; i<h; i++){
    for(int j = 0; j<w; j++){
      cin >> puzzle[i+1][j+1];
      if(puzzle[i+1][j+1] == '#'){
        counter++;
      }
    }
  }

  bool endfrag = false;//true ならこれ以上どこにも行けない
  bool goal = false;
  int loop = 0;
  while((!goal) && (!endfrag)){
    endfrag = true;
    for(int i = 0; i<h; i++){
      for(int j = 0; j<w; j++){
        if(min[i+1][j+1] == loop){
          // 右
          if(puzzle[i+1][j+2] == '.' && min[i+1][j+2] == -1){
            min[i+1][j+2] = loop+1;
            endfrag = false;
          }
          // 下
          if(puzzle[i+2][j+1] == '.' && min[i+2][j+1] == -1){
            min[i+2][j+1] = loop+1;
            endfrag = false;
          }
          // 左
          if(puzzle[i+1][j] == '.' && min[i+1][j] == -1){
            min[i+1][j] = loop+1;
            endfrag = false;
          }
          // 上
          if(puzzle[i][j+1] == '.' && min[i][j+1] == -1){
            min[i][j+1] = loop+1;
            endfrag = false;
          }
        }
      }
    }

    if(min[h][w] != -1){
      goal = true;
    }
    loop++;
  }
  if(min[h][w] == -1){
    cout << -1 << endl;
  }else{
    cout << (h*w - min[h][w] - counter -1) << endl;
  }

  return 0;
}


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

int n;
int q;
int s[11111]={0};
int t;
int c=0;

int main(){

  scanf(" %d",&n);

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

  scanf(" %d",&q);

  for(int i=0;i<q;i++){
    scanf(" %d",&t);
    for(int j=0;j<n;j++){
      if(s[j]==t){
        c++;
        break;
      }
    }
  }

  cout << c << endl;

  return 0;

}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

ll powmod(ll a,ll n,ll m) {
    if(n == 0)
        return 1;

    if(n % 2 ==0){
        ll r = powmod(a,n/2,m);
        return r*r % m;
    }

    return a*powmod(a,n-1,m)%m;
}

ll factmod(ll a,ll b,ll m) {
  if(a<b)return 0;
  ll s=1;
  while(a>=b){
    s = s*a % m;
    a -= 1;
  }
  return s;
}

ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

ll combmod(ll a,ll b,ll m){
  if(b==0)return 1;
  ll c=factmod(a,a-b+1,m);
  ll d=modinv(factmod(b,1,m),m);
  ll e=(c*d)%m;
  return e;
}

int main(){

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

  sort(a,a+n);

  ll s=0;

  ll dp[n+1]={};
  dp[k-1]=1;
  for(ll i=k;i<n+1;i++){
    dp[i]=dp[i-1]*i;
    dp[i]%=mod;
    dp[i]*=modinv(i-k+1,mod);
    dp[i]%=mod;
  }

  for(ll i=k-1;i<n;i++){
    ll b=dp[i];
    b*=a[i];
    b%=mod;
    s+=b;
    s%=mod;
  }

  //cout << s << endl;

  for(ll i=0;i<n-k+1;i++){
    ll b=dp[n-1-i];
    b*=a[i];
    b%=mod;
    s-=b;
    s+=mod;
    s%=mod;
  }

  cout << s << endl;


}

Measured memory_bytes: 5084
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;


int main()
{
    int n;
    int mini;
    cin>>n;
    int arr[n];
    for (int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    mini=arr[0];
    int ctr(0);
    for (int i=0;i<n;i++)
    {
        if (arr[i]<=mini)
        {
            ctr++;
            mini=arr[i];
        }
    }
    cout<<ctr<<endl;

}


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

using namespace std;

const int N = 100010;

int n;
int perm[N];

int main(){
	if(fopen("1.inp", "r")){
		freopen("1.inp", "r", stdin);
	}

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

	long long ans = 0;

	for(int i = 1; i <= n; ++i){
		if(perm[i] != i){
			continue;
		}
		
		int pter = i;
		while(perm[pter] == pter){
			++pter;
		}
		--pter;

		int len = pter - i + 1;
		ans += len / 2 + (len % 2);
		i = pter;
	}

	cout << ans;

	return 0;
}	

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  int K, A, B, ans;
  ans = 0;
  cin >> K >> A >> B;
  for (int i = A; i <= B; ++i) {
    if (i % K == 0) {
      ans = 1;
      break;
    }
  }
  if (ans == 1) {
    printf("OK\n");
  } else {
    printf("NG\n");
  }
  return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll par[214514];
ll ran[214514];
ll root(ll x){
	return par[x]==x?x:par[x]=root(par[x]);
}
void unite(ll x,ll y){
	x=root(x);
	y=root(y);
	if(x==y)return;
	if(ran[x]<ran[y])par[x]=y;
	else{
		par[y]=x;
		if(ran[x]==ran[y])ran[x]++;
	}
}
int main(){
	ll n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)par[i]=i;

	while(m--){
		ll a,b;
		cin>>a>>b;
		unite(a,b);
	}
	map<ll,ll>mp;
	for(int i=1;i<=n;i++)mp[root(i)]++;
	cout<<mp.size()-1<<endl;
	return 0;
}


Measured memory_bytes: 9864
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[0] << ' ' << a[1] << ' ' << a[2] << endl;
	return 0;
}


Measured memory_bytes: 3140
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

long X,A,B;
inline void solve(){
  IN3(X,A,B);
  if(B-A<=0)OUT("delicious");
  else if(B-A<=X)OUT("safe");
  else OUT("dangerous");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

using namespace std;

int main(){

    int H, W, h, w;

    cin >> H >> W >> h >> w;

    vector<vector<bool>> map(H, vector<bool>(W, true));

    for(int i = 0; i < h; i++){
	for(int j = 0; j < W; j++){
	    map.at(i).at(j) = false;
	}
    }
    for(int j = 0; j < w; j++){
	for(int i = 0; i < H; i++){
	    map.at(i).at(j) = false;
	}
    }
    int sum = 0;
    for(int i = 0; i < H; i++){
	for(int j = 0; j < W; j++){
	    if(map.at(i).at(j)) sum++;
	}
    }
    cout << sum << endl;
    
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

int a[200005];

int main(){
	int n,k,x,sum = 0;
	scanf("%d %d",&n,&k);
	for(int i = 1;i <= n;i++){
		scanf("%d",&x);
		if(a[x] == 0) sum++;
		a[x]++;
	}
	sort(a + 1,a + 1 + 200000);
	if(sum > k){
		int ans = 0,y = sum - k;
		for(int i = 1;i <= 200000;i++){
			if(a[i] != 0){
				ans += a[i];
				y--;
			}
			if(y == 0) break;
		}
		printf("%d\n",ans);
	}
	else printf("0\n");
}

Measured memory_bytes: 1024
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <memory.h>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <queue>

using namespace std;

#define TT1T2 template<class T1, class T2>
TT1T2 void debug_print_array(const T1 &a, T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cerr << a[i] << (i + 1 != sz ? "," : ""); cout << endl; }
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DA(a,n) cerr<<#a<<"=["; debug_print_array(a,n); cerr<<"]\n"
double __begin;
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <typename T, const int N> using Graph = vector <T> [N];

const int MAXN = 2000 + 100;
bool used[MAXN];
Graph<int, MAXN> g;

pair <int, int> dfs(int v, int k) {
    used[v] = true;
    if (k == 0) {
        return {0, 1};
    }

    pair <int, int> res = {1, 0};

    for (int& to : g[v]) {
        if (!used[to]) {
            auto it = dfs(to, k - 1);
            res.first += it.first;
            res.second += it.second;
        }
    }
    return res;
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(20);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n, k;
    cin >> n >> k;
    k++;

    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int ans = 0;

    for (int i = 0; i < n; i++) {
        memset(used, 0, sizeof(used));

        used[i] = true;

        vector <pair <int, int>> tmp;

        for (int& to : g[i]) {
            auto dfsRes = dfs(to, (k - 1) / 2);
            tmp.emplace_back(dfsRes.first, dfsRes.first + dfsRes.second);
        }
        int sum = 0;
        for_each(tmp.begin(), tmp.end(), [&sum](const pair <int, int>& p) {
            sum += p.first;
        });
        ans = max(ans, sum);

        if (k % 2 == 0) {
            for (auto& el : tmp) {
                ans = max(ans, sum - el.first + el.second);
            }
        }
    }

    cout << n - ans - 1 << endl;

    return 0;
}

Measured memory_bytes: 384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"

using namespace std;
const long long int MOD = 1000000007;

int H, W;
char field[500][501] = {};
char blue[500][501] = {};
char red[500][501] = {};

int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> field[i];
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			blue[i][j] = '.';
			red[i][j] = '.';
		}
	}
	for (int i = 0; i < H; i++) {
		if (i % 2) {
			for (int j = 0; j < W - 1; j++) {
				red[i][j] = '#';
			}
			blue[i][W - 1] = '#';
		}
		else {
			red[i][0] = '#';
			for (int j = 1; j < W; j++) {
				blue[i][j] = '#';
			}
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (field[i][j] == '#') {
				red[i][j] = '#';
				blue[i][j] = '#';
			}
		}
	}
	for (int i = 0; i < H; i++) {
		cout << red[i] << endl;
	}
	cout << endl;
	for (int i = 0; i < H; i++) {
		cout << blue[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 1536
import sys

input = sys.stdin.readline
# sys.setrecursionlimit(10 ** 8)

N = int(input())


def dfs(s, mx):
    if len(s) == N:
        print(s)
        return
    for c in range(ord("a"), mx + 2):
        t = s
        t += chr(c)
        dfs(t, max(c, mx))


dfs("", ord("a") - 1)


Measured memory_bytes: 4340
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// debug
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif


struct Graph {
  vector<vector<int>> edge;
  Graph(int n = 0) { resize(n); }
  void resize(int n) {
    edge.resize(n, vector<int>());
  }
  void addEdge(int from, int to, bool directed = false) {
    edge[from].push_back(to);
    if (!directed)
      edge[to].push_back(from);
  }
  vector<int>& operator[](int from) { return edge[from]; }
};

template<class T> using p_queue_rev = priority_queue<T, vector<T>, greater<T>>;
void dijkstra(Graph& edge, int start, vector<ll> &cost, vector<ll> &before) {
  cost[start] = 0;
  p_queue_rev<pair<ll, int>> q; q.emplace(0, start);
  while (!q.empty()) {
    ll cur_cost = q.top().first; int from = q.top().second; q.pop();

    if (cost[from] < cur_cost)
      continue;
    for (const auto& to : edge[from]) {
      if (cost[to] > cost[from] + 1) {
        before[to] = from;
        cost[to] = cost[from] + 1;
        q.emplace(cost[to], to);
      }
    }
  }
}

const ll INF = 1e15;
int main() {
  int in(N); int in(M);

  Graph G(N);
  rep(i, M) {
    int in(a); int in(b);
    --a, --b;
    G.addEdge(a, b);
  }

  vector<ll> cost(N, INF);
  vector<ll> before(N, INF);
  dijkstra(G, 0, cost, before);

  cout << "Yes\n";
  rep(i, N-1) {
    cout << before[i+1] + 1 << endl;
  }


  return 0;
}


Measured memory_bytes: 12880
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
//#define num 1000000007
#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define up(a,b) (((a)%(b)==0)?((a)/(b)):((a)/(b))+1)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) (a>b)?(a>c)?a:c:(b>c)?b:c
#define min3(a,b,c) (a<b)?(a<c)?a:c:(b<c)?b:c
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define mp make_pair
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;

ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b, a%b);
}
bool prime[3001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=3000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=3000; i += p) 
                prime[i] = false; 
        } 
    } 
}
ll powe[20];
void power()
{
	powe[0]=1;
	REP(i,1,20)
	{
		powe[i]=(powe[i-1]*10)%num;
        if(powe[i]<0)
        powe[i]+=num;
	}
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
} 
ll facto[200005];
void f()
{
	facto[0]=1;
	REP(i,1,200005)
	{
		facto[i]=mod((i*facto[i-1]),num);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll A[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k;
    cin>>k;
    cout<<A[k-1];
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define INF 2001001001
int N,C;
int D[31][31];
int arr[501][501];
long long wrong[3][31];

int main()
{
  cin>>N>>C;
  for (int i=1;i<=C;i++)
    for (int j=1;j<=C;j++)
      cin>>D[i][j];
  for (int i=1;i<=N;i++)
    for (int j=1;j<=N;j++)
      cin>>arr[i][j];
  if (N==1){
    cout<<0<<endl;
    return 0;
  }
  for (int i=1;i<=N;i++)
    for (int j=1;j<=N;j++)
      for (int c=1;c<=C;c++)
	wrong[(i+j)%3][c]+=D[arr[i][j]][c];
  long long ans=2001001001001;
  for (int i=1;i<=C;i++){
    for (int j=1;j<=C;j++){
      if (i==j)
	continue;
      for (int k=1;k<=C;k++){
	if (k==j || k==i)
	  continue;
	ans=min(ans,wrong[0][i]+wrong[1][j]+wrong[2][k]);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}
	
      


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

int main()
{
	string s, key = "keyence";
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; i + j <= n; j++)
		{
			string t = s;
			t.erase(i, j);
			if (t == key)
			{
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
template<class T>
void compress(vector<T> v, map<T, int>& zip, vector<T>& unzip)
{
	sort(ALL(v));
	v.erase(unique(ALL(v)), v.end());
	unzip.resize(v.size());
	REP(i, v.size())
	{
		zip[v[i]] = i;
		unzip[i] = v[i];
	}
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int d, n, m; 
	while (cin >> d >> n >> m, d)
	{
		vi shop(n), query(m), v;
		FOR(i, 1, n) cin >> shop[i];
		REP(i, m) cin >> query[i];
		sort(ALL(shop));
		v = shop;
		//v.insert(v.end(), ALL(query));
		map<int, int> zip; vi unzip;
		compress(v, zip, unzip);
		ll ans = 0;
		for (auto i : query)
		{
			auto it = zip.lower_bound(i);
			int t;
			if (it == zip.end()) t = (*zip.begin()).second;
			else t = (*it).second;
			ll tmp;
			if (it == zip.begin())
			{
				tmp = min(unzip[0] - i, i - unzip[t] + d);
			}
			else if (it == zip.end())
			{
				tmp = min(unzip[0] + d - i, i - unzip.back());
			}
			else tmp = min(unzip[t] - i, i - unzip[t - 1]);
			ans += tmp;
		}
		cout << ans << endl;
	}
	return 0;
}

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

main(){
  string S;
  cin >> S;
  if(S=="SUN")cout << 7 << endl;
  if(S=="MON")cout << 6 << endl;
  if(S=="TUE")cout << 5 << endl;
  if(S=="WED")cout << 4 << endl;
  if(S=="THU")cout << 3 << endl;
  if(S=="FRI")cout << 2 << endl;
  if(S=="SAT")cout << 1 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n, q; cin >> n >> q;
    string s; cin >> s;
    vpint query(q); vpin(query);
    vint sum(n, 0);
    repi(i, 1, n) {
        sum[i] = sum[i - 1];
        if(s[i - 1] == 'A' && s[i] == 'C') {
            sum[i]++;
        }
    }
    rfor(lr, query) {
        int l = lr.first - 1, r = lr.second - 1;
        print(sum[r] - sum[l]);
    }

    return 0;
}


Measured memory_bytes: 2176
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val h = sc.nextInt()
  val w = sc.nextInt()
  val a = Array(h) { sc.next() }

  var count = 0
  for (ai in a) {
    for (aii in ai) {
      if (aii == '#') count++
    }
  }

  if (count == h + w - 1) {
    println("Possible")
    return
  }
  println("Impossible")
}


Measured memory_bytes: 36388
#include <iostream>

using namespace std;

int main() {

  int n;
  cin >> n;
  int A[110][110];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      A[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    int u, k, v;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v;
      A[u-1][v-1] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j) cout << ' ';
      cout << A[i][j];
    }
    cout << endl;
  }
}



Measured memory_bytes: 3124
/**********************************************

1.
2.テァツつュテァツ板ーテゥツォツ佚ィツシツ?
3.sumita.takaki@gmail.com

last updated: 2013-07-10@12:55

 **********************************************/
#include<iostream>
#include<algorithm>
#include<sstream>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
using namespace std;


int main(void){

        string cipher;
        while(cin >> cipher){

                int i=0;
                while( cipher[i] != 0){

                        if(cipher[i] == 'A'){
                                cipher[i] = 'X';
                        }else if(cipher[i] == 'B'){
                                cipher[i] = 'Y';
                        }else if(cipher[i] == 'C'){
                                cipher[i] = 'Z';
                        }else{
                        cipher[i] = cipher[i] - 3;                        
                        }

                        i++;
                }

                cout << cipher << endl;

        }

        return 0;


}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 2010;
int N,K,Q;
int A[MC];
int s[MC],l[MC],r[MC];

int main(){
	cin >> N >> K >> Q;
	repp(i,0,N) cin >> A[i];
	int ans = 1e9;
	repp(i,0,N){
		vector<int> V,U;
		repp(j,0,N){
			if(A[j] < A[i]){
				sort(U.begin(),U.end());
				repm(k,(int)U.size()-K,-1) V.push_back(U[k]);
				U.clear();
			} else {
				U.push_back(A[j]);
			}
		}
		sort(U.begin(),U.end());
		repm(k,U.size()-K,-1) V.push_back(U[k]);
		if((int)V.size() >= Q){
			sort(V.begin(),V.end());
			ans = min(ans,V[Q-1]-V[0]);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
package main
 
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// override by `ldflags`
var env = "online"

func checkLocal() bool {
	return env == "local"
}

func debugPrint(format string, args ...interface{}) {
	// debug out to stderr
	if checkLocal() {
		fmt.Fprintf(os.Stderr, format, args...)
	}
}

var (
	BufferSize = 100 + 10
)

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	} 
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	a := scanInt(sc)
	fmt.Println(a*a*a)
}


Measured memory_bytes: 1084
N = int(input())
s = input()
c = input()

#データの加工
d = 0 #d=1:横向き, d=0:縦向き
domino = []
pre = s[0]
s += '_'
for x in s[1:]:
    if x == pre:
        d += 1
    else:
        domino.append(d)
        d = 0
    pre = x

#初期値（最初のドミノが横向きか縦向きか）
if domino[0] == 1: ans = 6
else: ans = 3

prex = domino[0]
for x in domino[1:]:
    if prex == 0: ans *= 2
    elif x == 1: ans *= 3
    #elif x == 0: ans *= 1
    prex = x
ans %= 1000000007
print(ans)

Measured memory_bytes: 9216
ABCD = input()

N = len(ABCD)


for i in range(2**(N-1)):
    temp_res = ''
    for j in range(N-1):
        temp_res += ABCD[j]
        if ((i >> j) & 1):
            temp_res += '+'
        else:
            temp_res += '-'
    temp_res += ABCD[-1]

    if eval(temp_res) == 7:
        res = temp_res + '=7'
        break

print(res)

Measured memory_bytes: 3060
// first second push_back unordered return continue break vector visited check flag bool while iterator begin end lower_bound upper_bound temp true false INT_MAX INT_MIN insert erase clear pop push compare INT64_MAX INT64_MIN  reverse replace stringstream string::npos length substr front priority_queue
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
const int mod = 1e9 + 7 ;
const int inf =
 1e9 + 5 ;
 //1e18L + 5;
const int nax = 2e5 + 5;
void min_self(int&a , int b){a=min(a,b);}
void max_self(int&a , int b){a=max(a,b);}
void add_self(int&a , int b){a=(a+b)%mod;}
//#define (x)  get<0>(x) 
//#define (x)  get<1>(x)
//#define (x)  get<2>(x)

vector<int> dx = {1,-1,0,0} , dy = {0,0,-1,1} ;

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

int h , w ; cin >> h>> w ; 
vector<string> arr(h) ;
for(int i = 0 ;i< h ; i++){
	cin >> arr[i] ;
}	

auto is_good = [&](int row1 , int col1){
	return row1 <0 || col1 <0 || row1>=h || col1 >=w || arr[row1][col1] == '#';
};
int ans = 0 ; 
for(int row = 0  ;row < h ; row++){
	for(int col = 0 ; col <w ; col ++){
		vector<vector<int>> dp (h , vector<int> (w ,inf ));
		dp[row][col]  = 0;
		vector<vector<bool>> visited(h , vector<bool>(w , false ));
		queue<pair<int,int>> q ;
		q.push({row ,col});
		while(!q.empty()){
			pair<int ,int> node = q.front() ; 
			q.pop(); 
			if(is_good(node.first , node.second) || visited[node.first][node.second])continue ; 
			visited[node.first][node.second] = true; 
			for(int dir = 0 ; dir < 4 ; dir ++){
				int newrow  = node.first + dx[dir] ; 
				int newcol  = node.second +dy[dir] ;
				if(is_good(newrow , newcol) || visited[newrow][newcol] )continue;
				// cout << row <<col << newrow <<newcol << endl;

				q.push({newrow , newcol});
				min_self(dp[newrow][newcol] , dp[node.first][node.second] + 1); 
				max_self(ans , dp[newrow][newcol]);
			}
		}
		// for(auto i:dp){for(auto j:i)cout<<j<<" " ;cout << endl;}cout << endl<<endl;
	}
}
cout << ans ;

	
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main( )
{
	int r, c;
	int rc[102][102] = { {0} } ;
	
	cin>>r>>c;
	for( int i=0; i<r; i++ ) {
		for( int j=0; j<c; j++ ) {
			cin>>rc[i][j];
			rc[r][j] += rc[i][j];
			rc[i][c] += rc[i][j];		
		}
		rc[r][c] += rc[i][c];
	}
	for( int i=0; i<=r; i++ ) {
		for( int j=0; j<=c; j++ ) {
			if( j < c ) {
				cout<<rc[i][j]<<" ";
			} else {
				cout<<rc[i][j]<<endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 1208