akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include <stdio.h>
#include <functional>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

string x(string s, const string cs, const string se) {
	int pos = 0;
	while ((pos = s.find_first_of(se)) != string::npos) {
		s.replace(pos, 1, cs);
	}
	return s;
}

string y(string a) {
	int pos4 = 0, pos9 = 0;
	a = x(a, "3", "5");
	a = x(a, "5", "6");
	a = x(a, "6", "7");
	a = x(a, "7", "8");
	int pos = a.length();
	if ((pos4 = a.find_first_of("4")) != string::npos && (pos9 = a.find_first_of("9")) != string::npos)
	{
		if (pos4 > pos9) {//4>9
			a = a.replace(pos9, 1, "7");
			pos = pos9 + 1;
		}
		else {
			a = a.replace(pos4, 1, "3");
			pos = pos4 + 1;
		}
	}
	else if ((pos4 = a.find_first_of("4")) != string::npos) {
		a = a.replace(pos4, 1, "3");
		pos = pos4 + 1;
	}
	else if ((pos9 = a.find_first_of("9")) != string::npos) {
		a = a.replace(pos9, 1, "7");
		pos = pos9 + 1;
	}
	while (pos != a.length()) {
		a = a.replace(pos, 1, "7");
		pos++;
	}
	return a;
}

int n;
int m;
int aji[100000];

int saiki(int cnt){
	int num = 0;
	vector<int> v;
	char c;
	bool flag = false;
	while (true) {
		cin >> c;
		if (c == '[') {
			num = saiki(cnt + 1);
			if (cnt == 0) {
				break;
			}
			v.push_back(num);
			num = 0;
		}
		else if (c == ']') {
			if (num != 0) {
				v.push_back(num + 1);
			}
			if (v.size() > 0) {
				sort(v.begin(), v.end());
				num = 0;
				for (int i = 0; i < v.size() / 2 + 1; i++) {
					num += v[i];
				}
			}
			//cnt--;
			
			return num;
		}
		else{
			num = num * 10 + (c - '0');
		}
	}
	return num;
}

int main(){
	int n;
	int cnt = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cout << saiki(0) / 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
#include<iostream>
#include <algorithm>
#define ULL unsigned long long 

using namespace std;

ULL lcm(ULL a,ULL b){
	if(a%b==0){
		return b;
	}return lcm(b,a%b);
}

int main(){
	ULL n,m;
	cin >> n >> m;
	cout << min(n-(n/m)*m,(n/m+1)*m-n);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define mREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } 
ll ans[2000];
int main(){
  int N,M,X,Y;
  cin >> N >> M >> X >> Y;
  vector<int>x(N);
  vector<int>y(M);
  rep0(i,N)cin >> x[i];
  rep0(i,M)cin >> y[i];
  int Z;
  sort(all(x));
  sort(all(y));
  Z = y[0];
  if(Z <= x[N-1]){
    cout << "War" << endl;
    return 0;
  }
  if(X < Z && Z <= Y){
    cout << "No War" << endl;
    return 0;
  }
  else{
    cout << "War" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>

#define rep(i,n) for(int i= 0; i < n; ++i)
#define X first
#define Y second
#define all(x) x.begin(), x.end()
typedef long long ll;
using namespace std;

ll n, a, b;
vector<ll> h;

bool c(ll cnt){
  vector<ll> tmp = h;
  ll d = b*cnt;
  ll s = a-b;
  ll ne = 0;
  rep(i,n) tmp[i] -=d;

  rep(i,n){
    if(tmp[i] > 0){
      ne += tmp[i]/s;
      if(tmp[i]%s != 0)ne++;
    }
  }
  return cnt >= ne;
}

int main(void){
  cin >> n >> a >> b;
  h.resize(n);
  for(auto& hi:h)cin >> hi;
  sort(all(h));
  ll mx = h.back();

  ll l = 0;
  ll r = 2000000000LL;
  while(l < r){
    ll mid = (l+r)/2;
    if(c(mid)){
      r=mid;
    }else{
      l=mid+1;
    }
  }

  cout << r << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k, sum=1;
  cin >> n >> k;
  
  for(int i=0; i<n; i++){
    if(sum*2 > sum+k) sum += k;
    else sum *=2;
  }

  cout << sum << endl;
}

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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A-B==0){
        cout << C << endl;
    }else if(B-C==0){
        cout << A << endl;
    }else{
        cout << B << endl;
    }
}


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

using namespace std;

const int mod = 998244353;

int main(){
  int N, S;
  cin >> N >> S;
  
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  
  vector<vector<long long>> dp(N + 1, vector<long long>(S + 1, 0));
  dp[0][0] = 1;
  for(int i = 0; i < N; i++){
    for(int j = 0; j <= S; j++){
      (dp[i + 1][j] += 2 * dp[i][j]) %= mod;
      if(j + A[i] <= S) (dp[i + 1][j + A[i]] += dp[i][j]) %= mod;
    }
  }
  
  cout << dp[N][S] << endl;
  
  return 0;
}

Measured memory_bytes: 73716
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;


// 75 = 3 * 5^2
int main() {
    
    int n;
    cin >> n;
    
    const vector<int> p = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
    const int pn = p.size();
    vector<int> f(p.size(), 0);
    
    // factorize N!
    for (int i = 1; i <= n; i++) {
        int m = i;
        if (m == 1) continue;
        for (int j = 0; j < pn; j++) {
            while (m % p[j] == 0) {
                m /= p[j];
                f[j]++;
            }
        }
    }
    
    // count them out
    
        int ans = 0;
    
        // (2, 4, 4)
        int over4 = 0;
        for (int i = 0; i < pn; i++)
            if (f[i] >= 4) over4++;
        for (int i = 0; i < pn; i++) {
            if (f[i] < 2) continue;
            int cand = f[i] >= 4 ? over4 - 1 : over4;
            ans += cand * (cand - 1) / 2;
        }
        
        // (4, 14)
        int over14 = 0;
        for (int i = 0; i < pn; i++)
            if (f[i] >= 14) over14++;
        ans += over14 * (over4 - 1);
        
        // (2, 24)
        int over2 = 0, over24 = 0;
        for (int i = 0; i < pn; i++) {
            if (f[i] >=  2) over2++;
            if (f[i] >= 24) over24++;
        }
        ans += over24 * (over2 - 1);
        
        // (74)
        if (f[0] >= 74) ans++;
        
    // answer to it
    cout << ans << endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        String op;
        Scanner scan = new Scanner(System.in);
        while(true){
            int a = scan.nextInt();
            op = scan.next();
            int b = scan.nextInt();
            if(op.equals("+")){
                System.out.println(a+b);
            }
            if(op.equals("-")){
                System.out.println(a-b);
            }
            if(op.equals("*")){
                System.out.println(a*b);
            }
            if(op.equals("/")){
                System.out.println(a/b);
            }
             
            if(op.equals("?")){
                break;
            }
 
        }
    }
 
}

Measured memory_bytes: 26448
fun main(){
    val input: List<Int> = readLine()!!.split(" ").map { it.toInt() }//条件入力
    val bucket: Array<Int?> = Array(input[0]){0}
    val getnumber = readLine()!!.split(" ").map { it.toInt() }
    for(a in getnumber){
        bucket[a-1] = bucket[a-1]?.plus(1)
    }
    for(a in bucket)
    println(a)
}

Measured memory_bytes: 71436
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
const int INF=0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;
template <typename _Tp> inline void read(_Tp&x);
inline void print(__int128 x);

char s[200005];
int a[200005],b[200005];
int main()
{
	int n;
	cin>>n;
	scanf("%s",s+1);
	int cnt=0,ans=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='R')cnt++;
	}
	for(int i=1;i<=cnt;i++){
		if(s[i]=='W')ans++;
	}
	cout<<ans<<endl;
 	return 0;
}
template <typename _Tp> inline void read(_Tp&x) {
	char ch;bool flag=0;x=0;
	while(ch=getchar(),!isdigit(ch)) if(ch=='-')flag=1;
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	if(flag) x=-x;
}
inline void print(__int128 x) {
	if(x<0) {x=-x;putchar('-');}
	if(x>9) print(x/10);
	putchar(x%10+'0');
}


Measured memory_bytes: 3960
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin>>n;
cout<<round(n/2.0)<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;

ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}

map<ll, int> prime_factor(ll n) {
  map<ll, int> res;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if(n != 1) res[n] = 1;
  return res;
}


int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
ll A,B;
cin >> A >> B;
ll G = gcd(A, B);
map<ll ,int> mp = prime_factor(G);
cout << SZ(mp)+1 << endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define PI (acos(-1))
#define _GLIBCXX_DEBUG

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

  int t = 0, x = 0, y = 0;
  rep(i, n){
    int it, ix, iy;
    cin >> it >> ix >> iy;

    int d = abs(x - ix) + abs(y - iy);
    if(d > (it - t) || (d - (it - t)) % 2 != 0){
      cout << "No" << endl;
      return 0;
    }
    else{
      t = it;
      x = ix;
      y = iy;
    }
  }

  cout << "Yes" << endl;

}

Measured memory_bytes: 256
MOD = 10**9+7

N = int(input())
x = list(map(int, input().split()))

ans = 0
mul = 0
for i in range(N-1):
    mul += pow(i+1, MOD-2, MOD)
    ans += (x[i+1] - x[i]) * mul % MOD
    ans %= MOD
for i in range(2, N):
    ans *= i
    ans %= MOD
print(ans)


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

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

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

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

    int count = 0;
    int max = 0;

    for(int i=0; i<N; i++){
        if(max < vec[i]){
            max = vec[i];
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define YY "YES\n"
#define NN "NO\n"
#define f first
#define s second
#define LL long long
using namespace std;

string s,s1,s2,s3,s4,tmp;
int a,b,c,d,n,aa,bb,cc,dd;
int main(){
	cin>>s;
	n=s.length();
	s1="dream";
	s2="dreamer";
	s3="erase";
	s4="eraser";
	bool ok=true;
	for (int i=0;i<n;i++){
		if (s[i]=='d'){
			int j;
			for (j=i;j<=i+4;j++){
				if (j>=n || s[j]!=s1[j-i]){
					ok=false;
					break;
				}
			}
			if(j==i+5) {
	            if(s[j]=='e' && s[j+1]=='r' && s[j+2]!='a') i=j+1;
	            else i=j-1;
	        }
		}
		else if (s[i]=='e'){
			int j;
			for (j=i;j<=i+4;j++){
				if (j>=n || s[j]!=s3[j-i]){
					ok=false;
					break;
				}
			}
			if(j==i+5) {
	            if(s[j]=='r')i=j;
	            else i=j-1;
	        }
		}
		else ok=false;
	}	
	cout<<(ok==true? YY:NN);
}


Measured memory_bytes: 3732
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int d = in.nextInt();
        int[] ci = new int[26];
        int[][] sdi = new int[d][26];
        for(int i=0; i<26; i++) {
            ci[i] = in.nextInt();
        }
        for(int day=0; day<d; day++) {
            for(int i=1; i<26; i++) {
                sdi[day][i] = in.nextInt();
            }
        }
        
        for(int day=0; day<d; day++) {
            int ans = 1;
            if(day<d-26) {
                int maxS = 0;
                int maxStype = 1;
                for(int i=0; i<26; i++) {
                    if(maxS < sdi[day][i]) {
                        maxS = sdi[day][i];
                        maxStype = i;
                    }
                }
                ans = maxStype;
            }
            else {
                ans = d - day; // FIXME
            }
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 46200
import heapq
k = int(input())
graph = [[] for i in range(k)]
for i in range(k):
    if i != k-1: graph[i].append((1, i+1))
    else: graph[i].append((1, 0))
    if (i * 10) % k != i: graph[i].append((0, (i * 10) % k))

que = []
heapq.heappush(que, (0, 1, 1)) #現在の頂点の始点からの距離,頂点の番号, 操作途中の数
dist = [1145141919] * k
dist[1] = 0

ans = 1145141919
while len(que) > 0:
    d, v, num = heapq.heappop(que)
    for cost, place in graph[v]:
        if place == 0:
            ans = min(ans, num + 1 if cost else num)
        if d + cost < dist[place]:
            dist[place] = d + cost
            heapq.heappush(que, (d + cost, place, (num + 1 if cost else num)))

print(ans)


Measured memory_bytes: 101640
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define F first
#define S second
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
 
 
void solve()
{
  string s;
  cin >> s;
  if(s[2]==s[3] && s[4]==s[5])
    cout <<"Yes\n";
  else
   cout << "No\n";
  return ;
}

signed main()
{
   FAST;
	int T=1;
	// cin >> T;
	while(T--)
	{
		solve();
	}
    return 0;
}

Measured memory_bytes: 256
fun main(arg: Array<String>) {
    val S = next()
    val N = S.length - 1
    var ans = 0L
    for (b in 0 until 1.shl(N)) {
        val P = BooleanArray(N + 1)
        for (n in 0 until N) {
            P[n] = (b.shr(n).and(1) == 1)
        }
        val Ex = StringBuilder()
        for (n in 0 until N + 1) {
            Ex.append(S[n])
            if (P[n]) Ex.append('+')
        }
        ans += fun (S: String): Long {
            var nums = 0L
            var num = 0L
            for (c in S) {
                if (c in '0'..'9') num = num * 10 + (c - '0')
                else {
                    nums += num
                    num = 0L
                }
            }
            if (num > 0) nums += num
            return nums
        }(Ex.toString())
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }




Measured memory_bytes: 31940
#include<iostream>
#include<cmath>
using namespace std;
int a;
int main()
{
    while(cin >> a)
    {
        for(int i=6;i>=0;i--)
        if(pow(2,i)<=a)
            {
                cout<<pow(2,i)<<endl;
                return 0;
            }
    }
}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

int main(){
    int N,c[200],ans=0;
    cin>>N;
    for(int i=1;i<=N;i=i+2){
        c[i]=0;
            for(int k=1;k<=i;k++){
               if(i%k==0)c[i]++;
            }
        if(c[i]==8)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }
int nmax=200000;
vvec g(nmax);



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n;
    cin>>n;
    vec a(n);
    vec b(n);
    int sum=0;
    int mem=0;
    rep(i,n){
        cin>>a[i]>>b[i];
        sum+=a[i];
        if(a[i]==b[i]) mem++;
    }
    if(mem==n) cout<<0<<endl;
    else{
        int m=INF;
        rep(i,n){
            if(a[i]>b[i]){
                chmin(m,b[i]);
            }
        }
        cout<<sum-m<<endl;
    }
    
}

Measured memory_bytes: 5248
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

div = make_divisors(int(input()))
x = len(div)
if x % 2 == 1:
    print(div[x//2] * 2 - 2)
else:
    print(div[x//2 - 1] + div[x//2] - 2)

Measured memory_bytes: 3268
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
const int maxn = 205;
vector< int > G[maxn];
int color[maxn], n;
int vis[maxn];
int num = 1;
bool DFS( int s, int preColor )
{
    color[s] = preColor ^ 1;
    vis[s] = 1;
    for( auto &i : G[s] )
    {
        if( !vis[i] )
        {
            if( !DFS( i, color[s] ) )
                return 0;
        }
        else if( color[s] == color[i] )
            return 0;
    }
    return 1;
}
void BFS( int s )
{
    queue< int > Q; Q.push(s);
    vis[s] = 1;
    while( !Q.empty() )
    {
        int ft = Q.front(); Q.pop();
        for( auto &i : G[ft] )
        {
            if( !vis[i] )
            {
                Q.push(i);
                vis[i] = vis[ft] + 1;
                num = max( num, vis[i] );
            }
        }
    }
}
int main()
{
    cin >> n;
    for( int i = 1; i <= n; ++ i )
        for( int j = 1; j <= n; ++ j )
        {
            char t; cin >> t;
            if( t == '1' ) G[i].push_back(j);
        }
    memset( color, -1, sizeof( color ) );
    for( int i = 1; i <= n; ++ i )
    {
        if( !vis[i] )
            if( !DFS( i, 0 ) )
            {
                cout << -1 << endl;
                return 0;
            }
    }
    for( int i = 1; i <= n; ++ i )
    {
//        memset( belong, 0, sizeof(belong) );
        memset( vis, 0, sizeof( vis ) );
        BFS( i );
    }
    cout << num << endl;

}

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

void chmin(ll& a, ll b) {
//      cout << "a= " << a << ",b= " << b << endl;
        if (b < a) a = b;
        return;
}

int main()
{
        ll INF = 1LL << 60;
        int N; cin >> N;
        vector<int> h(N, 0);
        for (int i = 0; i < N; ++i) {
                cin >> h[i];
        }
        vector<ll> dp(N, INF);
        dp[0] = 0;
        for (int i = 0; i < N; ++i) {
                chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
                if (i > 1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
        }
        cout << dp[N-1] << endl;
}


Measured memory_bytes: 1408
#include<stdio.h>
int max2(int a, int b){return a<b?b:a;}
int n, m, i;
int k;
char s[100001];
int D[100002], *d, e;
int now, max;
int main(void){
  scanf("%d%d%s", &n, &k, s);
  if(n==1){puts("1"); return 0;}  
  e=0; m=1;
  for(i=0; i<n-1; i++){
    if(s[i]==s[i+1]){
      e++;
    }else{
      D[m]=e+1;
      e=0; m++;
    }
  }
  D[m]=e+1;
  e=0; m++;
  
  if(s[0]=='0'){d=D; m++;}else{d=D+1;}
  
  k = (k<<1)+1;
  
  if(k>=m){
    for(i=0; i<m; i++){
      now+=d[i];
    }
    printf("%d\n", now);
  }else{
    for(i=0; i<k; i++){
      now+=d[i];
    }
    max = now;
    for(i=k; i<m; i+=2){
      now+=d[i];
      now+=d[i+1];
      now-=d[i-k];
      now-=d[i-k+1];
      max = max2(max, now);
    }
    printf("%d\n", max);
  }
}


Measured memory_bytes: 640
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
using namespace std;

int main(){
	const int M=1000000007;
	int N,W;
	scanf("%d%d",&N,&W);
	vector<int>w(N);
	vector<vector<int> >bag(N+1);
	bag[0].resize(W+1);bag[0][0]=1;
	for(int i=0;i<N;i++){
		scanf("%d",&w[i]);
		bag[i+1].resize(W+1);
	}
	sort(w.begin(),w.end(),greater<int>());
	for(int i=0;i<N;i++){
		for(int j=W;j>=0;j--)bag[i+1][j]=(bag[i][j]+(j>=w[i]?bag[i][j-w[i]]:0))%M;
	}
	int s=0,r=0;
	for(int i=N-1;i>=0;s+=w[i--])for(int j=max(0,W-s-w[i]+1);j<=W-s-(i!=N-1?w[i+1]:0);j++){
		r=(r+bag[i+1][j])%M;
	}
	printf("%d\n",r);
}

Measured memory_bytes: 8660
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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 dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int n, k, l;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> k >> l;
    UnionFind<int> road(n), rail(n);
    rep(i, 0, k) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        road.merge(a, b);
    }
    rep(i, 0, l) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        rail.merge(a, b);
    }
    map<Pii, int> p;
    rep(i, 0, n) {
        int x = road.root(i);
        int y = rail.root(i);
        p[mp(x, y)]++;
    }
    rep(i, 0, n) {
        int x = road.root(i);
        int y = rail.root(i);
        cout << p[mp(x, y)] << (i != n-1 ? " " : "\n");
    }
    return 0;
}


Measured memory_bytes: 16640
/*Fixed [removed string s]*/
#include <bits/stdc++.h>
#define  ll  long long
#define NOT_FOUND_ERROR -1
#define rep(k, n)  for(int i=k; i<n;  i++)
#define rep2(k,n)  for(int j=k; j<n;  j++)
using namespace std;
int DivUp(ll a, ll b) {return (a+(b-1)/b);} /*切り上げ*/

int main(){
    int a, b;
    cin >> a >> b;
    if(a==b){
        rep(0,a) cout << b;
        return 0;
    }
    rep(0,max(a,b)) cout << min(a,b);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i) = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {
  int n,m;cin>>n>>m;
  vector<int> a(n);rep(i,n)cin>>a[i];
  int sum = SUM(a);
  sort(all(a),greater<int>());
  
  int cnt = 0;
  rep(i,n){
    if(sum/(double)(4*m) > a[i])break;
    else cnt++;
  }
  if(cnt >= m)print("Yes");
  else print("No");
  return 0;
}


Measured memory_bytes: 256
N, C, K = map(int, input().split())
T = []
for i in range(N):
    t = int(input())
    T.append(t)
T.sort()

cnt = 0
tmp = 0
jousha = 0
for t in T:
    jousha += 1
    if jousha == 1:
        tmp = t

    if t - tmp > K:
        cnt += 1
        jousha = 1
        tmp = t
        continue

    if jousha == C:
        tmp = 0
        cnt += 1
        jousha = 0
        continue
if tmp != 0:
    cnt+=1
print(cnt)

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n, q;
    string s;
    cin >> n >> q >> s;
    vector<pair<char, char>> td(q);
    for (int i=0; i<q; ++i) {
        cin >> td.at(i).first >> td.at(i).second;
    }

    auto sim = [&](int cur) -> int {
        for (int i=0; i<q; ++i) {
            if (s.at(cur) == td.at(i).first) {
                if (td.at(i).second == 'L') --cur;
                else ++cur;
            }
            if (cur == -1 || cur == n) return cur;
        }
        return cur;
    };

    int res = n;
    int ok = n, ng = -1;
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if (sim(mid) == -1) ng = mid;
        else ok = mid;
    }
    res -= ng + 1;
    ok = -1, ng = n;
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if (sim(mid) == n) ng = mid;
        else ok = mid;
    }
    res -= n - ng;
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;
//const int MOD = 998244353;

// Lib
//
int N, M;
vector<vector<int> > G;


vector<bool> seen;
bool rec(int v, int p, int s, int t) {
    if (v == s && p != -1) return true; // 一周回ってきて s に戻って来たら OK
    if (v != s) seen[v] = true;
    for (auto nv :  G[v]) {
        if (nv == p || nv == t || seen[nv]) continue;
        if (rec(nv, v, s, t)) return true;
    }
    return false;
}

bool solve() {
    map<int,int> degs;
    for (int v = 0; v < N; ++v) degs[G[v].size()]++;
    // 次数チェック
    for (auto it : degs) if (it.first % 2 != 0) return false;
    if (degs[6] > 0) return true;
    if (degs[4] > 2) return true;
    if (degs[4] <= 1) return false;

    // 次数4 == 2 の場合
    vector<int> four;
    for (int v = 0; v < N; ++v) if (G[v].size() == 4) four.push_back(v);
    int s = four[0], t = four[1];
    seen.assign(N, 0);
    return rec(s, -1, s, t);
}

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    cin >> N >> M;
    G.assign(N, vector<int>());
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    if (solve()) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 7680
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#include <iomanip>
#include <tuple>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
using namespace std;
#define inf 10000000

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,k;
	cin >> n >> k;
	vector<int> x(n);
	ll sum = inf;
	ll msum = inf;
	rep(i,0,n) cin >> x[i];
	if(x[0]<0 && x[k-1]>=0) msum = abs(x[0]) + abs(x[k-1]) + min(abs(x[0]),abs(x[k-1]));
	else if(x[0]>=0) msum = abs(x[k-1]);
	else msum = abs(x[0]);
	sum = msum;
	
	rep(i,1,n-k+1){
		if(x[i]<0 && x[k+i-1]>=0) msum = abs(x[i]) + abs(x[k+i-1]) + min(abs(x[i]),abs(x[k+i-1]));
		else if(x[k+i-1]<0) msum = abs(x[i]);
		else msum = abs(x[k+i-1]);
		sum = min(sum,msum);
	}

	cout << sum << endl;
}


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

int N, K;
vector<int> d;
vector<vector<int>> A;

int main() {
    cin >> N >> K;
    A.resize(K);
    d.resize(K);
    int tmp;
    for (int i = 0; i < K; i++) {
        cin >> d.at(i);
        for (int j = 0; j < d.at(i); j++) {
            cin >> tmp;
            A.at(i).push_back(tmp);
        }
    }

    vector<int> have_okashi(N, 1);
    int okashi;
    for(int i = 0; i < K; i++) {
        for (int j = 0; j < A.at(i).size(); j++){
            okashi = A.at(i).at(j) - 1;
            have_okashi.at(okashi) = 0;
        }
    }

    cout << accumulate(have_okashi.begin(), have_okashi.end(), 0) << endl;
}

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

using namespace std;

int com_2(int a){
  return (a*(a-1))/2;
}

int main(){
  int n;
  int x;
  int y;
  vector<int> ans;
  cin >> n >> x >> y;
  for(int i=1;i<=n;i++){
    for(int j=i;j<=n;j++){
      if(i!=j){
        //cout << i << " " << j << endl;
        if(i<x && j<x){
          ans.push_back( abs(i-j) );
          continue;
        }
        if(i>y && j>y){
          ans.push_back( abs(i-j) );
          continue;
        }
        if(i<x && j>y){
          int kyori = abs(i-j);
          int sc = abs(x-y);
          ans.push_back(kyori-sc+1);
          continue;
        }
        int kouho_1 = abs(i-j);
        int tmp = abs(i-x);
        int tmp_2 = abs(j-y);
        int kouho_2= tmp+tmp_2+1;
        ans.push_back( min(kouho_1, kouho_2) );

      }
    }
  }

  sort(ans.begin(), ans.end());
  int num=1;
  int count=0;
  int size=0;
  //cout << ans.size() << endl;
  int k=0;
  while(num!=n){
    while(num==ans.at(k)){
      count++;
      if(k+1 != ans.size()){
        k++;
      }
      else{
        break;
      }
    }
    //cout << num << "--" << count << endl;
    cout << count << endl;
    num++;
    count=0;
  }
  return 0;
}


Measured memory_bytes: 10220
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
 
const int MOD = 1000000007;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    int n,W;
    cin>>n>>W;
    int w[n], v[n];
    pair<int,int> arr[n];
    int a,b;
    for(int i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
    int dp[n+1][W+1];

    for(int i=0;i<=n;i++)
    {
        for(int wt=0;wt<=W;wt++)
        {
            if(i==0||wt==0)
                dp[i][wt]=0;
            else if(w[i-1]<=wt)
                dp[i][wt]=max(v[i-1]+dp[i-1][wt-w[i-1]], dp[i-1][wt]);
            else
                dp[i][wt]=dp[i-1][wt];
        }
    }

    cout<<dp[n][W];



    return 0;
} 

Measured memory_bytes: 79232
#include <atcoder/all>
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    int n, m;
    cin >> n >> m;
    atcoder::dsu d(n);

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        d.merge(a - 1, b - 1);
    }

    cout << d.groups().size() - 1 << endl;

    return 0;
}

Measured memory_bytes: 8872
N,M=map(int,input().split())
k=[0]*M
s=[[] for _ in range(M)]

for i in range(M):
    a=list(map(int,input().split()))
    k[i]=a[0]
    s[i]=a[1:]
    s[i].sort()

p=list(map(int,input().split()))
    
ans=0
for i in range(pow(2,N)):
    light=0
    for j in range(M):
        temp=0
        for kk in range(k[j]):
            a=i>>(s[j][kk]-1)
            if a&1==1:
                temp+=1
        if temp%2!=p[j]:
            break
        light+=1
    if light==M:
        ans+=1
               
print(ans)





Measured memory_bytes: 41456
# N:駅の数
# Ci:i駅から i+1 駅への移動にかかる時間(cost)
# Si:i駅の最初の発車時間(start)
# Fi:i駅の発車スパン(frequency)
# Si % Fi = 0

N = int(input())
C = [0 for i in range(N)]
S = [0 for i in range(N)]
F = [0 for i in range(N)]
C[0], S[0], F[0] = 0, 0, 0


for i in range(N-1):
    C[i+1], S[i+1], F[i+1] = (int(i) for i in input().split())

for s in range(1, N+1):
    # print("start=", s)
    if s == N:
        t = 0
        pass
    else:
        t = 0
        for i in range(s, N):
            # print("i =", i)
            # print("S[", i, "] =", S[i])
            if t < S[i]:
                t = S[i]
            for j in range(F[i]):
                if (t + j) % F[i] == 0:
                    t = t + j
                    # print("notta zikan =", t)
                    t += C[i]
                    # print("tuita zikan =", t)
                    break
    print(t)


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int res = 0;
		res += X / 500 * 1000;
		X %= 500;
		res += X / 5 * 5;
		System.out.println(res);
	}
}


Measured memory_bytes: 35716
n = int(input())

x = []
y = []
h = []
for i in range(n):
    xi, yi, hi = map(int, input().split())
    x.append(xi)
    y.append(yi)
    h.append(hi)

isOk = False
i = 0
j = 0
constant = -1

for i in range(101):
    for j in range(101):

        constant = -1
        for k in range(n):
            if h[k] != 0:
                temp = h[k] + abs(i - x[k]) + abs(j - y[k])

                if constant == -1:
                    constant = temp

                if constant != temp:
                    break
        else:

            for p in range(n):
                if h[p] == 0 and constant - abs(i - x[p]) - abs(j - y[p]) > 0:
                    break
            else:
                isOk = True
                break
        
    if isOk:
        break

print(i, j, constant)
        

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct vl {
	int u, step;
};
const int MAXN = 1e5 + 69;
int n, m;
int s, t;
vector<int> a[MAXN];
int check[MAXN][3];
void bfs(vl u) {
	queue<vl> q;
	check[u.u][u.step] = 1;
	q.push(u);
	while (!q.empty()) {
		vl u = q.front(); q.pop();
		for (int v : a[u.u]) {
			int nstep = (u.step + 1) % 3;
			if (check[v][nstep]) continue;
			check[v][nstep] = check[u.u][u.step] + 1;
			q.push({v, nstep});
		}
	}
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 1, u, v; i <= m; i++) {
		cin >> u >> v;
		a[u].push_back(v);
	}
	cin >> s >> t;
	bfs({s, 0});
	if (!check[t][0]) cout << -1;
	else cout << (check[t][0] - 1) / 3;
}

Measured memory_bytes: 11424
#include <iostream>

using namespace std;
using ll = long long;

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

	int cnt = 0;
	for (int i = 0; i < S.size() / 2; ++i) {
		int end = S.size() - 1;

		if (S[i] != S[end - i]) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}


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

#define ll long long
#define ull unsigned long long
#define mod 1e9+7
#define INF 1 << 30
#define MAX (1 << 20)
#define NINF (-(1 << 30))
#define Point pair<int, int>
#define triplet pair<pair<int, int>, int>

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

    ll n, x, m;

    cin >> n >> x >> m;

    int arr[m];

    for (int i = 0; i < m; i++) arr[i] = -1;

    ll a0 = x, ans = 0;

    int i = 0;

    vector<ll> sum;

    for (i = 0; i < m; i++) {
        ans += a0;
        if(arr[a0] != -1)
            break;
        sum.push_back(ans);
        arr[a0] = i;
        a0 = (a0 * a0) % m;
    }

    //cout << "st: " << arr[a0] << ", et: " << i << endl;

    ans = (ans - sum[arr[a0]]);

    ans = ans * ((n - min(((ll)arr[a0] + 1), n)) / (i - arr[a0]));

    ans += sum[min((ll)arr[a0], n-1)];

    ans += (sum[arr[a0] + ((n - min(((ll)arr[a0] + 1), n)) % (i - arr[a0]))] - sum[arr[a0]]);

    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define pb push_back
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define F(i,x,n,y) for(i=x;i<n;i+=y)
#define fi(i,x,n) for(i=x;i<n;++i)
#define f(n) for(int i=0;i<n;++i)
#define fr(i,x,n) for(i=x;i>=n;--i)
#define endl '\n'

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,d,x;
    cin>>n;
    cin>>d>>x;
    int ans=n+x;
    f(n){
        int  tmp;
        cin>>tmp;
        ans+=(d-1)/tmp;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>


using namespace std;


int main(){
    uint64_t L,R;
    cin>>L>>R;
    uint64_t answer = 2018;
    uint64_t max_num = min(R, L+2018);

    for(uint64_t left=L; left<=max_num-1; left++){
        for(uint64_t right=left+1; right<=max_num; right++){
            answer = min(answer, ((left%2019)*(right%2019))%2019);
        }
    }

    cout<<answer<<endl;


    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#include <vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> checked(n,0);
  int pair = 0;
  int left = 0;
  rep(i, n-1){
    if(s[i] == '(' && !checked[i]){
      for(int m = i + 1; m < n; m++){
        if(s[m] == ')' && !checked[m]){
          checked[i] = 1;
          checked[m] = 1;
          pair++;
          break;
        }
      }
    }
    if(s[i] == '('){
      left++;
    }
  }
  if(s[n-1] == '(') left++;
  int right = n - left - pair;
  left -= pair;
    rep(i, right) cout << '(';
    cout << s;
    rep(i, left) cout << ')';
    cout << "\n";
  return 0;
}

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

using namespace std;

double res,l;

int main() {
	int n,k,i,t;
	cin>>n>>k;
	
	for(i=1;i<=n;i++){
		t = i;
		l = 1.0/n;
		while(t<k){
			t *= 2;
			l /= 2;;
		}
	  res += l;
	}
	
	cout<<fixed<<setprecision(12)<<res;
 	return 0;
}

Measured memory_bytes: 256
def main():
    K = int(input())

    if K % 2 == 0:
        print(-1)
        exit()
    
    c = 0

    for i in range(K):
        c = c * 10 + 7
        c %= K
        if c % K == 0:
            print(i+1)
            break
    else:
        print(-1)
    


if __name__ == '__main__':
    main()

Measured memory_bytes: 63068
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pr pair<ll, ll>
#define infinity (ll)4e18
#define pi 3.14159265358979323846264
#define tp tuple<ll, ll, ll>
using namespace std;
long long int mod = 1e9 + 7;

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

    ll a, b, h, m;
    cin >> a >> b >> h >> m;
    ld angle = abs(6 * m - 0.5 * (h * 60 + m));
    ld x = (pi * angle) / 180.0;
    ld ans = a * a + b * b - 2 * a * b * cos(x);
    ans = sqrt(ans);
    printf("%0.20Lf\n", ans);
    return 0;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for(int i = 0; i < s.size(); i++) {
    if(s.at(i) != t.at(i)) {
      ans++;
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};
constexpr int INF = 1e7;
int main() {
	int N;
	while (cin >> N) {
		vector<int> P(N);
		cin >> P;
		vector<int> len(N, -INF);
		int ret = 0;
		for (auto &p : P) {
			p--;
			if (p == 0 || len[p - 1] == -INF)len[p] = 1;
			else len[p] = len[p - 1] + 1;
			chmax(ret, len[p]);
		}
		cout << N - ret << endl;
	}
	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
    long long int N,K;
    long long int q0=0, q=0;
    cin >>N>>K;

    q0 = N/K;


    q = (N+K/2)/K;


    if(K%2 ==1){
        printf("%lld", q0*q0*q0);
    }else{
        printf("%lld", q0*q0*q0 + q*q*q  );
    }

    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n;
  cin >> n;
  vector<double> v(n);
  rep (i, n) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  rep (i, n - 1) {
    v[i + 1] = (v[i] + v[i + 1]) / 2;
  }
  printf("%.7f\n", v[n - 1]);

  return 0;
}

Measured memory_bytes: 256
// ConsoleApplication74.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include<algorithm>
#include<iomanip>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
using namespace std;
int main()
{
	int n, la;
	cin >> n >> la;
	if (n < 6)
	{
		la = 0;
	}
	else if (n >= 6 && n <= 12)
	{
		la = la / 2;
	}
	cout << la << "\n";
}


Measured memory_bytes: 256
d=input()
abhm=d.split()

import math
import numpy as np
A = int(abhm[0])
B = int(abhm[1])
H = int(abhm[2])
M = int(abhm[3])
c_2=A**2+B**2-2*A*B*math.cos(math.radians((M*0.5+H*30)-M*6))
C=np.sqrt(c_2)
print(C)

Measured memory_bytes: 27164