akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long LL;
int toInt(string a);
int main() {
	string hws = "1";
	string rig, in;
	int ans;
	cin >> in;
	while (strcmp(hws.c_str(), in.c_str()) < 0 || hws.length() < in.length()) {
		rig = hws;
		int center = ceil(hws.length() / 2.0) - 1;
		if (hws[center] != '9')
			hws[center]++;
		else {
			int i;
			for (i = center; i >= 0; i--)
				if (hws[i] != '9')
					break;
			if (i == -1) {
				for (int j = 0; j < hws.length(); j++)
					hws[j] = '0';
				hws[0] = '1';
				hws += '1';
			}
			else {
				hws[i]++;
				for (int j = i + 1; j <= center; j++) {
					hws[j] = '0';
				}
			}
		}
		for (int j = 0; j <= center; j++) {
			hws[hws.length() - 1 - j] = hws[j];
		}
		//cout << hws << endl;
	}
	
	int l = toInt(rig), c = toInt(in), r = toInt(hws);
	ans = r - c >= c - l ? l : r;
	cout << ans << endl;
	
	return 0;
}
int toInt(string a) {
	int ret = 0;
	for (int i = 0; i < a.length(); i++) {
		ret *= 10;
		ret += a[i] - '0';
	}
	return ret;
}



Measured memory_bytes: 3216
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
string s;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>s;
	for(char ch:s)
	{
	    if(ch=='7')
	    {
	        cout<<"Yes";
	        return 0;
	    }
	}
	cout<<"No";
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    list<int> b;
    stack<int> ans;
    REP(i, n)
    {
        int tmp;
        cin >> tmp;
        b.push_back(tmp);
    }
    while (!b.empty())
    {
        int i = 1;
        bool find = false;
        list<int>::iterator lstitr;
        for (auto itr = b.begin(); itr != b.end(); ++itr)
        {
            if (*itr == i)
            {
                lstitr = itr;
                find = true;
            }
            i++;
        }
        if (!find)
        {
            cout << -1 << endl;
            return 0;
        }
        //cout << *lstitr << endl;
        ans.push(*lstitr);
        b.erase(lstitr);
    }
    while (!ans.empty())
    {
        cout << ans.top() << endl;
        ans.pop();
    }
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string;

void main()
{
    auto s = readln.chomp;
    auto cnt = 0;
    char last = s[0];
    foreach (c; s[1..$]) {
        if (c != last) {
            ++cnt;
            last = c;
        }
    }
    writeln(cnt);
}

Measured memory_bytes: 2556
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <ios>
#include <iomanip>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;

ll pow_ll(ll a, ll n, ll mod){
    ll x = 1;
    while(n>0){
        if(n&1){
            x =  x * a % mod;
            x %= mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return x;
}

void solve() {
    ll m,n;
    cin >> m >> n;
    print(pow_ll(m,n,MOD)%MOD);

}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <math.h>

using namespace std;

int main()
{
	string str;
	int k;
	cin >> str >> k;

	for (int i = 0; i < str.length(); i++)
	{
		if (str.at(i) != 'a')
		{
			int a = 'z' - str.at(i);
			if (a  < k)
			{
				k -= 'z' - str.at(i) + 1;
				str.at(i) = 'a';
			}
		}
	}

	if (k > 0)
	{
		k = k % 26;
		str.at(str.length() - 1) += k;
	}


	cout << str << endl;

//		sort(c, c + n, greater<int>()); //降順ソート

	return 0;
}

Measured memory_bytes: 512
s = input()
t = input()
slen = len(s)
tlen = len(t)
dp = [[0 for j in range(tlen + 1)] for i in range(slen + 1)]
for i in range(slen):
  for j in range(tlen):
    if s[i] == t[j]:
      dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j], dp[i][j + 1])
    else:
      dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
result = ''
i = slen
j = tlen
while i > 0 and j > 0:
  if dp[i - 1][j] == dp[i][j]:
    i -= 1
  elif dp[i][j - 1] == dp[i][j]:
    j -= 1
  else:
    result = s[i - 1] + result
    i -= 1
    j -= 1
print(result)

Measured memory_bytes: 120156
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	string S;
	cin >> S;
	int A = (S[0] - '0') * 10 + (S[1] - '0');
	int B = (S[2] - '0') * 10 + (S[3] - '0');
	int a = 0;
	int b = 0;
	if (1 <= A && A <= 12) {
		a++;
	}
	if (1 <= B && B <= 12) {
		b++;
	}
	if (a == 0 && b == 0) {
		cout << "NA" << endl;
	}
	else if (a == 0 && b != 0) {
		cout << "YYMM" << endl;
	}
	else if (a != 0 && b == 0) {
		cout << "MMYY" << endl;
	}
	else {
		cout << "AMBIGUOUS" << endl;
	}
}

Measured memory_bytes: 764
n,m=map(int,input().split())
b=[]
for i in range(n):
  b.append(input())
ans=[[0]*m for i in range(n)]
d=[-1,0,1]
for i in range(n):
  for j in range(m):
    if b[i][j]=='#':
      for x in d:
        for y in d:
          X=i+x
          Y=j+y
          if 0 <= X < n and 0 <= Y < m:
            ans[X][Y]+=1
import sys
for i in range(n):
  for j in range(m):
    if b[i][j]=='#':
      sys.stdout.write('#')
    else:
      sys.stdout.write(str(ans[i][j]))
  sys.stdout.write('\n')


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int x, y, z;
    cin >> x >> y >> z;
    int ans = 0;
    ans++;
    x -= (y+2*z);
    while(x>0) {
        x -= y+z;
        if (x>=0) ans++;
    }
    
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"


int main()
{
    string s = "";
    cin >> s;
    string ans = "";

    FOR(i, 0, s.size())
    {
        if (s[i] == 'B')
        {
            if (ans.size() > 0)
            {
                ans.pop_back();
            }
        }
        else
        {
            ans.push_back(s[i]);
        }
    }

    COUT(ans);


    return 0;
}

Measured memory_bytes: 256
function main(input: string[]): void {
    const length = 26;
    const alphabet = new Array(length).fill('A')
        .map((v, i) => String.fromCodePoint(v.codePointAt(0) + i));
    const n = parseInt(input.shift(), 10);
    let s = '';
    for (const c of input.shift()) {
        s += alphabet[(alphabet.indexOf(c) + n) % length];
    }
    console.log(s);
}

import { readFileSync } from 'fs';
if (process.argv[1] == __filename) {
    const path = process.argv[2] || '/dev/stdin';
    const input = readFileSync(path, 'utf-8');
    main(input.split(/\s+/));
}

Measured memory_bytes: 7708
n = int(input())
s = ["".join(sorted(input())) for _ in range(n)]

dic = {}
for w in s:
    if w in dic:
        dic[w] += 1
    else:
        dic[w] = 1

ans = 0
for w in dic:
    ans += dic[w] * (dic[w] - 1) // 2

print(ans)


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

int main(){
    string S;
    cin >> S;
    int cnt = 700;
    if (S.at(0) == 'o') {
        cnt = cnt + 100;
    }
    if (S.at(1) == 'o') {
        cnt = cnt + 100;
    }
    if (S.at(2) == 'o') {
        cnt = cnt + 100;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
count = 0

for i in range(1, n-1):
    temp = p[i]
    array = [p[i-1], p[i], p[i+1]]
    array.sort()

    if temp == array[1]:
        count += 1

print(count)


Measured memory_bytes: 38256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vi in(n);
	rep(i,n){
		int a;
		cin>>a;
		a=min(a,24-a);
		in[i]=a;
	}
	sort(all(in));
	rep(i,n)if(i%2)in[i]=24-in[i];
	sort(all(in));
	int mi=in[0];
	rep(i,n-1)mi=min(mi,in[i+1]-in[i]);
	mi=min(mi,24-in[n-1]);
	cout<<mi<<endl;
/*	int l=0,r=24;
	while(r-l>1){
		int h=(l+r)/2;
		int s1=0,s2=0;
		bool H=true;
		rep(i,n){
			int t=in[i];
			
		}
		if(H)l=h;
		else r=h;
	}
	cout<<l<<" "<<r<<endl;
*/
}











Measured memory_bytes: 256
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

//#include "pch.h"
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> R(100000);
vector<bool> Gr(100000, false);

bool dfs(int x) {
	if (Gr[x])
		return false;
	Gr[x] = true;
	for (int j = 0;j < R[x].size();j++)
		dfs(R[x][j]);
	return true;
}

int main() {
	int N, M;
	cin >> N >> M;
	int x, y, z;
	for (int i = 0;i < M;i++) {
		cin >> x >> y >> z;
		x--; y--;
		R[x].push_back(y);
		R[y].push_back(x);
	}
	int cnt = 0;
	for (int i = 0;i < N;i++) {
		if (dfs(i))
			cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 8832
s = input()
K = int(input())
one = list(set(s))
check = 2
if len(s) >= 2:
    while check <= len(s) and check <= 5:
        for i in range(len(s) - check + 1):
            one.append(s[i:i+check])
        check += 1
    one = sorted(set(one))
    print(one[K-1])
    
     
else:
    one = sorted(one)
    print(one[K-1])

Measured memory_bytes: 4980
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a,b;
  cin >> a >> b;

  cout << (a+b+1)/2 << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
    a.append(input().split())

b = 1
for j in a:
    j.append(b)
    b += 1

for k in a:
    x=k.pop(1)
    k.insert(1,int(x)*-1)

a.sort()

for m in a:
    print(m[2])

Measured memory_bytes: 3064
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  string S;
  cin >> S;
  if(S=="SUN"){
    cout << 7 << endl;
  }
  else if(S=="MON"){
    cout << 6 << endl;
  }
  else if(S=="TUE"){
    cout << 5 << endl;
  }
  else if(S=="WED"){
    cout << 4 << endl;
  }
  else if(S=="THU"){
    cout << 3 << endl;
  }
  else if(S=="FRI"){
    cout << 2 << endl;
  }
  else if(S=="SAT"){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

const ll MAX = (ll)1e18;

int main() {
    int n; cin >> n;
    ll t, a; cin >> t >> a;
    rep(_, n-1) {
        int x, y; cin >> x >> y;
        debug(t, a);
        if (x==1 && y==1) {
            if (t<a) t = a;
            else a = t;
        } else if (x<y) {
            ll k1 = (t+x-1)/x, k2 = (a+y-1)/y;
            t = max(k1, k2)*x;
            a = t/x * y;
        } else {
            ll k1 = (t+x-1)/x, k2 = (a+y-1)/y;
            a = max(k1, k2)*y;
            t = a/y * x;
        }
        debug(t, a);
    }
    cout << t + a << endl;
}

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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1; y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

int n, m;
string s;

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

    ll x, y;
    extGCD(n, m, x, y);

    std::cout << x << " " << y << '\n';

    return 0;
}



Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#include <assert.h>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;

int A, B, C, D;
int imos[150];

signed main()
{
    cin >> A >> B >> C >> D;

    imos[A+1]++;
    imos[B+1]--;
    imos[C+1]++;
    imos[D+1]--;

    for (int i=1; i<150; i++) imos[i] += imos[i-1];

    int ans = 0;
    REP(i,150) if (imos[i] == 2) ans++;

    cout << ans << endl;
}


Measured memory_bytes: 256
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
 
def lcm(a, b):
    return a * b // gcd(a,b)
 
N = int(input())
Ts = []
c = 1
for i in range(N):
    c = lcm(c, int(input()))
 
print(int(c))


Measured memory_bytes: 3060
fn main(){
    let mut s:Vec<_> = getline().trim().bytes().collect();
    let mut n = s.len();
    
    let mut b = 1;
    for i in 1..((n+1)/2) {
        let mut ok = true;
        for j in 0..i {
            if s[j as usize] != s[(i+j) as usize] {
                ok = false;
                break;
            }
        }
        if ok { b = i; }
    }
    
    println!("{}", b*2);
}

fn getline() -> String{
    let mut __ret=String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}


Measured memory_bytes: 4352
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
                string input = Console.ReadLine();
                string[] nml = input.Split(' ');
                int n = int.Parse(nml[0]);
                int m = int.Parse(nml[1]);
                int l = int.Parse(nml[2]);

                int[,] a = new int[n, m];
                int[,] b = new int[m, l];
                long[,] c = new long[n, l];

                for (int i = 0; i < n;i++ )//a????????????a?????????????????£??\
                {
                    string inputa = Console.ReadLine();
                    string[] arraya = inputa.Split(' ');
                    for (int j = 0; j < m; j++)
                    {
                        a[i, j] = int.Parse(arraya[j]);
                    }
                }

                for (int i = 0; i < n; i++)//c????????????0??§?????????
                {
                    for (int j = 0; j < l; j++)
                    {
                        c[i, j] = 0;
                    }
                }

                    for (int i = 0; i < m; i++)//b????????????a?????????????????£??\
                    {
                        string inputb = Console.ReadLine();
                        string[] arrayb = inputb.Split(' ');
                        for (int j = 0; j < l; j++)
                        {
                            b[i, j] = int.Parse(arrayb[j]);
                        }
                    }

                for (int i = 0; i < n; i++)//3
                {
                    for (int j = 0; j < m; j++)//2
                    {
                        for (int k = 0; k < l; k++)//3
                        {
                            c[i,k] = c[i,k] + a[i,j]*b[j,k];
                        }
                    }
                }

                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < l; j++)
                    {
                        Console.Write(string.Format("{0}", c[i, j]));
                        if (j == l - 1)
                            break;
                        Console.Write(" ");
                    }
                    Console.WriteLine();
                }         
        }
    }
}

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

enum Week { sunday, monday }
public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine().Trim();
            if (s.Length == 1) Console.WriteLine(0);
            else Console.WriteLine(GetCount(s));
        }
    }
    public static int GetCount(string s)
    {
        var count = 0;
        while (true)
        {
            var sL = s.Length;
            var nL = new List<int>();
            for (int i = 1; i < sL; i++)
            {
                var s1 = s.Substring(0, i);
                var s2 = s.Substring(i);
                nL.Add(int.Parse(s1) * int.Parse(s2));
            }
            count++;
            var nLmax = nL.Max();
            if (nLmax < 10) return count;
            else if (s == nLmax.ToString()) return -1;
            else s = nLmax.ToString();
        }
    }
}

Measured memory_bytes: 9792
import java.lang.IllegalArgumentException

fun main(args: Array<String>) {
	val (n, m) = readLine()?.split(" ")?.map {it.toInt()} ?: throw IllegalArgumentException()
	
	val friendsUnion = FriendsUnion(n)
	repeat(m) {
		val (a, b) = readLine()?.split(" ")?.map { it.toInt() } ?: throw IllegalArgumentException()
		with(friendsUnion) { addFriends(a, b) }
	}
	println(friendsUnion.maxUnionNumber())
}

data class FriendsUnion(val n: Int, val rootList: MutableList<Int> = MutableList(n+1) {it}, val unionNumberList: MutableList<Int> = MutableList(n+1) {1}) {
	fun addFriends(friend1: Int, friend2: Int) {
		//添え字が若い方を親とする
		var (parent, child) = if (friend1 < friend2) Pair(friend1, friend2) else Pair(friend2, friend1)
		//それぞれのrootを探す
		val parentRootIndex = findRoot(parent)
		val childRootIndex = findRoot(child)
		//rootが同じならそのまま
		return if (parentRootIndex == childRootIndex) return else {
			//rootが違うなら子グループを親グループにマージ。
			unionNumberList[parentRootIndex] += unionNumberList[childRootIndex]
			unionNumberList[childRootIndex] = 0
			//子グループのrootの親を、親グループのrootにしておく。
			rootList[childRootIndex] = parentRootIndex
		}
	}
	
	private fun findRoot(friend: Int): Int {
		//rootが自分だった場合、自分を返す。
		return if (rootList[friend] == friend) friend else {
			//rootが自分じゃない場合、親がrootか判定した上で、親をrootにする(後々のfindRootを早くするため)。
			rootList[friend] = findRoot(rootList[friend])
			rootList[friend]
		}
	}
	
	fun maxUnionNumber(): Int {
		return unionNumberList.max() ?: throw IllegalArgumentException()
	}
}

Measured memory_bytes: 69112
"""
r>=kのものを調べる
bがN以下、aがb以下でfor loop
K

for loopを1重にしたい->0~Nまで動かすとどうなるか考える
bを固定する
N=b*p+r (r:あまり)

あるbについてaを0~Nまで動かすと、a%b=0,1,2,...,b-1,0,...
(0~b-1)がp回繰り返され、最後に0,1,...,r-1,rがつけ加わった形になる

あまりの数は、(b-K)*p + (r-K+1)
"""
N, K = map(int, input().split())

ans = 0

for b in range(1,N+1): #1~Nまで
  r = N%b
  p = (N-r)//b
  ans += max(0,(b-K)*p) + max(0,(r-K+1))

#a=0のときは、K=0で問題になりansからNを引けば良い
if K==0:
  ans -=N

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  //string S{}; std::cin >> S;
  ui X{}, Y{}, Z{}, K{}; cin >> X >> Y >> Z >> K;
  
  vector<ull> A(X), B(Y), C(Z);
  rep(0, A.size()) cin >> A[i];
  rep(0, B.size()) cin >> B[i];
  rep(0, C.size()) cin >> C[i];
  
  boost::sort(A, std::greater<ull>());
  boost::sort(B, std::greater<ull>());
  boost::sort(C, std::greater<ull>());

  std::priority_queue<ull, vector<ull>, std::less<ull>> queue;

  rep(0, X)
  {
    if(i + 1 > K) break;
    rep_uj(0, Y)
    {
      if((i + 1) * (j + 1) > K) break;
      for(ui k = 0; k < Z; ++k)
      {
        if((i + 1) * (j + 1) * (k + 1) <= K)
          queue.push(A[i] + B[j] + C[k]);
        else
          break;
      }
    }
  }
          

  rep(0, K)
  {
    std::cout << queue.top() << '\n';
    queue.pop();
  }

  using std::cout;
  // cout << ans << '\n';
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 1404
import sys
sys.setrecursionlimit(10**7)

N, M = map(int, input().split())

R = [[] for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    R[a - 1].append((b - 1, c))

INF = 10 ** 40
S = [-INF] * N
S[0] = 0

def score(fst, s, C):
    for nx, p in R[fst]:
        if S[nx] >= s + p or S[nx] >= INF:
            continue
        S[nx] = s + p
        if nx in C:
            S[nx] = INF
        C[nx] = C.get(nx, 0) + 1
        score(nx, S[nx], C)
        C[nx] -= 1
        if C[nx] == 0:
            del C[nx]

score(0, 0, {0: 1})

if S[-1] < INF:
    ans = S[-1]
else:
    ans = "inf"

print(ans)


Measured memory_bytes: 10648
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vector<pair<ll,int>> a;
  REP(i,n) {
    ll v;
    cin>>v;
    a.emplace_back(v, i);
  }
  sort(ALL(a), greater<pair<ll,int>>());
  vecll dp(n+1, 0);
  REP(i,n) {
    auto [x, k] = a[i];
    vecll tmp(n+1, 0);
    REP(j,i+1) {
      int rev = (n-1)-(i-j);
      tmp[j+1] = max(tmp[j+1], dp[j] + abs(j-k) * x);
      tmp[j] = max(tmp[j], dp[j] + abs(rev-k) * x);
    }
    swap(tmp, dp);
  }
  cout<<*max_element(ALL(dp))<<endl;
  return 0;
}


Measured memory_bytes: 3740
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
import itertools
# import math
# import networkx as nx
from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n,k=n1()
D=n1()

t=tuple(int(i) for i in str(n))

D2=[i for i in range(10) if not i in D]

ite=list(itertools.product(D2,repeat=(len(str(n)))))

index=bisect_left(ite,t)
if index==len(ite):
    if D2[0]==0:
        ans="".join([str(D2[1])]+["0"]*len(str(n)))
    else:
        ans="".join([str(D2[0])]*(len(str(n))+1))
else:
    ans="".join([str(i) for i in ite[bisect_left(ite,t)]])
print(ans)

Measured memory_bytes: 3572
#include <iostream>
#include <string>
using namespace std;
int main() {
    int n, o, sum;
    int f[3];
    string str;
    cin >> n;
    for (int i = 0; i < n; i++) {
        fill(f, f+3, 0);
        sum = o = 0;
        while (1) {
            cin >> str;
            if (str == "OUT") {
                o++;
                if (o == 3) break;
            }
            else if (str == "HOMERUN") {
                sum++;
                for (int i = 0; i < 3; i++) if (f[i] == 1) sum++, f[i] = 0;
            }
            else if (str == "HIT") {
                if (f[2] == 1) sum++, f[2] = 0;
                for (int i = 1; i >= 0; i--) if (f[i] == 1) swap(f[i], f[i+1]);
                f[0] = 1;
            }
        }
        cout << sum << endl;
    }
    return 0;
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int plan1 = A * N;
  int plan2 = B;
  if (plan1 < plan2) {
    cout << plan1 << endl;
  } else {
    cout << plan2 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a);i>int(b);--i)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define show(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl;
#define MOD 1000000007
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define SZ(x) ((int)(x).size())
#define sum(v,i) accumulate(all(v),i)
//#define int long long
using ll = long long;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
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; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }//最大公約数
int lcm(int a, int b) { return a * b / gcd(a, b); }	//最小公倍数
//template <typename... Args>void IN(Args& ... args) {cin >>args;IN(args...);return;} //まとめて入力　IN(a,b,c,d...)

void Main(){
	int n; cin >> n;
	if (n % 2 == 0)n--;
	cout << n / 2;
}

signed main() {
	Main();

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <array>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define REV(v) rbegin(v), rend(v)
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef unsigned long long ull;

const int N = 110;
long long C[N][N];

long double prob[N][N];
long double _time[N][N];

int main(){
	C[0][0] = 1;
	rep(i, N - 1) rep(j, i + 1){
		C[i + 1][j] += C[i][j];
		C[i + 1][j + 1] += C[i][j];
	}

	int n, m, L;
	cin >> n >> m >> L;

	vector<int> p(n), t(n), v(n);
	rep(i, n) cin >> p[i] >> t[i] >> v[i];

	rep(i, n){
		_time[i][0] = (double)L / v[i];
		FOR(j, 1, m + 1) _time[i][j] = _time[i][j - 1] + t[i];

		FOR(j, 0, m + 1){
			prob[i][j] = C[m][j] * pow(p[i] / 100., j) * pow((1 - p[i] / 100.), m - j);
			//cout << pow(p[i] / 100., j) << ' ' << pow(1 - p[i] / 100., m-j) << endl;
		}
	}

	cout.setf(ios::fixed);
	cout.precision(10);

	rep(i, n){
		long double a = 0;
		if (v[i]) rep(j, m + 1){
			long double ct = _time[i][j];
			long double cp = prob[i][j];
			rep(k, n){
				if (i == k) continue;
				int idx = m;
				long double tmp = 0;
				while (idx >= 0 && _time[k][idx] > ct) tmp += prob[k][idx--];
				cp *= tmp;
			}
			a += cp;
		}
		cout << a << endl;
	}


	return 0;
}

Measured memory_bytes: 1792
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[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)*) => {
        #[allow(unused_mut)]
        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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        a: usize,
        b: usize,
    }
    let mut ans = -1;
    for i in 1..1250 {
        if i * 8 / 100 == a && i / 10 == b {
            ans = i as isize;
            break;
        }
    }
    println!("{}", ans);
}


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

using namespace std;

#define ll long long

struct node {
	int n; // 頂点の番号
	ll c = 0; // カウンター
	ll temp = 0;
	bool isVisited = false;
	set<int> children;
};

node* g;

void solve(int r, ll count) {
	g[r].isVisited = true;
	count += g[r].temp;
	g[r].c = count;
	for (auto vi : g[r].children) {
		if (!g[vi].isVisited)
			solve(vi, count);
	}
}

signed main() {
	int n, q;
	cin >> n >> q;
	g = new node[n];
	for (int i = 0; i < n; ++i)
		g[i].n = i;

	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].children.insert(b);
		g[b].children.insert(a);
	}

	while (q--) {
		int p, x;
		cin >> p >> x;
		--p;
		g[p].temp += x;
	}

	solve(0, 0);

	for (int i = 0; i < n; ++i)
		cout << g[i].c << " ";
	cout << endl;

	return 0;
}


Measured memory_bytes: 46080
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
  	int c = 0;
    vector<int> a(200);
  cin >> n;
  bool f = false;
  for (int i = 0; i < n; i++) cin >> a.at(i);
  while(true){
  	for (int i = 0; i < a.size(); i++){
  		if(a.at(i)%2 != 0) {
      		f = true;
    	}
    }
       if (f) break;  
  	for (int i = 0;i < a.size(); i++){
      a.at(i)/=2;
      }
     c++;
  }
  cout << c << endl;
  }

Measured memory_bytes: 3540
<?php
  $input = fgets(STDIN);
  $arr1 = str_split($input);

  if(($arr1[0] == $arr1[1]) && ($arr1[1] == $arr1[2]) && ($arr1[0] == $arr1[2])) {
    echo "No";
  }else {
    echo "Yes";
  }
?>

Measured memory_bytes: 4728
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 a[][] = new int[n][m];
        int b[] = new int[m];
        for(int i = 0 ; i < n ; i++)
        {
            for(int j = 0 ; j < m ; j++)
                a[i][j] = sc.nextInt();
        }
        for(int i = 0 ; i < m ; i++)
            b[i] = sc.nextInt();
        for(int i = 0 ; i < n ; i++)
        {
            int sum = 0;
            for(int j = 0 ; j < m ; j++)
            {
                sum += a[i][j] * b[j];
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 40176
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct _Node{
    int key;
    struct _Node *right;
    struct _Node *left;
    struct _Node *parent;
} Node;
Node* getMinimum(Node []);
Node* find(Node [],int);
Node* getSuccessor(Node []);
void deleteNode(Node []);
void insert(int);
void inorder(Node []);
void preorder(Node []);

Node *root,*NIL;

int main(){
    int n,i,x;
    char std[10];
    Node *tmp;

    scanf("%d",&n);

    for(i=0;i<n;i++){
        scanf("%s",std);
        if(std[0] == 'f'){
            scanf("%d",&x);
            tmp = find(root,x);
            if(tmp != NIL) printf("yes\n");
            else printf("no\n");
        }
        else if(strcmp(std,"insert")==0){
            scanf("%d",&x);
            insert(x);
        }
        else if(strcmp(std,"print")==0){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        else if(strcmp(std,"delete")==0){
            scanf("%d",&x);
            deleteNode(find(root,x));
        }
    }

    return 0;
}

Node* getMinimum(Node *x){
    while(x->left != NIL){
        x = x->left;
    }
    return x;
}

Node * find(Node *u,int k){
    while(u != NIL && k != u->key){
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

Node * getSuccessor(Node *x){
    Node *y;

    if(x->right != NIL){
        return getMinimum(x->right);
    }
    y = x->parent;
    while(y != NIL && x == y->right){
        x = y;
        y = y->parent;
    }
    return y;
}

void deleteNode(Node *z){
    Node *y;
    Node *x;

    if(z->left == NIL || z->right == NIL){
        y = z;
    }
    else{
        y = getSuccessor(z);
    }

    if(y->left != NIL){
        x = y->left;
    }
    else{
        x = y->right;
    }

    if(x != NIL){
        x->parent = y->parent;
    }

    if(y->parent == NIL){
        root = x;
    }
    else{
        if(y == y->parent->left){
            y->parent->left = x;
        }
        else{
            y->parent->right = x;
        }
    }

    if(y != z){
        z->key = y->key;
    }

    free(y);
}

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z -> key = k;
    z -> left = NIL;
    z -> right = NIL;

    while(x != NIL){
        y = x;
        if(z -> key < x -> key){
            x = x -> left;
        }else{
            x = x -> right;
        }
    }
    z -> parent = y;
    if(y ==NIL){
        root = z;
    }else{
        if(z -> key < y -> key){
            y -> left = z;
        }else{
            y -> right = z;
        }
    }
}

void inorder(Node *u){
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(Node *u){
    if(u == NIL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}


Measured memory_bytes: 20524
N,K=map(int,input().split())
P=list(map(lambda x:int(x)-1,input().split()))
C=list(map(int,input().split()))

ans=0
check=set()

for i in range(N):
    
    if i in check:
        continue
    
    # create loop
    tmpK=K
    tmpans=0
    loop_check=set()
    tmp_idx=i
    loop=[]
    while tmp_idx not in loop_check:
        loop.append(C[tmp_idx])
        loop_check.add(tmp_idx)
        check.add(tmp_idx)
        tmp_idx=P[tmp_idx]
    
    S=sum(loop)
    L=len(loop)
    if S>=0 and tmpK//L>=2:
        tmpans=S*(tmpK//L-1)
        tmpK=tmpK%L+L
    
    # 部分最大列を検索
    #print('loop',loop)
    loop=[0]+loop*3
    for i in range(len(loop)-1):
        loop[i+1]+=loop[i]
    n=3*L+1
    def init_min(init_min_val):
        #set_val
        for i in range(n):
            seg_min[i+num_min-1]=init_min_val[i]    
        #built
        for i in range(num_min-2,-1,-1) :
            seg_min[i]=min(seg_min[2*i+1],seg_min[2*i+2])
    def query_min(p,q):
        if q<=p:
            return ide_ele_min
        p += num_min-1
        q += num_min-2
        res=ide_ele_min
        while q-p>1:
            if p&1 == 0:
                res = min(res,seg_min[p])
            if q&1 == 1:
                res = min(res,seg_min[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = min(res,seg_min[p])
        else:
            res = min(min(res,seg_min[p]),seg_min[q])
        return res
    #####単位元######
    ide_ele_min = 10**15
    #num_min:n以上の最小の2のべき乗
    num_min =2**(n-1).bit_length()
    seg_min=[ide_ele_min]*2*num_min

    init_min(loop)
    local_max=0
    for i,v in enumerate(loop):
        if i>=1:
            #print('v,min=',v,query_min(max(0,i-tmpK),i),v-query_min( max(0,i-tmpK),i ))
            local_max=max(local_max,v-query_min( max(0,i-tmpK),i ) )
    
    ans=max(ans,local_max+tmpans)

if ans==0:
    print(max(C))
else:
    print(ans)




Measured memory_bytes: 76608
#include<iostream>
#include<cstdio>
using namespace std;
int main( ){
  int n,a,b,c,d=0,max=0,t[101],hi;
  cin>>n>>a>>b>>c;
  for(int i=1;i<=n;i++){
    cin>>t[i];
  }
  for(int j=1;j<=n;j++){
    for(int i=1;i<=n-1;i++){
      if(t[i]<t[i+1]){
        int tmp;
        tmp=t[i];
        t[i]=t[i+1];
        t[i+1]=tmp;
      }
    }
  }
  for(int i=1;i<=n;i++){
    d+=t[i];
    hi=(c+d)/(a+b*i);
    if(hi>max)max=hi;
  }
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 3152
def LI():return list(map(int,input().split()))
def yes():print("Yes")
def no():print("No")
# from collections import defaultdict,deque,Counter
# from heapq import heappush,heappop
# import numpy as np
# n=int(input())

t=input()
t=t.replace("?","D")
print(t)

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

int main(){
    char s[11];
    cin>>s;
    int n=strlen(s)-1;
    ll ans=0;
    ll tmp;
    for(int bit=0;bit<(1<<n);bit++){
        tmp=s[0]-'0';
        for(int j=0;j<n;j++){
            if(bit&(1<<j)){
                ans+=tmp;
                tmp=0;
            }
            tmp=tmp*10+(s[j+1]-'0');
        }
        ans+=tmp;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e9 + 7;

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

  ll n;
  cin >> n;

  if(n == 3 || n == 5 || n == 7) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TOPSIC2
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            string[] A = Console.ReadLine().Split(' ');
            int[] ans = new int[N];

            for (int i = 0; i < N - 1; i++)
            {
                ans[int.Parse(A[i]) - 1]++;
            }

            foreach(var ele in ans)
            {
                Console.WriteLine(ele);
            }
        }
    }
}


Measured memory_bytes: 38276
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<iostream>
#include<cstdint>
#include<vector>
#include<cstddef>

using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64, i64>;
vector<vector<P>> G;
vector<i32> ans;
void dfs(i32 now,i32 parent, i32 color){
    ans[now] = color;
    for(auto &v : G[now]){
        if(v.first == parent)continue;
        if(v.second % 2)dfs(v.first,now,1- color);
        else dfs(v.first,now,color);
    }
}
int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i64 n;
    cin >> n;
    G.resize(n);
    rep(i,n - 1){
        i32 u,v,w;
        cin >> u >> v >> w;
        G[u - 1].emplace_back(P(v - 1, w));
        G[v - 1].emplace_back(P(u - 1, w));
    }
    ans.assign(n,0);
    dfs(0,-1,1);
    for(auto &v : ans)cout << v << endl;
}

Measured memory_bytes: 14232
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  int a,b;
  char op;
  cin >> a >> op >> b;
  while(op!='?'){
    int c;
    if(op=='+') c=a+b;
    if(op=='-') c=a-b;
    if(op=='*') c=a*b;
    if(op=='/') c=a/b;
    cout << c << endl;
    cin >> a >> op >> b;
  }
  return 0;
}


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

signed main(){
    int N,K;cin>>N>>K;
    string s;cin>>s;
    int j=0,ans=0,count=0;
    if(s[0]=='1') count--;
    REP(i,N){
        if(i>0&&s[i-1]=='0'&&s[i]=='1') count--;
        while(j<N &&count<K){
            if(j<N-1&&s[j]=='1'&&s[j+1]=='0') count++;
            j++;
        }
        //cout<<j-i<<endl;
        ans=max(ans,j-i);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

#include <bitset>

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  std::map<int,int> a;
  int result=0;
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    if(a.find(tmp)==a.end()){
      a.insert(std::make_pair(tmp,1));
    }else{
      a[tmp]++;
    }
  }
  for(auto itr=a.rbegin();itr!=a.rend();itr++){
    while((*itr).second>0){
      if((*itr).second<=0) continue;
      a[(*itr).first]--;
      int target_sum=1;
      while(target_sum<=(*itr).first){
        target_sum*=2;
      }
      int searching=target_sum-(*itr).first;
      if(a.find(searching)!=a.end()&&a[searching]>=1){
        result++;
        a[searching]--;
      }
    }

  }




  cout<<result<<endl;

  return 0;
}

Measured memory_bytes: 9600