akhauriyash/Code-Regression huggingface dataset:
module Graphical
	require 'set'

	def reachable_from(s, max_depth = nil)
		reached = Set[s]
		queue = [s]
		depth = 0
		loop {
			break if max_depth && depth >= max_depth
			next_queue = []
			until queue.empty?
				u = queue.shift
				each_out_connection_of(u){|v, _|
					next if reached.include?(v)
					reached << v
					next_queue << v
				}
			end
			break if next_queue.empty?
			queue = next_queue
			depth += 1
		}
		return reached
	end
end

def compress(used_x)
	x_map = {}
	used_x.to_a.uniq.sort.each_with_index{|x, i| x_map[x] = i}
	x_map
end

loop {
	n = gets.to_i
	break if n == 0
	rects = (1..n).map{ gets.split.map &:to_i }

	x_map = compress( rects.map{|r| [r[0], r[2]]}.flatten )
	y_map = compress( rects.map{|r| [r[1], r[3]]}.flatten )
	rects.map!{|x1, y1, x2, y2| [x_map[x1]+1 ,y_map[y1]+1, x_map[x2]+1 ,y_map[y2]+1]}

	a = (0..y_map.size+2).map{ (0..x_map.size+2).map{ 0 } }
	rects.each_with_index{|(x1, y1, x2, y2), k| 
		(y2..y1-1).each{|i|
			(x1..x2-1).each{|j|
				a[i][j] |= (1 << k)
			}
		}
	}

	a.extend Graphical
	def a.each_out_connection_of(u)
		y, x = u
		[[1,0],[-1,0],[0,1],[0,-1]].each{|dy, dx|
			u, v = y+dy, x+dx	
			yield([u, v], 1) if (0..self.size-1) === u && (0..self[0].size-1) === v && self[u][v] == self[y][x]
		}
	end

	hash = {}
	c = 0
	(0..a.size-1).each{|i|
		(0..a[i].size-1).each{|j|
			next if hash[[i, j]]	
			c += 1
			a.reachable_from([i,j]).each{|y, x|
				hash[[y,x]] = 1
			}
		}
	}
	p c
}

Measured memory_bytes: 12124
#include <iostream>
#include <algorithm>

using namespace std;

#define For(i,a,b) for(int i = a; i <= b;i++)

int n,A[100001];
std::string st;

int main() {
    cin >> n;
    
    For(i,1,n)
      cin >> A[i];
      
    sort(A + 1,A + 1 + n);
    
    int res = 0;
    For(i,1,n - 2)
       For(j,i + 1,n - 1)
          For(k,j + 1,n)
             if (A[i] + A[j] > A[k] && A[j] + A[k] > A[i] && A[k] + A[i] > A[j])
               res++;
             else
               break;
               
    cout << res;           
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long int;

const ll P = 1013;
const ll MOD = 1000000007;

int N;
ll hash_tab[100010];
map<ll, int> cnt;
vector<int> G[100010];

void dfs(int cur, int par=-1) {
  for(auto to : G[cur]) {
    if(to == par) continue;
    dfs(to, cur);
    (hash_tab[cur] += hash_tab[to]) %= MOD;
  }
  (hash_tab[cur] *= P) %= MOD;
  (hash_tab[cur] += 1) %= MOD;
  cnt[ hash_tab[cur] ]++;
}

int main() {
  cin >> N;
  for(int i=0; i<N-1; i++) {
    int u, v; cin >> u >> v;
    u--; v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  dfs(0);
  ll ans = 0;
  for(auto x : cnt) {
    ll tmp = x.second;
    ans += tmp * (tmp - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 23408
int main(void)
{
    int n,m,t,i,j;
  
    scanf("%d %d",&n,&m);
      
    int a[100][100],b[100],ans[100];
  
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
  
  
  
    for(i=0;i<m;i++)
    {
        scanf("%d",&b[i]);
    }
  
    for(i=0;i<n;i++)
    {
        t = 0;
          
        for(j=0;j<m;j++)
        {
            t = t + (a[i][j]*b[j]);
              
        }
  
        ans[i] = t;
          
    }
  
    for(i=0;i<n;i++)
    {
        printf("%d\n",ans[i]);
    }
  
  
      
    return 0;
  
}


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

//素数かどうか判定する関数
bool judge( int x )
{

    for( int i = 2; i <= sqrt(x); i++ )       //与えられた数が10なら
    {                                         //
        if( x % i == 0)
            return false;
    }

    return true;
}

int main()
{
    int n;

    while( cin >> n )                           
    {
        bool PN[n+1];                               //PrimeNumber
        int count = 0;                              //countは素数の数


        PN[0] = false;                              //0は素数ではない。
        PN[1] = false;                              //1は素数ではない。

        for( int i = 2; i <= n; i++)                //0,1以外の全ては素数候補。ここから篩にかける。 
        {
            PN[i] = true;                           //ex.100の場合、2~100を素数候補とする。
            count++;
        }

        for( int i = 2; i <= sqrt(n); i++)          //nの平方根以下の素数の倍数を消していけば、残ったものが素数となる。    
        {
            if( PN[i] == true )                     //素数ならば
            {
                 for( int j = 2; j <= n / i; j++ )  //素数の倍数を順に削除していく
                {
                    if( PN[i*j] == true )           //2*3と3*2で重複しないように
                    {
                        PN[i*j] = false;            //素数ではないことが分かった
                        count--;                    //削除
                    }
                    
                }
            }
   
        }
        cout << count << endl;
    }

    return 0;
}


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

int main(){
  int k,s,sum=0; cin>>k>>s;
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
      int z=s-x-y;
      if(0<=z && z<=k) sum++;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
const int MAXN = (int)1e6+7;

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

    int a,b,c;
    cin >> a >> b >> c;
    if (a+b+c>=22) cout << "bust" << endl;
    else           cout << "win"  << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>//
#include <vector>//
#include <map>
#include <cstdlib>
#include <numeric>
#include <algorithm>//ソート等に使用
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <thread>///////////////////
#include <queue>//幅優先等のキュー
#include <stack>
#include <bitset>

#define rep(i,m,n) for(int i=(m);i<=(n);i++)
#define mer(i,m,n) for(int i=(m);i>=(n);--i)

#define MOD 1000000007
//#define MOD 998244353
//#define MAX 

using namespace std;

using ll = long long int;
using ld = long double;
using std::swap;

vector<int> v;
vector<long long int> vll;
//vector<vector<int>> vec(50, vector<int>(4, 0));
vector<vector<int>> vv;
vector<char> vc;
vector<string> vs;




int main() {
	double D, T, S;
	cin >> D >> T >> S;
	double time = D / S;
	if (time <= T)cout << "Yes" << '\n';
	else cout << "No" << '\n';
	return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long int ll;

int main()
{
  int N, T, A, i, ans = 1;
  cin >> N >> T >> A;
  int H[N];
  T *= 1000;
  A *= 1000;
  for (i = 0; i < N; ++i) {
    cin >> H[i];
    H[i] = abs(T-H[i]*6-A);
  }
  int now = H[0];
  for (i = 0; i < N; ++i) {
    if ( H[i] < now) {
      now = H[i];
      ans = i+1;
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define all(v) v.begin(),v.end()
#define fio() ios::sync_with_stdio(0);cin.tie(0);
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define fornn(i,a,n) for(ll i=a;i<=n;i++)
#define pb push_back
#define MAXN 100005LL
#define INF LONG_MAX
#define MOD 1e9+7LL
inline void solve(){
	ll n;
	cin>>n;
	ll arr[n],dp[n];
	for(ll i=0;i<n;i++){
		cin>>arr[i];
	}
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(ll i=2;i<n;i++){
		dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
	}
	cout<<dp[n-1];
}
int main(){
	fio();
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 5180
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define N	 100
void solve(){
	int n, a, b;
	cin>>n>>a>>b;
	cout<<min(n*a,b)<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}



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

#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int N, x; cin >> N >> x;
	vector<int> a(N); rep(i, 0, N) { cin >> a[i]; }
	int ans = 0;
	rep(i, 1, N) {
		if (a[i - 1] + a[i] > x) {
			ans += a[i - 1] + a[i] - x;
			a[i] -= a[i - 1] + a[i] - x;
			a[i] = max(0LL, a[i]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1152
import bisect
import itertools

a, b, q = map(int, input().split())
ss, tt = [], []
for _ in range(a):
  ss.append(int(input()))
for _ in range(b):
  tt.append(int(input()))
  
for _ in range(q):
  x = int(input())
  md = pow(10, 15)
  xs, xt = bisect.bisect_left(ss, x), bisect.bisect_left(tt, x)
  ls, rs, lt, rt = ss[max(0, xs-1)], ss[min(a-1, xs)], tt[max(0, xt-1)], tt[min(b-1, xt)]
  for s, t in itertools.product([ls, rs], [lt, rt]):
    if s > t:
      if t > x:
        md = s - x if s - x < md else md
      elif s > x:
        if md > 2 * (s-x) + x-t:
          md = 2 * (s-x) + x-t
        if md > 2 * (x-t) + s-x:
          md = 2 * (x-t) + s-x
      else:
        md = x - t if x - t < md else md
    else:  # t > s
      if s > x:
        md = t - x if t - x < md else md
      elif t > x:
        if md > 2 * (x-s) + t-x:
          md = 2 * (x-s) + t-x
        if md > 2 * (t-x) + x-s:
          md = 2 * (t-x) + x-s
      else:
        md = x - s if x - s < md else md
  print(md)

Measured memory_bytes: 12120
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  long long takahashi, aoki, K;
  scanf("%lld", &takahashi);
  scanf("%lld", &aoki);
  scanf("%lld", &K);
  long long out1, out2;
  if (K>=takahashi){
    out1 = 0;
    out2 = (long long)fmax(0, aoki-(K-takahashi));
  } else {
    out1 = takahashi-K;
    out2 = aoki;
  }
  printf("%lld %lld\n",out1, out2);
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
 
using namespace std;
#define rep(i,a,b) for (ll i = a; i < b; i++)
#define rrep(i,a,b) for (ll i = a; i >= b; i--)
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
 
using namespace std;
#define rep(i,a,b) for (ll i = a; i < b; i++)
#define rrep(i,a,b) for (ll i = a; i >= b; i--)
#define l(s) s.length()
#define sort(v) sort(v.begin(), v.end());
#define scan(v,n) rep(i,0,n) {ll k; cin >> k; v.pb(k);}
#define print(v,n) {rep(i,0,n) cout << v[i] << " "; cout << endl;}
#define printstr(s,n) {rep(i,0,n) cout << s[i]; cout << endl;}
#define rev(a) reverse(a.begin(), a.end());
#define pb push_back
typedef long long ll;
typedef long double lld;
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
 
const ll mxN=1e3;
const ll N=1e9+7;
 
ll dp[mxN+1][mxN+1];
char gr[mxN+1][mxN+1];

  int main() {
      int T=1;// cin >> T;
      while(T--){
          ll h,w; cin >> h >> w;
          rep(i,0,h) 
              rep(j,0,w) 
                  cin >> gr[i][j];
          dp[0][0]=1;
          rep(i,0,h) {
              rep(j,0,w) {
                  if(gr[i][j]=='.') {
                      
                      if(i) dp[i][j]+=dp[i-1][j];
                      if(j) dp[i][j]+=dp[i][j-1];
                  }
                  dp[i][j]%=N;
              }
          }
          cout << dp[h-1][w-1];
      } 
	 return 0;
}


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

using namespace std;

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b && b==c){
    if(a%2==0 && b%2==0 && c%2==0){
      cout<<-1<<endl;
      return 0;
    }
  }
  int count=0;
  while(1){
    if(a%2!=0 || b%2!=0 || c%2!=0){
      cout<<count<<endl;
      return 0;
    }
    int d=a;
    int e=b;
    int f=c;
    a=(e+f)/2;
    b=(d+f)/2;
    c=(d+e)/2;
    count++;
  }
}

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


void solve(long long N, long long A, long long B, std::vector<long long> X){
    ll ans = 0, tmp;
    for(ll i=0; i< N-1; i++){
        tmp = X[i+1]-X[i];
        ans += min(B, A*tmp);
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    std::vector<long long> X(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&X[i]);
    }
    solve(N, A, B, std::move(X));
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int n, m, x;
    cin >> n >> m >> x;
    vector<bool> A(n + 1);
    rep(i, m) {
        int pos;
        cin >> pos;
        A.at(pos) = true;
    }

    int lcost = 0, rcost = 0;
    for (size_t i = 0; i < A.size(); i++) {
        if (i < x && A.at(i))
            lcost++;
        if (x < i && A.at(i))
            rcost++;
    }
    cout << min(lcost, rcost) << endl;
}


Measured memory_bytes: 3656
import sys
fin = sys.stdin.readline
from bisect import bisect, bisect_left
from collections import defaultdict


N = int(fin())
A_list = [int(elem) for elem in fin().split()]
B_list = sorted([int(elem) for elem in fin().split()])
C_list = sorted([int(elem) for elem in fin().split()])

# # create mapping
# map_B_to_num_C = dict()
# for B in B_list:
#     idx = bisect(C_list, B)
#     map_B_to_num_C[B] = N - idx

# # create cuml_sum
# cuml_combinations = [0] * N
# current_combinations = 0
# for i, B in enumerate(reversed(B_list)):
#     current_combinations += map_B_to_num_C[B]
#     cuml_combinations[N - i - 1] = current_combinations

cuml_combinations = [0] * N
current_combinations = 0
for i, B in enumerate(reversed(B_list)):
    idx = bisect(C_list, B)
    current_combinations += N - idx
    cuml_combinations[N - i - 1] = current_combinations

num_combinations = 0
for A in A_list:
    B_idx = bisect(B_list, A)
    try:
        num_combinations += cuml_combinations[B_idx]
    except IndexError:
        pass

print(num_combinations)


Measured memory_bytes: 23576
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

////////////////////////////////////////////////////////


int main() {
    ll n, k; cin >> n >> k;
    Vl a(n);
    rep(i, 0, n) cin >> a[i];
    rep(i, k, n){
        if(a[i-k] < a[i]) co("Yes");
        else co("No");
    }

    return 0;
}




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

using namespace std;

int d[10][10];

int main(){
    int n;
    cin >>n;
    for(int i=1;i<=n;i++){
        int f = i, l = i%10;
        while(f >= 10)
            f/=10;
        if(l != 0){
            d[f][l]++;
        }
    }
    int cnt = 0;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            cnt+= d[i][j] * d[j][i];
        }
    }
    cout <<cnt;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.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 x;

	cin >> x;
	double wx = x/(double)180*M_PI;
	double sx, sy;
	sx = 0;
	sy = 1;
	int ans=0;
	int i=1;
	do {
		ans++;
		sx += -sin((double)i*wx);
		sy += cos((double)i*wx);
		i++;
		if (abs(sx) < 2.0e-6 && abs(sy - 1.0) < 2.0e-6) break;
	} while(1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4000
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int N,A,B;
    cin >> N >> A >> B;
    int t[N];
    int result=0;
    for (int i = 0; i < N; ++i)
    {
    	cin >> t[i];
    	if(A>t[i] || B<=t[i]){
    		result++;
    	}
    }
    // 出力
    cout << result << endl;
    return 0;
}

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

int main(){
    int n;
    
    while(cin >> n,n){
        int s = 0;
        
 
        for(int i = 1 ; i*i <= n ; i++){
            if(n%i==0){
                s += i;
               if(i != n/i) s += n/i;
            }
        }
        
        s -= n;
        if(n == s){
            cout << "perfect number" << endl;
        }
        else if(n > s){
            cout << "deficient number" << endl;
        }
        else cout << "abundant number" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n); for(long long i = 0;i < (n);i++)
typedef long long ll;
typedef vector<long long> vl;

int main(){
	ll n; cin >> n;
	vl p(n); rep(i,n)cin >> p[i];
	ll ans = 0;
	ll m = 1000000;
	rep(i,n){
		if(p[i] <= m){
			ans++;
			m = p[i];
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 1792
use proconio::input;

fn main() {
    input! {
        n: usize
    }

    solve(n);
}

fn solve(n: usize) {
    let mut s = 0;
    for i in 1..(n + 1) {
        if i % 3 == 0 {
            continue;
        }
        if i % 5 == 0 {
            continue;
        }
        s += i;
    }
    println!("{}", s);
}


Measured memory_bytes: 2084
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int a[1000000];
int pos[1000000];
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,l=0,r=n+1,res=0;
set<int>s;
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>a[i];
}
s.insert(0);
s.insert(n+1);
for(int i=1; i<=n; i++)
{
pos[a[i]]=i;
}
for(int i=1; i<=n; i++)
{
auto x=s.lower_bound(pos[i]);
r=*x;
auto t=s.lower_bound(pos[i]);
l=*(--t);
res+=(r-pos[i])*(pos[i]-l)*i;
s.insert(pos[i]);
}
cout<<res<<endl;
return 0;
}

Measured memory_bytes: 15360
#include<bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i <= b; i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
ll n, a[200020], ans  = 0;
int main() { ios::sync_with_stdio(false);cin.tie(0);
	cin >> n;
	for (int i = 0; i <n; i++) cin >> a[i];
	for (int i = 0; i < n; i++){
		for (int j = i+1; j < n; j++) {
			ans += (a[i]*a[j]);
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <random>
#include <chrono>
#include <iomanip>
#define lint long long int
#define FOR(x, to) for(int x=0; x<(int)(to); x++) // for簡略表記
#define DUMP(ar) for(int loop_dump=0; loop_dump<(int)ar.size(); loop_dump++) cout << "[" << loop_dump << "]:" << ar[loop_dump] << endl // 配列一覧表示
#define DUMPL(ar) for(int loop_dump=0; loop_dump<(int)ar.size(); loop_dump++) { cout << ar[loop_dump]; if(loop_dump<(int)ar.size()-1) cout << ' '; } cout << endl; // 配列一行一覧表示
#define COUT(x) cout << x << endl // 単要素出力
#define ALL(ar) ar.begin(), ar.end() // コンテナの全要素
#define LOOPD(i) cout << "ループ[" << i << "]回目---------------" << endl // ループ回数デバグ
using namespace std;
// cout << fixed << setprecision(4) で小数点以下4桁の桁そろえ
// cout << setw(5) << ... で表示形式を5桁に設定 5桁未満なら頭に空白がつく 5桁越なら先頭から5桁まで
// cout << setw(5) << setfill('0') << ... で空白部分の埋め文字に5を使う
// getline(cin, [変数]); で空白などを含む入力の受け取り(行ごとの受け取り)
// cin >> ws; でそこまでにストリームに残されたホワイトスペースを取り除く(=以降のgetlineの有効化)

struct union_find{
    vector<int> par;
    vector<int> size;
    union_find(int n){
        par.resize(n);
        size.resize(n);
        for(int i=0; i<n; i++){
            par[i] = i;
            size[i] = 1;
        }
    }

    // yをxへ
    void unite(int x, int y){
        // cout << "x: " << x << "とy: " << y << "を接続" << endl;
        int par_x = find(x), par_y = find(y);
        if(size[par_x] > size[par_y]){
            size[par_x] += size[par_y];
            par[par_y] = find(x);
        }else{
            size[par_y] += size[par_x];
            par[par_x] = find(y);
        }

        // par[find(y)] = x;
        // cout << y << ":[" << par[y] << "]" << endl;
    }

    int find(int x){
        int tmp = x;
        while(par[tmp] != tmp){
            // cout << "x:" << x << " par[x]:" << par[x] << endl;
            tmp = par[tmp];
        }
        par[x] = tmp;
        return tmp;
    }

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

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

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

    vector<int> p(n);
    FOR(i, n) cin >> p[i];
    vector<pair<int, int>> c(m);
    FOR(i, m) cin >> c[i].first >> c[i].second;

    union_find uf(n);
    for(int i=0; i<m; i++){
        uf.unite(c[i].first-1, c[i].second-1);
    }

    // DUMP(uf.par);

    int ans = 0;
    for(int i=0; i<n; i++){
        if(uf.same(i, p[i]-1)){
            ans++;
        }
    }

    COUT(ans);
    // DUMP(uf.par);

    return 0;
}

Measured memory_bytes: 2176
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, tmp, s1, s2, abs, minAbs int
	fmt.Scanf("%d", &n)
	var w []int
	w = []int{}
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		w = append(w, tmp)
	}
	minAbs = 100
	for i := 0; i < n; i++ {
		s1 = 0
		s2 = 0
		for j := 0; j < n; j++ {
			if j <= i {
				s1 = s1 + w[j]
			} else {
				s2 = s2 + w[j]
			}

		}
		abs = int(math.Abs(float64(s1 - s2)))
		if minAbs > abs {
			minAbs = abs
		}
	}
	fmt.Print(minAbs)
}


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

bool is_ex(int x){
    if(x == 1) return true;
    for (int i = 2; i < x; ++i){
        for(int j = 1; j < x; ++j){
            int tmp = i;
            for(int k = 0; k < j; ++k) tmp *= i;
            if(tmp == x) return true;
            if(tmp > x) break;
        }
    }
    return false;
}

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

    int x;
    cin >> x;

    int res;
    for(int i = 1; i <= x; ++i){
        if(is_ex(i))res = i;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef  vector<int> vi;
typedef  pair<int,int> ii;
typedef  pair<int,string> pis;
double   pi=3.1415926535898;
#define speed      ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
#define lp(i,n)    for(int i=0;i<int(n);i++)
#define ff(i,a,b)  for(int i=a;i<=int(b);++i)
#define fr(i,a,b)  for(int i=a;i>=int(b);i--)
#define ms(x,a)    memset(x,a,sizeof(x))
#define all(x)     (x).begin(),(x).end()
#define sz(x)      int(x.size())
#define pb         push_back
#define r0         return 0;
#define CC         continue;
#define bb(x)      cerr<< x <<endl;
#define F          first
#define S          second       //  __builtin_popcount;
//freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
string ys = "YES\n";
string no = "NO\n" ;
const double EPS = 1e-9;
const int inf = 1<<30;
const ll M  = 1e9+7 ;
//const int N = 100100;
//////////////////////    Hi    ^_^  hack me if you can :P

int n , ans;

int a[100200];

int main()
{
    speed;

    cin >> n;
    ff(i,1,n) {
        cin >> a[i];
    }
    ff(i,1,n) {
        if (a[i] == i) {
            swap(a[i],a[i+1]);
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

vector<LL> input;
LL n;

LL solve(LL x){
    for(int i = 0; i < n; i++){
        x = x - x%input[i];
    }
    return x;
}

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

    cin >> n;
    input = vector<LL>(n);

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

    LL ok = 1333333333333333;
    LL ng = -1;

    while(abs(ok-ng)>1){
        LL middle = (ok+ng)/2;
        LL ret = solve(middle);
        if(ret >= 2){
            ok = middle;
        }else{
            ng = middle;
        }
    }

    LL min = ok;

    ok = 0;
    ng = 1333333333333333;

    while(abs(ok-ng)>1){
        LL middle = (ok+ng)/2;
        LL ret = solve(middle);
        if(ret <= 2){
            ok = middle;
        }else{
            ng = middle;
        }
    }

    LL max = ok;

    if(max - min < 0){
        cout << -1 << endl;
    }else{
        cout << min << " ";
        cout << max << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1152
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
s = 0
A2 = {}
for i in range(N):
  s += A[i]
  k = str(A[i])
  if k not in A2:
    A2[k] = 1
  else:
    A2[k] += 1

for i in range(Q):
  b,c = map(str,input().split())
  if b in A2:
    l = A2[b]
    s += l*(int(c)-int(b))
    print(s)
    A2.pop(b)
    if c in A2:
      A2[c] += l
    else:
      A2[c] = l
  else:
    print(s)

  

Measured memory_bytes: 23156
#include <bits/stdc++.h>
#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 sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

const int mod = 998244353;
struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
bool operator==(const mint& a, const mint& b) { return a.x == b.x;}

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    auto dp0 = make_vec<mint>(c-a+1, d-b+1);
    auto dp1 = make_vec<mint>(c-a+1, d-b+1);
    dp0[0][0] = 1;
    rep(i, c-a+1) rep(j, d-b+1) {
        if (j+1 <= d-b) dp1[i][j+1] += (dp0[i][j] + dp1[i][j]) * mint(a + i);
        if (i+1 <= c-a) {
            dp0[i+1][j] += dp1[i][j];
            dp0[i+1][j] += dp0[i][j] * mint(b + j);
        }
    }
    mint ans = dp0[c-a][d-b] + dp1[c-a][d-b];
    cout << ans << endl;
}


Measured memory_bytes: 144152
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define finish(x) {cout<<x<<'\n'; return;}
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

void solve() {
	int n, m, k;
	in2(n, m);
	in(k);
	string s[n];
	for(int i=0;i<n;i++) {
		cin>>s[i];
	}
	
	int t = n+m;
	int ans = 0;
	for(int i=0;i< (1<<t);i++) {
		//~cout<<"here"<<endl;
		bool r[10] = {false}, c[10] = {false};
		for(int j=0;j<t;j++) {
			if(i & (1<<j)) {
				if(j < n) r[j] = true;
				else c[j-n] = true;
			}
		}
		
		int cnt = 0;
		for(int x=0;x<n;x++) {
			for(int y=0;y<m;y++) {
				if(r[x] || c[y]) continue;
				if(s[x][y] == '#') cnt++;
			}
		}
		if(cnt == k) ans++;
	}
	cout<<ans<<en;
}

int main() {
	int t = 1;
	
	//~cin>>t;
	while(t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 3672
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int x1 = sc.nextInt();
		int x2 = sc.nextInt();
		int x3 = sc.nextInt();
		int x4 = sc.nextInt();
		int x5 = sc.nextInt();

		if(x1 == 0) {
			System.out.println(1);
		}else if(x2 == 0) {
			System.out.println(2);
		}else if(x3 == 0) {
			System.out.println(3);
		}else if(x4 ==0) {
			System.out.println(4);
		}else {
			System.out.println(5);
		}

		sc.close();

	}

}


Measured memory_bytes: 35792
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

int main(){
  string s;
  while(cin>>s){
    int c[256] = {};
    REP(i,s.size()){
      c[s[i]] ++;
    }
    cout<<min(min(c['K'],c['U']), min(c['P'],c['C']))<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
def digitsum(x):
	s = 0
	while x > 0:
		s,x = s+x%10,x//10
	return s
l = list(range(1,10))
for i in range(10,100000):
	while digitsum(i)*l[-1] > digitsum(l[-1])*i:
		l.pop()
	l.append(i)
for length in range(6,20):
	for j in range(1000,10000):
		i = j*10**(length-4)+10**(length-4)-1
		while digitsum(i)*l[-1] > digitsum(l[-1])*i:
			l.pop()
		l.append(i)
k = int(input())
for i in range(0,k):
	print(l[i])

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

int main() {
  int K;
  string S;
  cin >> K >> S;
  if(S.size()<=K){
    cout << S << endl;
  }
  else{
    rep(i,K){
      cout << S.at(i);
    }
    cout <<"..."<<endl;
  }
}

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

int main(){
    int N, M, C;
    vector<int> Bs(21);
    int A;

    cin >> N >> M >> C;

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

    int cnt = 0;
    for(int i = 0; i < N; i++){
        int feature = C;
        for(int j = 0; j < M; j++){
            cin >> A;
            feature += A * Bs[j];
        }
        if(feature > 0){
            cnt += 1;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3624
n = int(input())
data = list(map(int,input().split())) 
flg = 0 
ct = 0
while flg ==0:
    ct += 1
   # print(data)
    for i in range(n):
        if data[0]%2 == 0:
           
            data.append(data[0]//2)
            del data[0]
        else:
            flg = 1
            break
print(ct-1)            

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
  cin>>n;
  std::vector<int> h(n+1);
  for(int i=1;i<=n;i++)  cin>>h[i];
  int dp[n+1];
  dp[2] = abs(h[2]-h[1]);
  dp[1] = 0;
  for(int i=3;i<=n;i++){
    int a = abs(h[i]-h[i-2]);
    int b = abs(h[i] - h[i-1]);
    dp[i] = min(dp[i-2]+a,dp[i-1]+b);
  }
  cout<<dp[n]<<endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	using ll = long long;
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	cout<<(k%2==0 ? a-b : b-a)<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

LL getn(LL x) {
	if (x == (LL)(1)) {
		return (LL)(1);
	}
	return (LL)(1) + (LL)(2) * getn(x / (LL)(2));
}
int main() {
	LL h;
	cin >> h;
	cout << getn(h) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long 
#define ULL unsigned long long 

const int N = 1000+11;
const int M = 1e6+11;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const LL inff = 0x3f3f3f3f3f3f3f3f;


/*-----------------------------------------*/
 
 
int main(){
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	int basex,basey;
	
	basex=abs(tx-sx); basey=abs(ty-sy);
	for(int i=1;i<=basex;i++) printf("%c",'R');
	for(int i=1;i<=basey;i++) printf("%c",'U');
	for(int i=1;i<=1;i++) printf("%c",'R');
	for(int i=1;i<=basey+1;i++) printf("%c",'D');
	for(int i=1;i<=basex+1;i++) printf("%c",'L');
	for(int i=1;i<=1;i++) printf("%c",'U');
	
	for(int i=1;i<=basey;i++) printf("%c",'U');
	for(int i=1;i<=basex;i++) printf("%c",'R');
	for(int i=1;i<=1;i++) printf("%c",'U'); 
	for(int i=1;i<=basex+1;i++) printf("%c",'L');
	for(int i=1;i<=basey+1;i++) printf("%c",'D');
	for(int i=1;i<=1;i++) printf("%c",'R');
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(x,a) for(auto& (x):(a))
#define ALL(obj) (obj).begin(),(obj).end()
#define Yes(n) cout<<((n)?"Yes":"No")<<endl;
using namespace std;
using ll=long long;
const int INF=1e9;
const ll LINF=1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  int a,b,c; cin>>a>>b>>c;
  cout<<a*b/2<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(void)

{
ll a,b;
cin>>a>>b;
for(int i=1;i<=1000;i++){
        int c=i*0.08;
int c1=i*0.1;
    if(c==a and c1==b)return cout<<i,0;
}
cout<<-1;
}


Measured memory_bytes: 256
#include<iostream>
#include<utility>
using namespace std;
int main(){
    int N,W;
    int p,w;
    pair<int,int>m[101];
    cin>>N>>W;
    for(int i=1;i<=N;++i){
        cin>>p>>w;
        m[i]=make_pair(p,w);
    }
    int V[101][10001];
    for(int i=1;i<=N;++i){
        for(int c=1;c<=W;++c){
            if(c-m[i].second<0){
                V[i][c]=V[i-1][c];
            }
            else{
                int temp;
                temp=m[i].first+V[i][c-m[i].second];
                V[i][c]=max(temp,V[i-1][c]);
            }
        }
    }
    cout<<V[N][W]<<endl;
}

Measured memory_bytes: 7000
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
struct poi
{
    char s[15];
    int x;
    int num;
};
bool cmp1(poi a,poi b)
{
    if(strcmp(a.s,b.s)==0)
    {
        return a.x>b.x;
    }
    else
    {
        return strcmp(a.s,b.s)<0;
    }
}
int main()
{
    struct poi p[107];
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
        {
            scanf("%s%d",p[i].s,&p[i].x);
            p[i].num=i+1;
        }
        sort(p,p+n,cmp1);
        for(int i=0;i<n;i++)
        {
            printf("%d\n",p[i].num);
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
#define INF ((1<<31)-1)
int main(){
	int v,e;	cin>>v>>e;
	long long int edge[v][v];
	for(int i=0;i<v;i++){
		for(int j=0;j<v;j++)	edge[i][j]=INF;
	}
	int s,t,d;
	for(int i=0;i<e;i++){
		cin>>s>>t>>d;
		edge[s][t]=d;
	}
	for(int k=0;k<v;k++){
		for(int i=0;i<v;i++){
			for(int j=0;j<v;j++){
				if(edge[i][k]!=INF&&edge[k][j]!=INF){
					edge[i][j]=min(edge[i][j],edge[i][k]+edge[k][j]);
				}
			}
		}
	}
	for(int i=0;i<v;i++){
		if(edge[i][i]<0){
			cout<<"NEGATIVE CYCLE"<<endl;
			return 0;
		}
	}
	for(int i=0;i<v;i++){
		for(int j=0;j<v;j++){
			if(j)	cout<<" ";
			if(i==j)	cout<<0;
			else if(edge[i][j]>=INF)	cout<<"INF";
			else 	cout<<edge[i][j];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1236
using System;
using System.Linq;

namespace _0549
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] sums = new int[x[0]]; int now = 0;
            for (int i = 1; i < x[0]; i++)
            {
                now += int.Parse(Console.ReadLine());
                sums[i] = now;
            }
            int ret = 0; int back = 0;
            for (int i = 0; i < x[1]; i++)
            {
                int a = int.Parse(Console.ReadLine());
                ret += Math.Abs(sums[back] - sums[back + a]);
                ret %= 100000;
                back += a;
            }
            Console.WriteLine(ret);
        }
    }
}


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

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  rep(i, H){
    cin >> S.at(i);
  }
  int count = 0;
  vector<int> dx = {1,1,0,-1,-1,-1,0,1};
  vector<int> dy = {0,1,1,1,0,-1,-1,-1};
  
  rep(i, H){
    rep(j, W){
      if(S.at(i).at(j) == '.'){
        rep(k, 8){
          if(0 <= i+dx.at(k) && i+dx.at(k) < H && 0 <= j+dy.at(k) && j+dy.at(k) < W){
            if(S.at(i+dx.at(k)).at(j+dy.at(k)) == '#'){
              count++;
            }
          }
        }
        S.at(i).at(j) = '0' + count;
        count = 0;
      }
    }
  }
  
  rep(i, H){
    cout << S.at(i) << endl;
  }
}

Measured memory_bytes: 256
A, B, C = split(readline())
A, B, C = parse(Int, A), parse(Int, B), parse(Int, C)
v = [A, B, C]
X = [0. 1. 1.; 1. 0. 1.; 1 1 0.]

i = 0
v = [A, B, C]
v0 = [A, B, C]
if any(x->x==1, v % 2)
    print(0)
else
    while true
        v = X * v
        if any(x->x==1, v % 2)
            print(i)
            break
        end
        v *= 0.5
        if v[1] == v0[1] && v[2] == v0[2] || v[1] == v0[1] && v[2] == v0[2] || v[1] == v0[1] && v[2] == v0[2]
            print(-1)
            break
        end
        i+=1
    end
end

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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define FOR_EX(i, a, b) for (int i = a; i < b; i++)
#define FOR_IN(i, a, b) for (int i = a; i <= b; i++)

#define ALL(a) a.begin(), a.end()

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    int n;
    cin >> n;
    int a[3 * n];
    FOR_EX(i, 0, 3 * n) {
        cin >> a[i];
    }
    sort(a, a + 3 * n);
    reverse(a, a + 3 * n);
    long long sum = 0;
    int i = 1;
    while (n) {
        sum += a[i];
        i += 2;
        n--;
    }
    cout << sum << endl;
}


Measured memory_bytes: 1408
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int[]a = new int[N];
			int[]b = new int[N];
			
			for(int i = 0;i<N;i++) {
				a[i] = scan.nextInt();
				b[i] = a[i]-i-1;
			}
			
			Arrays.sort(b);
			
			long min = Long.MAX_VALUE;
			long goukei = 0;
			
			if(b.length%2==1) {//奇数
				int B = b[b.length/2];
				for(int i = 0;i<N;i++) {
					goukei+=Math.abs(b[i]-B);
				}
				
				System.out.println(goukei);
			}else {
				long goukei1 = 0;
				int b1 = b[(b.length/2)-1];
				int b2 = b[b.length/2];
				
				for(int i = 0;i<N;i++) {
					goukei+=Math.abs(b[i]-b1);
				}
				
				for(int i = 0;i<N;i++) {
					goukei1+=Math.abs(b[i]-b2);

				}
				System.out.println(goukei<goukei1?goukei:goukei1);
				
			}
			
			
			
			
			
			
			
			
		}
	}
}


Measured memory_bytes: 65576
#include <stdio.h>

int main() {
  int a,b,c,d;
  scanf("%d %d %d %d", &a,&b,&c,&d);
  int e = a - c;
  e = e < 0 ? -1 * e : e;
  if(e <= d) {
    printf("Yes\n");
    return 0;
  }
  int f = a - b;
  f = f < 0 ? -1 * f : f;
  if(f > d) {
    printf("No\n");
    return 0;
  }
  int g = b - c;
  g = g < 0 ? -1 * g : g;
  if(g <= d) {
    printf("Yes\n");
    return 0;
  }
  printf("No\n");
  return 0;
}


Measured memory_bytes: 128
exception Not_equal of int

let rank = Array.make 1000001 0
let tmp = Array.make 1000001 0

let cmp_sa rank a b n k =
  if rank.(a) <> rank.(b) then compare rank.(a) rank.(b)
  else
    compare
      (if a + k <= n then rank.(a+k) else (-1))
      (if b + k <= n then rank.(b+k) else (-1))

let construct_sa t n =
  let sa = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    sa.(i) <- i;
    rank.(i) <- Char.code t.[i];
  done;
  sa.(n) <- n;
  rank.(n) <- (-1);
  let rec doit k =
    if k > n then ()
    else begin
      Array.fast_sort (fun a b -> cmp_sa rank a b n k) sa;
      tmp.(sa.(0)) <- 0;
      for i = 1 to n do
        tmp.(sa.(i)) <-
          tmp.(sa.(i-1)) + (if cmp_sa rank sa.(i-1) sa.(i) n k = (-1) then 1 else 0);
      done;
      for i = 0 to n do rank.(i) <- tmp.(i) done;
      doit (2 * k)
    end in
  doit 1;
  sa

let range_cmp t n offset p k =
  let m = n - offset in
  let m = if m < k then m else k in
  try
    for i = 0 to m - 1 do
      if t.[i+offset] <> p.[i] then
        raise (Not_equal (compare t.[i+offset] p.[i]));
    done;
    if m = k then 0
    else (-1)
  with Not_equal i -> i

let () =
  let t = read_line () in
  let n = String.length t in
  let sa = construct_sa t n in
  let q = read_int () in
  for _ = 0 to q - 1 do
    let p = read_line () in
    let k = String.length p in
    let rec doit l r =
      if r - l <= 1 then l
      else
        let m = (l + r) / 2 in
        if range_cmp t n sa.(m) p k <= 0 then doit m r
        else doit l m in
    let l = doit 0 (n + 1) in
    Printf.printf "%d\n" (if range_cmp t n sa.(l) p k = 0 then 1 else 0);
  done

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

using namespace std;
typedef long long ll;

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

    vector<vector<ll>> a(n , vector<ll>(2));

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

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

    ll ans = 0, cnt = 0;
    for(int i=0; i<n; i++){
        int addNum = min(a[i][1], m - cnt);
        ans += a[i][0] * addNum;
        cnt += addNum;
        if(addNum == m) break;
    }

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

Measured memory_bytes: 5760
import java.util.Scanner;
import java.util.Queue;
import java.util.ArrayDeque;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = Long.parseLong(sc.next());
    Queue<Long> queue = new ArrayDeque<>();
    queue.add(h);
    Long vital;
    Long sum = 0L;
    Long base = 1L;
    while(!queue.isEmpty()){
      vital = queue.poll();
      sum+=base;
      base*=2;
      if(vital>1){
        queue.add(vital/2);
      }
    }
    System.out.print(sum);
    System.out.flush();
  }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
int q;
cin >> q;
vector<pair<ll,ll>>che(q);
ll ma = 0;
for(int i=0;i<q;i++){
    ll r,l;
    cin >> l >> r;
    che.at(i)=make_pair(l,r);
    ma = max({ma,r,l});
}
vector<ll>a(ma+1,0);
for(int i=1;i<ma+1;i++){
    if(primecheck(i)&&primecheck((i+1)/2)&&i%2!=0){
        a.at(i)=a.at(i-1)+1;
        continue;
    }
    a.at(i)=a.at(i-1);
}
for(int i=0;i<q;i++){
    ll ans = a.at(che.at(i).second)-a.at(che.at(i).first-1);
    cout << ans << endl;
}
}





Measured memory_bytes: 3452
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007

int main(){
    ll i,j,k,sum=0,flag=0,t,m,n,b,c,x,y,u,v,trc=0,row,col,l=0,lst;
 // string s1,s2,s;
   cin>>i>>j>>k;
   cout<<k<<" "<<i<<" "<<j<<endl;
       
    
	return 0;
}


Measured memory_bytes: 256
n=int(input())
li=[]
for i in range(n):
    a,b=map(int,input().split())
    li.append([b,a])
    
li.sort()
y="Yes"
sum=0
for i in range(len(li)):
    sum+=li[i][1]
#    print(sum,li[i][0])
    if li[i][0]<sum:
        y="No"
        break
        
print(y)

Measured memory_bytes: 35608
N = int(input())
ls = []
for i in range(N):
  a = input()
  ls.append(a)
AC,WA,TLE,RE = ls.count("AC"), ls.count("WA"), ls.count("TLE"), ls.count("RE")
print(f"AC x {AC}\nWA x {WA}\nTLE x {TLE}\nRE x {RE}")

Measured memory_bytes: 16292
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
  int N;
  cin >> N;
  ll mod = 1e9 + 7;
  ll num[66];
  for (int i = 0; i < 66; i ++) num[i] = 0;
  for (int i = 0; i < N; i ++) {
    ll A;
    cin >> A;
    for (int j = 0; j < 60; j ++) {
      num[j] += A % 2;
      A /= 2;
    }
  }
  ll ans = 0;
  ll bi = 1;
  for (int i = 0; i < 60; i ++) {
    ll kj = num[i] * (N - num[i]);
    kj %= mod;
    kj *= bi;
    kj %= mod;
    ans += kj;
    ans %= mod;
    bi *= 2;
    bi %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3584