akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
long long int arr[16][16];
vector<long long int> bits_on[200000];
long long int total_score[200000];

long long int dp[200000];

long long int foo(long long int mask)
{
    if(dp[mask] != -1) return dp[mask];
    if(mask == 0) 
        {
            dp[mask] = 0;
            return 0;
        }
    long long int maxm = -1;

    long long int sz = bits_on[mask].size();

    for (long long int i = 1; i < (1 << sz); ++i)
    {
         long long int tmpmask = 0;
         for (long long int j = 0; j < bits_on[mask].size(); ++j)
         {
             if(i & (1<<j))
             {
                tmpmask |= (1 << bits_on[mask][j]);
             }
         }
         maxm = max(total_score[tmpmask] + foo(mask ^ tmpmask), maxm);
    }
    dp[mask] = maxm;
    return maxm;
}
int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
    for (int i = 0; i < 200000; ++i)
    {
        dp[i] = -1;
    }
    long long int n;
    cin >> n;
    for (long long int i = 0; i < n; ++i)
    {
        for (long long int j = 0; j < n; ++j)
        {
            cin >> arr[i][j];
        }
    }

    for (long long int i = 0; i < (1 << n); ++i)
    {
        for (long long int j = 0; j < 17; ++j)
        {
            if(i & (1 << j))
            {
                bits_on[i].push_back(j);
            }
        }
        long long int score = 0;
        for (long long int j = 0; j < bits_on[i].size(); ++j)
        {
             for (long long int k = j + 1; k < bits_on[i].size(); ++k)
             {
                 score += arr[bits_on[i][j]][bits_on[i][k]];
             }
        }
        total_score[i] = score;
    }



    cout << foo((1<<n)-1);
    return 0;
}

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

int main() {
    int n,k;
    cin >> n >> k;
    vector<bool> vec(n);
    for(int i = 0;i < n;i++){
        vec.at(i) = false;
    }

    for(int i = 0;i < k;i++){
        int d;
        cin >> d;
        for(int j = 0;j < d;j++){
            int a;
            cin >> a;
            vec.at(a - 1) = true;
        }
    }
    int cnt = 0;
    for(int i = 0;i < n;i++){
        if(vec.at(i) == false){
            cnt++;
        }
    }
    cout << cnt << endl;
}


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

#include<stdlib.h>
#include<iostream>
#include<math.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define INF 2000000000
#define Min(a,b) (a<b?a:b)
#define Max(a,b) (a>b?a:b)
#define PI 3.1415926535897932
using namespace std;

int main()
{
IOS;
long long  n,d;
cin>>n>>d;
long long  count=0;
for(long long  i=0;i<n;i++){
	long long  a,b;
	cin>>a>>b;
	if(a*a+b*b<=d*d){
		count++;
	}
}
cout<<count<<endl;
return 0;
}

Measured memory_bytes: 3688
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	long long x;
	long long tmp=100;
	cin >> x;
	long long cnt=0;
	while(tmp<x)
	{
		tmp*=1.01;
		cnt++;
	}
	cout << cnt << endl;
	




}


Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  int ans = 0;
  REP(i, N) FOR(j, i+1, N) FOR(k, j+1, N){
    if(A[i] == A[j] || A[j] == A[k] || A[k] == A[i]) continue;
    int sum = A[i]+A[j]+A[k];
    int MAX = max(A[i], max(A[j], A[k]));
    if(MAX < sum-MAX){
      ans++;
    }
  }

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, ans, cnt[1100000], lc = 1;

ll powmod(ll a, ll b) {
	a %= MOD;
	ll res = 1;
	while (b > 0) {
		if (b % 2 == 1)res = res * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}
	return res;
}


void solve(ll n) {
	for (ll i = 2; i <= sqrt(n); i++)
	{
		ll now = 0;
		while (n % i == 0) {
			now++;
			n /= i;
		}
		cnt[i] = max(cnt[i], now);
	}
	if (n > 1) {
		cnt[n] = max(cnt[n], 1ll);
	}
}
int main() {
	cin >> n;
	vector<ll> s(n);
	REP(i, n) {
		cin >> s[i];
	}
	REP(i, n) {
		solve(s[i]);
	}
	REPO(i, 1000000) {
		if (cnt[i] > 0) {
			lc *= powmod(i, cnt[i]);
			lc %= MOD;
		}
	}
	//cout << lc << endl;
	REP(i, n) {
		ans += lc * powmod(s[i], MOD - 2) % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int N, K, C;
string S;

int main() {
    cin >> N >> K >> C;
    cin >> S;

    vector<int> a(N, 0);
    int thr = 0;
    for_(i,0,N) {
        if (i < thr) continue;
        if (S[i] == 'o') {
            a[i] = 1;
            thr = i + C + 1;
        }
    }

    if (accumulate(ALL(a), int()) > K) {
        return 0;
    }

    reverse(ALL(S));
    vector<int> b(N, 0);
    thr = 0;
    int cnt = 0;
    for_(i,0,N) {
        if (i < thr) continue;
        if (S[i] == 'o') {
            b[i] = 1;
            thr = i + C + 1;
            ++cnt;
        }
        if (cnt == K) break;
    }
    reverse(ALL(b));

    // reverse(ALL(S));
    // for_(i,0,N) cerr << S[i] << " ";
    // cerr << endl;
    // for_(i,0,N) cerr << a[i] << " ";
    // cerr << endl;
    // for_(i,0,N) cerr << b[i] << " ";
    // cerr << endl;

    for_(i,0,N) if (a[i] == 1 and b[i] == 1) cout << i+1 << endl;
}

Measured memory_bytes: 3332
<?php
  	fscanf(STDIN, "%d %d %d %d", $a, $b, $c, $d);
	
	$takahashi['life'] = $a;
	$takahashi['attack'] = $b;
	$aoki['life'] = $c;
	$aoki['attack'] = $d;

	while (TRUE) {
      	$aoki['life'] -= $b;
      	if ($aoki['life'] <= 0) break;
      	$takahashi['life'] -= $d;
      	if ($takahashi['life'] <= 0) break;
    }

	if ($takahashi['life'] > 0) echo "Yes\n";
	if ($aoki['life'] > 0) echo "No\n";

Measured memory_bytes: 16140
using System;

namespace ConsoleApp1
{
    class Program
    {

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine().Split(' ');
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(s[i]);
            }
            int max = n & 0x7FFFFFFE;
            int firstrain = 0;
            for (int i = 0; i < max; i += 2)
            {
                firstrain += a[i];
                firstrain -= a[i + 1];
            }
            firstrain += a[n - 1];
            int temprain = firstrain >> 1;
            var rain = new int[n];
            rain[0] = firstrain;
            
            for (int i = 1; i < n; i++)
            {
                temprain = a[i - 1] - temprain;
                rain[i] = temprain * 2;
            }

            Console.WriteLine(string.Join(" ", rain));
        }
    }
}


Measured memory_bytes: 33860
n = int(input())
a = list(map(int, input().split()))
b = []
if n % 2 == 0:
    for i in range(n-1, -1, -2):
        b.append(a[i])
    for i in range(0, n, 2):
        b.append(a[i])
else:
    for i in range(n-1, -1, -2):
        b.append(a[i])
    for i in range(1, n, 2):
        b.append(a[i])
print(*b)

Measured memory_bytes: 26180
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[200005],c[200005],b[200005],left,right,same;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",&a[i]);
	for(int i=1;i<=n;++i) scanf("%d",&c[i]);
	for(int i=1;i<=n;++i) b[i]=c[n-i+1];
	for(int i=1;i<=n;++i) if(a[i]==b[i]) {
		if(!left) left=i;right=i;same=a[i];
	}
	if(left) {
		for(int i=n;i>=right;--i) {
			if(a[i]==same||b[i]==same) break;
			swap(b[i],b[left]);++left;if(left>right) break;
		}
		if(left<=right)
		for(int i=1;i<=left;++i) {
			if(a[i]==same||b[i]==same) break;
			swap(b[i],b[right]);--right;if(left>right) break;
		}
	}
	if(left>right||!left) {printf("Yes\n");for(int i=1;i<=n;++i) printf("%d ",b[i]);}
	else printf("No");
	return 0;
}

Measured memory_bytes: 4020
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
import sys
from bisect import *
import itertools
import copy
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7


def main():
    s = input()
    ans = 0
    pres = ""
    nows = ""
    for i in range(len(s)):
        nows += s[i]
        if nows != pres:
            ans += 1
            pres = nows
            nows = ""
    print(ans)
                




if __name__ == '__main__':
    main()


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N; cin >> N;
    int n = 2 * N - 1;
    vec a(n); readv(a);

    int x1 = 1, x2 = n + 1;
    vec b(n);
    while(x2 - x1 > 1){
        int x = (x1 + x2) / 2;
        REP(i, n){
            if(a[i] >= x) b[i] = 1;
            else b[i] = 0;
        }
        int l = INF, r = INF;
        REP(i, N - 1) if(b[N - 1 + i] == b[N - 1 + i + 1]){
            r = i;
            break;
        }
        REP(i, N - 1) if(b[N - 1 - i] == b[N - 1 - (i + 1)]){
            l = i;
            break;
        }
        int c;
        if(l == INF && r == INF) c = b[0];
        else if(l <= r) c = b[N - 1 - l];
        else c = b[N - 1 + r];
        if(c == 0) x2 = x;
        else x1 = x;
    }
    cout << x1 << endl;

    return 0;
}


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

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

   	int a,b,c,ans;

	while(cin >> a >> b){
   		c = a + b;
   		ans = (int)log10((double)c) + 1;
   		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 3452
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 998244353
#define NUM 200010

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int pid=0,pnum=0,rpid[NUM];LL cost[NUM],rcost[NUM],cpid[NUM],que[NUM];
int judge(int a,int b){if(pnum<b||b==1)return 0;return cpid[que[a]]>cpid[que[b]]?1:0;}
void push(LL a,int n){int i=++pid,j=++pnum;rpid[i]=n,cpid[i]=a,que[j]=i;while(judge(j/2,j))que[j]=que[j/2],que[j/=2]=i;}
int pop(){int ans=rpid[que[1]],i=1,j;LL n=que[pnum--];que[1]=n;while(judge(i,j=i*2+judge(i*2,i*2+1)))que[i]=que[j],que[i=j]=n;return ans;}
void Dijkstra(int v,int e,int* a,int* b,int* l,int ver){int i,flag[NUM]={0},pre[e+1],last[e+1];FOR(i,1,v+1)cost[i]=LNF,last[i]=-1;cost[ver]=0;FOR(i,0,e)pre[i]=last[a[i]],last[a[i]]=i;while(flag[ver]==0){flag[ver]++;for(i=last[ver];i+1;i=pre[i])if(cost[b[i]]>cost[ver]+l[i]){cost[b[i]]=cost[ver]+l[i];push(cost[b[i]],b[i]);}while(flag[ver]&&pnum)ver=pop();}}


int main(){
  int N,M,i,ans=0;
  scanf("%d%d",&N,&M);
  int L[N+M-1],R[N+M-1],C[N+M-1];
  FOR(i,0,N-1)L[i]=i+2,R[i]=i+1,C[i]=0;
  FOR(i,N-1,N+M-1)scanf("%d%d%d",&L[i],&R[i],&C[i]);
  Dijkstra(N,N+M-1,L,R,C,1);

  printf("%lld\n",cost[N]<LNF?cost[N]:-1);
	return 0;
}


Measured memory_bytes: 10752
#include<stdio.h>

int main(){
	long n,k,ans;
	scanf("%ld%ld",&n,&k);
	if(n==1 && k==1){
		ans=1;
	}else if(n==1){
		ans=k-2;
	}else if(k==1){
		ans=n-2;
	}else{
		ans=n*k-(2*n+2*k-4);
	}
	printf("%ld\n",ans);
	return 0;
	}


Measured memory_bytes: 128
n,k=map(int,input().split())
a=list(map(int,input().split()))

c=[0]*(n+1)
for i in range(n):
    c[a[i]]+=1
c.sort(reverse=True)
csum=0
for i in range(k):
    csum+=c[i]
print(n-csum)


Measured memory_bytes: 24852
#include<stdio.h>
//#define int long long;
int main(){
	long long int  h,w;
    long long int count=1;
	scanf("%d %d",&h,&w);
if(h>=2&&w>=2){
	if((h&1)==0){
			count=(h/2)*w;
				printf("%lld",count);
		}
		else if((h&1)!=0&&(w&1)==0){
			count=h*(w/2);
			printf("%lld",count);
		}
		else if((h&1)!=0&&(w&1)!=0){
			int m=w/2;
			count=(h/2)*(w/2)+((h/2)+1)*(w-m);
			printf("%lld ",count);
		}
	}
	else{
		printf("1");
	}
	
}

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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int N;
v1 pre, in, post;
int pos = 0;
void sep(int i, int e){//i, j, eはin用, pはpre
	if(i>e) return;
	if(i == e){
		post.push_back(in[i]);
		pos++;
		return;
	}
	int root = pre[pos];
	pos++;
	int j = 0;
	while(in[j] != root){
		j++;
	}
	sep(i, j-1);
	sep(j+1, e);
	post.push_back(root);
}

void solve(){
	sep(0, N-1);
	rep(i, N){
		cout << post[i];
		if(i != N-1) cout << " ";
		if(i == N-1) cout << endl;
	}
}

int main(){
	 cin >> N;
	 rep(i, N){
		 int x;
		 cin >> x;
		 pre.push_back(x);
	 }
	 rep(i, N){
		 int x;
		 cin >> x;
		 in.push_back(x);
	 }
	 solve();
}



Measured memory_bytes: 3160
n = int(input())
xyh = []
for i in range(n):
    l = list(map(int,input().split()))
    xyh.append(l)

for i in range(101):
    for j in range(101):
        H = -1
        tmp = []
        for l in xyh:
            if l[2]==0:
                tmp.append([l[0],l[1]])
                continue
            h = l[2] + abs(i-l[0]) + abs(j-l[1])
            if H!=-1:
                if H!=h:
                    break
            else:
                H = h
        else:
            if H>=1:
                flag = True
                for mmm in tmp:
                    hhh = H - abs(mmm[0]-i) - abs(mmm[1]-j)
                    if hhh>0:
                        flag = False
                        break
                if flag:
                    print(i,j,H)
                    exit()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007

ll dp[53][53][2520];

int main() {
	int N, A;
	cin >> N >> A;
	vector<int> X(N);
	for (int i = 0;i < N;i++) {
		cin >> X[i];
	}

	dp[0][0][0] = 1;
	for (int i = 0;i < N;i++) {//何個使いましたか
		for (int j = 0;j < N;j++) {//何個目まで見ましたか
			for (int k = 0;k < 2520;k++) {//現在の値は何ですか
				if (k + X[j] < 2520)
					dp[i + 1][j + 1][k + X[j]] += dp[i][j][k];
				dp[i][j + 1][k] += dp[i][j][k];
			}
		}
	}
	ll ans = 0;
	for (int i = 1;i <= N;i++) {
		ans += dp[i][N][i * A];
	}
	cout << ans << endl;
}

Measured memory_bytes: 53376
from heapq import heappop, heappush
mod = 10**9+7
n, k = map(int, input().split())
a = [int(x) for x in input().split()]


def sgn(x):
    if x >= 0:
        return 0
    elif x < 0:
        return 1


pl = []
mn = []

for x in a:
    if x >= 0:
        pl.append(x)
    elif x < 0:
        mn.append(-x)

pl = sorted(pl, reverse=True)
mn = sorted(mn, reverse=True)


b = [(abs(a[i]), sgn(a[i])) for i in range(n)]
b = sorted(b, reverse=True)

c = [0, 0]
for i in range(k):
    c[b[i][1]] += 1


def solve(c):
    ans = 1
    for i in range(c[0]):
        ans *= pl[i]
        ans %= mod
    for i in range(c[1]):
        ans *= mn[i]
        ans %= mod
    if c[1] % 2:
        ans = (-ans) % mod
    return ans


if c[1] % 2 == 0:
    print(solve(c))
    exit()

if len(mn) == n and k % 2:
    tmp = 1
    for i in range(k):
        tmp *= mn[-i-1]
        tmp %= mod
    ans = -tmp
    print(ans % mod)
    exit()

ans = 0

chk1 = False
chk2 = False

if c[0] <= len(pl) - 1:
    chk1 = True

if 0 < c[0] and c[1] <= len(mn)-1:
    chk2 = True

if chk1 and chk2:
    tmp1 = pl[c[0]]*pl[c[0]-1]
    tmp2 = mn[c[1]]*mn[c[1]-1]
    if tmp1 > tmp2:
        c[0] += 1
        c[1] -= 1
        print(solve(c))
    else:
        c[0] -= 1
        c[1] += 1
        print(solve(c))
elif chk1:
    c[0] += 1
    c[1] -= 1
    print(solve(c))
elif chk2:
    c[0] -= 1
    c[1] += 1
    print(solve(c))
else:
    print(solve(c))


Measured memory_bytes: 117056
#include <iostream>
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;

int main(){
  FOR(i,1,10){
    FOR(j,1,10){
      cout << i <<"x"<<j<<"="<<i*j<<endl;
    }
  }
  return 0;
}

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

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

    for (int i = 0; i <= n; i++) {
        if (floor(i * 1.08) == n) {
            std::cout << i << std::endl;
            return 0;
        }
    }

    std::cout << ":(" << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int k,i;
    int a,b,x=0;
    scanf("%d",&k);
    scanf("%d%d",&a,&b);

    for(i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            x=1;
        }
    }
    if(x==1)
    {
        printf("OK\n");
    }
    else
    {
        printf("NG\n");
    }
    return 0;
}


Measured memory_bytes: 1556
#include <iostream>
#include <algorithm>
#define MAX 100001
using namespace std;



int main() {
    int n;
    int m;
    int zahyo[MAX];
    int ans = 0;
    bool ff = true;
    cin >> n >> m;

    if(n > m){
        ff = false;
    }

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

    sort(zahyo,zahyo+m);

    int diff[MAX];
    for (int j = 0; j <m-1; ++j) {
        diff[j] = zahyo[j+1] - zahyo[j];
    }

    sort(diff,diff+m-1);

    for (int k = 0; k <m -n; ++k) {
        ans += diff[k];
    }

    if(ff) {
        cout << ans;
    } else{
        cout << 0;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(int argc, const char * argv[]) {
  int n;
  cin >> n;
  vector<int> w(n);
  for(int i = 0; i < n; i++){
    cin >> w.at(i);
  }
  int allsum = 0;
  for(int i = 0; i < n; i++){
    allsum += w.at(i);
  }
  int tmp=0;
  int res = 99999999;
  for(int i = 0; i < n; i++){
    tmp += w.at(i);
    res = min(res, abs(tmp - (allsum - tmp)));
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static final Scanner sc = new Scanner(System.in);
    static final int MOD = (int) 1E9 + 7;
    
    public static void main(String[] args) {
        int N = nint();
        int[] A = nints(N, 1, 0);
        int[] B = nints(N, 1, 0);
        int[] C = nints(N-1, 1, 0);
        int ans = 0;
        
        for (int i = 1; i <= N; i++) {
            ans += B[A[i]];
            if (i > 1 && A[i] == A[i-1] + 1) {
                ans += C[A[i-1]];
            }
        }
        System.out.println(ans);
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0);
    }

    private static char[][] nchars2(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int H,W;
  cin>>H>>W;
  char c[H][W];
  REP(i,H)REP(j,W)cin>>c[i][j];
  REP(i,H){
    REP(j,W){
      if(c[i][j]=='#'){
        cout<<'#';
        continue;
      }
      int temp=0;
      FOR(ii,-1,2)FOR(jj,-1,2){
        if(ii==0 and jj==0)continue;
        if(i+ii<0 or j+jj<0 or i+ii>=H or j+jj>=W)continue;
        if(c[i+ii][j+jj]=='#')temp++;
      }
      cout<<temp;
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
buttonNum = int(input())
button = [0] * buttonNum
for i in range(buttonNum):
  button[i] = int(input())
pushedButton = 1
count = 0
checkAble = False
for i in range(buttonNum):
  count += 1
  if button[pushedButton - 1] == 2:
    checkAble = True
    break
  else:
    pushedButton = button[pushedButton - 1]
if checkAble:
  ans = count
else:
  ans = -1
print(ans)

Measured memory_bytes: 7028
#include<stdio.h>
int main (void)
{
    int H,W,i,j;
    while(1)
    {
        scanf("%d %d",&H,&W);
        if (H==0 && W==0) break;

        for(i=1;i<=H;i++)
        {
            for(j=1;j<=W;j++)
            {
                if(j%2==1)
                {
                    if(i%2==1)printf("#");
                    else printf(".");
                }
                else
                {
                    if(i%2==1)printf(".");
                    else printf("#");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2100
#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;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll a;
  string b; 
  cin >> a >> b;
  ll bb = (b[0] - '0') * 100;
  bb += (b[2] - '0') * 10;
  bb += (b[3] - '0');
  cout << a*bb/100 << endl;
  return 0;
}


Measured memory_bytes: 3652
from collections import deque
def dfs(i,j,seen):
    q=deque()
    q.append((i,j,0))
    seen[i][j]=0
    dx=[0,1,0,-1,-1,-1,1,1]
    dy=[1,0,-1,0,1,-1,1,-1]
    while q:
        X,Y,S=q.pop()
        if S==0:
            #下に遷移していくときの処理
            #q.append((V,P,1))
            for k in range(8):
                nx=X+dx[k]
                ny=Y+dy[k]
                if not(0<=nx<h and 0<=ny<w):continue
                if seen[nx][ny]==0:continue
                seen[nx][ny]=0
                q.append((nx,ny,0))
    return 1

def main(w,h):
    grid=[list(map(int,input().split())) for i in range(h)]
    ans=0
    for i in range(h):
        for j in range(w):
            if grid[i][j]:
                ans+=dfs(i,j,grid)
    print(ans)

while True:
    w,h=map(int,input().split())
    if (w,h)==(0,0):break
    main(w,h)


Measured memory_bytes: 6012
package main
 
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// override by `ldflags`
var env = "online"

func checkLocal() bool {
	return env == "local"
}

func debugPrint(format string, args ...interface{}) {
	// debug out to stderr
	if checkLocal() {
		fmt.Fprintf(os.Stderr, format, args...)
	}
}

var (
	BufferSize = 100 + 10
)

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	} 
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	s := scanInt(sc)
	fmt.Printf("%d:%d:%d\n", s/3600, (s%3600)/60, s%60)
}


Measured memory_bytes: 1104
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MAX_N =500;
ll N,M,Q;
ll dp[MAX_N][MAX_N];
ll LR[MAX_N][MAX_N];

ll dfs(int l,int r){
    if(l>r){
        return 0;
    }
    if(dp[l][r] != -1){
        return dp[l][r];
    }
    dp[l][r] = dfs(l+1,r) + dfs(l,r-1) -(dfs(l+1,r-1)) + LR[l][r];
    return dp[l][r]; 
}

int main() {
    memset(dp, -1,sizeof(dp));
    memset(LR,0,sizeof(LR));
    cin >> N >>M >>Q;
    for(int i=0;i<M;i++){
        ll l,r;
        cin >> l >> r;
        --l;--r;
        LR[l][r]++;
    }
    dfs(0,N-1);
    for(int i=0;i<Q;i++){
        ll p,q;
        cin >> p >> q;
        --p;--q;
        cout << dp[p][q] << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    string s;
    ll k;
    cin>>s>>k;
    ll ans=0;
    ll n = s.length();
    vector<string> v;
    REP(i,1,6){
        rep(j,n-i+1){
            string x;
            ll cnt = 0;
            while (cnt < i){
                x += s[j+cnt];
                cnt ++;
            }
            if(find(ALL(v),x)==v.end()){
                v.pb(x);
            }
        }
    }
    sort(ALL(v));
    cout<<v[k-1]<<endl;
    return  0;
}


Measured memory_bytes: 1152
s = input()
n = len(s)

t1 = [0,1]
t2 = [1,0]
num1 = num2 = 0
for i in range(n):
    tmp = i%2
    num1 += abs(int(s[i]) - t1[tmp])
    num2 += abs(int(s[i]) - t2[tmp])

if num1 >= num2:
    print(num2)
else:
    print(num1)

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<map>

using namespace std;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(){
    queue<char> a;
    queue<char> b;
    queue<char> c;
    string s, t, u;
    cin >> s >> t >> u;
    REP(i, s.size()){
        a.push(s[i]);
    } 
    REP(i, t.size()){
        b.push(t[i]);
    }
    REP(i, u.size()){
        c.push(u[i]);
    }

    char turn = 'a';
    while(1){
        if(turn == 'a'){
            if(a.empty()){
                cout << "A" << endl;
                return 0;
            }
            turn = a.front();
            a.pop();
        }
        else if(turn == 'b'){
            if(b.empty()){
                cout << "B" << endl;
                return 0;
            }
            turn = b.front();
            b.pop();
        }
        else{
            if(c.empty()){
                cout << "C" << endl;
                return 0;
            }
            turn = c.front();
            c.pop();
        }
    }
}


Measured memory_bytes: 256
<?php

$s = trim(fgets(STDIN));
$t = trim(fgets(STDIN));

$s_len = strlen($s);
$t_len = strlen($t);

$repeat = $s_len - $t_len+1;
$flg = false;
for ($i=0; $i < $repeat ; $i++) { 
	$s_end = $s_len-$i-1;
	for ($j=0; $j < $t_len ; $j++) { 
		$cur_s = $s[$s_end-$j];
		$cur_t = $t[$t_len-$j-1];
		if ($cur_s !== $cur_t && ($cur_s !== '?')){
			break;
		}
		if ($j === $t_len-1) {
			$flg = true;
			for ($k=0; $k < $t_len ; $k++) { 
				$s[$s_end-$k] = $t[$t_len-$k-1];
			}
		}
	}
	if ($flg) {
		break;
	}
}

if ($flg) {
	for ($i=0; $i < $s_len; $i++) { 
		$tmp = $s[$i];
		if ($tmp === '?') {
			echo 'a';
		}else{
			echo $tmp;
		}
	}
}else{
	echo 'UNRESTORABLE';
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

const int MAX_N = 212345;
struct BITMAX {
  int n;
  ll vs[MAX_N + 1];
  BITMAX() {
    this->n = MAX_N;
    clear();
  }
  void clear() {
    REP(i, n+1) vs[i] = 0; // default value
  }
  void update(int idx, ll val) {
    for (int x = idx + 1; x > 0; x -= x & -x) vs[x] = max(vs[x], val); // [0, idx] の範囲の最大値を val で更新しようと試みる
    // for (int x = idx + 1; x <= n; x += x & -x) vs[x] = max(vs[x], val); // [idx, ∞] の範囲の最大値を val で更新しようと試みる
  }
  ll get(int idx) {
    ll val = 0; // default value
    for (int x = idx + 1; x <= n; x += x & -x)  val = max(val, vs[x]); // [0, idx] の範囲の最大値を取得
    // for (int x = idx + 1; x > 0; x -= x & -x) val = max(val, vs[x]); // [idx, ∞] の範囲の最大値を取得
    return val;
  }
};
BITMAX bit;

int nextInt() { int x; scanf("%d", &x); return x;}

int h[MAX_N];
ll a[MAX_N];
ll dp[MAX_N];

int main2() {
  CLR(dp, 0);
  int N = nextInt();
  REP(i, N) h[i] = nextInt();
  REP(i, N) a[i] = nextInt();
  bit.clear();

  for (int i = 0; i < N; i++) {
    // cout << dp[i] << endl;
    // cout << a[i] << " " << h[i] << " " << bit.get(h[i]) << endl;
    dp[i+1] = a[i] + bit.get(N-h[i]);
    bit.update(N-h[i], dp[i+1]);
  }
  // cout << dp[N] << endl;
  ll ans = 0;
  for (int i = 1; i <= N; i++) chmax(ans, dp[i]);
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 6016
# -*- coding: utf-8 -*-

################ DANGER ################
test = ""
#test = \
"""
5 2 4
ans 1
"""

"""
5 2 3
ans 2
"""

"""
5 3 4
ans 2
"""

"""
7 2 5
ans 3, not 4 
"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
########################################  
    
n, a, b = map(int, input2().split())

def roundup(n, d):
    if n % d:
        return n // d + 1
    else:
        return n // d


if (b - a) % 2 == 0:
    print((b - a) // 2)
    
else:
    if (b - 1) < (n - a):
        print((a - 1) + roundup((b - a), 2))
            
    else:
        print((n - b) + roundup((b - a), 2))
        

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>

int main() {
    int a, b, c, d;
    std::cin >> a >> b >> c >> d;

    if (abs(c - a) <= d || (abs(b - a) <= d && abs(c-b) <= d)) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    return 0;
}


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

typedef long long ll;
ll c, s;
string a;
int main()
{
	ll i;
	cin >> a;
	for (i = 0; i < a.size(); i++) {
		if (a[i] == 'W') s += c;
		else c++;
	}
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 640
/*
11111111
00000110
00001100
00011000
00110000
01100000
*/
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<queue>
#include<vector>
#define ll long long
#define F first
#define S second
#define debug(x); printf("debug%d\n",x);
#define rep(f,t) for(int i=f;i<=t;i++)
const int inf=0x3f3f3f3f;
using namespace std;
const int N = 2e5 + 10 ;
int a[N] ;
vector<int> v[N] ;
int n , vis[N] , dep[N] , b[N] ;
int d[4] = {0 , 1 , 2 , 3} ;
void dfs(int u , int fa , int d)
{
	dep[u] = d ;
	vis[u] = 1 ;
	for(auto x : v[u])
	 {
		 if(x == fa || vis[x]) continue ;
		 dfs(x , u , d + 1) ;
	 }
}
int main()
{
	scanf("%d" , &n) ;
	for(int i = 1 , x , y ; i < n ;i ++)
	 scanf("%d%d" , &x , &y) , v[x].push_back(y) , v[y].push_back(x) ;
  dep[1] = 1;
	dfs(1 , -1 , 1) ;
  int c = 0 ;
	for(int i = 1; i <= n ;i ++)
	 c += dep[i] % 2 ;
  b[3] = n / 3 , b[1] = n / 3 + (n % 3 >= 1) , b[2] = n / 3 + (n % 3 >= 2) ;
	if(c <= n / 3 || (n - c) <= n / 3)
	 {
		 int y = 1 ;
		 if(c > n / 3) y = 0 ;
		 for(int i = 1 ; i <= n ;i ++)
		  if(dep[i] % 2 == y) a[i] = 3 ;
			else
			{
				if(b[1]) a[i] = 1 , b[1] -- ;
				else if(b[2]) a[i] = 2 , b[2] -- ;
				else if(b[3]) a[i] = 3 , b[3] -- ;
			}
	 }
	 else
	 {
		 for(int i = 1 ;i <= n ;i ++)
		  {
				if(dep[i] % 2)
				 {
					 if(b[1]) a[i] = 1 , b[1] -- ;
					 else if(b[3] ) a[i] = 3 , b[3] -- ;
				 }
				else
				 {
					 if(b[2]) a[i] = 2 , b[2] -- ;
					 else if(b[3]) a[i] = 3 , b[3] -- ;
				 }
			}
	 }
	 b[1] = 0 , b[2] = 0 , b[3] = 0 ;

	 for(int i = 1; i <= n ;i ++)
			 a[i] = d[a[i]] + ((b[a[i]] ++ ) * 3 ) , cout << a[i] << " " ;
	puts("") ;
	return 0 ;
}


Measured memory_bytes: 19840
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
class lowlink {
   public:
    vector<int> ord, low;
    vector<bool> used;
    vector<int> G[100005];
    vector<pair<int, int>> bridge;
    int n;
    int k;
    lowlink() {}
    lowlink(int _n) {
        n = _n;
        ord.resize(_n);
        low.resize(_n);
        used.resize(_n);
        k = 0;
    }
    void add_edge(int a, int b) { G[a].push_back(b); }
    void dfs(int v, int p) {
        used[v] = true;
        ord[v] = k;
        low[v] = ord[v];
        k++;
        for (int i = 0; i < G[v].size(); i++) {
            if (used[G[v][i]] == false) {
                dfs(G[v][i], v);
                low[v] = min(low[v], low[G[v][i]]);
            } else if (G[v][i] != p) {
                low[v] = min(low[v], ord[G[v][i]]);
            }
        }
    }
    bool isBridge(int u, int v) { return ord[u] < low[v] or ord[v] < low[u]; }
};
int main() {
    int n;
    int m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    lowlink l(n);
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        l.add_edge(a[i], b[i]);
        l.add_edge(b[i], a[i]);
    }
    l.dfs(0, -1);
    vector<pii> ans;
    rep(i, m) {
        if (l.isBridge(a[i], b[i])) {
            ans.push_back(pii(min(a[i], b[i]), max(a[i], b[i])));
        }
    }
    cout << ans.size() << endl;
    sort(ans.begin(), ans.end());
    for (auto x : ans) {
        // cout << x.first + 1 << " " << x.second + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 2560
import sys
input = sys.stdin.readline
N=int(input())
#素数リスト
n = 55555
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

#print(len(primes))
ans=[]
for i in primes:
    if i%5==1:
        ans.append(i)
#print(len(ans))
print(*ans[:N])


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

int main() {
  int N;
  cin>>N;
  for (int i(N);i<=999;i++){
    string s= to_string(i);
    if (s[0]==s[1]&&s[2]==s[1]){
      cout << i<<endl;
      return 0;
    }
  }
  return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n,a;
  cin>>n>>a;
  n %= 500;
  cout << (n<=a ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
X, Y, A, B, C = [int(x) for x in input().strip().split()]
p = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:X]
q = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:Y]
r = np.array(sorted([int(x) for x in input().strip().split()], reverse=True))[:min(C, X+Y)]

pq = np.hstack((p, q, r))
pq.sort()
print(sum(pq[-(X+Y):]))

Measured memory_bytes: 24988
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(void)
{
	int i,j,H=0,W=0,h,w;
	int ans=(1<<25);
	cin>>H>>W;
	int A[H][W]={0};
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			cin>>A[i][j];
		}
	}
	for(i=0;i<H;i++){
		for(j=0;j<W;j++){
			int sum=0;
			for(h=0;h<H;h++){
				for(w=0;w<W;w++){
					sum+=min(abs(h-i),abs(w-j))*A[h][w];
				}
			}
			ans=min(ans,sum);
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3120
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;

int main()
{
    int a[3], k;
    int i;
    
    cin >> a[0] >> a[1] >> a[2];
    cin >> k;
    
    sort(a, a+3);
    
    for(i = 1; i <= k; i++) {
        a[2] *= 2;
    }
    
    cout << a[0] + a[1] + a[2] << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<utility>
#include<vector>

using namespace std;

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) for(int i=0; i<n; i++)

typedef long long int ll;

int main(){
  ll data[100001]={0};
  ll accum[100001]={0};
  int n,a,b;
  ll k;
  scanf("%d %lld",&n,&k);
  REP(i,n){
    scanf("%d %d",&a,&b);
    data[a]+=b;
  }
  REP(i,100000){
    accum[i+1]=accum[i]+data[i+1];
    if(accum[i+1]>=k){
      printf("%d",i+1);
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 896
h, w, _ = gets.chomp!.split(" ").map(&:to_i)
cake = []
pos_y = {}
h.times do |i|
    chs = gets.chomp!.chars
    cake << chs
    chs.each_with_index do |ch, j|
        if ch == "#"
            pos_y[i] ||= {}
            pos_y[i][j] = 1
        end
    end
end
 
ans = []
pass_rows = []
index = 1
h.times do |j|
    w.times do |i|
        ans[j] ||= []
        next if ans[j][i] && cake[j][i] == "."
        
        if pos_y[j].nil?
            pass_rows << j
            ans[j] = Array.new(w, -1)
            break
        end
        ans[j][i] = index
        # 今自分がいちご
        if cake[j][i] == "#"
            # みぎの次のいちごまで全部ぬりきる
            if cake[j]
                tmp = i + 1
                while cake[j][tmp] == "."
                    ans[j][tmp] = index
                    tmp += 1
                end
            end
            index += 1
        # 自分はいちごでないが→にいちごがある
        elsif cake[j]
            # 次のいちごまで全部塗り切る
            tmp = i + 1
            while cake[j][tmp] != "#" && cake[j][tmp] != nil
                ans[j][tmp] = index
                tmp += 1
            end
            ans[j][tmp] = index
        end
    end
end

pass_rows.chunk_while {|i, j| i+1 == j }.to_a.each do |x|
    merge_index = x[0] == 0 ? x[-1] + 1 : x[0] - 1

    x.each do |y|
        ans[y] = ans[merge_index]
    end
end
 
ans.each do |x|
    puts x.join(" ")
end


Measured memory_bytes: 17020
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    lli n, k;
    cin >> n >> k;
    lli ans = 0;
    for (int i = 1; i <= n; i++) {
        lli b = (k - i % k) % k;
        lli c = (k - i % k) % k;
        if ((b + c) % k == 0) {
            if (b != 0 and c != 0)
                ans += ((n - b) / k + 1) * ((n - c) / k + 1);
            else if (b == 0 and c == 0) {
                ans += ((n - b) / k) * ((n - c) / k);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import math
A,B,H,M = map(int,input().split())

edge = max(30*H+0.5*M,6*M) - min(30*H+0.5*M,6*M)
C = math.cos(math.radians(edge))
ans = math.sqrt(pow(A,2) + pow(B,2) - 2 * A * B * C)
print(ans)

Measured memory_bytes: 9388
import java.awt.Point;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        Point[] ps = new Point[n + 1];
        for (int i = 1; i <= n; i++) {
            ps[i] = new Point(sc.nextInt(), sc.nextInt());
        }
        PriorityQueue<Fenth> q = new PriorityQueue<Fenth>();
        double ans = 0;

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            double dis = Math.hypot(ps[a].x - ps[b].x, ps[a].y - ps[b].y);
            q.add(new Fenth(a, b, dis));
            ans += dis;
        }
        UnionFind uf = new UnionFind(n + 1);
        while (!q.isEmpty()) {
            Fenth f = q.poll();
            int a = f.from;
            int b = f.to;
            if (uf.same(a, b))
                continue;
            uf.unite(a, b);
            ans -= f.length;
        }
        System.out.printf("%.4f\n", ans);
    }
}

class Fenth implements Comparable<Fenth> {
    int from;
    int to;
    double length;

    Fenth(int from, int to, double length) {
        this.from = from;
        this.to = to;
        this.length = length;
    }

    public int compareTo(Fenth f) {
        if (f.length > length)
            return 1;
        else if (f.length < length)
            return -1;
        else {
            return 0;
        }
    }

    public String toString() {
        return "from,to,length" + from + " " + to + " " + length;
    }
}

class UnionFind {
    int par[];
    int rank[];

    UnionFind(int n) {
        par = new int[n];
        rank = new int[n];
        for (int i = 0; i < n; i++) {
            par[i] = i;
        }
    }

    public int find(int x) {
        if (x == par[x])
            return x;
        else
            return par[x] = find(par[x]);
    }

    public void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (rank[x] > rank[y])
            par[y] = x;
        else {
            par[x] = y;
            if (rank[x] == rank[y])
                rank[y]++;
        }
    }

    public boolean same(int x, int y) {
        return find(x) == find(y);
    }
}

Measured memory_bytes: 14000
#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b){
	return a < b;
}
vector<int> ans;
int main(){
	int h;
	for(int i = 1; i <= 10; i++){
		cin >> h;
		ans.push_back(h);
	}
	sort(ans.begin(), ans.end(), cmp);
	for(int j = 9; j >= 7; j--)
		cout << ans[j] << endl;
	return 0;
}

Measured memory_bytes: 3132