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

using namespace std;

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

int main() {
    ll n, w; cin >> n >> w;
    ll we[n+1], va[n+1];
    memset(we, 0, sizeof(we));
    memset(va, 0, sizeof(va));
    for (int i = 1; i <= n; i++) {
        cin >> we[i] >> va[i];
    }

    ll dp[n+1][w+1];
    memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= w; j++) {
            if (j < we[i]) 
                dp[i][j] = dp[i-1][j];
            else 
                dp[i][j] = max(dp[i-1][j], va[i]+dp[i-1][j-we[i]]);
        }
    }
    cout << dp[n][w] << "\n";
    return 0;
}

Measured memory_bytes: 79104
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)

int main()
{
  int x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int a = x2 - x1, b = y2 - y1;

  cout << x2 - b << " " << y2 + a << " " << x1 - b << " " << y1 + a << endl;

  return 0;
}


Measured memory_bytes: 256
N,K = map(int, input().split())
A = list(map(int, input().split()))

count = 0

for i in range(N - K):
  kake_A = A[i]
  kake_B = A[i + K]
  if kake_A >= kake_B:
    print('No')
  else:
    print('Yes')

Measured memory_bytes: 31620
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(),x.end()
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
double pi=acos(-1);
typedef long long ll;
typedef unsigned long long ull;
inline ll lowbit(ll x){return x&(-x);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
const int INF=0x3f3f3f3f,max_n=1000005,mod=19260817;
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
inline ll pow(ll a,ll b,ll mod){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
bool vis[max_n];
vector<int>p;
int n=110000;
void sieve()
{
    for(int i=2;i<=n;i++)
    {
        if(!vis[i])
        {
            p.push_back(i);
        }
        for(int j=0;i*p[j]<=n;j++)
        {
            vis[i*p[j]]=1;
            if(i%p[j]==0)break;
        }
    }
}
int main()
{
	sieve();
    int n;cin>>n;
    cout<<*lower_bound(p.begin(),p.end(),n);
}

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

int main() {
  int n;cin>>n;
  vector <int> a(n);
  rep(i,n)cin>>a[i];
  reverse(a.begin(),a.end());
  rep(i,n-1)cout <<a[i]<< " ";
  cout <<a[n-1];
  cout<<endl;
}


Measured memory_bytes: 3104
#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<utility>
#include<iterator>
#include<regex>
#include<math.h>
#include<numeric>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(lli i=0;i<j;i++)
#define rep1(i,j) for(lli i=1;i<=j;i++)
#define rep0d(i,j) for(lli i=j-1;i>=0;i--)
#define MAX 1000000007
typedef struct tree Tree;

using namespace std;

bool cmpf(pair<lli, lli> left, pair<lli, lli> right) {
	return left.first < right.first;
}
bool cmp(pair<lli, lli> left, pair<lli, lli> right) {
	if (left.first != right.first)return left.first < right.first;
	else return left.second < right.second;
}

int main() {
	vector<lli> div;
	lli n,m;
	cin >> m >> n;
	rep1(i, sqrt(n)) {
		if (n % i == 0) {
			div.push_back(i);
			div.push_back(n / i);
		}
	}
	sort(rall(div));
	rep0(i, n) {
		if (div[i] <= n/m) {
			cout << div[i];
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

signed main() {
  INIT;
  VAR(string,s);

  REP(o1,2){
    REP(o2,2){
      REP(o3,2){
        int res = s[0]-'0';
        res += (o1?1:-1) * (s[1]-'0');
        res += (o2?1:-1) * (s[2]-'0');
        res += (o3?1:-1) * (s[3]-'0');
        if(res == 7) {
          OUT(s[0]);
          OUT((o1?"+":"-"));
          OUT(s[1]);
          OUT((o2?"+":"-"));
          OUT(s[2]);
          OUT((o3?"+":"-"));
          OUT(s[3]);
          OUT("=7")BR;
          return 0;
        }
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<cctype>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<algorithm>
#include<numeric>
#include<vector>
using std::vector;
#include<string>
using std::string;
#include<set>
using std::set;
#include<map>
using std::map;
#include<unordered_map>
#include<queue>
#include<tuple>
using std::get;
using std::pair;
using std::tuple;
#include<iostream>
#include<sstream>
#include<iomanip>
using lnt = long long int;
using unt = unsigned long long int;
using ust = unsigned;
using dou = double;
using P = std::pair<int,int>;
#define FZ(i,n)       for(int i=0;i<(n);++i)
#define FB(i,n)       for(int i=(n)-1;i>=0;--i)
#define FV(i,st,ed)   for(int i=st;i<(ed);++i)
#define FC(i,n)       for(int i=n;i;--i)
#define FZU(i,n)      for(ust i=0;i!=(n);++i)
#define FVU(i,st,ed)  for(ust i=st;i<(ed);++i)
#define FCU(i,n)      for(ust i=n;i;--i)
#define ALL(x)        std::begin(x),std::end(x)
#define DTRL(x,y)     do{auto&x_(x),&y_(y);if(x_!=y_)return x_<y_;}while(0)

#define RI(x) scanf("%d",&(x))
#define RII(x,y) scanf("%d %d",&(x),&(y))
#define RS(x) scanf("%s",x)
#define RI64(x) scanf("%lld",&(x))
#define RII64(x,y) scanf("%lld%lld",&(x),&(y))

#define FIR first
#define SEC second
#define pritnf printf
int main(){
    int N,K;
    std::string s;
    std::cin >> N >> K >> s;
    std::vector<std::pair<int,int>> a;
    for(auto it = s.begin();it<s.end();){
        auto jt = std::find(it,s.end(),'1');
        auto kt = std::find(jt,s.end(),'0');
        a.emplace_back(jt-it,kt-jt);
        it = kt;
    }
    int sum = 0;
    for(int i=0;i<K && i<int(a.size());++i){
        sum+= a[i].first;
        sum+= a[i].second;
    }
    int ans = sum;
    for(int i=K;i<N && i<int(a.size());++i){
        sum-= a[i-K].first;
        sum+= a[i].first;
        sum+= a[i].second;
        ans = std::max(ans,sum);
        sum-= a[i-K].second;
    }
    std::cout << ans<< '\n';
}


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

template <typename TYPE>
void swap(TYPE* a, TYPE* b)
{
	TYPE temp;
	temp = *a;
	*a = *b;
	*b = temp;
}

int main(void)
{
	int a[5];

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

	for (int i = 0; i < 5 - 1; i++)
	{
		for (int j = i; j < 5; j++)
		{
			if (a[i] < a[j]) swap(&a[i], &a[j]);
		}
	}
	for (int i = 0; i < 5; i++)
	{
		if (i == 0)
			cout << a[i];
		else cout << " " << a[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3120
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush=
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var S = cin.ReadInt;
			var W = cin.ReadInt;
			Console.WriteLine(W>=S ? "unsafe" : "safe");
		}
		
	}
	static class ExtendClass {
		public static void Swap<T>(this T[] A, int x, int y) {
			var tmp = A[x];
			A[x]=A[y];
			A[y]=tmp;
		}
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
		public static IEnumerable<int> Indices<T>(this T[] X) => Enumerable.Range(0, X.Length);
		public static IEnumerable<int> Indices<T>(this T[,] X, int dim)
			=> Enumerable.Range(0, X.GetLength(dim));
		public static string Join<T>(this T[,] X, string separatorD2 = ",", string separatorD1 = "\n")
			=> X.Indices(0).Select(
				i => X.Indices(1).Select(j => X[i, j]).Join(separatorD2)
			).Join(separatorD1);
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator=separator;
			this._stream=stream;
			inputStream=new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count!=0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i<tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i<N; ++i)
				ret[i]=Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i<N; ++i) ret[i]=ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i<N; ++i) ret[i]=ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i<N; ++i) ret[i]=ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek()==-1; }
		}
	}
}

Measured memory_bytes: 27856
n = int(input())
a = list(map(int, input().split()))
minimum = 1000001
maximum = -1000001
sum = 0
for i in range(n):
    if(a[i] < minimum):
        minimum = a[i]
    if(maximum < a[i]):
        maximum = a[i]
    sum += a[i]
print("%d %d %d" % (minimum, maximum, sum))


Measured memory_bytes: 6600
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
using ll=long long;
const ll MOD=1000003;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
#define range(i) (i).begin(),(i).end()
#define rrange(i) (i).rbegin(),(i).rend()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}
inline long double median(vector<ll> v){
    ll size=v.size();
    sort(v.begin(),v.end());
    if (size % 2 == 1) return v[(size - 1) / 2];
    else return v[(size / 2) - 1] ;
}
template<class T> inline bool chmax(T& a,T b) {if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b) {if(a>b){a=b;return 1;} return 0;}
template<class T,class L>ostream& operator << (ostream& os, pair<T,L>& p){os << p.first << " " << p.second;return os;}

int main(){
  ll x,a;
  cin>>x>>a;
  if(x<a) cout<<0;
  else cout<<10;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
char s[52], t[52];
int main()
{
	int n, i, j;
	long long total, mod = 1000000007;
	scanf("%d%s%s", &n, s, t);
	if(s[0] == t[0])
	{
		total = 3;
		i = 1;
		j = true;
	}
	else
	{
		total = 6;
		i = 2;
		j = false;
	}
	for( ; i < n; ++i)
	{
		if(j)
		{
			if(s[i] == t[i])
			{
				(total *= 2) %= mod;
			}
			else
			{
				(total *= 2) %= mod;
				j = false;
				++i;
			}
		}
		else
		{
			if(s[i] == t[i])
			{
				j = true;
			}
			else
			{
				(total *= 3) %= mod;
				++i;
			}
		}
	}
	printf("%lld\n", total);
}

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

int main() {
	string str;
	char ya[] = "YAKI";
	cin >> str;
	for (int i = 0; i < 4; i++) 
		if (ya[i] != str[i]) {
			cout << "No" << endl;
			return 0;
		}
	cout << "Yes" << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  long long a, b, n;
  cin >> a >> b >> n;
  n = min(n, b - 1);
  cerr << n << endl;
  cerr << a * n / b << endl;
  cerr << a * (n / b) << endl;
  cout << a * n / b - a * (n / b) << endl;
  return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

const int N = 1e5 + 5;

char s[N],t[N],t2[N];
int n,ans,tn;

inline bool check(int ln,int x) {
  for (int i = 1 ; i <= ln ; i++)
    if (t[i] != x)
      return false;
  return true;
}

inline void do_it(int ln,int x) {
  for (int i = 1 ; i <= ln ; i++)
    t2[i] = t[i];
  t2[ln + 1] = 0;
  for (int i = ln ; i >= 1 ; i--)
    if (t2[i] != x)
      t[i] = t2[i + 1];
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> (s + 1);
  n = strlen(s + 1);
  ans = n - 1;
  for (int i = 'a' ; i <= 'z' ; i++) {
    for (int j = 1 ; j <= n ; j++)
      t[j] = s[j];
    for (int j = n ; j >= 1 ; j--) {
      if (check(j,i))
        ans = min(ans,n - j);
      do_it(j,i);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define N 300009
#define inf 1e18
int mod=1e9+7;
int maxN=1e9;

#define PI 3.141596535

int fact[N];

int power(int a,int n){
    int ans=1;
    while(n){
        if(n&1)ans=(ans*a)%mod;
        n=n/2;
        a=(a*a)%mod;
    }
    return ans%mod;
}

int inv(int n){
    return power(n,mod-2)%mod;
}

void init(){
    fact[0]=1;
    for(int i=1;i<N;i++){
        fact[i]=(fact[i-1]*i)%mod;
    }
}

int ncr(int n,int r){
    int x=fact[n];
    int y=(fact[r]*fact[n-r])%mod;
    int ans=(x*inv(y)%mod)%mod;
    return ans%mod;
}
int a[5000];
int n;
int K[N];
vector<int>G[N];
int col[N];

void dfs(int s,int p=0){
    for(auto it:G[s]){
        if(it!=p){
            dfs(it,s);
            K[col[s]]+=(K[col[it]]+1);
        }
    }
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    int ans=0;
    while(k<=n+1){
        ans=(ans+((n-k+1)*k)%mod+1LL)%mod;
        k++;
    }
    cout<<ans<<"\n";
   
    return 0;
}

Measured memory_bytes: 10668
using System;
public class Hello{
    public static void Main(){
        
        int n=int.Parse(Console.ReadLine());
        int k=int.Parse(Console.ReadLine());
        int a=1;
        
        for(int i=0;i<n;i++)
        {
            if(a*2 > a+k)
                a+=k;
            else
                a*=2;
        }
        
        Console.WriteLine(a);
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


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

    int min = a[0];
    int max = a[0];
    for (int i=1; i < n; i++){
        if (a[i] < min) min = a[i];
        if (max < a[i]) max = a[i];
    }

    printf("%d\n", max-min);



    return 0;
} 



Measured memory_bytes: 128
str = gets.chomp
while str != "0 0"
  n,p = str.split.map(&:to_i)
  #print("n=",n," p=",p,"\n")
  array = Array.new(n,0)
  i = 0
  index = 0
  loop do
    index = 0 if index == n
    #???????°???????????????¨???
    if p > 0
      #???????
      if p == 1
        flag = true
        array.size.times do |i|
          if i != index && array[i] != 0
            flag = false
            break
          end
        end
        #??????
        if flag
          puts index
          str = gets.chomp
          break
        end
      end
      array[index] += 1
      p -= 1
    #?°???????????????§???
    elsif p == 0
      p = array[index]
      array[index] = 0
    end
    index += 1
  end
end


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

int main() {
    int K;
    cin >> K;
    if (K % 2 == 0) {
        int harf = K / 2;
        cout << harf * harf << endl;
    } else {
        int harf = K / 2;
        cout << harf * (harf + 1) << endl;
    }
    return 0;
}


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

int main(){
	int i,j,k,n,m,l,f,x,y,z; string s;
	cin >> n >> k;
	i = max(n/2, (n-n/2));
	if(i >= k) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> v[100001];
bool visited[100001];
int dist[100001];
int maxa=0;
int dfs(int i){
	visited[i]=true;
	for(int j=0;j<v[i].size();j++){
		if(visited[v[i][j]]){
			dist[i]=max(dist[i],1+dist[v[i][j]]);
		}else{
			dfs(v[i][j]);
			dist[i]=max(dist[i],1+dist[v[i][j]]);
		}
	}
	maxa=max(dist[i],maxa);
	if(v[i].size()==0){
		dist[i]=0;
		return 0;
	}
	//cout<<dist[i]<<" "<<i<<" ";
	return dist[i];
}
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
	}
	for(int i=0;i<=n;i++){
		visited[i]=false;
	}
	for(int i=0;i<=n;i++){
		dist[i]=INT_MIN;
	}
	for(int i=1;i<=n;i++){
		if(visited[i]==false){
			dfs(i);
		}
	}
	cout<<maxa;
}

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


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Printer pr = new Printer(System.out);

		int n = sc.nextInt();
		int m = sc.nextInt();

		BitSet bs = new BitSet(n);
		bs.set(0);
		int[] cnt = new int[n];
		Arrays.fill(cnt, 1);
		for (int i = 0; i < m; i++) {
			int x = sc.nextInt() - 1;
			int y = sc.nextInt() - 1;

			if (bs.get(x)) {
				bs.set(y);
			}
			cnt[x]--;
			cnt[y]++;
			if (cnt[x] == 0) {
				bs.clear(x);
			}
		}

		pr.println(bs.cardinality());

		pr.close();
		sc.close();
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
//					it = Arrays.asList(br.readLine().split(" ")).iterator();
					it = Arrays.asList(br.readLine().split("\\p{javaWhitespace}+")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

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

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 23880
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_B&lang=ja

def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i + 1

n = int(input())
A = list(map(int, input().split()))
q = partition(A, 0, n - 1)

for j in range(n - 1):
    if j == q:
        print("[{}]".format(A[q]), end=' ')
    else:
        print(str(A[j]), end=' ')
print(A[-1])


Measured memory_bytes: 16392
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

bool visit(const vector<vi> &g, int v, vector<int> &order, vector<int> &color) {
  color[v] = 1;
	for(int e : g[v]) {
    if (color[e] == 2) continue;
    if (color[e] == 1) return false;
    if (!visit(g, e, order, color)) return false;
  }
  order.push_back(v); color[v] = 2;
  return true;
}
bool topologicalSort(const vector<vi> &g) {
  int n = g.size();
  vector<int> color(n), order;
  rep(u, n) if (!color[u] && !visit(g, u, order, color))
    return false;
  return true;
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vector<vi> e(200);
	
	rep(i, n){
		int a, b; string s;
		cin >> a >> s >> b; a--; b--; b += 100;
		if(s == "lock") swap(a, b);
		e[a].pb(b);
	}
	cout << (int)!topologicalSort(e) << endl;
	return 0;
}


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

class Program
{
    static void Main(string[] args)
    {


		//long[] a = new long[n];




		int n = int.Parse(Console.ReadLine());
		string[] s1 = Console.ReadLine().Split(' ');
		Stack<int> s = new Stack<int>();

		for (int i = 0; i < n; i++)
		{
			s.Push(int.Parse(s1[i]));

		}

		while (s.Count > 0)
		{
			Console.Write("{0}", s.Pop());
            if (s.Count == 0) break;
			Console.Write(" ");
		}
        Console.WriteLine("");
		//Console.WriteLine("");

	}
}

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

int main(){
    int n;
    cin >> n;
    vector<int> x(n), p(n), q(n);
    for(int i=0;i<n;i++)
        cin >> p[i];
    for(int i=0;i<n;i++)
        cin >> q[i];
    for(int i=0;i<n;i++)
        x[i] = i+1;
    int a = 0,b = 0;
    int ct = 0;
    do{
        ct++;
        if(p == x) a = ct;
        if(q == x) b = ct;
    }while(next_permutation(x.begin(), x.end()));
    cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		if(a==0) {
			System.out.println(1);
		}else if(b==0) {
			System.out.println(2);
		}else if(c==0) {
			System.out.println(3);
		}else if(d==0) {
			System.out.println(4);
	}else if(e==0) {
		System.out.println(5);
	}
	}
}


Measured memory_bytes: 35688
#include <bits/stdc++.h>
using namespace std;
int N, K;
int main() {
    cin >> N >> K;
    vector<int> x(N, 0);
    for(int i = 0; i < N; ++i) {
        cin >> x.at(i);
    }

    int sum = 0;

    for(int i = 0; i < N; ++i) {
        int a = x.at(i);
        int b = abs(x.at(i)-K);
        if(a > b) {
            sum += b*2;
        }else {
            sum += a*2;
        }
    }

    cout << sum << endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

int N;
int L[111111],R[111111];

signed main(){
	cin>>N;
	rep(i,N)cin>>L[i]>>R[i],L[i]--;


	vint ordL(N),ordR(N);
	iota(all(ordL),0);iota(all(ordR),0);
	sort(all(ordL),[&](int i,int j){
		return L[i]>L[j];
	});

	sort(all(ordR),[&](int i,int j){
		return R[i]<R[j];
	});


	int base=0;
	int tmp=max(0ll,R[ordR[0]]-L[ordL[0]]);
	base+=tmp;
	rep(i,N)R[i]-=tmp;
	int ans=0;
	rep(i,N)chmax(ans,R[i]-L[i]);

	const int INF=1001001001;
	vint lis;
	int l=L[ordR[0]];
	int r=R[ordL[0]];
	for(auto i:ordL){
		if(L[i]>=R[ordR[0]]){
			chmin(r,R[i]);
			continue;
		}
		if(R[i]<=L[ordL[0]]){
			chmax(l,L[i]);
			continue;
		}
		lis.pb(i);
	}


	for(auto i:lis){
		chmax(ans,max(0ll,r-L[ordL[0]])+max(0ll,R[ordR[0]]-max(l,L[i])));
		chmin(r,R[i]);
	}
	chmax(ans,max(0ll,r-L[ordL[0]])+max(0ll,R[ordR[0]]-l));
	cout<<ans+base*2<<endl;
	return 0;
}

Measured memory_bytes: 4472
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll sum = accumulate(all(A), 0LL);
  ll m = N*(N+1)/2;
  if(sum % m != 0) {
    cout << "NO" << endl;
  } else {
    ll k = sum / m;
    ll cnt = 0;
    bool ok = true;
    rep(i, N) {
      int j = (i+1)%N;
      ll sub = k-(A[j]-A[i]);
      if(sub < 0 || sub % N != 0) {
        ok = false;
        break;
      }
      cnt += sub / N;
    }
    if(ok && cnt == k) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 3988
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0011
{
    class Program
    {
        static void Main(string[] args)
        {
            int w = int.Parse(Console.ReadLine());
            int n = int.Parse(Console.ReadLine());
            int[] ansnumber = new int[w];
            for(int i = 0; i < w; ++i)
            {
                ansnumber[i] = i + 1;
            }
            for (int i = 0; i < n; ++i)
            {
                int[] order = Console.ReadLine().Split(',').Select(int.Parse).ToArray();
                Parse(ansnumber, order[0], order[1]);
            }
            foreach (var item in ansnumber)
            {
                Console.WriteLine(item);
            }

        }

        static void Parse(int[] number,int i,int j)
        {
            int n = number[i-1];
            number[i-1] = number[j-1];
            number[j-1] = n;
        }
    }
}



Measured memory_bytes: 14236
package main

import (
	"fmt"
)

func main() {
	var (
		n, y int
	)
	res10000 := -1
	res5000 := -1
	res1000 := -1
	fmt.Scan(&n, &y)

	for i := 0; i <= n; i++ {
		for j := 0; i+j <= n; j++ {
			k := n - i - j
			total := 10000*i + 5000*j + 1000*k
			if total == y {
				res10000 = i
				res5000 = j
				res1000 = k
			}
		}
	}

	fmt.Printf("%d %d %d\n", res10000, res5000, res1000)
}


Measured memory_bytes: 512
n = int(input())
l = []
for _ in range(n):
    a, b, c = map(int, input().split())
    l.append([a, b, c])

dp = [[0]*3 for _ in range(n)]
dp[0] = l[0]

for i in range(1, n):
    for j in range(3):
        if j == 0:
            dp[i][j] = l[i][j] + max(dp[i-1][1], dp[i-1][2])
        elif j == 1:
            dp[i][j] = l[i][j] + max(dp[i-1][0], dp[i-1][2])
        elif j == 2:
            dp[i][j] = l[i][j] + max(dp[i-1][0], dp[i-1][1])

print(max(dp[-1]))

Measured memory_bytes: 44324
S = list(input())

N = len(S)

ans = [0]*N

for _ in range(2):
    cnt = 0
    for i in  range(len(S)):
        if S[i] =='R':cnt +=1
        else:
            ans[i] += int(cnt/2)
            ans[i-1] += int((cnt+1)/2)
            cnt = 0

    S.reverse()
    ans.reverse()
    for i in range(len(S)):
        if S[i] == 'L':
            S[i] ='R'
        else:
            S[i] = 'L'

print(*ans)

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

typedef long long int ll;

using namespace std;

ll count(ll n)
{
    return (n * (n - 1LL)) / 2LL;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    map<int, int> cnt;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        cnt[a[i]]++;
    }
    
    ll total = 0LL;
    for (auto c : cnt)
    {
        total += count((ll) c.second);
    }
    
    for (int i = 0; i < n; ++i)
    {
        int c = cnt[a[i]];
        
        ll res = total - count((ll) c) + count((ll) (c - 1));
        cout << res << "\n";
    }

    return 0;
}


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

int main() {
  int n, k; cin >> n >> k;
  vector<double> dp(max(n, k)+1, 1);
  for (int i = k-1; i >= 0; i--) {
    dp[i] = dp[min(k, i*2)] / 2;
  }
  double res = 0;
  for (int i = 1; i <= n; i++) {
    res += dp[i] / n;
  }
  cout << fixed << setprecision(12) << res << endl;
}

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

int main()
{
    long long n;
    cin>>n;
    pair<long long,long long> B[n];
    for(int i = 0; i < n; i++){
        cin>>B[i].first;
        B[i].second = i;
    }
    sort(B, B + n);
    for(int i = 0; i < n; i++){
        if(i == B[n-1].second){
            cout<<B[n-2].first<<endl;
        }else{
            cout<<B[n-1].first<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4736
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 2e5 + 200;
const long long MNN = 2e3 + 200;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong n, b[MXN], ans;

int main () {
    ios;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> b[i];
    }
    for(llong i = 1; i < n; i++){
        llong res = 0;
        if ((n - 1) % i == 0) {
            for (int j = 1, k = n; j < k; j += i, k -= i) {
                res+= b[j] + b[k];
                ans = max(ans, res);
            }
        } else {
            for (int j = 1, k = n; j < n && k > i; j += i, k -= i) {
                res += b[j] + b[k];
                ans = max(ans, res);
            }
        }
    }
    cout << ans;
    return 0;
}


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

using namespace std;
int dp[10][10];
int h,w;
int a[202][202];
int main() {
  cin >> h >> w;

  for(int i = 0; i < 10; i++) {
    for(int j = 0; j < 10; j++) {
      cin >> dp[i][j];
    }
  }

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

  for(int k = 0; k < 10; k++) {
    for(int i = 0; i < 10; i++) {
      for(int j = 0; j < 10; j++) {
	dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j]);
      }
    }
  }

  int ans = 0;

  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      if(a[i][j] == -1 || a[i][j] == 1) continue;
      ans += dp[a[i][j]][1];
    }
  }

  cout << ans << endl;
}
  
  


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

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){
    
}

void solve(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n+1),b;
    for(ll i=1;i<=n;i++){
        cin >> a[i];
    }
    bool visited[n+1];
    memset(visited,false,sizeof visited);

    ll ind = 1;
    ll curr = 0;
    map<ll,ll> MAP;
    while(1){
        if(visited[ind]){
            break;
        }
        b.pb(ind);
        MAP[ind] = curr;
        visited[ind] = true;
        ind = a[ind];
        curr++;
    }
    ll sz = curr - MAP[ind];

   if( k < MAP[ind] ){
       cout << b[k];
   }
   else{
       k -= MAP[ind];
       k %= sz;
       //cout << k << " " << MAP[ind] << " ";;
       cout << b[MAP[ind] + k];
   }
}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 18740
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<long long, long long>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    int x; cin >> x;
    int ans;
    if (x <= 599)
        ans = 8;
    else if (x <= 799)
        ans = 7;
    else if (x <= 999)
        ans = 6;
    else if (x <= 1199)
        ans = 5;
    else if (x <= 1399)
        ans = 4;
    else if (x <= 1599)
        ans = 3;
    else if (x <= 1799)
        ans = 2;
    else
        ans = 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define VPII vector<PII>
#define VPLL vector<PLL>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------
const int MX = 100005;
int a[MX];
unordered_map<int, int> mp[33];

int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    int n,c; cin >> n >> c;

    FOR(i,0,n-1) {
        int s,t, c; cin >> s >> t >> c;
        mp[c][s]++;
        s--;
        a[s]++; a[t]--;
        mp[c][t]++;
    }

     FOR(i,1,30) {
        for(auto &[k, v]: mp[i]) {
            //cout << k << " " << v;
            if(v >= 2) {
                a[k-1]--;
                a[k]++;
            }
        }
    }

    int ans = 0;
    int cur = 0;
    FOR(i,0,MX) {
        cur += a[i];
        chmax(ans, cur);
    }

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


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

using namespace std;

typedef long long ll;

void solve() {
	ll a, b, c;
	cin >> a >> b >> c;
	a -= b;
	cout << max(0ll, c - a) << endl;
}

int main() {
	ll t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1276>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

const ll MAX_PRIME = 1299710;
vector<int> primes;
vector<int> is_prime(MAX_PRIME + 1,true);
void init_primes(){
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= MAX_PRIME;i++){
        if(is_prime[i]){
            primes.push_back(i);
            for(int j = i*2; j <= MAX_PRIME; j+=i) is_prime[j] = false;
        }
    }
}

int K;
ll solve(){
    ll res = 0;
    if(is_prime[K]) return 0;
    auto it = upper_bound(primes.begin(),primes.end(),K);
    res = *it - *(it-1);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    init_primes();
    while(cin >> K,K){
        cout << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 8364
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;


int main() {
	string s;
	ll k;
	cin >> s >> k;
	
	for (ll i = 0; i < k; ++i) {
		if (s[i] != '1') {
			cout << s[i] << endl;
			return 0;
		}
	}
	cout << 1 << endl;
	return 0;
}


Measured memory_bytes: 256
/*
___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr andarash mazide nemat.
___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat.
___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb.

___az dast o zabane ke barayad ?
___kaz ohdeye shokrash be dar ayad !


___man be to dami gharar natvanam kard
___va ehsane to ra shomar natvanam kard
####################
___gar bar tane man zaban shavad har moyee
___yek shokre to az hezar natvanam kard

*/

#include <bits/stdc++.h>

#define pb push_back
#define SALI main
#define left(x) ((x)*2)
#define right(x) (((x)*2)+1)
#define fuck(x) cout << #x << " : " << x << "   ";
#define findLowVec(v,x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define findUpVec(v,x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define findLowArr(a,n,x) (lower_bound(a, a+n, x) - a)
#define findUpArr(a,n,x) (upper_bound(a, a+n, x) - a)
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;

template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p)
{return out << "(" << p.first << ", " << p.second << ")";}

template<class A> ostream& operator <<(ostream& out, const vector<A> &v)
{out << "[";for(int i = 0; i < v.size(); i++) {if(i) out << ", ";out << v[i];}return out << "]";}

template<class A,class B> ostream& operator <<(ostream& out, const set<A,B> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

template<class A> ostream& operator <<(ostream& out, const set<A> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

const int N = 1e5 + 10;
vector<int> G[N];
int dp[N];

void dfs(int u)
{

    dp[u] = 1;
    int p = 0;
    for(auto v : G[u]){
        if(dp[v] == 0){
            dfs(v);
        }
        p = max(p,dp[v]);
    }
    dp[u] += p;

}

int32_t SALI()
{
    int n,m; cin >> n >> m;
    for(int i = 0; i < m; i++){
        int u,v; cin >> u >> v; G[u].pb(v);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        if(dp[i] == 0){
            dfs(i);
        }
        ans = max(ans,dp[i]);
    }
    cout << ans-1 << endl;

}


/**< WRITEN BY ALI ADELKHAH */



Measured memory_bytes: 12556
import java.util.Scanner;

class Main{
    public static void main(String[] args){
	final Scanner sc=new Scanner(System.in);
	while(sc.hasNext()){
	    int a=sc.nextInt();
	    int b=sc.nextInt();
	    int c=sc.nextInt();
	    int d=sc.nextInt();
	    int e=sc.nextInt();
	    int f=sc.nextInt();
	    int b2=b*d;
	    int c2=c*d;
	    int e2=a*e;
	    int f2=a*f;
	    double y = (double)(c2-f2)/(b2-e2);
	    double x = (double)((c-b*y)/a);
	    System.out.printf("%.3f %.3f\n",x,y);
	}
    }
}

Measured memory_bytes: 16388
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i++)
#define RFOR(i, a, b) for(int i=(int)(a); i!=(int)(b); i--)
#define REP(i, n) FOR(i, 0, n)
using namespace std;
using ll = long long;

int main(){
  int n; cin >> n;
  int a[n];
  REP(i, n) cin >> a[i];

  enum class State{up, down, unkown};

  int ans = 0; State st = State::unkown;
  REP(i, n-1){
    if(st == State::unkown){
      if(a[i] < a[i+1]) st = State::up;
      else if(a[i] > a[i+1]) st = State::down;
    }
    if(st == State::down && a[i] < a[i+1]){
      st = State::unkown;
      ans++;
    }
    if(st == State::up && a[i] > a[i+1]){
      st = State::unkown;
      ans++;
    }
  }

  cout << ans + 1 << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  std::string s; std::cin >> s;
  auto c = s.front();
  auto ret =
      c == 'S'
    ? "Cloudy"
    : c == 'C'
    ? "Rainy"
    : "Sunny";
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 256