akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE FlexibleContexts #-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Arrow
-- import Control.Comonad
import Data.Maybe
import Data.List
import Data.Bool
import Data.Fixed
import Data.Tuple
import Data.Ratio
import Text.Printf
import qualified Data.Map.Strict as M
import qualified Data.Array.IO as IA
import qualified Data.Vector as V
 
getI = read <$> getLine :: IO Int
getIs = map read . words <$> getLine :: IO [Int]
getD = read <$> getLine :: IO Double
getDs = map read . words <$> getLine :: IO [Double]
getInt = read <$> getLine :: IO Integer
getInts = map read . words <$> getLine :: IO [Integer]
 
type Row = Integer
type Col = Integer
type PointI = (Integer, Integer)
type Point = (Int, Int)
 
mmm = 1000000007
fact n
    | n < 1 = 1
    | True = foldr1 (*) [1..n]
fi = fromInteger
fig = fromIntegral
rf = realToFrac
 
(.<.) f g -- combination
    | f < g = 0 
    | g < 1 || f < 1 = 1
    | True = foldr1 (*) (take g [f,f-1..]) `div` fact g
(.>.) f g --combination with repetition
    | g < 1 || f < 1 = 1
    | True = fact (f + g - 1) `div` (fact (f - 1) * fact g)
comb = (.<.)
combWp = (.>.)
 
unique a = unique_ (reverse . sort $ a) [] Nothing
    where
        unique_ [] arr _ = arr
        unique_ (x:xs) arr n
            | n == Just x = unique_ xs arr n
            | otherwise = unique_ xs (x:arr) $ Just x
 
zeroume keta num
    | (length . show $ num) > keta = show num
    | otherwise = do 
        let zeros = take keta $ repeat '0'
        reverse . take keta $ (reverse . show $ num) ++ zeros
 
i2b num
    | num < 2 = show num
    | otherwise = i2b_ num []
        where
            i2b_ num str
                | num == 0 = str
                | num == 1 = '1':str
                | otherwise = do
                    let next = num `div` 2
                    let this = if odd num then '1' else '0'
                    i2b_ next (this:str)
 
mapIncr = mapPlus 1
mapPlus n Nothing = Just n
mapPlus n a = (+) n <$> a
 
countIf f = length . filter f
 
-- 
--
--

main = do
  [x1,y1,x2,y2] <- getIs
  let ydiff = x2 - x1
      xdiff = y1 - y2
  printf "%d %d %d %d\n" (x2 + xdiff) (y2 + ydiff) (x1 + xdiff) (y1 + ydiff)


Measured memory_bytes: 508
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimise ("ofast")
#pragma GCC optimise("unroll-loops")
#define int long long

using namespace std;

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

const int N = 200000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000000;
const ll LOG = 25;

int n, m, s, t, dis[2][N], dp[2][N], ind[N];
vector<pii> G[N];
vector<int> g[N];

void DJ(int v, int id){
	memset(dis[id], 31, sizeof dis[id]);
	dis[id][v] = 0;
	set<pii> st;
	st.insert({0, v});
	while (st.size()){
		pii fr = *st.begin();
		st.erase(st.begin());
		for (auto u:G[fr.S]){
			if (dis[id][u.F] > fr.F + u.S){
				st.erase({dis[id][u.F], u.F});
				dis[id][u.F] = fr.F + u.S;
				st.insert({dis[id][u.F],  u.F});
			}
		}
	}
}

bool cmp(int x, int y){
	return dis[0][x] < dis[0][y];
}

bool cmp2(int x, int y){
	return dis[1][x] < dis[1][y];
}

void calc(int id){
	for (int i = 1; i <= n; i++){
		g[i].clear();
	}
	for (int i = 1; i <= n; i++){
		for (auto u:G[i]){
			if (dis[id][u.F] == dis[id][i] + u.S) {g[i].pb(u.F);}
		}
	}
	for (int i = 1; i <= n; i++) ind[i] = i;
	if (id == 0){
		sort(ind + 1, ind + n + 1, cmp);
	}else{
		sort(ind + 1, ind + n + 1, cmp2);
	}
	//cout << ind[1] << '\n';
	dp[id][ind[1]] = 1;
	for (int i = 1; i <= n - 1; i++){
		for (auto u:g[ind[i]]){
			//cout << ind[i] << ' ' << u << '\n';
			dp[id][u] += dp[id][ind[i]];
			dp[id][u] %= MOD;
		}
	}
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m >> s >> t;
	for (int i = 1; i <= m; i++){
		int v, u, w;
		cin >> v >> u >> w;
		G[v].pb({u, w});
		G[u].pb({v, w});
	}
	DJ(s, 0);
	DJ(t, 1);
	calc(0);
	calc(1);
	int sm  = dis[0][t];
	//cout << dp[0][t] << ' ' << dp[1][s] << '\n';
	ll ans = dp[0][t] * dp[0][t] % MOD;
	//cout << ans << '\n';
	for (int i = 1; i <= n; i++){
		if (dis[0][i] * 2 == sm && dis[1][i] * 2 == sm){
			//cout << "YES" << 
			ans -= (dp[0][i] * dp[0][i] % MOD) * 1ll * (dp[1][i] * dp[1][i] % MOD) % MOD;
			ans %= MOD;
			ans += MOD;
			ans %= MOD;
		}
		for (auto u:G[i]){
			if (dis[0][i] * 2 < sm && (dis[0][i] + u.S) * 2 > sm){
				//cout << "YES" << i << ' ' << u.F << '\n';
				if (dis[0][i] + dis[1][u.F] + u.S == sm){
					ans -= (dp[0][i] * dp[0][i] % MOD) * 1ll * (dp[1][u.F] * dp[1][u.F] % MOD) % MOD;
					ans %= MOD;
					ans += MOD;
					ans %= MOD;
				}
			}
		}
	}
	cout << ans;




	return 0;
}


Measured memory_bytes: 33008
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		Scanner scan = new Scanner(System.in);
		char[] str = new char[1200];
		int[] count = new int[26];
		int temp;
		
		
		while (scan.hasNext()) {
			// 入力
			str = scan.next().toCharArray();
			
			// 文字を数える
			for (int i = 0; i < str.length; i++) {
				temp = str[i]-'a' < 0 ? str[i]-'A' : str[i]-'a';
				if (temp >= 0 && temp <= 25) count[temp]++;
			}
		}			
		
		// 出力
		for (int i = 0; i < count.length; i++) {
			System.out.println((char)(i+'a') + " : " + count[i]);
		}
	}
}



Measured memory_bytes: 26336
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll fact[100010], invfact[100010];
ll n,k;
vector<int> E[100000];
ll extgcd(ll a, ll b, ll& x, ll&y){
    ll d=a;
    if(b!=0){
        d=extgcd(b, a%b, y, x);
        y-=(a/b)*x;
    }
    else {
        x=1; y=0;
    }
    return d;
}
ll mod_inverse(ll a, ll m=MOD){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}
ll dfs(int cur, int par){
    if(par==-1){
        ll ans=1;
        for(auto &to: E[cur]){
            ans*=dfs(to, cur);
            ans%=MOD;
        }
        ll t=sz(E[cur])+1;
        if(t>k) return 0;
        ans*=fact[k]*invfact[k-t]%MOD;
        ans%=MOD;
        return ans;
    }
    else{
        if(sz(E[cur])==1){
            return 1;
        }
        ll ans=1;
        for(auto &to: E[cur]){
            if(to!=par){
                ans*=dfs(to, cur);
                ans%=MOD;
            }
        }
        ll t=sz(E[cur])-1;
        if(k<=2) return 0;
        if(k-2<t) return 0;
        ans*=fact[k-2]*invfact[k-2-t]%MOD;
        ans%=MOD;
        return ans;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    rep(i,0,n-1){
        int a,b;
        cin>>a>>b;
        a--; b--;
        E[a].pb(b); E[b].pb(a);
    }
    fact[0]=1; invfact[0]=1;
    rep(i,1,k+1){
        fact[i]=fact[i-1]*i%MOD;
        invfact[i]=mod_inverse(fact[i]);
    }
    cout <<dfs(0,-1)<<"\n";
}

Measured memory_bytes: 11648
#include<iostream>
#include<string>
#include<vector>
using namespace std;

int main(){
	string a,b;
	vector<int> sum;
	int al, bl, sl;
	int n, up, num;
	cin >> n;
	for(int i=0;i<n;++i){
		cin >> a >> b;
		al = a.size()-1;
		bl = b.size()-1;
		up = 0;
		while(al >= 0 || bl >= 0){
			num = up;
			if(al>=0) num += a[al] - 48;
			if(bl>=0) num += b[bl] - 48;
			if(num > 9){
				sum.push_back(num - 10);
				up = 1;
			}else{
				sum.push_back(num);
				up = 0;
			}
			al -= 1;
			bl -= 1;
		}
		if(up == 1){
			sum.push_back(1);
		}
		sl = sum.size();
		if(sl > 80){
			cout << "overflow" << endl;
		}else{
			for(int j=sl-1;j>=0;--j){
				cout << sum[j];
			}
			cout << endl;
		}
		sum.clear();
	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#define INF 0x3fffffff
#define MAXCF 10
int n,ans=INF;
int main() {
	scanf("%d",&n);
	for(int i=0;i<=n;i+=9) {
		int j=(n-i)/6*6,k=n-i-j;
		int tmpi=i,tmpj=j,cnti=0,cntj=0;
		while(tmpi) cnti+=tmpi%9,tmpi/=9;
		while(tmpj) cntj+=tmpj%6,tmpj/=6;
		int tmp=cnti+cntj+k;
		if(tmp<ans) ans=tmp;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = 0;
        for(int i = 0;i < 4;i++){
            if(s.charAt(i) == '+'){
                ans++;
            }
            if(s.charAt(i) == '-'){
                ans--;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
ll n, c;
ll bestL[maxn], bestR[maxn], x[maxn], v[maxn];

int main(){
    cin.tie(0);
    cin.sync_with_stdio(0);
    cin >> n >> c;
    for(int i = 1; i <= n; i++){
        cin >> x[i] >> v[i];
    }
    bestL[0] = bestR[n+1] = 0;
    ll cur = 0;
    for(int i = 1; i <= n; i++){
        cur += v[i];
        bestL[i] = max(cur - x[i], bestL[i-1]);
    }   
    cur = 0;
    for(int i = n; i > 0; i--){
        cur += v[i];
        bestR[i] = max(cur - (c - x[i]), bestR[i+1]);
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        ans = max(ans, bestL[i]);
        ans = max(ans, bestR[i]);
        ans = max(ans, bestL[i] - x[i] + bestR[i+1]);
        ans = max(ans, bestR[i] - (c - x[i]) + bestL[i-1]);
    }
    cout << ans;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
#define All(x) (x).begin(),(x).end()
#define RAll(x) (x).rbegin(),(x).rend()


int main(){
	int K, N;
	cin >> K >> N;
	vector<int> A(N);
	for(auto &a : A) cin >> a;
	int ans = INT_MAX;
	for(int i=0;i<N;i++) {
		// i -> N-1+i
		if(N-1+i >= N) {
			ans = min(ans, A[(N-1+i)%N]+K-A[i]);
		} else{
			ans = min(ans, A[N-1+i] - A[i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;

int main()
{

	int N;
	cin >> N;

	string S[N];
	set<string> gachas;
	for (int i = 0; i < N;i++){
		cin >> S[i];
		gachas.insert(S[i]);
	}
	
	
	cout << gachas.size() << endl;
	return 0;

}

Measured memory_bytes: 25464
#include <stdio.h>
#include <math.h>
int main(){
  int i,n;
  double xa,ya,xb,yb,ra,rb;

  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%lf %lf %lf %lf %lf %lf",&xa,&ya,&ra,&xb,&yb,&rb);
    double d=sqrt(pow((xa-xb),2)+pow((ya-yb),2));
    if (d<ra-rb)
      printf("2\n");
    else if (d<rb-ra)
      printf("-2\n");
    else if (d>ra+rb)
      printf("0\n");
    else
      printf("1\n");
  }
  return 0;
}

Measured memory_bytes: 620
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int A, B;


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

    int ans = -1;
    repe(x, 1, 1250)
        if(x*8/100 == A and x/10 == B){ ans = x; break; }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
s = gets.chomp
ss = s.gsub(/x/, "")
if ss[0...(ss.size+1)/2] != ss.reverse[0...(ss.size+1)/2]
  puts -1
  exit
end

xs = []
s += "@"
i = 0
while i < s.size && j = s.index(/[^x]/, i)
  xs << (j - i)
  i = j+1
end
#p s, xs

puts (0...xs.size/2).reduce(0){ |a,i| a += (xs[i]-xs[-1-i]).abs  }




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

#include <vector>
using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)

typedef long long ll;

struct UnionFind {
    vector<int> d;
    UnionFind(int n = 0) : d(n, -1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};

int main() {
    int N, M;
    cin >> N >> M;
    // vector<set<int>> friends(N);
    UnionFind uf(N);
    rep(i, M) {
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        uf.unite(A, B);
        // friends[A].insert(B);
        // friends[B].insert(A);
    }
    int ans = -1;
    rep(i, N) {
        // ans = max(ans, (int)friends[i].size() + 1);
        ans = max(ans, uf.size(i));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4028
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define INF (INT_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

bool validate(int a[], int n){
  for(int i = 0; i + 1 < n; i++){
    if(a[i] > a[i + 1]){
      return false;
    }
  }
  return true;
}

void check(int a[], int n, int x[], int y[], int m){
  int b[n];
  for(int i = 0; i < n; i++){
    b[i] = a[i];
  }
  for(int i = 0; i < m; i++){
    b[y[i]] += b[x[i]];
  }
  if(validate(b, n)){
    cerr << "valid" << endl;
  }
  else{
    cerr << "invalid" << endl;
  }
}

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

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

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

  int y[2 * n - 1], x[2 * n - 1];
  int sp = 0;
  if(abs(a[ma]) >= abs(a[mi])){
    for(int i = 0; i < n; i++){
      y[sp] = i;
      x[sp] = ma;
      ++sp;
    }
    for(int j = 0; j < n - 1; j++){
      y[sp] = j + 1;
      x[sp] = j;
      ++sp;
    }
  }
  else{
    for(int i = 0; i < n; i++){
      y[sp] = i;
      x[sp] = mi;
      ++sp;
    }
    for(int j = n - 1; j > 0; j--){
      y[sp] = j - 1;
      x[sp] = j;
      ++sp;
    }
  }

  string s;
  s += to_string(2 * n - 1) + "\n";
  for(int i = 0; i < 2 * n - 1; i++){
    s += to_string(x[i] + 1) + " ";
    s += to_string(y[i] + 1) + "\n";
  }

  if(DEBUG){
    check(a, n, x, y, 2 * n - 1);
  }

  cout << s << endl;

  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int k = Integer.parseInt(in.next());
            String S = in.next();
            String tmp1 = S.substring(0, k - 1);
            String tmp2 = S.substring(k);
            Character tmp3 = Character.toLowerCase(S.charAt(k - 1));

            // 出力
            out.println(tmp1 + tmp3 + tmp2);

        }

    }
}



Measured memory_bytes: 21332
#include<stdio.h>
int main(){
    unsigned long ulW_D_inact[100][100];    /* 行列Ａの格納用変数 */
    unsigned long ulW_D_act[100];           /* 行列Ｂの格納用変数 */
    unsigned long ans[100];           /* 積の格納用変数 */
    unsigned short row, col;          /* 行列の要素数の格納用変数 */
    unsigned short i, j;              /* ループ変数 */

    /* 配列の初期化 */
    for(i = 0;i < 100;i++){
        for(j = 0;j < 100;j++){
            ulW_D_inact[i][j] = 0;
        }
        ulW_D_act[i] = 0;
        ans[i] = 0;
    }

    /* 行列の要素数の入力 */
    scanf("%d %d", &row, &col);

    /* 行列Ａの入力 */
    for(i = 0;i < row;i++){
        for(j = 0;j < col;j++){
            scanf("%d", &ulW_D_inact[i][j]);
        }
    }

    /* 行列Ｂの入力 */
    for(i = 0;i < col;i++){
        scanf("%d", &ulW_D_act[i]);
    }

    /* ＡとＢの積の計算 */
    for(i = 0;i < row;i++){
        for(j = 0;j < col;j++){
            /* i番目の積の計算 */
            ans[i] += ulW_D_inact[i][j] * ulW_D_act[j];
        }
    }
    /* 積の出力 */
    for(i = 0;i < row;i++){
        /* i番目の積の出力 */
        printf("%d\n", ans[i]);
    }
    return 0;
}


Measured memory_bytes: 2100
X, Y = map(int, input().split())

def mod_Combination(n, k, mod):
    def ext_gcd(a, b):
        if b == 0:
            return a, 1, 0
        else:
            d,x,y = ext_gcd(b,a%b)
            x-=(a//b)*y 
        return d,y,x
    p,q=1,1
    for i in range(n-k+1, n+1):
        p=(p*i)%mod
    for i in range(2, k+1):
        q=(q*i)%mod
    return int(p*(ext_gcd(q, mod)[1]%mod)%mod)

if X > Y:
    X, Y = Y, X

a = (2*X - Y)/3
b = (2*Y - X)/3

if (X+Y)%3 != 0:
    ans = 0

elif Y > 2*X:
    ans = 0

else:
    ans = mod_Combination(int(a + b), int(a), 10**9 + 7)

print(ans)


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

using namespace std;

typedef long long ll;

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 1LL; i <= n; i += 1LL) {
        ans += i * (n - i + 1LL);
    }
    for (ll i = 1LL; i <= n - 1; i += 1LL) {
        ll a, b;
        cin >> a >> b;
        ans -= (a > b ? b : a) * (n - (a > b ? a : b) + 1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

void func_A(){
    
    int a;
    cin >> a;

    cout << (a + a * a + a * a*a);

}

void func_B() {

    string s, t;
    cin >> s >> t;

    int count = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] != t[i]) count++;
    }

    cout << count;
}

int read(int num, long long *time, vector<unsigned long long> book) {

    int count = 0;
    for (int i = 0; i < num; ++i) {
        *time -= book[i];
        if (*time > 0) {
            ++count;
            continue;
        }
        else break;

    }

    return count;
}

void func_C() {

    int n, m;
    long long k;
    cin >> n >> m >> k;
    vector<unsigned long long> a(n+1), b(m+1);
    int max_a=0, max_b=0;
    for (int i = 1; i <= n; ++i) {
        unsigned long long temp;
        cin >> temp;
        if (i == 1) a[i] = temp;
        else a[i] = temp + a[i - 1];

        if (k >= a[i]) {
            max_a = i;
        }
    }
    for (int i = 1; i <= m; ++i) {
        unsigned long long temp;
        cin >> temp;
        if (i == 1) b[i] = temp;
        else b[i] = temp + b[i - 1];

        if (k >= b[i]) {
            max_b = i;
        }
    }
    
    int count = max_a + max_b;
    int cnt = 0;
    for (; count >= 0; --count, ++cnt) {
        long long time = k;
        unsigned long long cost = pow(10, 10);

        if (cnt == 0) time -= a[max_a] + b[max_b];
        else {
            for (int i = 0; i <= cnt; ++i) {
                unsigned long long temp;
                if (max_a - i <= 0 || max_b - (cnt - i) <= 0) continue;
                temp = a[max_a - i] + b[max_b - (cnt - i)];
                if (temp < cost) cost = temp;
            }
            time -= cost;
        }

        if (time >= 0) break;
        
    }

    cout << count;
}

void func_Cfix() {

    int n, m;
    long long k;
    cin >> n >> m >> k;
    vector<unsigned long long> a(n+1), b(m+1);
    a[0] = 0;
    b[0] = 0;
    for (int i = 1; i <= n; ++i) {
        unsigned long long temp;
        cin >> temp;
        if (i == 1) a[i] = temp;
        else a[i] = temp + a[i - 1];

    }
    for (int i = 1; i <= m; ++i) {
        unsigned long long temp;
        cin >> temp;
        if (i == 1) b[i] = temp;
        else b[i] = temp + b[i - 1];

    }

    int ans = 0;
    int j = m;
    for (int i = 0; i <= n; ++i) {
        if (a[i] > k) break;

        while (a[i] + b[j] > k) --j;

        ans = (ans > i + j) ? ans : i + j;
    }

    cout << ans;


}

int main() {

    //func_A();
    //func_B();
    func_Cfix();

    return 0;
}

Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
long long i[11110][11111];
long long ii[11111]={};
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=0,h=0,j=0;
  string s;
  cin >>s;
  if(s[0]=='1') d++;
  if(s[1]=='1') d++;
  if(s[2]=='1') d++;
  cout <<d<<'\n';
  return (0);
}


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define pb push_back
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

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

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, T;
    cin >> n >> T;
    int ans = INF;
    int c[n], t[n];
    rep(i, n){
        cin >> c[i] >> t[i];
    }

    rep(i, n){
        if(t[i] <= T){
            ans = min(ans, c[i]);
        }
    }

    if(ans == INF){
        ppp("TLE");
    }
    else{
        ppp(ans);
    }



    return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    int32 a[n];
    int64 alternatingSum = 0;
    REP(i,n){
        cin >> a[i];
        alternatingSum += ((i % 2 == 0)?1:-1) * a[i];
    }
    int64 x = alternatingSum / 2;
    cout << x * 2;
    FOR(i,1,n){
        x = a[i-1] - x;
        cout << " " << x * 2;
    }
    cout << endl;
    return 0;
}

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

using namespace std;

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    int i = 0;
    while(i+2 < n) {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') {
            cnt++;
            i += 3;
        } else {
            i++;
        }
    }    
    cout << cnt << "\n";
}

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

using namespace std;

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

  int x = 0, ans = x;
  for (int i = 0; i < N; ++i) {
    if (S[i] == 'I') x++;
    else x--;
    ans = max(ans, x);
  }

  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,X,T,m,l;
  cin>>N>>X>>T;
  m=N/X;
  l=N%X;
  if(l>0)
    m++;
  cout<<m*T<<endl;
  return 0;
  
}

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

using ll = long long;

int path(int x, int y) {
  return abs(x - y);
}

int ans[2010];
int main () {
  int n, x, y;
  scanf("%d %d %d", &n, &x, &y);
  for(int i = 1; i <= n; i++) {
    for(int j = i + 1; j <= n; j++) {
      int c = abs(i - j);
      c = min(c, abs(i - x) + 1 + abs(y - j));
      c = min(c, abs(i - y) + 1 + abs(x - j));
      ans[c]++;
    }
  }
  for(int k = 1; k < n; k++)
    printf("%d\n", ans[k]);
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
 
const int mx = 55;
char ss[mx], * endS = "FESTIVAL";
 
int main(){
    cin >> ss;
    ss[strlen(ss) - strlen(endS)] = '\0';
    cout << ss << endl;
    return 0;
}

Measured memory_bytes: 256
from heapq import *

n = int(input())
v_list = list(map(int, input().split()))
heapify(v_list)

while 1 < len(v_list):
    item = (heappop(v_list)+heappop(v_list))/2
    heappush(v_list, item)

print(v_list[0])

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

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

void solve() {
  int N, ans = 0;
  string S;
  cin >> N >> S;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        int flag_i = -1;
        int flag_j = -1;
        for (int l = 0; l < N; l++) {
          int c = (int)(S[l] - '0');
          if (flag_i == -1 && c == i) {
            flag_i = l;
          } else if (flag_j == -1 && flag_i >= 0 && c == j) {
            flag_j = l;
          } else if (flag_j >= 0 && c == k) {
            ans++;
            break;
          }
        }
      }
    }
  }
  cout << ans << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/rope>

using namespace std;

#pragma GCC optimize("03")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define arctan atan
#define arccos acos
#define arcsin asin
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define vt vector
#define pr pair
#define u_map unordered_map
#define endl "\n"
typedef double db;			typedef long long ll;		typedef long double ld;			typedef string str;
typedef pr<int, int> pii;	typedef pr<ll,ll> pll;		typedef pr<ld,ld> pdd;
typedef vt<int> vi;			typedef vt<ll> vll;			typedef vt<bool> vb;
typedef vt<str> vs;			typedef vt<pii> vpii;		typedef vt<pll> vpll;
typedef map<int, int> mii;	typedef map<int, bool> mib;	typedef map<int, str> mis;		typedef map<int, char> mic;
typedef complex<db> cpx;	typedef vt<cpx> vcpx;
ll f(ll x)
{
	if (x < 1) return 0LL;
	ll res[] = {x,1,x+1,0};
	return res[x%4LL];
}

ll xor_range(ll a, ll  b)
{
	return (f(b) ^ f(a-1));
}
void input()
{
	ll l,r;
	cin >> l >> r;
	cout << xor_range(l,r);
}

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	input();
	return 0;
}

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

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

int dy[] = {0,1,0,-1};
int dx[] = {1,0,-1,0};
int dy8[] = {0,1,1,1,0,-1,-1,-1};
int dx8[] = {1,1,0,-1,-1,-1,0,1};

/*==================================================*/
/*variable*/
int N,A,B;
ll V[55];
map<ll, ll> m;
ll cmb[55][55];
/*==================================================*/
/*function*/
/*==================================================*/

int main() {
    cin>>N>>A>>B;
    REP(i,0,N) cin>>V[i], m[V[i]]++;

    cmb[0][0] = cmb[1][0] = cmb[1][1] = 1;
    REP(i,2,55){
        REP(j,0,i+1){
            if(j == 0 || j == i){
                cmb[i][j] = 1;
            }else{
                cmb[i][j] = cmb[i-1][j-1] + cmb[i-1][j];
            }
        }
    }

    sort(V, V+N);
    pair<ll, ll> mx = make_pair(1,1);
    pair<pair<ll, ll>, ll> ans[55]; //合計, 選択数, 組み合わせ

    REP(r,A,B+1){
        long long sum = 0.0;
        ll c = 1;
        set<int> st;
        RREP(i,N-r,N){
            sum += V[i];
            if(st.find(V[i]) == st.end()){
                st.insert(V[i]);
                c *= cmb[m[V[i]]][min(m[V[i]], (ll)(i-(N-r)+1))];
            }
        }
        ans[r-A] = make_pair(make_pair(sum, r), c);
        if(mx.F*ans[r-A].F.S < mx.S*ans[r-A].F.F){
            mx = make_pair(ans[r-A].F.F, ans[r-A].F.S);
        }
    }

    ll cnt = 0;
    REP(i,0,B-A+1){
        if(mx.F*ans[i].F.S == mx.S*ans[i].F.F){
            cnt += ans[i].S;
        }
    }

    cout.precision(7);
    cout<<fixed<<((double)mx.F / (double)mx.S)<<endl;
    cout<<cnt<<endl;

    return 0;
}


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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

vector<ll> pos;
vector<ll> poss;
vector<ll> neg;
vector<ll> negg;
ll n,k;

bool check(ll x) {
    ll ans = 0;

    //neg neg
    //int tmp = 0;
    for(int i = 0; i < neg.size(); i++) {
        ll l = i+1;
        ll r = negg.size()-1;

        while(l <= r) {
            ll mid = (l+r) >> 1;
            if(negg[i] * negg[mid] > x) r = mid-1;
            else l = mid+1;
        }

        while(l > negg.size()-1) l--;
        while(l > i and negg[i]*negg[l] > x) l--;
        ans += max(0ll, l-i);
        //tmp += max(0ll,l-i);
    }

    //cout << "neg neg " << tmp << endl;
    //tmp = 0;


    //neg pos
    for(int i = 0; i < neg.size(); i++) {
        ll l = 0;
        ll r = poss.size()-1;

        while(l <= r) {
            ll mid = (l+r) >> 1;
            if(neg[i] * poss[mid] > x) r = mid-1;
            else l = mid+1;
        }

        while(l > poss.size()-1) l--;
        while(l >= 0 and neg[i]*poss[l] > x) l--;
        ans += max(0ll, l+1);
        //tmp += max(0ll,l+1);
    }
    //cout << "neg pos " << tmp << endl;
    //tmp = 0;

    //pos pos
    for(int i = 0; i < pos.size(); i++) {
        ll l = i+1;
        ll r = pos.size()-1;

        while(l <= r) {
            ll mid = (l+r) >> 1;
            if(pos[i] * pos[mid] > x) r = mid-1;
            else l = mid+1;
        }

        while(l > pos.size()-1) l--;
        while(l > i and pos[i]*pos[l] > x) l--;
        ans += max(0ll, l-i);
        //tmp += max(0ll, l-i);
    }

    //cout << "pos pos " << tmp << endl;
    //cout << x << " " << ans << " " << " " << k << " " << (ans >= k) << endl;

    return (ans >= k);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> k;

    for(int i = 0; i < n; i++) {
        ll x; cin >> x;
        if(x >= 0) { pos.pb(x), poss.pb(x); }
        else { neg.pb(x), negg.pb(x); }
    }

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

    sort(poss.begin(), poss.end());
    reverse(poss.begin(), poss.end());

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

    sort(negg.begin(), negg.end());
    reverse(negg.begin(), negg.end());

    ll l = -1e18 + 5;
    ll r = 1e18 + 5;
    ll ans = 0;

    while(l <= r) {
        ll mid = (l+r) >> 1;
        if(check(mid)) ans = mid, r = mid-1;
        else l = mid+1;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3720
// https://atcoder.jp/contests/abc120/tasks/abc120_d

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <regex>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }
struct UnionFind {
    vector<int> par; // 親の番号
    UnionFind(int size) : par(size, -1) {}
    // xとyの木を併合
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (par[y] < par[x])
                swap(x, y);
            par[x] += par[y];
            par[y] = x;
            return true;
        } else {
            return false;
        }
    }
    // 2つのデータx, yが属する木が同じならtrueを返す
    bool same(int x, int y) { return root(x) == root(y); }
    // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    int root(int x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
    // 頂点 v が属するグループと同じグループに属する頂点数を得る
    int size(int x) { return -par[root(x)]; }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m, t1, t2;
    cin >> n >> m;
    vector<ll> ans, a, b;

    for (int i = 0; i < m; i++) {
        cin >> t1 >> t2;
        a.push_back(--t1);
        b.push_back(--t2);
    }
    reverse(ALL(a));
    reverse(ALL(b));
    UnionFind tree(n);

    ll cur = n * (n - 1) / 2;
    for (int i = 0; i < m; i++) {
        ans.push_back(cur);
        if (!tree.same(a[i], b[i])) {
            t1 = tree.size(a[i]);
            t2 = tree.size(b[i]);
            cur -= t1 * t2;
            tree.unite(a[i], b[i]);
        }
    }
    reverse(ALL(ans));
    for (auto x : ans) {
        cout << x << '\n';
    }

    return 0;
}

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

int main(){
  int k,n,sum=0; cin >>k >>n;
  vector<int>a(n);
    for(int i=0; i<n; i++)
    {int p; cin >>p; a[i]=p;}
  vector<int>b(n-1);
    for(int i=0; i<n-1; i++)
    {b[i]=a[i+1]-a[i];} 

  sort(b.begin(), b.end());
  cout <<k-max(b[n-2],k+a[0]-a[n-1]);

return 0;
}

Measured memory_bytes: 1792
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

void solve() {
	int n;
	cin >> n;
	int cnt = 0;
	REP(i, n) {
		int a, b;
		char c;
		cin >> a >> c >> b;
		if (c == '(') {
			cnt += b;
		}
		else {
			cnt -= b;
		}
		if (cnt == 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

#undef int
int main() {
	init();
	solve();
}


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

int main() {
    int n;
    vector<double> a(60);
    cin >> n;

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

    sort(a.begin(), a.begin()+n);

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

    cout << a[n-1] << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define vv vector < vector < ll > >

using namespace std;
int m=1e9+7;
int s[55][55];
int n;
vv g;

vv mult(vv a , vv b)
{
    vv c=vv(n,vector < ll >(n));
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            c[i][j]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int k=0;k<n;k++)
            {
                c[i][j]+=(a[i][k]*b[k][j])%m;
                c[i][j]%=m;
            }
        }
    }
    return c;
}

vv pow(vv a , ll t)
{
    vv ret=vv(n,vector < ll > (n) );
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            ret[i][j]=(i==j);
        }
    }
    while(t)
    {
        if(t%2)
            ret=mult(a,ret);
        a=mult(a,a);
        t/=2;
    }
    return ret;
}

int main()
{
    ll k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            cin>>s[i][j];
    }
    for(int i=0;i<n;i++)
    {
        vector < ll > t;
        t.clear();
        for(int j=0;j<n;j++)
        {
            t.push_back(s[i][j]);
        }
        g.push_back(t);
    }
    vv a=vv(n,vector < ll > (n));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            a[i][j]=0;
            if(i==0)
                a[i][j]=1;
        }
    }
    vv b=pow(g,k);
    vv ans=mult(a,b);
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        sum+=ans[0][i];
        sum%=m;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#define MAX 500000
 
int num;
void merge(int s[MAX],int left,int mid, int right){
  int i,j,k,n1,n2,L[250002],R[250002];
  n1 = mid - left;
  n2 = right - mid;
  for (i=0;i<n1;i++) L[i]=s[left+i];
  for (i=0;i<n2;i++) R[i]=s[mid+i];
  L[n1]=10000000000;
  R[n2]=10000000000;
  i=0;
  j=0;
  for (k=left;k < right; k++){
   num++;
    if(L[i]<= R[j]){
      s[k]=L[i];
      i++;
    } else {
      s[k]=R[j];
      j++;
    }
  }
}
 
void mergeSort(int s[MAX],int left, int right) {
  int mid;
  if (left+ 1 < right) {
    mid = (left + right)/2;
    mergeSort(s,left,mid);
    mergeSort(s,mid,right);
    merge(s,left,mid,right);
  }
}
 
int main() {
  int n,i,s[MAX];
  num=0;
  scanf("%d",&n);
  for(i = 0; i< n;i++)
    scanf("%d",&s[i]);
  mergeSort(s,0,n);
  for(i=0;i<n-1;i++)
    printf("%d ",s[i]);
  printf("%d\n",s[n-1]);
  printf("%d\n",num);
  return 0;
}

Measured memory_bytes: 5632
#include <iostream>
//#include <bits/stdc++.h>
#include<iomanip>

using namespace std;
#define ll long long int 
#define tezz std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
int main() {
                int n,c,e=0;
                cin>>n;
                cin>>c;
                int i;
                while(n--){
                    int i;
                    cin>>i;
                    e = e + (i>=c);
                }
                cout<<e;
                
                
}

Measured memory_bytes: 256
from itertools import permutations
n,m = map(int,input().split())

li = set()
for i in range(m):
    a,b = map(int,input().split())
    li.add((a,b))
    li.add((b,a))

#print(li)
ans = 0

for v in permutations(range(1,n+1)):
    if v[0] != 1:
        continue
    flag = True
    for i in range(len(v)-1):
        if (v[i],v[i+1]) not in li:
            flag = False
            break
    if flag:
        ans +=1
print(ans)

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



int main(){
  int N;
  cin >> N;
  vector<char> V(N);
  int Rcounter = 0;
  rep(i, N){
    char c;
    cin >> c;
    V[i] = c;
    if(c=='R') Rcounter++;
  }
  int ans = 0;
  rep(i, Rcounter){
    if(V[i]=='W') ans++;
  }
  cout << ans << endl;
  
  
  
}

      
  
  




Measured memory_bytes: 3624
package main

import (
  "fmt"
)
  
func main() {
  var N, M int
  fmt.Scanf("%d %d\n", &N, &M)
 
  var sum int = 0
  for i := 0; i < M; i++ {
    var c int
    fmt.Scanf("%d", &c)
    sum += c
  }
  if sum > N {
    fmt.Println(-1)
    return
  }
  fmt.Println(N - sum)
}

Measured memory_bytes: 2564
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<ll, ll>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    set<P> aa;
    sort(all(a));
    rep(i, n) {
        P now = P(a[i], 1);
        int j = i;
        while(j < n-1 and a[j] == a[j+1]) {
            now.second++;
            j++;
        }
        i = j;
        aa.insert(now);
    }
    int q;
    cin >> q;
    while(q--) {
        int b, c;
        cin >> b >> c;
        auto itr = aa.lower_bound(P(b, 0));
        if((*itr).first == b) {
            sum += (c-b)*(*itr).second;
            P now = *itr;
            aa.erase(itr);
            itr = aa.lower_bound(P(c, 0));
            if((*itr).first == c) {
                P cc = *itr;
                aa.erase(itr);
                cc.second += now.second;
                aa.insert(cc);
            } else {
                now.first = c;
                aa.insert(now);
            }
        }
        cout << sum << endl;
        
    }
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;
int a[5] = {3,5,1,2,4},B[5];
int main(){
	string s;
	cin >> s;
	if(s[3] == '7') s[3] = '8';
	cout << s << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[]Tokyo=new int[10];
        int[]Kyoto=new int[10];

        for (int i=0;i<Tokyo.length;i++) {
            Tokyo[i] = sc.nextInt();
        }

        for (int i =0;i<Kyoto.length;i++){
            Kyoto[i]=sc.nextInt();
        }
        Arrays.sort(Tokyo);
        int tokyo=Tokyo[9]+Tokyo[8]+Tokyo[7];
        Arrays.sort(Kyoto);
        int kyoto=Kyoto[9]+Kyoto[8]+Kyoto[7];
         System.out.println(tokyo+" "+kyoto);
        }

    }

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll K,N;
ll P[101010];
char S[10];

ll i, j, k;

int main(){
    scanf("%lld%lld", &N, &K);
    rep(i,0,N){
        scanf("%lld", &P[i]);
    }
    sort(P, P + N);
    ll ans = 0;
    rep(i,0,K){
        ans += P[i];
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3824
#include <iostream>
using namespace std;
int main(void){
  int N;
  cin >> N;
  int str[N];
  int kaisu = 0;
  bool syuryo = false;
  for(int i = 0; N > i; i++)cin >> str[i];
  while(true){
    for(int i = 0; N > i; i++){
      if(str[i] % 2 == 0){
        str[i] /= 2;
      } else {
        syuryo = true;
        break;
      }
    }
    if(syuryo){
      break;
    }
    kaisu++;
  }
  cout << kaisu << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<random>
#include<math.h>
#include<limits.h>
#include<iterator>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> > 
#define vb vector<bool> 
#define vvb vector<vector<bool> > 
#define INF 1123456789012345
using namespace std;
 
void end(ll n){
	cout << n << endl;
	exit(0);
}
 
int main(){
	ll n, a, b; cin >> n >> a >> b;
	if (a == b) end(1);
	if (n < 2 || a>b) end(0);
	ll ans = (n - 2)*(b - a) + 1;
	end(ans);
	return 0;
}

Measured memory_bytes: 256
#n = int(input())
#h, w = map(int,input().split())
#ls = list(map(int,input().split()))
#ls = [list(map(int,input().split())) for i in range(n)]
#ls = [input() for i in range(h)]
s = input()

if s[0] == "A" and s[2:-1].count("C") == 1:
  ls = list(s)
  ls.remove("A")
  ls.remove("C")
  if str(ls).islower():
    print("AC")
    quit()
print("WA")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> mochi(N);
  for (int i=0; i<N; i++){
    cin >> mochi.at(i);
  }
  int count = 1;
  sort(mochi.begin(), mochi.end());
  int prev = mochi.at(0);
  for (int i=1; i<N; i++){
    if (prev != mochi.at(i)){
      count += 1;
      prev = mochi.at(i);
    }
  }
  cout << count << endl;
}
    

Measured memory_bytes: 256