akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int INF = 1e9;
inline int read(){
	int X = 0,w = 0 ;
	char ch = 0;
	while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
	while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
	return w ? -X : X;
}
ll a,b,c,d,g;
ll gcd(ll a,ll b)
{
	return a%b==0?b:gcd(b,a%b);
}
ll adj(ll a,ll b,ll m)
{
	if((a%m+m)%m>b)
	{
		b+=m;
	}
	return a+b-(a%m+m)%m;
}
bool check()
{
	if(b>a or b>d)
	{
		return 0;
	}
	g=gcd(b,d);
	return adj(c-b+1,a%g,g)>=0;
}
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		cin>>a>>b>>c>>d;
		if(check())
		{
			cout<<"Yes"<<endl;
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=50000005;
int s,len[N],p[N];
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
int main()
{
    p[0]=1;
    scanf("%d",&s);
    ll ans=0;
    int sum=0;
    for(int l=1,r=0;l<10000000;l++)
    {
        while(sum<s)
        {
            r++;
            p[r]=p[r-1];
            len[r]=len[r-1];
            if(r/p[r]!=0) p[r]*=10,len[r]++;
            sum+=len[r];
        }
        if(sum==s) ans++;
        sum-=len[l];
    }
    for(int t=1;t<=s/8;t++)
    {
        if(s%t) ans=(ans+1)%mod;
        else ans=(ans+(qpow(10,s/t)-qpow(10,s/t-1)-t+1))%mod;
    }
    ans=(ans+mod)%mod;
    printf("%lld\n",ans);
}


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

int main() {
  int N;
  cin>> N;
  
  vector<int>A(N);
  vector<int>B(N);
  vector<int>C(N-1);
  int answer=0;
  
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >>B.at(i);
  }
  for (int i = 0; i < N-1; i++) {
    cin >>C.at(i);
  }
  
  
 for (int i = 0; i < N-1; i++) {
   if(A.at(i)+1==A.at(i+1)){
     answer=answer+B.at(A.at(i)-1)+C.at(A.at(i)-1);
   }
   else{
     answer=answer+B.at(A.at(i)-1);
   }
     
 }
  
  answer=answer+B.at(A.at(N-1)-1);
    
  cout<<answer<<endl;
 

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<string>
using namespace std;
int main(void){
string s;
while(1){
	cin>>s;
	if(s=="#")break;
	//now -1 l 1 r
	int r=-1,l=-1,ans=0,now=0;
for(int i=0;i<s.size();i++){
	if(s[i]=='1'||s[i]=='4'||s[i]=='7'){
		if(now==0){
			if(l==0){
				r=0;
			//	cout<<ans<<' '<<now<<' '<<l<<' '<<r<<endl;
				continue;
			}
		l=0;
		if(r!=-1&&r!=0){
			now=-1;
		}

		}else{
			if(now==1){
				now=-1;
				l=0;
			}else if(l>0){
				now=-1;
				l=0;
				ans++;
			}else{
				now=1;
				r=0;
			}
		}

		}else if(s[i]=='2'||s[i]=='8'){
	if(now!=0){
		if(now==-1){
			if(l==2){
				l=1;
				ans++;
			}else{
				now=1;
				r=1;
			}
		}else{
			if(now==1){
				if(r==0){
					r=1;
					ans++;
				}else{
					now=-1;
					l=1;
				}
			}
		}

	}else{
		if(l==0){
			r=1;
			now=1;
		}else if(r==2){
			l=1;
			now=-1;
		}else{
			r=1;
			l=1;
		}
	}

		}else{
			if(now==0){
				if(r==2){
					l=2;
//cout<<ans<<' '<<now<<' '<<l<<' '<<r<<endl;
					continue;
				}
				r=2;
				if(l!=-1&&l!=2){
					now=1;
				}
			}else{
				if(now==-1){
					now=1;
					r=2;
				}else{
					if(r!=2){
						ans++;
						r=2;
					}else{
						l=2;
						now=-1;
					}
				}

			}

}
//cout<<ans<<' '<<now<<' '<<l<<' '<<r<<endl;
}
cout<<ans<<endl;

}

	return 0;
}

Measured memory_bytes: 3148
if __name__ == "__main__":
    n = int(input())

    arr = [int(x) for x in input().split()]
    s1 = sum(arr)
    s2 = sum((x * x for x in arr))

    ans = s1*s1 - s2

    if ans % 2 != 0:
        ans += 10**9+7

    ans //= 2

    print(ans % (10**9 + 7))

Measured memory_bytes: 94324
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
inline int read()
{
    int s=0,f=1; char ch=getchar();
    while(!isdigit(ch) && ch!='-')ch=getchar();
    if(ch=='-')ch=getchar(),f=-1;
    while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
    return ~f?s:-s;
}


const int maxn=1e4+20;

inline int Ask(int x,int y)
{
    printf("? %d %d",x,y);
    cout<<endl;
    char ch;
    cin>>ch;
    return ch=='Y';
}

int main()
{
    int A=read(),B=read();
    if(A<=B)puts("Impossible");
    else
    {
	static int st[maxn],top;
	REP(i,0,A+B-1)
	{
	    if(!top || Ask(st[top],i))st[++top]=i;
	    else top--;
	}
	static int ans[maxn];
	
	REP(i,0,A+B-1)
	    ans[i]=Ask(st[top],i);
	printf("! ");
	REP(i,0,A+B-1)printf("%d",ans[i]);cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 724
N = int(input())
A = list(map(int, input().split()))
count = 1

conti_flg = 0  # {-1: '-', 0: '=', 1: '+'}
fst = A[0]
for i in A:
    snd = i
    if fst > snd:
        conti_flg = -1 if conti_flg <= 0 else 2
    elif fst < snd:
        conti_flg = 1 if conti_flg >= 0 else 2

    if conti_flg == 2:
        count += 1
        conti_flg = 0
    fst = snd

print(count)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<i64> x1(3), x2(3);
  cin >> x1[0] >> x1[1] >> x1[2] >> x2[0] >> x2[1] >> x2[2];
  vector<i64> dp(N + 1);
  dp[0] = N;
  REP(i, 3) {
    i64 t1 = x1[i], t2 = x2[i];
    if (t1 >= t2) continue;
    for (int j = t1; j <= N; ++j) {
      if (dp[j - t1] >= t1) {
        dp[j] = max(dp[j], dp[j - t1] - t1 + t2);
      }
    }
  }
  i64 donb = *max_element(dp.begin(), dp.end());
  dp.resize(donb + 1);
  fill(dp.begin(), dp.end(), 0);
  dp[0] = donb;
  REP(i, 3) {
    i64 t1 = x1[i], t2 = x2[i];
    if (t1 <= t2) continue;
    for (int j = t2; j <= donb; ++j) {
      if (dp[j - t2] >= t2) {
        dp[j] = max(dp[j], dp[j - t2] - t2 + t1);
      }
    }
  }
  cout << (*max_element(dp.begin(), dp.end())) << endl;
  ;
}

Measured memory_bytes: 195584
n = int(input())

if n/11 == int(n/11):
     a = n/11
     print(int(2*a))
else:
    a = int(n/11)
    # a+1 の帯に入る
    if n <= 11*a+6:
        print(int(2*(a+1)-1))
    else:
        print(int(2*(a+1)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           ((ll)x.size())
#define hell            (1000000007)
#define inf             ((ll)5e18 + 5)
#define PI              ((double)3.14159265358979323844)
#define DECIMAL(n)      cout << fixed << setprecision(n);
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define bitcount(a)     (ll)__builtin_popcount(a)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<(ll)ceil(a/(b*1.0))*c<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define watch(x) cout << #x << " is " << x << endl;
#define print(a, l, r) \
    for (int i = l; i < r; i++) cout << a[i] << (i == (r - 1) ? endl : " ");
const long long M = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, a, b;
    cin >> n >> a >> b;

    long long ans = ((n) / (a + b)) * a + ((n % (a + b)) ? min(n % (a + b), a) : 0);
    cout << ans << endl;
    return 0;
}


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

int cal(int a) {
    int count = 0;
    int x = a;
    while (x) {
        x /= 10;
        count++;
    }
    return count;
}

int main() {
    ll N;
    cin >> N;
    int i_max = sqrt(N);
    int d = 20;
    for (int i = 1; i <= i_max; i++) {
        if (N % i == 0) {
            d = min(d, cal(N / i));
        }
    }
    cout << d << endl;
}

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

string a[10000];

int solve(int i,int j){

  if(a[i][j] == '1') a[i][j] = '0';

  if(i + 1 < 12 && a[i+1][j] == '1') solve(i+1,j);
  if(j + 1 < 12 && a[i][j+1] == '1') solve(i,j+1);
  if(i - 1 > -1 && a[i-1][j] == '1') solve(i-1,j);
  if(j - 1 > -1 && a[i][j-1] == '1') solve(i,j-1);
}

int main(){

  while(cin >> a[0]){

    for(int i=1;i<12;i++) cin >> a[i];

    int count = 0;

    for(int i=0;i<12;i++){
      for(int j=0;j<12;j++){
	if(a[i][j] == '1'){
	  count++;
	  solve(i,j);
	}
      }
    }

    cout << count << endl;
  }
}

Measured memory_bytes: 1268
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, M = map(int, rl().split())
    A = list(map(int, rl().split()))
    
    ans = N - sum(A)
    print(ans if 0 <= ans else -1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9852
N = int(input())
ws = list(map(int,input().split()))
mae = 0
ushiro = 0
ans = 10000000
for w in range(len(ws)):
    if abs(sum(ws[:w])-sum(ws[w:]))<ans:
        ans = abs(sum(ws[:w])-sum(ws[w:]))
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>
#include <cmath>
#include<stdio.h>
#include<queue>
#include<stack>
#include<set>
#define MAX 1000000000000000000LL
long long inf=1000000007;
using namespace std;
int main(){
    int n; cin>>n;
    int num[101];
    long long dp[101][21]={};
    for(int i=1; i<=n; i++){
        cin>>num[i];
    }
    dp[1][num[1]]=1;
    
    for(int i=2; i<n; i++){
        for(int j=0; j<=20; j++){
            if(num[i]<=j)dp[i][j]+=dp[i-1][j-num[i]];
            if(num[i]+j<=20)dp[i][j]+=dp[i-1][j+num[i]];
        }
    }
    
    cout<<dp[n-1][num[n]]<<endl;
    return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  ll c;
  cin >> n >> c;
  vector<ll> x(n), v(n);
  rep(i,n) {
    cin >> x[i] >> v[i];
  }
  auto solve = [&]() {
    vector<ll> vsum(n+1,0);
    rep(i,n) {
      vsum[i+1] += vsum[i] + v[i];
    }
    vector<ll> maxc(n+1,0); //n-1...iまで食べられるときの差し引きカロリーの最大値
    for (int i = n-1; i >= 0; --i) {
      maxc[i] = (vsum[n] - vsum[i]) - (c-x[i]); //n-1...iまで食べた時の差し引き
      chmax(maxc[i], maxc[i+1]);
    }
    ll ans = 0;
    rep(i,n) {
      ll res = vsum[i+1] - x[i]; //反時計でiまで
      chmax(ans,res); //iで退店
      res -= x[i];
      res += maxc[i+1]; //時計でi+1まで
      chmax(ans,res);
    }
    return ans;
  };
  ll ans = solve();
  rep(i,n) x[i] = c - x[i]; //反対方向も試す
  reverse(all(x));
  reverse(all(v));
  chmax(ans, solve());
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(){
	int ans = 0;
	string S;
	cin >> S;
	for (int i = 0;i < 4;i++) {
		if (S[i] == '+') {
			ans++;
		}
		else {
			ans--;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
h=[int(e) for e in input().split()]
l=[0]*(n+1)
cnt=0
for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]>h[b-1]:
        l[b]+=1
    elif h[a-1]<h[b-1]:
        l[a]+=1
    else:
        l[a]+=1
        l[b]+=1
for j in l:
    if j==0:
        cnt+=1
print(cnt-1)


Measured memory_bytes: 85068
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)
#define RREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define RREP1(i, n) for (ll i = n; i >= 1; i--)
#define FOR(i, a, b, c) for (ll i = a; i <= b; i += c)
#define RFOR(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)
#define INF 1145141919
typedef long long ll;

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    
    if (a - b == b - c) puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 128
import itertools
H,W,K=map(int,input().split())

C=[]

for i in range(H):
  C.append(input())

ans=0
for i in range(H+1):
  for j in range(W+1):
    for n in itertools.combinations(list(range(H)),i):
      for m in itertools.combinations(list(range(W)),j):
        count = 0
        for a in n:
          for b in m:
            if(C[a][b]=="#"):count+=1
        if(count == K):
          ans += 1
print(ans)

Measured memory_bytes: 9216
n,q=map(int,raw_input().split())
exist=set([1])
cup=range(n+2)
now=1
exist.add(cup[now-1])
exist.add(cup[now+1])
for i in xrange(q):
    a,b=map(int,raw_input().split())
    if now==a:now=b
    elif now==b:now=a
    tmp=cup[a]
    cup[a]=cup[b]
    cup[b]=tmp
    exist.add(cup[now-1])
    exist.add(cup[now+1])
exist=list(exist)
ans=0
for i in xrange(len(exist)):
    if exist[i]!=0 and exist[i]!=n+1:ans+=1
print ans

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

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

int main() {
  int N; scanf("%d", &N);
  long ans{1};
  for (int i{1}; i <= N; ++i) {
    ans *= i;
    ans %= 1000000007;
  }

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        int ans = -1;
        int[] arr = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        int n = arr[0];
        int m = arr[1];
        string[] ansArr = new string[3];
        ansArr = ansArr.Select(a => a = "").ToArray();
        for(int i = 0; i < m; i++)
        {
            string[] arrN = Console.ReadLine().Split(' ').ToArray();
            int keta = int.Parse(arrN[0]) - 1;
            if (keta + 1 > n)
            {
                Console.WriteLine(-1);
                return;
            }
            string c = arrN[1];
            if(ansArr[keta].Equals("") || ansArr[keta].Equals(c))
            {
                ansArr[keta] = c;
            } else
            {
                Console.WriteLine(-1);
                return; 
            }
        }
        //ansArr = ansArr.Reverse().ToArray();
        if (n == 1)
        {
                ansArr[0] = ansArr[0].Equals("") ? "0" : ansArr[0];
                ans = Henkan(ansArr);
        } else if(n == 2)
        {
            if (!ansArr[0].Equals("0"))
            {
                ansArr[0] = ansArr[0].Equals("") ? "1" : ansArr[0];
                ansArr[1] = ansArr[1].Equals("") ? "0" : ansArr[1];
                ans = Henkan(ansArr);
            }
        } else if(n == 3)
        {
            if (!ansArr[0].Equals("0"))
            {
                ansArr[0] = ansArr[0].Equals("") ? "1" : ansArr[0];
                ansArr[1] = ansArr[1].Equals("") ? "0" : ansArr[1];
                ansArr[2] = ansArr[2].Equals("") ? "0" : ansArr[2];
                ans = Henkan(ansArr);
            }
        }
        Console.WriteLine(ans);

    }
    static int Henkan(string[] arr)
    {
        string hen = "";
        for(int i = 0; i <  3; i++)
        {
            hen += arr[i];
        }
        return int.Parse(hen);
    }

}





Measured memory_bytes: 11348
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
#include"algorithm"
#include"queue"
using namespace std;
int yy[1001][1001],n,m,c,d,pl;
char xx[1001][1001];
struct mm
{
	int x;
	int y;
};
int dir[4][2] ={-1,0,1,0,0,-1,0,1};
int check(int x,int y)
{
	if(x < 0 || y < 0 || x >= n || y >= m)
		return 0;
	else
		return 1;
}
void bfs(int x1,int y1)
{
	queue<mm>qq;
	mm vv;
	vv.x = x1;
	vv.y = y1;
	qq.push(vv);
	yy[x1][y1] = 0;
	while(!qq.empty())
	{
		vv = qq.front();
		qq.pop();
		int x0 = vv.x;
		int y0 = vv.y;
		for(int i = 0; i < 4 ; i++)
		{
			int xt = x0 + dir[i][0];
			int yt = y0 + dir[i][1];
			if(check(xt,yt) && xx[xt][yt] == xx[x0][y0] && yy[xt][yt] == -1)
			{
				yy[xt][yt] = yy[x0][y0] + 1;
				vv.x = xt;
				vv.y = yt;
				qq.push(vv);
			}
 		}
	}
}
int main()
{
	while(~scanf("%d %d",&n,&m))
	{
		memset(yy, -1,sizeof(yy));
		if(n == 0 || m == 0) break;
		for(int i = 0; i < n; i++)
		{
			scanf("%s",xx[i]);
		}
		pl = 0;
		for(int i = 0; i< n; i++)
		{
			for(int j = 0; j < m; j++)
			{
				if(yy[i][j] == -1)
				{
					bfs(i,j);	
					pl ++;
				}
			}
		}
		printf("%d\n",pl);
	}
}

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

#define      ll     long long int

int main()
{
    int n, i, j;
    set<int> st;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> j;
        st.insert(j);
    }
    cout << (int) st.size() << '\n';
    return 0;
}



Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut s: String = read();
    for i in (0..s.len()).rev() {
        if i % 2 == 1 {
            s.remove(i);
        }
    }

    println!("{}", s);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define SpeeD ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define endl '\n'
//pair<int, int> *p=new pair<int, int>[n];
//std::vector<pair<int,int>> vp;
//v.push_back(make_pair(x,y))
//pair<int, int> p[1000001];
//string *s=new string [n];
//int freq[e];
//freq[a[i]-'a']++; freq[a[i]]++;
 using namespace std;
ll n,t,m,c1,c2,c,x,y,sum,mn=999999999,avg,pos,dif,j,dis,mx,xi,yi,q;
vector<ll>v;
set<string>s;
map<string , ll >mp;
bool PE(int x)
{
for (int i=2;i*i<=x;i++)
if (x%i==0)
return false;
return true;
}
bool PR(string s)
{
int n=s.length();
for(int i=0;i<n/2;i++)
if(s[i]!=s[n-i-1])
return false;
return true;
}

int main(void)
{ SpeeD;
string s;
cin>>s;
string t;
cin>>t;
for (int i = 0 ;i < s.length();i++)
if (s[i]!=t[i]){
cout<<"No";
return 0;}
cout<<"Yes";

}



Measured memory_bytes: 3644
/*      Welcome to my Code      */
 
#include <bits/stdc++.h>
#define ll                      long long int
#define i(a,n)                  int a=n;
#define l(a,n)                  ll a=n;
#define d(a,n)                  double a=n;
#define s(a)                    string a;
#define c(a)                    ll a; cin>>a;a
#define cd(a)                   double a; cin>>a;
#define cs(a)                   string a; cin>>a;
#define ci(a)                   cin>>a
#define co(a)                   cout<<a
#define cos(a)                  cout<<a<<" "
#define con(a)                  cout<<a<<endl
#define yes                     cout<<"YES"<<endl
#define no                      cout<<"NO"<<endl
#define nl                      cout<<endl
#define ca(arr,n)               for(ll i=0;i<n;i++) cin>>arr[i]
#define caa(arr,n)              c(n); ll arr[n]; for(ll i=0;i<n;i++) cin>>arr[i];
#define f0(i,a,n)               for(ll i=a;i>=n;i--)
#define f(i,n)                  for(ll i=0;i<n;i++)
#define f1(i,a,n)               for(ll i=a;i<n;i++)
#define lcm(a,b)                (a*b)/__gcd(a,b)
#define T                       ll t=1; cin>>t; while(t--)
#define sr(a,n)                 sort(a,a+n)
#define rv(a,n)                 reverse(a,a+n)
#define fast                    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ret(x)                  return cout<<x,0;
 
using namespace std;
 
int main()
{
    fast;
    string s;
    cin>>s;
    ll sum=0;
    f(i,s.length()) sum+=(s[i]-'0');
    if(sum%9==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}
 
/*It's not who I am underneath, but what I do that defines me
 
MMMMMMMMMMMMMMMMMMMMM.                             MMMMMMMMMMMMMMMMMMMMM
 `MMMMMMMMMMMMMMMMMMMM           M\  /M           MMMMMMMMMMMMMMMMMMMM'
   `MMMMMMMMMMMMMMMMMMM          MMMMMM          MMMMMMMMMMMMMMMMMMM'
     MMMMMMMMMMMMMMMMMMM-_______MMMMMMMM_______-MMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
      MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
     .MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM.
    MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
                   `MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM'
                          `MMMMMMMMMMMMMMMMMM'
                              `MMMMMMMMMM'
                                 MMMMMM
                                  MMMM
                                   MM
*/

Measured memory_bytes: 3732
from itertools import permutations

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

def count(x):
    i = 0
    for perm in permutations(range(1, n+1)):
        if perm == x:
            return i
        i += 1

print(abs(count(p) - count(q)))


Measured memory_bytes: 3060
import numpy as np

W, H, N = map(int, input().split())
l = np.zeros((H,W))

for i in range(N):
  x, y, a = map(int, input().split())
  if a==1:
    l[:,:x] = 1
  elif a==2:
    l[:,x:] = 1
  elif a==3:
    l[:y,:] = 1
  elif a==4:
    l[y:,:] = 1
    
print(H*W-int(l.sum().sum()))


Measured memory_bytes: 12504
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
const ll mod = 1e9 + 7;
map<int, ll>dp[N];
int n;
ll a[N];
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)scanf("%lld", &a[i]);
	dp[1][1] = a[1]; dp[1][0] = 0;
	dp[2][0] = 0; dp[2][1] = max(a[1], a[2]);
	for (int i = 3; i <= n; i++) {
		int L = n / 2 - (int)ceil(0.5*(n - i + 1)), R = (int)ceil(0.5*i);
		for (int j = L; j <= R; j++) {
			if (dp[i - 1].count(j) && !dp[i - 2].count(j - 1))continue;
			else if (dp[i - 1].count(j) && !dp[i - 2].count(j - 1))dp[i][j] = dp[i - 1][j];
			else if (dp[i - 2].count(j - 1) && !dp[i - 1].count(j))dp[i][j] = dp[i - 2][j - 1] + a[i];
			else dp[i][j] = max(dp[i - 1][j], dp[i - 2][j - 1] + a[i]);
		}
	}
	printf("%lld\n", dp[n][n / 2]);
	return 0;
}

Measured memory_bytes: 39744
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,h;
    cin>>n>>h;
    int t[n];
    int at=0;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        at=max(at,a);
        t[i]=b;
    }
    sort(t,t+n);
    reverse(t,t+n);
    for(int i=0;i<n;i++){
        if(at>t[i]){cout<<(h-1)/at+1+i<<endl;return 0;}
        h-=t[i];
        if(h<=0){cout<<i+1<<endl;return 0;}
    }
    cout<<(h-1)/at+1+n<<endl;
}


Measured memory_bytes: 640
gets.to_i.times do
  a,b,c,d = gets.chomp.split(" ").map(&:to_i)
  f = true
  if a >= b && b <= d
    a %= b
    d %= b
    g = b.gcd(d)
    maxb = b-g+a%g
    if c < maxb
      puts "No"
    else
      puts "Yes"
    end
  else
    puts "No"
  end
end

Measured memory_bytes: 1916
//#pragma GCC optimize "trapv"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand rng
#define fios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define M_PI 3.14159265358979323846
typedef long long ll;



int main() {
	//fios;
	int k;
	cin >> k;
	for(int i = 0; i < k; i++) {
		cout << "ACL";
	}
	cout << endl;

}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main(){
        long long a,b,c,d;
        long long ans1,ans2,ans3,ans4;
        long long max;
  		cin >> a >> b >> c >> d;

        ans1 = a * c;
        ans2 = a * d;
        ans3 = b * c;
        ans4 = b * d;
		max = -9223372036854775807;
        if(max < ans1){
                max = ans1;
        }
        if(max < ans2){
                max = ans2;
        }
        if(max < ans3){
                max = ans3;
        }
        if(max < ans4){
                max = ans4;
        }
  		cout << max;
        return 0;
}

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

#define endl "\n"
#define long long long

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

    long int n,a,b;
    cin>>n>>a>>b;

    cout<<min(n*a,b);

    return 0;
}


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

int main(){
  ll x, p=100, cnt=0;
  cin >> x;

  while(p<x){
    p+=p/100;
    cnt++;
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 3588
#include <iostream> pre processor directive
#include <string>
#include <iomanip>
using namespace std;
int main()
{
 int N,H;
 cin>>H>>N;
 int Arr[N];
 for (int i=0;i<N;i++){
    cin>>Arr[i];
 }
 int sum=0;
 for (int i=0;i<N;i++){
    sum+=Arr[i];
 }
 if (sum>=H){
    cout<<"Yes"<<endl;
 }else{
    cout<<"No"<<endl;
 }
}



Measured memory_bytes: 640
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		try(Scanner scan = new Scanner(System.in);){
			int N = Integer.parseInt(scan.next());
			int a = Integer.parseInt(scan.next());
			int b = Integer.parseInt(scan.next());
			int sum = 0;
			for(int i=1; i<=N; i++) {
				int tmpSum = 0;
				int num = i;
				while(num != 0) {
					tmpSum += num %10;
					num /= 10;
				}
				if(tmpSum >= a && tmpSum <= b) {
					sum += i;
				}
			}
          System.out.println(sum);
		}
	}
}

Measured memory_bytes: 23764
def solve(s, count, i, p):
    if count == 3:
        p = list(p.split(":"))
        if int(p[0]) + int(p[1]) > int(p[2]) and int(p[1]) + int(p[2]) > int(p[0]) and int(p[0]) + int(p[2]) > int(p[1]) :
            return 1
        else:
            return 0

    if i == len(s):
        return 0

    if s[i] in p:
        return solve(s, count, i + 1, p)
    else:
        return solve(s, count + 1, i + 1, p + s[i] + ":") + solve(s, count, i + 1, p)


n = int(input())
l = list(input().strip().split(" "))
q = ""
print(solve(l, 0, 0, q))


Measured memory_bytes: 76840
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	string s, t;
	cin >> s >> t;
	vi p[30];
	rep(i, s.size()) p[s[i] - 'a'].pb(i);
	rep(i, t.size()) if(!p[t[i] - 'a'].size()){
		cout << -1 << endl;
		return 0;
	}
	ll ans = 0;
	int pos = -1;
	rep(i, t.size()){
		int ps = lb(all(p[t[i] - 'a']), pos + 1) - p[t[i] - 'a'].begin();
		if(ps == (p[t[i] - 'a'].size()) || p[t[i] - 'a'][ps] <= pos){
			ans += (s.size() - pos) + (p[t[i] - 'a'][0]);
			pos = p[t[i] - 'a'][0];
		}
		else{
			ans += p[t[i] - 'a'][ps] - pos;
			pos = p[t[i] - 'a'][ps];
		}
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

int main()
{
   int N;
   unsigned int A[200] = {0};
   int temp = 0;

   cin >> N;

   for (int i=0;i<N;i++) cin >> A[i];

   for (int j=1;j<31;j++)
   {
      int bin = pow(2,j);
      for (int i=0;i<N;i++)
      {
         if (A[i] % bin == 0) continue;
         else
         {
             temp = j;
             break;
         }
      }
      if (temp!=0) break;
   }

   cout << temp-1 << endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    int cnt = 0;
    while(A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
        cnt++;
        int nxtA = B / 2 + C / 2;
        int nxtB = C / 2 + A / 2;
        int nxtC = A / 2 + B / 2;
        if(A == nxtA && B == nxtB && C == nxtC) {
            cout << -1 << endl;
            return 0;
        }
        A = nxtA; B = nxtB; C = nxtC;
    }
    cout << cnt <<endl;

    return 0;
}


Measured memory_bytes: 256
a,b,k = gets.chomp.split(" ")
a = a.to_i
b = b.to_i
k = k.to_i
if k<=a then
  a -= k
elsif k<= a + b then
  b = b - (k-a)
  a = 0
else
  a = 0
  b = 0
end
print(a)
print(" ")
puts(b)

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

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		Runner[] a = new Runner[18];
		int cnt=0;
		for(int  j = 0;j<3;j++){
			Runner[] b = new Runner[8];
			for(int i = 0;i<8;i++){
				int num = cin.nextInt();
				double time= cin.nextDouble();
				b[i]=new Runner(num,time);
			}
			Arrays.sort(b);
			for(int i = 0;i<6;i++){
				a[cnt++]=b[i+2];
			}
			System.out.println(b[0].num + " " + b[0].timestr);
			System.out.println(b[1].num + " " + b[1].timestr);
		}
		Arrays.sort(a);
		System.out.println(a[0].num + " " + a[0].timestr);
		System.out.println(a[1].num + " " + a[1].timestr);
	}
}
class Runner implements Comparable{
	int num;
	double time;
	String timestr;
	Runner(int a,double b){
		num=a;
		time=b;
		timestr=String.valueOf(time);
		if(timestr.length()==4){
			timestr = timestr+"0";
		}
		
	}
	public int compareTo(Object o) {
		Runner r = (Runner)o;
		if(this.time-r.time > 0)
			return 1;
		else if(this.time-r.time == 0)
			return 0;
		else{
			return -1;
		}
	}
}

Measured memory_bytes: 12000
Alist = list(map(int,input().split()))
p = [0,0,0,0,0,0]
p[0] = abs(Alist[0] - Alist[1]) + abs(Alist[1] - Alist[2])
p[1] = abs(Alist[0] - Alist[2])+ abs(Alist[1] - Alist[2])
p[2] = abs(Alist[1] - Alist[2])+ abs(Alist[0] - Alist[2])
p[3] = abs(Alist[1] - Alist[0])+ abs(Alist[0] - Alist[2])
p[4] = abs(Alist[0] - Alist[2])+ abs(Alist[1] - Alist[0])
p[5] = abs(Alist[2] - Alist[1])+ abs(Alist[1] - Alist[0])
print(min(p))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int x,n;
  set<int> st;
  cin>>x>>n;
  for (int i = 0; i < n; ++i)
  {
    int tmp;
    cin>>tmp;
    st.insert(tmp);
  }
  int i=0;
  while(true)
  {
    int y=x-i;
    if(st.find(y)==st.end())
    {
      cout<<y<<endl;
      return 0;
    }
    y=x+i;
    if(st.find(y)==st.end())
    {
      cout<<y<<endl;
      return 0;
    }
    i++;
  }
}

Measured memory_bytes: 3632
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int[] a = new int[M];
		int[] b = new int[M];
		int[] c = new int[M];
		for (int i=0;i<M;i++) {
			a[i] = Integer.parseInt(sc.next())-1;
			b[i] = Integer.parseInt(sc.next())-1;
			c[i] = -Integer.parseInt(sc.next());
		}

		long[] dist = new long[N];
		for (int i=1;i<N;i++) {
			dist[i] = Long.MAX_VALUE;
		}
		boolean flag = true;
		int ans_flag = 0;
		int cnt = 0;
		long ans_tmp=0;
		while (flag) {
			flag = false;
			for (int i=0;i<M;i++) {
				if (dist[a[i]] != Long.MAX_VALUE && dist[b[i]] > dist[a[i]] + c[i]) {
					dist[b[i]] = dist[a[i]] + c[i];
					flag = true;
				}
			}
			if (cnt==N-1) {
				ans_tmp = dist[N-1];
			}
			if (cnt==2*N) {
				if (dist[N-1]<ans_tmp) {
					ans_flag = 1;
				}
				break;
			}
			cnt++;
		}
		if (ans_flag == 0) {
			System.out.println(-dist[N-1]);
		} else if (ans_flag == 1) {
			System.out.println("inf");
		}
	}
}

Measured memory_bytes: 26076
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> A;
    for(int i=0; i<2*N; i++)
    {
    	int a;
    	cin >> a;
    	A.push_back(a);
    }

    vector<int> num;

    for(int i=0; i<N; i++)
    {
    	int x = 0;
        for(int j=0; j<2*N; j++)
        {
        	if(j<=i || j>=N+i) x+=A[j]; 
        }
        num.push_back(x);
    }

    int M = *max_element(num.begin(), num.end());
    cout << M << endl;
	return 0;
}

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

using namespace std;
typedef long long int ll;

#define debug(val) "[ " << #val " : " << (val)
#define space " "
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vector<ll>>
#define vii vector<vector<int>>
#define PI (double)(atan(1)*4)
#define pb push_back
#define pi pair<int , int >
#define ff first
#define ss second
#define INF 2000000000
vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};
const int Mod = 1000 * 1000 * 1000 + 7;
const int maxN = 100000 * 5 + 3;
vi  last(maxN), a(maxN);
int n;

struct Query {
    int l, r, idx;
    bool operator<(Query const &other) {
        return r < other.r;
    }
};
struct Fenwick{
    vector<int> fen;
    int n ;
    Fenwick(int n ){
        this->n = n ;
        fen.assign(n+1 , 0 ) ;
    }
    int sum(int l) {
        int res = 0;
        while (l > 0) {
            res += fen[l];
            l -= (l & (-l));
        }
        return res;
    }

    int range_sum(int l, int r) {
        return sum(r) - sum(l - 1);
    }

    void update(int l, int delta) {
        while (l <= n) {
            fen[l] += delta;
            l += l & (-l);
        }
    }

};


void solve() {
    int q;
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    last.assign(n+1 , -1 ) ;
    vector<Query> queries;
    vector<int> res(q);
    Fenwick fen(n+1) ;
    for (int i = 0; i < q; i++) {
        int L, R;
        cin >> L >> R;
        queries.pb({L , R , i });
    }
    sort(queries.begin(), queries.end());
    int ptr = 1;
    for (int i = 0; i < q; i++) {
        int l = queries[i].l, r = queries[i].r;
        int q_idx = queries[i].idx;
        for (int j = ptr; j <= r; j++) {
            int val = a[j];
            if (last[val] != -1) {
                fen.update(last[val], -1);
            }
            ptr = r;
            last[val] = j;
            fen.update(last[val], 1);
        }
        //   cout << "Solution of " << l << space << r << " is " << space;
        res[q_idx] = fen.range_sum(l, r);
    }
    for (int v : res) {
        cout << v << endl;
    }
}


int main() {
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0); // FAST IO
    int q = 1;
    //cin >> q;
    for (int i = 1; i <= q; i++) {
        solve();
    }
}

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

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc=new Scanner(System.in);

		//整数ABC
		int[] suu=new int[3];
		suu[0]=sc.nextInt();
		suu[1]=sc.nextInt();
		suu[2]=sc.nextInt();
		Arrays.sort(suu);
		int count=0;

		while(suu[0]!=suu[1]||suu[0]!=suu[2]||suu[1]!=suu[2]) {
			Arrays.parallelSort(suu);
			if(suu[2]-suu[0]>=2&&suu[2]-suu[1]<2) {
				suu[0]+=2;
				count++;
			}else {
				suu[0]+=1;
				suu[1]+=1;
				count++;
			}
		}
		
		System.out.println(count);

	}

}

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

using namespace std;
typedef long long ll;
long long mod = 1000000007;
const int INF = 1001001001;

int main(){
  int x;
  cin >> x;
  set<int> s;
  set<int> s2;
  for(int i=2;i<110000;i++){
    s.insert(i);
  }
  while(s.size()){
    int val = *begin(s);
    s2.insert(val);
    s.erase(val);
    int val2 = val;
    while(val<110000){
      val += val2;
      if(s.count(val)) s.erase(val);
    }
  }
  auto it = lower_bound(s2.begin(),s2.end(),x);
  cout << *it << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/math/special_functions/prime.hpp>

using namespace std;
using namespace boost;

using ll = long long;

int main() {
    bitset<100001> b;
    for (auto &&i: boost::irange(0U, boost::math::max_prime)) {
        unsigned int target{boost::math::prime(i)};
        for (auto &&j: boost::irange(0U, i)) {
            if (boost::math::prime(j) > (target + 1) / 2)break;
            if (target % 2 == 1 && (target + 1) / 2 == boost::math::prime(j) && target <= 100000)b[boost::math::prime(i)]=true;
        }
    }
    vector<ll> v(100001, 0);
    for (auto &&i: boost::irange(1LL, 100001LL)){
        v.at(i) = v.at(i-1) + b[i];
    }

    ll q;
    cin >> q;
    for (auto &&i: boost::irange(0LL, q)){
        ll l, r;
        cin >> l >> r;
        cout << v.at(r) - v.at(l-1) << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
N = int(input())
nums = list(map(int, input().split()))
INF = 10**10
dp = [INF] * (N)
dp[0] = 0
dp[1] = abs(nums[1]-nums[0])
for i in range(2, N):
  dp[i] = min(dp[i-2]+abs(nums[i]-nums[i-2]), dp[i-1]+abs(nums[i]-nums[i-1]))
print(dp[N-1])


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-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; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    string s;
    cin >> s;

    rep(i, s.size()) {
        if (i % 2 == 0) cout << s[i];
    }

    cout << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mxe max_element
#define mne min_element
#define bg begin()
#define nd end()

void swap(int &a,int &b)
{
    int t=a;
    a=b;
    b=t;
    return ;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll t,n,m;
    
    cin>>n;
    
    cout<<(n+(n*n)+(n*n*n))<<"\n";

    
    
    
    return 0;
}
 
 
 
 
 




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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n;
int q[N];

int main()
{
	scanf("%d", &n);
	
	int cnt = 0;
	for (int i = 1; i <= n; i ++ )
	{
		int x;
		scanf("%d", &x);
		
		int l = 1, r = cnt;
		while (l < r)
		{
			int mid = l + r >> 1;
			if (q[mid] < x) r = mid;
			else l = mid + 1;
		}
		
		if (!cnt || q[r] >= x) q[ ++ cnt] = x;
		else q[r] = x;
	}
	
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
using namespace std;
int main (){
  int A,B,K,X;
  X=0;
  cin >> A >> B >> K;
  for (int i=0;i<K;i++){
    if (X==0){
      X=1;
      if (A%2==1){A--;}
      A/=2;B+=A;
    }else{
      X=0;
      if (B%2==1){B--;}
      B/=2;A+=B;
    }
  }
  cout << A<<" "<<B<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
struct Warehouse {
	int id, position, count;
};
long long int min_cost(const int state, const int current, const long long int weight, const std::vector<Warehouse>& warehouses, std::vector<std::vector<long long int>>& memo) {
	if (state == memo.size() - 1) return 0;
	if (memo[state][current] >= 0) return memo[state][current];
	long long int min_time = LLONG_MAX;
	for (auto i = 0; i < warehouses.size(); ++i) if ((state & (1 << i)) == 0) {
		min_time = std::min(min_time, min_cost(state | (1 << i), i, weight + warehouses[i].count * 20, warehouses, memo) + std::abs(warehouses[current].position - warehouses[i].position) * weight);
	}
	return memo[state][current] = min_time;
}
std::vector<int> cal_min_route(const std::vector<Warehouse>& warehouse) {
	std::vector<std::vector<long long int>> memo(1 << warehouse.size(), std::vector<long long int>(warehouse.size(), -1));
	std::vector<int> result; result.reserve(warehouse.size());
	int state = 0;
	long long int default_weight = 70;
	int current_pos = 0;
	for (auto _i = 0; _i < warehouse.size(); ++_i) {
		long long int min = LLONG_MAX;
		int min_pos = 0;
		for (auto i = 0; i < warehouse.size(); ++i) if ((state & (1 << i)) == 0) {
			const auto temp = min_cost(state | (1 << i), i, default_weight + warehouse[i].count * 20, warehouse, memo) + (result.empty() ? 0.0 : (std::abs(current_pos - warehouse[i].position) * default_weight));
			if (min > temp) {
				min = temp;
				min_pos = i;
			}
		}
		result.push_back(warehouse[min_pos].id);
		state |= 1 << min_pos;
		default_weight += warehouse[min_pos].count * 20;
		current_pos = warehouse[min_pos].position;
	}
	return result;
}
int main() {
	int n; std::cin >> n;
	std::vector<Warehouse> warehourse(n); for (auto& w : warehourse) std::cin >> w.id >> w.position >> w.count;
	auto result = cal_min_route(warehourse);
	for (auto i = 0; i < n; ++i) {
		if (i != 0) std::cout << ' ';
		std::cout << result[i];
	}
	std::cout << '\n';
}


Measured memory_bytes: 7528
#include <bits/stdc++.h>
using namespace std;
int a, b, c;
int main() {
    cin >> a >> b >> c;
    int kind = 0;
    if(a != b) {
        kind++;
    }
    if(b != c) {
        kind++;
    }
    if(a != c) {
        kind++;
    }
    if(a == b && b == c) {
        cout << 1 << endl;
        return 0;
    }

    cout << kind << endl;
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

ll K;

ll f(vector<int> g,bool x){
  ll ans = 1LL;
  if(x){
    for(ll i = 0LL; i < (ll)g.size();i++){
      ans=(ans*(K-i-1LL))%mod;
    }
  }
  if(!x){
    for(ll i = 0; i < (ll)g.size();i++){
      ans=(ans*(K-i-2LL))%mod;
    }
  }
  return ans;
}

int main() {
  ll N;
  cin>>N>>K;
  vector<vector<int>> g(N);
  for(int i = 0; i < N-1; i++) {
    int x,y;
    cin>>x>>y;
    g[x-1].push_back(y-1);
    g[y-1].push_back(x-1);
  }
  queue<int> q;
  vector<bool> seen(N,false);
  q.push(0);
  seen[0]=true;
  vector<int>parent(N,-1),dep(N,0);
  vector<vector<int>> child(N);
  int d = 0;
  while(!q.empty()){
    d++;
    int t= q.front();
    q.pop();
    for(auto nx:g[t]){
      if(seen[nx]) continue;
      seen[nx]=true;
      q.push(nx);
      child[t].push_back(nx);
      parent[nx]=t;
      dep[nx]=d;
    }
  }
  queue<int> bfs;
  ll ans = K;
  bfs.push(0);
  while(!bfs.empty()){
    int t = bfs.front();
    bfs.pop();
    ans=(ans*f(child[t],(dep[t]<1)))%mod;
    for(auto x:child[t]){
      bfs.push(x);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 12032
fun main(args: Array<String>) {
    val n = readLine()!!.split(" ").map { it.toInt() }[0]
    val p = readLine()!!.split(" ").map { it.toInt() }
    var ans = 0
    for(i in 0 until n-2){
        if (p[i] < p[i+1] && p[i+1] < p[i+2]) ans++
        else if (p[i] > p[i+1] && p[i+1] > p[i+2]) ans++
    }
    println(ans)
}

Measured memory_bytes: 37904
N, M = map(int,input().split())
s_c = [list(map(int, input().split())) for i in range(M)]
X = [-1]*N
for i in range(M):
    X[s_c[i][0] - 1] = s_c[i][1]
x = True
for i in range(N):
    u = True
    for j in range(M):
        if s_c[j][0] - 1 == i:
            u = False
            break
    if u:
        if i == 0 and N >= 2:
            X[i] = 1
        else:
            X[i] = 0
for i in range(M):
    if s_c[i][0] == 1 and s_c[i][1] == 0 and N != 1:
        x = False
        break
if M >= 2:
  for i in range(M):
     for j in range(i+1,M):
        if s_c[i][0] == s_c[j][0]:
            if s_c[i][1] != s_c[j][1]:
                x = False
if x:
    for i in range(N):
        print(X[i], end= "")
    print()
else:
    print(-1)



    

    

Measured memory_bytes: 3064
D,N=map(int,input().split())
if D==0:
    if N==100:
        print(101)
    else:
	    print(N)
elif D==1:
    if N==100:
        print(10100)
    else:
	    print(100*N)
elif D==2:
    if N==100:
        print(1010000)
    else:
	    print(10000*N)

Measured memory_bytes: 3060