akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		boolean next = false;
		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = parseInt(line);
			if (n == 0) break;
			
			String[] teams = new String[n];
			int[][] points = new int[n][2];
			for (int i = 0; i < n; i++) {
				StringTokenizer st = new StringTokenizer(br.readLine());
				teams[i] = st.nextToken();
				points[i][0] = i;
				points[i][1] = parseInt(st.nextToken()) * 3 + parseInt(st.nextToken()) * 0 + parseInt(st.nextToken());
			}
			Arrays.sort(points, new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					if (o1[1] == o2[1]) {
						return o1[0] - o2[0];
					} else {
						return o2[1] - o1[1];
					}
				}
			});
			if (next) System.out.println();
			next = true;
			for (int i = 0; i < n; i++) {
				System.out.println(teams[points[i][0]] + "," + points[i][1]);
			}
		}
	}
}

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

// O(NloglogN)
int main(){
    int n;
    cin >> n;
    vector<int> p;
    vector<bool> np(n+5, 0);
    for(int i = 2; i < n+1; i++){
        if(np[i])   continue;
        p.push_back(i);
        for(int j = i+i; j < n+5; j += i)   np[j] = true;
    }
    int ans = 0;
    for(int x : p){
        ans += !np[2+x];
    }
    cout << 2*ans << endl;
    return 0;
}


Measured memory_bytes: 8172
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b;
    cin >> a >> b;
    int right = 0, left = 0;
    for(int i=1; i<1000; i++){
        left = right;
        right += i;
        if(b-a==i){
            cout << left - a << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main (String[] args) throws IOException{
	    InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
	    BufferedReader in = new BufferedReader(reader);
		String[] str = in.readLine().split(" ");
		int X = Integer.parseInt(str[0]);
		int Y = Integer.parseInt(str[1]);
		if((Y-2*X)%2 == 0 && (Y-2*X)/2 >= 0 && X-((Y-2*X)/2) >= 0) {
			System.out.println("Yes");
		}else
			System.out.println("No");
	}
}

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

int main() {
    int N;
    cin >>N;
    vector<ll>data(N);
    for(int i=0;i<N;i++){
        cin >>data[i];
    }
    int mx=0;
    for(int j=0;j<N-1;j++){
        int count =0;
        while(data[j]>=data[j+1]){
            count++;
            j++;
            if(j ==N-1)break;
        }
    mx =max(mx,count);  
}
cout <<mx<<endl;
}

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

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

	int res = N;
	for (int i = 0; i <= N; i++){
		int pre = 0;

		int x = i;
		while (x > 0){
			pre += x%6;
			x /= 6;
		}

		x = N-i;
		while (x > 0){
			pre += x%9;
			x /= 9;
		}

		res = min(res, pre);
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }



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

  char s;
  cin >> s;  

  if(s >= 'A' && s <= 'Z') cout << 'A' << endl;
  else cout << 'a' << endl;
  return 0;
}

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

int32_t main()
{
 ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 int n,k; cin>>n>>k; int A[n];
 for(int i=0;i<n;i++)
 {
     cin>>A[i];
 }
 for(int i=k;i<n;i++)
 {
     if(A[i]>A[i-k]){cout<<"Yes"<<endl;}
     else{cout<<"No"<<endl;}
 }
}


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

typedef long long ll;
typedef pair<ll, ll> PX;
typedef pair<ll, ll> PY;
struct ED {
	ll p1;
	ll p2;
	ll cost;
	ED(ll k1, ll k2, ll k3) : p1(k1), p2(k2), cost(k3) {}
};
const int maxlen = 200005;
PX px[maxlen];
PY py[maxlen];
ll fa[maxlen];
vector<ED> edges;

bool cmp(const pair<ll, ll>& a, const pair<ll, ll>& b) {
	return a.first < b.first;
}

bool cmp_(const ED& e1, const ED& e2) {
	return e1.cost < e2.cost;
}

int getf(int i) {
	return i == fa[i] ? i : fa[i] = getf(fa[i]);
}

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> px[i].first >> py[i].first;
		px[i].second = py[i].second = i;
		fa[i] = i;
	}
	sort(px + 1, px + 1 + n, cmp);
	sort(py + 1, py + 1 + n, cmp);
	for (int i = 1; i < n; i++) {
		edges.push_back(ED(px[i].second, px[i + 1].second, px[i + 1].first - px[i].first));
		edges.push_back(ED(py[i].second, py[i + 1].second, py[i + 1].first - py[i].first));
	}
	sort(edges.begin(), edges.end(), cmp_);
	ll ans = 0;
	for (int i = 0; i < edges.size(); i++) {
		if (getf(edges[i].p1) != getf(edges[i].p2)) {
			ans += edges[i].cost;
			fa[getf(edges[i].p1)] = getf(edges[i].p2);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 13936
#include <stdio.h>
int main(){
  int n, a[100000]={0};
  scanf("%d", &n);
  for(int i=0; i<n; i++){
    scanf("%d", &a[i]);
    a[i]--;
  }
  int cnt=1, idx=0;
  while(cnt <= n){
    if( a[idx] == 1 ){ printf("%d\n", cnt); return 0; }
    cnt++;
    idx = a[idx];
  }
  printf("-1\n");
  return 0;
}

Measured memory_bytes: 2124
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find(all(v), i) != (v).end())
#define ERASE(v,i) (v).erase(remove(all(v), i), (v).end())
#define INDEX(v,i) (find(all(v), i) - (v).begin())
#define rep(i,n) for(int i = 0; i < (int)n; ++i)
#define debug(x) cerr << #x << " = " << (x) << endl;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

const int INF = 100000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

ll factor(ll n) {
	return n == 1 ? 1 : n * factor(n - 1);
}

int main() {
	ll n; cin >> n;
	cout << factor(n) << endl;
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#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 all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 12345678901234567

const int maxn = 1e5 + 10;


//initialization here
//
int n, ma, mb;
int a[50], b[50], c[50];
int dp[50];
//
//initialization finish


// your function is here
//

//
// your function finished



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

	// your code is here
	//

	ll x; cin >> x;

	ll ans = 0;
	ans += (x / 11) * 2;
	if(x%11 !=0)ans += x % 11 <= 6 ? 1 : 2;

	Print(ans);

	//
	// your code finished
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int maxi = min(D,B),mini = max(A,C);
    if(maxi < mini)cout << 0 << endl;
    else    cout << maxi - mini << endl;
}

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

vector<int> bk[10];
vector<int> pr;
int dp[2001];
int n, k;

int main(){
	for(int i = 1; i < 2001; i++) dp[i] = -1;
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++){
		int c, g; scanf("%d%d", &c, &g);
		g--;
		bk[g].push_back(c);
	}
	for(int i = 0; i < 10; i++){
		pr.clear();
		int sum = 0;
		sort(bk[i].begin(),bk[i].end(),greater<int>());
		for(int j = 0; j < bk[i].size(); j++){
			sum += bk[i][j];
			pr.push_back(sum+j*(j+1));
		}
		for(int j = k; j >= 0; j--){
			for(int u = 0; u < pr.size(); u++){
				if(j-u-1<0) break;
				if(dp[j-u-1] == -1) continue;
				dp[j] = max(dp[j],dp[j-u-1]+pr[u]);
			}
		}
	}
	printf("%d\n", dp[k]);
}

Measured memory_bytes: 1088
#include <bits/stdc++.h>
#define per pair <long long , long long>
#define f first
#define se second
using namespace std;
long long x , y , z;
priority_queue <long long , vector <long long> , greater <long long> > pq;
long long solmax, maxx[100005];
per a[100005];
inline bool cmp (per a , per b)
{
    if (a.f - a.se < b.f - b.se)
        return false;
    else if (a.f - a.se == b.f - b.se)
        return (a.f > a.se);
    return true;
}
int main()
{
    //freopen("coins.in" ,"r", stdin);
    //freopen("coins.out" ,"w", stdout);

    scanf("%lld %lld %lld\n", &x, &y, &z);

    long long n = x + y + z;
    long long s = 0LL;
    for (long long i = 1; i<=n; ++i)
    {
        long long c;
        scanf("%lld %lld %lld\n", &a[i].first, &a[i].second, &c);
        a[i].first -= c;
        a[i].second -= c;
        s += c;
    }
    sort(a + 1, a + n + 1, cmp);
    long long sact = 0;
    for (long long i = n; i >= n - y + 1; --i)
    {
        sact += a[i].se;
        pq.push(a[i].se);
    }
    maxx[n - y + 1] = sact;
    for (long long i = n - y; i >= 1; --i)
    {
        if (a[i].se > pq.top())
            sact -= pq.top() , sact += a[i].se ,pq.pop(), pq.push(a[i].se);
        maxx[i] = sact;
    }
    while (!pq.empty())
        pq.pop();
    sact = 0;
    for (long long i = 1; i<=x; ++i)
    {
        sact += a[i].f;
        pq.push(a[i].f);

    }
    solmax = sact + maxx[x + 1];
    for (long long i = x + 1; i <= n - y; ++i)
    {
        if (a[i].f > pq.top())
            sact -= pq.top() , sact += a[i].f ,pq.pop(), pq.push(a[i].f);
        solmax = max(solmax , sact + maxx[i + 1]);
    }
    printf("%lld\n", solmax + s);
    return 0;
}


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

const int N = 11;
int n, m;
bool S[N][N];
int P[N];
int main() {
    cin >> n >> m;
    rep(i, m) {
        int k; cin >> k;
        rep(j, k) {
            int a; cin >> a;
            a--;
            S[i][a]=true;
        }
    }
    rep(i, m) {
        cin >> P[i];
    }

    int ans = 0;
    rep(mask, (1<<n)) {
        int on=0;
        rep(i, m) {
            int cnt = 0;
            rep(j, n) if(S[i][j] && (mask>>j)&1) cnt++;
            if(cnt%2 != P[i]) break;
            on++;
        }
        if(on == m) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
map<int,int>mp;
int main()
{     int n,m,i,j,k,a,sum=0;
      scanf("%d",&n);
      for(i=1;i<=n;i++){
      	scanf("%d",&a);
      	if(!mp[a])sum++,mp[a]=i;
      	  else sum--,mp[a]=0;
      }
      cout<<sum<<endl;
	  return 0;
}


Measured memory_bytes: 4992
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        
        int ans = 0;
        for(int i = 0; i < n; i++) {
            if(isPrime(sc.nextInt())) ans++;
        }

        System.out.println(ans);
    }

    private static boolean isPrime(int x) {
        if(x == 2) return true;
        if(x < 2 || x % 2 == 0) return false;

        int i = 3;
        while(i <= Math.sqrt((int)x)) {
            if(x % i == 0) return false;
            i += 2;
        }

        return true;
    }
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    cin >> a;
    sort(rall(a));
    int ans = 0;
    for (int i = k;i < n;i++) {
        ans += a[i];
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
mod = 1000000007
def ff(a, b):
  ans = 1
  while b:
    if b & 1: ans = ans * a % mod
    b >>= 1
    a = a * a % mod
  return ans
n=int(input())
print(((ff(10,n)-2*ff(9,n)+ff(8,n))%mod+mod)%mod)


Measured memory_bytes: 9108
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()


template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//-----CODE------//


void solve(void)
{
  int N;cin>>N;
  vector<pair<int,int> > vp;
  for (int i = 0; i < N; i++)
  {
    int A,B;
    cin>>A>>B;
    vp.emplace_back(A,B);
  }
  map<pair<int,int>,int> mp;
  for (int i = 0; i < N; i++)
  {
    for (int j = i+1; j < N; j++)
    {
      int dx = vp[i].first - vp[j].first;
      int dy = vp[i].second - vp[j].second;
      mp[make_pair(dx,dy)]++;
      mp[make_pair(-1*dx,-1*dy)]++;
    }
  }
  int MAX = 0;
  for (auto &&x : mp)
  {
      chmax(MAX,x.second);
  }
  cout<<N -MAX<<endl;
  

  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);

std::cout << std::fixed;
std::cout << std::setprecision(9);
solve();

return 0;
}


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

int main() {
  
  int a,b;
  cin >> a >> b;
  
  cout << (a*3 + b) / 2 << endl;
  
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define MAX 132000
#define ll long long
#define pi pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fr first
#define sd second
#define vp vector<pi>
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
struct Line{int v,next,w;}e[MAX];
int h[MAX],cnt=1;
inline void Add(int u,int v,int w){e[cnt]=(Line){v,h[u],w};h[u]=cnt++;}
int n;ll mid,mn[MAX];
vp f[MAX];
bool cmpx(pi a,pi b){return a.fr<b.fr;}
bool cmpy(pi a,pi b){return a.sd<b.sd;}
void Merge(vp &u,vp ls,vp rs)
{
	if(ls.size()>rs.size())swap(ls,rs);
	int t1=ls.size(),t2=rs.size();
	if(!t1||!t2)return;
	sort(ls.begin(),ls.end(),cmpy);
	sort(rs.begin(),rs.end(),cmpx);
	mn[0]=rs[0].sd;for(int i=1;i<t2;++i)mn[i]=min(mn[i-1],rs[i].sd);
	for(int i=0,j=t2-1;i<t1;++i)
	{
		while(j>=0&&ls[i].sd+rs[j].fr>mid)--j;
		if(j>=0)u.pb(mp(ls[i].fr,mn[j]));
	}
	sort(ls.begin(),ls.end(),cmpx);
	sort(rs.begin(),rs.end(),cmpy);
	mn[0]=rs[0].fr;for(int i=1;i<t2;++i)mn[i]=min(mn[i-1],rs[i].fr);
	for(int i=0,j=t2-1;i<t1;++i)
	{
		while(j>=0&&ls[i].fr+rs[j].sd>mid)--j;
		if(j>=0)u.pb(mp(mn[j],ls[i].sd));
	}
}
void dfs(int u)
{
	f[u].clear();if(!h[u]){f[u].pb(mp(0,0));return;}
	for(int i=h[u];i;i=e[i].next)dfs(e[i].v);
	for(int i=h[u];i;i=e[i].next)
		for(int j=0,l=f[e[i].v].size();j<l;++j)
			f[e[i].v][j].fr+=e[i].w,f[e[i].v][j].sd+=e[i].w;
	if(h[u])Merge(f[u],f[e[h[u]].v],f[e[e[h[u]].next].v]);
}
int main()
{
	n=read();
	for(int i=2,a,v;i<=n;++i)a=read(),v=read(),Add(a,i,v);
	ll l=0,r=1e9,ret=1e9;
	while(l<=r)
	{
		mid=(l+r)>>1;dfs(1);
		if(f[1].empty())l=mid+1;
		else ret=mid,r=mid-1;
	}
	cout<<ret<<endl;
	return 0;
}


Measured memory_bytes: 28768
S = input()

a = len(S) / 2
b = len(S) % 2
x = 0

if b == 0:
  for i in range(1, int(a+1)):
    if S[i-1]!=S[-i]:
      x += 1
else:
  for i in range(1, int(a+1)):
    if S[i-1]!=S[-i]:
      x += 1

print(x)

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

const int inf = 1e9;
const ll linf = 1e18;

template <long long mod> class modint
{
private:
    long long x;

public:
    modint(long long x = 0) : x(x >= 0 ? x % mod : (x % mod) + mod) {}
    modint &operator+=(const modint rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator-=(const modint rhs) {
        if ((x += mod - rhs.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator*=(const modint rhs) {
        (x *= rhs.x) %= mod;
        return *this;
    }
    modint &operator/=(const modint rhs) {
        *this *= rhs.inv();
        return *this;
    }
    modint operator+(const modint rhs) const { return modint(*this) += rhs; }
    modint operator-(const modint rhs) const { return modint(*this) -= rhs; }
    modint operator*(const modint rhs) const { return modint(*this) *= rhs; }
    modint operator/(const modint rhs) const { return modint(*this) /= rhs; }

    modint operator-() const { return modint(-x); }

    modint pow(long long n) const {
        modint e = *this, ret = modint(1);
        while (n) {
            if (n & 1) ret *= e;
            e *= e, n >>= 1;
        }
        return ret;
    }

    modint inv() const { return pow(mod - 2); }

    friend ostream &operator<<(ostream &os, const modint &m) {
        os << m.x;
        return os;
    }

    friend istream &operator>>(istream &is, modint &m) {
        long long in;
        is >> in;
        m = modint(in);
        return is;
    }
};
using mint = modint<1000000007>;

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

    int n; cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    
    mint ans = 0;
    for (int bit = 0; bit < 60; bit++) {
        ll cnt0 = 0, cnt1 = 0;
        for (int i = 0; i < n; i++) {
            ((a[i] & (1LL << bit)) ? cnt1 : cnt0)++;
        }
        ans += (mint)(cnt0 * cnt1) * (mint)(1LL << bit);
    }

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

Measured memory_bytes: 2560
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    int w, h;
    cin >> w >> h;
    VI p(w), q(h);
    REP(i,w) scanf("%d", &p[i]);
    REP(i,h) scanf("%d", &q[i]);
    sort(p.begin(),p.end());
    sort(q.begin(),q.end());
    p.push_back(1e9);
    q.push_back(1e9);

    ll ans = 0;
    int i = 0, j = 0;
    while(i < w || j < h){
        if (p[i] < q[j]){
            ans += (ll)(h+1-j)*p[i];
            i++;
        }else{
            ans += (ll)(w+1-i)*q[j];
            j++;
        }
    }

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

Measured memory_bytes: 1408
def solve():
  s = input()
  news = ""
  n = len(s)
  pas = False
  for i in range(n-1):
    if pas:
      pas = False
      continue
    if s[i] == 'B' and s[i+1] == "C":
      news += "T"
      pas = True
    else:
      news += s[i]
  ans = 0
  beforea = 0

  n = len(news)
  for i in range(n):
    if news[i] == "A":
      beforea += 1
    elif news[i] == "B" or news[i] == "C":
      beforea = 0
    if news[i] == "T":
      ans += beforea 
  print(ans)
solve()

Measured memory_bytes: 3500
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<cstdio>

using namespace std;

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		if(a%2==0){
			if(a%3!=0&&a%5!=0){
				puts("DENIED");
				return 0;
			}
		}
	}
	puts("APPROVED");
	return 0;
}

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

#define ll long long
#define endl "\n"

inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m;
    cin>>m;
    return m;
}
void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
const int N=1e2+5;

int main()
{
    string s;
    cin>>s;
    for(int i=0; i<s.length()-1; ++i)
    {
        if(s[i]==s[i+1])
        {
            cout<<i+1<<" "<<i+2<<endl;
            return 0;
        }
        if(i+2<s.length())
        {
            if(s[i]==s[i+2])
            {
                cout<<i+1<<" "<<i+3<<endl;
                return 0;
            }
        }
    }
    cout<<"-1 -1\n";
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  vint d(n);
  rep(i, n) cin >> d[i];
  sort(all(d));
  d.erase(unique(all(d)), d.end());
  cout << d.size() << endl;

  return 0;
}


Measured memory_bytes: 764
#include<stdio.h>
int main()
{
    int n,i, s, max =-1,ttl1 =0, ttl2=0,ttl ;
    scanf("%d", &n);
    for(i=1;i<=n;i++)
    {
        scanf("%d", &s);
        if(s>max)
        {
            max = s;
            ttl1=max/2;
        }
        ttl2 += s;

    }
    ttl = ttl1 +ttl2-max;
    printf("%d", ttl);
    return 0;
}


Measured memory_bytes: 1700
a = gets.to_i
b = gets.chomp.split(" ").map(&:to_i);

len = b.length
sum = 0
for i in 0..len-1
  sum = sum + b[i]
end

n = (sum.to_f / len.to_f).round(0)

ans = 0
for i in 0..len-1
  ans = ans + (n - b[i]) * (n - b[i])
end

print ans

Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0; i<n; i++)
		cin >> a[i];
	vector<int> baqet(pow(10,5), 0);
	for(int i=0; i<n; i++){
		if(a[i])
			baqet[a[i]-1]++;
		baqet[a[i]]++;
		if(a[i]<pow(10,5)-1){
			baqet[a[i]+1]++;
		}
	}
	int max=0;
	for(int i=0; i<pow(10,5); i++){
		if(baqet[i]>max)
			max=baqet[i];
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, z, w;
    cin >> n >> z >> w;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int ans = abs(a[n - 1] - w);
    if(n >= 2) chmax(ans, abs(a[n - 1] - a[n - 2]));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
int main(){
    string s,t;
  cin>>s>>t;
  rep(i,s.size()) if(s[i] !=t[i]){
    cout <<"No";
    return 0;
  }
  if (t.size()-s.size()==1) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 3616
n,m = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))
mod = 10**9+7
dp = [1]*(m+1)#Tをiまで見た時のSとの部分列のも場合の数
for i in range(n):
    tmp = dp[:]
    for j in range(m):
        if S[i]==T[j]:
            dp[j+1] = (tmp[j+1] + dp[j])%mod
        else:
            dp[j+1] =(tmp[j+1]+dp[j]-tmp[j])%mod
print(dp[-1])


Measured memory_bytes: 74008
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,t;
    cin>>a>>b;
    if(a>0&&b>0){cout<<"Positive"<<endl;return 0;} 
    if((a<0&&b>0)||(a>0&&b<0)){cout<<"Zero"<<endl;return 0;}
    t=b-a+1;
    if(t%2==0)cout<<"Positive"<<endl;
    else cout<<"Negative"<<endl;
    return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

int main() {
  int N;
  cin >> N;
  vi a(N);
  rep(i, N) cin >> a[i];

  map<int, int> m;
  rep(i, N) {
    m[a[i]]++;
    m[a[i] + 1]++;
    m[a[i] - 1]++;
  }
  int res = 0;
  for (auto p : m) {
    res = max(res, p.second);
  }

  cout << res << endl;
}

Measured memory_bytes: 5120
#include <stdio.h>

const int base = 1E9 + 7;

int main() {
    int n; scanf("%d", &n);
    int *f = new int[n + 1];
    f[0] = 0;
    f[1] = n;
    f[2] = 1ll * n * n % base;
    int sum = 0;
    for (int i = 3; i <= n; i++) {
        f[i] = (f[i - 1] + 1ll * (n - 1) * (n - 1) % base) % base;
        f[i] = (f[i] + sum + n - i + 2) % base;
        sum = (sum + f[i - 2]) % base;
    }
    printf("%d", f[n]);
    return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int n;
string s[2000005];
map<string,int> m;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s[i];
        m[s[i]]++;
    }
    int maxv=0;
    for(const auto& x:m)
    {
        int v=x.second;
        if(v>maxv) maxv=v;
    }
    for(map<string,int>::iterator it=m.begin();it!=m.end();it++)
    {
        if(it->second==maxv)
        {
            cout<<it->first<<endl;
        } 
    }
    return 0;
}

Measured memory_bytes: 40832
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int K = input.nextInt();
		long ans = 0;
		long R = input.nextLong();
		long S = input.nextLong();
		long P = input.nextLong();
		String T = input.next();
		boolean[] v = new boolean[N];
		for (int i = 0; i < N; i++) {
			if (!(i-K>=0&&T.charAt(i-K)==T.charAt(i)&&v[i-K])) {
				v[i]=true;
				char cur = WIN(T.charAt(i));
				if (cur=='p') ans+=P;
				else if (cur=='r') ans+=R;
				else if (cur=='s') ans+=S;
			}
		}
		System.out.println(ans);
	}
	public static char WIN(char x) {
		if (x=='r') return 'p';
		if (x=='p') return 's';
		return 'r';
	}
}

Measured memory_bytes: 30512
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
int del(int x) { return x>=P?x-P:x; }
void add(int &x,int y) { x=del(x+y); }
int f[N][8];
const int nx[8][2]={{1,2},{3,4},{5,6},{1,1},{1,2},{7,2},{6,6},{5,5}};
char s[N];
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	scanf ("%s",s+1);
	int n=strlen (s+1);
	f[0][0]=1;
	for (int i=0; i< n; i++)
		for (int j=0; j<=7; j++)
		{
			int g=f[i][j];
			if (s[i+1]!='1') add(f[i+1][nx[j][0]],g);
			if (s[i+1]!='0') add(f[i+1][nx[j][1]],g);
		}
	pr(del(f[n][2]+f[n][6]));

    return 0;
}


Measured memory_bytes: 11776
S = input()
ls = len(S)
ans = 0

for i in range(2 ** (ls-1)):
    susiki = ""
    shiki = []  
    for j in range(ls-1):
        if (i >> j) & 1:
            shiki.append("+")
        else:
            shiki.append("")
    
    for k in range(ls):
        if k == ls - 1:
            susiki = susiki + S[k]
        else:
            susiki = susiki + S[k] + shiki[k]
    ans += eval(susiki)

print(ans)

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i(0);i<N;i++){
    cin>>A[i];
  }
  int cnt(0);
  for(int i(0);i<N;i++){
    for(int j(i+1);j<N;j++){
      for(int k(j+1);k<N;k++){
        if(A[i] == A[j] || A[j] == A[k] || A[i] == A[k]) continue;
        int tmp[3] = {A[i],A[j],A[k]};
        sort(tmp,tmp+3);
     //   cout << tmp[0] << " "<< tmp[1] << " " << tmp[2] << endl;
        if(tmp[2] < tmp[1]+tmp[0]) cnt++;
      } 
    } 
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.StringTokenizer;
 
public class Main {
	static int n ;
	static int d ;
	
	
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		//BufferedReader br = new BufferedReader(new FileReader("input.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st ;
		Scanner sc = new Scanner(System.in);
		//PrintWriter out = new PrintWriter("output.txt");
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int W = sc.nextInt();
		int[] v = new int[n+1];
		int [] wt = new int[W+1];
		for(int i=0;i<n;i++)
		{
			wt[i] = sc.nextInt();
			v [i] = sc.nextInt();	
		}
		
		  long K[][] = new long[n+1][W+1]; 
	       
		     // Build table K[][] in bottom up manner 
		     for (int i = 0; i <= n; i++) 
		     { 
		         for (int w = 0; w <= W; w++) 
		         { 
		             if (i==0 || w==0) 
		                  K[i][w] = 0; 
		             else if (wt[i-1] <= w) 
		                   K[i][w] = Math.max(v[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]); 
		             else
		                   K[i][w] = K[i-1][w]; 
		         } 
		      }
		
		System.out.println(K[n][W]);
		
		out.flush();
		out.close();
		
	}
	
	
}

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

#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll long long


int main()
{
	sup;
    
    string n;
    cin >>n;
    ll ans = 0;
    for(auto c : n)
        ans += (c - '0');
    
    if(ans % 9)
        cout << "No" << endl;
    else 
        cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 3700
import sys

class Dice(object):
    def __init__(self, dice):
        self.__dice = dice

    def roll_north(self):
        self.__dice = (self.__dice[1], self.__dice[5], self.__dice[2],
                       self.__dice[3], self.__dice[0], self.__dice[4])

    def roll_south(self):
        self.__dice = (self.__dice[4], self.__dice[0], self.__dice[2],
                       self.__dice[3], self.__dice[5], self.__dice[1])

    def roll_west(self):
        self.__dice = (self.__dice[2], self.__dice[1], self.__dice[5],
                       self.__dice[0], self.__dice[4], self.__dice[3])

    def roll_east(self):
        self.__dice = (self.__dice[3], self.__dice[1], self.__dice[0],
                       self.__dice[5], self.__dice[4], self.__dice[2])

    def number(self, face_id):
        return self.__dice[face_id - 1]


dice = Dice([int(i) for i in sys.stdin.readline().split()])
command = sys.stdin.readline().strip()
for c in command:
    if c == "N":
        dice.roll_north()
    elif c == "S":
        dice.roll_south()
    elif c == "W":
        dice.roll_west()
    elif c == "E":
        dice.roll_east()
print(dice.number(1))

Measured memory_bytes: 6752
using System;

namespace AtCoder {

    class Program {

        static void Main(string[] args) {

            var Ns = Console.ReadLine();

            var result = true;
            var str = "1974";
            foreach(var ch in str) {

                if(!Ns.Contains(ch.ToString())) {
                    result = false;
                }
            }
            Console.WriteLine(result ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 13140
using System;
using System.Collections.Generic;
using System.Linq;

namespace Test01
{   
    class Program
    {      
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x) - 1).ToArray();
            int[] b = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int[] c = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            long sum = 0;
            int mae = -1;
            for(int i = 0; i < a.Length; i++)
            {
                sum += b[a[i]];
                if (mae != -1 && a[i] == mae + 1) sum += c[mae];
                mae = a[i];
            }

            Console.WriteLine(sum);
        }
    }
}


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

const int mod = 1e9 + 7, N = 1e5 + 10;

ll pw(ll a, ll b) {
    ll r = 1;
    for( ; b ; b >>= 1, a = a * a % mod) {
        if(b & 1) {
            r = r * a % mod;
        }
    }
    return r;
}

ll getinv(ll n) {
    return pw(n, mod - 2);
}

ll n, a[N];

int main() {
    cin >> n;
    for(int i = 1 ; i <= n ; ++ i) {
        cin >> a[i];
    }
    ll ans = -1;
    for(int i = 1 ; i < n ; ++ i) {
        ll x = 0, y = 0;
        for(int j = 1 ; j <= i ; ++ j) {
            x += a[j];
        }
        for(int j = i + 1 ; j <= n ; ++ j) {
            y += a[j];
        }
        if(ans == -1) ans = abs(x - y);
        else ans = min(ans, abs(x - y));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>
#include <unordered_map>
#define INF 9999999
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char> > grid(H, vector<char>(W, 0));
	for (int i = 0; i < H; i++)for (int j = 0; j < W; j++) {
		cin >> grid[i][j];
	}
	vector<int> gyo, retu;
	for (int i = 0; i < W; i++) {
		for (int j = 0; j < H; j++) {
			if (grid[j][i] != '.') break;
			if (j == H - 1) retu.push_back(i);
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (grid[i][j] != '.') break;
			if (j == W - 1) gyo.push_back(i);
		}
	}
	for (int i = 0; i < H; i++){
		if (find(gyo.begin(), gyo.end(), i) != gyo.end()) continue;
		for (int j = 0; j < W; j++) {
			if (find(retu.begin(), retu.end(), j) == retu.end()) {
				cout << grid[i][j];
			}
			if (j == W - 1) cout << endl;
		}
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int>data(100005);
  int64_t ans=0;
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    data.at(x)++;
    ans+=x;
  }
  int Q;
  cin >> Q;
  for(int i=0;i<Q;i++){
    int b,c;
    cin >> b >> c;
    data.at(c)+=data.at(b);
    ans+=data.at(b)*(c-b);
    data.at(b)=0;
    cout << ans << endl;
  }
}

Measured memory_bytes: 3780
N, A, B =map(int,input().split())
d = abs(B-A)
ans = 0
if d % 2 == 0:
    ans = d // 2
else:
    ans = min(A- 1, N-B) + 1 + d//2

    '''
    if N - B >= A - 1:
        ans = B - 1
    else:
        ans = N - A
'''
print(ans)


Measured memory_bytes: 9132
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1.01e9;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

const int mod = (int) 1e9 + 7;

void add(int & x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int sum(int x, int y) {
  add(x, y);
  return x;
}

int mult(int x, int y) {
  return (ll) x * y % mod;
}

int power(int x, ll p) {
  int res = 1;
  while (p) {
    if (p & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
    p >>= 1;
  }
  return res;
}

int inv(int x) {
  return power(x, mod - 2);
}

void precalc() {
}

int a, b, c;

bool read() {
  if (scanf("%d%d%d", &a, &b, &c) < 3) {
    return false;
  }
  return true;
}

void solve() {
  int res = 0;
  for (int i = 1; i < 1000; i++) {
    if ((a & 1) || (b & 1) || (c & 1)) {
      break;
    }
    int na = (b + c) / 2;
    int nb = (a + c) / 2;
    int nc = (a + b) / 2;
    a = na, b = nb, c = nc;
    res++;
  }
  if (res > 500) {
    printf("-1\n");
  } else {
    printf("%d\n", res);
  }
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time: %.3f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

class RSQ{
private:
    int n;
    vector<int> node;
    int get2(int a, int b, int k, int l, int r){
        if(a==l and r==b)return node[k];
        int m=(l+r)/2;
        if(b<=m)return get2(a,b,k*2+1,l,m);
        else if(a>=m)return get2(a,b,k*2+2,m,r);
        else return get2(a,m,k*2+1,l,m)+get2(m,b,k*2+2,m,r);
    }
public:
    RSQ(vector<int> vec){
        int tmp_size=vec.size();
        n=1; while(n<tmp_size)n*=2;
        node=vector<int>(n*2-1,0);
        for(int i=0; i<tmp_size; i++)node[i+n-1]=vec[i];
        for(int i=n-2; i>=0; i--)node[i]=node[i*2+1]+node[i*2+2];
    }
    void update(int x, int v){
        x+=n-1; node[x]+=v;
        while(x>0){x=(x-1)/2;node[x]+=v;}
    }
    int get(int a, int b){return get2(a,b,0,0,n);}
};

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

    int n,k; cin>>n>>k;
    vector<int> a(n+1); a[0]=0;
    rep(i,n){
        int t; cin>>t;
        a[i+1]=a[i]+t-k;
    }

    vector<int> a2=a;
    sort(all(a2));
    map<int,int> mp;
    int now=0; mp[a2[0]]=now;
    rep(i,n){
        if(a2[i+1]!=a2[i])now++;
        mp[a2[i+1]]=now;
    }

    RSQ sg(vector<int>(mp.size(),0));
    int ans=0;
    rep(i,n+1){
        ans+=sg.get(0,mp[a[i]]+1);
        sg.update(mp[a[i]],1);
    }
    cout<<ans<<endl;

}

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

int main() {
  string S, T;
  cin >> S >> T;
  vector<char> StoT(26, '.'), TtoS(26, '.');
  bool can = true;
  for (int i = 0; i < S.size(); i++) {
    if (StoT[S[i]-'a'] == '.') StoT[S[i]-'a'] = T[i];
    else {
      if (StoT[S[i]-'a'] != T[i]) {
        can = false;
        break;
      }
    }
    if (TtoS[T[i]-'a'] == '.') TtoS[T[i]-'a'] = S[i];
    else {
      if (TtoS[T[i]-'a'] != S[i]) {
        can = false;
        break;
      }
    }
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

struct node {
	ll w;
	ll val;
	node(ll _w,ll _val) {
		w = _w;
		val = _val;
	}
};
int n, cnt = 0;
ll w, ans = 0, x, y;
vector<node>q[4];
map<ll,int>p;

void dfs(ll value,ll weight,int dep) {
	//cout<<value<<endl;
	ans = max(ans, value);
	
	if(dep>=cnt)return;
	
	for(int i=0;i<=q[dep].size();i++) {
		if(i*q[dep][0].w + weight>w)break;
		ll tmp = 0;
		for(int j=0;j<i;j++)tmp+=q[dep][j].val;
		dfs(value+tmp, weight+i*q[dep][0].w, dep+1);
	}
	
	return;
}

bool cmp(const node &v1, const node &v2) {
	return v1.val > v2.val;
}

int main() {
	//freopen("in.txt","r",stdin);
	cin>>n>>w;
	
	for(int i=0;i<n;i++) {
		scanf("%lld%lld",&x,&y);
		if(p.count(x))q[p[x]].push_back(node(x,y));
		else {
			p[x] = cnt++;
			q[p[x]].push_back(node(x,y));
		}
	}
	//cout<<cnt<<endl;
	
	for(int i=0;i<cnt;i++) {
		sort(q[i].begin(),q[i].end(),cmp);  
	}
	
	dfs(0,0,0);
	cout<<ans<<endl;
	return 0;
}

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

#define ff first
#define ss second
#define pb push_back

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int N = 16;

int a[N], x[N][N], y[N][N];

int main() {
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
		for(int j = 0; j < a[i]; j++){
			scanf("%d %d", &x[i][j], &y[i][j]);
			x[i][j]--;
		}
	}
	int ans = 0;
	for(int mask = 0; mask < (1 << n); mask++){
		int q[N];
		bool ok = 1;
		memset(q, -1, sizeof q);
		for(int i = 0; i < n; i++){
			if(mask & (1 << i)){
				for(int j = 0; j < a[i]; j++){
					if(q[x[i][j]] == -1){
						q[x[i][j]] = y[i][j];
					}
					else{
						if(q[x[i][j]] != y[i][j]){
							ok = 0;
							break;
						}
					}
				}
			}
			if(!ok) break;
		}
		for(int i = 0; i < n; i++){
			if(mask & (1 << i)){
				if(q[i] == 0){
					ok = 0;
					break;
				}
			}
			else if(q[i] == 1){
				ok = 0;
				break;
			}
		}
		if(ok){
			ans = max(ans, __builtin_popcount(mask));
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 384
X = input()

def solve(X):
    if X == '0':
        return 0
    if len(X) % 2 == 0:
        ans = 0
        y = len(X)
        while (y > 1):
            if y % 2 == 0:
                ans += 9 * 10**(y-2)
            y -= 2
        return ans 
    else:
        ans = int(X) - 10**(len(X)-1) + 1
        return ans + solve(str(10**(len(X)-1)-1))

print(solve(X))


    

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  string s;
  cin>>s;
  int c1=0;
  int i;
  for( i=0;i<s.size();i++)
  {
    if(s[i]=='W')
      c1++;
      

  }
  int k=0;
  i=n-1;
  while(c1--)
  {
    if(s[i]!='W')
      k++;
    i--;
    

    
  }
  cout<<k<<endl;
  

  
  
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define ll long long
//map<key,value>

int main(){
  double n,k;
  double ans=0;
  cin >> n >> k;
  for(int i=1;i<=n;i++){
    double save=0;
    for(int j=0;j<=30;j++){
      if(i*pow(2,j) >= k){
        save = j;break;
      }
    }
    ans  += 1/(n*(double)pow(2,save));
  }
  cout << setprecision(12) << ans;
  return 0;
}


Measured memory_bytes: 256