akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

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

    int a[4][13] = {
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
    };
    for (int i = 0; i < n; i++) {
        char mark;
        int number;
        cin >> mark >> number;
        if (mark == 'S') {
            a[0][number-1] = 1;
        } else if (mark == 'H') {
            a[1][number-1] = 1;
        } else if (mark == 'C') {
            a[2][number-1] = 1;
        } else {
            a[3][number-1] = 1;
        }
    }

    int cnt = 0;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 13; j++) {
            if (cnt == 52 - n) {
                break;
            }
            if (a[i][j] == 0) {
                char mark;
                if (i == 0) {
                    mark = 'S';
                } else if (i == 1) {
                    mark = 'H';
                } else if (i == 2) {
                    mark = 'C';
                } else {
                    mark = 'D';
                }
                cout << mark << " " << j+1 << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3108
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <valarray>
#include <utility>
#include <numeric>
#include <memory>
#include <functional>
#include <stdexcept>
#include <typeinfo>
#include <limits>
#include <complex>
#include <locale>
using namespace std;
const int inf=2e9;
string s;
int p=0,h;
string k="KIHBR";
int main()
{
	cin>>s;
	if ((int)s.size()>9)
	{
		cout<<"NO";
		return 0;
	}
	for (auto x:s)
	{
		if (x==k[p])
		{
			p++;
			h=0;
		}
		else
		{
			if (x!='A')
			{
				cout<<"NO" ;
				return 0;
			}
			h++;
		}
		if (h>=2)
		{
			cout<<"NO";
			return 0;
		}
		else
		{
			if (h==1 && (p==1 || p==2))
			{
				cout<<"NO";
				return 0;
			}
		}
	}
	if (p==5)
	{
		cout<<"YES";
	}
	else
	{
		cout<<"NO";
	}
	return 0;
}

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

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

  int n, m, x;
  cin >> n >> m >> x;
  vector<pair<int, vector<int>>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second.resize(m);
    for (auto &j : a[i].second) cin >> j;
  }

  int ans = 1e8;
  for (int mask = 0; mask < (1 << n); mask++) {
    int cost = 0;
    vector<int> skill(m);
    for (int i = 0; i < n; i++) {
      if (mask & (1 << i)) {
        for (int j = 0; j < m; j++) {
          skill[j] += a[i].second[j];
        }
        cost += a[i].first;
      }
    }
    bool can = 1;
    for (int j = 0; j < m; j++) {
      if (skill[j] < x) can = 0;
    }
    if (can) {
      ans = min(ans, cost);
    }
  }
  
  if (ans == (int) 1e8) {
    ans = -1;
  }

  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;


int main()
{ios_base::sync_with_stdio(false);
ll a,b;
cin>>a>>b;
ol((a*b)/__gcd(a,b));
return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
typedef long long ll;

int main(){
  int n,ans=0;
  cin>>n;
  int x[n];
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  sort(x,x+n);
  reverse(x,x+n);
  cout<<x[n/2-1]-x[n/2]<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

#define Whats(x) cout<<#x<<" is "<<(x)<<endl
#define Divhim() cout<<">>>>>>>>>"<<endl
#define Divher() cout<<"<<<<<<<<<"<<endl
#define Oops() cout<<"!!!!!!!!!!"<<endl

template<typename T> bool Getmax(T &a,T b){return (a<b)?(a=b,true):false;}
template<typename T> bool Getmin(T &a,T b){return (a>b)?(a=b,true):false;}

const int N=2e5+10;

int n;

int fir[N],ne[N*2],to[N*2],tote;
void Adde(int u,int v)
{
	to[++tote]=v;ne[tote]=fir[u];fir[u]=tote;
	to[++tote]=u;ne[tote]=fir[v];fir[v]=tote;
}

int dep[N];

void Dfs(int u,int fa=0)
{
	dep[u]=dep[fa]+1;
	for(int i=fir[u],v;i;i=ne[i])if((v=to[i])!=fa)
		Dfs(v,u);
}

void Out(int a)
{
	if((a-2)%3)puts("First");
	else puts("Second");
}

int main()
{
	scanf("%d",&n);
	for(int i=1,u,v;i<n;++i)
	{
		scanf("%d%d",&u,&v);
		Adde(u,v);
	}
	Dfs(1);
	int a=0;
	for(int i=1;i<=n;++i)if(dep[i]>dep[a])a=i;
	Dfs(a);
	for(int i=1;i<=n;++i)if(dep[i]>dep[a])a=i;
	Out(dep[a]);
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll K;
    cin>>K;
    if(K<=9){
        cout<< K <<"\n"; return;
    }
    vector<ll> A;
    rep(i,9){
        A.emplace_back(i+1);
    }
    ll now=9;
    ll ima=9;
    rep(i,64){
        vector<ll> B;
        bool ok=false;
        for(auto x: A){
            if(x%10==0){
                ++now; ima=x*10; B.emplace_back(ima);
                if(now==K) {ok=true; break;}
                ++now; ima+=1; B.emplace_back(ima);
                if(now==K) {ok=true; break;}
            }
            else if(x%10!=9){
                ++now; ima=x*10+x%10-1; B.emplace_back(ima);
                if(now==K) {ok=true; break;}
                ++now; ima+=1; B.emplace_back(ima);
                if(now==K) {ok=true; break;}
                ++now; ima+=1; B.emplace_back(ima);
                if(now==K) {ok=true; break;}
            }
            else{
                ++now; ima=x*10+x%10-1; B.emplace_back(ima);
                if(now==K) {ok=true; break;}
                ++now; ima+=1; B.emplace_back(ima);
                if(now==K) {ok=true; break;}
            }
        }
        if(ok){
            cout<< ima <<"\n"; return;
        }
        A.clear();
        A=B;
    }

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
    static void Main(){
        int n = int.Parse(Console.ReadLine());
        long[] a = new long[n];
        for (int i = 0;i < n;i++)
            a[i] = long.Parse(Console.ReadLine());
        bool f = false;
        for (int i = 0;i < n;i++)
            f = f || a[i] % 2 == 1;
        Console.WriteLine(f ? "first" : "second");
    }
}

Measured memory_bytes: 15712
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,K = MI()
A = [0] + LI()

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


Measured memory_bytes: 105732
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int N,R,p,c;
int main() {
  while(cin >> N >> R && N>0){
    vector<int> a(N);
    for(int i=0;i<N;i++){
      a[i] = N-i;
      //cout << a[i] << endl;
    }
    for (int i=0; i<R;++i){
      cin >> p >> c;
      rotate(a.begin(),a.begin()+p-1,a.begin()+p-1+c);
      for(int j=0;j<a.size(); j++){
	//cout << a[j] << endl;
      }
    }
    cout << a[0] << endl;
  }
}

Measured memory_bytes: 3152
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
using namespace std;
int main(){
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    if(a < b&&b <= a+x)
        printf("safe");
    if(b <= a)
        printf("delicious");
    if(b >= a + x + 1)
        printf("dangerous");
}


Measured memory_bytes: 256
// In the name of God

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

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

const int maxn=4010,mod=998244353;
const ll inf=1e18;

int ans[maxn],fac[maxn],ifac[maxn],tw[maxn];

int Pow(int a,int b){
    int ans=1;
    while(b){
	if(b&1)	ans=1ll*ans*a %mod;
	a=1ll*a*a %mod;
	b>>=1;
    }
    return ans;
}

inline int C(int n,int k){
    if(n<k) return 0;
    return 1ll*fac[n]*ifac[k] %mod *ifac[n-k] %mod;
}

int solve(int n,int x){// x1+x2+x3+...+xn == x // xi>=0
    return C(n+x-1,n-1);
}

int main(){
    fac[0]=1;
    for(int i=1;i<maxn;i++)
	fac[i]=1ll*fac[i-1]*i %mod;
    ifac[maxn-1]=Pow(fac[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--)
	ifac[i]=1ll*ifac[i+1]*(i+1) %mod;
    tw[0]=1;
    for(int i=1;i<maxn;i++)
	tw[i]=2ll*tw[i-1] %mod;
    
    int k,n;cin>>k>>n;
    for(int i=2;i<=k+1;i++){
	int cnt=(i/2)-((i&1)==0);
	for(int j=0;j<=cnt;j++){
	    ans[i]=(1ll*ans[i]+1ll*C(cnt,j)*tw[j] %mod *(solve(k-2*(cnt-j)-j-((i&1)==0),n-j)+((i&1)?0:solve(k-2*(cnt-j)-j-1,n-j-1))))%mod;
	}
    }   
    
    for(int i=2;i<=k+1;i++)
	cout<<ans[i]<<"\n";
    for(int i=k;i>=2;i--)
	cout<<ans[i]<<"\n";
}


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

using namespace std;

int d[35][35];
int a[2][35];

int main() {
	int n, c;
	scanf("%d %d", &n, &c);
	for (int i = 1; i <= c; i++) {
		for (int j = 1; j <= c; j++) {
			scanf("%d", &d[i][j]);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int x;
			scanf("%d", &x);
			a[(i + j) % 3][x]++;
		}
	}
	int ans = 1e9;
	for (int i = 1; i <= c; i++) {
		for (int j = 1; j <= c; j++) {
			if (i == j) continue;
			for (int k = 1; k <= c; k++) {
				if (k == i || k == j) continue;
				int cur = 0;
				int c1 = i;
				int c2 = j;
				int c3 = k;
				for (int l = 1; l <= c; l++) {
					cur += a[0][l] * d[l][c1];		
				}			
				for (int l = 1; l <= c; l++) {
					cur += a[1][l] * d[l][c2];
				}
				for (int l = 1; l <= c; l++) {
					cur += a[2][l] * d[l][c3];
				}
				ans = min(ans, cur);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    edge = [list(map(int,input().split())) for _ in range(N)]
    for i in range(N):
        edge[i][i] = 10**10
        
    ans = 0
    for i in range(N):
        for j in range(i):
            d = min(a+b for a,b in zip(edge[i],edge[j]))
            if edge[i][j] > d:
                print(-1)
                exit()
            elif edge[i][j] < d:
                ans += edge[i][j]

    print(ans)    

if __name__ == "__main__":
    main()

Measured memory_bytes: 8692
r=range
h,*s=open(0)
h,w,k=map(int,h.split())
m=9e9
for i in r(1<<h-1):
 t,v,l=[],-1,1
 for j in r(h):z=i>>j&1;t+=[j+1]*z;l+=z
 t+=h,
 c=[0]*l
 for i in r(w):
  b=f=g=0;u=[]
  for j in r(l):d,b=sum(s[j][i]>"0"for j in r(b,t[j])),t[j];u+=d,;g|=d>k;c[j]+=d;f|=c[j]>k
  v+=f
  if f:c=u
 if g<1:m=min(m,v+l)
print(m)

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

int main(){

    vector<int> ABC(3);
    cin >> ABC[0] >> ABC[1] >> ABC[2];
    sort(ABC.begin(), ABC.end());

    int ans = 0;
    int min = ABC[0], mid = ABC[1], max = ABC[2];
    ans += max - mid;
    min += max - mid;
    if(min != max){
        ans += (max - min + 1) / 2;
        min += (((max - min + 1) / 2) * 2);
    }
    if(min != max){
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n ;
	cin >> n;
	auto v = vector<int>();
	auto c = vector<int>();
	
	for(int i=0;i<n;i++){
	    int num;
	    cin >> num;
	    v.push_back(num);
	}
	
	for(int i=0;i<n;i++){
	    int num;
	    cin >> num;
	    c.push_back(num);
	}
	
	int sum=0;    
	for(int i=0;i<n;i++){
	    if(v[i]-c[i]>=0){
	        sum+= v[i] -c[i];
	    }
	}
	
	cout  << sum;
	
	
	
}

Measured memory_bytes: 256
import io.StdIn._
object Main extends App {
  val Array(n, k) = readLine.split(" ").map(_.toInt)
  val Array(r, s, p) = readLine.split(" ").map(_.toInt)
  val t = readLine
  val map = Map('r' -> 'p', 's' -> 'r', 'p' -> 's')
  val point = Map('r' -> r, 's' -> s, 'p' -> p)
  val l = t.zipWithIndex.groupBy(_._2 % k).map(_._2.unzip._1)
  val res = l
    .map(r => {
      r.foldLeft((0, 'x'))((a, b) => {
          map(b) match {
            case win if win == a._2 => (a._1, 'x')
            case win                => (a._1 + point(win), win)
          }
        })
        ._1
    })
    .sum
  println(res)
}


Measured memory_bytes: 137020
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n;
		cin >> n;
		int h[100];
		for (int j = 0; j < n; j++) {
			cin >> h[j];
		}
		int max1 = 0, min1 = 0;
		for (int j = 1; j < n; j++) {
			if (h[j - 1] < h[j])max1 = max(max1, h[j] - h[j - 1]);
			if (h[j - 1] > h[j])min1 = max(min1, h[j - 1] - h[j]);
		//	cout << max1 << ' ' << min1 << endl;
		}
		cout << max1 << ' ' << min1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<string> S(N);
	vector<int> P(N);
	for(int i=0;i<N;i++){
		cin >> S[i] >> P[i];
	}
	vector<pair<pair<string, int>, int>> V(N);
	for(int i=0;i<N;i++){
		V[i].first.first = S[i];
		V[i].first.second = -1 *  P[i];
		V[i].second = i;
	}
	sort(V.begin(), V.end());
	for(int i=0;i<N;i++){
		cout << V[i].second + 1 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define SORT(i) sort((i).begin(),(i).end())
constexpr ll INF = 2000000000;
constexpr ll mod = 10e8 + 7;

int main() {
	string s;
	cin >> s;
	ll k;
	cin >> k;
	ll one = 0;
	rep(i, s.size()) {
		if (i == 0) {
			if (s[0] == '1')++one;
		}
		else {
			if (s[i - 1] == s[i])++one;
			else break;
		}
	}
	if (one >= k)cout << '1' << "\n";
	else cout << s[one] << "\n";

	return 0;
}

Measured memory_bytes: 256
def primes(n):
    '''
    素数テーブルの作成
    '''
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return is_prime

Q = int(input())

lenght = 10**5+100
prime = primes(lenght)
is_2017 = [0] * (lenght)
for i in range(1, lenght-1):
    if i%2==1 and prime[i] and prime[(i+1)//2]:
        is_2017[i] = is_2017[i-1] + 1
    else:
        is_2017[i] = is_2017[i-1]


for _ in range(Q):
    l, r = map(int, input().split())
    print(is_2017[r]-is_2017[l-1])


Measured memory_bytes: 52056
# import re
from sys import stdin
s = stdin.readline().rstrip()
# s_re = re.sub(s, '.', 'x')
# print(s_re)

# s = input()
s_list = list(s)
# print(s_list)
x_str = ''
for x in s_list:
    x_str += 'x'

print(x_str)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  string A, B, C;
  cin >> A >> B >> C;
  char next = 'a';
  char ans;
  for(;;) {
    if(next == 'a') {
      next = A.front();
      ans = 'A';
      if(A.length()) A.erase(0,1);
      else break;
    } else if (next == 'b') {
      next = B.front();
      ans = 'B';
      if(B.length()) B.erase(0,1);
      else break;
    } else if (next == 'c') {
      next = C.front();
      ans = 'C';
      if(C.length()) C.erase(0,1);
      else break;
    } else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] L = new int[N+1];
        for(int i = 0; i < N; i++){
            L[i] = sc.nextInt();
        }

        int ans = 0;
        L[N] = 10000;
        Arrays.sort(L);
        for(int i = 0; i < N; i++){
            int upper = i;
            for(int j = i + 1; j < N; j++){
                while(L[upper] < L[i] + L[j]){
                    upper++;
                }
                ans += upper - 1 - j;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 26168
#include<bits/stdc++.h>
using namespace std;
long long w[100005],v[100005],dp[100005],ans = 0;
int main(){
    int N,W;
    cin >> N >> W;
    for(int i = 0;i < N;i++){
        cin >> w[i] >> v[i];
    }
    for(int i = 0;i < N;i++){
        for(int j = W;j >= 0;j--){
            if(j+w[i]<=W){
                dp[j+w[i]]=max(dp[j+w[i]],dp[j]+v[i]);
            }
        }
    }
    for(int i = 0;i <= W;i++){
        ans = max(ans,dp[i]);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define MOD 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,k;
    cin>>n>>k;

    if(k/2 >= n){
        cout<<n<<"\n";
    }else if(n % k == 0){
        cout<<"0"<<"\n";
    }else if (n%k > 0){
        if(k/2 < n%k){
            cout<<abs((n%k)-k)<<"\n";
        }else{
            cout<<n%k<<"\n";
        }
    }

    
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 200000, MAX_C = 200000;
const ll MOD = 1000000007;
int n;
int c[MAX_N];
ll dp[MAX_N];
int last[MAX_C+1];

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  fill_n(last,MAX_C+1,-1);

  cin >> n;
  forn (i,n) cin >> c[i];

  n = unique(c,c+n) - c;

  last[c[0]] = 0;
  dp[0] = 1;

  forn1 (i,n-1) {
    dp[i] = dp[i-1];
    if (last[c[i]] >= 0) {
      dp[i] = (dp[i] + dp[last[c[i]]]) % MOD;
    }
    last[c[i]] = i;
  }

  cout << dp[n-1] << "\n";

  return 0;
}


Measured memory_bytes: 3328
while True:
    line = input().split(" ")
    a0 = int(line[0])
    L = int(line[1])
    if a0 == 0 and L == 0:
        break
    #print(a0)
    a_list = [a0]
    a0 = str(a0).zfill(L)
    sortedA =  sorted(a0)
    minNum = int("".join(sortedA))
    sortedB =  sorted(a0, reverse=True)
    maxNum = int("".join(sortedB))
    a = maxNum - minNum
    j = 1
    while not(a in a_list):
        j += 1
        a_list.append(a)
        a = str(a).zfill(L)
        sortedA =  sorted(a)
        minNum = int("".join(sortedA))
        sortedB =  sorted(a, reverse=True)
        maxNum = int("".join(sortedB))
        a = maxNum - minNum
    index = a_list.index(a)
    print(index, a, j-index)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
string a,b;
int dp[3005][3005];
string bus(int x,int y){
    string res="";
    while(x and y){
        if(a[x-1]==b[y-1]){
            res+=a[x-1];
            x--;y--;
        }else{
            if(dp[x][y-1]>dp[x-1][y])y--;
            else x--;
        }
    }
    reverse(res.begin(),res.end());
    return res;
}
int main(){
    int maxi=0,x,y;
    cin>>a>>b;
    for(int i=1;i<=a.size();i++){
        for(int j=1;j<=b.size();j++){
            if(a[i-1]==b[j-1])dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    cout<<bus(a.size(),b.size());
    return 0;
}


Measured memory_bytes: 35584
#include<stdio.h>

int main(void)
{
	int m;
	char s[11];
	scanf("%s",s);
	m=(s[5]-'0')*10+s[6]-'0';
	if(m<=4)
		printf("Heisei");
	else
		printf("TBD");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    vector<vector<int> > v(3, vector<int>(3));
    for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) cin >> v[i][j];

    vector<int> a(3), b(3);
    for (int i = 0; i <= 100; i++) {
        a[0] = i;
        b[0] = v[0][0] - a[0];
        for (int j = 1; j <= 2; j++) {
            a[j] = a[0] - (v[0][0] - v[j][0]);
            b[j] = b[0] - (v[0][0] - v[0][j]);
        }
        bool can = true;
        for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++)
            if (v[i][j] != a[i] + b[j]) can = false;
        if (can) {
            cout << "Yes" << '\n';
            return 0;
        }
    }

    cout << "No" << '\n';
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 計算
long long
fCalc(
	int piMax					// <I> 最大値
	, int piMod					// <I> 余り
)
{
	int i;

	// 余り有無
	if (piMod < 1) {
		return (long long)piMax * (long long)piMax;
	}

	// b が余りを超える
	long long llCnt = 0;
	for (i = piMod + 1; i <= piMax; i++) {

		// 繰り返し回数
		int liCnt = piMax / i;
		llCnt += (long long)(i - piMod) * (long long)liCnt;

		// 繰り返さない部分
		int liLen = piMax % i;
		if (liLen < 1) {
			continue;
		}
		liLen -= piMod - 1;
		if (liLen < 1) {
			continue;
		}
		llCnt += (long long)liLen;
	}

	return llCnt;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 最大値・余り取得
	int liMax, liMod;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d%d", &liMax, &liMod);

	// 計算
	long long llCnt = fCalc(liMax, liMod);

	// 結果セット
	sprintf(lc1Out, "%lld\n", llCnt);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

string S;
int main(){
    cin>>S;
	ll ans=0;
	if(S[0]!=S[1])ans++;
	if(S[1]!=S[2])ans++;
	if(ans>0){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
    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++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

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

  rep(j, 2){
    rep(k, 2){
      string ans = s;
      ans[0] = j ? 'S' : 'W';
      ans[1] = k ? 'S' : 'W';
      repi(i, 1, n-1){
        if((s[i] == 'o' and ans[i] == 'S') or (s[i] == 'x' and ans[i] == 'W')){
          ans[i+1] = ans[i-1]; 
        }else{
          ans[i+1] = ans[i-1] == 'S' ? 'W' : 'S'; 
        }
      }

      if((s[0] == 'o' and ans[0] == 'S') or (s[0] == 'x' and ans[0] == 'W')){
        if(ans[n-1] != ans[1]){
          continue;
        }
      }else{
        if(ans[n-1] == ans[1]){
          continue;
        }
      }

      if((s[n-1] == 'o' and ans[n-1] == 'S') or (s[n-1] == 'x' and ans[n-1] == 'W')){
        if(ans[n-2] == ans[0]){
          cout << ans << endl;
          return 0;
        }
      }else{
        if(ans[n-2] != ans[0]){
          cout << ans << endl;
          return 0;
        }
      }
    }
  }

  cout << -1 << endl; 

  return 0;
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int,input().split()))
MOD = 10 ** 9 + 7
digit = 60
o=[0]*digit
z=[0]*digit

for i in a:
  for j in range(digit):
    if (i >> j) & 1:
      o[j] += 1
    else:
      z[j] += 1
ans = 0    
for j in range(digit):
  ans += (o[j]*z[j]*pow(2,j,MOD))
print(ans % MOD)

Measured memory_bytes: 124456
n = int(input())
x = list(map(int, input().split()))
x_sorted = sorted(x)
target = x_sorted[n // 2 - 1]

for num in x:
    if num <= target:
        print(x_sorted[n // 2])
    else:
        print(x_sorted[n // 2 - 1])


Measured memory_bytes: 25620
#include <cstdio>
#include <algorithm>

using namespace std;

int n;
int h[100021][21];
int dp[100021][21];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%d%d%d", &h[i][1], &h[i][2], &h[i][3]);
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= 3; ++j) {
            for (int k = 1; k <= 3; ++k) {
                if(j == k) continue;
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + h[i][j]);
            }
        }
    }
    printf("%d\n", max(dp[n][1], max(dp[n][2], dp[n][3])));
    return 0;
}

Measured memory_bytes: 16512
import java.util.*

fun main(args: Array<String>){
    val sc = Scanner(System.`in`)
    val r = sc.nextInt()
    val D = sc.nextInt()
    val x2000 = sc.nextInt()
    val list = mutableListOf<Int>(x2000)

    for(x in 0..9){
        list.add(r*list[x] - D)
        println(list[x+1])
    }
}

Measured memory_bytes: 31008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	ll a,b;
	cin>>a>>b;
	for(ll i=1;i<=10000000;i++)
	{
		if(max(a,b)*i%min(a,b)==0)
		{
			cout<<max(a,b)*i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const unsigned int mod=1000000007;
int main() {
    int h,w;
    cin>>h>>w;
    int arr[h+1][1001];
    for(int i=1;i<=h;i++) {
        for(int j=1;j<=w;j++) {
            char x;
            cin>>x;
            if(x=='.') arr[i][j]=1;
            else arr[i][j]=0;
        }
    }
    long long dp[h+1][w+1]={0};
    dp[1][1]=1;
    for(int i=1;i<=h;i++) {
        for(int j=1;j<=w;j++) {
            if(arr[i][j]==1 && i-1>0 && j-1>0) {
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
            }
            else if(arr[i][j]==1 && i-1>0)
                dp[i][j]=(dp[i-1][j])%mod;
            else if(arr[i][j]==1 && j-1>0)
                dp[i][j]=(dp[i][j-1])%mod;
        }
    }
    cout<<dp[h][w];
    return 0;
}


Measured memory_bytes: 12032
#include <stdio.h>
#include <stdlib.h>

#define MAX_DATA_NUM      100

static void Exchange_Void(int *pSortBuff, int insert, int key );

int main(void)
{
    int data_num;			/* Data Num */
	int cd;					/* Count Data */
	int key = 0;			/* Compare Num */
	int *pSortBuff;
	int insert;
	int loop;
   
    pSortBuff = (int *)malloc(sizeof(int) * MAX_DATA_NUM);
    /* get "Data Num" */
    scanf("%d", &data_num);
     
    /* get Name & time */
    while((scanf("%d", &(pSortBuff[cd])) != EOF) && cd < MAX_DATA_NUM)
    {
        cd++;
    }
    
	
    /* get Data Num equal process num */
    if( data_num == cd )
    {
         while(key < data_num)
        {
        	if(key>0)
        	{
        		insert = -1;
	        	for(loop=key-1; loop>=0; loop--)
	        	{
	        		if(pSortBuff[loop] > pSortBuff[key])
	        		{
	        			insert = loop;
	        		}
	        	}
        		if(insert != -1)
        		{
        			Exchange_Void(pSortBuff, insert, key);
        		}
        	}
        	// print
			for(loop=0; loop<data_num-1; loop++)
			{
				printf("%d ", pSortBuff[loop]);
			}
        	printf("%d\n", pSortBuff[data_num-1]);
			key++;
        }
    }
    else
    {
        /* error input */
    }
	free(pSortBuff);
    return 0;
}

static void Exchange_Void(int *pSortBuff, int insert, int key )
{
	int swap;
	int loop;
	
	swap = pSortBuff[key];
	
	for(loop=key; loop>insert; loop--)
	{
		pSortBuff[loop] = pSortBuff[loop-1];
	}
	pSortBuff[insert] = swap;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector<int> mid(0);
    string ans = "IMPOSSIBLE";
    for(int i = 0;i < m;i ++){
        int a,b;
        cin >> a >> b;
        if(a==1) mid.push_back(b);
        if(b==n) mid.push_back(a);
    }
    sort(mid.begin(),mid.end());
    for(int i = 0;i < mid.size()-1;i ++){
        if(mid[i]==mid[i+1]) {ans = "POSSIBLE";break;}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(i*500+j*100+k*50==x){
          ans ++;
        }
      }
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int a, b;
  int gcd;

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

  if( a > b ) {
    gcd = a % b;
    while(1) {
      if(((b % gcd) == 0) && (((a % b) % gcd) == 0)) break;
      else gcd--;
    }
  }
  else if( a < b ) {
    gcd = b % a;
    while(1) {
      if(((a % gcd) == 0) && (((b % a) % gcd) == 0)) break;
      else gcd--;
    }
  }
  else gcd = a;

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

  return 0;

}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define sz(s) (ll)s.size()
#define print(d) cout << fixed << setprecision(15) << d
#define pii pair<ll,ll>
#define ppii pair<ll,pii>
#define ff first
#define ss second
const ll MOD = 1000000007;
const ll MAXN = 1e6 + 5;
const ll inf = 2e18;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
tree_order_statistics_node_update> ord_set;
#define debug(x) cerr << #x << " = " << x << endl


ll power(ll x, ll y, ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
  
    return (y%2 == 0)? p : (x * p) % m; 
} 



int main()
{
  fast
  ll h;
  cin >> h;
  ll n;
  cin >> n;
  ll arr[n+1];
  ll cost[n+1];
  fr(i,0,n)cin >> arr[i+1],cin>>cost[i+1];
  ll dp[h+1][n+1];
  fr(i,0,h+1)
  {
    fr(j,0,n+1)
    {
       dp[i][j]=inf;
       if(i==0)dp[i][j]=0;
       else if(j==0)dp[i][j]=inf;
       else if(i>=arr[j])
       {
         dp[i][j]=min(dp[i - arr[j]][j]+cost[j],dp[i][j-1]);
       }
       else
         dp[i][j]=min(dp[i][j-1],cost[j]);
    }
  }
  cout << dp[h][n];
    return 0;

}










Measured memory_bytes: 78464
#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	set<char> c(all(s));

	if (c.size()%2) {
		cout << "No" << endl;
	}
	else if (c.size()==4) {
		cout << "Yes" << endl;
	}
	else if(*c.begin()=='E' && *++c.begin()=='W'){
		cout << "Yes" << endl;
	}
	else if (*c.begin() == 'N' && *++c.begin() == 'S') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int m, n;
int w[110];

bool check(int mid) {
  int sum = 0, res = 1;
  for (int i = 0; i < n; i++) {
    if (w[i] > mid) return false;
    if (sum + w[i] > mid) sum = w[i], res++;
    else sum += w[i];
  }
  return res <= m;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  while (cin >> m >> n, m) {
    for (int i = 0; i < n; i++) {
      cin >> w[i];
    }
    int ng = 0, ok = 1500000;
    while (ok - ng > 1) {
      int mid = (ng + ok) / 2;
      if (check(mid)) ok = mid;
      else ng = mid;
    }
    cout << ok << endl;
  }

  return 0;
}


Measured memory_bytes: 3184
import itertools
import numpy as np
N,M,X=map(int,input().split())
lista=[]
for i in range(N):
    lista.append(list(map(int,input().split())))
lista=np.array(lista)
cost=1000000000000000
judge=[X]*M
data=[k for k in range(1,N+1)]
for i in range(1,N+1):
    a=list(itertools.combinations(data,i))
    for j in a:
        clist=np.array([0]*(M+1))
        for k in j:
            clist=clist+lista[k-1]
        if all(clist[1:]>=judge):
            if clist[0]<cost:
                cost=clist[0]
                m=j
c=0
try:
    for i in m:
        c+=lista[i-1][0]

    print(c)
except:
    print(-1) 

Measured memory_bytes: 27684
import java.util.*;

class Main {
        public static void main(String args[]) {
                int[] ans = new int[26];
                try (Scanner sc = new Scanner(System.in)) {
                        while (sc.hasNextLine()) {
                                String S = sc.nextLine();
                                for (int i = 0; i < S.length(); i++) {
                                        if (0 <= S.charAt(i) - 'a' && S.charAt(i) - 'a' < 26) {
                                                ans[S.charAt(i) - 'a']++;
                                        } else if (0 <= S.charAt(i) - 'A' && S.charAt(i) - 'A' < 26) {
                                                ans[S.charAt(i) - 'A']++;
                                        }
                                }
                        }
                }
                for (int i = 0; i < 26; i++) {
                        System.out.printf("%c : %d\n", i + 'a', ans[i]);
                }
        }
}

Measured memory_bytes: 26400
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <memory.h>
#include <set>
#include <cmath>
#define fio ios::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int n, a, b, c, paint[100'005];
int chk[100'005];
vector<pii> gph[100'005];
pii p[100'005];
void dfs(int x) {
	chk[x] = true;
	for (pii e : gph[x]) {
		int nx = e.first, nc = e.second;
		if (!chk[nx]) {
			p[nx] = { x, nc };
			dfs(nx);
		}
	}
}
void go(int x) {
	chk[x] = false;
	for (pii e : gph[x]) {
		int nx = e.first, nc = e.second;
		if (chk[nx]) {
			int pnx = p[nx].first, pnc = p[nx].second;
			int ppnx = p[pnx].first, ppnc = p[pnx].second;
			if (ppnx != -1 && pnc % 2 && ppnc % 2) {
				paint[nx] = paint[ppnx];
			}
			else if (pnc % 2 == 0) {
				paint[nx] = paint[pnx];
			}
			else {
				paint[nx] = !paint[pnx];
			}
			go(nx);
		}
	}
}
int main(void){
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		scanf("%d %d %d", &a, &b, &c);
		gph[a].push_back({ b, c });
		gph[b].push_back({ a, c });
	}
	p[1] = { -1, -1 };
	paint[1] = 0;
	dfs(1);

	go(1);
	for (int i = 1; i <= n; i++) {
		printf("%d\n", paint[i]);
	}
	return 0;
}

Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> store;
	for(int i=0;i<=n;i++)
	{
		int temp;
		cin>>temp;
		store.push_back(temp);
	}

	sort(store.begin(), store.end());
	int mgcd=0;
	for(int i=1;i<store.size();i++)
	{
		mgcd=__gcd(mgcd,store[i]-store[i-1]);
	}
	cout<<mgcd<<endl;
}

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

typedef long long lint;

lint f(lint b,lint n){
    if(n<b) return n;
    return f(b,n/b)+n%b;
}

int main(){
    lint n,s;
    cin >> n >> s;

    if(s==n){
        cout << (n+1) << endl;
        return 0;
    }
    if(s>n){
        cout << "-1" << endl;
        return 0;
    }
    for(lint i=2;i<=sqrt(n)+1;i++){
        if(f(i,n)==s){
            cout << i << endl;
            return 0;
        }
    }

    lint min=-1;
    for(lint x=1;x<=sqrt(n-s);x++){
        if((n-s)%x!=0) continue;
        if(x>s) continue;
        lint b=(n-s)/x+1, y=s-x;
        if(x<b && y<b && b*x+y==n){
            if(min<0 || min>b) min=b;
        }
    }

    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()

l = [0]*len(S)

l[0] = 1

if S[0] != S[1]:
  l[1] = 2
else:
  l[1] = 1

for i in range(2,len(S),1):
  if S[i] != S[i-1]:
    l[i] = l[i-1]+1
  else:
    l[i] = l[i-3]+2
print(l[len(l)-1])

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

int main() {
  string s;
  cin >> s;
  int c =0;
  if(s == "RRS" || s =="SRR") c=2;
  else if(s == "RRR") c=3;
  else if(s == "SSS") c=0;
  else c=1;
  cout << c;
}



Measured memory_bytes: 3612
n = gets.to_i
a,b = 2.times.map{Array.new(n)}
n.times do |i|
    a[i],b[i] = gets.split.map(&:to_i)
end
ans = 0
c = 0
(n-1).downto(0) do |i|
    ans += (b[i]-a[i]-c)%b[i]
    c += (b[i]-a[i]-c)%b[i]
end
puts ans

Measured memory_bytes: 3324
f x y z
  | x + y - z<= 0 = "0" ++ " " ++ "0"
  | x + y - z > 0 = if z - x >= 0 then "0" ++ " " ++  show(y-(z-x)) else show(x - z) ++ " "++ show(y) 
main = do
 [a,b,c] <- map read . words <$> getLine
 putStrLn $ f a b c

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector<vector<ll>> x(3, vector<ll>(n));

  REP(j, n) REP(i, 3) { cin >> x[i][j]; }

  const ll INF = 1e18;
  ll ans = -INF;
  REP(bit, (1LL << 3)) {
    vector<ll> c(3, 1);
    REP(i, 3) {
      if (bit & (1LL << i)) {
        c[i] = -1;
      }
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, -INF));
    dp[0][0] = 0;
    REP(i, n) REP(j, m + 1) if (dp[i][j] != -INF) {
      chmax(dp[i + 1][j], dp[i][j]);
      if (j + 1 <= m) {
        ll ad = 0;
        REP(k, 3) { ad += c[k] * x[k][i]; }
        chmax(dp[i + 1][j + 1], dp[i][j] + ad);
      }
    }

    ans = max(ans, dp[n][m]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 8200
#from pprint import pprint
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from copy import deepcopy
#from itertools
#import sys 
#sys.setrecursionlimit(N) #N回まで再起を許可する。

# = map(int,input().split())

# = list(map(int,input().split()))

# = [list(map(int,input().split())) for _ in range(XXXX)]

t = list(input())

#print(t)

#pdはプラス2カウントできるので、できるだけpdを作るように置き換える。


for i in range(len(t)):
    if t[i] == "?":
        if i == len(t)-1:
            t[i] = "D"
        elif i == 0:
            if t[i+1] == "D":
                t[i] = "P"
            else:
                t[i] = "D"
        elif t[i-1] == "P":
            t[i] = "D"
        elif t[i+1] == "P":
            t[i] = "D"
        elif t[i+1] == "D":
            t[i] = "P"
        elif t[i+1] == "?":
            t[i] = "P"
            t[i+1] = "D"

print("".join(t))

Measured memory_bytes: 10872
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
typedef pair<ll, ll> LP;
 
ll POW(ll m,ll n)
{
  if(n<0) return 0;
  if(n==0) return 1;
  return m*POW(m,n-1)%MOD;
}
 
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a, ll m) {
    ll x, y;
    extGCD(a, m, x, y);
    return mod(x, m);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return m%MOD*COM(m-1,n)%MOD*modinv(m-n,MOD)%MOD;
}
 

int main()
{
  char c[5];
  cin >> c[0] >> c[1] >> c[2];
  rep(i,3){if(c[i]=='1')c[i]='9';
           else if(c[i]=='9')c[i]='1';
          }
  printf("%c%c%c",c[0],c[1],c[2]);
}

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

using namespace std;

int main() {
    int h, w;
    cin >> h >> w;

    for (int i = 0; i < w + 2; i++) {
        cout << "#";
    }
    cout << endl;

    for (int i = 0; i < h; i++) {
        string a;
        cin >> a;
        cout << "#" << a << "#" << endl;
    }

    for (int i = 0; i < w + 2; i++) {
        cout << "#";
    }
    cout << endl;
}


Measured memory_bytes: 256
n = gets.to_i
MOD = 10**9+7
#前処理 O(n)
$fact,$fact_inv,$inv = Array.new(n+1),Array.new(n+1),Array.new(n+1)
$fact[0] = $fact[1] = 1
$fact_inv[0] = $fact_inv[1] = 1
$inv[1] = 1
for i in 2..n
  $fact[i] = $fact[i-1] * i % MOD
  $inv[i] = MOD - $inv[MOD % i]*(MOD/i) % MOD
  $fact_inv[i] = $fact_inv[i-1] * $inv[i] % MOD
end
#クエリ O(1)
def nCkMOD(n,k)
  $fact[n]*($fact_inv[k]*$fact_inv[n-k] % MOD) % MOD
end


ans = 0
for j in 1..(n/3)
  ans += (nCkMOD(n-2*j-1,j-1))
  ans %= MOD
end
puts ans

Measured memory_bytes: 14408
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	a,b,c = MI()
	if((a==b and b!=c) or (a==c and a!=b) or (b==c and b!=a)):
		print("Yes")
	else:print("No")


if __name__ == '__main__':
	main()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

int main()
{
  ll n; cin >> n;
  ll k; cin >> k;
  vector<ll> d1(n+1, 0);
  for (int i=0; i<n; i++){
    cin >> d1[i];
  }

  while (k--) {
    vector<ll> d2(n+1, 0);
    rep(i, n) {
      d2[max(0LL, i-d1[i])]++;
      d2[min(n, i+d1[i]+1)]--;
    }
    ll mi = inf;
    rep(i, n) {
      d2[i+1] += d2[i];
      mi = min(mi, d2[i]);
    }
    d1 = d2;
    if (mi == n) break;
  }
  for (int i=0; i<n; i++) {
    if (i>0) cout << " ";
    cout << d1[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 6424
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    if (N % K == 0) {
      System.out.println(0);
    } else {
      System.out.println(1);
    }
  }
}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main(){
	int S;
	int h,m,s;
	cin>>S;
	h=S/3600;
	m=S/60-h*60;
	s=S-h*3600-m*60;
	cout<<h<<":"<<m<<":"<<s<<endl;
	return 0;
}

Measured memory_bytes: 1164