akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
using namespace std; 
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'

int n;
vector<vi> adjList;
vector<vector<ll>> dp;
ll mod = 1e9+7;

ll solve(int p, int parent, int c) {
	if (dp[p][c] != -1) return dp[p][c];
	
	ll ans = 1;
	for (int i: adjList[p]) if (i != parent) {
		ll v = solve(i, p, 0);
		if (c != 1) v += solve(i, p, 1);
		ans = (ans * (v % mod)) % mod;
	}
	
	return dp[p][c] = ans;
}

int main() {
	#ifndef ONLINE_JUDGE
	freopen("test.in", "r", stdin);
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n;
	adjList.resize(n); dp.resize(n, vector<ll>(2, -1));
	for_(i, 0, n-1) {
		int a, b; cin >> a >> b;
		a -= 1; b -= 1;
		adjList[a].push_back(b); adjList[b].push_back(a);
	}
	
	cout << (solve(0, 0, 1) + solve(0, 0, 0)) % mod << endl;

	return 0;
}


Measured memory_bytes: 22432
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>

int main() {

    char s[4];

    scanf("%s", s);

    if(s[0]==s[1] || s[1]==s[2] || s[2]==s[3]){
        puts("Bad");
    }else{
        puts("Good");
    }
    
    
    return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,i;cin>>A>>B; 
  for(i=10*B;i<10*(B+1);i++){
    if(25*A<=2*i&&2*i<25*(A+1))break;
  }
  if(i<10*(B+1))cout<<i<<endl;
  else cout<<"-1"<<endl;
}


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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

int main() {

  for (int w; cin >> w, cin;) {

    vi ans;
    for (int i = 0; i < 10; ++i) {
      int g = 1 << i;
      if (w & g) ans.push_back(g);
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1212
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{

	int ii;
	char c;
	int count[26];

	//クリア
	memset(count, (int)0, sizeof(int)* 26);

	while ((c = fgetc(stdin)) != EOF) {
		if ((c & 0xDF) >= 'A' && (c & 0xDF) <= 'Z') {
			count[(int)((c & 0xDF) - 'A')]++;
		}
	}

	for (ii = 0; ii < 26; ii++) {
		printf("%c : %d\n", (char)('a' + ii), count[ii]);
	}

	return 0;

}

Measured memory_bytes: 524
n, m = map(int, input().split())
st = []
cp = []
for _ in range(n):
    a, b = map(int, input().split())
    st.append((a, b))
for _ in range(m):
    c, d = map(int, input().split())
    cp.append((c, d))
res = []
for i in range(n):
    dists = []
    for j in range(m):
        dist = abs(cp[j][0] - st[i][0]) + abs(cp[j][1] - st[i][1])
        dists.append(dist)
    print(dists.index(min(dists)) + 1)

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

int main(void){
    int n, *h, count, flag;

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

    count = 1;
    flag = 0;
    for(int i = 1;i < n;i++){
        for(int j = 0;j < i;j++){
            if(h[i] < h[j]){
                flag = 1;
                break;
            }
        }
        if(flag == 0){
            count++;
        }
        flag = 0;
    }

    cout << count << endl;

    delete[] h;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#define int long long
using namespace std;
#define mod 1000000007
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
bool vis[200005];
vector<int> vec[2000005], v1;
int child[2000005];
int parent[2000005];
int div1[100005];
int min_indx[200005];
int count1 = 0;
int height = 0;
int max_indx[200005];
void dfs(int node)
{

    vis[node] = 1;

    min_indx[count1] = node;
    max_indx[node] = min(max_indx[node], count1);
    count1++;

    //  count1++;
    child[node] = height++;
    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            dfs(vec[node][i]);
            min_indx[count1] = node;
            max_indx[node] = min(max_indx[node], count1);
            count1++;
        }
    }
    height--;
}
int MAXN = 200005;
int LOGMAXN = (int)log2(200005) + 1;
int M[200005][60];
int ans[200005];
void fun(int a, int b, int c)
{
    //ll val = 1;

    while (a <= b)
    {
        ans[a] += c;
        int p = -a;
        a += (a & p);
    }
}
int find1(int a)
{
    int sum = 0;
    while (a != 0)
    {
        sum += ans[a];
        int p = -a;
        a -= (a & p);
    }
    return sum;
}
void process2(int A[], int N)
{
    int i, j;

    for (i = 0; i < N; i++)
        M[i][0] = i;
    for (j = 1; 1 << j <= N; j++)
        for (i = 0; i + (1 << j) - 1 < N; i++)
            if (find1(M[i][j - 1]) < find1(M[i + (1 << (j - 1))][j - 1]))
                M[i][j] = M[i][j - 1];
            else
                M[i][j] = M[i + (1 << (j - 1))][j - 1];
}
int arr1[1000005], arr2[1000005];
int32_t main()
{
    FAST;
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a ^ b ^ c) << "\n";

    return 0;
}

Measured memory_bytes: 50504
#include <stdio.h>
#include <ctype.h>
#define MAX 1202
#define alphaNum 26

int main(void){
	int i;
	char str[MAX];
	int count[alphaNum] = {0};

	while(fgets(str, MAX, stdin) != NULL){
		for(i = 0; str[i] != '\n'; i++){
			if(isalpha(str[i])){
				if(isupper(str[i])){
					count[str[i] - 'A']++;
				}
				if(islower(str[i])){
					count[str[i] - 'a']++;
				}
			}
		}
	}

	for(i = 0; i < alphaNum; i++){
		printf("%c : %d\n", i + 'a', count[i]);
	}
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
    using namespace std;
    int main(){
        string S, T;
        cin >> S >> T;
        int ans = 0;
        
        for (int i = 0; i < 3;i++){
            if(S[i]==T[i]){
                ans++;
            }    
        }
        cout << ans << endl;
    }

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		sc.close();

		for (int i = x; i >= 1; i--) {
			for (int j = 1; j < 32; j++) {
				for (int j2 = 2; j2 < 10; j2++) {
					int a = (int) Math.pow(j, j2);
					if (a == i) {
						System.out.println(i);
						return;
					}
				}
			}
		}
	}
}


Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

bool is_reversible(string s) {
  string t = s;
  reverse(t);
  return s == t;
}

void solve() {
  string s; cin >> s;

  if (!is_reversible(s)) {
    No();
    return;
  }

  int n = s.size();
  if (is_reversible(s.substr(0, (n-1)/2))) Yes();
  else No();
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; (i) < (int) (n); (i) ++)
using namespace std;
 
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 0;
	rep(i, n) {
		vector<int> a(26), b(26);
		for (int j = 0; j < i; j ++) a[s[j] - 'a'] ++;
		for (int j = i; j < n; j ++) b[s[j] - 'a'] ++;
		int cnt = 0;
		for (int j = 0; j < 26; j ++) cnt += a[j] > 0 && b[j] > 0;
		ans = max(ans, cnt);
	}
	cout << ans << endl;
        return 0;
}

Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr int MOD_TYPE = 2;
constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr ld PI = acos(-1.0);
constexpr ld EPS = 1e-11;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

#pragma endregio

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  int n;
  cin >> n;
  pair<pair<string, int>, int> v[100];
  rep(i, n)
  {
    string s;
    int p;
    cin >> s >> p;
    v[i].first = MP(s, -p);
    v[i].second = i + 1;
  }
  sort(v, v + n);
  rep(i, n)
  {
    cout << v[i].second << endl;
  }

  return 0;
}

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0)
#define sq(n) (n)*(n)

using namespace std;
typedef long long ll;

int main() {
    FAST;



            ll n;
            cin>>n;
            if(n>=30)
            {
                cout<<"Yes"<<endl;
            }
            else
            {
                cout<<"No"<<endl;
            }


    return 0;
}





Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define mod 1000000007ll
#define mod1 998244353ll
#define endl '\n'
#define inf ((ll)1e18+1)
#include<chrono>
using namespace chrono;
mt19937_64 rng(high_resolution_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define debr(x,y) {cout<<"-->  "<<#x<<" to "<<#y<<" :  "; auto itr=x; while(itr!=y) cout<<(*itr++)<<' '; cout<<endl; }
#define deba(x) {cout<<"-->  "<<#x<<" :  "; for(auto ele:(x)) cout<<ele<<"  "; cout<<endl; }
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s);istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a <<"  ,  ";
    err(++it, args...);
}

const ll maxN=10000000+1;
int how[maxN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    for(ll x=0;x<=n;x++)how[x]=0;
    for(ll x=1;x<=n;x++){
        for(ll y=x;y<=n;y+=x){
            how[y]++;
        }
    }
    ll ans=0;
    for(ll x=1;x<=n;x++){
        ans+=x*how[x];
    }
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 42668
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)


int main(void){
	string a;
	cin >> a;
	for(int e=0;e<a.size();e++){
		if(a[e]=='?'){
			a[e] = 'D';
		}
	}
	cout << a;
	return 0;
}


Measured memory_bytes: 3752
def main():
    import sys
    from collections import deque
    input = sys.stdin.readline

    s_old = list(str(input()))
    q = int(input())
    pl_mi = 1
    pl_mi_2 = 1
    query = [list(input().split()) for i in range(q)]

    s = deque(s_old)
    s.pop()

    for i in range(q):
        if query[i][0] == "1":
            pl_mi = pl_mi * (-1)
            continue
        else:
            if query[i][1] == "1":
                pl_mi_2 = 1
            else:
                pl_mi_2 = -1
            if pl_mi * pl_mi_2 == 1:
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
    
    if pl_mi == 1:
        s_new = "".join(list(s))
        print(s_new)
    else:
        s.reverse()
        s_new = "".join(list(s))
        print(s_new)




if __name__ == "__main__":
    main()

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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>


int main() {
    long A, B, N;
    cin>>A>>B>>N;
    long y = 0;
    if(N >= B) y = B-1;
    else y = N;
    long ans = y*A/B;
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 998244353
#define INF 1000000000000000007LL

const int N = 200005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

int fact[N], ifact[N];

int val[N];

int powmod(int a, int b, int c){
    int ans = 1;
    while(b){
        if(b&1){
            ans = (ans*a)%c;
        }
        a = (a*a)%c;
        b >>= 1;
    }
    return ans;
}

int ncr(int n, int r){
    int v = (((fact[n]*ifact[n-r])%MOD)*ifact[r])%MOD;
    return v;
}

void solve(){
    int n, m, k; cin>>n>>m>>k;
    val[1]=m;
    for(int i=2; i<=n; i++){
        val[i]=val[i-1]*(m-1);
        val[i]%=MOD;
    }
    int ans = 0;
    for(int i=0; i<=k; i++){
        int cur = ncr(n-1, i);
        cur = cur * val[n-i];
        cur %= MOD;
        ans += cur;
        ans %= MOD;
    }
    cout<<ans;
}

void pre(){
    fact[0]=1;
    ifact[0]=1;
    for(int i=1; i<=200001; i++){
        fact[i]=fact[i-1]*i;
        fact[i]%=MOD;
        ifact[i]=powmod(fact[i], MOD-2, MOD);
    }
}

signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    pre();
    int t=1;
    // cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
    return 0;
}





Measured memory_bytes: 8276
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int cnt = 0;
		
		for (int i = 0; i<n; i++) {
			if (sc.nextInt() != i+1) {
				cnt += 1;
			}
			if (cnt > 2) {
				break;
			}
		}

		if (cnt > 2) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}
}}

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

int main(){
    int x[5];
    int ans;
    for(int i=0;i<5;i++){
        cin>>x[i];
        if(!x[i]){
            ans=i+1;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n,m,q,a[52],b[52],c[52],d[52],res,vec[12];
void Search(int x,int cur){
	if(x==n+1){
		int tot=0;
		for(int i=1;i<=q;i++)
			if((vec[b[i]]-vec[a[i]])==c[i])
				tot+=d[i];
		res=max(res,tot);
		return;
	} 
	for(int i=cur;i<=m;i++){
		vec[x]=i;
		Search(x+1,i);
		vec[x]=0;
	}
} 
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m>>q;
	for(int i=1;i<=q;i++){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	}
	res=0;
	Search(1,1);
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define pb           push_back
#define pii          pair<int,int>
#define vi           vector<int>
#define vpii         vector<pair<int,int>>
#define gph          map<int, vector<int>>
#define mp           make_pair
#define FOR(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD0(i, n) for (int i = (int)n; i >= 0; i--)
#define FORD1(i, n) for (int i = (int)n; i >= 1; i--)
#define FORS(i, n) for(; i < (int)(n); i++)
#define debug(X) { cout << #X << " = " << (X) << endl; }
#define printArr(A,n) { cout << #A << " = "; FOR(i,n) cout << A[i] << ' '; cout << endl; }
using namespace std;
//#define int long long int
vi adj[(int)2e5];
vi start((int)2e5);
vi len((int)2e5, -1);
pii intersect(int i, int j){
   if(len[i] == -1 && len[j] == -1)return mp(0, -1);
   if(len[i] == -1)return mp(start[j], len[j]);
   if(len[j] == -1)return mp(start[i], len[i]);
   if(start[i] % 2 != start[j] % 2)return mp(0, 0);
   int s = max(start[i],start[j]);
   int e = min(start[i] + len[i]*2 - 2, start[j] + len[j]*2 -2);
   if(e < s)return mp(0, 0);
   return mp(s, (e- s)/2 + 1);
}
void calc(int i, int k){
    //need to adjust the range for the child
    if(len[i] != -1)start[i]--,len[i]++;
    pii temp = intersect(i, k);
    if(len[i] != -1)start[i]++,len[i]--;
    start[k] = temp.first;
    len[k] = temp.second;
}
bool check(int cur, int P){
    for(int child: adj[cur]){
        if(child != P){
            if(check(child, cur))return true;
            calc(child, cur);
        }
    } 
//    cout << cur << " " << start[cur] << " " << len[cur]  <<endl;
    if(len[cur] == 0)return true;
    return false;
}
void dfs(int cur, int P){
    if(P != -1){
        int pval = start[P];
        if(len[cur] == -1)start[cur] = pval + 1;
        else{
            if(start[cur] < pval)start[cur] = pval -1;
            else start[cur] = pval+1;
        }
        len[cur] = 1;
    }
    for(int child: adj[cur]){
        if(child != P){
            dfs(child, cur);
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    int n;cin >> n;
    int x, y;
    FOR(i, n -1){
        cin >>x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    int k;cin >> k;
    FOR(i, k){
        cin >>x >> y;
        start[x] = y;
        len[x] = 1;
    }
    if(check(1, -1))cout << "No";
    else{
        cout << "Yes" << "\n";
        //assuming start[1] = 0 if not set otherwise the set value will be used
        len[1] = 1;
        dfs(1, -1);
        FOR1(i, n){
            cout << start[i] << "\n";
        }
    }
}




Measured memory_bytes: 16640
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    private Scanner sc;

    private void solve() {
        sc = new Scanner(System.in);
        Deque<String> stack = new ArrayDeque<String>();
        String line = sc.nextLine();
        String[] a = line.split(" ");
        for (String s : a) {
            if ("+".equals(s)) {
                int n1 = Integer.parseInt(stack.pop());
                int n2 = Integer.parseInt(stack.pop());
                stack.push(String.valueOf(n1 + n2));
            } else if ("-".equals(s)) {
                int n1 = Integer.parseInt(stack.pop());
                int n2 = Integer.parseInt(stack.pop());
                stack.push(String.valueOf(n2 - n1));
            } else if ("*".equals(s)) {
                int n1 = Integer.parseInt(stack.pop());
                int n2 = Integer.parseInt(stack.pop());
                stack.push(String.valueOf(n1 * n2));
            } else {
                stack.push(s);
            }
        }
        System.out.println(stack.pop());
    }
}

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

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

  map<int, bool> p;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    p[a] = true;
  }

  for (int i = 0; i < N + 1; i++) {
    int before = X - i;
    int after = X + i;

    if (p.count(before) == 0) {
      cout << before << endl;
      return 0;
    }
    if (p.count(after) == 0) {
      cout << after << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3608
N = int(input())
x = list(map(int,input().split()))

P = int((sum(x) / len(x)))
a = 0
b = 0
c = 0
ans_list = []

for i in range(N):
    a += (x[i] - P) * (x[i] - P)
    b += (x[i] - (P + 1)) * (x[i] - (P + 1))
    c += (x[i] - (P - 1)) * (x[i] - (P - 1)) 
ans_list.append(a)
ans_list.append(b)
ans_list.append(c)

print("{}".format(min(ans_list)))   

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
using P = pair<int, ll>;

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    vector<ll> a(n);
    vector<P> query(m);
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < m; ++i) cin >> query[i].first >> query[i].second;
    
    sort(a.begin(), a.end());
    sort(query.begin(), query.end(), [](P& a, P& b){ return a.second > b.second; });

    int idxa = 0;
    for (int i = 0; i < m; ++i)
    {
        int b = query[i].first;
        int c = query[i].second;
        if (c <= a[idxa]) break;
        bool ok = false;
        for (int k = 0; k < b; ++k)
        {
            a[idxa] = c;
            ++idxa;
            if (idxa >= n || a[idxa] >= c)
            {
                ok = true;
                break;
            }
        }
        if (ok) break;
    }

    ll sum = 0;
    for (int i = 0; i < n; ++i)
    {
        sum += a[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
int a[100];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	int ans = 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]
						&& (a[i] + a[j]) > a[k]
						&& (a[i] + a[k]) > a[j]
						&& (a[j] + a[k]) > a[i]) {
					ans++;
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef array<int, 2> duo;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int n; cin >> n;
        vector<int> a(n); cin >> a;
        int ans = 0;
        for (int i = 1; i < n-1; i++) {
                vector<int> x{a[i-1], a[i], a[i+1]};
                sort(all(x));
                if (x[1] == a[i]) ++ans;
        }

        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;



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

    for (int i = 0; i < n; i++)cin >> a[i];
    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (a[i] == a[j])continue;
            for (int k = j + 1; k < n; k++) {
                if (a[j] == a[k])continue;
                if (a[i] + a[j] <= a[k])break;
                ans++;
            }
        }
    }
    cout << ans << endl;
    
   
    return 0;

}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	int h , w ;
	cin >> h >> w ;
	int c[10][10];
	rep(i,10) rep(j,10) cin >> c[i][j]; 
	int A[h][w];
	rep(i,h) rep(j,w) cin >> A[i][j];

	rep(k,10){
		rep(i,10){
			rep(j,10){
				chmin(c[i][j],c[i][k]+c[k][j]);
			}
		}
	}
	int ans = 0 ;
	rep(i,h){
		rep(j,w){
			int a = A[i][j] ;
			if(a==-1) continue;
			ans += c[a][1];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N],dp[N];
main()
{   int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);

    for(int i=3;i<=n;i++)
    {
        dp[i]= 2e9;
        for(int j=1;j<=k;j++)
        {
            if(i-j>=1)

            dp[i]=min( abs(a[i]-a[i-j]) + dp[i-j] , dp[i] ) ;
        }
    }
    cout<<dp[n];
}


Measured memory_bytes: 4416
#include<stdio.h>

int main(){
    int n,m,l;
    scanf("%d %d %d",&n,&m,&l);
    long mat1[n][m]={},mat2[m][l] = {},result[n][l] = {};
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++){
            scanf("%ld",&mat1[i][j]);
        }
    }
    for(int i = 0;i < m;i++){
        for(int j = 0;j < l;j++){
            scanf("%ld",&mat2[i][j]);
        }
    }
    
    int x=0;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < l;j++){
            for(int k = 0;k < m;k++){
                result[i][j] += mat1[i][k] * mat2[k][j];
            }
        }
    }
    
    for(int i = 0;i < n;i++){
        for(int j = 0;j < l;j++){
            if(j != l-1){
                printf("%ld ",result[i][j]);
            } else{
                printf("%ld\n",result[i][j]);
            }
        }
    }
    return 0;
}



Measured memory_bytes: 2836
#include <stdio.h>


int main(void) {
	int x, n;
	scanf("%d %d", &x, &n);

	int q[100]; 
	for (size_t i = 0; i < 100; i++) {
		q[i] = 0;
	}

	for (int i = 0; i < n; i++) {
		int p;
		scanf("%d", &p);
		q[p - 1] = 1;
	}

	int y = x, i = 0;
	while(y > 0 && y <= 100) {
		if (q[y - 1] == 0) {
			break;
		}
		
		if (i >= 0) {
			i = - (i + 1);
		} else {
			i = - (i - 1);
		}
		y = y + i;
	}
	printf("%d\n", y);

	return 0;
}


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

using namespace std;

typedef long long int 	ll;
typedef pair<int,int>   ii;
typedef vector< ii >   vii;
typedef vector<int>     vi;
typedef vector< vi >   vvi;

#define mm 100005
#define nn 1005
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define cases int t;  cin>>t;   while(t--)
#define check(a,n) forn(iiii,int(n)) cout<<ll(a[iiii])<<" "; cout<<endl
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{
    fast_io;
    int n,m,k,c,ans[105][105]={0};
    cin>>n>>m>>k;
    int i=0,j=0;
    forn(s,k)
    {
        cin>>c;
        while(c)
        {
            if(i%2==0)
            {
                if(j+c<=m) ans[i][j]+=s+1,ans[i][j+c]-=s+1,j+=c,c=0;
                else ans[i][j]+=s+1,ans[i][m]-=s+1,c-=m-j,j=m;
                if(j==m) i++;
            //    cout<<s<<" "<<c<<" "<<i<<" "<<j<<endl;
            }
            else
            {
                if(j-c>=0) ans[i][j-c]+=s+1,ans[i][j]-=s+1,j-=c,c=0;
                else ans[i][0]+=s+1,ans[i][j]-=s+1,c-=j,j=0;
                if(j==0) i++;
              //  cout<<s<<" "<<c<<" "<<i<<" "<<j<<endl;
            }
        }
    }
    forn(i,n)
        forn(j,m)
            ans[i][j+1]+=ans[i][j];
    forn(i,n){
        forn(j,m)
            cout<<ans[i][j]<<" ";cout<<endl;}
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(void){
    int N;
    cin>>N;
    int cnt=0;
    REP(i,N){
        if((i+1)%2!=0)cnt++;
    }
    double ans=(double)cnt/N;
    printf("%.20lf\n",ans);
}

Measured memory_bytes: 256
import java.io.*;

public class Main {

  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] in = br.readLine().split(" ");
    int a = Integer.parseInt(in[0]);
    int b = Integer.parseInt(in[1]);
    int k = Integer.parseInt(in[2]);

    br.close();

    for(int i = 0; i < k; i++){
      a /= 2;
      b += a;
      i++;
      if(i >= k) break;
      b /= 2;
      a += b;
    }
    System.out.println(a + " " + b);
  }
}

Measured memory_bytes: 21972
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll k;
	cin >> k;
	int n = 50;
	ll rem = k % n;
	vl ret(n);
	REP(i, n)ret[i] = n - 1 + k / 50;
	REP(i, rem)ret[i] += n - rem + 1;
	FOR(i, rem, n)ret[i] -= rem;
	cout << n << endl;
	REP(i, n) {
		if (i)cout << " ";
		cout << ret[i];

	}
	cout << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string s, pre, suf;
  int m, h;
  cin >> s;
  while (s != "-") {
    cin >> m;
    for (int i = 0; i < m; i++) {
      cin >> h;
      pre = s.substr(0, h);
      suf = s.substr(h, s.size() - h);
      s = suf + pre;
    }
    cout << s << endl;
    cin >> s;
  }

}


Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std ;
int n ;
const int N = 1e5 + 10 ;
int a[N] ;
signed main() {
  cin >> n ;
  for(register int i = 1 ; i <= n ; i ++) {
    int x ;
    cin >> x ;
    a[x] = i ;
  }
  for(register int i = 1 ; i <= n ; i ++) cout << a[i] << ' ' ;
  return 0 ;
}

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

int main()
{
    int N;
    int A[1000];
    cin >> N;
    for(int i=0; i<N; i++)
        cin >> A[i];

    for(int j=0; j<N; j++)
    {
        if(A[j] % 2 == 1)
            A[j] = 0;
    }

    bool answer = true;

    for(int k=0; k<N; k++)
    {
        if(A[k] % 3 != 0 && A[k] % 5 != 0)
        {
            answer = false;
        }
    }

    if(answer)
        cout << "APPROVED";
    else
        cout << "DENIED";
    
    

    return 0;
}

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

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

using namespace std;
using ll = long long;

constexpr ll MOD = 1e9 + 7;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int M, D; cin >> M >> D;
  int ans = 0;
  for (int i=1; i<=M; i++) for (int j=1; j<=D; j++) {
    int x = j / 10;
    int y = j % 10;
    if (x>=2 && y>=2 && x*y==i) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
K, T = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
cnt = 0
if T == 1:
    print(K - 1)
    exit()

tmp = a[0] - sum(a[1:])
if tmp <= 0:
    print(0)
else:
    print(tmp - 1)

Measured memory_bytes: 3060
import sys
from collections import deque
def input():return sys.stdin.readline().strip()

def main():
    N = int(input())
    info = [tuple(map(int, input().split())) for _ in range(N)]

    RL = sorted([(X+L, X-L) for X, L in info])
    RL = deque(RL)

    now, _ = RL.popleft()
    ans = 1
    for _ in range(N-1):
        R, L = RL.popleft()
        if now <= L:
            now = R
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 31580
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  int ret = 1000000000;
  rep(i,S.size()-2){
    int tmp = 0;
    rep(j,3){
      tmp *= 10;
      tmp += S[i+j]-'0';
    }

    if(ret > abs(tmp - 753)){
      ret = abs(tmp - 753);
    }
  }
  
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/tenka1-2019/submissions/5065329

import sys

input = sys.stdin.readline

N = int(input())
a = [int(input()) for _ in range(N)]
total = sum(a)
MOD = 998244353

'''(1)全体'''
U = pow(3, N, MOD)  # 三角形を構成できない場合を含むRGBの組み合わせ総数

'''(2)単円'''
dp = [[0] * (total + 1) for _ in range(N + 1)]
dp[0][0] = 1
# dp[i][R]:=i番目まででRとなる場合の数

for i in range(N):
    for r in range(total + 1):
        if r - a[i] >= 0:
            dp[i + 1][r] += dp[i][r - a[i]]
        dp[i + 1][r] += 2 * dp[i][r]
        dp[i + 1][r] %= MOD
        # g, bに加算する分で、2回起こる
# print(dp)

single_circle = 0
for r in range(total + 1):
    if r >= (total / 2):
        single_circle += dp[N][r]
# print(single_circle)

'''(3)２円の積集合'''
if total % 2 == 0:
    dp2 = [[0] * (total + 1) for _ in range(N + 1)]
    dp2[0][0] = 1
    # dp[i][R]:=i番目まででRとなる場合の数

    for i in range(N):
        for r in range(int(total / 2) + 1):
            if r - a[i] >= 0:
                dp2[i + 1][r] += dp2[i][r - a[i]]
            dp2[i + 1][r] += dp2[i][r]
            dp2[i + 1][r] %= MOD
    # print(dp2)

two_circle_intersect = dp2[N][int(total / 2)] if total % 2 == 0 else 0

'''(3)３円の積集合'''
three_circle_intersect = 0

'''(4)解答'''
ans = 0

ans += U
ans %= MOD

ans -= 3 * single_circle
ans %= MOD

ans += 3 * two_circle_intersect
ans %= MOD

ans -= three_circle_intersect
ans %= MOD

print(ans)

Measured memory_bytes: 457096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  vector<int> m(3);

  rep(i, 3) {
    cin >> m[i];
  }

  std::sort(m.begin(), m.end());

  cout << m[0] + m[1] << endl;


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int N;
int* BIT;

void add(int loc,int value){

	BIT[loc] += value;

	loc += loc & -loc;

	while(loc <= N){
		BIT[loc] += value;
		loc += loc & -loc;
	}
}

int getSum(int loc){

	int sum = BIT[loc];

	loc -= loc & -loc;

	while(loc > 0){
		sum += BIT[loc];
		loc -= loc & -loc;
	}
	return sum;
}


char buf[400001],next_buf[400001];
int table[26],index[26],loc[26][200000],ruisekiwa[400000];
bool must_left[400000];


int main(){

	for(int i = 0; i < 26; i++){
		table[i] = 0;
		index[i] = 0;
	}

	int length,tmp;

	scanf("%s",buf);

	for(length = 0; buf[length] != '\0'; length++);

	for(int i = 0; i < length; i++){
		tmp = buf[i] - 'a';
		table[tmp]++;
		if(index[tmp] < length/2){
			loc[tmp][index[tmp]] = i;
			index[tmp]++;
		}
	}

	for(int i = 0; i < 26; i++){
		if(table[i]%2 == 1){
			printf("-1\n");
			return 0;
		}
	}

	for(int i = 0; i < length; i++)must_left[i] = 0;

	for(int i = 0; i < 26; i++){
		for(int k = 0; k < table[i]/2; k++){
			must_left[loc[i][k]] = true;
		}
	}

	ll ans = 0;

	int left_index = 0,right_index = 0;

	for(int i = 0; i < length; i++)ruisekiwa[i] = 0;
	for(int i = 0; i < length; i++){
		if(must_left[i] == false){
			next_buf[length/2+right_index++] = buf[i];
			ruisekiwa[i]++;
		}else{
			next_buf[left_index++] = buf[i];
		}
		if(i > 0){
			ruisekiwa[i] += ruisekiwa[i-1];
		}
		if(must_left[i]){
			ans += ruisekiwa[i];
		}
	}

	for(int i = 0; i < 26; i++)index[i] = 0;

	for(int i = 0; i < length/2; i++){
		tmp = next_buf[i]-'a';

		loc[tmp][(table[tmp]/2-1)-index[tmp]] = (length/2)-i;
		index[tmp]++;
	}

	for(int i = 0; i < 26; i++)index[i] = 0;

	int *right_half = new int[length/2];

	for(int i = 0; i < length/2; i++){
		tmp = next_buf[(length/2)+i]-'a';
		right_half[i] = loc[tmp][index[tmp]];
		index[tmp]++;
	}

	N = length/2;
	BIT = new int[N+1];

	for(int i = 0; i <= N; i++)BIT[i] = 0;

	for(int i = 0; i < N; i++){
		ans += i-getSum(right_half[i]);
		add(right_half[i],1);
	}

	printf("%lld\n",ans);

	return 0;
}

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

int main() {
    int n, h[100000], hight;
    bool flg;
    
    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> h[i];
    }
    
    flg = true;
    hight = h[0] - 1;
    for ( int i = 1; i < n; i++ ) {
        if ( h[i] < hight ) {
            flg = false;
        } else {
            h[i] = max(h[i]-1, hight);
            hight = max(hight, h[i]);
        }
    }
    
    if ( flg ) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    
    return (0);
}


Measured memory_bytes: 3976
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)

#include <cstdio>
#include <vector>
#include <cstring>
#include <climits>

using namespace std;

int main(){
    int A[5];
    int dis;

    REP(i, 5) {
        scanf("%d", &A[i]);
    }
    scanf("%d", &dis);

    int max = 0, min = 124;

    REP(i, 5) {
        max = max > A[i] ? max : A[i];
        min = min < A[i] ? min : A[i];
    }

    if ((max - min) > dis) {
        printf("%s\n", ":(");
    } else {
        printf("%s\n", "Yay!");
    }

}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

char data[101][101];

pair<int, int> search(pair<int, int> p);

int main()
{
    int n, m;

    while (cin >> n >> m, n || m) {
        for (int i = 0; i < n; i++) {
            cin >> data[i];
        }
        bool c[101][101] = {false};
        pair<int, int> pos = make_pair(0, 0);
        while (1) {
            pair<int, int> np = search(pos);
            if (np == pos) {
                cout << pos.second << " " << pos.first << endl;
                break;
            } else {
                pos = np;
            }
            if (c[pos.first][pos.second]) {
                puts("LOOP");
                break;
            } else {
                c[pos.first][pos.second] = true;
            }
        }
    }
    return 0;
}

pair<int, int> search(pair<int, int> p)
{
    if (data[p.first][p.second] == 'v') {
        return make_pair(p.first+1, p.second);
    } else if (data[p.first][p.second] == '^') {
        return make_pair(p.first-1, p.second);
    } else if (data[p.first][p.second] == '>') {
        return make_pair(p.first, p.second+1);
    } else if (data[p.first][p.second] == '<') {
        return make_pair(p.first, p.second-1);
    } else {
        return p;
    }
}

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

int main(){
    long long int N,X,count=1;
    cin >>N>>X; long long int M[N];
    for(long long int i=0;i<N;i++){
    cin >> M[i];
    }
    for(long long int i=0;i<N;i++){
       if(i==0&&M[0]<=X){
          count++;
          continue;
       }
       M[i]+=M[i-1];
       if(M[i]<=X){
          count++;
          continue;
       }
    }
    cout <<count;
    
 }



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] a = new int[n], b = new int[n];
			IntStream.range(0, n).forEach(i -> {
				a[i] = scanner.nextInt();
				b[i] = scanner.nextInt();
			});
			Arrays.sort(a);
			Arrays.sort(b);
			System.out.println(middle(b) - middle(a) + 1);
		}
	}

	/**
	 * 配列の中央値を計算する
	 * 
	 * <pre>
	 * 配列の個数Nが奇数のときの中央値は a[N/2]
	 * 配列の個数Nが偶数のときの中央値は a[(N-1)/2]+a[(N-1)/2+1] （本来の中央値の2倍）
	 * </pre>
	 * 
	 * @param a 配列
	 * @return 配列の中央値
	 */
	private static int middle(int[] a) {
		if (0 == (a.length & 1)) {
			return a[(a.length - 1) / 2] + a[(a.length - 1) / 2 + 1];
		} else {
			return a[a.length / 2];
		}
	}
}


Measured memory_bytes: 61952
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011

struct point {
    ll x, y;
    int id;

    bool operator<(const point& who)const {
        return mp(x, y) < mp(who.x, who.y);
    }
};

int n, a, b, i;
ll x, y, D;
point P[maxN];

vector<int> list[maxN];
ll cnt[maxN];
int addit[maxN];

ll ans;
bool us[maxN];

ll abss(ll x) {
    if (x < 0)
        return -x;
    return x;
}

void add_edge(int x, int y) {
    list[x].pb(y);
    list[y].pb(x);
}

void solve(ll DX, ll DY) {
    int i;

    sort(P + 1, P + n + 1);
    memset(addit, 0, sizeof(addit));

    for (i = 1; i <= n; i++) {
        int posl = lower_bound(P + 1, P + n + 1, (point){P[i].x - DX, P[i].y - DY, -1}) - P;
        int posr = upper_bound(P + 1, P + n + 1, (point){P[i].x - DX, P[i].y + DY, -1}) - P;

        if (posl >= posr) continue;

        cnt[P[i].id] += posr - posl;

        add_edge(P[i].id, P[posl].id);
        addit[posl]++;
        addit[posr - 1]--;
    }

    for (i = 1; i <= n; i++) {
        addit[i] += addit[i - 1];
        if (addit[i] == 0) continue;

        add_edge(P[i].id, P[i + 1].id);
    }
}

void dfs(int node) {
    us[node] = true;
    ans += cnt[node];

    for (auto to : list[node])
        if (!us[to])
            dfs(to);
}

int main()
{
 //   freopen("test.in","r",stdin);

    scanf("%d%d%d", &n, &a, &b);
    for (i = 1; i <= n; i++) {
        scanf("%lld%lld", &x, &y);
        P[i] = {x - y, x + y, i};
    }

    D = max(abss(P[a].x - P[b].x), abss(P[a].y - P[b].y));

    solve(D, D);

    for (i = 1; i <= n; i++)
        swap(P[i].x, P[i].y);

    solve(D, D - 1);

    dfs(a);
    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 15104
import scala.io.StdIn._
object Main extends App {
    val Array(n, t) = readLine().split("\\s").map(_.toInt)

    var min_cost = 9999
    for (_ <- 1 to n) {
      val Array(c,ti) = readLine().split("\\s").map(_.toInt)
      if (ti<=t){
        min_cost = List(min_cost,c).min
      }
    }
    if (min_cost==9999){
      println("TLE")
    } else{
      println(min_cost)
    }
}

Measured memory_bytes: 25536
import math
while True:
  a=float(input())
  b=float(input())
  if a == 0 and b ==0: break
  hoge= (a/2)**2+b**2
  hoge=float(math.sqrt(hoge))
  ans=float(a*hoge*2+a*a)
  print "%5f"%(ans)

Measured memory_bytes: 4404
N, M = map(int, input().split(" "))
data = []
for i in range(N):
  A = list(map(int, input().split(" ")))
  A_ = sorted(A[1:])
  data.append(A_)
  
counter = 0  
for m in range(M):
  flag = 1
  for d in data:
    if m+1 in d:
      flag *= 1
    else:
      flag *= 0
  if flag == 1:
    counter += 1

print(counter)
      

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

int main(){
  string S;
  cin >> S;
  bool flag = true;
  if(S.at(0) != 'A') flag = false;
  int n = S.size();
  int counter = 0;
  int c;
  for(int i = 2; i < n-1; i++){
    if(S.at(i) == 'C'){
      counter++;
      c = i;
    }
  }
  if(counter != 1) flag = false;

  for(int i = 0; i < n; i++){
    if(i != c && i != 0 && (S.at(i) < 'a' || S.at(i) > 'z')) flag = false;
  }

  if(flag) cout << "AC" << endl;
  else cout << "WA" << endl;

}

Measured memory_bytes: 256