akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int Task4Core();

int main()
{
	cout << Task4Core();

	return 0;
}
int Task4Core()
{
	int N = 0;

	cin >> N;

	map<int, int> num; // 差分、個数
	
	for (int i = 0; i < N; ++i) {
		int n = 0;
		cin >> n;
		++num[n];

		bool isError = true;
		if (N % 2 != 0) { // 奇数
			if (n % 2 != 0) {
				return 0;
			}
			else if (n > N - 1) {
				return 0;
			}
		}
		else {
			if (n % 2 == 0) {
				return 0;
			}
			else if (n > N - 1) {
				return 0;
			}
		}
	}

	//　並び方は人数によって決まる。

	int numPower = N / 2;

	int product = 1;
	int numerator = 1000000000 + 7;
	for (int i = 0; i < numPower; ++i) {
		if ((N % 2) != 0) {// 奇数の場合
			if (i == 0) {
				if (num[i] != 1) {// 左右比較が0 の場合
					return 0;
				}
			}
			else {
				if (num[2 * i] != 2) {
					return 0;
				}
			}
		}
		else {
			if (num[2 * i + 1] != 2) {
				return 0;
			}
		}
		product = (product * 2) % numerator;
	}

	return product;
}

Measured memory_bytes: 2560
import sys
input = sys.stdin.readline

N, X = map(int, input().split())
b = [2**(i+2)-3 for i in range(N)]
p = [2**(i+1)-1 for i in range(N)]

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + b[N-1]:
        return f(N-1, X-1)
    else:
        return p[N-1]+1+f(N-1, X-2-b[N-1])

print(f(N, X))

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


int main()
    {
        int n;
        cin >> n;
        int arr[n][3];
       for(int i=0;i<n;i++){
       	cin>>arr[i][0]>>arr[i][1]>>arr[i][2];

       }
   			for(int i=1;i<n;i++){


   					arr[i][0] += max(arr[i-1][1] , arr[i-1][2]);
   					arr[i][1] += max(arr[i-1][2] , arr[i-1][0]);
   					arr[i][2] += max(arr[i-1][0] , arr[i-1][1]);
   			
   		}
        int ans = -1;
        ans = max(arr[n-1][0] , arr[n-1][1]);
        ans = max( ans , arr[n-1][2]);
        cout<<ans;
    
	return 0;
}


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

public class P
{
    public int x { get; set; }
    public int y { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var alist = new List<long>();
        var n = long.Parse(Console.ReadLine().Trim());
        var n2 = (long)Math.Sqrt(n+1);
        for (long i = 1; i <=  n2; i++)
            if (n % i == 0)  alist.Add(getF(i, n / i));
        Console.WriteLine(alist.Min());
    }
    public static long getF (long a , long b)
    {
        var wa = a.ToString().Length;
        var wb = b.ToString().Length;
        if (wa >= wb) return wa;
        else return wb;
    }
}

Measured memory_bytes: 13268
def MAP(): return list(map(int,input().split()))

n = int(input())
b = MAP()

a = [0]*n
a[0] = b[0]
a[n-1] = b[n-2]

for i in range(n-2):
    a[i+1] = min(b[i],b[i+1])
print(sum(a))

Measured memory_bytes: 3064
def main(N, X, M):
    kurikaesi = []
    shoki = [X]
    st_shoki = {X}

    now = X
    for n in range(1, N):
        next = (now ** 2) % M
        if next in st_shoki:
            i = shoki.index(next)
            kurikaesi = shoki[i:]
            shoki = shoki[:i]
            break
        else:
            shoki.append(next)
            st_shoki.add(next)
            now = next
    else:
        print(sum(shoki))
        exit()

    shou = (N - len(shoki)) // len(kurikaesi)
    amari = (N - len(shoki)) % len(kurikaesi)

    print(sum(shoki) + sum(kurikaesi) * shou + sum(kurikaesi[:amari]))
    
if __name__ == '__main__':
    N, X, M = list(map(int, input().split()))
    main(N, X, M)

Measured memory_bytes: 13416
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: u64,
    }
    let mut ans = 0u64;
    let mut m = 1;
    let mut r = n/(1+m);
    while m*m <= n {
        if n/m == n%m {
            ans += m;
        }
        m += 1;
        r = n/(1+m);
    }
    while r > 0 {
        let m = (n-r)/r;
        if n/m == n%m {
            ans += m;
        }
        r -= 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define int long long int
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output1.txt","w", stdout);
    #endif
    IOS;
    int n,mod;
    mod=1000000007;
    cin>>n;
    int a[n],s=0;
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        s=s+a[i];
    }
    int ans=0;
    for (int i = 0; i < n-1; ++i)
    {
        s-=a[i];
        ans=ans+(a[i]*(s%mod))%mod;
    }
    cout<<ans%mod;
    #ifndef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}       

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}


int main(void) {
	string S;
	cin >> S;
	int64 cnt = 0;
	REP(i, S.size()/2) {
		if (S[i] != S[S.size()-i-1]) cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 764
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

const string YES = "Yes";
const string NO = "No";

void solve(long long a, long long b, long long c){
    ll r = c-a-b;
    if(r <= 0) {
        cout<<NO<<endl; 
        return;
    }
    r = r*r;
    ll l = 4*a*b;
    cout<<((l < r) ? YES:NO)<<endl;
}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long c;
    scanf("%lld",&c);
    solve(a, b, c);
    return 0;
}


Measured memory_bytes: 256
n,m,k = map(int, input().split())

N = 998244353

factorial = [1]
inverse = [1]
for i in range(1, n+2):
    factorial.append(factorial[-1] * i % N)
    inverse.append(pow(factorial[-1], N - 2, N))

def combi(n, r):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % N

ans=0
if k<n//2:
    for i in range(k+1):
        ans+=m*combi(n-1,i)*pow(m-1,n-1-i,N)%N
        ans%=N
    print(ans)
else:
    for i in range(k+1,n):
        ans+=m*combi(n-1,i)*pow(m-1,n-1-i,N)%N
        ans%=N
    ans = pow(m,n,N)-ans
    if ans < 0:
        ans +=N
    print(ans)


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, 0);
  int sum = 0;
  rep(i, n) {
    cin >> a.at(i);
    sum += a.at(i);
  }
  sort(a.begin(), a.end());

  string ans = (a.at(n - m) * 4 * m >= sum) ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <map>
#define for1(x,y) for(long long x = 1; x<ll(y); x++)
#define forn(x,y,z) for(long long x = y; x< ll(z); x++)
#define for0(x,y,z) for(long long x = y; x< ll(z); x++)
# define PII pair<int,int>
# define FF first
# define SS second
# define PB push_back

#define forn(x,y,z) for(long long x = y; x< ll(z); x++)
#define for0(x,y,z) for(long long x = y; x< ll(z); x++)
using namespace std;
typedef long long ll;
typedef long double ld;	

#define maxn 1000015
const double EPS = (1e-7), EPSm= (1e7);
const ll linf = (ll)1e17 + 5;
long double PI = 3.14159265359;
int dir[8][2]={{1,0},{-1,0},{0,1},{0,-1},{-1,-1},{1,1},{-1,1},{1,-1}};
	
const int MAXN = 1e5+10;
const int NINF = -1e5;
const int INF = 20000000;

void solve()
{
	char n;
	int sum=0;
	while(1){
		scanf("%1c",&n);
		if(n=='\n'){
			if(sum%9==0){
				cout<<"Yes\n";
				return;
			}
			else 
			{
				cout<<"No\n";
				return;
			}
		}
		sum+=n-'0';
		sum%=9;
	}
		
		
}


int main()
{
	//ios::sync_with_stdio(false);
	//cin.tie(0);
	//int test;
	//cin >> test;
	//while(test--)
		solve();
	return 0;
}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,t;
	scanf("%d%d%d",&n,&x,&t);
	if(n<x) printf("%d",t);
	else
	{
		if(n%x!=0)
		{
			int p=n/x+1;
			printf("%d",p*t);
		}
		else
		{
			int p=n/x;
			printf("%d",p*t);
		}
	}
	return 0;	
} 

Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
int main() {
  int S, S1, S2, S3;
  cin >> S;
  S1 = S / 100; S2 = ( S - S1 * 100 ) / 10; S3 = ( S - ( S1 * 100 + S2 * 10 ) );
  cout << S1 + S2 + S3 << endl;
}

Measured memory_bytes: 256
// c++include
#include <iostream>
// cinclude
#include <stdio.h>
#include<string.h>
#include<math.h>
//c++標準ライブラリ
#include<vector>
#include<string>
//std使用<-namespace
using namespace std;

// define, typedef
#define rpt(i, n) for(i = 0; i < (n); i++)
typedef long long ll;

// main関数
int main(void) {
	int a, b, plus, minus, mul, max;
	cin >> a >> b;
	plus = a + b;
	minus = a - b;
	mul = a * b;
	max = plus;
	if (max <= minus)
		max = minus;
	if (max <= mul)
		max = mul;
	cout << max;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define MAXN 4000007
#define mo 19930726
using namespace std;
typedef unsigned long long ull;
#define ms(arr) memset(arr, 0, sizeof(arr))
const int inf = 0x3f3f3f3f;
int f[1001][1001],x[100001],y[10001],col[10001];
int n,m,a[1001][1001],cnt[100001],tot;
bool vis[100001];
struct po
{
	int nxt,to;
};
po edge[1000001];
inline int read()
{
    int x=0,c=1;
    char ch=' ';
    while((ch>'9'||ch<'0')&&ch!='-')ch=getchar();
    while(ch=='-') c*=-1,ch=getchar();
    while(ch<='9'&&ch>='0')x=x*10+ch-'0',ch=getchar();
    return x*c;
}
inline void put_color(int u)
{
	vis[u]=1;
	cnt[col[u]]++;
	for(re int i=1;i<=n;i++){
		if(a[u][i]==0){
			if(!vis[i]){
				col[i]=!col[u];
				put_color(i);
			} else if(col[u]==col[i]){
				cout<<-1;
				exit(0);
			}
		}
	}
}
int main()
{
	n=read();m=read();
	for(re int i=1;i<=n;i++) a[i][i]=1;
	for(re int i=1;i<=m;i++){
		int u=read(),v=read();
		a[u][v]=a[v][u]=1;
	}
	for(re int i=1;i<=n;i++) {
		if(!vis[i]){
			cnt[0]=cnt[1]=0;
			put_color(i);
			tot++;
			x[tot]=cnt[0];
			y[tot]=cnt[1];
		}
	}
	f[0][0]=1;
	for(re int i=1;i<=tot;i++){
		for(re int j=0;j<=n;j++){
			if(f[i-1][j]){
				f[i][j+x[i]]=1;
				f[i][j+y[i]]=1;
			}
		}
	}
	int ans=n*n;
	for(re int i=0;i<=n;i++){
		if(f[tot][i]) ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
	}
	cout<<ans;

}

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

int main(){
    int n; cin>>n;
    vector<int> a(n),b(n);
    rep(i,n) cin>>a[i]>>b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(n%2==1) cout << b[n/2]-a[n/2]+1 << endl;
    else cout << (b[n/2-1]+b[n/2]) - (a[n/2-1]+a[n/2]) + 1 << endl;
    return 0;
}

Measured memory_bytes: 4748
def judge(data_N,data,data_num,tmp_key,sum_data):#dataリスト（ソート済）のdata_num以降の数字だけを使って、tmp_keyがつくれるか
    if(data_N <=data_num):
        return 0
    x=data[data_num]
    if(sum_data[data_num] +x < tmp_key):
        return 0
    if(x==tmp_key):
        return 1
    if(tmp_key <x):
        return 0
    if(judge(data_N,data,data_num+1,tmp_key -x,sum_data)):
        return 1
    if(judge(data_N,data,data_num+1,tmp_key,sum_data)):
        return 1
    return 0

data_N=int(input())
data=list(map(int,input().split()))
data.sort()

tmp_sum=sum(data)
sum_data=[tmp_sum - i for i in data]#i番目の要素はdataのi+1番目以降のsumを表す



key_num=int(input())
keys=list(map(int,input().split()))

for key in keys:
    if(key in data):
        print("yes")
    else:
        if(judge(data_N,data,0,key,sum_data)):
            print("yes")
        else:
            print("no")


Measured memory_bytes: 5628
#define rep(i,n) REP(i,0,n)
#define REP(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;


class Node {
   public:
   vector<long> to;
   bool seen = false;
   bool finish = false;
   Node(){;};
};
vector<Node> vGr;

ll N,K;
long long DIV = (long long)1e9+7;
long long Pow[(long long)1e5+100];
long long GetPow(long long l) {
   if(!Pow[l]) Pow[l] = (GetPow(l-1)*(K-2-l+1))%DIV;
   return Pow[l];
}

long long Pow2[(long long)1e5+100];
long long GetPow2(long long l) {
   if(!Pow2[l]) Pow2[l] = (GetPow2(l-1)*(K-1-l+1))%DIV;
   return Pow2[l];
}

ll ans = 1;

void bfs (int vertex) {
   if (vGr[vertex].seen) return;
   vGr[vertex].seen = true;
   int m = vGr[vertex].to.size()-1;
   if (vertex) {
      // K-2Cm*m!;
      // cout<<GetPow(m)<<endl;
      ans *= GetPow(m);
      ans = ans%DIV;
   } else {
      // cout<<GetPow2(m+1)<<endl;
      ans *= GetPow2(m+1);
      ans = ans%DIV;
   }
   // cout<<vertex<<" "<<vGr[vertex].to.size()-1<<endl;
   for (auto el: vGr[vertex].to) {
      bfs(el);
   }
   return;
}

int main(void) {
   cin>>N>>K;
   ll a,b;
   vGr.resize(N);
   rep(i,N-1) {
      cin>>a>>b;
      vGr[a-1].to.push_back(b-1);
      vGr[b-1].to.push_back(a-1);
   }
   Pow[0] = 1;
   Pow2[0] = 1;
   bfs(0);
   ans *= K;
   ans = ans%DIV;
   cout<<ans<<endl;








   return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) cin >> p[i];
  sort(p.begin(), p.end());
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (i == N - 1) ans += p[i] / 2;
    else ans += p[i];
  }
  cout << ans << endl;
}

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

int main() {
long long x;
cin>>x;
long long n;
cin>>n;
long long a[n];
for(long long i=0;i<n;i++){
    cin>>a[i];
}
sort(a,a+n);
long long ans=x;
long long temp1=ans;
long long temp2=ans;
set<long long>s;
long long count=0;
for(long long i=x;i<=101;i++){
    for(long long j=0;j<n;j++){
        if(a[j]==i){
            break;
        }
        if(j==n-1){
            temp1=i;
            count=1;
            break;
        }
    }
    if(count==1){
        count=0;
        break;
    }
}
for(long long i=x;i>=0;i--){
    for(long long j=0;j<n;j++){
        if(a[j]==i){
            break;
        }
        if(j==n-1){
            temp2=i;
            count=1;
            break;
        }
    }
    if(count==1){
        count=0;
        break;
    }
}
if(abs(temp2-x)<=abs(temp1-x)){
    cout<<temp2<<endl;
}
else{
    cout<<temp1<<endl;
}


}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define ll long long 
#define mod 1000000007
void fast(){
  ios_base::sync_with_stdio(false);cin.tie(NULL);
}

int main() {
   fast();
   unordered_map<int,long long int> m;
   int n;
   cin>>n;
   long long ans=1;
   for(int i=2;i<=n;i++){
    int k=i;
     for(int j=2;j<=sqrt(i);j++){
      while(k%j==0){
        m[j]++;
        k=k/j;
      }
     }
     if(k>1){
      m[k]++;
     }
   }
   for(auto i:m){
      ans*=(i.second+1);
      ans%=mod;
      //cout<<i.second<<"\n";
   }
   cout<<ans<<"\n";




}

Measured memory_bytes: 3552
#include <stdio.h>

using namespace std;

const int MAX_N = 50;
char S[MAX_N][MAX_N + 1];

char bomb(int i, int j, int h, int w) {
    int ans = 0;

    if (S[i - 1][j - 1] == '#' && i != 0 && j != 0) {
        ans++;
    }
    if (S[i - 1][j] == '#' && i != 0) {
        ans++;
    }
    if (S[i - 1][j + 1] == '#' && i != 0 && j != w) {
        ans++;
    }

    if (S[i][j - 1] == '#' && j != 0) {
        ans++;
    }
    if (S[i][j + 1] == '#' && j != w) {
        ans++;
    }

    if (S[i + 1][j - 1] == '#' && i != h && j != 0) {
        ans++;
    }
    if (S[i + 1][j] == '#' && i != h) {
        ans++;
    }
    if (S[i + 1][j + 1] == '#' && i != h && j != w) {
        ans++;
    }

    return ans + '0';
}

int main() {

    int H, W;
    scanf("%d %d", &H, &W);

    for (int i = 0; i < H; ++i) {
        scanf("%s", S[i]);
    }

    // for (int i = 0; i < H; ++i) {
    //     for (int j = 0; j < W; ++j) {
    //         printf("%c", S[i][j]);
    //     }
    //     printf("\n");
    // }

    char SS[H][W + 1];
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (S[i][j] == '#') SS[i][j] = '#';
            else SS[i][j] = bomb(i, j, H, W);
        }
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            printf("%c", SS[i][j]);
        }
        printf("\n");
    }

    return 0;
}


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

const int INF = 1001001001;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for (int i = 0; i < N; ++i) cin >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    for (int i = 0; i < K; ++i) ans += p[i];
    cout << ans << endl;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    if (a+b+c>=22)
        cout<<"bust";
    else
        cout<<"win";
    return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 100010

int N;
int A[MAX_N];
int Num[MAX_N];

int main()
{
    ZERO(A);
    ZERO(Num);
    cin >> N;
    REP(i, N) {
        int a;
        scanf("%d", &a);
        Num[a]++;
    }
    int ans = 0;
    REP(i, MAX_N) {
        int tmp = 0;
        if(i != 0) { tmp += Num[i-1]; }
        tmp += Num[i];
        if(i != N) { tmp += Num[i+1]; }
        ans = max(tmp, ans);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <vector>
using namespace std;
int n;
int main ()
{
	scanf("%d",&n);
	if(n%10==n/100) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.*;

public class Main {
	
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int q = sc.nextInt();
			long [][] dp = new long[n][n];
			for(int i = 0; i < m; i++){
				int l = sc.nextInt() - 1;
				int r = sc.nextInt() - 1;
				dp[l][r]++;
			}
			
			for(int i = 1; i < n; i++){
				for(int j = 0; j < n; j++){
					if(j+i >= n)continue;
					dp[j][j + i] += dp[j][j+i-1] + dp[j+1][j+i];
					
					if(j+1 <= j + i - 1){
						dp[j][j + i] -= dp[j+1][j + i - 1];
					}
					
				}
			}
			
			for(int i = 0; i < q; i++){
				int a = sc.nextInt()-1;
				int b = sc.nextInt()-1;
				System.out.println(dp[a][b]);
			}
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


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

using namespace std;
const int MOD = 1000000007;
// T A G C = 0 1 2 3

bool is_ng(int d, int a, int b) {
    if(d == 1 && a == 2 && b == 3) return true;
    return false;
}

void calc(vector<vector<vector<vector<long long>>>> &v, int n, int a, int b, int c) {
    for(int d = 0; d < 4; d++) {
        if(is_ng(b, c, d) || is_ng(c, b, d) || is_ng(b, d, c)) continue;
        if(is_ng(a, c, d) || is_ng(a, b, d)) continue;
        v[n+1][b][c][d] += v[n][a][b][c]  % MOD;
    }
}

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

    vector<vector<vector<vector<long long>>>> v(N+1, vector<vector<vector<long long>>>(4, vector<vector<long long>>(4, vector<long long>(4, 0))));
    v[0][0][0][0] = 1;

    for(int n = 0; n < N; n++) {
        for(int a = 0; a < 4; a++) {
            for(int b = 0; b < 4; b++) {
                for(int c = 0; c < 4; c++) {
                    calc(v, n , a, b, c);
                }
            }
        }
    }
    long long count = 0;
    for(int a = 0; a < 4; a++) {
        for(int b = 0; b < 4; b++) {
            for(int c = 0; c < 4; c++) {
                count += v[N][a][b][c] % MOD;
            }
        }
    }

    cout << count % MOD << endl;
}

Measured memory_bytes: 384
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	string s;
	while(cin>>N>>s) {
		ll ans=0,x=0;
		REP(i, N) {
			x+=s[i]=='I'?1:-1;
			maxUpdate(ans, x);
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;
typedef unsigned long long ULL;
typedef long long LL;

int main(){
    ULL N,A,B;
    ULL temp;
    ULL D;
    ULL ans;
    cin >> N >> A >> B;
    if(A > B){
        temp = A;
        A = B;
        B = A;
    }
    D = B - A;
    if(D % 2 == 0){
        cout << D / 2 << endl;
    }else{
        ans = B - 1;
        ans = min(ans,N - A);
        ans = min(ans,A + (D-1)/2);
        ans = min(ans,N-B+1 + (D-1)/2);
        cout << ans << endl;
    }
    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct knap{
	long long int value;
	long long int weight;
};
int main(){
	long long int n,w;
	cin>>n>>w;
	knap arr[n];
	long long int dp[n+1][w+1];
	for(int i=0;i<n;i++){
		cin>>arr[i].weight>>arr[i].value;
	}
	for (int i =0; i<=n; i++) 
   { 
       for (int j =0; j <=w; j++) 
       { 
           if (i==0 || j==0) 
               dp[i][j] = 0; 
           else if (arr[i-1].weight <= j) 
                 dp[i][j] = max(arr[i-1].value + dp[i-1][j-arr[i-1].weight],dp[i-1][j]); 
           else
                 dp[i][j] =dp[i-1][j]; 
       } 
   } 
	cout<<dp[n][w]<<"\n";
}


Measured memory_bytes: 79104
use std::collections::HashMap;

fn main() {
    proconio::input! {
        n: usize,
        x: String,
    }

    let bp = x.match_indices('1').count() as u64;
    let p = if bp == 1 { vec![2, 1] } else { vec![bp + 1, bp - 1] };

    let xr: Vec<char> = x.chars().rev().collect();

    let mut pows = vec![vec![1, 1]; n];
    let mut xv = if xr[0] == '1' { vec![1; 2] } else { vec![0; 2] };
    for i in 1..n {
        for j in 0..=1 {
            pows[i][j] = (pows[i - 1][j] * 2) % p[j];
            if xr[i] == '1' {
                xv[j] += pows[i][j];
                xv[j] %= p[j];
            }
        }
    }

    for i in (0..n).rev() {
        if bp == 1 && xr[i] == '1' {
            println!("0");
        } else {
            let xi = if xr[i] == '0' {
                (xv[0] + pows[i][0]) % p[0]
            } else {
                let p = if xv[1] >= pows[i][1] { 0 } else { p[1] };
                xv[1] + p - pows[i][1]
            };
            println!("{}", 1 + pop_pop_count(xi));
        }
    }
}

fn pop_pop_count(mut v: u64) -> u64 {
    let mut r = 0;
    while v > 0 {
        v %= v.count_ones() as u64;
        r += 1;
    }
    r
}


Measured memory_bytes: 14060
import java.util.Scanner;

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

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

		int q = scanner.nextInt();
		int[] T = new int[q];
		for (int i = 0; i < q; i++) {
			T[i] = scanner.nextInt();
		}

		for (int i = 0; i < q; i++) {
			int index = T[i];
			int min = 0;
			int max = n - 1;
			int weight;
			while (true) {
				weight = (min + max) / 2;
				if (S[weight] == index) {
					count++;
					break;
				} else if (min > max) {
					break;
				} else {
					if (S[weight] < index) {
						min = weight + 1;
					} else {
						max = weight - 1;
					}
				}
			}
		}
		System.out.println(count);
                scanner.close();
	}
}
	

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

string check(string N){
   int i,same=1;
   char last=N[0];
   for(i=1;i<N.length();i++){
      if(N[i]!=last){
         last=N[i];
         same=1;
      }
      else{
         same++;
      }
      if(same==3)
         break;
   }
   if(same==3)
      return "Yes";
   else
      return "No";
}
int main(){

   string N;
   cin>>N;
   cout<<check(N)<<endl;

return 0;}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int MOD = 998244353;
using namespace std;
const int SIZE = 200010;
int L[SIZE],R[SIZE];
long long dp[SIZE];
long long sum[SIZE]; // sum[i] 代表 dp[1]+...+dp[i]
int get(int l,int r){
    if(l<=1)l=1;
    if(l>r)return 0;
    return ((sum[r]-sum[l-1])%MOD+MOD)%MOD;
}
int main() {
    int N,K;
    cin>>N>>K;
    for(int i=1;i<=K;i++){
        cin>>L[i]>>R[i];
    }
    dp[1]=sum[1]=1;
    for(int i=2;i<=N;i++){
        for(int j=1;j<=K;j++){
            dp[i] = (dp[i] + get(i-R[j],i-L[j])) % MOD;
        }
        sum[i] = (sum[i-1] + dp[i]) %MOD;
    }
    cout<< dp[N] << endl;
    return 0;
}


Measured memory_bytes: 6756
//DPCoded
	//

#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef set<int> si;
typedef set<string> ss;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef pair<int, int> ii;

//#define FILEINOUT
#ifdef FILEINOUT
ifstream In("Input.txt");
ofstream Out("Output.txt");
#else
#define In cin
#define Out cout
#endif

int main() {
	
	int n;
	In >> n;
	ll d;
	In >> d;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ll x, y;
		In >> x >> y;
		if (x * x + y * y <= d * d) ans++;
	}
	Out << ans << endl;
	return 0;
}


Measured memory_bytes: 3192
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:usize,
    b:usize,
    c:usize,
    d:usize,
    e:usize,
    k:usize,
    }
    if max(a,max(b,max(c,max(d,e))))-min(a,min(b,min(c,min(d,e))))>k {println!(":(")}
    else { println!("Yay!") }
}

Measured memory_bytes: 2064
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;


LL solve(long long H, long long W){
	if(H==1||W==1){
		return 1;
	}
	if(H%2==0||W%2==0){
		return H*W/2;
	}
	return (H*W+1)/2;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    cout << solve(H, W) << endl;
    return 0;
}


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

int main()
{
    int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;

    cout << arr[K - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
import * as fs from 'fs';

namespace AtCoder.abc122 {
    class ProgramB {
        args: string[];

        // ATCODER
        // 3
        constructor(args: string[]) {

            this.args = args;
        }

        main(): void {
            // ACGT
            const s: string = this.args[0];
            const target: string[] = ['A', 'C', 'G', 'T'];
            let ans: number = 0;
            let wk: number = 0;
            s.split('').forEach((val: string) => {
                if (target.some(x => x === val)) {
                    wk++;
                } else {
                    wk = 0;
                }
                if (wk >= ans) {
                    ans = wk;
                }
            });

            console.log(ans);
        }
    }

    const args: string[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
    new ProgramB(args).main();
}

Measured memory_bytes: 7500
/*  ex5_3
    yy8332  */

#include <stdio.h>

int main(void){
  int height, width, i, j, k, num = 0;
  char multi_array[100][100];

  //入力読み取り
  scanf("%d %d", &height, &width);

  for(i = 0; i < height; i++){
    for(j = 0; j < width; j++){
      scanf(" %c", &multi_array[i][j]);
    }
  }

  //横の操作
  for(i = 0; i < height; i++){

    for(j = 0; j < width; j++){
      if(multi_array[i][j] == '#'){
        num = 1;
      }
    }

    if(num == 0){
      height -= 1;
      for(k = i; k < height; k++){
        for(j = 0; j < width; j++){
          multi_array[k][j] = multi_array[k + 1][j];
        }
      }
      i -=1;
    }
    num = 0;
  }

  //縦の操作
  for(j = 0; j < width; j++){

    for(i = 0; i < height; i++){
      if(multi_array[i][j] == '#'){
        num = 1;
      }
    }

    if(num == 0){
      width -= 1;
      for(k = j; k < width; k++){
        for(i = 0; i < height; i++){
          multi_array[i][k] = multi_array[i][k + 1];
        }
      }
      j -=1;
    }
    num = 0;
  }


  //出力
  for(i = 0; i < height; i++){
    for(j = 0; j < width; j++){
      printf("%c", multi_array[i][j]);
    }
    printf("\n");
  }


  return 0;
}


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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << ":" << #x << " = " << (x) << endl;
#else
#define dbg
#endif

#pragma endregion Macros

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

    sort(A.begin(), A.end());

    vector<ll> sum(N + 1);
    sum[0] = 0;
    rep(i, N){
        sum[i + 1] = sum[i] + A[i];
    }

    ll ans = 1;

    for (int i = A.size() - 2;i>=0;i--){
        if(sum[i+1]*2 < A[i+1]){
            break;
        }
        ans++;
    }

    cout << ans << endl;


}


Measured memory_bytes: 4848
import sys
from itertools import accumulate

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    R = [0] + list(accumulate(A))
    subs = []
    for left in range(n):
        for right in range(left + 1, n + 1):
            subs.append(R[right] - R[left])

    res = 0
    for mask in reversed(range(40)):
        if len(subs) == 0:
            break
        tmp = []
        for i in range(len(subs)):
            if subs[i] & (1 << mask):
                tmp.append(subs[i])
        if len(tmp) >= k:
            res += 1 << mask
            subs = tmp
    print(res)


if __name__ == '__main__':
    resolve()


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

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

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int n, k;
  cin >> n >> k;
  if(n % k == 0){
    cout << 0 << endl;
  }
  else{
    cout << 1 << endl;
  }
}






Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int n,j;
    while(scanf("%d",&n)!=EOF)
    {

        int c[600],s[600],f[600];
        int i;
        for(i=1; i<n; i++)
        {
            scanf("%d%d%d",&c[i],&s[i],&f[i]);
        }
        int t=0;
        for(i=1; i<n; i++)
        {
            t=0;
            int t=0;
            t=t+c[i]+s[i];
            for(j=i; j<n-1; j++)
            {
                for(;; t++)
                {
                    if(s[j+1]<=t&&t%f[j+1]==0)
                    {
                        t+=c[j+1];
                        break;
                    }
                }
            }
            printf("%d\n",t);
        }
        printf("0\n");
    }
}


Measured memory_bytes: 128
def solver(N, x, requests):
    count = 0
    list.sort(requests)
    for req in requests:
        if x < req or x == 0:
            count += 1
            break
        x -= req
        N -= 1
        count += 1
    if N > 0 or (x > 0 and count > 0):
        count -= 1
    return count
N, x = tuple([int(n) for n in input().split(" ")])
requests = [int(n) for n in input().split(" ")]
print(solver(N, x, requests))

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

int main() {
  ll n;
  cin >> n;
  string s;
  vector<ll> cnt(5);
  rep(i, n) {
    cin >> s;
    switch (s[0]) {
      case 'M':
        cnt[0]++;
        break;

      case 'A':
        cnt[1]++;
        break;

      case 'R':
        cnt[2]++;
        break;

      case 'C':
        cnt[3]++;
        break;

      case 'H':
        cnt[4]++;
        break;

      default:
        break;
    }
  }

  // rep(i, n) cerr << cnt[i] << endl;

  ll ans = 0;
  for (int i = 0; i <= 2; i++) {
    for (int j = i + 1; j <= 3; j++) {
      for (int k = j + 1; k <= 4; k++) {
        ans += cnt[i] * cnt[j] * cnt[k];
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    var inputString = readLine()!!
    val commandNum = readLine()!!.toInt()
    (0 until commandNum).forEach {
        val variables = readLine()!!.split(" ")
        val command = variables[0]
        val startIdx = variables[1].toInt()
        val endIdx = variables[2].toInt()
        when (command) {
            "replace" -> {inputString = inputString.replaceRange(startIdx, endIdx + 1, variables[3])}
            "reverse" -> {inputString = inputString.replaceRange(
                    startIdx, endIdx + 1, inputString.substring(startIdx, endIdx + 1).reversed())
            }
            "print" -> println("${inputString.substring(startIdx, endIdx + 1)}")
        }
    }
}



Measured memory_bytes: 32540
#include <bits/stdc++.h>
using namespace std;
/*  
- Our collaboration has been a thing of beauty.
- And for those who fear Allah , He will make their path easy. 
*/
bool isUpper(char c)
{
   return (c>=65 && c<97);
}
int main()
{
  string s;
  getline(cin,s);
  int len = s.length();
  if(isUpper(s[0]))
   cout<<s[0];
  for(int i =1 ;i<len;++i)
  {
   
    if(isUpper(s[i])&& s[i-1]==' ')
              cout<<s[i];
       
  }
  
}


Measured memory_bytes: 256
//特殊な状態の列挙
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <utility>
using namespace std;

vector<vector<bool>> routes;
vector<bool> node_used;
vector<int> route;
int n, m, count=0;

void perm(int pos){
  if(pos == n){
    for(int i=1; i<n; i++){
      if(!routes.at(route[i-1]).at(route[i])) return;
    }
    count++;
    return;
  }

  for(int i=1; i<n; i++){
    if(!node_used[i]){
      route[pos] = i;
      node_used[i] = true;
      perm(pos+1);
      node_used[i] = false;
    }
  }

  return;
}

int main(){
  //input
  int tmp_1, tmp_2;
  cin >> n >> m;

  vector<vector<bool>> routes_buf(n, vector<bool>(n, false));
  routes.swap(routes_buf);

  vector<bool> node_used_buf(m, false);
  node_used_buf.at(0) = true;
  node_used.swap(node_used_buf);

  vector<int> route_buf(n);
  route.swap(route_buf);

  for(int i=0; i<m; i++){
    cin >> tmp_1 >> tmp_2;
    routes.at(tmp_1-1).at(tmp_2-1) = true;
    routes.at(tmp_2-1).at(tmp_1-1) = true;
  }

  perm(1);

  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, m;
vector<int> g[101010];
int dp[101010];
int indeg[101010];
bool  vis[101010];

int calc(int cur){
    if(vis[cur])return dp[cur];
    vis[cur] = true;
    int ret = 0;
    REP(i, (int)g[cur].size()){
        ret = max(ret, calc(g[cur][i]) + 1);
    }
    return dp[cur] = ret;
}

int main(){
    INIT;
    cin >> n >> m;
    REP(i, m){
        int x, y;
        cin >> x >> y;
        x--, y--;
        g[y].emplace_back(x);
        indeg[x]++;
    }
    REP(i, n){
        if(indeg[i] == 0)calc(i);
    }
    int ans = 0;
    REP(i, n)ans = max(ans, dp[i]);
    cout << ans << endl;
}

Measured memory_bytes: 11264
#include <stdio.h>

#define MAX_NUM 1000000007

long long int MinNum(long long int N, long long int K) {
	if (N > K) {
		return K;
	}
	else {
		return N;
	}
}
int main(void) {
	long long int N, K;
	long long int Amari;
	long long int Amari2;
	long long int minmunNum;
	long long int Sho;
	scanf("%lld %lld", &N, &K);

	Amari = N % K;
	Sho = N / K;
	Amari2 = (Sho + 1) * K - N;
	minmunNum = MinNum(Amari, Amari2);

	printf("%lld\n", minmunNum);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
    int n;scanf("%d",&n);
    int m,M;
    int a[n];scanf("%d",&a[0]);m=a[0],M=a[0];
    for(int i=1;i<n;i++){
        scanf("%d",&a[i]);
        if(m>a[i]) m=a[i];
        if(M<a[i]) M=a[i];
    }   
    printf("%d",M-m);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(i, name)in(i)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(i,v) for(auto &i:(v))
#define all(v) (v).begin(),(v).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  VEC(int, a, N);
  sort(all(a), greater<>());
  int ans = 0;
  rep(i, 0, N) {
    ans += a[i] * (i % 2 ? -1 : 1);
  }
  print(ans);
}


Measured memory_bytes: 256
N, A, B, C, D = map(int, input().split())
S = input()

if "##" in S[A:C] or "##" in S[B:D]:
  print("No")
  exit()

if D - C < 0:
  if "..." not in S[B-2:D+1]:
    print("No")
    exit()
    
print("Yes")

Measured memory_bytes: 3572