akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
int n,k;
vector<int> w(n);

bool ok(int x){
    int res = 0;
    int c = 0;
    rep(i,n){
        if(w[i] > x) return false;
        if(res + w[i] > x){
            res = w[i];
            ++c;
        }else{
            res += w[i];
        }
    }
    if(res > 0) c++;
    return c <= k;
}

int main(){
    cin >> n >> k;
    w.resize(n);
    rep(i,n) cin >> w[i];
    int left = 0,right = INF+10;
    while(right - left > 1){
        int mid = (right + left)/2;
        if(ok(mid)) right = mid;
        else left = mid;
    }
    cout << right << endl;
    return 0;
}


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

int  main()
{
	int a,b; cin >> a >> b;
	if (a >= 13)
		cout << b << endl;
	else if (a <= 12 && a >= 6)
		cout << b/2 << endl;
	else
		cout << 0 << endl;
	return (0);
}


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

const int INF = 1 << 25;

int main() {
    int N, S;
    std::cin >> N >> S;
    std::vector<int> A(N);
    for (auto& a : A) std::cin >> a;

    int sum = 0, r = 0;  // sum = A[l]+...+A[r-1]
    int ans = INF;
    for (int l = 0; l < N; ++l) {
        while (r < N && sum < S) {
            sum += A[r];
            ++r;
        }
        if (sum >= S) ans = std::min(ans, r - l);
        sum -= A[l];
    }
    std::cout << (ans == INF ? 0 : ans) << std::endl;
    return 0;
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  lol n, p, memo, ans = 1;
  cin >> n >> p;
  map<int, int> PrimeCount;
  if(n == 1) {
    ans *= p;
  } else {
    memo = p;
    while(memo % 2 == 0){
      PrimeCount[2] ++;
      memo /= 2;
    }
    ans *= pow(2, PrimeCount[2] / n);
    for(lol i = 3;i * i <= p;i += 2){
      while(memo % i == 0){
	PrimeCount[i] ++;
	memo /= i;
      }
      ans *= pow(i, (PrimeCount[i] / n));
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 23680
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  ll ans=0,sum=0;
  map<ll,ll> m;
  m[0]=1;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    sum+=a;
    if(m.find(sum)==m.end()) m[sum]=1;
    else{
      ans+=m[sum];
      m[sum]++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 12800
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

int A,B,Q;
ll INF = 100000000000;
ll MINF = -100000000000;
int main() {
    cin >> A >> B >> Q;
    vector<ll> T(A+2), Z(B+2);
    T[0] = Z[0] = MINF;
    for(int i=1;i<=A;i++){
        cin >> T[i];
    }
    T[A+1] = INF;
    for(int i=1;i<=B;i++){
        cin >> Z[i];
    }
    Z[B+1] = INF;
    for(int i=0;i<Q;i++){
        ll query;
        cin >> query;
        int tm = distance(T.begin(), upper_bound(T.begin(), T.end(), query));
        int zm = distance(Z.begin(), upper_bound(Z.begin(), Z.end(), query));
// printf("%d,%d,%lld,%lld,%lld,%lld\n", tm, zm ,T[tm], T[tm-1],Z[zm], Z[zm-1]);
        ll a = query - min(T[tm-1], Z[zm-1]);
        ll b = max(T[tm],Z[zm]) - query;
        ll c = (ll)abs(Z[zm] - T[tm-1]) + (ll)min(abs(query - Z[zm-1]), abs(T[tm] - query));
        ll d = (ll)abs(Z[zm] - T[tm-1]) + (ll)min(abs(query - T[tm-1]), abs(Z[zm] - query));
        ll e = (ll)abs(T[tm] - Z[zm-1]) + (ll)min(abs(query - T[tm-1]), abs(Z[zm] - query));
        ll f = (ll)abs(T[tm] - Z[zm-1]) + (ll)min(abs(query - Z[zm-1]), abs(T[tm] - query));
// printf("%lld,%lld,%lld,%lld,%lld,%lld\n", a,b,c,d,e,f);
        ll answer = min(
            min(
                min(a,b),
                min(c,d)
            ),
            min(e,f)
        );
        cout << answer << endl;
    }
}


Measured memory_bytes: 2944
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  if n == 0
    then return ()
    else do
      ls <- replicateM n readLn
      mapM_ putStrLn (solve ls)
      main

solve :: [Int] -> [String]
solve ls = toGraph (update (replicate 10 0) ls)
  where
    toGraph :: [Int] -> [String]
    toGraph = map toAst
      where
        toAst :: Int -> String
        toAst 0 = "-"
        toAst n = replicate n '*'
        
    update :: [Int] -> [Int] -> [Int]
    update counter [] = counter
    update counter (x:xs) = update (plus x counter) xs
      where
        plus :: Int -> [Int] -> [Int]
        plus 0 (x:xs) = (x+1):xs
        plus n (x:xs) = x:(plus (n-1) xs)
        

Measured memory_bytes: 7048
#include <stdio.h>

int main(){
  int i,j,n,k;
  int a[100000];
  int sum,ans;

  while(1){
    sum = ans = 0;

    scanf("%d%d" ,&n ,&k);
    if(n == 0 && k == 0) break;


    for(i = 0 ; i < n ; i++){
      scanf("%d" ,a + i);
    }
    
    for(i = 0 ; i < k ; i++){
      sum += a[i];
    }
    
    ans = sum;
    
    for(j = 0 ; j < n - k ; j++){
      sum -= a[j];
      sum += a[j+k];
      if(ans < sum) ans = sum;
    }
    
    printf("%d\n" ,ans);
  }

  return 0;
}

Measured memory_bytes: 992
import sys

def print_arr(arr):
	for i in range(len(arr)):
		sys.stdout.write(str(arr[i]))
		if i != len(arr) - 1:
			sys.stdout.write(' ')
	print()

def insertion_sort(arr, g):
	n = len(arr)
	cnt = 0
	for i in range(n):
		key = arr[i]
		j = i - g
		while j >= 0 and arr[j] > key:
			arr[j + g] = arr[j]
			j -= g
			cnt += 1
		arr[j + g] = key
	return cnt

def shell_sort(arr, G):
	cnt = 0
	for i in range(len(G)):
		cnt += insertion_sort(arr, G[i])
	return cnt

def get_gaps(n):
	lst = []
	v = 1
	cnt = 1
	while v <= n:
		lst.append(v)
		v += 3**cnt
		cnt += 1
	if len(lst) == 0: lst.append(1)
	return list(reversed(lst))

n = int(input())
arr = [None] * n
for i in range(n):
	arr[i] = int(input())

G = get_gaps(n)
cnt = shell_sort(arr, G)

print(len(G))
print_arr(G)
print(cnt)
for i in range(n):
	print(arr[i])



Measured memory_bytes: 45480
#include<cstdio>
#include<algorithm>
using namespace std;
int f[26],t[26],n,maxn,k;
char s[102];
int main()
{
	scanf("%d",&n);
	scanf("%s",s);
	for (int i=0;i<n;i++) f[s[i]-'a']++;
	for (int i=0;i<n-1;i++)
	{
		t[s[i]-'a']++;
		if (t[s[i]-'a']==1 && f[s[i]-'a']>1) k++;
		if (t[s[i]-'a']==f[s[i]-'a'] && f[s[i]-'a']>1) k--;
		maxn=max(maxn,k);
	}
	printf("%d",maxn);
	return 0;
}

Measured memory_bytes: 128
import queue

N = int(input())
l = [int(x) for x in input().split()]
l.sort(reverse=True)
ans = 0
room = queue.Queue()
room.put(l[0])
for i in range(1, N):
    ans += room.get()
    room.put(l[i])
    room.put(l[i])
print(ans)

Measured memory_bytes: 32012
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll max_n = 1200000;  //ここはとりあえず大きく取っておいた方が良い 1200000じゃダメだった
const ll mod = 1000000007;
vector<ll> fac(max_n);
vector<ll> ifac(max_n);

ll mpow(ll x, ll n){
    ll ans = 1;
    while(n){
        if(n % 2){
            ans = ans * x % mod;
        }
        x = x * x % mod;
        n >>= 1;
    }
    return ans;
}

ll comb(ll a, ll b){
    if(a == 0 && b == 0) return 1;
    if(a < 0 || b < 0) return 0;
    if(a < b) return 0;
    ll tmp = ifac[b] * ifac[a-b] % mod;
    return tmp * fac[a] % mod;
}



int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    ll X, Y;cin>>X>>Y;
    if((X+Y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }
    if(X > 2* Y || X*2 < Y){
        cout<<0<<endl;
        return 0;
    }

    ll a = (2 * Y - X) / 3;
    ll b = (2 * X - Y) / 3;

    //ll N = X+Y;  //ここを変えたらコンパイルエラーが出なくなった
    ll N = a+b+10;
    fac[0] = 1;
    ifac[0] = 1;
    REP(i,N){
        fac[i+1] = fac[i] * (i+1) % mod; // fac[i] = n! % mod;
        ifac[i+1] = ifac[i] * mpow(i+1,mod-2) % mod; // ifac[i] = (i!) * pow(i, mod-2) % mod;
    }

    cout << comb(a+b,a) << endl;

}

Measured memory_bytes: 19072
s = input()
for i in range(len(s)-1):
  if s[i] == s[i+1]:
    print(i+1,i+2)
    exit()
  elif i <= len(s)-3:
    if s[i] == s[i+2]:
      print(i+1,i+3)
      exit()
print(-1,-1)

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

#define ll long long
string s;
map<char,int> m;
bool diff = true;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>s;
	for(int i=0;i<s.size();i++){
		m[s[i]]++;
		if(m[s[i]] > 1){
			diff = false;
			break;
		}
	}
	if(diff)
		cout<<"yes";
	else
		cout<<"no";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,M;
  cin>>N>>M;
  vector<long long> l(M);
  vector<long long> r(M);
  for(long long i=0;i<M;i++)
    cin>>l.at(i)>>r.at(i);
  sort(l.begin(),l.end());
  sort(r.begin(),r.end());
  long long a=r.at(0)-l.at(M-1)+1;
  if(a>0)
  cout<<a<<endl;
  else
    cout<<0<<endl;
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;	// 人数
  int K;	// 制限身長
  int i;
  int entryCount = 0;
  
  cin >> N;
  cin >> K;
  
  int h[N];
  
  for(i = 0; i < N; i++){
    cin >> h[i];
    if(h[i] >= K){
      entryCount++;
    }
  }
  
  cout << entryCount << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int main()
{
	string a;
	cin>>a;
	if(a[0]!='A')
	{
		cout<<"WA";
		return 0;	
	}
	int t=0;
	for(int i=2;i<a.size()-1;i++)
	{
		if(a[i]=='C')
		{
			t++;
		}
	}
	if(t!=1)
	{
		cout<<"WA";
		return 0;		
	}
	for(int i=0;i<a.size();i++)
	{
		if((a[i]!='A'||i!=0)&&(a[i]!='C'||(i<2||i==a.size()-1)))
		{
			if(a[i]>='A'&&a[i]<='Z')
			{
				cout<<"WA";
				return 0;
			}
		}
	}
	cout<<"AC";
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

void solve() {
  int a, b;
  cin >> a >> b;
  if(a <= 5) b = 0;
  if(a <= 12) b /= 2;
  cout << b << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

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

    ll l,r;
    cin >> l >> r;
    ll ans = inf;
    if((r-l)<2019){
        for(ll i=l;i<r;i++){
            for(ll j=i+1;j<=r;j++){ 
                ll a = ((i%2019)*(j%2019))%2019;
                ans = min(ans,a);
            }
        }
    }else{
        ans = 0;
    }
    cout << ans << endl;
    return 0;

}

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

#define EPS (1e-5)

double P, E, T;
double TR, TL;

double solve(int K, double R, double L){
  double M = (R + L) / 2;

  if(K == 0) return (TR < M && M < TL ? 1 : 0);
  if(TR < R && L < TL) return 1;
  if(L < TR || TL < R) return 0;

  double res = 0;

  if(M - T > -EPS){
    res += (1 - P) * solve(K - 1, R, M);
    res += P * solve(K - 1, M, L);
  }
  else{
    res += (1 - P) * solve(K - 1, M, L);
    res += P * solve(K - 1, R, M);
  }

  return res;
}

int main(){
  int K;
  double R, L;

  while(cin >> K >> R >> L >> P >> E >> T){
    TR = T - E;
    TL = T + E;
    printf("%.10f\n", solve(K, R, L));
  }
}

Measured memory_bytes: 0
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  ll N; cin>>N;
  vector<ll> vec(1001,0);
  vector<ll> list;
  rep(i,N)
  {
    ll l; cin>>l;
    vec.at(l)++;
  }
  list=vec;
  rep(i,1000)
  {
    vec.at(i+1)+=vec.at(i);
  }
  
  ll ans=0;
  //3辺異なる
  for(int i=1;i<=1000;i++)
  {
    for(int j=i+1;j<=1000;j++)
    {
      ans+=list.at(i)*list.at(j)*(vec.at(min(i+j-1,1000))-vec.at(j));
    }
  }
  //短長長
  for(int i=1;i<=1000;i++)
  {
    for(int j=i+1;j<=1000;j++)
    {
      if(list.at(j)>1)
      {
        ans+=list.at(i)*list.at(j)*(list.at(j)-1)/2;
      }
    }
  }
  //長短短
  for(int i=1;i<=1000;i++)
  {
    if(list.at(i)>1)
    {
      ll n=list.at(i);
      ans+=n*(n-1)/2*(vec.at(min(2*i-1,1000))-vec.at(i));
    }
  } 
  //正三角形
  for(int i=1;i<=1000;i++)
  {
    if(list.at(i)>2)
    {
      ll n=list.at(i);
      ans+=n*(n-1)*(n-2)/6;
    }
  }  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define REP1(i,n) for(long long i=1;i<=(n);i++)
#define REP2D(i,j,h,w) for(long long i=0;i<(h);i++) for(long long j=0;j<(w);j++)
#define REP2D1(i,j,h,w) for(long long i=1;i<=(h);i++) for(long long j=1;j<=(w);j++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();++ite)
#define ALL(a) ((a).begin()),((a).end())
#define RANGE(a) (a),((a)+sizeof(a))
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define ENTER printf("\n")
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<(a)<<endl
#ifdef DEBUG
#define DBPRT(a) cout << "[Debug] - " << #a << " : " << (a) << endl
#define DBSTART if(1){
#define DBEND }
#else
#define DBPRT(a) do{}while(0)
#define DBSTART if(0){
#define DBEND }
#endif
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
#define PRTLST2D(arr2,d1,d2) do{cout<<"L\t";REP(_i,d2) cout<<_i<<"\t"; cout<<endl; REP(_i,d1){cout<<_i<<"\t";REP(_j,d2){cout<<arr2[_i][_j]<<"\t";}cout<<endl;}}while(0);

#define TOSUM(arr,sum,n) {sum[0]=arr[0];REP1(i,n-1) sum[i]=sum[i-1]+arr[i];}

#define MIN(target,v1) (target)=min(target,v1)
#define MAX(target,v1) (target)=max(target,v1) 
#define P1 first
#define P2 second
#define PB push_back
#define UB upper_bound
#define LB lower_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,0,1,1,0,0,-1};
const int Move_[8][2] = {-1,0,-1,-1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p) {os<<"( "<<p.P1<<" , "<<p.P2<<" )";return os;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {ITE(v) os << (ite-v.begin()) << " : " << *ite <<endl;return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v) {os<<" { ";ITE(v) {os<<*ite;if(ite!=--v.end()){os<<" , ";}} os<<" } ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& m) {ITE(m) {os<<ite->P1<<"\t\t|->\t\t"<<ite->P2<<endl;} return os;}

//---------------------
#define MAXN 1000005
#define INF (INF_LL/4)
//---------------------

ll n;

int main(){
	cin >> n;
	ll maxn = (ll) sqrt(n) + 5;
	ll res = INF;
	REP1(i,maxn) if(!(n%i)) res = min(res,(ll)(i+n/i-2));
	PRT(res);
	return 0;
}









Measured memory_bytes: 256
#include <stdio.h>

int x[200000], y[200000];

int main(){
	int N, i, j, k = 0;
	scanf("%d", &N);
	for(j = 0; j < N; j++){
		if(j % 2 == 1){
			x[k] = 0;
			y[k] = j;
			k++;
		}
		if((N - 1 + j) % 2 == 1){
			x[k] = N - 1;
			y[k] = j;
			k++;
		}
	}
	for(i = 1; i < N - 1; i++){
		if(i % 2 == 1){
			x[k] = i;
			y[k] = 0;
			k++;
		}
		if((N - 1 + i) % 2 == 1){
			x[k] = i;
			y[k] = N - 1;
			k++;
		}
	}
	for(i = 1; i < N - 1; i++){
		for(j = 1; j < N - 1; j++){
			if(i % 2 == 0){
				if(j % 6 == 1){
					x[k] = i;
					y[k] = j;
					k++;
				}
			}
			else{
				if(j % 6 == 4){
					x[k] = i;
					y[k] = j;
					k++;
				}
			}
		}
	}
	printf("%d\n", k);
	for(i = 0; i < k; i++){
		printf("%d %d\n", x[i], y[i]);
	}
	return 0;
}

Measured memory_bytes: 2688
#include<iostream>
#include<map>

using namespace std;

int main(){
  string b;
  map<string, string> m={{"A", "T"}, {"T", "A"}, {"C", "G"}, {"G", "C"}};
  
  cin >> b;
  
  cout << m[b] << endl;
  return 0;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
ww = [0 for i in range(w)]
hw = [list(ww) for i in range(h)]

count = 1
tmp_w = 0
tmp_h = 0
for i in a:
    for j in range(i):
        #print(hw)
        hw[tmp_h][tmp_w] = str(count)
        if tmp_w != w - 1:
            tmp_w += 1
        else:
            tmp_h += 1
            tmp_w = 0
    count += 1
y = 1
for i in hw:
    if y % 2 == 0:
        i.reverse()
    y += 1
    print(' '.join(i))

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

int main(void)
{
  long int n,m,h;
  int i;
  int sum=0;

  scanf("%ld %ld",&n,&m);
  for(i=0;i<m;i++)
  {
    scanf("%d",&h);
    sum+=h;
  }

  if(sum>n)
  {
    printf("-1\n");
  }
  else
  {
    printf("%ld\n",n-sum);
  }

  return 0;
}

Measured memory_bytes: 1708
#include <iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

int gcd(int a, int b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

int main() {
	int n,MAX=0;
	cin >> n;
	vector<int> a(n+2),l(n+2),r(n+2);
	a[0] = 0;
	l[0] = 0;
	r[n+1] = 0;
	for (int i = 1; i <= n; i++)cin >> a[i];

	for (int i = 1; i <= n; i++) {
		l[i] = gcd(l[i - 1], a[i-1]);
	}
	for (int i = n; i >= 0; i--) {
		r[i] = gcd(r[i + 1], a[i + 1]);
	}

	for (int i = 0; i <= n; i++) {
		if (MAX < gcd(l[i], r[i])) MAX = gcd(l[i], r[i]);
	}

	cout << MAX << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<string.h>
int main(){
    char c[1200] = {0};
    int i = 0;
    int j = 0;
    for(i=0;i<1200;i++){
        scanf("%c",&c[i]);
        if(c[i]=='\n'){
            break;
        }
    }
    for(j=0;j<=i;j++){
        if(c[j]>=65&&c[j]<=90){
            c[j] = c[j]+32;
        }
        else if(c[j]>=97&&c[j]<=122){
            c[j] = c[j]-32;
        }
    }
    for(j=0;j<=i;j++){
        printf("%c",c[j]);
    }
   // printf("\n");
    return 0;
}

Measured memory_bytes: 524
#include "bits/stdc++.h"

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

int a,b;

void input(){
	cin>>a>>b;
	return;
}

void solve(){
	b+=a*3;
	cout<<b/2<<endl;
	return;
}

int main(){
	input();
	solve();
	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++)

int main() {
	int N, K;
	cin >> N >> K;
	vector<bool> judge(N, true);
	rep(i, K) {
		int d;
		cin >> d;
		rep(j, d) {
			int A;
			cin >> A;
			judge[A - 1] = false;
		}
	}
	int ans = 0;
	rep(i, N) {
		if (judge[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static final int MAX_NODES = 51 * 51;
	
	public static final boolean[][] mul(boolean[][] one, boolean[][] two, final int NODES){
		boolean[][] ret = new boolean[NODES][NODES];
		
		for(int h = 0; h < NODES; h++){
			for(int v = 0; v < NODES; v++){
				if(ret[h][v]){
					continue;
				}
				
				for(int t = 0; t < NODES; t++){
					ret[h][v] = one[h][t] && two[t][v];
					
					if(ret[h][v]){
						break;
					}
				}
			}
		}
		
		return ret;
	}
	
	public static final boolean[][] pow(boolean[][] adj, final int NODES, final int Z){
		if(Z == 1){
			return adj;
		}else if(Z % 2 == 0){
			boolean[][] ret = pow(adj, NODES, Z / 2);
			return mul(ret, ret, NODES);
		}else{
			return mul(adj, pow(adj, NODES, Z - 1), NODES);
		}
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
			final int Z = sc.nextInt();
			
			if(N == 0 && M == 0 && Z == 0){
				break;
			}
			
			int[] pre = new int[2 * M];
			int[] now = new int[2 * M];
			
			for(int i = 0; i < M; i++){
				int s = sc.nextInt();
				int t = sc.nextInt();
				
				pre[i * 2] = s;
				now[i * 2] = t;
				pre[i * 2 + 1] = t;
				now[i * 2 + 1] = s;
			}
			
			boolean[][] A = new boolean[2 * M + 1][2 * M + 1];
			for(int i = 0; i < 2 * M; i++){
				for(int j = 0; j < 2 * M; j++){
					if(now[i] == pre[j] && now[j] != pre[i]){
						A[i][j] = true;
					}
				}
			}
			
			for(int i = 0; i < 2 * M; i++){
				if(pre[i] == 1){
					A[2 * M][i] = true;
				}
			}
			
			A = pow(A, 2 * M + 1, Z);
			
			boolean flag = false;
			for(int i = 0; i < 2 * M; i++){
				if(now[i] == N && A[2 * M][i]){
					flag = true;
					break;
				}
			}
			
			System.out.println(flag ? "yes" : "no");
		}
	}

}

Measured memory_bytes: 30540
import java.io.*;

public class Main {

    public static void main(String[] argv) throws IOException {
        //*
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        while(true) {
            String s = in.readLine();
            if (s == null) {
                break;
            }
            f(s);
        }
        //*/
    }

    public static void f(String s) {
        char[] c = s.toCharArray();
        char[] r = new char[c.length];
        for(int i = 0; i < c.length; i++) {
            r[c.length - i - 1] = c[i];
        }
        System.out.println(r);
    }
}

Measured memory_bytes: 9352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
const int maxn = 1e5+5;
const int N = 1000;
typedef long long ll;
int t,head[maxn];
ll dist[maxn],w;
bool vis[maxn];
struct Edge
{
    int from,to,nxt;
    ll cost;
}e[2*maxn];
void addedge(int u,int v,int w)
{
    e[t].from=u;
    e[t].to=v;
    e[t].cost=w;
    e[t].nxt=head[u];
    head[u]=t++;
}
void dfs(int u,int fa)
{
    for(int i=head[u];i!=-1;i=e[i].nxt){
        int to=e[i].to;
        if(to==fa) continue;
        dist[to]=dist[u]+e[i].cost;
        dfs(to,u);
    }
}
int main()
{
    int n;
    while(cin>>n){
        t=0;
        memset(head,-1,sizeof(head));
        memset(dist,0,sizeof(dist));
        int u,v;
        for(int i=1;i<n;i++){
            cin>>u>>v>>w;
            addedge(u,v,w);
            addedge(v,u,w);
        }
        int q,k;
        cin>>q>>k;
        dfs(k,-1);
        int x,y;
        for(int i=0;i<q;i++){
            cin>>x>>y;
            cout<<dist[x]+dist[y]<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  long long int arr[n];
  for(int i=0; i<n; i++)
  {
    cin>>arr[i];
  }
  long long int stool=0;
  for(int i=1; i<n; i++)
  {
   	if(arr[i]<arr[i-1])
    {
      stool+=(arr[i-1]-arr[i]);
      arr[i]=arr[i-1];
    }
  }
  cout<<stool<<endl;
}


Measured memory_bytes: 5168
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
using namespace std;
int main(){
	char ch;
	int count[26];
	for (int i = 0; i < 26; i++){
		count[i] = 0;
	}

	while (cin >> ch){
		if (islower(ch)){
			count[ch - 'a']++;
		}
		else if (isupper(ch)){
			count[ch - 'A']++;
		}
	}
	
	for (int i = 0; i < 26; i++){
		printf("%c : %d\n", 'a' + i, count[i]);
	}
	return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;


int main(){
    int N;
    cin >> N;
    vector<int> T(N), A(N);
    rep(i, N) cin >>T[i] >> A[i];

    ll t = 1, a = 1;

    for(int i = 0; i < N; i++){
        ll n = max((t + T[i] - 1) / T[i] , (a + A[i] - 1) / A[i]);
        t = n * T[i]; a = n * A[i];
//        cout << "i:" << i << " " << t << " " << a << endl;
    }
    cout << t + a << endl;
    return 0;
}


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

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end())); }
TEMP_T T    cums(T& v){ T r; r.push_back(v[0]); for(int i=1; i<v.size(); i++) r.push_back(r[i-1] + v[i]); return r; }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }


struct Solver {
  Solver(){}
  int solve(){
  }
};

typedef long long lint;

static inline lint in(){ lint x; scanf("%lld", &x); return x; }

int main()
{
  int n;
  while (n = in()){
    vector<lint> pipe, joint;
    for (int i = 0; i < n; i++) pipe.push_back(in());
    for (int i = 0; i < n - 1; i++) joint.push_back(in());
    sort(pipe);
    sort(joint);
    revs(pipe);
    revs(joint);
    lint sum = 0;
    for (int i = 0; i < n; i++) sum += pipe[i];
    lint c = n;
    lint maxi = c * sum;
    for (int i = 0; i < n - 1; i++){
      c--;
      sum += joint[i];
      if (maxi > c * sum) break;
      maxi = c * sum;
    }
    printf("%lld\n", maxi);
  }

  return (0);
}

Measured memory_bytes: 2632
#include<bits/stdc++.h>
const long double pi=acos(-1);
const int N=2e5+10;
using namespace std;
int arr[50];
bool check(int n)
{
	while(n)
	{
		if(arr[n%10])
		{
			return false;
		}
		n/=10;
	}
	return true;
}
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=k;i++)
	{
		int x;
		cin>>x;
		arr[x]=1;
	}
	while(1)
	{
		if(check(n))
		{
			cout<<n<<"\n";
			break;
		}
		n++;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 1e3;
int A[N+9], B[N+9];
int n, inf=1e9, mem[N+9][10009];

int dp(int i, int h) {
	if(h<=0) return 0;
	if(i>n) {
		return inf;
	}
	if(mem[i][h]!=-1) return mem[i][h];
	int a = B[i] + dp(i, h-A[i]);
	int b = B[i] + dp(i+1, h-A[i]);
	int c = dp(i+1, h);
	return mem[i][h] = min({a, b, c});
}
int main() {
	ios_base::sync_with_stdio(0);
	int a,b,h,T,cas=0;
	cin>>h>>n;
	for(int i=1;i<=n;++i) cin>>A[i]>>B[i];
	memset(mem, -1, sizeof(mem));
	cout<<dp(1, h);
	return 0;
}

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

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    cout << string(ty-sy, 'U')
         << string(tx-sx, 'R')
         << string(ty-sy, 'D')
         << string(tx-sx, 'L')
         << 'L'
         << string(ty-sy+1, 'U')
         << string(tx-sx+1, 'R')
         << 'D'
         << 'R'
         << string(ty-sy+1, 'D')
         << string(tx-sx+1, 'L')
         << 'U'
         << endl;
}


Measured memory_bytes: 256
s = input()
i = 0
while s[i] == 'B':
    i += 1
ans = s[i]
for j in range(i+1,len(s)):
    if s[j] =='0' or s[j] == '1':
        ans = ans + s[j]
    else:
        ans = ans[:-1]
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cmath>

using namespace std;
const long long INF = (long long) (1e18)+1;

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

  bool flag = false;
  int A = 0;
  int B = 0;

  for (int i=0; i < 3; ++i) {
    if (s[i] == 'A') {
      A++;
    } else {
      B++;
    }
  }

  if (A > 0 && B > 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
bool = []
for i in s:
    if i == "#":
        bool.append(1)
    else:
        bool.append(0)
black = sum(bool)
bool_t = [0]
for i in range(n):
    bool_t.append(bool[i] + bool_t[i])
ans = float("inf")
for i in range(n + 1):
    ans = min(ans, bool_t[i] + n - black - (i - bool_t[i]))
print(ans)


Measured memory_bytes: 13032
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int ans=0;
    for(int i=0; i<n; i++){
        int a,b;
        cin >> a >> b;
        ans=ans+(b-a+1);
    }
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 256
k,n = map(int,input().split())
l= list(map(int,input().split()))
li = []

for i in range(n):
  if i != n-1:
    li.append(l[n-i-1]-l[n-i-2])
  else:
    li.append(k-l[n-1]+l[0])

li.sort(reverse=True)
print(k-li[0])

Measured memory_bytes: 26436
def solve(C):
    C.sort(key=lambda x: x[2], reverse=True)
    for xi in range(0, 101):
        for yi in range(0, 101):
            h = C[0][2] + abs(xi - C[0][0]) + abs(yi - C[0][1])
            if all(max(h - abs(xi - c[0]) - abs(yi - c[1]), 0) == c[2] for c in C):
                return [str(xi), str(yi), str(h)]


if __name__ == "__main__":
    N = int(input())
    C = []
    for n in range(N):
        d = input().split(" ")
        C.append((int(d[0]), int(d[1]), int(d[2])))
    print(" ".join(solve(C)))


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N; cin >> N;
	vector<int> a(N);
	for (int& x : a) cin >> x;
	ll ans = 0;
	for (int& x: a) {
		if (x <= 10) continue;
		int y = 10 + x % 2;
		ans += (x - y) / 2;
		x = y;
	}
	vector<int> v;
	for (int i = 0; i < N; i++)
		while (a[i]--)
			v.push_back(i);
	int M = v.size();
	for (int i = 0; i + 1 < M;) {
		if (v[i + 1] - v[i] >= 2) i++;
		else {
			i += 2;
			ans++;
		}
	}
	cout << ans << endl;
}


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

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


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

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

        int n = sc.nextInt();
        Tree t = new Tree(n);

        for(int i = 0; i < n; i++) {
        	int id = sc.nextInt();
            int k = sc.nextInt();
            int pc = -1;
            for(int j = 0; j < k; j++) {
            	int c = sc.nextInt();
            	if (j == 0)
                    t.setChild(id, c);
                else
                    t.setRightSib(pc, c);
                t.setPar(c, id);
                pc = c;
            }
        }

        for(int i = 0; i < n; i++)
        	t.printR(i);
	}
}

class Tree {
	private class Node {
		int parent = -1;
		int leftChild = -1;
		int rightSib = -1;

		public int getDepth() {
			if(parent == -1)
				return 0;
			else
				return node[parent].getDepth() + 1;
		}

		public String getType() {
			if(parent == -1)
				return "root";
			else if(leftChild == -1)
				return "leaf";
			else
                return "internal node";
		}
	}

	private Node[] node;

	public Tree(int n) {
		node = new Node[n];
		for(int i = 0; i < n; i++) {
			node[i] = new Node();
		}
	}

    public void setChild(int id, int c) {
        node[id].leftChild = c;
    }

    public void setRightSib(int id, int sib) {
        node[id].rightSib = sib;
    }

    public void setPar(int id, int par) {
        node[id].parent = par;
    }

    public void printR(int id) {
    	System.out.print("node " + id + ": parent = " + node[id].parent + ", depth = " + node[id].getDepth() + ", "
                + node[id].getType() + ", [");
        if (node[id].leftChild != -1) {
            System.out.print(node[id].leftChild);
            for (int c = node[node[id].leftChild].rightSib; c != -1; c = node[c].rightSib)
                System.out.print(", " + c);
        }
        System.out.println("]");
    }

}



Measured memory_bytes: 131536
#include <bits/stdc++.h> 
    #include<ext/pb_ds/assoc_container.hpp> 
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    #define int long long  
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
    #define INF 1e10
    const double pi=3.14159265358979323;
    const int mod=998244353;
    int gcd(int a, int b) 
    { 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
    } 
    void swap(int a,int b)
    {
      int temp=a;
      a=b;
      b=temp;
    } 
    int  binpow(int  a,int  b) 
    {
    int res = 1;
    while (b > 0) {
        if (b%2 == 1)
            res = (res * a)%mod;
        a = (a* a)% mod;
        b >>= 1;
    }
    return res;
}
    int modinv(int y)
    {
        return binpow(y,mod-2);
    }

    int fact[500000+5];
    void precal()
    {
    fact[0]=1;
    for(int i=1;i<500000+5;i++)
    {
        fact[i]=(i*fact[i-1])%mod;
    }
}
    signed main() {

 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    #ifndef ONLINE_JUDGE
      if(fopen("INPUT.txt","r"))
      {
      freopen ("INPUT.txt" , "r" , stdin);
      freopen ("OUTPUT.txt" , "w" , stdout); 
      }
    #endif  
    // -------------------------------------Code starts here--------------------------------------------------------------------- 
    int t=1; 
    //cin>>t;
    while(t--)
    {
        int x,n;
        cin>>x>>n;
        int a[n];
        set<int > s;
        f(i,1,1000)
        {
            s.insert(i);
            s.insert(-1*i);
        }
        s.insert(0);
        f(i,0,n)
        {
            cin>>a[i];
            s.erase(a[i]);
        }
        int mn=INF;
        int ch=INF;
        for(auto i:s)
        {
            if(abs(i-x)<mn)
            {
                mn=abs(i-x);
                ch=i;
            }
            else if(abs(i-x)==mn)
            {
                if(ch>=i)
                    ch=i;
            }
        }
        cout<<ch<<endl;
    }
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
         
int main() {
          int N, K, sum = 1;
          cin >> N >> K;
          for (int i; i < N; i++){
            if (sum <= K)
              sum *= 2;
            else
              sum += K;
          }
          cout << sum << endl;
        }

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

int main()
{
  int A, B;
  cin >> A >> B;
  
  string ans;
  if (A == B) ans = "Draw";
  else if (A == 1 || (B != 1 && A > B)) ans = "Alice";
  else ans = "Bob";
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int d = sc.nextInt();
		int t = sc.nextInt();
		int s = sc.nextInt();

		if ( s*t>=d ) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35824
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

vector<LL> v;

void rec(int k,int s,LL p){
    if(k == 0){
        v.pb(p);
        return;
    }
    if(p == 0){
        for (int i = 0; i < 10; i++) {
            rec(k-1,i,p*10+i);
        }
    }
    else{
        for (int i = -1; i <= 1; i++) {
            if(0<=s+i&&s+i<10) rec(k-1,s+i,p * 10 + s + i);
        }
    }
}


int main(){
    int k;cin >> k;
    rec(11,0,0);
    sort(ALL(v));
    v.erase(unique(ALL(v)),v.end());
    cout << v[k] << endl;
    return 0;
}


Measured memory_bytes: 10348
#include <bits/stdc++.h>
#define MAXN 100010

using namespace std;

int n, k, h[MAXN];

int main() {
	scanf("%d%d", &n, &k);
	int ans = 0;
	for(register int i = 1; i <= n; ++i) {
		scanf("%d", &h[i]);
		if(h[i] >= k) ++ans;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	 int A=10,B=11,C=12,D=13,E=14,F=15;
	 char x,y;
	 scanf("%c%*c%c",&x,&y);
	 if(x==y)
	 	 printf("=\n");
	 if(x<y)
	 	 printf("<\n");
	 if(x>y)
	 	 printf(">\n");
	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int N,M;
    int tN;
    cin>>N>>M;
    for(int i=0;i<M;i++){
        cin>>tN;
        N-=tN;
    }
    if(N<0)cout<<-1<<endl;
    else cout<<N<<endl;
    return 0;
}

Measured memory_bytes: 3192
# AtCoder Beginner Contest 149 : C (2019/12/29)
X = int(input())
if X != 2:
    if X % 2 == 0:
        X = X + 1
    while True:
        i = 2
        flag = False
        while True:
            if i >= X:
                flag = True
            if X % i == 0:
                break
            i = i + 1
        if flag == True:
            break
        else:
            X = X + 2
print(X)

Measured memory_bytes: 3060
//============================================================================
// Name        : HelloWorld.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
typedef long long ll;
using namespace std;
int A,B,X;
int main() {
	cin>>A>>B>>X;
    if(A<=X && (A+B)>=X){
    	cout<<"YES"<<endl;
    }else{
    	cout<<"NO"<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
# frozen_string_literal: true

def show(x)
  r = if x then 'YES'
      else 'NO'
      end
  puts r
end

def solve(x)
  sel = ['A', '']
  %w[KIH B R].reduce(sel) do |a, i|
    a.flat_map do |s|
      s + i
    end.product(sel).map(&:join)
  end.include?(x)
end

show solve gets.chomp


Measured memory_bytes: 3836
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static boolean[] eratosthenes(int m) {
		int n = m + 1;
		boolean[] isp = new boolean[n];
		if (n < 2) return isp;

		Arrays.fill(isp, true);

		for (int i=2; i*i<n; i++) {
			if (!isp[i]) continue;
			for (int j=i+i; j<n; j+=i) {
				isp[j] = false;
			}
		}

		return isp;
	}

	static boolean solve() {
		int n = in.nextInt();
		int x = in.nextInt();
		if (n + x == 0) return false;

		int[] v = new int[n];
		for (int i=0; i<n; i++) {
			v[i] = in.nextInt();
		}

		boolean[] f = new boolean[x+1];
		f[0] = true;
		for (int i=0; i<x+1; i++) {
			if (!f[i]) continue;
			for (int j=0; j<n; j++) {
				if (i + v[j] <= x)
					f[i+v[j]] = true;
			}
		}

		boolean[] p = eratosthenes(x+1);
		for (int i=x; i>=2; i--) {
			if (f[i] && p[i]) {
				out.println(i);
				return true;
			}
		}

		out.println("NA");

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 60824
#include<stdio.h>



int main()

{
   int a, b, c;

   scanf( "%d %d %d", &a, &b, &c);

   if( a==b && b==c && c==a)
    printf("No");
   else if( a==b )
    printf("Yes");
   else if( b==c)
   printf("Yes");
   else if(c==a)
    printf("Yes");
   else
    printf( "No");

   return 0;

}


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


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if ((a < b) && (b < c)) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3108
def slove():
    import sys
    input = sys.stdin.readline
    n, h, w = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        cnt += min(a // h, b // w)
    print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 39152
#include <iostream>
using namespace std;
int main(void){
	int a,b,x,y=1;
	cin>>a>>b;
	char C[a][b]={0};
	int D[a][b]={0};
	for (int c=0;c<a;c++){
		for (int d=0;d<b;d++){
			cin>>C[c][d];
			if(C[c][d]=='c'){
				D[c][d]=0;
				x=5;
				y=1;
			}
			else if(C[c][d]=='.'){
				D[c][d]=-1;
				if (x==5){
					D[c][d]=y;
					y++;
				}
			}

		}
		x=0;
		y=1;
	}
	for (int c=0;c<a;c++){
		for (int d=0;d<b;d++){
			cout<<D[c][d];
			if (d<=b-2) cout<<" ";
		}
		cout<<endl;
	}
	return 0;
}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
using Graph = vector<vector<int>>;
queue<int> quex,quey;
const int MOD = 1000000007;




int main(){
    ll a,b,c;  cin >> a >> b >> c;
    ll all=0,cnt=0;
    ll ans=0;
    cnt=a/(c+b);


        
            if(a%(b+c)>=b) ans+=b;
            else ans+=a%(b+c);

            
    
    

    ans+=b*cnt;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int , int> pi;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int fh = n/500;
	n %= 500;
	int f = n/5;
	cout<<fh*1000+f*5<<endl;
	return 0;
};


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

using namespace std;

int main() {
    int N; cin>>N;
    vector<int> An(N+1);
    for (int i=1;i<=N;i++) {
        cin >> An[i];
    }

    vector<int> box(N+1,0);
    int total=0;
    for (int i=N;i>=1;i--) {
        int s=0;
        for (int j=i+i;j<=N;j+=i) {
            s += box[j];
        }
        if (An[i]==0 && s%2==1) {
            box[i]=1;
            total++;
        } 
        else if (An[i]==1 && s%2==0) {
            box[i]=1;
            total++;
        }
    }
    
    cout << total << endl;
    for (int i=1;i<=N;i++) {
        if (box[i] == 1) cout << i << endl;
    }

    return 0;
}

Measured memory_bytes: 2432
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define reps(i,n) for(int i=1;i<=int(n);i++)

int main(){
	
	
	int n,a,b,c;
	cin>>n>>a>>b>>c;
	
	int sina[111];
	rep(i,n)cin>>sina[i];
	
	sort(sina,sina+n);
	reverse(sina,sina+n);
	
	rep(i,n){
		double val = (double)c/a;
		double nextval = (double)(c+sina[i])/(a+b);
		
		if(val<nextval){
			a+=b;
			c+=sina[i];
		}
	}
	
	printf("%d\n",c/a);
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
 
#define REP(i, n) for(ll i = 0;i < n;i++)
#define REP1(i, n) for(ll i = 1;i < n;i++)
#define REPR(i, n) for(ll i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
 
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
 
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
 
#define pb(a) push_back(a)
 
ll n,m;
 
vector<vector<ll>> vv = vector<vector<ll>>(100000, vector<ll>(2, 1));
 
//親番を返す
ll fnd(ll cid){
  ll nid=cid;
  ll tmp;
  REP(i,10000000){ 
    tmp=vv[nid][1];
    if (tmp==-1)break;
    nid=tmp;
  }
  return nid;
}
 
 
 
int main(){
  cin >> n >> m;
  vector<ll> a(m),b(m);
  vector<ll> ans(m);
  REP(i,m) cin>>a[i]>>b[i];
  
  REP(i,n) vv[i][1]=-1;
  
  ans[m-1]=n*(n-1)/2;
  REP(i,m-1){
    ll cid0=a[m-1-i]-1;
    ll cid1=b[m-1-i]-1;
    ll pid0=fnd(cid0);//親id検索
    ll pid1=fnd(cid1);//親id検索
    
    ll t0=vv[pid0][0];//つながっている数0
    ll t1=vv[pid1][0];//つながっている数1
    ll t2=t0+t1;
    
    if (pid0==pid1){
      ans[m-2-i]=ans[m-1-i];
      continue;
    }
    //結合
    if (t0<t1)//大きい方にまとめたい
    {
      vv[pid0][1]=pid1;
      vv[pid1][0]=t2;
    }else{
      vv[pid1][1]=pid0;
      vv[pid0][0]=t2;
    }
    
    ans[m-2-i]=ans[m-1-i]-t0*t1;
  }
 
  //結果y捨つ力
  REP(i,m)
  {
  cout<<ans[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 9088