akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def ti(): return tuple(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

from functools import reduce

def gcd(a, b):
    if a < b:
        a, b = b, a
    r = a % b
    if r == 0:
        return b
    return gcd(b, r)

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def table(n:int, p=10**9+7):
    global fact, factinv, inv
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, n+1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)

def main():
    N = ii()
    A = ti()
    P = 10**9 + 7
    lcm_a = lcm_list(A) % P

    #逆元テーブルの作成
    N = 10**6+1
    inv_t = [0]+[1]
    for i in range(2,N):
        inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

    ans = 0
    for num in A:
        ans = (ans + inv_t[num] * lcm_a) % P
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 115748
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
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 ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

int main(){
  ll n;cin>>n;
  ll k;cin>>k;
  VL a(n);
  REP(i,n){
    cin>>a[i];
    a[i]--;
  }
  ll now=0;
  vector<int> past(n,0);
  past[0]=1;
  ll dep=1;
  ll len=0;
  ll len1=0;
  for(int i=0;i<k;i++){
    now=a[now];
    dep++;
    if(i==k-1){
      cout<<now+1<<endl;
      return 0;
    }
    if(past[now]==0){
      past[now]=dep;
    }else{
      len=dep-past[now];
      len1=past[now]-1;
      break;
    }
  }
  k-=len1;
  k%=len;
  for(int i=0;i<k;i++){
    now=a[now];
  }
  cout<<now+1<<endl;
}

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

using namespace std;

int main()
{
    double x;  cin >> x;
    double ini = 100;
    int cont = 0;
    while (ini < x )
    {
        ini = (ini + floor(ini/100));
        // cout << ini << "\n";
        cont++;
    }

    cout << cont << "\n";
    
}

Measured memory_bytes: 3684
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
ll N, K;
ll A[200000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    sort(A, A+N);
    ll l = (-1e+18);
    l--;
    ll r = (1e+18);
    r++;
    // cout << r << endl;
    // c以下をカウント
    while(r-l > 1){
        ll c = (l+r)/2;
        ll cnt = 0;
        for(ll i = 0; i < N-1; i++){
            if(A[i] == 0){
                if(c >= 0) cnt += (N-i-1);
            }else{
                if(A[i] < 0){
                    ll u = i+1, v = N-1;
                    // 単調減少
                    if(A[u]*A[i] <= c) {
                        cnt += (N-i-1);
                        continue;
                    }
                    if(A[v]*A[i] > c) continue;
                    while(v-u > 1){
                        ll x = (u+v)/2;
                        if(A[x]*A[i] > c) u = x;
                        else v = x;
                    }
                    cnt += (N-v);
                }else{
                    ll u = i+1, v = N-1;
                    // 単調増加
                    if(A[v]*A[i] <= c) {
                        cnt += (N-i-1);
                        continue;
                    }
                    if(A[u]*A[i] > c) continue;
                    while(v-u > 1){
                        ll x = (u+v)/2;
                        if(A[x]*A[i] <= c) u = x;
                        else v = x;
                    }
                    cnt += (u-i);
                }
            }
        }
        // cout << c << ' ' << cnt << endl;
        if(cnt >= K) r = c;
        else l = c;
    }
    cout << r << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(){
  
  int i,count=0;
  char s[4];
  
  scanf("%s",s);
  
  for(i=0;i<3;i++){
  if(s[i]=='1'){
    count++;
    }
  }
  printf("%d",count);
return 0;  
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main()
{
	int N, M;
	cin >> N >> M;
	int left = 1, right = N;

	rep(i, M)
	{
		int L, R;
		cin >> L >> R;
		if (left<L) left = L;
		if (right > R)right = R;
	}
	int ans = right -left + 1;
	if (ans < 0) cout << 0;
	else cout << ans;
	return 0;
}


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

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

const int MAXN { 52 }, MAXM { 1 << 21 };

ll st[MAXN][MAXM];

vector<ii> adj[MAXN];

ll dp(int i, int mask, int N, vector<set<int>>& ys, int M)
{
#ifdef DEBUG
//cout << "calculando dp[" << i << "][" << mask << "]..." << endl;
#endif
    if (i == N - 1)
        return mask == ((1 << M) - 1) ? 1 : 0;

    if (st[i][mask] != -1)
        return st[i][mask];

    ll res = dp(i + 1, mask, N, ys, M);

    int nmask = mask;

    for (int k = 0; k < M; ++k)
        if (ys[k].count(i))
            nmask |= (1 << k);

    res += dp(i + 1, nmask, N, ys, M);

    st[i][mask] = res;
    return res;
}

set<int> path(int s, int f, int N)
{
    vector<int> found(N + 1, 0), ps(N + 1), es(N + 1);
    queue<int> q;

    q.push(s);
    found[s] = 1;

    while (not q.empty())
    {
        auto u = q.front();
        q.pop();

        if (u == f)
            break;

        for (auto p : adj[u])
        {
            auto v = p.first, e = p.second;

            if (not found[v])
            {
                found[v] = 1;
                ps[v] = u;
                es[v] = e;

                q.push(v);
            }
        }
    }

    set<int> path;
    int p = f;

    while (p != s)
    {
        path.insert(es[p]);
        p = ps[p];
    }

#ifdef DEBUG
cout << "path from u = " << s << " to " << f << " = ";
for (auto x : path)
    cout << x << ' ';
cout << endl;
#endif

    return path;
}

ll solve(int N, int M, const vector<ii>& ms)
{
    memset(st, -1, sizeof st);

    vector<set<int>> ys;

    for (int i = 0; i < M; ++i)
        ys.push_back(path(ms[i].first, ms[i].second, N));

    return dp(0, 0, N, ys, M);
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    vector<ll> xs(N);

    for (int i = 0; i < N - 1; ++i)
    {
        int a, b;
        cin >> a >> b;

        adj[a].push_back(ii(b, i));
        adj[b].push_back(ii(a, i));
    }

    int M;
    cin >> M;

    vector<ii> ms(M);

    for (int i = 0; i < M; ++i)
        cin >> ms[i].first >> ms[i].second;

    auto ans = solve(N, M, ms);

    cout << ans << '\n';

    return 0;
}


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

using ll = long long;

signed main(){
  int n;
  cin>>n;
  vector<int> as(n);
  for(int i=0;i<n;i++) cin>>as[i];

  using P = pair<int, int>;
  vector<P> vp;
  for(int i=0;i<n;i++) vp.emplace_back(as[i],i);
  sort(vp.rbegin(),vp.rend());

  ll ans=0;
  multiset<int> ss({-1,-1,n,n});
  for(auto p:vp){
    int k=p.second;
    ll way=0;

    int w=*----ss.upper_bound(k);
    int x=*  --ss.upper_bound(k);
    int y=*    ss.upper_bound(k);
    int z=*  ++ss.upper_bound(k);

    way+=(ll)abs(w-x)*(ll)abs(k-y);
    way+=(ll)abs(x-k)*(ll)abs(z-y);

    ans+=way*(ll)as[k];
    ss.emplace(k);
  }

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


Measured memory_bytes: 6132
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;
const ll INF = 1 << 29;

ll C[200][200] = {};
int r[10] = {};
bool al[200] = {};
int N, M, R;
ll dmin = INF;

void bfs(int now,int count,ll d) {
	if (count == R) {
		dmin = min(dmin, d);
		return;
	}

	if (count == 0) {
		REP(i, R) {
			if (al[r[i] - 1]) {
				al[r[i] - 1] = false;
				bfs(r[i], 1, 0);
				al[r[i] - 1] = true;
			}
		}
	}

	if (count != 0 && count != R) {
		REP(i, R) {
			if (al[r[i] - 1]) {
				al[r[i] - 1] = false;
				bfs(r[i], count + 1, d + C[now - 1][r[i] - 1]);
				al[r[i] - 1] = true;
			}
		}
	}

	return;
}


int main() {
	cin >> N >> M >> R;
	REP(i, R) {
		cin >> r[i];
		al[r[i] - 1] = true;
	}
	REP(i, N) REP(j, N) C[i][j] = C[j][i] = INF;
	REP(i, M) {
		int a, b;
		ll c;
		cin >> a >> b >> c;
		C[a - 1][b - 1] = C[b - 1][a - 1] = c;
	}

	//REP(i, 200) cout << i << " " << al[i] << endl;
	REP(k, N) REP(i, N) REP(j, N) C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
	
	bfs(0, 0, 0LL);
	cout << dmin << endl;
	//cin >> N >> M >> R;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

vector<string> split(const string &str, char sep)
{
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

int n;

map<string, vector<string>> mss;
set<string> used;
set<string> ss;

void solve(string s) {
	if (mss.find(s) == mss.end()) {
		ss.insert(s);
		//cout << "!!" << ss.size() << endl;
		return;
	}
	rep(i, mss[s].size()) {
		if (used.find(mss[s][i]) == used.end())solve(mss[s][i]);
		used.insert(mss[s][i]);
	}
}

int main() {
	while (cin >> n&&n) {
		used.clear();
		mss.clear();
		ss.clear();
		string s, ans;
		rep(i, n) {
			cin >> s;
			rep(j, s.size()) {
				if (s[j] == ':')s[j] = ',';
			}
			s.pop_back();
			vector<string> vs = split(s, ',');
			reverse(ALL(vs));
			string buf = vs.back();
			if (i == 0)ans = buf;
			vs.pop_back();
			mss[buf] = vs;
		}
		solve(ans);
		cout << ss.size() << endl;
	}
}


Measured memory_bytes: 3400
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
 
    int h, w;
    cin >> h >> w;
    char C[h][w];
    int dp[h][w] = {};
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> C[i][j];
            dp[i][j] = 1e9;
        }
    }
 
    dp[0][0] = C[0][0] == '#';
 
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(i - 1 >= 0){
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + (C[i][j] != C[i - 1][j]));
            }
            if(j - 1 >= 0){
                dp[i][j] = min(dp[i][j], dp[i][j - 1] + (C[i][j] != C[i][j - 1]));
            }
        }
    }
 
    int ans = dp[h - 1][w - 1];
    if(C[0][0] == '.' and C[h - 1][w - 1] == '.'){
        ans /= 2;
    }else if(C[0][0] == '.' and C[h - 1][w - 1] == '#'){
        ans = (ans + 1) / 2;
    }else if(C[0][0] == '#' and C[h - 1][w - 1] == '.'){
        ans /= 2;
    }else{
        ans = (ans + 1) / 2;
        
    }
 
    cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>


int main( void )
{
	int N ;
	while( scanf( "%d" ,&N ) != EOF )
	{
		long cnt[ 4 + 1 ][ 50 + 1 ] = { 1 } ;

		int i ,j ,k ;
		for( i = 1 ; i <= 4 ; ++i )
		{
			for( j = 0 ; j <= N ; ++j )
			{
				if( cnt[ i - 1 ][ j ] > 0 )
				{
					for( k = 0 ; k <= 9 ; ++k )
					{
						if( j + k < 50 + 1 )
						{
							cnt[ i ][ j + k ] += cnt[ i - 1 ][ j ] ;
						}
					}
				}
			}
		}

		printf( "%ld\n" ,cnt[ 4 ][ N ] ) ;
	}

	return 0 ;
}


Measured memory_bytes: 1972
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(int, n);
  Cins(int, n, a);
  set<string> st;

  int cnt = 0;
  rep(i, n) {
    if (1 <= a[i] && a[i] <= 399)
      st.insert("gray");
    else if (a[i] <= 799)
      st.insert("brown");
    else if (a[i] <= 1199)
      st.insert("green");
    else if (a[i] <= 1599)
      st.insert("light blue");
    else if (a[i] <= 1999)
      st.insert("blue");
    else if (a[i] <= 2399)
      st.insert("yellow");
    else if (a[i] <= 2799)
      st.insert("orange");
    else if (a[i] <= 3199)
      st.insert("red");
    else
      cnt++;
  }

  int mn = sz(st);
  int mx = mn + cnt;
  if (mn == 0) mn = 1;

  cout << mn << " " << mx << endl;
}

Measured memory_bytes: 256
using System;
class _0021
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            string[] data = Console.ReadLine().Split();
            Console.WriteLine((slant(new Point(double.Parse(data[0]), double.Parse(data[1])), new Point(double.Parse(data[2]), double.Parse(data[3]))) == slant(new Point(double.Parse(data[4]), double.Parse(data[5])), new Point(double.Parse(data[6]), double.Parse(data[7])))) ? "YES" : "NO");
        }
    }
    public static double slant(Point p1, Point p2)
    {
        return (p2.getY - p1.getY) / (p2.getX - p1.getX);
    }
}
class Point
{
    private double x, y;
    public Point() { x = 0.0; y = 0.0; }
    public Point(double i, double j) { x = i; y = j; }
    public double getX { get { return x; } }
    public double getY { get { return y; } }
}

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


int main()
{
    int n,W;
    cin>>n>>W;
    int w[n],v[n];
    for(int i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
    long long int dp[n+1][W+1];
    for(int i=0;i<=n;i++)
        dp[i][0]=0;
    for(int j=0;j<=W;j++)
        dp[0][j]=0;
    
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=W;j++)
        {
            if(w[i-1]<=j)
                dp[i][j]=max(dp[i-1][j],(v[i-1]+dp[i-1][j-w[i-1]]));
            else
                dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][W]<<endl;

}

Measured memory_bytes: 82340
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
	//作るときはParentの値を全て-1にする
	//こうするとすべてバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}
	//AとBをくっつける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついているからくっつけない
			return false;
		}
		//大きい方(A)に小さいほう(B)をくっつけたい
		//大小が逆だったらひっくり返しちゃう
		if (size(A) < size(B)) swap(A, B);
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
	//AとBが同じグループにいるか
	bool same(int A, int B) { return root(A) == root(B); }
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	vector<int> res(100001);
	vector<vector<int>> b(n);
	UnionFind Uni(n);
	rep(i, m) {
		int a, b; cin >> a >> b;
		a--; b--;
		Uni.connect(a, b);
		res[a]++; res[b]++;
	}
	rep(i, k) {
		int c, d; cin >> c >> d;
		c--; d--;
		b[c].emplace_back(d);
		b[d].emplace_back(c);
	}
	rep(i, n) {
		int ans = Uni.size(i) - 1 - res[i];
		for (auto& c : b[i]) if (Uni.same(c, i)) ans--;
		cout << ans << (i == n - 1 ? "\n" : " ");
	}
	return 0;
}


Measured memory_bytes: 6784
s=input()
t=input()
ans=0
s1=s
ans=0
flag=1
for i in t:
    if i not in s1:
        flag=0
if flag==0:
    print(-1)
else:
    for i in t:
        if i in s1:
            ans+=s1.index(i)+1
            s1=s1[s1.index(i)+1:]
        else:
            ans = ((ans+len(s)-1)//len(s))*len(s) 
            ans+=s.index(i)+1   
            s1=s[s.index(i)+1:]
    print(ans)

Measured memory_bytes: 3540
#include<bits/stdc++.h>
long long i,a,N,s,A=INT_MAX,l,r,S[100002];int main(){scanf("%ld%ld",&N,&s);for(;i<N;i++){scanf("%ld",&a);S[i+1]+=S[i]+a;}for(;;){if(S[r]-S[l]>=s){A=std::min(A,r-l);l++;}else r++;if(r>N){if(A==INT_MAX)A=0;printf("%ld\n",A);return 0;}}}

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

int main() {
  int N , answer;
  answer = 1; 
  cin >> N;
  
   vector<int> vec(N);
   for (int i = 0; i < N; i++) {
   cin >> vec.at(i);
   }
   sort(vec.begin(), vec.end());
   reverse(vec.begin(),vec.end());
  
   for (int i = 1; i < N; i++) {
     if(vec.at(i) != vec.at(i-1)){
     answer ++;
     }
   
   }
  cout << answer;
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> now(3,0);
    for(int i=0;i<n;i++)
    {
        vector<int> nxt(3,0);
        int a,b,c;
        cin >> a >> b >> c;
        nxt[0]=max(now[1],now[2])+a;
        nxt[1]=max(now[0],now[2])+b;
        nxt[2]=max(now[0],now[1])+c;
        now=nxt;
    }
    cout << max(max(now[0],now[1]),now[2]) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, s;
  cin >> k >> s;
  int cnt = 0;
  for(int i=0; i<=k; i++){
    for(int j=0; j<=k; j++){
      int t = s - i -j;
      if(t>=0 && t<=k) cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
A = []
for i in range(N):
  key,value = map(int,input().split())
  dic = {"key":key,"value":value}
  A.append(dic)
sorted_A = sorted(A, key=lambda x:x['key'])
count = 1;
k = 0
for i in range(N):
  k += sorted_A[i].get("value")
  if k < M:
    count += 1
  else:
    break
result = 0
baught = 0
for i in range(count):
  baught += sorted_A[i].get("value")
  if baught < M:
    result += sorted_A[i].get("key") * sorted_A[i].get("value")
  else:
    result += sorted_A[i].get("key") * (sorted_A[i].get("value") - baught + M)
print(result)

Measured memory_bytes: 42352
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=10**9+7

h,n=map(int,input().split())
a=list(map(int,input().split()))
if sum(a)>=h:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 78400
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.La;
		long p=s[2]*s[3]/Gcd(s[2],s[3]),ans=0;
		long a=s[0]/s[2],b=s[1]/s[2];
		a*=s[2];
		b*=s[2];
		if(a<s[0]){a+=s[2];}
		ans+=(b-a)/s[2]+1;
		a=s[0]/s[3];b=s[1]/s[3];
		a*=s[3];
		b*=s[3];
		if(a<s[0]){a+=s[3];}
		ans+=(b-a)/s[3]+1;
		a=s[0]/p;b=s[1]/p;
		a*=p;
		b*=p;
		if(a<s[0]){a+=p;}
		ans-=(b-a)/p+1;
		Console.WriteLine("{0}",s[1]-s[0]+1-ans);
	}
	static long Gcd(long a,long b){
		long c=Math.Max(a,b)%Math.Min(a,b);
		b=Math.Min(a,b);
		while(c!=0){
			a=b%c;
			b=c;
			c=a;
		}
		return b;
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}


Measured memory_bytes: 13268
from collections import Counter, defaultdict

MOD = 10 ** 9 + 7
N = int(input())
A = list(map(int, input().split()))

max_A = max(A)
f = list(range(max_A + 1))
for i in range(2, int(max_A ** 0.5) + 1):
    if f[i] == i:
        f[i::i] = [i] * (max_A // i)


def factors(x):
    factor = defaultdict(int)
    while x != 1:
        factor[f[x]] += 1
        x //= f[x]
    return factor


L = defaultdict(int)
for i in range(N):
    Ai = factors(A[i])
    for p, index in Ai.items():
        L[p] = max(L[p], index)
lcm = 1
for p, index in L.items():
    if index == 0:
        continue
    lcm *= pow(p, index, MOD)
    lcm %= MOD

ans = 0
for Ai in A:
    ans += lcm * pow(Ai, MOD - 2, MOD)
    ans %= MOD
print(ans % MOD)


Measured memory_bytes: 51828
import java.util.Scanner;
//import java.io.*;
//import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		//InputStreamReader is = new InputStreamReader(System.in);
		//BufferedReader br = new BufferedReader(is);
		int A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();
		int D = scan.nextInt();
		int P = scan.nextInt();
		int x = A*P;
		int y = B;
		if(P > C){
			y += (P-C)*D;
		}
		if(x < y){
			System.out.println(x);
		}else{
			System.out.println(y);
		}
	}
}

Measured memory_bytes: 26288
N,W=list(map(int,input().split()))
weights=[]
value=[]
for i in range(N):
    w,v=list(map(int,input().split()))
    weights.append(w)
    value.append(v)
t=sum(value)
maxa=10**18
dp=[maxa for i in range(t+1)]
dp[0]=0
for i in range(N):
    for val in range(t-value[i],-1,-1):
       dp[val+value[i]] = min(dp[val+value[i]],dp[val]+weights[i])
ans=0
for i in range(t+1):
    if(dp[i]<=W):
        ans=max(ans,i)
# print(dp)
print(ans)

Measured memory_bytes: 75776
$_=<>;($a,$b)=glob<>;s#F+#push@{$`=~y/T//&1},length$&#ge;$a-=/^1/&&shift@0;$s=$_?b:a,map$$s+=$$s>0?-$_:$_,sort{$b-$a}@$_ for 0,1;print$a|$b?No:Yes

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX





void solve()
{
  int n;
  cin >> n;
  int x, y;
  cin >> x >> y;
  int ans[n+1] = {0};

  for(int i=1; i<=n; i++)
    rep(j,i+1,n)
    {
      int d = j-i;
      int d1 = abs(i-x)+abs(j-y)+1;
      ans[min(d, d1)]++;
    }
  rep(i,1,n-1)
  {
    cout << ans[i] << endl;
  } 


}

signed main()
{
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}


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

#define int long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define ff first
#define ss second

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

const int inf = 2e18;
const int ninf = -2e18-5;
const int mod = 1e9 + 7;

vector<int> g[100010];
vector<int> visited(100010, -1);

void dfs(int u){
	int cur = 0;
	for(auto v: g[u]){
		if (visited[v]==-1) dfs(v);
		cur = max(cur, visited[v]+1);
	}
	visited[u] = cur;
}

signed main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	int n, m; cin>>n>>m;
	for(int i=0; i<m; i++){
		int x, y; cin>>x>>y;
		g[x-1].pb(y-1);
	}
	int ans = 0;
	for(int i=0; i<n; i++){
		if(visited[i]==-1) dfs(i);
		ans = max(ans, visited[i]);
	}
	cout<<ans<<endl;
	return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

int n,k;

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n >> k;

  cout << n - k + 1 << endl;


  return 0;
}


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

#define PI 3.14159265358979
#define EPS 10e-8

typedef complex<double> Point;

Point ps[4];

int main() {
  while (1) {
    for (int i=0; i<4; i++) {
      double x, y;
      if (scanf("%lf%lf", &x, &y) != 2) return 0;
      ps[i] = Point(x, y);
    }
  
    double theta = abs(arg((ps[0]-ps[1])/(ps[2]-ps[3])));
    if (PI/2 - EPS < theta && theta < PI/2 + EPS) puts("YES");
    else puts("NO");
  }
}

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

using namespace std;

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

		vector<vector<int>>list(n, vector<int>(n, 0));
		int number;

		for (int i = 0;i < n;i++) {
			cin >> number;
			for (int j = 0;j < number;j++) {
				int codename;
				cin >> codename;
				list[i][codename - 1] = 1;
			}
		}//list[a][b]:a know b

		cin >> number;
		
		vector<int>ans(n,1);
		int leaked;
		for (int i = 0;i < number;i++) {
			cin >> leaked;
			for (int j = 0;j < n;j++) {
				if (list[j][leaked - 1] == 0) ans[j] = 0;
			}
		}//who is imposible
		int sum = 0,telltale;

		for (int i = 0;i < n;i++) {
			sum += ans[i];
			if (ans[i] == 1) telltale = i + 1;
		}

		if (sum == 1)cout << telltale << endl;
		else cout << -1 << endl;

	}
	return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
 
using namespace std;
 
#define MAX 25
 
int H,W,mem;
char field[MAX][MAX];
bool visited[MAX][MAX][16][4];
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
 
void Nextpos(int &y,int &x){
    if(x >= W){
	x = 0;
    }else if(y >= H){
	y = 0;
    }else if(x < 0){
	x = W-1;
    }else if(y < 0){
	y = H-1;
    }
}
 
bool solve(int y,int x,int dir){
    if(x >= 0 && field[y][x] == '@') return true;
    if(x >= 0 && visited[y][x][mem][dir]) return false;
    if(x >= 0) visited[y][x][mem][dir] = true;
 
    int nx = x + dx[dir], ny = y + dy[dir];
    Nextpos(ny,nx);
   
    if(isdigit(field[ny][nx])){
	mem = field[ny][nx] - '0';
    }else{
	switch(field[ny][nx]){
	case '>':
	    dir = 0;
	    break;
	case 'v':
	    dir = 1;
	    break;
	case '<':
	    dir = 2;
	    break;
	case '^':
	    dir = 3;
	    break;
	case '_':
	    dir = (mem == 0 ? 0 : 2);
	    break;
	case '|':
	    dir = (mem == 0 ? 1 : 3);
	    break;
	case '?':
	    for(int i = 0 ; i < 4 ; i++){
		if(solve(ny,nx,i)) return true;
	    }
	    break;
	case '+':
	    mem = (mem == 15 ? 0 : mem+1);
	    break;
	case '-':
	    mem = (mem == 0 ? 15 : mem-1);
	    break;
	}
    }
    if(solve(ny,nx,dir)) return true;
    return false;
}
 
int main(){
    cin >> H >> W;
    for(int i = 0 ; i < H ; i++){
	for(int j = 0 ; j < W ; j++){
	    cin >> field[i][j];
	}
    }
    mem = 0;
    memset(visited,false,sizeof(visited));
    cout << (solve(0,-1,0) ? "YES" : "NO") << endl;
    return 0;
}

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

public class Program
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var vals = Enumerable.Range(0, n).Select(x => Console.ReadLine().Split(' ').Select(y => long.Parse(y)).ToArray()).ToArray();
        var dp = new long[n,3];
        for (int i = 0; i < 3; i++)
        {
            dp[0, i] = vals[0][i];
        }
        for (int i = 1; i < n; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                for (int k = 0; k < 3; k++)
                {
                    if (j == k)
                    {
                        continue;
                    }
                    dp[i, j] = chmax(dp[i, j], dp[i - 1, k] + vals[i][j]);
                }
            }
        }
        Console.WriteLine(Enumerable.Range(0, 3).Select(x => dp[n - 1, x]).Max());
    }

    public static long chmin(long x, long y)
    {
        return x > y ? y : x;
    }

    public static long chmax(long x, long y)
    {
        return x > y ? x : y;
    }
}

Measured memory_bytes: 29616
/*
  AOJ 2565
  Title:Broken Audio Signal
  @kankichi573
*/
#include <stdio.h>
#include <limits.h>
#include <ctype.h>
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
int N,a[1000],x[1000];

void solve()
{
  int i,up,low,none_f;

  up=INT_MAX;
  low=INT_MIN;
  none_f=0;
  for(i=0;i<N-1;i++)
    {
      if(x[i]==-1)  // x
	{
	  if(x[i+1]==-1)
	    {
	      none_f=-1;
	      break;
	    }
	  else
	    {
	      if((i%2)==0)
		up=min(up,a[i+1]);
	      else
		low=max(low,a[i+1]);
	    }
	}
      else        // number
	{
	  if(x[i+1]==-1)
	    {
	      if((i%2)==1)
		up=min(up,a[i]);
	      else
		low=max(low,a[i]);
	    }
	  else
	    {
	      if((i%2)==1)
		{
		if(a[i]<=a[i+1])
		  {
		    none_f=-1;
		    break;
		  }
		}
	      else
		{
		    if(a[i]>=a[i+1])
		      {
			none_f=-1;
			break;
		      }
		}		 
	    }
	}
    }

  //printf("UP=%d low=%d\n",up,low);
   if(low+2>up || none_f)
    {
      printf("none\n");
      return;
    }
   else if(low+2==up)
    {
      printf("%d\n",(low+up)/2);
      return;
    }

 AMB:
    printf("ambiguous\n");

}
dump()
{
  int i;
  
  for(i=0;i<N;i++)
    if(x[i])
      printf("x ");
    else
      printf("%d ",a[i]);
  printf("\n");
}
main()
{
  int i;
  char c;

  while(scanf("%d ",&N) && N)
    {
      for(i=0;i<100;i++)
	a[i]=x[i]=0;

      //      printf("N=%d\n",N);
      for(i=0;i<N;i++)
	{
	LOOP:
	  c=fgetc(stdin);
	  if(!isprint(c) || isspace(c))
	    goto LOOP;
	  else if(c=='x')
	    x[i]=-1;
	  else
	    {
	      x[i]=0;
	      ungetc(c,stdin);
	      scanf("%d ",&a[i]);
	    }
	}
      //dump();
      solve();
    }
  return(0);
}

Measured memory_bytes: 628
n = int(input())
A = list(int(x) for x in input().split())
m = 1000
k = 0

last = n-1
tmp = A[n-1]
for i in reversed(range(n)):
    if tmp > A[i]:
        last = i + 1
        break
    tmp = A[i]

for i in range(n):
    if i == last:
        m += A[i] * k
        break
    elif i + 1 <= last and A[i] < A[i + 1]:
        k += m // A[i]
        m -= A[i] * (m // A[i])
    elif i + 1 <= last and A[i] > A[i + 1]:
        m += A[i] * k
        k = 0


print(m)

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


struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
  int p;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL) x=x->left;
  return x;

}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){
  while(u!=NIL&&k!=u->key){
    if(k<u->key) u=u->left;
    else u=u->right;
  }
  return u;

}

Node treeSuccessor(Node x){
  if(x->right!=NIL) return treeMinimum(x->right);
  Node y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
   Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y=z;
  else y = treeSuccessor(z);
  if(y->left != NIL){
    x=y->left;
  }
  else{
    x=y->right;
      }
  if(x!=NIL)
    x->parent=y->parent;

  if(y->parent==NIL)
    root=x;
  else {
    if(y==y->parent->left)
      y->parent->left=x;
    else
      y->parent->right=x;
  }
  if(y!=z)
    z->key=y->key;

  free(y);

}

void insert(int k){
  Node y = NIL;
  Node x = root;
 Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;



  
  while (x != NIL){
    y = x; // 親を設定
    if(z->key < x->key)
    x = x->left; // 左の子へ移動
    else 
      x = x->right; // 右の子へ移動
	       }
  z->parent = y;

  if(y == NIL) // T が空の場合
    root = z;
  else if (z->key < y->key)
    y->left = z ;// z を y の左の子にする
  else 
      y->right = z ;// z を y の右の子にする
  





}

void inorder(Node u){
  if(u== NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
  
}

void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int i,n,x;
  char com[20];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",com);

    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
      
  }

  return 0;

}








Measured memory_bytes: 20484
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    for(int i = 0; i < n; i++){
        int c;
        cin >> c;
        c -= (i+1);
        a[i] = c;
    } 
    b = a;
    sort(b.begin(),b.end());
    int mid = b[n/2];
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ans += abs(a[i]-mid);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
int W, Q, a, b, e, x[107], d[107], l[107], r[107]; char c;
int main() {
	while (cin >> W >> Q, W | Q) {
		for (int i = 0; i < 107; i++) x[i] = d[i] = l[i] = r[i] = 0; e = 0;
		for (int i = 0; i < Q; i++) {
			cin >> c >> a;
			if (c == 's') {
				cin >> b;
				int f = 0;
				for (int j = 0; j <= W - b; j++) {
					if (find(x + j, x + j + b, 1) == x + j + b) {
						fill(x + j, x + j + b, 1); d[e] = a; l[e] = j, r[e] = j + b;
						cout << j << endl; f = 1; e++; break;
					}
				}
				if (!f) cout << "impossible" << endl;
			}
			else {
				for (int j = 0; j < e; j++) {
					if (d[j] == a) fill(x + l[j], x + r[j], 0);
				}
			}
		}
		cout << "END" << endl;
	}
}

Measured memory_bytes: 3092
// 2011/09/08 Tazoe

#include <iostream>
#include <string>
using namespace std;

void North(int D[6])
{
	int tmp = D[0];
	D[0] = D[1];
	D[1] = D[5];
	D[5] = D[3];
	D[3] = tmp;
}

void East(int D[6])
{
	int tmp = D[0];
	D[0] = D[4];
	D[4] = D[5];
	D[5] = D[2];
	D[2] = tmp;
}

void West(int D[6])
{
	int tmp = D[0];
	D[0] = D[2];
	D[2] = D[5];
	D[5] = D[4];
	D[4] = tmp;
}

void South(int D[6])
{
	int tmp = D[0];
	D[0] = D[3];
	D[3] = D[5];
	D[5] = D[1];
	D[1] = tmp;
}

void Right(int D[6])
{
	int tmp = D[1];
	D[1] = D[2];
	D[2] = D[3];
	D[3] = D[4];
	D[4] = tmp;
}

void Left(int D[6])
{
	int tmp = D[1];
	D[1] = D[4];
	D[4] = D[3];
	D[3] = D[2];
	D[2] = tmp;
}

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int D[6] = {1, 2, 3, 5, 4, 6};
		int sum = D[0];
		for(int i=0; i<n; i++){
			string str;
			cin >> str;

			if(str=="North")
				North(D);
			else if(str=="East")
				East(D);
			else if(str=="South")
				South(D);
			else if(str=="West")
				West(D);
			else if(str=="Right")
				Right(D);
			else if(str=="Left")
				Left(D);

			sum += D[0];
		}

		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 0
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	static final double INF = 4e9;
	void main() {
		int xs = sc.nextInt();
		int ys = sc.nextInt();
		int xt = sc.nextInt();
		int yt = sc.nextInt();
		int n = sc.nextInt();
		int[] xx = new int[n + 2];
		int[] yy = new int[n + 2];
		int[] rr = new int[n + 2];
		xx[0] = xs; yy[0] = ys;
		xx[n + 1] = xt; yy[n + 1] = yt;
		for (int i = 1; i <= n; i++) {
			xx[i] = sc.nextInt();
			yy[i] = sc.nextInt();
			rr[i] = sc.nextInt();
		}
		n += 2;
		double[] dd = new double[n]; Arrays.fill(dd, INF); dd[0] = 0;
		boolean[] used = new boolean[n];
		while (true) {
			int i = -1;
			for (int j = 0; j < n; j++)
				if (!used[j]) {
					if (i == -1 || dd[i] > dd[j])
						i = j;
				}
			if (i == -1)
				break;
			used[i] = true;
			for (int j = 0; j < n; j++)
				if (!used[j])
					dd[j] = Math.min(dd[j], dd[i] + Math.max(Math.hypot(xx[i] - xx[j], yy[i] - yy[j]) - rr[i] - rr[j], 0));
		}
		println(dd[n - 1]);
	}
}


Measured memory_bytes: 41340
// https://atcoder.jp/contests/abc074/tasks/abc074_b
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> n;
  cin >> k;
  vi x(n);
  rep(i, 0, n)
  {
    cin >> x[i];
    if ((k - x[i]) > x[i])
    {
      ans += x[i] * 2;
    }
    else
    {
      ans += (k - x[i]) * 2;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF 1e9+7
#define LLINF 1e18
// #define int ll
using namespace std;
const int MOD = 1e9 +7;

bool is_prime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return n!=1;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    vector<int> ans;
    cin>>n;
    for(int i=1;i<55555;i+=5){
        if(is_prime(i)) ans.pb(i);
    }
    rep(i,n){
        cout<<ans[i];
        if(i!=n-1) cout<<" ";
        else cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io._
import java.util.StringTokenizer

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M = in.next().toInt
  val high = new Array[Int](N+1)
  for (i <- 1 to N) {
    high(i) = in.next().toInt
  }

  val dp = Array.fill[Boolean](N+1)(true)
  dp(0) = false
  for (_ <- 1 to M) {
    val A, B = in.next().toInt
    dp(A) &= high(A) > high(B)
    dp(B) &= high(B) > high(A)
  }

  val ans = dp.count(identity)
  println(ans)

}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int[][] b = countNumbers(a);
        boolean ans = false;
        if(b.length == 1){
            if(b[0][0] == 0) ans = true;
        }else if(b.length == 2){
            if(b[0][0] == 0 && b[0][1] * 2 == b[1][1]) ans = true;
        }else if(b.length == 3){
            if(b[0][0] == (b[1][0] ^ b[2][0])
                    && b[1][0] == (b[2][0] ^ b[0][0])
                    && b[0][1] == b[1][1]
                    && b[1][1] == b[2][1]) ans = true;
        }
        System.out.println(ans ? "Yes" : "No");
        sc.close();

    }

    public static int[][] countNumbers(int[] array){
        int n = array.length;
        int[][] ret = new int[n][];
        int nums = 0;
        for (int i = 0; i < n; i++) {
            if(i == 0 || array[i] != array[i-1]) ret[nums++] = new int[]{array[i], 0};
            ret[nums-1][1]++;
        }
        return Arrays.copyOf(ret, nums);
    }

}


Measured memory_bytes: 51740