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

int map[22][22];
char S[22][22];

void dfs_(int x,int y){
    map[x][y]=min({map[x-1][y-1],map[x+1][y-1],map[x-1][y+1],map[x+1][y+1]})+1;
    //if(S[y+1][x-1]=='.'&&map[y+1][x-1]>map[x][y]) dfs(x,y);
    //if(S[y+1][x+1]=='.'&&map[y+1][x+1]>map[x][y]) dfs(x,y);
    //if(S[y-1][x-1]=='.'&&map[y-1][x-1]>map[x][y]) dfs(x,y);
    //if(S[y-1][x+1]=='.'&&map[y-1][x-1]>map[x][y]) dfs(x,y);
}

void dfs(int x, int y) {
    if(S[y][x-1]=='.'&&map[y][x-1]>map[y][x] + 1) {
        map[y][x - 1] = map[y][x]+1;
        dfs(x-1,y);
    }
    if(S[y][x+1]=='.'&&map[y][x+1]>map[y][x] + 1) {
        map[y][x+1] = map[y][x]+1;
        dfs(x+1,y);
    }
    if(S[y+1][x]=='.'&&map[y+1][x]>map[y][x] + 1) {
        map[y+1][x] = map[y][x]+1;
        dfs(x,y+1);
    }
    if(S[y-1][x]=='.'&&map[y-1][x]>map[y][x] + 1) {
        map[y-1][x] = map[y][x]+1;
        dfs(x,y-1);
    }

}

int main (){
    int H,W,maxB=0;
    cin >> H >> W;
    for(int i = 0 ; i<H+2 ; i++){
        for(int j = 0; j<W+2 ; j++){
            S[i][j]='#';
        }
    }
    
    for(int i = 1 ; i<H+1 ; i++){
        for(int j = 1; j<W+1 ; j++){
            cin >> S[i][j];
        }
    }

    for(int i = 1 ; i<H+1 ; i++){
        for(int j = 1 ; j<W+1 ; j++){
            if(S[i][j] == '.'){
        
                int y=i,x=j;
                for(int k = 0 ; k<H+2 ; k++){
                    for(int l = 0 ; l<W+2 ; l++)map[k][l]=100000;
                }
                map[y][x] = 0;
                dfs(x,y);
                int maxA = 0;
                for(int k = 1 ; k<H+2 ; k++){
                    for(int l = 1 ; l<W+2 ; l++){
                        if(map[k][l]>maxA && map[k][l]<10000){
                             maxA = map[k][l];
                        }
                       
                    }
                }
                maxB=max(maxB,maxA);
            }
        }
    }

  

    cout << maxB << endl;
    
    return 0;
}

Measured memory_bytes: 256
#template
def inputlist(): return [int(j) for j in input().split()]
from collections import Counter
#template
#issueから始める
N = int(input())
x = [0]*N
y = [0]*N
ans = 0
for i in range(N):
    x[i],y[i] = inputlist()
for i in range(N-1):
    for j in range(i+1,N):
        dx = (x[i]-x[j])**2
        dy = (y[i]-y[j])**2
        dl = (dx+dy)**(1/2)
        ans += 2*dl
print(ans/N)

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

using namespace std;

#define ll					long long
#define vi					vector<int>
#define vii					vector<vi>
#define ALL(s)			(s).begin(),(s).end()
#define pii					pair<int, int>
#define pll					pair<ll, ll>
#define si					set<int>
#define mp					make_pair
#define F						first
#define S						second
#define pb					push_back
#define tc(t)				int t; cin >> t; int t2 = 1; while(t--)
#define _						ios_base::sync_with_stdio(false); cin.tie(NULL); 
const ll MOD =  998244353;
const ll INF = 1<<29;
const ll MAX_N = 1e6 + 7;



ll ncr(int n, int r) 
{ 
    long long p = 1, k = 1; 
  
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
            long long m = __gcd(p, k); 
            p /= m; 
            k /= m; 
  
            n--; 
            r--; 
        } 
    } 
  
    else
        p = 1; 
  
    return p; 
}
int main() {_
	int n;
	cin >> n;
	double side = (float)n/3;
	double ans = side*side;
	ans *= side;

	cout << setprecision(12) << fixed << ans << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


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

int main() {
  ll n,p,ans,c,d;
  ans=1;
  cin >> n >> p;
    map<ll, ll> res = prime_factors(p);
    for(map<ll, ll>::iterator it = res.begin(), end = res.end(); it != end; ++it) {
      c=it->second;
      d=it->first;
      
        rep(i,c/n)ans=ans*d;
    }
    printf("%lld",ans);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

    int x,a,b;
    cin>>x>>a>>b;

    if(-a+b<=0){
        cout<<"delicious"<<endl;
    }else if(-a+b>0&&-a+b<=x){
        cout<<"safe"<<endl;
    }else{
        cout<<"dangerous"<<endl;
    }
    
}

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

int main(){
    int n, m;
    cin >> n >> m;
    int num[n];
    rep(i, n) num[i]=-1;
    rep(i, m){
        int s, c;
        cin >> s >> c;
        if(num[s-1]!=-1 && num[s-1]!=c){
            cout<<-1<<endl;
            return 0;
        }
        num[s-1]=c;
    }

    if(n==1){
        if(num[0]==-1) cout<<0<<endl;
        else cout<<num[0]<<endl;
        return 0;
    }

    if(num[0]==0){
        cout<<-1<<endl;
        return 0;
    }

    rep(i, n){
        if(i==0){
            if(num[i]==-1) cout<<1;
            else cout<<num[i];
        }else{
            if(num[i]==-1) cout<<0;
            else cout<<num[i];
        }
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#pragma GCC optimize("O2")
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define leastsigbit(x)     __builtin_ffs(x)
const int mod    =        1e9+7;
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<ll,ll>
#define vpii vector<pii>
#define tt ll tt;cin >> tt;while(tt--)
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n";}
const double PI = acos(-1);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm( ll x, ll y) { return (x*y)/gcd(x,y);}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
bool isPowerOfTwo(int x)
{
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));
}
#define int long long
const int MAXN = 2e5+ 10;
const ll inf = 1e18;

int intlog(double base, double x) {
    return (int)(log(x) / log(base));
}
int32_t main() {
    fio

    int n;
    cin >> n;
    vi suff(n);
    vi a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];

    }
    int ans = 0;
    for (int k = n-1; k >= 0; --k) {
        if(k < n-1)
        suff[k] = (suff[k+1] + a[k])%mod;
        else suff[k] = a[k];
    }
    for (int j = 0; j < n - 1; ++j) {
        int sum = (a[j] * suff[j+1])%mod;
        ans+=sum;
        ans%=mod;
    }
    cout << ans << endl;
    cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;


}






Measured memory_bytes: 6400
#include <stdlib.h>
#include <stdio.h>


int gcd(int a, int b) {
    // a > b
    if (a%b == 0) {
        return b;
    } else {
        return gcd(b, a%b);
    }
}


int main(void) {
    long long A, B, C, D, gcd_cd, lcm_cd, result;
    

    scanf("%lld %lld %lld %lld", &A, &B, &C, &D);
    
    if (C >= D)
        gcd_cd = gcd(C, D);
    else
        gcd_cd = gcd(D, C);
    
    lcm_cd = C / gcd_cd * D;
    //printf("%lld %lld\n", gcd_cd, lcm_cd);

    A = A-1;
    result = (B/C + B/D - B/lcm_cd) - (A/C + A/D - A/lcm_cd);
    printf("%lld\n", (B - A) - result);

    return 0;
}

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

using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i(0); i < N; i++) {
		int tmp;
		cin >> tmp;
		a[i] = tmp;
	}
	int ans(0);
	for (int i(0); i < N; i++) {
		int tmp;
		tmp = a[i];
		int itr(1);
		int renzoku(1);
		while (i + itr < N && a[i + itr] == tmp) {
			renzoku++;
			itr++;
		}
		ans += renzoku / 2;
		i = i + renzoku - 1;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  int ans = 10000000;
  rep(i, 100) {
    int m = i * 1000 - n;
    if (m >= 0) ans = min(ans, m);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
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; }
using namespace std;


int main(){
  ll N,ans=0;
  cin>>N;
  
  if(N%2==1){
    cout<<0<<endl;
    return 0;
  }
  
  ans+=N/10;
  N/=10;
  
  while(N>0){
    ans+=N/5;
    N/=5;
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3644
N = int(input())
H = [int(_) for _ in input().split()]


def yes():
    print('Yes')
    exit()


def no():
    print('No')
    exit()


minus = [0] * N
while True:
    f = 0
    for i in range(N - 1):
        if H[i] > H[i + 1]:
            f = 1
            if minus[i]:
                no()
            H[i] -= 1
            minus[i] += 1
    if not f:
        yes()


Measured memory_bytes: 14396
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      br.readLine();
      final var a = Arrays.stream(br.readLine().split(" "))
          .mapToInt(Integer::parseInt)
          .toArray();
      final var q = Integer.parseInt(br.readLine());
      final var bc = new int[q][2];
      for (int i = 0; i < q; i++) {
        final var line = br.readLine().split(" ");
        bc[i][0] = Integer.parseInt(line[0]);
        bc[i][1] = Integer.parseInt(line[1]);
      }

      Map<Integer, Long> counts = new HashMap<>();
      for (int i = 0; i < a.length; i++) {
        counts.put(
            a[i],
            counts.containsKey(a[i]) ? counts.get(a[i]) + 1 : 1
        );
      }

      long sum = counts
          .entrySet()
          .stream()
          .mapToLong(entry -> entry.getKey() * entry.getValue())
          .sum();

      for (int i = 0; i < q; i++) {
        final long replaceCount = counts.containsKey(bc[i][0]) ?
                                  counts.get(bc[i][0]) :
                                  0L;

        if (replaceCount > 0) {
          counts.put(
              bc[i][1],
              counts.containsKey(bc[i][1]) ? counts.get(bc[i][1]) + replaceCount : replaceCount
          );
          counts.put(
              bc[i][0],
              0L
          );
        }

        sum += replaceCount * (bc[i][1] - bc[i][0]);

        System.out.println(sum);
      }
    }
  }
}


Measured memory_bytes: 66644
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>
#include <iomanip>

using namespace std;



void change(string s) 
{ 

	
	int n = s.length(); 

	
	int cc = 0; 

	for(int i=0;i<n/2;i++) 
	{ 

		
		if(s[i]== s[n-i-1]) 
			continue; 

		
		cc+= 1; 

		
		if(s[i]<s[n-i-1]) 
			s[n-i-1]= s[i] ; 
		else
			s[i]= s[n-i-1] ; 
	} 
	printf("%d\n", (cc)) ; 
	 
} 

int main() 
{ 
string s;
cin >> s; 
change((s)); 
return 0; 
} 





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
typedef long long ll;
using namespace std;
ll func(ll h)
{
	if (h == 1) {
    	return 1;
    } else {    	
       	return 2 * func(h/2) + 1;        
    }
}
int main()
{
	ll H; cin >> H;
  	cout << func(H) << endl;
}


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

  int main() {

    int N;
    cin >> N;
    int M = N - ( N / 10 * 10 );

    if (M == 2 || M == 4 || M == 5 || M == 7 || M == 9)
    {
      cout << "hon" << endl;
    }
    else if (M == 0 || M == 1 || M == 6 || M == 8)
    {
      cout << "pon" << endl;
    }
    else 
    {
      cout << "bon" << endl;
    }

  }


Measured memory_bytes: 3648
N = int(input())

A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))

total_table = {}

def make_table(l):
	table = {}
	for v in l:
		if v in table:
			table[v] += 1
		else:
			table[v] = 1
		if v in total_table:
			total_table[v] += 1
		else:
			total_table[v] = 1
	return table

A_table = make_table(A_list)
B_table = make_table(B_list)

total_list = []
for v, c in total_table.items():
	total_list.append((c, v))

total_list.sort()
total_list.reverse()

A_head = []
A_tail = []
B_head = []
B_tail = []
for c, v in total_list:
	a = A_table[v] if v in A_table else 0
	b = B_table[v] if v in B_table else 0
#	print(c, a, b)
	while a > 0 and len(A_head) + len(B_head) < N:
		A_head.append(v)
		a -= 1
	
	while b > 0 and len(A_head) + len(B_head) < N:
		B_head.append(v)
		b -= 1
	
	while a > 0:
		A_tail.append(v)
		a -= 1
	
	while b > 0:
		B_tail.append(v)
		b -= 1

#print(A_head)
#print(A_tail)
#print(B_head)
#print(B_tail)

A_tail.reverse()
B_head.reverse()

A_list = A_head + A_tail
B_list = B_tail + B_head

#print(A_list)
#print(B_list)

def check():
	for a, b in zip(A_list, B_list):
		if a == b:
			return False
	else:
		return True

if check():
	AB_list = list(zip(A_list, B_list))
	AB_list.sort()
	print("Yes")
	print(*(b for a, b in AB_list))
else:
	print("No")


Measured memory_bytes: 91244
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define int int64_t
#define double long double
#define rep(i, N) for(int i=0; i<N; i++)
#define repr(i, N) for(int i=N-1; i>=0; --i)
#define all(v) v.begin(),v.end() 
using namespace std;
//using pr = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;

//プロトタイプ宣言
bool has_divisor(int, int);

//グローバル変数
//const int MAX_N;
//const int MAX_M;
//vvec data(N, vec(M));
//const int INF = ;
//const int mod = ;

//関数：
/* yにxをn回乗じmodで割った余りを返す。
（素数pに対して x**p = x (mod p) が成り立つ。）*/
int mod_pow(int y, int x, int n, int mod) {
	int ans = y;
	rep(i, n) {
		ans *= x;
		ans %= mod;
	}
	return ans;
}

/* ユークリッドの互除法(mx > mn) */
int gcd(int mx, int mn) {
	if(mn == 0) return(mx);
	else gcd(mn, mx%mn);
}

/* 素数判定関数 */
bool is_prime(int n) {
	if (n == 1) return false;
	else if (n == 2) return true;
	else {
		return !has_divisor(n, 2);
	}
}

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

	int k, s; cin >> k >> s;
	
	int n = min(k, s);
	int ct = 0;
	rep(x, n+1)rep(y, n+1) {
		int z = s - x - y;
		if(z >=0 && z <= k) ct++;
	}
	
	cout << ct << endl;
	return 0;
}

// 以下の関数等は気にしない。
bool has_divisor(int n, int i) {
	//base case 1:
	if (i == n) return false;
	//base case 2:
	if (n % i == 0) return true;
	return has_divisor(n, i+1);
}

//std::string str;
//str = std::to_string(int i);
//bitset<3> s(N);
//int ans = (char)grid - '0';
//int id = lower_bound(all(arr), x) - arr.begin();

/*struct data {
	char *name;
	int age;
	int height;
	double weight;
};*/

/*string ans = w;
string &ref = ans;
rep(i, N) {
	ref[i] = arr[i];
}*/


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

long long N, K;

long long resid_cnt[200000] = {};
int main(){
  cin >> N >> K;

  for(int i = 1; i <=  N; i++){
    if((2*i) % K == 0){
      resid_cnt[i%K]++;
    }
  }
  long long ans = 0;
  for(int k = 0; k < K; k++){
    if(k % K == (K-k) % K){
      ans += resid_cnt[k] * resid_cnt[k] * resid_cnt[k];
    }
  }
  cout << ans << endl;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a1,a2,a3;
	cin>>a1>>a2>>a3;
	if(a1+a2+a3>=22){
		cout << "bust";
	}
	else{
		cout << "win";
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> a(M), b(M), order(N);

    for (int i = 0; i < M; i++)
    {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < N; i++)
    {
        order[i] = i+1;
    }
    
    
    bool ok;
    int cnt = 0;
    do
    {
        for (int i = 0; i < N-1; i++)
        {
            for (int j = 0; j < M; j++)
            {
                ok = false;
                if(order[i] == a[j] && order[i+1] == b[j]){
                    ok = true;
                    break;
                }
                else if(order[i] == b[j] && order[i+1] == a[j]){
                    ok = true;
                    break;
                }
            }
            if(!ok) break;
        }
        if(ok) cnt++;
    } while (next_permutation(order.begin()+1, order.end()));

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, a;
  cin >> N;
  for(int i=0; i<N; i++){
    if(i<9){
      a++;}
    else if(98<i && i<999){
      a++;}
    else if(9998<i && i<99999){
      a++;}
  }
  cout << a << endl;
}

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

int parent[100000];
int r[100000];

void init(int n)
{
    for (int i = 0; i < n; i++) {
        parent[i] = i;
        r[i] = 0;
    }
}

int root(int a)
{
    if (parent[a] == a) {
        return a;
    }
    return parent[a] = root(parent[a]);
}

bool is_same_set(int a, int b)
{
    return root(a) == root(b);
}

void unite(int a, int b)
{
    a = root(a);
    b = root(b);

    if (a == b) {
        return;
    }

    if (r[a] < r[b]) {
        parent[a] = b;
    } else {
        parent[b] = a;
        if (r[a] == r[b]) {
            r[a]++;
        }
    }
}

int main(int argc, char const* argv[])
{
    int m, n;
    cin >> n >> m;
    int p[n], x[m], y[m];
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> x[i] >> y[i];
    }

    init(n);
    for (int i = 0; i < m; i++) {
        unite(p[x[i] - 1] - 1, p[y[i] - 1] - 1);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (is_same_set(i, p[i] - 1)) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		do
		{
			int a = scanner.nextInt(); //a1
			int b = scanner.nextInt(); //b1
			int c = scanner.nextInt(); //c1
			int d = scanner.nextInt(); //a2
			int e = scanner.nextInt(); //b2
			int f = scanner.nextInt(); //c2
			double x = (double)(c*e - f*b) / (a*e - d*b) - -0D;
			double y = (double)(a*f - d*c) / (a*e - d*b) - -0D;
			System.out.println(String.format("%.3f %.3f", x, y));
		}
		while(scanner.hasNext());
	}
}

Measured memory_bytes: 18200
#include<stdio.h>
int main()
{
	int n,i,temp,r = 0;
	scanf("%d",&n);
	int b[n];
	r = n/2;
	for(i = 0;i<n;i++)
	{
		scanf("%d",&temp);
		if(n%2==0)
		{
			if(i%2==0)
			b[r = (i+r)] = temp;
			else
			b[r = (r-i)] = temp;
		}
		else
		{
			 if(i%2==0)
			 b[r = (r-i)] = temp;
			 else
			 b[r = (r+i)] = temp;
		}
	}
		for(i = 0;i<n;i++)
			printf("%d ",b[i]);
	return 0;
}

Measured memory_bytes: 2816
N, K = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)

count = Array.new(200000)
as.each do |i|
    count[i] ||= 0
    count[i] += 1
end

count = count.compact.sort
if count.length <= K
    print 0
else
    print count[0...(count.length - K)].inject(:+)
end

Measured memory_bytes: 21488
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

double solve(int r)
{
  return 2 * r * 3.14159265358979323846;
}

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


  std::cout << std::setprecision(20);
  std::cout << solve(r) << std::endl;
}


Measured memory_bytes: 3784
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
int INF = 1<<29;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
long long int i,j,k;
int x[10][10];
int h,w;


int main(){
	cin>>h>>w;
	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
			cin>>x[i][j];
		}
	}
	for(k=0;k<10;k++){
		for(i=0;i<10;i++){
			for(j=0;j<10;j++){
				if(x[i][k]+x[k][j]<x[i][j])x[i][j]=x[i][k]+x[k][j];
			}
		}
	}
	//ここで最短距離を計算旋回
	int a,ans=0;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cin>>a;
			if(a==-1)continue;
			else ans += x[a][1];
		}
	}
	cout<<ans<<endl;
	return 0;
 
}

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

typedef long long ll;

ll N, X;
ll R = 1;

int main() {
  cin >> N >> X;
  ll now = 0;
  for (ll i = 0; i < N; ++i) {
    ll l;
    cin >> l;
    now += l;
    if (now <= X) ++R;
  }
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-9
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	ll H[100001];
	scan(N);
	rep(i,N){
		scan(H[i]);
	}
	int ans=0,now=0;
	brep1(i,N-1){
		if(H[i-1]>=H[i]){
			now++;
			ans=max(ans,now);
		}
		else{
			now=0;
		}
	}
	prin(ans);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,map<S,T> a){
  os<<"{";
  for (auto i : a)
  {
    os<<i<<",";
  }
  os<<"}"<<endl;
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, std::vector<std::string> S){
  map<string,ll> m;
  REP(N){
    if(m.count(S[i])){
      ++m[S[i]];
    }else{
      m[S[i]]=1;
    }
  }
  dump(m);
  set<string> ans;
  ll num=0;
  for (auto &&i : m)
  {
    if(i.second>num){
      ans.clear();
      num=i.second;
    }
    if(num==i.second){
      ans.insert(i.first);
    }
  }
  for (auto &&i : ans)
  {
    cout<<i<<endl;
  }
}

int main(){
  cout<<setprecision(1000);
  cin.tie(0);
  ios::sync_with_stdio(false);
    long long N;
    cin>>N;
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 34816
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long 
    #define ld long double
    #define MOD 998244353
    #define mod9 1000000009
    #define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    #define mp make_pair
    #define pb push_back
    #define ct ll t;cin>>t;while(t--)
    #define bi begin()
    #define ei end()
    #define fi first 
    #define se second  
    #define foe(i,a,b) for(ll i=a;i<b;i++)
    #define rfoe(i,a,b) for(ll i=a;i>=0;i--)
    #define sz(s) s.size() 
    #define mem(a,s) memset(a,s,sizeof(a)) 
    #define all(v) v.bi,v.ei
    #define MAX             8000000000000000064LL
    #define MIN            -8000000000000000064LL   

    typedef pair<ll,ll> pii;
    
    ll add(ll a, ll b){return (a%MOD + b%MOD + ((MAX)/MOD)*MOD)%MOD;}
    ll sub(ll a, ll b){return (a%MOD - b%MOD + ((MAX)/MOD)*MOD)%MOD;}
    ll mul(ll a, ll b){return ((a%MOD)*(b%MOD) + ((MAX)/MOD)*MOD)%MOD;}
    ll lcm(ll a,ll b){return(a*b)/__gcd(a,b);}
    ll fact[1000007 ]={0};
    ll expo(ll x, ll y) {ll res=1;x=x%MOD;while(y>0){if(y&1)res=(1ll*res*x)%MOD;
    y=y>>1;x=(1ll*x*x)%MOD;} return res;}
    void facto() {fact[0]=1;fact[1]=1;for(ll i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%MOD;}
    ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[r],MOD-2)))%MOD; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res;}
    ll npr(ll n,ll r) {facto(); ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res; }
    int const N=2e5+9;
    ll const INF = 2e18+5;
    ll dx[8]={0,0,1,-1,1,1,-1,-1};
    ll dy[8]={1,-1,0,0,-1,1,-1,1};
    long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = mul(res,a);
        a = mul(a,a);
        b >>= 1;
    }
    return res;
}
  
    void solve()
    {  
        ll n,k;
        cin>>n>>k;
        vector<ll>v;
        ll l[k],r[k];
        foe(i,0,k)
        {
           cin>>l[i]>>r[i];
        }
        sort(all(v));
        ll dp[n+1];
        mem(dp,0);
        dp[0]=0;
        dp[1]=1;
        foe(i,2,n+1)
        {
           foe(j,0,k)
           {
               if((i-l[j])>=1)
               {
                   dp[i]=add(dp[i],dp[i-l[j]]);
                //    if(l[j]==r[j])continue;
                   dp[i]=sub(dp[i],dp[max(0LL,i-r[j]-1)]);
               }
           }
        //    cout<<dp[i]<<" ";
            if(i==n)
            {
                cout<<dp[n]<<" ";
                return;
            }   
           dp[i]=add(dp[i],dp[i-1]);
        }
    }
    int main()
    {
        fast
        // facto();
        // Sieve();
    //    ct    
        { 
            solve();
        }
    }


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
ll n;
cin >> n;
vll a(n);
vin (a);
cout << *max_element(all(a)) - *min_element(all(a)) << endl;
}

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

int main() {
    int n;
    int a[30];
    int b[60];
    int c[60];
    int mc;
    cin >> n;
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++) cin >> b[i];
    for(int i=0;i<n-1;i++) cin >> c[i];
    
    int sum = 0;
    for(int j=0;j<n-1;j++){
        if(a[j+1] == (a[j]+1)){
            sum = sum + c[a[j]-1];
        }
    }
    for(int k=0;k<n;k++) sum = sum+b[k];

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0] * (n + 1)
sb = [0] * (m + 1)
for i in range(n):
  sa[i + 1] = sa[i] + a[i]
for i in range(m):
  sb[i + 1] = sb[i] + b[i]
r = m
ans = 0
for i in range(n + 1):
  if sa[i] > k:
    break
  while sa[i] + sb[r] > k:
    r -= 1
  ans = max(ans, i + r)
print(ans)


Measured memory_bytes: 47532
n, p = map(int, input().split())
a = [i % 2 for i in map(int, input().split())]
zero = a.count(0)
one = a.count(1)

def comb(n, r):
    a = 1
    for i in range(n-r+1, n+1):
        a *= i
    for i in range(1,r+1):
        a //= i
    return a

ans = 0

if p:
    for i in range(zero+1):
        for j in range((one+1)//2 + 1):
            ans += comb(zero, i)*comb(one, 2*j+1)
else:
    for i in range(zero+1):
        for j in range((one+1)//2 + 1):
            ans += comb(zero, i)*comb(one, 2*j)
print(ans)



Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

#define f first
#define s second

typedef pair<int, int> P;
typedef pair<P, P> P2;

int main(){
  int n;
  P2 team[310];
  int id, u, a, p;
  while(cin >> n, n){
    for(int i = 0 ; i < n ; i++){
      cin >> id >> u >> a >> p;
      team[i].f.f = -a;
      team[i].f.s = p;
      team[i].s.f = u;
      team[i].s.s = id;
    }
    
    sort(team, team+n);
    
    map<int, int> AC_cnt;
    vector<int> AC_team;
    
    for(int i = 0 ; i < n ; i++){
      AC_cnt[team[i].s.f]++;
      if(AC_team.size() < 10 && AC_cnt[team[i].s.f] <= 3){
	AC_team.push_back(team[i].s.s);
      }
      else if(AC_team.size() < 20 && AC_cnt[team[i].s.f] <= 2){
	AC_team.push_back(team[i].s.s);
      }
      else if(AC_team.size() < 26 && AC_cnt[team[i].s.f] <= 1){
	AC_team.push_back(team[i].s.s);
      }
    }
    
    for(int i = 0 ; i < AC_team.size() ; i++){
      cout << AC_team[i] << endl;
    }
    /*
    for(int i = 0 ; i < n ; i++){
      printf("%d %d %d %d\n", team[i].s.s, team[i].s.f, -team[i].f.f, team[i].f.s);
    }
    */
  }
  return 0;
}

Measured memory_bytes: 1224
(function() {
    'use strict';

    var fs = require('fs');
    var contents = fs.readFileSync('/dev/stdin', 'utf-8');

    var watch = function(n) {
        var h = Math.floor(n / 3600);
        var m = Math.floor((n - 3600 * h) / 60);
        var s = n % 60;
        return h + ":" + m + ":" + s;
    }

    console.log(watch(parseInt(contents)));
})();

Measured memory_bytes: 15528
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define deb 0
using namespace std;
int main(void){
    int n;
    while(1){
        cin>>n;
        if(!n)break;
        double p[2][200];
        double xmin=10000.0;
        bool flg[200]={0};
        int xi,first;
        for(int i=0;i<n;i++){
            scanf("%lf,%lf",&p[0][i],&p[1][i]);
            if(xmin>p[0][i])xmin=p[0][i],first=xi=i;
            if(deb)cout<<"first="<<first<<endl;
        }
        if(deb)for(int i=0;i<n;i++){
            cout<<i<<" ... ("<<p[0][i]<<","<<p[1][i]<<")"<<endl;
        }
        if(deb)cout<<"."<<endl;
        double r=10000;
        double next=270,ith=1000,now=0;
        int nextnum,nextnow;
        int q=n;
        while(q--){
            if(deb)cout<<"next="<<next<<endl;
            for(int i=0;i<n;i++){
                if(!flg[i]&&i!=xi){
                    if(deb)cout<<i<<"******"<<endl;
                    double xd=p[0][i]-p[0][xi],yd=p[1][i]-p[1][xi];
                    double rd=hypot(xd,yd);
                    now=atan2(yd/rd,xd/rd)/M_PI*180;
                    if(now<0)now+=360;
                    if(deb)cout<<"xd="<<xd<<",yd="<<yd<<endl;
                    if(deb)cout<<"rd="<<rd<<endl;
                    if(deb)cout<<"atan2="<<now<<endl;
                    double fnow;
                    next-now<0 ? fnow=next-now+360:fnow=next-now;
                    if(deb)cout<<"next-now="<<fnow<<endl;
                    if(fnow<ith){
                        nextnum=i;
                        nextnow=now;
                        ith=fnow;
                        if(deb)cout<<"///"<<nextnum<<endl;
                    }
                }
            }
            flg[nextnum]=1;
            if(deb)cout<<"<"<<nextnum<<">"<<endl<<endl;
            xi=nextnum;
            next=nextnow;
            ith=1000;
            if(flg[first])break;
        }
        int f=0;
        for(int i=0;i<n;i++){
            if(!flg[i])f++;
            if(deb)cout<<"flg["<<i<<"] = "<<flg[i]<<endl;
        }
        cout<<f<<endl;
    }
    return 0;
}

Measured memory_bytes: 1348
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))


signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    long double n,m,d; cin >> n >> m >> d;
    if(d==0.0){
         fout( (m-1.0)/(n) );
    }
    else{
        double cnt=2.0*(n-d);
        fout( cnt/n * (m-1.0)/n) ;
    }
}


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

int main() {
	int n,k,x,su=0;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		su+=min(x,abs(k-x));
	}
	cout<<(su<<1);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int i,n,j;
		boolean f[]=new boolean[60000];
		for(i=2;i<f.length;i++) f[i]=true;

		for(i=2;i<f.length;i++){
			if(f[i]){
				for(j=2;j*i<f.length;j++){
					f[j*i]=false;
				}
			}
		}//hurui
		
		while(sc.hasNext()){
			n=sc.nextInt();
			for(i=n-1;;i--){
				if(f[i]){
					System.out.print(i+" ");
					break;
				}
			}//for
			for(j=n+1;;j++){
				if(f[j]){
					System.out.println(j);
					break;
				}
			}
		}//while
	}
}

Measured memory_bytes: 12000
import java.util.*;

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

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

        int ret = 0;
        for (int i = 0; i < n; i++) {
            ret += a[i] - 1;
        }

        System.out.println(ret);
    }
}

Measured memory_bytes: 25964
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  int N;
  int a[30];

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

  int ans = 0;
  int mx = 0;
  for (int i = 0; i < N; ++i) {
    if (a[i] >= mx) ++ans;
    chmax(mx, a[i]);
  }

  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int K = 60;
const int INF = 1e18 + 239;

int dp[K][2][2];

void init() {
	for (int i = 0; i < K; i++) {
		for (int f = 0; f < 2; f++) {
			for (int s = 0; s < 2; s++) {
				dp[i][f][s] = INF;
			}
		}
	}
	dp[0][0][0] = 0;
}

int safe_shift(int a, int b) {
	if (a == 0) return 0;
	return (a << b);
}

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

	int n;
	cin >> n;
	int x, y;
	int z = 0;
	for (int i = 0; i < n; i++) {
		int v;
		cin >> v;
		if (i == 0) {
			x = v;
		} else if (i == 1) {
			y = v;
		} else {
			z ^= v;
		}
	}
	//(x - a) ^ (y + a) == z
	init();
	for (int i = 0; i + 1 < K; i++) {
		for (int cf = 0; cf < 2; cf++) {
			for (int cs = 0; cs < 2; cs++) {
				if (dp[i][cf][cs] == INF) continue;
				for (int b = 0; b < 2; b++) {
					int ncf = 0;
					int ncs = 0;
					int bx = (x >> i) & 1;
					int by = (y >> i) & 1;
					// int vf = (b ^ bx);
					// int vs = (b ^ by);
					int rbf = b ^ bx ^ cf;
					int rbs = b ^ by ^ cs;
					if ((bx << i) - (b << i) - safe_shift(cf, (i - 1)) < 0) ncf = 1;
					if ((by << i) + (b << i) + safe_shift(cs, (i - 1)) > (1LL << i)) ncs = 1;
					// if (i == 0 && cf == 0 && cs == 0 && b == 1) {
					// 	cerr << rbf << ' ' << rbs << endl;
					// 	cerr << ((z >> i) & 1) << endl;
					// 	cerr << ncf << ' ' << ncs << endl;
					// }
					if ((rbf ^ rbs) != ((z >> i) & 1)) continue;
					dp[i + 1][ncf][ncs] = min(dp[i + 1][ncf][ncs], dp[i][cf][cs] + (b << i));
				}
			}
		}
	}
	int ans = dp[K - 1][0][0];
	if (ans >= x) {
		cout << -1 << endl;
	} else {
		cout << ans << endl;
	}
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  int a[n];
  REP(i,n){
    cin>>a[i];
  }
  //a[i]のj桁目のbitが立っているかどうかを格納する配列
  vector<vector<int>> bits(n,vector<int>(20,0));
  REP(i,n){
    REP(j,20){
      if(1&a[i]>>j){
        bits[i][j]=1;
      }
    }
  }
  vector<int> sbits(20,0);
  int r=0;
  long long ans=0;
  REP(l,n){
    if(r+1>=n){
      ans += (long long)r-l+1;
      continue;
    }
    if(l==0 || r<l){
      REP(i,20){
        sbits[i]+=bits[l][i];
      }
      r=l;
    }
    bool flag=true;
    while(flag && r+1<n){
      REP(i,20){
        if(sbits[i]+bits[r+1][i]>1){
          flag=false;
          break;
        }
      }
      if(flag){
        r++;
        REP(i,20){
          sbits[i]+=bits[r][i];
        }
      }
    }
    ans += (long long)r-l+1;
    REP(i,20){
      sbits[i]-=bits[l][i];
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 24448
#include <iostream>

using namespace std;

int main(){
  long long x, ans;

  cin >> x;
    
  ans = x / 11 * 2;
  x %= 11;

  if(x <= 6 && x > 0){
      cout << ans + 1 << endl;
  }else if(x > 6){
      cout << ans + 2 << endl;
  }else{
      cout << ans << endl;
  }
}

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

int main() {
    using namespace std;
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    vector<int> xs(x.size());
    copy(x.begin(), x.end(), xs.begin());
    sort(xs.begin(), xs.end());
    int mc1 = xs[n/2 - 1];
    int mc2 = xs[n/2];
    for (int i = 0; i < n; i++) {
        if (x[i] <= mc1) {
            cout << mc2 << endl;
        } else {
            cout << mc1 << endl;
        }
    }
}

Measured memory_bytes: 3712
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;
long double t_h = 12;
long double t_m = 1;
long double pi = 3.1415926535897932384626433832795l;
int main()
{
  // freopen("in", "r", stdin);
  long double a, b, h, m;
  cin >> a >> b >> h >> m;
  long double t_hour = h + m / 60;
  long double rad_h = -t_hour / t_h * 2 * pi;
  long double rad_m = -t_hour * 2 * pi;
  printf("%.20Lf", sqrt(a * a + b * b - 2 * a * b * cos(rad_h - rad_m)));
  return 0;
}

Measured memory_bytes: 4168
#include <stdio.h>
int main(){
      int a,b,c,i,te;
      a=b=c=-1;
      for(i=0;i<10;i++){
            scanf("%d",&te);
           if(te>=a){
                  c=b;
                  b=a;
                 a=te;
           }
          else if(te>=b){
                   c=b;
                   b=te;
           }
          else if(te>c) c=te;
      }
      printf("%d\n%d\n%d\n",a,b,c);
      return 0;
}

Measured memory_bytes: 600
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int g[10][10];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      scanf("%d", &g[i][j]);
    }
  }
  for (int k = 0; k < 10; ++k) {
    for (int i = 0; i < 10; ++i) {
      for (int j = 0; j < 10; ++j) {
        if (g[i][k] + g[k][j] < g[i][j]) {
          g[i][j] = g[i][k] + g[k][j];
        }
      }
    }
  }
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      int x;
      scanf("%d", &x);
      if (x == -1) continue;
      ret += g[x][1];
    }
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 256
N = int(input())
V = list()
C = list()
plus = list()

for i, j in zip(range(N), input().split()):
    V.append(int(j))
for i, j in zip(range(N), input().split()):
    C.append(int(j))

for i, j in zip(V, C):
    if i-j > 0:
        plus.append(i-j)

print(sum(plus))


Measured memory_bytes: 3060
/*------U Have To DO It------*/
/* BY-> RicoProg */
/*        ___ 
           __|__|
          |  |___       */
#include <bits/stdc++.h>
using namespace std;
 
 
//---------------------------------------------------MACROS----------------------------------------------------------
#define ll long long
#define beg(i ,n) for(int i=0;i<n;i++)
#define beg1(i ,n) for(int i=1;i<n;i++)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back 
#define mp make_pair
#define nl "\n" 
#define vec(v , n) vector<ll> v(n)
#define all(x) x.begin() , x.end()
#define pii pair<int , int>
#define pll pair<ll , ll>
#define mii map<int , int>
#define mll map<ll , ll>
#define msi map<string , int>
#define mci map<char , int>
#define f1 first
#define f2 second
 
//---------------------------------------------------GLOBAL----------------------------------------------------------
const ll MOD = 998244353 ;
const ll MAX = 1e5 + 7;
//---------------------------------------------------FUNCTIONS-------------------------------------------------------

vector<ll> gr[100001] ;
bool vis[100001] ;
ll dp[100001] ;
ll n , m ;

void rec(ll x){
	if(dp[x]!=-1){
		return ;
	}
	if(gr[x].size()==0){
		dp[x] = 0 ;
		return ;
	}
	dp[x] = 0 ;
	for(auto i : gr[x]){
		if(!vis[i]){
			rec(i) ;
			dp[x] = max(dp[x] , dp[i]);
		}
	}
	dp[x]+=1 ;
	return ;
}

void solve(){
	memset(dp , -1 , sizeof(dp)) ;
	ll a , b , ans=0 ;
	cin >> n >> m ;
	beg(i , m){
		cin >> a >> b ;
		gr[a].pb(b) ;
	}
	beg1(i , n+1){
		if(!vis[i]) rec(i) ;
	}
	beg1(i , n+1) ans = max(ans , dp[i]) ;
	cout << ans ;
}
 
//---------------------------------------------------DRIVER----------------------------------------------------------
int main()
{
    fast ;
    int t=1 ;
    //cin >> t ;
    while(t--){
        solve() ;
    }
    return 0;
}	

Measured memory_bytes: 8576