akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
int main(){
  ll n,k;
  cin >> n >> k;
  ll cnt=0;
  for(int j=k; j<=n+1;j++){
    //ll min=(j-1)*j/2;
    //ll max=(n+n-j+1)*j/2;
    //for(int i=0; i<j;i++){
    //  min+=i;
    //}
    //cout << min << endl;
    //for(int i=n-j+1; i<n+1;i++){
    //  max+=i;
    //}
    //cout << max << endl;
    //cnt = (cnt + max -min+1)%MOD;
    cnt = (cnt + (n-j+1)*j+1)%MOD;
    //cout << (n-j+1)*j << endl;
    //cout << max - min << endl;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;

    int score[201][3];
    int total[201] = {0}; //合計得点
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 3; j++){
            cin >> score[i][j];
        }
    }

    for(int j = 0; j < 3; j++){
        for(int i = 0; i < N; i++){
            int c = 0;
            int S = score[i][j];
            //cout << "S = " << S << endl;
            for(int k = 0; k < N; k++){
                //cout << "#" << score[k][j] << endl;
                if(k == i) continue;
                else{
                    if(S == score[k][j]) c++;
                    else c += 0;
                }
            }
            if(c == 0) total[i] = total[i] + S;
            else total[i] += 0;
            //cout << "@" << total[i] << endl;
        }
    }
    for(int i = 0; i < N; i++){
        cout << total[i] << endl;
    }
}



Measured memory_bytes: 3100
def inpl(): return map(int, input().split())
N, M = inpl()
t = []
for i in range(N):
    t.append(0)
for i in range(M):
    a, b = inpl()
    t[a-1] += 1
    t[b-1] += 1
    
for i in t:
    print(i)

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    int cnt = 1;
    while (pow (K, cnt) <= N) cnt++;
    cout << cnt << endl;
    return 0;
}

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

using namespace std;

using int64 = long long;

struct INFTY {
  const int64 infll = (1LL << 62) - 1;
  const int inf = (1 << 30) - 1;

  operator int64() { return infll; }

  operator int() { return inf; }
} inf;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  int N;
  cin >> N;
  deque< int > A(2 * N - 1);
  for(auto &p : A) cin >> p;


  //      1
  //     110
  //    01100
  //   0011000
  //  000110000
  // 00001100000

  //  0
  // 001

  //  1
  // 110

  auto check = [&](int v) {
    deque< int > B(A);
    for(auto &p : B) p = p >= v;
    int latte = N - 1, malta = N - 1;
    while(latte > 0 && B[latte - 1] != B[latte]) --latte;
    while(malta + 1 < B.size() && B[malta + 1] != B[malta]) ++malta;
    if(malta - (N - 1) >= (N - 1) - latte) return B[latte];
    else return B[malta];
  };

  int ok = 1, ng = 2 * N;
  while(ng - ok > 1) {
    int mid = (ok + ng) / 2;
    if(check(mid)) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
}


Measured memory_bytes: 1952
#include <bits/stdc++.h>
using namespace std;
const int LIM=10e5+5;
	vector<vector<int>> arr(LIM);
	vector<int> c(LIM,-1);
int dfs(int node){
	if(c[node]!=-1)
		return c[node]+1;
	for(int i=0;i<arr[node].size();i++){
		int x=arr[node][i];
			
		c[node]=max(dfs(x),c[node]);
	}
	return c[node]+1;
	

}
int main(){
	//freopen ("t.txt","r",stdin);
	int n,m;
	cin>>n>>m;


	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		arr[a].push_back(b);
	}

	
	int maxx=0,tem=0;
	for(int i=1;i<=n;i++){
			maxx=max(dfs(i),maxx);
	}

	cout<<maxx;
return 0;
}


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

int main() {
  int N;
  cin >> N;
  int d[N];
  REP(i, 0, N){
    cin >> d[i];
  }

  int double_sum = 0;
  int add_sum = 0;
  REP(i, 0, N){
    double_sum += d[i] * d[i];
    add_sum += d[i];
  }

  int ans;
  ans = ((add_sum * add_sum) - double_sum) / 2;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll a[3];
    for(ll i = 0; i < 3; i++)
        cin >> a[i];
    sort(a, a+3, greater<ll>());
    ll c = a[0]-a[1]+a[0]-a[2];
    ll ans;
    if(c%2==0) ans = c/2;
    else if(c%2!=0){
        ll d = a[0]-a[1];
        a[2]+=d;
        ans = d+1+(a[0]-a[2]+1)/2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
using namespace std;
int main() {
	string x;
	int co = 0, ans = 0;
	cin >> x;
	int n = x.size();
	for (int i = 0; i < n; i++) {
		if (x[i] == 'S') {
			co++;
		}
		else {
			if (co > 0) {
				ans += 2;
				co--;
			}
		}
	}
	cout << n - ans << endl;
	return 0;
}

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

int main(){
    int N;
    string s;
    cin >> N >> s;
    int r=0;
    int b=0;
    for(int i=0;i<N; i++){
        if(s[i]=='R')r++;
        else b++;
    }
    if (r>b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
inline void read(int& x)
{
	x=0;char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) x=x*10+c-'0',c=getchar();
}
struct Node
{
	int x,range;
	inline friend bool operator < (Node a,Node b)
		{
			return a.x-b.range<b.x-a.range;
		}
}node[maxn];

int main()
{
	int n;
	read(n);
	for(int i=1;i<=n;++i) read(node[i].x),read(node[i].range);
	sort(node+1,node+n+1);
	int maxr=-0x3f3f3f3f,ans=0;
	for(int i=1;i<=n;++i)
	{
		if(maxr<=node[i].x-node[i].range)
			maxr=max(maxr,node[i].x+node[i].range);
		else ++ans;
	}
	printf("%d\n",n-ans);
	return 0;
}

Measured memory_bytes: 1152
from itertools import product
from copy import deepcopy

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]

ans = 0
for hl in product([0, 1], repeat=h):
    for wl in product([0, 1], repeat=w):
        cnt = 0
        cc = deepcopy(c)
        for ci, hi in zip(c, hl):
            for cij, wj in zip(ci, wl):
                if cij == '#' and hi == 0 and wj == 0:
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)


Measured memory_bytes: 71740
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll n,x;
Vi dps;
Vi dpp;

ll cals(ll n){
	if(dps[n]!=-1)return dps[n];

	if(n==0)return 1;
	else{
		return dps[n] = 3+cals(n-1)*2;
	}
}

ll calp(ll n){
	if(dpp[n]!=-1)return dpp[n];
	if(n==0)return 1;
	else{
		return dpp[n] = 1+calp(n-1)*2;
	}
}


ll calc(ll x,ll lv){
	if(x==0)return 0;
	if(x==cals(lv))return calp(lv);
	x-=1;
	if(x<=cals(lv-1)){
		return calc(x,lv-1);
	}else{
		x-=cals(lv-1)+1;
		return 1 + calc(x,lv-1) + calp(lv-1);
	}
}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	std::cout<<std::fixed<<std::setprecision(30);
	cin>>n>>x;
	dps.resize(n+1,-1);
	dpp.resize(n+1,-1);
	ll ans = calc(x,n);
	print(ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
  for (ll i = 0; i < v.size(); ++i) \
    cout << v[i] << " ";            \
  cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)
#define get(n) \
  ll n;        \
  cin >> n
#define getvec(v, n)         \
  vector<ll> v(n);           \
  for (ll i = 0; i < n; i++) \
    cin >> v[i];
#define getstr(s) \
  string s;       \
  cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void mainSolve()
{
  get(h);
  get(w);
  get(m);
  map<ll, set<ll>> r;
  map<ll, set<ll>> c;
  while (m--)
  {
    get(a);
    get(b);
    r[a].insert(b);
    c[b].insert(a);
  }
  ll tr = 0;
  ll row = 1;
  for (int i = 1; i <= h; i++)
  {
    if (r[i].size() > tr)
    {
      row = i;
      tr = r[i].size();
    }
  }
  ll col = 0;
  ll tc = 0;
  for (int i = 1; i <= w; i++)
  {
    if (c[i].size() > tc)
    {
      col = i;
      tc = c[i].size();
    }
  }
  ll ans = 0;
  for (int i = 1; i <= w; i++)
  {
    ll curr = tr + c[i].size();
    if (c[i].find(row) != c[i].end())
      --curr;
    ans = max(ans, curr);
  }
  for (int i = 1; i <= h; i++)
  {
    ll curr = tc + r[i].size();
    if (r[i].find(col) != r[i].end())
      --curr;
    ans = max(ans, curr);
  }
  p1(ans);
}

int main()
{
  fio;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  //get(t);
  ll t = 1;
  while (t--)
  {
    mainSolve();
  }
  return 0;
}


Measured memory_bytes: 88020
#include<stdio.h>
int n[3], ans;
int main(){
  scanf("%d%d%d", n, n+1, n+2);
  if(n[0] == n[1]){
    ans = n[2];
  }else if(n[0] == n[2]){
    ans = n[1];
  }else{
    ans = n[0];
  }
  printf("%d\n", ans);
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,c=0;
    cin>>n;
    string s1,s2,temp;
    cin>>s1>>s2;
    for(int i=0;i<n;i++)
    {
        if(s1.substr(i,n)==s2.substr(0,n-i))
        {
            temp = s1.substr(0, i) + s2;
            int ans = temp.size();
            cout << ans << endl;
            return 0;
        }
    }
    cout<<2*n<<endl;
}

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

int main()
{
    int n ;
    cin>> n ;
    int arr[n] ;
    for (int i=0 ;i<n ;i++)
    {
        cin>> arr[i] ;
    }
    map<int,int>mp ;
    int counter =0 ;
for (int i=0 ;i<n ;i++)
{
    for (int j=i+1 ;j<n ;j++)
    {
        for (int k =j+1 ;k<n ;k++)
        {
if(arr[i]+arr[j]>arr[k]&&arr[i]+arr[k]>arr[j]&&arr[j]+arr[k]>arr[i]&&arr[i]!=arr[j]&&arr[k]!=arr[j]&&arr[i]!=arr[k])
{
    counter++ ;

}
        }
    }
}
cout<< counter<<endl ;
}


Measured memory_bytes: 3628
//itp1_10c
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;

int main(){
 while(true){
  int n;
  cin>>n;
  if(n==0) break;
  vector<int> v(n,0);
  int sum=0;
  double sumd=0;
  double a,aa;
  for(int i=0;i<n;i++)
   cin>>v[i];
  for(int i=0;i<n;i++)
    sum+=v[i];
  double ave=1.0*sum/n;
  for(int i=0;i<n;i++)
   sumd+=(v[i]-ave)*(v[i]-ave);
  aa=sumd/n;
  a=sqrt(aa);
  printf("%.8f\n",a);
 }
  
 return 0;
}

Measured memory_bytes: 1224
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

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

	vi T(D), A(N), B(N), C(N);
	REP(i, D) {
		cin >> T[i];
	}
	REP(i, N) {
		cin >> A[i] >> B[i] >> C[i];
	}

	vvi dp(D+1, vi(N));
	vvi ok(D+1, vi(N));
	FOR(i, 1, D) {
		REP(j, N) {
			if(A[j] <= T[i-1] && T[i-1] <= B[j]) {
				ok[i][j] = 1;	
			}
		}
	}

	FOR(i, 2, D) {
		REP(j, N) {
			REP(k, N) {
				if(ok[i-1][j] && ok[i][k]) {
					dp[i][k] = max(dp[i][k], dp[i-1][j]+abs(C[j]-C[k]));
				}
			}
		}
	}

	int ans = 0;
	REP(i, N) {
		ans = max(ans, dp[D][i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1532
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

// √a+√b < √c
// a+b+2√ab < c
// √ab <(c-a-b)/2

int main(void){
  long double a, b, c;
  cin >> a >> b >> c;

  long double ab = a*b;

  if(sqrt(ab) < (c-a-b)/2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
int i,d,b,s,t,y,sum;  
while(scanf("%d", &d)!= EOF) {  
    sum=0;
b=600/d;   
for(i=1;i<b;i++){   
y=i*d;       
t=y*y;
s=d*t; 
sum+=s;
}
printf("%d\n",sum);
if(d == 0) {
break;
}   
}
return 0;
}


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

using namespace std;

typedef long long int lli;

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

    int n, m, a[100001] = { 0 }, tmp;

    cin >> n >> m;
    for (int i=0; i<m; i++) {
        cin >> tmp;
        a[tmp] = 1;
    }
    
    lli ans[100002] = { 0, 1 }, mod = 1000000007;
    for (int i=1; i<=n; i++) {
        if (a[i]) continue;
        ans[i+1] = ans[i] + ans[i-1];
        ans[i+1] %= mod;
    }

    cout << ans[n+1] << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

#define N 8

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  char buf[ N ][ 16 ];
  int x, y;

  for ( y = 0; y < N; ++y )
  {
    fgets ( buf[ y ], sizeof ( buf[ y ] ), stdin );
  }

  puts ( "90" );
  for ( y = 0; y < N; ++y )
  {
    for ( x = 0; x < N; ++x )
    {
      putchar ( buf[ N - x - 1 ][ y ] );
    }
    puts ( "" );
  }

  puts ( "180" );
  for ( y = 0; y < N; ++y )
  {
    for ( x = 0; x < N; ++x )
    {
      putchar ( buf[ N - y - 1 ][ N - x - 1 ] );
    }
    puts ( "" );
  }

  puts ( "270" );
  for ( y = 0; y < N; ++y )
  {
    for ( x = 0; x < N; ++x )
    {
      putchar ( buf[ x ][ N - y - 1 ] );
    }
    puts ( "" );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  int S, C;
  int none[3] = {1,1,1};
  int digit[3] = {0,0,0};
  int imp = 0;
  if (N > 1) digit[0] = 1;
  for (int i=0; i<M; i++) {
    cin >> S >> C;
    if (imp) continue;
    if (S > N) { imp = 1; continue; }
    if (N > 1 && S == 1 && C == 0) { imp = 1; continue; }
    S--;
    if (none[S]) {
      none[S] = 0;
      digit[S] = C;
    } else {
      if (digit[S] != C) {
        imp = 1;
      }
    }
  }
  if (imp) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < N; i++) {
      cout << digit[i];
    }
    cout << endl;
  }
}

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

def group_by_val(list_):
    res = dict()
    for v in list_:
        if v not in res:
            res[v] = [v]
            continue
        res[v].append(v)
    return res

def count_leng(dict_):
    res = dict()
    for k in dict_:
        res[k] = len(dict_[k])
    return res

def comb2(list_):
    leng = len(list_)
    if leng == 1:
        return 0
    return (leng*(leng-1)) // 2

grouped_dict = group_by_val(A)
group_leng = count_leng(grouped_dict)

sum_val = 0
for k in grouped_dict:
    sum_val += comb2(grouped_dict[k])

for a in A:
    print(sum_val-(group_leng[a]-1))

Measured memory_bytes: 42172
#include <iostream>

using namespace std;

int main(){
	long long int N, A, B, C, X, Y[105];
	long long int ans;

	while(true){
		cin >> N >> A >> B >> C >> X;
		if( 0==(N|A|B|C|X) )
			break;
		ans = 0;
		
		for(int i=0; i<N; i++){
			cin >> Y[i];
		}
		for(int i=0; i<N&&ans<10002; ans++){
			if( X == Y[i] ){
				i++;
			}
			X = (A*X + B) % C;
		}

		cout << ((ans-1<=10000)?ans-1:-1) << endl;
	}
	return 0;
}

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

#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int N = 3002;
int dp[2][N];
int a[N];
int n;

void solve()
{
   cin >> n;
    
   f(i,n) cin >> a[i];
    
   for(int i=1;i<=n;i++)
     for(int j=0;j<n-i+1;j++)
          dp[i%2][j] = max(-dp[(i-1)%2][j]+a[j+i-1],-dp[(i-1)%2][j+1]+a[j]);  
       
   cout << dp[n%2][0] << '\n'; 
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

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

int main(){
  int K;
  cin >> K;
  string s;
  cin >> s;
  
  if(s.size() <= K){
    cout << s << endl;
  }
  else{
  	for(int i = 0; i < K; i++){
      cout << s[i];
  	}
    cout << "..." << endl;
  }
  return 0;
}


Measured memory_bytes: 3620
r = input()
if r == 'RRR':
    print(3)
elif r == 'RRS' or r == 'SRR':
    print(2)
elif r == 'RSR' or r == 'RSS' or r =='SSR' or r =='SRS':
    print(1)
elif r == 'SSS':
    print(0)


Measured memory_bytes: 8948
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;
 
int main() {
  int n,m;
  cin>>n>>m;
  P a[m];
  for(int i=0; i<m; i++) cin>>a[i].F>>a[i].S;
  sort(a,a+m);
  P dp[n];
  for(int i=0; i<n; i++) dp[i]=P(i,i);
  for(int i=0; i<m; i++) {
    dp[a[i].S-1].F=min(dp[a[i].S-1].F,dp[a[i].S].F);
    dp[a[i].S-1].S=max(dp[a[i].S-1].S,dp[a[i].S].S);
    dp[a[i].S].F=min(dp[a[i].S].F,dp[a[i].S-1].F);
    dp[a[i].S].S=max(dp[a[i].S].S,dp[a[i].S-1].S);
  }
  for(int i=0; i<n; i++) {
    if(i) cout<<" ";
    cout<<dp[i].S-dp[i].F+1;
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 5448
if __name__ == '__main__':
    n = int(raw_input())
    A = map(int, raw_input().split())
    for x in A:
        print x,
    print
    for i in range(1, n):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v

        for x in A:
            print x,
        print


Measured memory_bytes: 4644
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  int r, s, p;
  cin >> r >> s >> p;
  string t;
  cin >> t;
  vector<vector<int>> vp(k, vector<int>());
  rep(i, n){
    int pos = i % k;
    int add;
    if(t.at(i) == 'r') add = 0;
    else if(t.at(i) == 's') add = 1;
    else add = 2;
    vp.at(pos).push_back(add);
  }
  int ans = 0;
  rep(i, k){
    int add = 0;
    bool lf = false;
    rep(j, vp.at(i).size()){
      if(j != 0 && lf == false && vp.at(i).at(j) == vp.at(i).at(j-1)){
        lf = true;
        continue;
      }
      lf = false;
      int now = vp.at(i).at(j);
      if(now == 0) add += p;
      else if(now == 1) add += r;
      else add += s;
    }
    ans += add;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5120
#include <iostream>

using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int cnt = 0;
  if (B >= C) {
    cnt = B + C;
  } else {
    C -= B;
    cnt += B * 2;
    if (C > A) {
      cnt += A + 1;
    } else {
      cnt += C;
    }
  }

  cout << cnt << endl;
  return 0;
}

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

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

using namespace std;
using ll = long long;

vector<int> kmp(string s) {
  int n = s.size();
  vector<int> p(n + 1);
  p[0] = -1;
  int j = -1;
  for (int i = 0; i < n; i++) {
    while (j != -1 && s[i] != s[j]) j = p[j];
    p[i + 1] = ++j;
  }
  return p;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  string x;
  while (x.size() < t.size() * 2) x += s;
  while (x.size() < s.size() * 2) x += s;
  vector<bool> match(x.size());
  int u = 0;
  auto pre = kmp(t);
  rep(i, x.size()) {
    while (u != -1 && t[u] != x[i]) u = pre[u];
    u++;
    if (u == t.size()) {
      match[(i+1 - t.size()) % s.size()] = true;
    }
  }
  vector<vector<int>> g(s.size());
  vector<int> deg(s.size());
  rep(i, s.size()) {
    if (match[i]) {
      int j = (i + t.size()) % s.size();
      g[i].push_back(j);
      deg[j]++;
    }
  }
  queue<int> q;
  rep(i, s.size()) {
    if (deg[i] == 0) {
      q.push(i);
    }
  }
  vector<int> dp(s.size());
  int num = 0;
  while (!q.empty()) {
    num++;
    int u = q.front(); q.pop();
    for (int v : g[u]) {
      dp[v] = max(dp[v], dp[u] + 1);
      if (--deg[v] == 0) {
        q.push(v);
      }
    }
  }
  if (num != s.size()) {
    cout << -1 << endl;
  } else {
    cout << *max_element(dp.begin(), dp.end()) << endl;
  }
}

Measured memory_bytes: 36168
i = 1
until (furoshiki = $<.gets.to_i).zero?
  table = {0 => 0}
  Array.new($<.gets.to_i) {$<.gets.split(",").map(&:to_i)}.each do |v, w|
    h = Hash.new(0)
    table.each {|key, value| h[key + w] = table[key] + v if key + w <= furoshiki}
    table.merge!(h) {|k, v1, v2| [v1, v2].max}
  end
  m = table.values.max
  max = table.select {|k, v| v == m}.sort {|a, b| a[0] <=> b[0]}.first
  puts "Case #{i}:", max[1], max[0]
  i += 1
end


Measured memory_bytes: 34908
#include <stdio.h>
int a[1000001];
int main(){
    int K;
    scanf("%d",&K);
    a[1]=7%K;
    for(int i=2;i<=K;i++)a[i]=(a[i-1]*10+7)%K;

    for(int i=1;i<=K;i++)if(a[i]==0){
        printf("%d\n",i);
        return 0;
    }
    printf("-1\n");
}

Measured memory_bytes: 5612
n = int(input())
li = list(map(int,input().split()))
li.reverse()
ans = [0]*n
for i,l in enumerate(li):
    j = n - i
    if n//j < 2 and l==1:
        ans[j-1] += 1
    else:
        tmp = 0
        for k in range(2,n//j+1):
            tmp += ans[j*k-1]
        if tmp%2 == 0 and l==1:
            ans[j-1] += 1
        elif tmp%2 == 1 and l == 0:
            ans[j-1] += 1
print(ans.count(1))
if ans.count(1) == 0:
    exit()
fin_li = []
for ai,a in enumerate(ans):
    if a == 1:
        fin_li.append(ai+1)
print(*fin_li)

#print(ans)

Measured memory_bytes: 14132
import numpy as np

A, B, H, M = map(int,input().split())

angle_m = (360.0 * (H + M / 60.0))%  360
angle_h = 30.0 * (H + M / 60.0)

angle = abs(angle_m - angle_h)

x2 = A ** 2 + B ** 2 - 2.0 * A * B * np.cos(angle * np.pi / 180.0)

x = np.sqrt(x2)

print(x)

Measured memory_bytes: 27204
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define mp            make_pair
#define PI            3.14159265
#define M             1000000007
#define MM            998244353
#define fr            first
#define sc            second
#define all(v)        (v).begin(),(v).end()
#define rall(v)       (v).rbegin(),v.rend()
#define vc            vector
#define vi            vector<int>
#define pii           pair<int,int>
#define psi           pair<string,int>
#define pis           pair<int,string>
#define mii           map<int,int>
#define msi           map<string,int>

int c[1000005];
int v1[1000005];
int solve(){
    int n,d,ans=0; cin>>n>>d;
    int x[n][d];
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < d; ++j)
        {
            cin>>x[i][j];
        }
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = i+1; j < n; ++j)
        {
            int s=0;
            for (int k = 0; k < d; ++k)
            {
                s+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            int t=sqrt(s);
            if(t*t==s) ans++;
        }
    }
    cout<<ans;
}

signed main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

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

using namespace std;

typedef long long ll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;  

int main(){
    int H,W,K;
    cin >> H >> W >> K;
    int ans = 0;
    vector<string> mass(H);
    for(int i = 0; i < H; i++) cin >> mass[i];
    for(int i = 0; i < 1<<H; i++){
        for(int j = 0; j < 1<<W; j++){
            vector<int> gyo;
            vector<int> retu;
            int temp = i;
            for(int k = 0; k < H; k++){
                if(!(temp & 1)) gyo.emplace_back(k);
                temp >>= 1; 
            }
            temp = j;
            for(int k = 0; k < W; k++){
                if(!(temp & 1)) retu.emplace_back(k);
                temp >>= 1; 
            }
            temp = 0;
            for(auto g : gyo){
                for(auto r : retu){
                    if(mass[g][r] == '#') temp++;
                }
            }
            if(temp == K) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          int a = Input.ScanInt();
          Input.ScanInt();
          Input.ScanInt();
          Input.ScanInt();
          a = Input.ScanInt()-a;
          
          Console.WriteLine(a<=Input.ScanInt() ? "Yay!" : ":(");
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  char c = s[0];
  int ans = 1;
  for(int i = 1; i < n; i++){
    if(c != s[i]){
      ans++;
      c = s[i];
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3724
#include <stdio.h>
#define MAX 500000

void divi(int*,int,int);
void conq(int*,int,int,int);
int youko1,haire1[MAX],count=0;
int main()
{
  int i,lefhasi,righasi;
  scanf("%d",&youko1);
  for(i=0;i<youko1;i++)
    {
      scanf("%d",&haire1[i]);
    }
  lefhasi=0;
  righasi=youko1;
  divi(haire1,lefhasi,righasi);
  for(i=0;i<youko1-1;i++)
    {
      printf("%d ",haire1[i]);
    }
  printf("%d\n",haire1[youko1-1]);
  printf("%d\n",count);
  return 0;
}

void divi(int *haire1,int lefhasi,int righasi)
{
  int man;
  if(lefhasi+1<righasi)
    {
      man=(lefhasi+righasi)/2;
      divi(haire1,lefhasi,man);
      divi(haire1,man,righasi);
      conq(haire1,lefhasi,man,righasi);
    }
}

void conq(int *haire1,int lefhasi,int man,int righasi)
{
  int lefnum,rignum,i=0,j=0,k=0;
  lefnum=man-lefhasi;
  rignum=righasi-man;
  int lefhai[lefnum+1],righai[rignum+1];
  for(i=0;i<lefnum;i++)
    {
      lefhai[i]=haire1[lefhasi+i];
      // printf("%d\n",lefhai[lehasi+i]);
    }
  for(i=0;i<rignum;i++)
    {
      righai[i]=haire1[man+i];
      //printf("%d\n",righai[man+i]);
    }
  lefhai[lefnum]=1000000000;
  righai[rignum]=1000000000;
  i=0;
  for(k=lefhasi;k<righasi;k++)
    {
      if(lefhai[i]<=righai[j])
	{
	  haire1[k]=lefhai[i];
	  i++;
	  count++;
	}
      else
	{
	  haire1[k]=righai[j];
	  j++;
	  count++;
	}
    }
}
//4124232
/*

int divi(int haire1[],int lehasi,int rihasi)
{
  int man;
  if(lehasi+1<rihasi)
    {
      man=(lehasi+rihasi)/2;
      divi(haire1[],lehasi,man);
      divi(haire1[],man,rihasi);
      conq(haire1[],lehasi,man,rihasi);
    }
  return 0;
}

int conq(int haire1[],int lehasi,int man,int rihasi)
{
  int lefnum,rignum,lefhai,righai,i=0,j=0,k=0;
  lefnum=man-lehasi;
  rignum=right-man;
  for(i=1;i<=lefnum-1;i++)
    {
      lefhai[i]=haire1[lehasi+i];
      printf("lefhai[lehasi+i]\n");
    }
  for(i=1;i<=rignum-1;i++)
    {
      righai[i]=haire1[man+i];
      printf("righai[man+i]\n");
    }
  lefhai[lefnum]=50000;
  righai[rignum]=50000;
  i=0;
  for(k=lehasi;k<rihasi;k++)
    {
      if(lefhai[i]<=righai[j])
	{
	  haire1[k]=lefhai[i];
	  i++;
	  count++;
	}
      else
	{
	  haire1[k]=righai[j];
	  j++;
	  count++;
	}
    }
  return 0;
}
  int man,haileft[100],hairight[100],p,q;
  //printf("%d\n",lehasi);
  //printf("%d\n",rihasi);
  if(lehasi+1<rihasi)
    {
      man=(lehasi+rihasi)/2;
      //printf("%d\n",man);
      for(p=lehasi;p<=man;p++)
	{
	  printf("%d ",haire1[p]);
	}
      printf("\n");
      for(q=man+1;q<rihasi;q++)
	{
	  printf("%d ",haire1[q]);
	}
      printf("\n");
      divi(lehasi,man);
      divi(man,rihasi);
      conq(lehasi,man,rihasi);
    }
  return 0;
}
 */



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

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

    int cnt = 0, idx;
    for(int i = 0; i < s.size(); i++, cnt++){
        if(s[i] != '1'){
            idx = i;
            break;
        }
    }

    cout << (k <= cnt ? '1' : s[idx]) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <functional>
#include <sstream>
#include <bitset>
#include <map>

using namespace std;

typedef long long ll;

ll pcount (vector<ll>& len, vector<ll>& pnum, ll x, ll cur) {
  if (x <= 0) return 0;
  if (cur==0) return 1;
  ll sum;
  sum = 0;
  if (x == 2*len[cur-1]+3) sum += 2*pnum[cur-1]+1;
  else if (x > len[cur-1] + 2) {
    sum += pnum[cur-1] + 1;
    sum += pcount(len,pnum,x - len[cur-1] - 2,cur-1);
  } else if (x == len[cur-1] + 2) {
    sum += pnum[cur-1] + 1;
  } else if (x > 1){
    sum += pcount(len,pnum,x-1,cur-1);
  }
  return sum;
}

int main() {
  ll N,X;
  cin>>N>>X;
  vector<ll> len,pnum;
  len.push_back(1);
  pnum.push_back(1);
  for (ll i = 1; i <= N; i++) len.push_back(2*len[i-1]+3);
  for (ll i = 1; i <= N; i++) pnum.push_back(2*pnum[i-1]+1);
  ll ans;
  ans = pcount(len,pnum,X,N);
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;


int solve( vector<int>D, int idx ) {
	if( idx == D.size() ) {
		return 0;
	}
	if( D[idx] == 0 ) {
		return solve( D, idx + 1 );
	}
	int now = D[idx];
	int ret = INT_MAX;
	for( size_t i = idx; i < D.size(); i++ ) {
		D[i] -= now;
		if( D[i] < 0 ) {
			D[i] += 10;
		}
		ret = min( ret, solve( D, idx + 1 ) + 1 );
	}
	return ret;
}

int main() {

	long long int N;
	while( cin >> N, N ) {
		string A, B;
		cin >> A >> B;
		vector<int>D( N );
		for( size_t i = 0; i < N; i++ ) {
			D[i] = A[i] - B[i];
			if( D[i] < 0 ) {
				D[i] += 10;
			}
		}

		cout << solve( D, 0 ) << endl;
	}
}

Measured memory_bytes: 3108
#include <iostream>
#include <string>
using namespace std;
int N, A, B, C, D;
string S;

int main(void){
    // Your code here!
    cin >> N >> A >> B >> C >> D;
    cin >> S;

    for(int i = A-1; i <= C-2; i++) {
        if(S[i] == '#' && S[i+1] == '#') {
            cout <<"No" << endl;
            return 0;
        }
    }
    for(int i = B-1; i <= D-2; i++){
        if(S[i] == '#' && S[i+1] == '#') {
            cout <<"No" << endl;
            return 0;
        }
    }
   
    if(C < D){
        cout << "Yes" << endl;
    } else{
        bool flag = false;
        for(int i = B-2; i <= D-2; i++){
            if(S[i] =='.' && S[i+1] == '.' && S[i+2] == '.') {
                flag = true;
                break;
            }
        }
        
        if(flag) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	
	public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
       int ar[]=new int[4];
       for(int i=0;i<3;i++)
       {
           int a=sc.nextInt();
           int b=sc.nextInt();
           a-=1;
           b-=1;
           ar[a]+=1;
           ar[b]+=1;
       }
       for(int i:ar)
       {
           if(i>2)
           {
               System.out.println("NO");
               System.exit(0);
           }
       }
       System.out.println("YES");
    }
}

Measured memory_bytes: 21972
#include<stdio.h>

int A[101][101],s[101],d[101],f[101],l;

void dfs(int n){
  int i;
  d[n]=l++;
  for(i=1;i<=s[n];i++){
    if(!d[A[n][i]]) dfs(A[n][i]);
  }
  f[n]=l++;
}

int main(){
  int i,j,b,c,n;
  scanf("%d",&n);
  l=1;
  for(i=1;i<=n;i++){
    d[i]=f[i]=0;
    scanf("%d",&b);
    scanf("%d",&s[b]);
    for(j=1;j<=s[b];j++){
      scanf("%d",&A[b][j]);
    }
  }
  for(i=1;i<=n;i++){
    if(!d[i]) dfs(i);
  }
  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,d[i],f[i]);
  }
  return 0;
}
      



Measured memory_bytes: 2108
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int res = 0;
  char w[ 16 ], *p;

  scanf ( "%s", w );
  for ( p = w; *p != '\0'; ++p )
  {
    *p = tolower ( *p );
  }

  for ( ; ; )
  {
    char t[ 1024 ], *p;

    scanf ( " %s", t );
    if ( !strcmp ( t, "END_OF_TEXT" ) ) break ;

    for ( p = t; *p != '\0'; ++p )
    {
      *p = tolower ( *p );
    }
    res += !( strcmp ( t, w ) );
  }

  printf ( "%d\n", res );

  return ( 0 );
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll N ;
    ll D;
    cin >> N >> D ;

    ll X[N];
    ll F[N];

    ll res = 0;
    ll idx = 0;
    ll count = 0;

    for (ll i = 0 ; i <N;i++)
    {
      cin >> X[i] >> F[i];
      if (X[i]*X[i]+F[i]*F[i] <= D*D)
      count++;
    }

    cout << count;

    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define VI         vector<int>
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


int main(){
  int k;
  cin >> k;
  queue<ll> q;
  REP(i,9)q.push(i+1);

  ll n;
  REP(i,k){
    n = q.front(); q.pop();

    if(n%10==0){
      q.push(n*10);
      q.push(n*10+1);
    }else if(n%10==9){
      q.push(n*10+8);
      q.push(n*10+9);
    }else{
      for(int j = -1; j < 2; j++){
        q.push(n*10+n%10+j);
      }
    }
  }

  cout << n << endl;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define be(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};

int main()
{
    int n;
    while(cin>>n)
    {
        if(n==0)return 0;
        vector<pair<int,int> >m={};
        m.push_back(make_pair(0,0));
        REP(i,n-1)
        {
            int a,b;cin>>a>>b;
            if(b==0)m.push_back(make_pair(m.at(a).first-1,m.at(a).second));
            if(b==1)m.push_back(make_pair(m.at(a).first,m.at(a).second-1));
            if(b==2)m.push_back(make_pair(m.at(a).first+1,m.at(a).second));
            if(b==3)m.push_back(make_pair(m.at(a).first,m.at(a).second+1));
        }
        int mxx=0,mnx=0,mxy=0,mny=0;
        REP(i,n)
        {
            mxx=max(m.at(i).first,mxx);
            mxy=max(m.at(i).second,mxy);
            mnx=min(m.at(i).first,mnx);
            mny=min(m.at(i).second,mny);
        }
        cout<<mxx-mnx+1<<" "<<mxy-mny+1<<endl;
    }
}


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

int getnum(vector<int> test, int n){
    vector<int> a(n);
    
    for (int i = 0 ; i < n; i++){
        a.at(i) = i + 1;
    }
    int count = 0;

    while(!equal(a.begin(), a.end(), test.begin())){
        next_permutation(a.begin(), a.end());
        count++;
    }

    return count;
}

int main() {
    int n;
    cin >> n;

    vector<int> data(n);
    vector<int> p(n);
    vector<int> q(n);

    for (int i = 0; i < n; i++){
        cin >> p.at(i);
    }
    for (int i = 0; i < n; i++){
        cin >> q.at(i);
    }

    cout << abs(getnum(p, n) - getnum(q, n)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

// f : 二項演算 Group * Group -> Group
// g : 逆元関数 Group -> Group
// G1 : 単位元
template<typename Group>
class CumulativeSum {
	std::vector<Group> elements;
	std::vector<Group> sum;
	
	bool built;
	
	using F = std::function<Group(Group, Group)>;
	using G = std::function<Group(Group)>;
	
	const F f;
	const G g;
	const Group G1;
	
	private:
	void build() {
		if(built) return;
		built = true;
		sum.assign(elements.size() + 1, G1);
		for(int i = 0; i < elements.size(); i++) sum[i + 1] = f(sum[i], elements[i]);
	}
	public:
	CumulativeSum(F f, G g, Group G1) : f(f), g(g), G1(G1) {
		built = false;
		elements.clear();
		sum.clear();
	}
	CumulativeSum(F f, G g, Group G1, std::vector<Group> vec) : f(f), g(g), G1(G1) {
		built = false;
		elements.swap(vec);
		sum.clear();
	}
	void swap(std::vector<Group> vec) {
		built = false;
		elements.swap(vec);
	}
	void add(Group x) {
		built = false;
		elements.push_back(x);
	}
	void pop_back() {
		if(!elements.size()) return;
		built = false;
		elements.pop_back();
	}
	Group get(int k) { // [0, k)
		build();
		return sum[k];
	}
	Group get(int a, int b) { // [a, b)
		build();
		return f(g(sum[a - 1]), sum[b]);
	}
	int size() {
		return elements.size();
	}
};

int main() {
	int n, k;
	while(scanf("%d%d", &n, &k) and (n and k)) {
		std::vector<i64> a(n);
		for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
		CumulativeSum<i64> cs([](i64 a, i64 b) { return a + b; }, [](i64 a) { return -a; }, 0, a);
		
		i64 ma = -(1LL << 60);
		for(int i = 1; i + k - 1 <= n; i++) ma = std::max(ma, cs.get(i, i + k - 1));
		printf("%lld\n", ma);
	}
	return 0;
}



Measured memory_bytes: 5132
#include <iostream>

using namespace std;

int main()
{
string first,second,u;
int one,two;
cin>>first>>second;
cin>>one>>two;
cin>>u;
if(first==u){
    cout<<one-1<<' '<<two;
}else{
cout<<one<<' '<<two-1;
}
    return 0;
}


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




























int main () {
    int K;
    cin >> K;
    
    int result = -1;
    int i = 0;
    int j = 7 % K;
    while (j != 0 && i <= K) {
        j = (j * 10 + 7) % K;
        i++;
    }

    if (i != K + 1) {
        result = i + 1;
    }

    cout << result << endl;
}

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



int main() {
    string s;
    cin >> s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7') cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

char maze[1005][1005];
int dist[1005][1005];

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

const int ddx[5] = {2,1,0,-1,-2};
const int ddy[5] = {2,1,0,-1,-2};

int main(){
	int h,w,ch,cw,dh,dw;
	cin >> h >> w >> ch >> cw >> dh >> dw;
	ch--, cw--, dh--, dw--;
	rep(i,h) rep(j,w) cin >> maze[i][j];
	rep(i,h) rep(j,w) dist[i][j] = -1;
	queue<pair<int,int>> a;
	queue<pair<int,int>> b;
	dist[ch][cw] = 0;
	a.emplace(ch, cw);
	while(!a.empty() || !b.empty()){
		if(!a.empty()){
			auto p = a.front(); a.pop();
			b.emplace(p);
			rep(i,4){
				int ny = p.first + dy[i];
				int nx = p.second + dx[i];
				if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
				if(dist[ny][nx] != -1) continue;
				if(maze[ny][nx] == '#') continue;
				dist[ny][nx] = dist[p.first][p.second];
				a.emplace(ny, nx);
			}
		}else{
			auto p = b.front(); b.pop();
			rep(i,5)rep(j,5){
				int nny = p.first + ddy[i];
				int nnx = p.second + ddx[j];
				if(nny < 0 || nny >= h || nnx < 0 || nnx >= w) continue;
				if(dist[nny][nnx] != -1) continue;
				if(maze[nny][nnx] == '#') continue;
				dist[nny][nnx] = dist[p.first][p.second] + 1;
				a.emplace(nny, nnx);
			}
		}
	}
	int ans = dist[dh][dw];
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 8548
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
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 namespace std;
using ll = long long;
const int lim = 1e5 + 1;
const ll mod = 1e9 + 7;

ll dp[lim][13];

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

    dp[0][0] = 1;
    
    //何桁目かの情報を保持
    ll mul = 1;

    reverse(all(s));

    //下位の桁から計算していく
    rep(i, s.size()){
        int c;
        if(s[i] == '?') c = -1;
        else c = (s[i] - '0');

        // ?を10通り試す
        rep(j, 10){
            if(c != -1 && c != j) continue;
            //余りのパターンを13通り試す
            rep(k, 13){
                dp[i+1][(j*mul + k) % 13] += dp[i][k];
            }
        }

        //更新したところのmodを取る
        rep(j, 13) dp[i+1][j] %= mod;

        mul *= 10;
        mul %= 13;
    }

    cout << dp[s.size()][5] << endl;

    return 0;
}

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


typedef long long ll; 
const int mod=1e9+7; 
const int nax=2e5+5; 

int mul(int a, int b){
  return (ll)a*b%mod; 
}
void add_self(int &a, int b){
  a+=b; 
  if(a>= mod) a-=mod; 
}

int fac[nax], ifac[nax], inv[nax]; 
void init(){
  fac[0]=1; 
  for(int i=1;i<nax;i++){
    fac[i]=mul(fac[i-1],i); 
  }
  ifac[0]=ifac[1]=1;
  inv[1]=1; 
  for(int i=2;i<nax;i++){
    int q=mod/i, r=mod%i; 
    inv[i]=-1*mul(q,inv[r]);  
    add_self(inv[i],mod); 
    ifac[i]=mul(ifac[i-1],inv[i]); 
  }
}

int ways(int a, int b, int c, int d){
  if(a>c || b>d) return 0; 
  int rows=c-a, cols=d-b; 
  int ret=mul(fac[rows+cols],mul(ifac[rows],ifac[cols])); 
  return ret; 
}

int main(){
  int h,w,a,b; 
  cin>>h>>w>>a>>b; 
  init(); 
  int ans=0; 
  for(int i=1;i<=h-a;i++){
    if(i!=h-a)
      add_self(ans,mul(ways(1,1,i,b+1),ways(i,b+2,h,w))); 
    else 
      add_self(ans,mul(ways(1,1,i,b+1),ways(i,b+1,h,w))); 
  }
  cout<<ans<<endl; 
}

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

using namespace std;

int s(int n) {
  int a = 0;
  while (n) {
    a += n % 10;
    n /= 10;
  }
  return a;
}

int main() {
  int n;
  cin >> n;
  cout << (n % s(n) ? "No\n" : "Yes\n");
  return 0;
}


Measured memory_bytes: 256