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

const int INF = 100000000;

int main(){
	int n,ma,mb;
	int a[40],b[40],c[40];
	int p[201][201];
	int q[201][201];
	int z,k;
	scanf("%d %d %d",&n,&ma,&mb);
	z = n / 2;
	k = n - z;
	for(int i=0;i<z;i++) scanf("%d %d %d",a+i,b+i,c+i);
	fill(p[0],p[0]+201*201,INF);
	fill(q[0],q[0]+201*201,INF);
	for(int i=0;i<(1<<z);i++){
		int sum_a = 0, sum_b = 0, cost = 0;
		for(int j=0;j<z;j++){
			if((i>>j)&1){
				sum_a += a[j];
				sum_b += b[j];
				cost += c[j];
			}
		}
		p[sum_a][sum_b] = min(cost,p[sum_a][sum_b]);
	}
	for(int i=0;i<k;i++) scanf("%d %d %d",a+i,b+i,c+i);
	for(int i=0;i<(1<<k);i++){
		int sum_a = 0, sum_b = 0, cost = 0;
		for(int j=0;j<k;j++){
			if((i>>j)&1){
				sum_a += a[j];
				sum_b += b[j];
				cost += c[j];
			}
		}
		q[sum_a][sum_b] = min(cost,q[sum_a][sum_b]);
	}
	int ans = INF;
	int ponpoko = max(ma,mb);
	for(int i=1;i*ponpoko<=400;i++){
		int yamada = min(ma*i,200);
		int suzuki = min(mb*i,200);
		for(int j=max(ma*i-200,0);j<=yamada;j++){
			for(int k=max(mb*i-200,0);k<=suzuki;k++){
				ans = min(ans,p[j][k]+q[ma*i-j][mb*i-k]);
			}
		}
	}
	if(ans==INF) printf("-1\n");
	else printf("%d\n",ans);
	/*
	while(true){
		int usi,uma,usa;
		scanf("%d %d %d",&usi,&uma,&usa);
		if(usi==0&&uma==0&&usa==0) return 0;
		if(usi==1) printf("p[%d][%d] = %d\n",uma,usa,p[uma][usa]);
		if(usi==2) printf("q[%d][%d] = %d\n",uma,usa,q[uma][usa]);
	}
	*/
}


Measured memory_bytes: 512
import java.io.PrintWriter;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		char[] s = sc.next().toCharArray();
		int K = sc.nextInt();
		int N = s.length;
		
		for(int i=0; i<N; i++) {
			if(s[i]!='a' && 'z'-s[i]+1 <= K) {
				K -= 'z'-s[i]+1;
				s[i] = 'a';
			}
		}
		s[N-1] = (char)('a'+(((s[N-1]-'a')+K)%26));
		
		pw.println(s);
		
		sc.close();
		pw.close();
	}
}


Measured memory_bytes: 14152
// https://beta.atcoder.jp/contests/abc084

#define SUBMIT

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#include <unordered_map>
#include <map>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

int main() {
    int M;
    cin >> M;
    cout << 24 + (24 - M) << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    ll N, K;
    cin >> N >> K;
    ll M = (ll) 1e9 + 7;
    ll res = 0;
    for(ll k = K; k <= N + 1; k++) {
        ll tmp = 0;
        tmp += N * (N + 1) / 2LL;
        tmp -= (N - k) * (N - k + 1) / 2LL;
        tmp -= k * (k - 1) / 2LL;
        tmp++;
        res = (tmp + res) % M;
    }

    cout << res << endl;
}

Measured memory_bytes: 3636
N, K = map(int, input().split())
mod = 10 ** 9 + 7
P = [[0] * (K + 1) for i in range(N + 1)]
for i in range(1, N + 1):
	P[i][1] = 1
for i in range(1, min(N, K) + 1):
	P[i][i] = 1
for n in range(1, N + 1):
	for k in range(2, min(n - 1, K) + 1):
		P[n][k] = (P[n - k][k] + P[n - 1][k - 1]) % mod
print(P[N][K])



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

int main(){
  int A, B;
  cin >> A >> B;
  int count = 0;
  int check = 0;
  while(true){
    if(A > B){
      check += A;
      A --;
    }
    else {
      check += B;
      B --;
    }
    count ++;
    if(count == 2){
      break;
    }
  }
  cout << check << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int A, B;
  cin >> A >> B;
  cout << (A + B) % 24 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, A, B;
  cin>>N>>A>>B;
  ll h[N];
  for(int i=0;i<N;++i) cin>>h[i];
  ll maxh = 0;
  for(int i=0;i<N;++i) maxh = max(maxh, h[i]);
  ll l=1, r=inf, m;
  ll tmp;
  while(l<r) {
    m = (l+r)/2;
    tmp = 0;
    for(int i=0;i<N;++i) {
      if(h[i]-B*m<=0) continue;
      if((h[i]-B*m)%(A-B)==0) tmp += (h[i]-B*m)/(A-B);
      else tmp += (h[i]-B*m)/(A-B)+1;
    }
    if(tmp<=m) r = m;
    else l = m+1;
  }
  cout<<l<<endl;
}



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

int main() {
    string s; cin >> s;
    int res = 0;
    for(int i=0;i<s.size()/2;i++){
        if(s[i]!=s[s.size()-1-i])res++;
    }
    cout << res << endl;
}

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

int main(){
	int a, b;
	while(cin >> a >> b){
		int sum = a + b;
		int c = 0;
		while(sum > 0){
			c++;
			sum /= 10;
		}
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	int N, K, X, Y;
  	cin >> N >> K >> X >> Y;
  	if(N > K){
		cout << K*X + (N-K)*Y << endl;
    }
	else{
		cout << N*X << endl;
    }
	return;
}

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


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

int main() {

  int N, D;
  cin >> N >> D;

  vector<vector<int>> date(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> date.at(i).at(j);
    }
  }

  int A = N * (N - 1) / 2;
  vector<int> vec(A);
  int con = 0;

  for (int i = 0; i < N - 1; i++) {
    for (int j = 1; j < N; j++) {
      if (i >= j) continue;
      int X = 0;
      for (int k = 0; k < D; k++) {
        int Y = date.at(i).at(k) - date.at(j).at(k);
        X += Y * Y;
      }
      vec.at(con) = X;
      con++;
    }
  }

  int ans = 0;

  for (int i = 0; i < A; i++) {
    int X = floor(sqrt(vec.at(i)));
    if (X * X == vec.at(i)) ans++;
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

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

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

const int MAX = 220000;
int N;
string S;
int cB[MAX], cW[MAX];

int main(int argc, const char * argv[]) {
    cin >> N >> S;

    memset(cB, 0, N+1);
    memset(cW, 0, N+1);
    repd(i, 1, N+1) {
        if (S[i-1] == '.') {
            cW[i] = cW[i-1] + 1;
            cB[i] = cB[i-1];
        }
        else {
            cB[i] = cB[i-1] + 1;
            cW[i] = cW[i-1];
        }
        //printf("%d, %d\n", cB[i], cW[i]);
    }

    int ans = MAX;
    repd(i, 0, N+1) {
        int b = cB[i] - cB[0];
        int w = cW[N] - cW[i];
        int count = b+w;
        if (count < ans) {
            ans = count;
            //output(i);
        }
    }

    output(ans);
    return 0;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,m,ans=1e9+7;
char a[200005],b[200005];

signed main()
{
	string s1,s2;
	cin>>s1>>s2;
	n=s1.size();
	for (int i=1;i<=n;i++)  a[i]=s1[i-1];
	m=s2.size();
	for (int i=1;i<=m;i++)  b[i]=s2[i-1];
	
	for (int i=1;i<=n-m+1;i++)
	{
		int cnt=0;
		for (int j=i;j<=i+m-1;j++)
		{
			if (a[j]!=b[j-i+1])  cnt++;
		}
		ans=min(ans,cnt);
	}
	
	
	cout<<ans<<endl;
	
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1'000'000'007;

int main(){
    static ll dp[1002][1002];
    int H, W;
    cin >> H >> W;
    string a[1000];
    for(int i=0;i<H;i++) cin >> a[i];

    for(int i=0;i<=W+1;i++){
        for(int j=0;j<=H+1;j++){
            if(i==1 && j==1) dp[1][1] = 1;
            else if(i == 0 || i == W+1 || j == 0 || j == H+1 || a[j-1][i-1] == '#') dp[i][j] = 0;
            else dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
        }
    }

    cout << dp[W][H] << endl;
    
    return 0;
}

Measured memory_bytes: 9088
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main(int argc, char *argv[])
{
  int N, a[123456];

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

  int n = 0, inc = 0, ans = -1;
  for (int i = 0; i < 10000000; i++) {
    n = a[n]-1;
    inc++;
    if (n == 1){
      ans = inc;
      break;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int gcd(int a,int b);

int main(void){
    int A,B,C,D;
    int T,S;
    T=0;
    S=0;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    while(A>0){
        A=A-D; 
        T++;
    }
    while(C>0){
        C=C-B; 
        S++;
    }
    if (T>=S){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;

}

// 最大公約数
int gcd(int a,int b){
    int c;
    int tmp;
    if(b > a){  //bがaより大きい場合bとaを入れ替える
        c = a;
        a = b;
        b = c;
    }
    tmp = a % b;
    while(tmp!=0){
        a = b;
        b = tmp;
        tmp = a % b;
    }
    return b;
}


Measured memory_bytes: 1660
#include<stdio.h>
int adjust(int n){
    if (n % 1000 != 0)
        n += 1000 - n % 1000;
    return n;
}
int exec(int n){
    if (n <= 0)
        return 100000;
    else
        return adjust(1.05 * exec(n-1));
}
int main(){
    int n;
    scanf("%d", &n);
    printf("%d\n", exec(n));
    return 0;
}

Measured memory_bytes: 588
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int N,K,a=1,sum=1;
	cin>>N>>K;
	while(true){
		a*=K;
		if(N>=a)sum++;
		else break;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0},dy={0,1,0,-1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    ll N,K,a,b;
    cin>>N>>K;
    a=N%K;
    b=a-K;
    cout<<min(abs(a),abs(b))<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        sc.close();

        int all = 0;
        int min = Integer.MAX_VALUE;
        int eat = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            int taste = l + (i + 1) - 1;
//            System.out.println(taste);
            all += taste;
            if (Math.abs(taste) < min) {
                min = Math.abs(taste);
                eat = taste;
            }
        }
//        System.out.println(all);
        System.out.println(all - eat);
    }

}


Measured memory_bytes: 22732
#[allow(unused)]
use std::io::Write;

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    // 複数数字
    let (a, b, c): (usize, usize, usize) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        let mut ws = s.split_whitespace();
        let a = ws.next().unwrap().parse().unwrap();
        let b = ws.next().unwrap().parse().unwrap();
        let c = ws.next().unwrap().parse().unwrap();
        (a, b, c)
    };

    let str =
    if a + b + c >= 22 {
        "bust"
    } else {
        "win"
    };
    println!("{}", str);
}


Measured memory_bytes: 4352
n = int(input())
p = list(map(int, input().split()))

count = 0
for i in range(1, n-1):
    if (p[i] > p[i+1]) and (p[i] < p[i-1]):
        count += 1
    elif (p[i] > p[i-1]) and (p[i] < p[i+1]):
        count += 1

print(count)


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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
    
    ll N,M;
    cin>>N>>M;
    ll ans = N;
    ll a;
	rep(i,M){
        cin>>a;
        ans-=a;
    }

    if(ans<0){
        ans = -1;
    }
    cout<<ans<<"\n";

	return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    string str;
    cin >> str;
    int cnt = 1;
    for(int i = 1; i < n; i++){
        cnt += str[i] != str[i - 1];
    }
    cout << cnt << "\n";
}

Measured memory_bytes: 512
#include <iostream>
#include <climits>
#include <algorithm>
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
using namespace std;
int main() {
	long long N, K;
	cin >> N >> K;
	while (N > K) {
		N = N % K;
	}
	long long v;
	if (N > K) {
		v = N - K;
	}
	else {
		v = K - N;
	}
	if (v < N) {
		cout << v << endl;
	}
	else {
		cout << N << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    while(true){
        int w,h;
        cin >>h>>w;
        if(w!=0||h!=0){
            for (int k = 0; k < w; k++){
                cout<<'#';
            }
            cout<<endl;
            for (int i = 0; i < h-2; i++){
                cout<<'#';
                for (int j = 0; j < w-2; j++){
                    cout<<'.';
                }
                cout<<'#'<<endl;
            }
            for (int k = 0; k < w; k++){
                cout<<'#';
            }
            cout<<endl;
        }else{
            break;
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define prime 1000000007
#define INF 2147483647
int dx8[8]={-1,0,1,1,1,0,-1,-1};
int dy8[8]={1,1,1,0,-1,-1,-1,0};
int dx4[4]={-1,0,1,0};
int dy4[4]={0,-1,0,1};
signed main(void){
    int n;string s;cin>>n>>s;
    int ans=0;
    rep(i,1000){
        int m=i;
        char a=(char)('0'+m%10);m/=10;
        char b=(char)('0'+m%10);m/=10;
        char c=(char)('0'+m%10);
        int now=0;
        while(now<n){
            if(s[now]==c){
                now++;
                break;
            }
            now++;
        }
        if(now==n)continue;
        while(now<n){
            if(s[now]==b){
                now++;break;
            }
            now++;
        }
        if(now==n)continue;
        while(now<n){
            if(s[now]==a)break;
            now++;
        }
        if(now==n)continue;
        ans++;
    }
    cout<<ans<<endl;
}
        


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<cmath>
#include<sstream>
#include<iomanip>
#include <map>
#include <stack>

struct max_min
{
    int64_t max = 0;
    int64_t min = 0;
};

const int64_t cc = pow( 10, 9 ) + 7;
//std::cout<< std::fixed << std::setprecision(10) << ( double )( max ) / 2;
bool sort_pair( std::pair< int64_t, int64_t > origin, std::pair< int64_t, int64_t > another )
{
    return origin.first < another.first;
}

//コンビネーションをmodで割った余りを産出
int64_t nCk( int64_t n, int64_t k  )
{
    int64_t ans_x = 1;
    int64_t ans_y = 1;

    for( int i = n; i > n - k; i-- )
    {
        ans_x *= i;
    }

    for( int i = 1; i <= k; i++ )
    {
        ans_y *= i;
    }

    return ans_x / ans_y;
}

int main()
{
    std::string word = "aa";
    std::string w = "No";
    int64_t a,b,c,d,e,f;
    std::cin>> a;
    std::cin>> b;

    std::vector< std::string >  list( a );
    c = 0;

    c += nCk( a, 2 );
    c += nCk( b, 2 );
    std::cout<< c;
}


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

using ll = long long;
const int MOD = 1e9 + 7;

map<ll, int> factors;
void setIO(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}
void factorize(long long n){
   int count = 0;
   while (!(n % 2)) {
      n/= 2;
      count++;
   }
   if (count) factors[2] += count;
   for (ll i = 3; i <= sqrt(n); i += 2) {
      count = 0;
      while (n % i == 0) {
         count++;
         n = n / i;
      }
      if (count) factors[i] += count;
   }
   if (n > 2) factors[n] += 1;
}
int main() {
	setIO();
	ll n; cin >> n;
	factorize(n);
	int count = 0;
	vector<ll> vints;
	vints.reserve(factors.size());
	for(auto const& imap: factors)
    	vints.push_back(imap.first);
	for(ll i : vints){
		int num = 1;
		while(factors[i] >= num){
			factors[i] -= num;
			num++;
			count++;
		}
	}
	if(factors[n]) ++count;
	cout << count << "\n";
}


Measured memory_bytes: 3680
def gcd(a,b):
    if a < b:
        temp = a
        a = b
        b = temp
    if a == 0:
        return b
    elif b== 0:
        return a
    elif a % b == 0:
        return b
    else:
        return gcd(a%b,b)

n = int(input())
a = list(map(int,input().split()))
ans = gcd(a[0],a[1])
for i in range(2,n-1):
    ans = gcd(ans,a[i])
print(ans)

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

int main(void){
    int N;
    int i,j;
    int count=0;
    string A,B,C;
    
    cin>>N;
    cin>>A>>B>>C;
    
    for(i=0;i<N;i++){
        if(A.at(i)==B.at(i)&&B.at(i)==C.at(i)){
            continue;
        }else if(A.at(i)!=B.at(i)&&B.at(i)==C.at(i)){
            A.at(i)=B.at(i);
            count++;
        }else if(A.at(i)==B.at(i)&&B.at(i)!=C.at(i)){
            C.at(i)=B.at(i);
            count++;
        }else if(B.at(i)!=A.at(i)&&A.at(i)==C.at(i)){
            B.at(i)=A.at(i);
            count++;
        }else{
            B.at(i)=A.at(i);
            count++;
            C.at(i)=A.at(i);
            count++;
        }
    }
    
    cout<<count<<endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
	int a, b;

	while(scanf("%d %d", &a, &b) != EOF){
		int ans = 0; a += b;
		while(a / 10 != 0){
			ans++;
			a /= 10;
		}
		ans++;
		cout << ans << endl;
	}
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N,K,Q;
  cin >> N >> K >> Q;
  ll Score[N] = {0};
  for (int i = 0; i < Q; i++) {
    ll A;
    cin >> A;
    Score[A - 1]++;
  }
  for (int i = 0; i < N; i++) {
    if (Score[i] > Q - K) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1408
get_string(String) :-
  current_input(Input),
  read_string(Input, ' \n', '', _, String).
 
get_number(Number) :-
  get_string(String),
  number_string(Number, String).

solve(0,0).
solve(N,Sum) :-
  get_number(A),
  Next is N-1,
  solve(Next,S),
  Sum is S + A.

main :-
  get_number(A),
  get_number(N),
  solve(N,Sum),
  Ans is A - Sum,
  (Ans < 0 -> writeln(-1) ; writeln(Ans)).

Measured memory_bytes: 9328
h,w = map(int,input().split())
c = [list(map(int,input().split())) for _ in range(10)]
a = [list(map(int,input().split())) for _ in range(h)]
INF = 10**10
d = [[c[i][j] for j in range(10)] for i in range(10)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])

ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] != -1:
            ans += d[a[i][j]][1]
print(ans)

Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#define ll long long
using namespace std;


int main ()
{
    int n, m, c;
    cin >> n >> m >> c;
    int B[20];
    int A[20][21] = {0};
    for (int i = 0; i < m; ++i) {
        cin >> B[i];
    }
    for(int i = 0; i < n; ++i) {
        A[i][m]=0;
        for (int j = 0; j < m; ++j) {
            cin >> A[i][j];
            A[i][m]+=(B[j]*A[i][j]);
        }
    }
    int count = 0;
    for(int i = 0; i < n; ++i) {    
        if((A[i][m]+c)>0){
            count++;
        }
    }
    cout << count;
}

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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  ll n, t;
  cin >> n >> t;

  vector<ll> vt(n);
  for (int i = 0; i < n; ++i) {
    cin >> vt[i];
  }

  ll ans = t * n, cur_t = t;
  for (int i = 1; i < vt.size(); ++i) {
    if (vt[i - 1] + t >= vt[i]) {
      ans -= (vt[i - 1] + t) - vt[i];
    }
  }

  cout << ans << '\n';
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[102][100002];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll n, w;
    cin >> n >> w;
    for (int i = 1; i <= w; i++)
        dp[0][i] = -1ll;
    dp[0][0] = 0ll;
    for (ll i = 1; i <= n; i++)
    {
        ll hz, zh;
        cin >> hz >> zh;
        for (ll j = 1; j <= w; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if(j - hz >= 0)
            dp[i][j] = max(dp[i][j], dp[i - 1][j - hz] + zh);
        }
    }
    ll ax = 0ll;
    for (ll i = 1; i <= w; i++)
        ax = max(dp[n][i], ax);
    cout << ax;
}

Measured memory_bytes: 82444
s = list(input())
a = [chr(ord('a') + i) for i in range(26)]
cnt = [0]*26
for i in range(len(s)):
    ind = a.index(s[i])
    cnt[ind] += 1
for i in range(len(cnt)):
    if cnt[i] == 0:
        print(a[i])
        exit()
print("None")



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

using namespace std;

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

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

    int f = 0;
    int t;
    vector<int> L;
    for(int i=0; i<N; ++i){
        if(p[i] != i+1) L.push_back(i);
    }
    if(L.size() < 3) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

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

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

    bool ans = true;
    for(int j = 0; j < 5; j++)
    {
        /* code */
    
    

    for(int i = 0; i < 4; i++)
    {
        if(a[i] - a[j] > k || a[i] - a[j] < -k){
            ans = false;
            break;
        }
    }
    }
    
    if(ans){
        cout << "Yay!\n";
    }
    else {
        cout << ":(\n";
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

ll n;
vector<vector<pair<ll, ll>>> g;
vector<ll> color;

void dfs(ll v, ll p = -1, ll d = 0) {
    if (color[v] != -1) return;
    color[v] = d % 2;
    for(auto u : g[v]) {
        if (u.first == p) continue;
        dfs(u.first, v, d + u.second);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    cin >> n;
    g.resize(n);
    rep(i, n - 1) {
        ll u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        g[u].push_back(make_pair(v, w));
        g[v].push_back(make_pair(u, w));
    }
    color.resize(n, -1);
    dfs(0);
    rep(i, n) printf("%lld\n", color[i]);
    return 0;
}


Measured memory_bytes: 9984
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int C = sc.nextInt();
		int[] B = new int[M];
		for(int i = 0; i < M; i++) {
			B[i] = sc.nextInt();
		}
		int[][] A = new int[N][M];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < M; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		int ans = 0;
		for(int i = 0; i < N; i++) {
			int tmp = 0;
			for(int j = 0; j < M; j++) {
				tmp += A[i][j] * B[j];
			}
			if(tmp + C > 0) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22100
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int x,y;cin>>x>>y;
    if(x==2||y==2){
        cout<<"No"<<endl;
        return 0;
    }
    if(y==4||y==6||y==9||y==11){
        if(x!=4&&x!=6&&x!=9&&x!=11){
            cout<<"No"<<endl;
        }
        else
            cout<<"Yes"<<endl;
    }
    else if(y!=4&&y!=6&&y!=9&&y!=11){
        if(x==4||x==6||x==9||x==11){
            cout<<"No"<<endl;
            
        }
        else
            cout<<"Yes"<<endl;
    }
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
#include <stdio.h>
int c(char *p,int d){return ((26+*p-*(p+1))%26==d);}
int a(char *p){return((*p>'`')&&(*p<'{'));}

char *decode (char *inbuf, int s) {
  //int p = 0;
  char *p=inbuf-1;
  while (*++p){
    if(a(p)) {
      int t = *p + s;

      if (t > 'z')      *p = (char)(t - 26);
      else if (t < 'a') *p = (char)(t + 26);
      else              *p = (char)t;
    }
    //    p++;
  }
  return (inbuf);
}

int main(s){
  char inbuf[82];
  while(fgets(inbuf,80,stdin)){
    char *p=inbuf-1;
    while(*++p){
      if((c(p,12))&&((c(p+1,3)&&!a(p+3))||(c(p+1,7)&&c(p+2,7)&&!a(p+4))||(c(p+1\
,25)&&c(p+2,16)&&!a(p+4)))){s='t'-*p;p+=3;break;}
    }
    printf("%s",decode(inbuf, s));
  }
  return 0;
}

Measured memory_bytes: 520
#include <stdio.h>

int main(void){
	int N,M;
	scanf("%d %d",&N,&M);
	int K[N];
	int A[N][M];
	int n,kn;
	int count;
	int ans=0;
	int i,j,k;
	for(i=0; i<N; i++){
		scanf("%d",&K[i]);
		for(j=0; j<K[i]; j++){
			scanf("%d",&A[i][j]);
		}
	}

	for(k=1; k<=M; k++){
		count=0;
		for(i=0; i<N; i++){
			for(j=0; j<K[i]; j++){
				if(k==A[i][j]){
					count++;
				}
			}
		}
		if(count==N){
			ans++;
		}
	}

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

Measured memory_bytes: 128
x,k,d=map(int,input().split())
if x<0:
  x*=-1
if x>=k*d:
  x-=k*d
else:
  a=x//d
  if (k-a)%2==0:
    x-=a*d
  else:
    x-=(a+1)*d
print(abs(x))

Measured memory_bytes: 9132
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
odd=v[1::2]
even=v[0::2]
a=Counter(odd)
b=Counter(even)
if a.most_common()[0][0]!=b.most_common()[0][0]:
    print(n-a.most_common()[0][1]-b.most_common()[0][1])
else:
    if len(a)>1 and len(b)>1:
        print(min(n-a.most_common()[0][1]-b.most_common()[1][1],n-a.most_common()[1][1]-b.most_common()[0][1]))
    elif len(a)>1 and len(b)==1:
        print(n-a.most_common()[1][1]-b.most_common()[0][1])
    elif len(a)==1 and len(b)>1:
        print(n-a.most_common()[0][1]-b.most_common()[1][1])
    elif len(a)==1 and len(b)==1:
        print(n//2)

Measured memory_bytes: 19040
#include <iostream>
#include <string>
#include <vector>
 
int main()
{
    int flag1 = 0, flag2 = 0;
    std::string str;
    std::cin >> str;
 
    for (int i = 0; i < str.size() + 1; i++)
    {
        if (str[i]=='C')
        {
            flag1 = 1;
        }
 
        if (flag1 == 1 && str[i] == 'F')
        {
            flag2 = 1;
        }
    }
    if (flag2 != 1)
    {
        std::cout << "No" << std::endl;
    }
 
    if (flag2 == 1)
    {
        std::cout << "Yes" << std::endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))

highest = h[0]
for i in range(n-1):
  if h[i] <= h[i+1] and h[i]+1 >= highest:
    continue
  else:
    if h[i]-1 <= h[i+1] and h[i+1] >= highest:
      highest = h[i]-1
      continue
    else:
      print("No")
      exit()
print("Yes")

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

int main() {
  ll x;
  cin >> x;
  ll a,b;
  a=x/500;
  x%=500;
  b=x/5;
  cout<<a*1000+b*5<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ll long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fr(i, a, b) for(int i=a; i>=b; i--)
#define l long int
#define endl '\n'
#define pb push_back
#define pf pop.front()
using namespace std;

	int h,w;
	int sx,sy;
	int ex,ey;
    int dx[]={-1,1,0,0};
    int dy[]={0,0,-1,1};
    int dist[1001][1001];
	char s[1001][1001];
    
    deque<pair<int,int >>q;

bool legal(int x,int y)
{
if((x<0 || y<0 || x>=h || y>=w) || s[x][y]=='#')
return false;

return true;
}

void solve()	
{
    
	cin>>h>>w>>sx>>sy>>ex>>ey;

f(i,0,h+1)
f(j,0,w+1)
dist[i][j]=INT_MAX;

	f(i,0,h)
    f(j,0,w)
	cin>>s[i][j];
	
	sy--,ex--,sx--,ey--;
	dist[sx][sy]=0;

	q.push_front({sx,sy});
    while(!q.empty())
    {
        int curx=q.front().first;
        int cury = q.front().second;
//        cout<<curx<<" "<<cury<<" "<<dist[curx][cury]<<endl;
        q.pop_front();
        
        for(int i=0;i<4;i++)
        {
            if(!legal(curx+dx[i] , cury+dy[i]))continue;
            
			 if(dist[curx][cury]<dist[curx+dx[i]][cury+dy[i]])
            {
                dist[curx+dx[i]][cury+dy[i]] = dist[curx][cury];
                q.push_front({curx+dx[i] , cury+dy[i]});
            }
        }

        for(int i=curx-2;i<=curx+2;i++)
        {
            for(int j=cury-2;j<=cury+2;j++)
            {
            	if(!legal(i,j))continue;
            	
                if(dist[curx][cury]+1<dist[i][j])
                {
				dist[i][j]=dist[curx][cury]+1;
                q.push_back({i ,j});
				}
            }
        }

    }
	dist[ex][ey]>=INT_MAX?cout<<"-1":cout<<dist[ex][ey];
}


int32_t main()
{
//FAST
l T=1;
//cin>>T;
while(T--)
{
solve();
}
}










Measured memory_bytes: 8456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
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; }
const ll INF=1LL<<60;
const int inf=1<<30;
const int mod=1e9+7;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<int> c(n);
    for(int i=0;i<n-1;i++){
        int a;cin >> a;
        a--;
        c[a]++;
    }
    for(int i=0;i<n;i++){
        cout << c[i] << endl;
    }
}

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

typedef long long ll;

char s[15];

int main(){
    int a,b,ba,T,sum;
    a=b=ba=sum=0;
    scanf("%d",&T);
    while (T--){
        scanf("%s",s);
        int len=strlen(s);
        if (s[0]=='B'&&s[len-1]=='A') ++ba;
        else if (s[0]=='B') ++b;
        else if (s[len-1]=='A') ++a;
        for (int i=1;i<len;++i){
            if (s[i]=='B'&&s[i-1]=='A') ++sum;
        }
    }
    if (a!=0){
        sum+=min(a,b)+ba;
    }
    else{
        if (ba!=0){
            sum+=ba-1;
            if (b!=0) sum++;
        }
    }
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin >> k;
  vector<long long> A(87);
  A.at(0) = 2;
  A.at(1) = 1;
  for(int i=2;i<87;i++){
    A.at(i) = A.at(i-1) + A.at(i-2);
  }
  cout << A.at(k) << endl;
}


Measured memory_bytes: 3612
//This code was made by Chinese_zjc_.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
string a,b;
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>a>>b;
	cout<<(b+a);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    constexpr int n = 3;

    int q[101];
    memset(q, -1, sizeof(q));

    for (int i = 0; i < n * n; i++) {
        int a;
        cin >> a;

        q[a] = i;
    }

    int m;
    cin >> m;

    int r = 0;
    for (int j = 0; j < m; j++) {
        int b;
        cin >> b;

        int i = q[b];
        if (i >= 0) r ^= 1 << i;
    }

    int p[8] = {
        0b000000111,
        0b000111000,
        0b111000000,
        0b001001001,
        0b010010010,
        0b100100100,
        0b100010001,
        0b001010100,
    };

    int f = 0;
    for (int k = 0; k < 8; k++) {
        //if ((r & p[k]) == p[k]) f = 1;
        if (!(~r & p[k])) f = 1;
    }

    cout << (f ? "Yes" : "No") << endl;

    return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
const ll mod = 1e9+7;

int n;
string s[2];
ll dp[maxn];

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

  cin>>n;
  cin>>s[0]>>s[1];
  if (s[0][0]==s[1][0]) {
    dp[0] = 3;
  } else {
    dp[0] = 6;
  }

  for (int i=1; i<n; i++) {
    // continuing =
    if (s[0][i]==s[0][i-1] && s[1][i]==s[1][i-1]) {
      dp[i]=dp[i-1];
      continue;
    }
    // vertical |
    if (s[0][i]==s[1][i]) {
      if (s[0][i-1]==s[1][i-1]) {
	dp[i]=2LL*dp[i-1];
	dp[i]%=mod;
      } else {
	dp[i]=dp[i-1];
      }
    } else {
      // starting =
      if (s[0][i-1]==s[1][i-1]) {
	dp[i]=2LL*dp[i-1];
      } else {
	dp[i]=3LL*dp[i-1];
      }
      dp[i]%=mod;
    }
  }

  cout<<dp[n-1]<<endl;
  

  return 0;
}


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

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する


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

    int N;
    cin >> N;
    string S;
    cin >> S;
    reverse(S.begin() + N,S.begin() + 2 * N);

    map<pair<string,string>, ll> mp;

    for(int i = 0;  i < 1 << N; i++){
        string red,blue;
        for(int bit = 0; bit < N; bit++){
            if(i >> bit & 1){
                red += S[bit];
            }else{
                blue += S[bit];
            }
        }
        mp[make_pair(red,blue)]++;
    }

    ll ans = 0ll;
    for(int i = 0;  i < 1 << N; i++){
        string red,blue;
        for(int bit = 0; bit < N; bit++){
            if(i >> bit & 1){
                blue += S[bit + N];
            }else{
                red += S[bit + N];
            }
        }
        ll tmp = mp[make_pair(blue,red)];
        ans += tmp;
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 49408
#include<iostream>
using namespace std;
typedef long long ll;
const ll mod=998244353;
ll aa[123456];

ll ksm(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res%mod;
}
int main()
{
	int n,x;int maxx=0;
	ll count=1;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(i==1&&x!=0) count=0;
		aa[x]++;
		maxx=max(x,maxx); 
	}	
	for(int i=maxx;i>1;i--)
	{
		if(aa[i]==0) count=0;
		count=count*ksm(aa[i-1],aa[i])%mod;
	}
	if(aa[0]>1) count=0;
	cout<<count<<endl;
	return 0;
 } 

Measured memory_bytes: 1024
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;

int main() {
	int n;
	cin >> n;
	int d = n % 10;
	int c = (n / 10) % 10;
	int b = (n / 100) % 10;
	int a = (n / 1000) % 10;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				int ret = 0;
				if (i == 0) {
					ret = a + b;
				} else {
					ret = a - b;
				}
				if (j == 0) {
					ret = ret + c;
				} else {
					ret = ret - c;
				}
				if (k == 0) {
					ret = ret + d;
				} else {
					ret = ret - d;
				}
				if (ret == 7) {
					cout << a;
					cout << (i == 0 ? "+" : "-");
					cout << b;
					cout << (j == 0 ? "+" : "-");
					cout << c;
					cout << (k == 0 ? "+" : "-");
					cout << d;
					cout << "=7" << endl;
					return 0;
				}
			}
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
using namespace std;
long long x;
long long f(long long x){
	if(x==1)return x;
	return 2*f(x/2)+1;
}
int main(){
	cin>>x;
	cout<<f(x);
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a, b;
	int d, r;
	double f;

	scanf("%d %d", &a, &b);
	d = a / b;
	r = a % b;
	f = a*1.0 / b;	
	printf("%d %d %lf\n", d, r, f);

	return 0;
}

Measured memory_bytes: 632
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <unordered_map>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for(int i = (int)(n-1); i > -1; i--)

ull MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    ll ans = 0;
    vector<ll> numbers(N);
    rep(i,N){
        cin >> numbers[i];
    }

    rep(i,60){
        ll x = 0;
        rep(j,N) if( numbers[j] >> i & 1) x++;
        ll plus = x*(N-x) % MOD;
        rep(j,i) plus = plus * 2 % MOD;
        ans += plus;
        ans %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
N = int(input())
A = list(map(int, input().split()))
d = {}
d_sum = {}
for i in range(N):
  if A[i] in d:
    d[A[i]] += 1
    d_sum[A[i]] += d[A[i]] - 1
  else:
    d[A[i]] = 1
    d_sum[A[i]] = 0
#print(A, d,d_sum)
#print(sum(A), sum(d.values()))
ans = sum(d_sum.values())
for i in range(N):
  print(ans - (d[A[i]] - 1))

    

Measured memory_bytes: 30592
#include<bits/stdc++.h>
using namespace std;
int N, k, num[111111];
bool check(int x){
	int sum = 0, l = 1, r = x, ans = 1e9;
	for(int i = 0;i < x; i++){
		if(num[i+1] == 0 && num[i] == 1)sum++;
	}
	ans = sum;
	while(r < N){
		r++;
		l++;
		if(num[l-1] == 0 && num[l] == 1)sum--;
		if(num[r] == 0 && num[r-1] == 1)sum++;
		ans = min(ans, sum);
	}
	if(ans <= k)return true;
	return false; 
}
int main(){
	cin>>N>>k;
	num[0] = 1;
	for(int i = 1;i <= N; i++){
		scanf("%1d", &num[i]);
	}
	int l = 0, r = N, ans = 0;
	while(l <= r){
		int mid = (l + r) >> 1;
		if(check(mid)){
			l = mid + 1;
			ans = max(ans, mid);
		}
		else r = mid - 1;
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] S = sc.next().split("");
		if(S[2].equals(S[3]) && S[4].equals(S[5])) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}
}


Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
 
#define N 101
#define WHITE 0
#define BLACK 1
#define GRAY 2
 
int n,head=1,tail=1,adj[N][N],color[N],d[N],Q[N];
 
int Queemp(){
  if(head == tail){
    return 1;
  }
 else{
    return 0;
  }
}


void Enque(int r){
  int i;
  Q[tail] = r;
  tail++;
}


int Deque(void){
  int i;
  i = Q[head];
  Q[head] = -1;
  head++;
  return i;
}


void bfs(int s){
  int u,v;
  color[s] = GRAY;
  d[s] = 0;
  Enque(s);
  while(Queemp() == 0){
    u = Deque();
    for(v=1;v<=n;v++){
      if(color[v] == WHITE && adj[u][v] == 1){
    color[v] = GRAY;
    d[v] = d[u] + 1;
    Enque(v);
      }
    }
    color[u] = BLACK;
  }
}


int main(void) {
  int i,j,k,u,v;

  for(i=1;i<N;i++){
    for(j=1;j<N;j++){
      adj[i][j] = 0;
    }
    Q[i] = -1;
    color[i] = WHITE;
    d[i] = INT_MAX;
  }
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&u,&k);
    for(j=1;j<=k;j++){
      scanf("%d",&v);
      adj[u][v] = 1;
    }
  }
  bfs(1);
  for(i=1;i<=n;i++){
    if(d[i] == INT_MAX){
      d[i] = -1;
    }
    printf("%d %d\n",i,d[i]);
  }
  return 0;
}

Measured memory_bytes: 640
N = int(input())
Data = [list(map(int, input().split())) for _ in range(N)]

dp = [[None, None, None] for _ in range(N)]
# dp[0][0]はAを選んだ時
dp[0] = [Data[0][0], Data[0][1], Data[0][2]]

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

print(max(dp[-1]))


Measured memory_bytes: 47280
#include <stdio.h>

int main(void)
{
	int i, a, b, c;
	
	scanf("%d", &i);
	
	for (;i > 0; i--) {
		scanf("%d %d %d", &a, &b, &c);
		
		a *= a;
		b *= b;
		c *= c;
		
		if (a > b && a > c) {
			if (a == b + c)
				printf("YES");
			else 
				printf("NO");
		} else if (b > a && b > c) {
			if (b == a + c)
				printf("YES");
			else
				printf("NO");
		} else {
			if (c == a + b)
				printf("YES");
			else
				printf("NO");
		}
		printf("\n");
	}
	
	return 0;
}
			
		

Measured memory_bytes: 0
import java.util.Scanner;

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

		long a = sc.nextLong() - 1;
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		long countA = 0;
		long countB = 0;

		long tmp = c * d / euclid(c, d);

		countA = a - a / c - a / d + a / tmp;
		countB = b - b / c - b / d + b / tmp;

		System.out.println(countB - countA);
	}

	public static long euclid(long n, long m) {
		if(m==0) return n;
		return euclid(m, n%m);
	}
}

Measured memory_bytes: 23764
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	String[] s = br.readLine().split(" ");
	int x = Integer.parseInt(s[0]);
	int y = Integer.parseInt(s[1]);

	int menseki = x*y;
	int shu = (x+y)*2;
	System.out.println(menseki + " " + shu); 
    }
}

Measured memory_bytes: 24156
#include <iostream>

using namespace std;

int main()
{
    int n, a, b;
    cin >> n;
    cin >> a;
    cin >> b;

    if (b > a)
    {
        swap(a, b);
    }

    cout << b;
    cout << " ";
    if(b - (n - a) > 0){
        cout << b - (n - a) << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}

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

int M, K;

int main(){
	cin >> M >> K;
	if(M == 0){
		if(K > 0) cout << -1 << endl;
		else cout << "0 0" << endl;
	}else if(M == 1){
		if(K > 0) cout << -1 << endl;
		else cout << "0 0 1 1" << endl;
	}else{
		int ub = 1;
		for(int i = 0; i < M; i++) ub *= 2;
		if(ub - 1 < K) cout << -1 << endl;
		else{
			vector<int> res;
			for(int i = 0; i < ub; i++){
				if(i == K) continue;
				res.push_back(i);
			}
			res.push_back(K);
			for(int i = ub - 1; i >= 0; i--){
				if(i == K) continue;
				res.push_back(i);
			}
			res.push_back(K);
			for(int i = 0; i < res.size(); i++){
				cout << res[i] << (i == res.size() - 1 ? '\n' : ' ');
			}
		}
	}
	return 0;
}


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

using namespace std;

int main()
{
	string qn,str,p,answer;
	int q,a,b,y,f;
	cin >> str >> q;
	for (int i = 0 ; i < q ; i++ ){
		cin >> qn;
		if (qn == "replace"){
			cin >> a >> b >> p;
			for (int j = 0 ; j < b - a + 1 ; j++ ){
				str[a + j] = p[j]; 
			}
		} 

		if (qn == "reverse"){
			cin >> a >> b;
				for (int x = a ; x < b ; x++ ){
					y = b;
					answer[x] = str[x];
					
				    str[x] = str[y];
				    str[y] = answer[x];
					b--;
                   
				}
		}
		
		if (qn == "print"){
			cin >> a >> b;
			cout << str.substr(a,b - a + 1) << endl;
		}
	}

 return 0;
}

Measured memory_bytes: 3232