akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
using namespace std;
typedef long long ll;

int main() {
	ll i, j;
	int ans1 = 1;
	int ans2 = 1;
	string S;
	cin >> S;
	int Slen = S.length();
	int prev_num = 1;
	char prev_c = S[0];

	prev_num = 1;
	prev_c = S[0];
	i = 1;
	while (1)
	{
		if (i >= Slen)
			break;
		if (S[i] == prev_c && prev_num==1)
		{
			prev_num = 2;
			i++;
		}
		else
		{
			prev_num = 1;
			prev_c = S[i];
		}
		if (i >= Slen)
			break;
		ans1++;
		i++;
	}

	prev_num = 2;
	i = 2;
	while (1)
	{
		if (i >= Slen)
			break;
		if (S[i] == prev_c && prev_num == 1)
		{
			prev_num = 2;
			i++;
		}
		else
		{
			prev_num = 1;
			prev_c = S[i];
		}
		if (i >= Slen)
			break;
		ans2++;
		i++;
	}
	int ans = max(ans1, ans2);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    string s;
    cin >> s;
    int len = s.length();
    int count = 0;
    for (int i = 0; i < (len + 1) / 2; i++) {
        if ( s[i] != s[len - 1 - i]) {
            count ++;
        }
    }
    cout << count << endl;
    return 0;
}

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

int main(){
 int  N,y;
  cin >> N;
  if(N%1000 == 0){
    cout << 0 << endl;
  }
  else{
  y = 1000 - N%1000;
    cout << y << endl;
  }
}

Measured memory_bytes: 3608
#if 1

#include <bits/stdc++.h>
using namespace std;
int n,m;
int c[100005];
vector <int> v[100005];

void dfs(int x)
{
    if(c[x]) return;
    c[x] = 1;
    for(int i = 0;i < v[x].size();i++)
    {
        dfs(v[x][i]);
    }
}

int main()
{
    int x,y,z;
    scanf("%d %d", &n, &m);
    for(int i = 1;i <= m;i++)
    {
        scanf("%d %d %*d", &x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    int ans = 0;
    for(int i = 1;i <= n;i++)
    {
        if(c[i]) continue;
        dfs(i);
        ans++;
    }
    printf("%d",ans);
}

#endif // 1++


Measured memory_bytes: 9216
#include<cstdio>
#include<queue>
#include<iostream>
#include<cstring>
using namespace std;
int hd[100010],nxt[400010],edg[400010],ver[400010];
int n,m;
int l,r,dd;
int tot,nuuum;
int dist[100010],visnum[100010];
bool ins[100010];
int mmnb;
inline int rd()
{
    char ch;
    int res;
    while((ch=getchar())>'9'||ch<'0');
    res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9') res=(res<<1)+(res<<3)+ch-'0';
    return res;
}
inline void add_edge(int x,int y,int z)
{
    ver[++tot]=y,edg[tot]=z,nxt[tot]=hd[x],hd[x]=tot;
}
int main()
{
    memset(dist,0x3f,sizeof(dist));
    n=rd(),m=rd();
    if(m==0) {printf("Yes");return 0;}
    for(int i=1;i<=m;i++)
    {
        l=rd(),r=rd(),dd=rd();
        add_edge(r,l,dd);
        add_edge(l,r,-dd);
    }
    for(int ttt=1;ttt<=n;ttt++)
    {
        if(dist[ttt]==1061109567)
        {
            ++nuuum;
            int s=ttt;
            queue<int> que;
    int summ=1;
    que.push(s);
    visnum[s]=nuuum;
    while(!que.empty())
    {
        int ttemp=que.front();
        que.pop();
        for(int m=hd[ttemp];m;m=nxt[m])
        {
            int y=ver[m];
            if(visnum[y]==0) {visnum[y]=nuuum,++summ;que.push(y);}
        }
    }
    queue<int> q;
    q.push(s);
    dist[s]=0;
    while(!q.empty())
    {
        int y=q.front();
        q.pop();
        ins[y]=0;
        for(int i=hd[y];i;i=nxt[i])
        {
            int z=ver[i];
            if(visnum[z]==nuuum)
            {
                if(dist[z]>dist[y]+edg[i])
                {
                	if(dist[z]==1061109567) {dist[z]=dist[y]+edg[i];q.push(z);}
                }
                else
                if(dist[z]!=dist[y]+edg[i]) {printf("No");return 0;}
            }
        }
    }
        }
    }
    printf("Yes");
}

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

int main(){
  string s;
  cin >> s;
  map<char,int> mp;
  for(auto e : s) mp[e]++;
  if(mp.size() == 2 && mp[s[0]] == 2) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
function Main(input) {
  input = input.trim().split("\n");
  const NK = input[0].split(" ");
  var N = parseInt(NK[0], 10);
  var K = BigInt(NK[1]);
  var Aarr = input[1].split(" ").map((n) => parseInt(n, 10));
  var now = 1;
  var d = 0;
  if (N > K) {
    for (var i = 0; i < K; i++) {
      now = Aarr[now - 1];
    }
    console.log(now);
    return;
  }

  t = new Array(N).fill(-1);
  t[0] = 0;
  for (var i = 1; i <= N; i++) {
    now = Aarr[now - 1];
    if (t[now - 1] != -1) {
      d = i - t[now - 1]; //ループ幅
      var sa = i - d + 1; //あまりの部分
      K -= BigInt(sa);
      if ((K %= BigInt(d)) == 0) {
        K = BigInt(d);
      } else {
        K %= BigInt(d);
      }
      K += BigInt(sa);
      break;
    }
    t[now - 1] = i;
  }

  now = 1;
  for (var i = 0; i < BigInt(K); i++) {
    now = Aarr[now - 1];
  }
  console.log(now);
  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 44692
S = gets.chomp
M = 1e9.to_i + 7

def mpow(x, n)
  ret = 1
  while n > 0
    if n.even?
      x = x * x % M
      n >>= 1
    else
      ret = ret * x % M
      n -= 1
    end
  end
  ret
end

N = S.length
as, cs, qs = [], [], []
as[0], cs[0], qs[0] = 0, 0, 0
(1 .. N).each do |i|
  as[i], cs[i], qs[i] = as[i - 1], cs[i - 1], qs[i - 1]
  case S[i - 1]
  when 'A'
    as[i] += 1
  when 'C'
    cs[i] += 1
  when '?'
    qs[i] += 1
  end
end
res = 0
(2 ... N).each do |i|
  if S[i - 1] == 'B' || S[i - 1] == '?'
    a, q = as[i - 1], qs[i - 1]
    la = a * mpow(3, q) + q * mpow(3, q - 1)
    c, q = cs[N] - cs[i], qs[N] - qs[i]
    rc = c * mpow(3, q) + q * mpow(3, q - 1)
    res = (res + la*rc) % M
  end
end
puts res

Measured memory_bytes: 4516
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
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; }
using namespace std;

int N,C;
int imos[33][100100];

signed main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N>>C;
    rep(i,N){
        int s,t,c; cin>>s>>t>>c;
        imos[c][s]++; imos[c][t+1]--;
    }
    for(int i=1; i<100100; i++)rep(j,33){
        imos[j][i]+=imos[j][i-1];
    }
    int ans=0;
    rep(i,100100){
        int cnt=0;
        rep(j,33)if(imos[j][i])cnt++;
        chmax(ans,cnt);
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define ll long long
ll input(){
	ll x=0,f=0;char ch=getchar();
	while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f? -x:x;
}

ll t;
ll Ans=0;
ll t3[50],sum[50];
int main(){
	t=input()+1;
	t3[0]=1,sum[0]=1;
	for(int i=1;i<40;i++){
		t3[i]=t3[i-1]*3;
		sum[i]=t3[i]+sum[i-1];
	}
	ll x=1,tt=0;
	while(x<t){
		Ans++;
		if(x+sum[tt+1]<=t){
			tt++;
			x+=t3[tt];
		}else if(x+sum[tt]<=t){
			x+=t3[tt];
		}else{
			tt--;
			x+=t3[tt];
		}
	}
	printf("%lld\n",Ans);
}


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

int main()
{
    long long int a,b,x;
    cin >> a >> b >> x;
    long long int count = 0;

    if(a % x == 0)
        cout << b / x - a / x + 1;
    else
        cout << b /x - a / x;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forn(i,n) for(int i=1;i<=n;i++)
#define forRn(i,n) for(int i=n;i>=1;i--)
#define forz(i,n) for(int i=0;i<n;i++)
#define forRz(i,n) for(int i=n-1;i>=0;i--)
#define forab(i,a,b) for(int i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define magic ios::sync_with_stdio(false); cin.tie(nullptr)
using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pdd = pair<double, double>;
using vi = vector<int>;

const int KyaRyunHa = 7;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int dx[] = { -1, 0, 1, 0, -1, 1, 1, -1 };
const int dy[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int test,N,M,K;

int arr[300005];

int main(void)
{
    magic;
    int sum=0;
    cin>>N;
    forz(i,N){ cin>>arr[i]; sum+=arr[i]; }
    sort(arr,arr+N);
    sum-=arr[N-1];
    cout<<((arr[N-1]<sum)?"Yes":"No");
}


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

int main() {
    int n;
    cin>>n;
    int cnt[4] = {0};
    for(int i=0; i<n; i++) {
        int temp;
        cin>>temp;
        cnt[temp]++;
    }
    double dp[n+1][n+1][n+1];
    dp[0][0][0] = 0;
    for(int k=0; k <= cnt[3]; k++) {
        for(int j=0; j+k <= cnt[2]+cnt[3]; j++) {
            for(int i=0; i+j+k <= n; i++) {
                if(i+j+k > 0) dp[i][j][k] = (double) n / (i + j + k);
                if(i) dp[i][j][k] += dp[i-1][j][k] * i / (i + j + k);
                if(j) dp[i][j][k] += dp[i+1][j-1][k] * j / (i + j + k);
                if(k) dp[i][j][k] += dp[i][j+1][k-1] * k / (i + j + k);
            }
        }
    }
    cout<< setprecision(16) << dp[cnt[1]][cnt[2]][cnt[3]] << endl;
    return 0;
}

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

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

	if (x == 1 || x == 2 * N - 1) cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		if (N == 2) {
			cout << 1 << endl;
			cout << 2 << endl;
			cout << 3 << endl;
			return 0;
		}
		int cnt = 0;
		if (x <= N) {
			cnt = 2;
			for (int i = 0; i < N - 3; i++) {
				if (cnt == x) cnt++;
				cout << cnt << endl;
				cnt++;
			}
			cout << 2 * N - 2 << endl;
			cout << 1 << endl;
			cout << x << endl;
			cout << 2 * N - 1 << endl;
			for (int i = 0; i < N - 2; i++) {
				if (cnt == x) cnt++;
				cout << cnt << endl;
				cnt++;
			}
		}else{
			cnt = 3;
			for (int i=0; i < N-3; i++) {
				if (cnt == x) cnt++;			
				cout << cnt << endl;
				cnt++;
			}
			cout << 2 << endl;
			cout << 2 * N - 1 << endl;
			cout << x << endl;
			cout << 1 << endl;
			for (int i = 0; i < N - 2; i++) {
				if (cnt == x) cnt++;
				cout << cnt << endl;
				cnt++;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int N, Y;
    cin >> N >> Y;
    int diff = Y-1000*N;
    for(int j=0; j<=N; j++){
        if((diff - 4000*j) % 9000 == 0){
            int k = (diff - 4000*j) / 9000;
            int i = N - j - k;
            int nowdiff = diff - 4000*j - 9000*k;
            if(nowdiff == 0 && i >= 0 && k >= 0){
                cout << k << " " << j << " " << i << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
w_dict = {}
max_c = 1
for i in range(n):
  w = input()
  if w in w_dict.keys():
    count = w_dict[w] + 1
    w_dict[w] = count
    if count > max_c:
      max_c = count
  else:
    w_dict[w] = 1

print_list = []
for k,v in w_dict.items():
  if v == max_c:
    print_list.append(k)
    
for p in sorted(print_list):
  print(p)

Measured memory_bytes: 32988
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    int N;
    string S;
    cin >> N >> S;
    set<string> oneCharSet, twoCharsSet, threeCharsSet;
    for (int i = 0; i < N; ++i)
    {
        const char ch = S[i];
        // ２文字セットにchを足して３文字にする
        for (const auto twoChars : twoCharsSet)
        {
            threeCharsSet.insert(twoChars + ch);
        }
        // １文字セットにchを足して２文字にする
        for (const auto oneChar : oneCharSet)
        {
            twoCharsSet.insert(oneChar + ch);
        }
        // １文字セットにchを加える
        oneCharSet.insert({ ch });
    }
    cout << threeCharsSet.size() << endl;
}


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

/*struct pair {
	int x;
	int y;
};*/


int main() {
	std::string s;
	std::cin >> s;
	bool flug = true;
	for (int i = 0; i < (s.size() - 1) / 2; i++) {
		if (s[i] != s[s.size() - 1 - i]||s[i]!=s[(s.size()-3)/2-i]) {
			//std::cout << i << " " << s[i] <<" "<< s[s.size() - 1 - i] << " " << s[(s.size() - 3) / 2-i];
			flug = false;
			break;
		}
	}
	if (flug) std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A0 = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

A = [[1,a] for a in A0] 
ABC = A + BC
ABC.sort(key=lambda x:x[1], reverse=True)

summation = 0
p = 0
n = 0

while n<N:
    summation += ABC[p][1] * (min(ABC[p][0], N-n))
    n += min(ABC[p][0], N-n)
    p += 1

print(summation)

Measured memory_bytes: 43968
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000000000000
#define ll long long int
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}

int main(){
	//mahakal();fast;
	ll a , b, n ;
	cin>>a>>b>>n ;
	if(a<b)swap(a,b);
	ll ans = ceil((long double)n/a);
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
  int n,i,t,ans=0;
  vector<int> sb;
  cin >> n;
  sb.push_back(0);
  t=0;
  while (1){
    int k=sb[t++];
    if (k*10+3 > n) break;
    if (k*10+3 <= n) sb.push_back(k*10+3);
    if (k*10+5 <= n) sb.push_back(k*10+5);
    if (k*10+7 <= n) sb.push_back(k*10+7);
  }
  
  for (i=1;i<sb.size();i++){
    int a=sb[i],j,l[3]={};
    for (j=0;a>0;j++){
      l[(a%10-3)/2]++;
      a/=10;
    }
    if (l[0]*l[1]*l[2]==0) continue;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
import math,itertools,fractions,heapq,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  q=[]

  field=[S() for _ in range(h)]
  counter=[[inf]*w for _ in range(h)]

  sharp_cnt=0
  for x in field:
    sharp_cnt+=x.count('#')

  q.append((0,0,1))

  while len(q)>0:
    y,x,cnt=q.pop()
    if counter[y][x]<cnt:
      continue
    counter[y][x]=cnt

    for dy,dx in dd:
      ny=y+dy
      nx=x+dx

      if 0<=ny and 0<=nx and ny<h and nx<w:
        if field[ny][nx]!='#':

          if counter[ny][nx]>cnt+1:
            q.append((ny,nx,cnt+1))

  step_cnt=counter[h-1][w-1]

  if step_cnt==inf:
    return -1

  return h*w-sharp_cnt-step_cnt

# main()
print(main())


Measured memory_bytes: 68440
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;

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

    int a, b;
    cin >> a >> b;

    if( a <= 0 && 0 <= b ){
      cout << "Zero\n";
    } else if( a < 0 && b < 0 && abs(a,b+1)%2 == 1) {
      cout << "Negative\n";
    } else {
      cout << "Positive\n";
    }
    
    return 0;
}


Measured memory_bytes: 256
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,nd,cnt
    integer(int32), allocatable:: a(:),da(:)

    read*, n
    allocate(a(n),da(n-1))
    read*, a(:)

    do i=1,n-1
        da(i) = a(i+1)-a(i)
    end do
    deallocate(a)
    cnt=1
    nd = da(1)
    do i=2,size(da)
        if (da(i)==0 .or. nd==0 .or. (da(i) >0 .eqv. nd>0)) then
            if (nd==0) nd=da(i)
        else
            cnt=cnt+1
            if (i+1 <= size(da)) nd=da(i+1)
        end if
    end do
    print'(i0)', cnt
end program name

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	string S;
	cin >> S;

	if (S.size() == 3) {
		swap(S[0], S[2]);
	}
	co(S);

	Would you please return 0;
}

Measured memory_bytes: 256
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[K] - answers if Taro wins with K stones

    OPT[a[i]] = True 1 <= k <= N

    5
    2 3
    
    t t j j j
    t t t j j

    OPT(K) - True, if Taro loses the game with K stones
    OPT(K) = all(not OPT(K-a[i])) 1 <= i <= N
    OPT(0) = True
    """
    N, K = read_ints()
    a = read_ints()
    OPT = [False]*(K+1)
    OPT[0] = True
    for k in range(1, K+1):
        OPT[k] = all(not OPT[k-a[i]] for i in range(N) if k-a[i] >= 0)
    if OPT[K]:
        return 'Second'
    return 'First'


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 46300
import math

x = int(input())


def is_prime(n):
    if n < 2:
        return False
    if n % 2 == 0 and n > 2:
        return False
    return all(n % i for i in range(3, int(math.sqrt(n)) + 1, 2))


for n in range(100005):
    if n >= x and is_prime(n):
        print(n)
        break


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

int main(){
    int a,b;
    cin >> a >> b;
    if (a > b){
        cout << "a > b" << endl;
    } else if (a < b) {
        cout << "a < b" << endl;
    } else if(a == b){
        cout << "a == b" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1145141
int main(){
    ll n,a,b,c;
    cin>>n>>a>>b>>c;
    vector<int>L(n);
    for(int i=0;i<n;i++)cin>>L[i];
    ll tuple_search=pow(4,n);
    vector<int>make_a,make_b,make_c,search_array;
    ll ans=INF,search_enumeration,cnt,comp_ans;
    for(int i=1;i<tuple_search;i++){
        //初期化
        search_array.clear();
        make_a.clear();
        make_b.clear();
        make_c.clear();
        search_enumeration=i;
        comp_ans=0;
        cnt=0;
        //4進数全探索
        while(search_enumeration!=0){
            search_array.insert(search_array.begin(),search_enumeration%4);
            search_enumeration/=4;
            cnt++;
        }
        while(cnt<n){
            search_array.insert(search_array.begin(),0);
            cnt++;
        }
        for(int j=0;j<n;j++){
            if(search_array[j]==1){//A
                make_a.push_back(L[j]);
            }
            if(search_array[j]==2){//B
                make_b.push_back(L[j]);
            }
            if(search_array[j]==3){//C
                make_c.push_back(L[j]);
            }
        }
        if(make_a.empty()||make_b.empty()||make_c.empty()){
            //処理は無し！wwwwww
        }
        else{
            ll hoge=0;
            for(auto x:make_a){
                hoge+=x;
                comp_ans+=10;
            }
            comp_ans+=abs(a-hoge);
            comp_ans-=10;
            hoge=0;
            for(auto x:make_b){
                hoge+=x;
                comp_ans+=10;
            }
            comp_ans+=abs(b-hoge);
            comp_ans-=10;
            hoge=0;
            for(auto x:make_c){
                hoge+=x;
                comp_ans+=10;
            }
            comp_ans+=abs(c-hoge);
            comp_ans-=10;
            
            ans=min(ans,comp_ans);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

struct route_t {
  uint32_t dist;
  uint32_t p;
  const bool operator<(const route_t &route) { return p > route.p; }
};

int32_t main() {
  while (true) {
    uint32_t N, M;
    cin >> N >> M;

    if (N == 0 && M == 0)
      break;

    vector<route_t> routes;
    for (uint32_t i = 0; i < N; i++) {
      uint32_t D, P;
      cin >> D >> P;
      routes.push_back(route_t({D, P}));
    }
    sort(routes.begin(), routes.end());

    uint32_t expect = 0;
    for (uint32_t i = 0; i < routes.size(); i++) {
      route_t route = routes[i];
      if (M > 0) {
        uint32_t used = min(route.dist, M);
        M -= used;
        route.dist -= used;
      }
      expect += route.dist * route.p;
    }
    cout << expect << endl;
  }

  return 0;
}

Measured memory_bytes: 3284
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

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

const long long MOD = 1e9+7;

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; }

int main() {
    int h, a;
    cin >> h >> a;
    int ans = (h + a - 1) / a; 
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>

using namespace std;
int main() {
	
	
	int a, b, d, r;
	double f;
	
	cin>> a >> b;
		
	d = a / b;
	r = a % b; 
	f = (double)a / b;
		cout<<fixed<<endl;
		cout<< d << " " << r << " " << f <<endl;
}


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

int main() {
	ll q, h, s, d; cin >> q >> h >> s >> d;
	ll n; cin >> n;
	//2リットルあたりで最も小さいもの
	ll Min = min({ q * 8,h * 4,s * 2,d });
	//1
	ll Min2 = min({ q * 4,h * 2,s });
	cout << (n / 2)*Min + (n % 2)*Min2 << endl;
}

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

using namespace std;

int main(){

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

    int h[n];
    for(int i=0;i<n;i++)cin >> h[i];

    long long dp[n];
    dp[0] = 0;

    for(int i=1;i<n;i++){
        dp[i] = 1000000000;
        for(int j=max(0,i-k);j<i;j++){
            dp[i] = min(dp[i], dp[j]+abs(h[i]-h[j]));
        }
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		String KX = scanner.nextLine();

		int K = Integer.parseInt(KX.split(" ")[0]);

		int X = Integer.parseInt(KX.split(" ")[1]);

		//ArrayList<Integer> baseNumArray = new ArrayList<Integer>();

		String output = "";

		for(int i = ( X - K) + 1;i < (X + K);i++) {
			output=output + i + " ";
		}

		String output2 =  output.substring(0,output.length()-1);

		System.out.println(output2);

	}

}

Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
    char input[5];
    char rvs[5];
    int i;
    scanf("%s", &input);
    for (i = 0; i < 3; i++){
        rvs[2 - i] = input[i];
    }
    rvs[3] = '\0';
    if (strcmp(input, rvs)){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}

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

int main()
{
ll n , m ;
cin >> n >> m ;
string s ;
cin >> s ;
vector<vector<ll>> g(n);
vector<vector<ll>> num(n,vector<ll>(2));
rep(i, m)
{
  ll a, b;
  cin >> a >> b;
  g[a - 1].push_back(b - 1);
  g[b - 1].push_back(a - 1); //無向辺
  if(s[b-1]=='A')num[a-1][0]++;
  if(s[b-1]=='B')num[a-1][1]++;
  if(s[a-1]=='A')num[b-1][0]++;
  if(s[a-1]=='B')num[b-1][1]++;
}
vector<bool> liv(n,1);
queue<ll> q;
rep(i,n)if(num[i][0]==0||num[i][1]==0){q.push(i);liv[i]=0;}
while(!q.empty()){
  ll p=q.front();
  q.pop();
  ll a=((s[p]=='A') ? 0 : 1 );
  for(auto r:g[p]){
    if(liv[r]==0)continue;
    num[r][a]--;
    if(num[r][a]==0){q.push(r);liv[r]=0;}
  }
}
bool ok=0;
rep(i,n)if(num[i][0]>0&&num[i][1]>0)ok=1;
cout << (ok ? "Yes" : "No" ) << endl;
return 0;
}

Measured memory_bytes: 22916
S = input()
ans = "Yes"

for i in range(len(S)):
	if i%2 == 0:
		if S[i] == 'L':
			ans = "No"
			break
	
	if i%2 == 1:
		if S[i] == 'R':
			ans = "No"
			break
	
print(ans)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
  int n,m;
  long long a[100000];
  cin >> n >> m;
  for(int i = 0 ; i < 100000; i++) a[i] = 0;
  for(int i = 0 ; i < m; i++){
    int temp ;
    cin >> temp;
    a[temp-1] = -1;
  }

  for(int i = 0; i < n;i++){
    if(a[i] != -1){
      if(i == 0) a[i] = 1;
      else if(i == 1) {
        if(a[0] != -1) a[i] = 2;
        else a[i] = 1;
      }
      else{
        if(a[i-2] != -1) a[i] += a[i-2] % 1000000007;
        a[i] = a[i] % 1000000007;
        if(a[i-1] != -1) a[i] += a[i-1] % 1000000007;
        a[i] = a[i] % 1000000007;
      }
    }
  }
  cout << a[n-1];
  return 0;
}


Measured memory_bytes: 1024
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower, islower
#include <math.h>

#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
//using ll = long long; using ld = long double;
//using P = pair<int, int>;
long long n, m, x, y, z, A, B, C, D;
const long long template_arry_size = 1000625;
long long a[template_arry_size];
long long b[template_arry_size];
long long c[template_arry_size];
string s, t;
long long ans = 0;
map<long long, long long> memo;

long long dfs(long long N) {
    if (N == 0) return 0;
    if (N == 1) return D;
    if (memo.count(N)) return memo[N];
    long long l2 = (N / 2)  * 2;
    long long r2 = ((N + 1) / 2) * 2;
    long long l3 = (N / 3)  * 3;
    long long r3 = ((N + 2) / 3) * 3;
    long long l5 = (N / 5)  * 5;
    long long r5 = ((N + 4) / 5) * 5;

    long long res = 1e18;
    if (N < res / D) res = N * D;
    res = min(res, llabs(l2 - N) * D + A + dfs(l2 / 2));
    res = min(res, llabs(r2 - N) * D + A + dfs(r2 / 2));
    
    res = min(res, llabs(l3 - N) * D + B + dfs(l3 / 3));
    res = min(res, llabs(r3 - N) * D + B + dfs(r3 / 3));
    
    res = min(res, llabs(l5 - N) * D + C + dfs(l5 / 5));
    res = min(res, llabs(r5 - N) * D + C + dfs(r5 / 5));

    memo[N] = res;
    
    return res;
}

void solve(int tc = 0) {
    cin >> n;
    cin >> A >> B >> C >> D;
    
    cout << dfs(n) << endl;
}

int main(){
    int T;
    cin >> T;
    rep(i,T) {
        memo.clear();
        solve();
    }
    
}

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

int main()
{
    long double a;
    long double b;
    cin >> a >> b;
    ll ans = 0;
    ans = floor(a * b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3732
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPL(i,f,n) for(int i=f, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

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

	int N;
	cin >> N;
	ll ans = 1;

	for (int i = 1; i <= N; i++) ans = ans * i % 1000000007;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long

using namespace std;

int main() {
      cin.sync_with_stdio(0);

      double a, b, c, d;
      cin >> a >> b >> c >> d;

      double pi = acos(-1);
      double a1 = ((2 * pi) / 12 * (c + d / 60));
      double a2 = ((2 * pi) / 60 * d);
      double v = abs(a1 - a2);
      v = min(v, 2 * pi - v);

      cout << fixed << setprecision(10) << sqrt(a * a + b * b - 2 * a * b * cos(v));

      return 0;
}

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

using namespace std;

int main(){
 long n,m; 
  cin >> n >> m;
  
  long w[8][n];
  long a,b,c;
  for(int i=0;i<n;i++){
  cin >> a >> b >> c;
    w[0][i]=a+b+c;
    w[1][i]=0-a+b+c;
    w[2][i]=a-b+c;
    w[3][i]=a+b-c;
    w[4][i]=0-a-b+c;
    w[5][i]=0-a+b-c;
    w[6][i]=a-b-c;
    w[7][i]=0-a-b-c;
  }
  
  for(int i=0;i<8;i++) sort(w[i],w[i]+n,greater<long>());
  
  long res=0;
  for(int j=0;j<8;j++){
    long comp=0;
  for(int i=0;i<m;i++) comp+=w[j][i];
    res=max(res,comp);
  }
  cout << res << endl;
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数
using namespace std;

signed main() {
  int a, b;
  cin >> a >> b;
  vector<string> st(a);
  for (int i = 0; i < a; i++) {
    cin >> st[i];
  }
  
  sort(st.begin(), st.end());
  for (int i = 0; i < a; i++) {
    cout << st[i];
  }
  cout << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cstdio>
#include <cmath>

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)

using ll = long long;
using namespace std;

constexpr int INF = 2147483647; // 2 * 1e9
constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w, n;
	int c[100][100];
	cin >> h >> w >> n;
	vector<int>a;
	REP(i, n){
		int t;
		cin >> t;
		a.push_back(t);
	}
	int now = 0;
	REP(i, h){
		if(i % 2 == 0){
			REP(j, w){
				if(a[now] != 0){
					c[i][j] = now + 1;
					--a[now];
				}
				else{++now;
					c[i][j] = 1 + now;
					--a[now];
				}
			}
		}
		else{
			for(int j = w - 1; j >= 0; --j){
				if(a[now] != 0){
					c[i][j] = now + 1;
					--a[now];
				}
				else{
					++now;
					c[i][j] = now + 1;
					--a[now];
				}
			}
		}
	}
	REP(i, h){
		REP(j, w){
			if(j == 0) cout << c[i][j];
			else cout << " " << c[i][j];
		}
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 512
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_071_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(14).
    01 x      PIC 9(4).
    01 a      PIC 9(4).
    01 b      PIC 9(4).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO x a b.

    SUBTRACT x FROM a.
    SUBTRACT x FROM b.

    IF a < b THEN
        DISPLAY 'A'
    ELSE
        DISPLAY 'B'
    END-IF.

    STOP RUN.


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof x)
#define copy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

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

const int MAXN = 100005;

int n, a[MAXN], c;

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = read();
	for (int i = 1; i <= n; i ++) a[i] = read();
	sort(a + 1, a + n + 1);
	if (a[n] - a[1] > 1) return puts("No"), 0;
	if (a[1] == a[n])
	{
		if (a[1] == n - 1) return puts("Yes"), 0;
		if ((a[1] << 1) <= n) return puts("Yes"), 0;
		return puts("No"), 0;
	}
	for (int i = 1; i <= n; i ++) if (a[i] == a[1]) c ++;
	if (c + (a[n] - c << 1) <= n && c < a[n]) return puts("Yes"), 0;
	return puts("No"), 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using Graph_c = vector<vector<char>>;
using ll=long long;
// 幅優先探索
struct Z{
  ll y;
  ll x;
  ll depth;
};

ll H,W,y,x,depth;
vector<ll> y_vec={1,0,-1,0};
vector<ll> x_vec={0,1,0,-1};
Graph_c A,B;
queue<Z> q;

ll bfs(){
  while(!q.empty()){
    Z now=q.front(); q.pop();
    y=now.y, x=now.x, depth=now.depth;    
//    cout<<"x:"<<x<<" y:"<<y<<" A:"<<A[y][x]<<endl;
    for(ll i=0; i<4; i++){
      Z next={y+y_vec[i], x+x_vec[i], depth+1};
      if(A[next.y][next.x]=='.'){
        q.push(next);
        A[next.y][next.x]='#';
      }
    }
  }
  return depth;
}

int main(){
  cin>>H>>W;
  A.assign(H+2, vector<char>(W+2, '!'));
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      char a; cin>>a;
      A[i][j]=a;
      if(a=='#') q.push({i,j,0});
    }
  }
  B=A;
  ll ans=0;
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      if(A[i][j]=='.') continue;
      ans=max(ans,bfs());
//      cout<<"i:"<<i<<" j:"<<j<<"ans"<<ans<<endl;
    }
  }
  cout<<ans<<endl;
}


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

void setnum(char cc[]){
	int j,len=strlen(cc);
	for(j=len;j>-1;j--){
		cc[80-len+j]=cc[j];
	}
	memset(cc,'0', 80-len);
}

int main(void) {
	
	char a[82],b[82];
	int ca,i,n;
	scanf("%d",&n);
	for(1;n>0;n--){
		scanf("%82s",a);scanf("%82s",b);
		if(strlen(a)>80 || strlen(b)>80 ){printf("overflow\n");continue;}
		setnum(a);setnum(b);
		ca=0;
		
		for(i=79;i>-1;i--){
			ca+=a[i]+b[i]-'0'*2;
			a[i]=ca%10+'0';
			if(ca>9)ca=1; else ca=0;
		}

		if(ca==1) printf("overflow\n");

		else {
			for(i=0;i<80;i++){
				if(ca!=0 || a[i]>'0' || i==79){
				ca=1;
				printf("%c",a[i]);
				}
			}
			printf("\n");
		}
		
	}

	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);ios::sync_with_stdio(false);



signed main(){
    ll n,ans=-INF;cin>>n;
    vector<ll> v(3*n),l(n+1,0),r(n+1,0);
    priority_queue<ll,vector<ll>, greater<ll>> ql;
    priority_queue<ll> qr;
    rep(i,3*n){
        cin>>v[i];
        if(i<n){
            ql.push(v[i]);
            l[0]+=v[i];
        }else if(2*n<=i){
            qr.push(v[i]);
            r[n]+=v[i];
        }
    }

    for(int i=n;i < 2*n;i++)
    {
        l[i-n+1]=l[i-n];
        if(ql.top()<v[i]){
            l[i-n+1]+=v[i]-ql.top();
            ql.pop();
            ql.push(v[i]);
        }
    }

    for(int i=2*n-1;n<=i;i--)
    {
        r[i-n]=r[i-n+1];
        if(qr.top()>v[i]){
            r[i-n]+=v[i]-qr.top();
            qr.pop();
            qr.push(v[i]);
        }
    }

    rep(i,n+1){
        ans=max(ans,l[i]-r[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6516
#include <iostream>
#include <unordered_map>

using namespace std;

struct Node {
  Node* prev;
  int cnt;
};

int main() {
  int N;
  cin >> N;
  unordered_map<int, Node> m;
  int P;
  int res = 1;
  for (int n = 0; n < N; ++n) {
    cin >> P;
    if (m.count(P-1)) {
      Node prev = m[P-1];
      int cnt = prev.cnt+1;
      if (cnt > res) res = cnt;
      m[P] = Node{&prev, cnt};
    } else {
      m[P] = Node{nullptr, 1};
    }
  }
  cout << N - res << endl;

  return 0;
}

Measured memory_bytes: 11260
import java.util.*;

public class Main {
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int i = 0;
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
        
        if(x-r<0||x+r>W||y-r<0||y+r>H){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
        
    }
    
}



Measured memory_bytes: 26344
import java.io.*;
import java.lang.*;
import java.util.*;

public class Main
{
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String in = sc.nextLine();
        if (in.toUpperCase().equals(in)) {
            System.out.println("A");
        }
        else {
            System.out.println("a");
        }
    }
}


Measured memory_bytes: 35740
S = input()
s = ''
ar = ['dream', 'dreamer', 'erase', 'eraser']
for i in range(1, len(S)+1):
    s = S[-i] + s
    if s in ar:
        s = ''
    if len(s) > 10:
        break

if len(s) == 0:
    print('YES')
else:
    print('NO')

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

void solve() {

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    vector<int> a(5);
    int res = 0;
    for (int i = 0; i < 5; ++i) {
        cin >> a[i];
        if (a[i] == 0) {
            res = i+1;
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3652
from collections import*
n,m,*w,s,t=map(int,open(0).read().split())
e=[[]for _ in[0]*-~n]
for u,v in zip(w[::2],w[1::2]):e[u]+=v,
f=[-3]*n*4
f[s*3]=0
q=deque([(s,0)])
while q:
  v,m=q.popleft()
  u=-~m%3
  for w in e[v]:
    if f[w*3+u]<0:
      f[w*3+u]=f[v*3+m]+1
      q+=(w,u),
print(f[t*3]//3)

Measured memory_bytes: 32436
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int main() {
    int N,K;
    cin >> N >> K;
    int h[N];
    for (int i = 0;i<N;i++){
        cin >> h[i];
    }
    sort(h,h+N);
    int temin = h[K-1] - h[0];
    for (int i = 0;i < N -K + 1;i++){
        if((h[K-1+i] - h[i]) < temin){
            temin = h[K-1+i] - h[i];
        }
    }
    cout << temin << endl;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int k,n;cin>>k>>n;
  vector<int> a(n);
  int i;
  rep(i,n)cin>>a[i];
  int ans=k;
  rep(i,n)
  {
    //i->i+n-1
    if(a[(i+n-1)%n]>a[i])
    {
      ans=min(ans,a[(i+n-1)%n]-a[i]);
      //ans=min(ans,a[i]+k-a[(i+n-1)%n]);
    }
    else
    {
      ans=min(ans,a[(i+n-1)%n]+k-a[i]);
      //ans=min(ans,a[(i+n-1)%n]-a[i]);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

N = int(input())
l = make_divisors(N)
g = 0
for c in l:
    rc = N//c - 1
    if (rc != 0):
        if (N % rc) == (N//rc):
            g+=rc
print(g)

Measured memory_bytes: 3264
#include<bits/stdc++.h>
using namespace std;
int dp[100005],a[100005];
int main()
{
    int i,k,n,m,mx,x,l;
    cin>>n>>k;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(i=2;i<n;i++)
    {
        mx=INT_MAX;
        l=1;
        while((i-l)>=0)
        {
            x=abs(a[i]-a[i-l])+dp[i-l];
            mx=min(mx,x);
            if(l==k)
            {
                break;
            }
            l++;
        }
        dp[i]=mx;
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"

using namespace std;
typedef long long ll ;
typedef pair <ll,ll>  pii;

vector <int> v[2001];
map <int,int> mp;

void bfs(int nod) {
    bitset <2001> b;
    queue <pii> q;            b[nod] = 1;

    q.push({nod,0});
    while(!q.empty()) {

        if(q.size()) {
            int nc = q.front().first;
            int d = q.front().second;
            mp[d]++;
            q.pop();
            for(auto x : v[nc]) {
                if(b[x] == 0) {
                    b[x] = 1;
                    q.push({x,d + 1});
                }
            }
        }
    }
}

int  main() {
    int n,i,x,y;
    cin >> n >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
    for(i = 1; i <= n - 1; i++) {
        v[i + 1].push_back(i);
        v[i].push_back(i + 1);
    }
    for(i = 1; i <= n; i++) {
        bfs(i);
    }
    for(i = 1; i <= n - 1; i++) {
        cout << mp[i] / 2 << "\n";
    }
    return 0;
}


Measured memory_bytes: 512
import java.util.*;

import java.io.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        int[] dp = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        dp[0] = 0;
        dp[1] = Math.abs(h[1] - h[0]);
        for (int i = 2; i < n; i++) {
            dp[i] = Math.min(dp[i - 2] + Math.abs(h[i] - h[i - 2]), dp[i - 1] + Math.abs(h[i] - h[i - 1]));
        }
        System.out.println(dp[n-1]);
    }
}


Measured memory_bytes: 60540
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

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


int main(void)
{
	int k, x;
	while(scanf("%d%d", &k, &x)==2)
	{
		int cand_min=x-k+1;
		int cand_max=x+k-1;

		for(int i=cand_min;i<cand_max;i++)
		{
			printf("%d ", i);
		}
		printf("%d\n", cand_max);
	}
	return 0;
}


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

using namespace std;

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


Measured memory_bytes: 256
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()
d = []
for i in range(N):
    if T[i] == "r":
        if i < K or d[i-K] != "p":
            d.append("p")
        else:
            d.append("a")
    elif T[i] == "s":
        if i < K or d[i-K] != "r":
            d.append("r")
        else:
            d.append("a")
    else:
        if i < K or d[i-K] != "s":
            d.append("s")
        else:
            d.append("a")
ans = d.count("r") * R + d.count("s") * S + d.count("p") * P
print(ans)

Measured memory_bytes: 10016
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
#define MAX 10000000000
#define rep(i,n) for(int i = 0; i < n;i++)
ll v, n, e, u, k, ans = 0,sum;
bool c[1000001];
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
int main(void) {
	string s, t;cin >> s;t = s;
	reverse(s.begin(), s.end());
	rep(i, s.size()) {
		if (s[i] != t[i]) {
			ans++;
		}
	}
	cout << ans / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
// #define int long long
struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
}IoSetup;

using Int = __int128_t;
using ll = long long;
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int SMOD = 1000000007;
constexpr int NMOD = 998244353;
constexpr int dx[]={1,0,-1,0,1,1,-1,-1};
constexpr int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T&b){if(a<b)return(a=b,1);return 0;}
template<class T>bool chmin(T &a, const T&b){if(b<a)return(a=b,1);return 0;}

int dist[1111][1111];

signed main() {

    int h, w;

    cin >> h >> w;

    int ch, cw, dh, dw;

    cin >> ch >> cw >> dh >> dw;
    ch--, cw--, dh--, dw--;

    vector<string> s(h);

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

    memset(dist, 0x3f, sizeof(dist));

    dist[ch][cw] = 0;

    deque<pii> que;

    que.push_front({ch, cw});

    while(!que.empty()) {
        int y = que.front().first;
        int x = que.front().second;
        que.pop_front();

        for(int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(inside(nx, ny, w, h) and dist[ny][nx] > dist[y][x] and s[ny][nx] != '#') {
                dist[ny][nx] = dist[y][x];
                que.push_front({ny, nx});
            }
        }

        for(int i = 0; i < 5; i++) {
            for(int j = 0; j < 5; j++) {
                int nx = x + j - 2;
                int ny = y + i - 2;
                if(inside(nx, ny, w, h) and dist[ny][nx] > dist[y][x] + 1 and s[ny][nx] != '#') {
                    dist[ny][nx] = dist[y][x] + 1;
                    que.push_back({ny, nx});
                }
            }
        }
    }

    if(dist[dh][dw] >= INF) dist[dh][dw] = -1;

    cout << dist[dh][dw] << endl;

    return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int prime[] = new int[10000001];
		int n;

		Arrays.fill(prime, 1);
		prime[0] = 0;
		prime[1] = 0;
		for (int i = 2; i < 10000001 / 2; i++) {
			if (prime[i] == 1) {
				for (int j = i * 2; j < 10000001; j += i) {
					prime[j] = 0;
				}
			}
		}

		while (true) {
			n = sc.nextInt();
			if (n == 0) {
				break;
			}
			while (true) {
				if (prime[n] == 1 && prime[n - 2] == 1 && prime[n - 6] == 1 && prime[n - 8] == 1) {
					System.out.println(n);
					break;
				}
				n--;
			}
		}
	}
}

Measured memory_bytes: 63360
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Solve is
   A : Integer;
   P : Integer;
begin
   Get (A);
   Get (P);
   P := P+A*3;
   Put_Line (Integer'Image (P/2));
end Solve;

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  ll n,k;
  cin>>n>>k;
  cout<<min(n%k,k-n%k)<<endl;
  return 0;
}


Measured memory_bytes: 256