akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var one = cin.ReadLine.Split(' ');
            var A = int.Parse(one[0]);
            var B = int.Parse(one[1]);
            var K = int.Parse(one[2]);

            List<int> divSet = new List<int>();
            int result = 0;
            for (int i = 1; i < 101; i++)
            {
                if (A%i == 0 && B%i == 0)
                {
                    divSet.Add(i);
                }
            }
            result = divSet[divSet.Count - K];
            Console.Write(result);
        }

    }
    public class deci
    {
        public bool IsFinish { get; set; } = false;
        public int Len { get; set; }
    }
    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13268
#include <cassert>
#include <iomanip>
#include <functional>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
    int n, k; cin >> n >> k;
    int x[n], y[n], c[n];
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> c[i];
    if (k == 1) { cout << "0\n"; return 0; }
    double lb = 0, ub = 2e7;
    function<bool(double, double, double)> check = [&](double cx, double cy, double v) {
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            double a = cx - x[i], b = cy - y[i];
            if (c[i] * sqrt(a * a + b * b) <= v * (1 + 1e-7)) cnt++;
        }
        return cnt >= k;
    };
    for (int xx = 0; xx < 100; xx++) {
        double v = (lb + ub) / 2;
        bool ok = false;
        for (int i = 0; !ok && i < n; i++) {
            if (check(x[i], y[i], v)) {
                ok = true;
                break;
            }
            for (int j = i+1; j < n; j++) {
                double vx = x[j] - x[i], vy = y[j] - y[i],
                    d = sqrt(vx * vx + vy * vy),
                    di = v / c[i], dj = v / c[j];
                if (d > di + dj || di > d + dj || dj > d + di) continue;
                double k = (d * d - dj * dj + di * di) / 2 / d,
                    h = sqrt(di * di - k * k),
                    cx1 = x[i] + k * vx / d - h * vy / d,
                    cx2 = x[i] + k * vx / d + h * vy / d,
                    cy1 = y[i] + k * vy / d + h * vx / d,
                    cy2 = y[i] + k * vy / d - h * vx / d;
                // cerr << d << ' ' << di << ' ' << dj << ' ' << k << ' ' << h << ' ' << cx1 << ' ' << cx2 << ' ' << cy1 << ' ' << cy2 << endl;
                
                // cerr<< (abs(sqrt(pow(cx1 - x[i], 2) + pow(cy1 - y[i], 2)) - di)) << ' '
                //     <<  (abs(sqrt(pow(cx2 - x[i], 2) + pow(cy2 - y[i], 2)) - di)) << ' '
                //     <<  (abs(sqrt(pow(cx2 - x[j], 2) + pow(cy2 - y[j], 2)) - dj)) << endl;

                if (check(cx1, cy1, v) || check(cx2, cy2, v)) {
                    ok = true;
                    break;
                }
            }
        }
        if (ok) ub = v;
        else lb = v;
        // cerr << setprecision(12) << v << ' ' << (ok ? "OK" : "NG") << endl;
    }
    cout << setprecision(12) << lb << endl;
}


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

bool dp[201];

int main() {

    dp[0] = true;

    for(int i=0; i<101; i++){
        if(dp[i]){
            dp[i+4] = true;
            dp[i+7] = true;
        }
    }

    int n;

    cin >> n;

    string ans = "No";

    if(dp[n]){
        ans = "Yes";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from operator import itemgetter


def solve(string):
    n, *ab = map(int, string.split())
    ab = sorted(zip(*[iter(ab[::-1])] * 2))
    past = 0
    for b, a in ab:
        past += a
        if past > b:
            return "No"
    return "Yes"


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n)])))


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int n, k = 0;
vector<vector<pair<int, int> > > g;
vector<int> res;

void dfs(int s = 0, int p = -1, int c = 0) {
  int color = 1;
  for (auto e: g[s]) {
	int next = e.first, id = e.second;
	if (next == p) continue;
	if (color == c) color++;
	res[id] = color;
	k = max(k, color);
	dfs(next, s, color++);
  }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	cin >> n;
	g.resize(n);
	res.resize(n - 1, -1);
	rep (i, n - 1) {
	  int a, b;
	  cin >> a >> b;
	  g[a - 1].emplace_back(b - 1, i);
	  g[b - 1].emplace_back(a - 1, i);
	}
	dfs();
	cout << k << endl;
	rep (i, n - 1) cout << res[i] << endl;
	
    
    return 0;
}



Measured memory_bytes: 11008
/**
 *    author:  tourist
 *    created: 10.05.2020 20:38:12       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> ok(n, 0);
  for (int i = 0; i < k; i++) {
    int foo;
    cin >> foo;
    while (foo--) {
      int bar;
      cin >> bar;
      ok[bar - 1] = 1;
    }
  }
  cout << n - accumulate(ok.begin(), ok.end(), 0) << '\n';
  return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

vector<long long> dp;

long long f(int i, int k, const vector<long long> &h) {
  if (i == 0) {
    return 0;
  }

  if (dp[i] == -1) {
    dp[i] = numeric_limits<int>::max();
    for (int j = 1; j <= min(k, i); ++j) {
      long long a = abs(h[i] - h[i - j]) + f(i - j, k, h);
      dp[i] = min(dp[i], a);
    }
  }

  return dp[i];
}

int main() { IO;
  int n, k;
  cin >> n >> k;

  vector<long long> h(n);
  for (auto &hi : h) cin >> hi;

  dp.resize(n);
  fill(dp.begin(), dp.end(), -1);

  long long ans = f(n - 1, k, h);
  cout << ans << endl;

  return 0;
}


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

using namespace std;
const int mod = 1e9+7;
const int N = 200005;

int n, a[N];
int ans[N];

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", a + i);

	vector<int> pos;
	for(int i = n; i >= 1; i--) {
		int cnt = 0;
		for(int j = i + i; j <= n; j += i) {
			cnt += ans[j];
		}
		if(cnt % 2 != a[i] % 2) {
			ans[i] = 1;
		}
		if(ans[i]) pos.push_back(i);
	}
	reverse(pos.begin(), pos.end());

	printf("%d\n", (int)pos.size());

	for(int x : pos) printf("%d ", x);
	printf("\n");
}


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

int main() {
    ll a,b,v,w,t;
    cin>>a>>v>>b>>w>>t;
    ll dist = abs(a-b);
    if(dist<=(v-w)*t||dist==0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 3636
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

ll ceilDiv(ll a, ll b) {
	return (a / b) + (a % b == 0 ? 0 : 1);
}

bool doInK(vector<int> &health, ll k, ll a, ll b) {
	int n = health.size();
	vector<int> minusHealth(n, 0);
	for (int i = 0; i < n; ++i) {
		minusHealth[i] = max((ll)0, health[i] - k * b);
	}
	ll addtlDamage = a - b;
	ll totalSteps = 0;
	for (int i = 0; i < n; ++i) {
		totalSteps += ceilDiv(minusHealth[i], addtlDamage);
	}
	return (totalSteps <= k);
}


int main() {

	int n;
	ll a, b;
	scanf("%d %lld %lld", &n, &a, &b);

	vector<int> health(n, 0);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &health[i]);
	}

	ll lo = 1;
	ll hi = 1000000000;
	// binary search for the lowest k such that 
	while (lo < hi) {
		int mid = lo + (hi - lo) / 2;
		if (doInK(health, mid, a, b)) {
			hi = mid;
		} else {
			lo = mid + 1;
		}
	}

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

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
using matrix = vector<vector<uint>>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acos(-1);

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

    string S;
    cin >> S;
    int N = S.length();
    vector<int> pos(2020);
    pos[0] = 1;
    ll cnt = 0;
    ll num = 0, c = 1;
    for (int i = N - 1; i >= 0; --i) {
        (num += (S[i] - '0') * c) %= 2019;
        cnt += pos[num];
        pos[num]++;
        (c *= 10) %= 2019;
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

ll f(ll mask, int d) {
  ll res = mask;
  for (int i = 0; i <= 50; ++i) if (mask & (1LL << i)) {
    res |= 1LL << (i % d);
  }
  return res;
}

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n;
  cin >> n;
  vi a(n), b(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) cin >> b[i];
  for (int i = 0; i < n; ++i) if (a[i] != b[i] && a[i] <= 2 * b[i]) {
    cout << -1 << endl;
    return 0;
  }
  ll res = 0;
  vl v(n);
  for (int i = 0; i < n; ++i) v[i] = 1LL << a[i];
  for (int k = 50; k >= 1; --k) {
    bool ok = 1;
    for (int i = 0; i < n; ++i) {
      ll cur = v[i];
      for (int d = k - 1; d >= 1; --d) {
        cur = f(cur, d);
      }
      if (!(cur & (1LL << b[i]))) ok = 0;
    }
    if (!ok) {
      //cerr << k << endl;
      res += 1LL << k;
      for (int i = 0; i < n; ++i) v[i] = f(v[i], k);
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    int n, h;
    cin >> n >> h;
    vector<int> a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }
    sort(all(a), greater<int>());
    sort(all(b), greater<int>());

    int ctr = 0;
    rep (i, n) {
        if (b[i] <= a[0]) {
            break;
        }
        h -= b[i];
        ctr++;
        if (h <= 0) {
            cout << ctr << endl;
            exit(0);
        }
    }
    cout << ctr + (h + a[0] - 1) / a[0] << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <numeric>
#define ll long long

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define pb emplace_back
#define mp make_pair

//#define DEBUG

using namespace std;

const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

typedef pair<ll, ll> P;

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;
}

int R, C, N, M, K, Q;

vector<int> v[200005];
vector<int> res;

void dfs(int node, int p = 0){
    PRINT(node)
    PRINT(res[node])
    for(int i:v[node]){
        if(i == p) continue;
        res[i] += res[node];
        dfs(i, node);
    }
    return;
}

signed main() {
    //cout << fixed << setprecision(10);
    cin >> N >> Q;

    rep(i, N-1){
        int from,to; cin >> from >> to;
        from --;
        to --;
        v[from].pb(to);
        v[to].pb(from);
    }
    res.assign(N,0); 
    rep(i,Q){
        int node, val; cin >> node >> val;
        res[--node] += val;
    }
    dfs(0);

    rep(i, N){
        cout << res[i] << " ";
    }
    cout << endl;

    //cout << max << endl;
}


Measured memory_bytes: 23552
A = []
A.append([int(x) for x in input().split()])
A.append([int(x) for x in input().split()])
A.append([int(x) for x in input().split()])

A2 = []
# print(A)
for r in A:
    mi = min(r)
    A2.append([x - mi for x in r])

a2 = A2[0]
ans = "Yes"
for x in A2:
    if a2 != x:
        ans = "No"

# print(A2)
print(ans)


Measured memory_bytes: 3064
# Union Find

# xの根を求める
def find_root(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find_root(par[x])
        return par[x]


# xとyの属する集合の併合
def unite(x, y):
    x = find_root(x)
    y = find_root(y)

    if x == y:
        return False
    else:
        # sizeの大きいほうがx
        if par[x] > par[y]:
            x, y = y, x
        par[x] += par[y]
        par[y] = x
        return True


# xとyが同じ集合に属するかの判定
def same(x, y):
    return find_root(x) == find_root(y)


# xが属する集合の個数
def size(x):
    return -par[find_root(x)]


# 初期化
# 根なら-size,子なら親の頂点

#nは要素数
n,m = map(int,input().split())
lis = [list(map(int,input().split())) for i in range(m)]
par = [-1] * n

hazime = n * (n-1) // 2

ans = []
num = 0
for a,b in lis[::-1]:
    a -= 1
    b -= 1
    x = find_root(a)
    y = find_root(b)
    if x != y:
        num += par[x] * par[y]
    unite(a,b)
    ans.append(num)
ans.insert(0,0)
  # print(ans)
for i in range(1,m+1):
    print(hazime-ans[-i-1])

Measured memory_bytes: 34744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX=2500;
const ll lim=1e10+5;
int n,ans,isp[100005],p;
ll a[100005],prime[100005];
map<ll,int> mp;
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=MX;i++) isp[i]=1;
	for(int i=2;i<=MX;i++)
	{
		if(isp[i]) prime[++p]=i;
		for(int j=1;j<=p&&prime[j]*i<=MX;j++)
		{
			isp[i*prime[j]]=0;
			if(i%prime[j]==0) break;
		}
	}
	for(int i=1;i<=p;i++) a[i]=1ll*prime[i]*prime[i]*prime[i];
	for(int i=1;i<=n;i++) 
	{
		ll x;
		scanf("%lld",&x);
		for(int j=1;j<=p&&x>=a[j];j++) while(x%a[j]==0) x/=a[j];
		mp[x]++;
//		printf("x=%lld\n",x);
	}
	for(map<ll,int>::iterator it=mp.begin();it!=mp.end();it++)
	{
		ll x=it->first,y=1,ori=x;
		int cnt=it->second;
		if(!cnt) continue;
		if(x==1)
		{
			ans++;
			continue;
		}
//		printf("x=%lld cnt=%d\n",x,cnt);
		for(int j=1;j<=p&&x>=prime[j];j++)
		{
			if(x%prime[j]==0)
			{
				int tmp=0;
				while(x%prime[j]==0) x/=prime[j],tmp++;
				tmp=3-tmp;
				while(tmp--) y*=prime[j];
			}
		}
		if(y>lim) 
		{
			ans+=cnt;
			continue;
		}
		ll sq=sqrt(x);
		if(sq*sq==x) 
		{
			y*=sq;
			if(y>lim) ans+=cnt;
			else if(cnt>=mp[y]) ans+=cnt,mp[y]=0; 
		}
		else 
		{
			if(y*x<lim) 
			{
				y*=x;
				if(y*x<lim)
				{
					y*=x;
					if(cnt>=mp[y]) ans+=cnt,mp[y]=0;
				}
				else ans+=cnt;
			}
			else ans+=cnt;
		}
//		printf("x=%lld y=%lld ans=%d\n",ori,y,ans);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 10496
n = int(input())
s = []
for i in range(n):
    s.append(input())

count = 0
count_a = 0
count_b = 0
count_ab = 0
for i in range(n):
    if s[i][0] =='B' and s[i][-1] =='A':
        count_ab = count_ab + 1
    elif s[i][0] =='B':
        count_b = count_b + 1
    elif s[i][-1] =='A':
        count_a = count_a + 1
    
    count = count + s[i].count('AB')

if count_ab!=0 and count_b==0 and count_a ==0:
    count = count + count_ab-1
elif count_b==0 and count_a ==0:
    count = count
else:
    count = count +min(count_a,count_b) + count_ab

print(count)

Measured memory_bytes: 3700
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

class UnionFind {
    int n;
    vector<int> par;
    vector<int> rank;
    vector<long long> sz;

public:
    UnionFind(int a) : n(a), rank(a, 0) {
        par.reserve(n);
        for (int i = 0; i < a; i++) par.push_back(i);
        sz.resize(n, 1);
    }
    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        int x_root = find(x);
        int y_root = find(y);
        if (rank[x_root] > rank[y_root]) {
            sz[x_root] += sz[y_root];
            par[y_root] = x_root;
        } else if (rank[x_root] < rank[y_root]) {
            sz[y_root] += sz[x_root];
            par[x_root] = y_root;
        } else if (x_root != y_root) {
            sz[x_root] += sz[y_root];
            par[y_root] = x_root;
            rank[x_root]++;
        }
    }
    long long size(int x){ return sz[find(x)]; }
    bool same(int x, int y) { return find(x) == find(y); }
};



int main(){
    long long N, M;
    cin >> N >> M;
    vector<pair<int, int>> AB(M);
    for(int i=0; i<M; i++){
        cin >> AB[i].first >> AB[i].second;
        AB[i].first--;
        AB[i].second--;
    }
    reverse(AB.begin(), AB.end());

    vector<long long> ans(M+1);
    UnionFind uf(N);
    ans[0] = (N*(N-1))/2;
    
    for(int i=0; i<M; i++){
        int A = AB[i].first, B = AB[i].second;
        int par0 = uf.find(A);
        int par1 = uf.find(B);
        if(par0 == par1){
            ans[i+1] = ans[i];
            continue;
        }
        long long sz0 = uf.size(par0);
        long long sz1 = uf.size(par1);
        long long dif = sz0 * sz1;
        ans[i+1] = ans[i] - dif;
        uf.unite(par0, par1);
    }
    reverse(ans.begin(), ans.end());

    for(int i=1; i<=M; i++)
        cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
const int maxn=505;
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n,k,v[maxn],val[maxn],cnt;
bool cmp(int a,int b){return a>b;}
int main()
{
	n=read(),k=read();
	for(int i=1;i<=n;i++)v[i]=read();
	if(k>=2*n){
		sort(v+1,v+1+n,cmp);
		int ans=0;
		for(int i=1;i<=n;i++){
			if(v[i]>0)ans+=v[i];
		}
		printf("%d\n",ans);
		return 0;
	}
	int ans=0;
	for(int l=0;l<=n;l++){
		for(int r=n+1;r>=1;r--){
			if(l>=r)continue;
			int cnt=0;int tmp=l+n-r+1,sum=0;
			if(tmp>k)continue;
			for(int i=1;i<=l;i++)val[++cnt]=v[i],sum+=val[cnt];
			for(int i=n;i>=r;i--)val[++cnt]=v[i],sum+=val[cnt];
			sort(val+1,val+1+cnt);
			for(int i=1;i<=min(cnt,k-tmp);i++){
				if(val[i]<0){
				sum-=val[i];
				}
			}//printf("%d %d %d %d\n",l,r,tmp,sum);
			ans=max(ans,sum);
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n;
    long long a, b;
    long long xi, x;
    long long ans=0;
    cin >> n >> a >> b;
    cin >> x;
    for (int i =0; i < n-1; ++i) {
        cin >> xi;
        if (a*(xi - x) > b)
            ans += b;
        else
            ans += a*(xi-x);
        x = xi;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3224
#include <iostream>
#include <cstdio>

using namespace std;

double isConvex(double xa, double ya, double xb, double yb, double x, double y)
{
	double ret;
	ret = (xa-xb)*(y-ya) + (ya-yb)*(xa-x);
	return ret;
}

int main()
{
	double xa, ya, xb, yb, xc, yc, xd, yd;
	while( scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF ){
		// 直線BDと線分ACが交わるか
		double bd_ac = isConvex(xb, yb, xd, yd, xa, ya)*isConvex(xb, yb, xd, yd, xc, yc);
		// 直線ACと線分BDが交わるか
		double ac_bd = isConvex(xa, ya, xc, yc, xb, yb)*isConvex(xa, ya, xc, yc, xd, yd);
		
		// bd_acが負またはac_bdが負ならば、交差している
		if( bd_ac < 0.0 && ac_bd < 0.0 ){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 1224
N, K = gets.split.map(&:to_i)

ans = 0

N.times do |i|
  me = i + 1
  
  if me >= K
    

    ans += 1 

  else

    # p "yet!"
    # p me
    # p "がme"
    win = Math.log(K.to_f / me.to_f, 2).ceil
    
    # p win
    # p "がwin"
    #
    p_ = ( 1.to_f / (2 ** win) )
  
    ans += p_

  end


    #p ans if me < 10


end


puts (ans / N.to_f)





Measured memory_bytes: 1916
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

void preParse(int u) {
    if (u == NIL) return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}
void inParse(int u) {
    if (u == NIL) return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}
void postParse(int u) {
    if (u == NIL) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main() {
    int i, v, l, r, root;
    
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        T[i].p = NIL;
    }
    
    for (i = 0; i < n; i++) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if (l != NIL) T[l].p = v;
        if (r != NIL) T[r].p = v;
    }
    
    for (i = 0; i < n; i++) if (T[i].p == NIL) root = i;
    
    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 2120
while True:
    m,f,r = map(int,input().split())
    
    if m == f == r == -1:
        break
    
    if m == -1 or f == -1 or (m+f) < 30:
        print("F")
    elif (m+f) >= 80:
        print("A")
    elif 65 <= (m+f) < 80:
        print("B")
    elif 50 <= (m+f) < 65:
        print("C")
    elif 30 <= (m+f) < 50:
        if r >= 50:
            print("C")
        else:
            print("D")

        


Measured memory_bytes: 5596
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<iostream>
#include<map>
#include<cstring>
#define INF 0x3f3f3f3f
#define eps 1000000000
using namespace std;
set<int> a;
string s;
map<int,int>tim;
int n,l[105],ans,now;
int main(){
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='R')
            now++;
        else
            now=0;
        ans=max(ans,now);
    }
    printf("%d",ans);
}


Measured memory_bytes: 3232
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>

using namespace std;

int main(){
  int A, B; cin >> A >> B;
  if(A == 1) A += 13;
  if(B == 1) B += 13;

  if (A > B) cout << "Alice" << endl;
  else if(A == B) cout << "Draw" << endl;
  else cout << "Bob" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> vi;
int main()
{
    int i,j,k,x,y,ans,curr,temp;
    int n,m;
    scanf("%d %d",&n,&m);
    int arr[m];
    for(i=0;i<m;i++)
    {
        scanf("%d",&arr[i]);
    }
    sort(arr,arr+m);
    for(i=1;i<m;i++)
    {
        vi.push_back(arr[i] - arr[i-1]);
    }
    sort(vi.begin(),vi.end());
    int len = vi.size();
    ans = 0;
    if(n == 1)
    {
        ans = arr[m-1] - arr[0];
    }
    else if(n >= m)
    {
        ans = 0;
    }
    else
    {
        int sum = arr[m-1] - arr[0];
        n--;
        int idx = len-1;
        while(n>0)
        {
            sum -= vi[idx];
            idx--;
            n--;
        }
        ans = sum;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long int ll;
void solve()
{
	int n;cin>>n;
	int ld=n%10;
	if(ld==2||ld==4||ld==5||ld==7||ld==9){
		cout << "hon";
	}
	else if(ld==0||ld==1||ld==6||ld==8){
		cout << "pon";
	}
	else cout << "bon";
}
int main(){
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
	solve();
	return 0;
}

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


 int main(){
   string s;
   cin >> s;
   int a=0,b=0;
   FOR(i,s.size()){
     if(s[i]=='0'){
       a++;
     }else{
       b++;
     }
   }
   int ans=s.size()-abs(a-b);
   cout << ans << endl;
 }

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

typedef std::pair<int, int> ii;

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n;
	std::cin >> n;
	std::vector<ii> ranges(n);
	for(int i = 0; i < n; i++) {
		std::cin >> ranges[i].first >> ranges[i].second;
	}
	std::vector<int> p[2];
	for(int i = 0; i < n; i++) {
		p[0].push_back(i);
		p[1].push_back(i);
	}
	std::sort(p[0].begin(), p[0].end(), [&](int a, int b) -> bool { return ranges[a].first > ranges[b].first; });
	std::sort(p[1].begin(), p[1].end(), [&](int a, int b) -> bool { return ranges[a].second < ranges[b].second; });
	for(int j = 0; j < 2; j++) {
		for(int i = 0; i < n; i++) {
			//std::cout << p[j][i] << (i + 1 == n ? '\n' : ' ');
		}
	}
	long long curDist = 0;
	int curPos = 0;
	int pt[2];
	pt[0] = 0;
	pt[1] = 0;
	std::vector<bool> used(n, false);
	for(int s = 0; s < n; s++) {
		while(pt[0] < n && used[p[0][pt[0]]]) {
			pt[0]++;
		}
		while(pt[1] < n && used[p[1][pt[1]]]) {
			pt[1]++;
		}
		int use = p[s % 2][pt[s % 2]];
		if(ranges[use].first <= curPos && curPos <= ranges[use].second) {

		} else if(ranges[use].second < curPos) {
			curDist += curPos - ranges[use].second;
			curPos = ranges[use].second;
		} else {
			curDist += ranges[use].first - curPos;
			curPos = ranges[use].first;
		}
		used[use] = true;
	}
	long long ans = curDist + std::max(curPos, -curPos);
	curDist = curPos = pt[0] = pt[1] = 0;
	used.assign(n, false);
	for(int s = 1; s <= n; s++) {
		while(pt[0] < n && used[p[0][pt[0]]]) {
			pt[0]++;
		}
		while(pt[1] < n && used[p[1][pt[1]]]) {
			pt[1]++;
		}
		int use = p[s % 2][pt[s % 2]];
		if(ranges[use].first <= curPos && curPos <= ranges[use].second) {

		} else if(ranges[use].second < curPos) {
			curDist += curPos - ranges[use].second;
			curPos = ranges[use].second;
		} else {
			curDist += ranges[use].first - curPos;
			curPos = ranges[use].first;
		}
		used[use] = true;
	}
	std::cout << std::max(ans, curDist + std::max(curPos, -curPos)) << std::endl;
}

Measured memory_bytes: 2164
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

    ll operator"" _64(unsigned long long x){ return ll(x); }
    ull operator"" _64u(unsigned long long x){ return ull(x); }

    template<class T>
    vector<T> make_vector(int n, T t){
        return vector<T>(n, t);
    }
    template<class ...Ts>
    auto make_vector(int n, Ts ... ts){
        return vector<decltype(make_vector(ts...))>(n, make_vector(ts...));
    }

    template<class T>
    ostream& operator<<(ostream& os, const vector<T>& v){
        for (auto &&x : v) { os << x << ' '; } cout << endl; return os ;
    }
}
using namespace utils;

class solver{
    istream& is;
    ostream& os;

public:
    solver(istream& I, ostream& O) :is(I), os(O) {}
    void run(){
        ll N;
        is >> N;
        if(!is) return;
        vector<int> H(N);
        for (auto &&h : H) {
            is >> h;
        } // end h
        int ans = 0;
        int l = 0, r = 0;
        int prev = H[l];
        while(r < N){
            if(prev < H[r]){
                ans = max(ans, r - l - 1);
                l = r;
            }
            prev = H[r];
            r++;
        }
        ans = max(ans, r - l - 1);

        os << ans << endl;
    }
};

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_C.txt";
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int loop = 0;
    while(fs) {
        loop++;
        cout << '#' << loop << "#------\n";
        solver(fs, cout).run();
    }
    if(loop <= 1) {
        cout << "===" << endl;
        while(cin) solver(cin, cout).run();
    }
#else
    solver(cin, cout).run();
#endif
    return 0;
}


Measured memory_bytes: 640
n, x = map(int,input().split())
l = [int(i) for i in input().split()]
d = [0] * (n+1)
for i in range(1, n+1):
    d[i] = d[i-1] + l[i-1]

ans = len([i for i in d if i <= x])
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define itn int
#define rep(i, n) for(int i = 0; i < n; i++)
#define irep(i,n) for(int i = n-1; i>=0; i--)
#define FOR(a,b) for(int i=a; i<b+1; i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> v(n,vector<int>(3));
    rep(i,n-1){
        rep(j,3){
            cin >> v[i][j];
        }
    }
    rep(i,n-1){
        int time=0;
        for(int j=i;j!=n-1;j++){
            if(time==0||time<v[j][1]){
                time=v[j][1]+v[j][0];
                continue;
            }
            if(time%v[j][2]==0){
                time+=v[j][0];
                continue;
            }
            int tmp=time/v[j][2];
            tmp++;
            time=v[j][2]*tmp+v[j][0];
        }
        cout << time << endl;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int isprime(int n) {
  int i;
  for(i = 2; i * i <= n; i++) {
    if(n % i == 0) return 0;
  }
return 1;
}

int main(){
  int n, i;
  while(1){
    scanf("%d", &n);
    if(n == 0) break;
    for(i=n ; i >= 5 ; i--){
      if(isprime(i) && isprime(i-2)) break;
    }
    printf("%d %d\n", i - 2, i);
  }
  return 0;
}

Measured memory_bytes: 1720
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main()
{
    ll n;
    cin >> n;
    vei a(n), b(n);
    int ans = 0;
    bool flag = false;
    rep(i, n)
    {
        cin >> a[i] >> b[i];
        if (a[i] == b[i])
        {
            ans++;
        }
        else
        {
            ans = 0;
        }
        if (ans >= 3)
        {
            flag = true;
        }
    }
    if (flag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

#define ll long long

using namespace std;


int main(){
    ll a,b,k,val;
    cin>>a>>b>>k;
    val = k>a? a:k;
    a -= val;
    k -= val;

    val = k>b? b:k;
    b -= val;
    k -= val;

    cout<<a<<" "<<b<<"\n";

}

Measured memory_bytes: 256
#!/bin/bash
":" //#; docker run --rm -it -v "$(cd $(dirname $0) && pwd)":/vo:ro  node:5.2-slim /bin/bash -c "node /vo/$(basename $0) < /vo/g.inp"; exit $?

"use strict";
let main = (input) => {
    let lst = input.split("\n");
    let m1 = lst[0].split(" ")[0];
    let m2 = lst[1].split(" ")[0];
    if(m1===m2) {
	return 0;
    } else {
	return 1;
    };
};
console.log(main(require("fs").readFileSync("/dev/stdin", "utf-8").trim()));


Measured memory_bytes: 11468
a, b, c = map(int, input().split())

if a == 7 and b == 5 and c == 5:
	print('YES')
elif b == 7 and c == 5 and a == 5:
	print('YES')
elif c == 7 and a == 5 and b == 5:
	print('YES')
else:
	print('NO')

Measured memory_bytes: 3060
from collections import deque

k = int(input())
Runrun = deque()
for i in range(9):
    Runrun.append(i + 1)
while k > 1:
    t = Runrun.popleft()
    r = t % 10
    if r != 0:
        Runrun.append(10 * t + r - 1)
    Runrun.append(10 * t + r)
    if r != 9:
        Runrun.append(10 * t + r + 1)
    k -= 1
print(Runrun.popleft())

Measured memory_bytes: 11952
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	x := getNextString(scanner)
	n := len(x)
	stack := make([]byte, n+1)
	stack[0] = 'T'
	si := 0
	for i := 0; i < n; i++ {
		if stack[si] == 'S' && x[i] == 'T' {
			si--
			continue
		}
		si++
		stack[si] = x[i]
	}
	fmt.Fprintln(writer, si)

	writer.Flush()
}


Measured memory_bytes: 1280
#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)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    ll N;
    cin >> N;
    ll res = 0;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            ll m = N / i - 1;
            if (N / (m + 1) < m) res += m;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

    int n, x;
    int i, j, k;
    int cnt = 0;

    while(1) {

      scanf("%d %d\n", &n, &x);
       if (n == 0 && x == 0) {
       break;
       } 

        for (i = 1; i <= n - 2; i++) {
            for (j = i + 1; j <= n - 1; j++) {
                for (k = j + 1; k <= n; k++) {

                 if(i + j + k == x) {
                   cnt++;
                 }
                 }
            }
         
        }
      printf("%d\n", cnt);
      cnt = 0;
    }
    return  0;
}

Measured memory_bytes: 604
from collections import deque

N=int(input())
A=list(map(int,input().split()))
edge=[[] for i in range(N)]
for _ in range(N-1):
    u,v=map(int,input().split())
    edge[u-1].append(v-1)
    edge[v-1].append(u-1)

ans=[0]
parent=[-1]*N
que=deque([(0,-1)])
while que:
    v,pv=que.popleft()
    for nv in edge[v]:
        if nv!=pv:
            parent[nv]=v
            ans.append(nv)
            que.append((nv,v))
ans=ans[::-1]

for v in range(N):
    edge[v]=[nv for nv in edge[v] if nv!=parent[v]]


dpc=[[] for i in range(N)]
dpn=[[] for i in range(N)]
sz=[0]*N
for v in ans:
    sz[v]=1
    sz[v]=1
    dpc[v]=[10**18,A[v]]
    for nv in edge[v]:
        merged=[10**18]*(sz[v]+sz[nv]+1)
        for i in range(1+sz[v]):
            for j in range(1+sz[nv]):
                merged[i+j-1]=min(merged[i+j-1],dpc[v][i]+min(dpc[nv][j],dpn[nv][j]))
                if dpn[nv][j]<=10**15:
                    merged[i+j]=min(merged[i+j],dpc[v][i])
        dpc[v]=merged
        sz[v]+=sz[nv]
    sz[v]=1
    if A[v]<0:
        dpn[v]=[10**18]*2
    else:
        dpn[v]=[10**18,A[v]]
    for nv in edge[v]:
        merged=[10**18]*(sz[v]+sz[nv]+1)
        for i in range(1,1+sz[v]):
            for j in range(1,1+sz[nv]):
                if dpc[nv][j]<0:
                    merged[i+j]=min(merged[i+j],dpn[v][i])
                merged[i+j-1]=min(merged[i+j-1],dpn[v][i]+dpn[nv][j])
                if dpn[nv][j]<=10**15:
                    merged[i+j]=min(merged[i+j],dpn[v][i])
        dpn[v]=merged
        sz[v]+=sz[nv]

ans=N
for i in range(1,N+1):
    if dpc[0][i]<0 or dpn[0][i]<=10**15:
        ans=i
        break

print(ans-1)


Measured memory_bytes: 237136
import std.conv;
import std.stdio;
import std.string;

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


void main()
{
    ulong A, B;
    scan(A, B);
    writeln(f(A - 1) ^ f(B));
}

ulong f(ulong x)
{
    auto mod = x % 4;
    switch (mod)
    {
    case 0:
        return x;
    case 1:
        return 1;
    case 2:
        return x ^ 1;
    case 3:
        return 0;
    default:
        assert(0);
    }
}


Measured memory_bytes: 256
list = input().split(" ")
N = int(list[0])
A = int(list[1])
B = int(list[2])

t = 0
for i in range(1,N+1):
    num = len(str(i))
    sum = 0
    for j in range(num):
        sum = sum + int(str(i)[j])
    if (A <= sum) and (sum <= B):
        t = t + i
print(t)

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

long long mod=1e9+7;
long long fact[200010];
long long poww(long long a, long long b){
  long long res = 1;
  while (b){
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
long long C(long long k,long long n)
{
    return fact[n] * poww(fact[k],mod-2) % mod * poww(fact[n-k],mod-2) % mod;
}
int main()
{
    long long h,w,a,b;
    cin >> h >> w >> a >> b;
    fact[0]=1;
    for(long long i=1;i<=200000;i++)
    {
        fact[i]=fact[i-1]*i;
        fact[i]=fact[i] % mod;
    }
    //cout << C(3,5);
    long long ans=0;
    for(long long i=1;i<=w-b;i++)
    {
        ans=ans+C(h-a-1,h-a+b+i-2)*C(a-1,a+w-b-i-1)%mod;
        ans=ans%mod;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define MAXN	2005
#define INF	1e9
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
char a[MAXN], b[MAXN];
int n, x[MAXN], y[MAXN];
int m, qx[MAXN], qy[MAXN];
void init() {
	for (int i = 1; i <= n; i++) {
		if (a[i] == '0') continue;
		int pos = i, cnt = 0;
		while (b[pos] == '0') {
			cnt++;
			pos--;
			if (pos == 0) pos = n;
		}
		x[i] = cnt;
		pos = i, cnt = 0;
		while (b[pos] == '0') {
			cnt++;
			pos++;
			if (pos > n) pos = 1;
		}
		y[i] = cnt;
	}
}
int pred(int x, int y) {
	if (x - y <= 0) return x - y + n;
	else return x - y;
}
int succ(int x, int y) {
	if (x + y <= n) return x + y;
	else return x + y - n;
}
int calc(int goal, int posi, int nega) {
	return nega * 2 + posi * 2 - goal;
}
int checklft(int value) {
	int ans = 0; m = 0;
	for (int i = 1; i <= n; i++)
		if (a[i] == '0') {
			if (b[succ(i, value)] == '1') ans++;
		} else {
			if (b[succ(i, value)] == '0') ans++;
			if (b[succ(i, value)] == '0' && y[i] > value) {
				m++;
				qx[m] = x[i];
				qy[m] = y[i];
			}
		}
	static int a[MAXN];
	memset(a, 0, sizeof(a));
	for (int i = 1; i <= m; i++)
		a[qy[i] - 1] = max(a[qy[i] - 1], qx[i]);
	int delta = INF;
	for (int i = n; i >= value; i--) {
		a[i] = max(a[i], a[i + 1]);
		delta = min(delta, calc(value, i, a[i]));
	}
	return ans + delta;
}
int checkrit(int value
) {
	int ans = 0; m = 0;
	for (int i = 1; i <= n; i++)
		if (a[i] == '0') {
			if (b[pred(i, value)] == '1') ans++;
		} else {
			if (b[pred(i, value)] == '0') ans++;
			if (b[pred(i, value)] == '0' && x[i] > value) {
				m++;
				qx[m] = x[i];
				qy[m] = y[i];
			}
		}
	static int a[MAXN];
	memset(a, 0, sizeof(a));
	for (int i = 1; i <= m; i++)
		a[qx[i] - 1] = max(a[qx[i] - 1], qy[i]);
	int delta = INF;
	for (int i = n; i >= value; i--) {
		a[i] = max(a[i], a[i + 1]);
		delta = min(delta, calc(value, i, a[i]));
	}
	return ans + delta;
}
bool impossible() {
	for (int i = 1; i <= n; i++)
		if (b[i] == '1') return false;
	for (int i = 1; i <= n; i++)
		if (a[i] == '1') return true;
	return false;
}
int main() {
	scanf("%s\n%s", a + 1, b + 1);
	n = strlen(a + 1);
	if (impossible()) {
		cout << -1 << endl;
		return 0;
	}
	init();
	int ans = INF;
	for (int i = 0; i <= n; i++) {
		ans = min(ans, checklft(i));
		ans = min(ans, checkrit(i));
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

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


#define all(v) v.begin(),v.end()
#define INF 1<<30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef long long ll;

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

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

int main(){
	while(1){
		rep(y,1020){
			rep(x,1020){
				s[y][x]=0;
			}
		}
		int m,n;
		cin>>m>>n;
		if(m==0) break;
		int w = ceil(sqrt(m));
		w = (w%2==0)? w+1:w; 
		int h = w;
		int sx = w/2;
		int sy = w/2;
		int dir = 0;
		int cnt = 1;
		s[sy][sx]=1;
		REP(i,1,w*w){
			rep(k,2){
				rep(j,i){
					cnt++;
					sx = sx+dx[dir%4];
					sy = sy+dy[dir%4];
					s[sy][sx] = cnt;

					if(cnt==m) goto END;
				}
				dir++;
			}
		}
		END:;
		rep(y,h){
			rep(x,w){
				// printf("%4d ",s[y][x]);
				if(s[y][x]==n){
					sy = y;
					sx = x;
				}
			}
			// cout << endl;
		}
		pii dp[1020][1020];
		rep(y,1000){
			rep(x,1000){
				dp[y][x] = mp(0,0);
			}
		}
		for (int y = h+1; y >= sy; --y)
		{
			for(int x = 0;x<w;++x){
				rep(i,3){
					if(x+i-1<0||x+i-1>=w) continue;
					if(dp[y][x].fi < dp[y+1][x+i-1].fi){
						dp[y][x].fi = dp[y+1][x+i-1].fi;
						dp[y][x].se = dp[y+1][x+i-1].se;
					}
					if(dp[y][x].fi == dp[y+1][x+i-1].fi){
						if(dp[y][x].se < dp[y+1][x+i-1].se){
							dp[y][x].fi = dp[y+1][x+i-1].fi;
							dp[y][x].se = dp[y+1][x+i-1].se;
						}
					}
				}
				if(is_prime(s[y][x])){
					dp[y][x].fi++;
					if(dp[y][x].se==0) dp[y][x].se = s[y][x];
				}
			}
		}
		// rep(y,h){
		// 	rep(x,w){
		// 		printf("%2d ",dp[y][x].fi);
		// 	}
		// 	cout << endl;
		// }
		cout << dp[sy][sx].fi << " "<<dp[sy][sx].se<< endl;
	}
	return 0;
}

Measured memory_bytes: 15228
import java.util.*;
class Main{
	public static void main(String[]z){
		Scanner cin=new Scanner(System.in);
		int n,k,m,r,i;
		for(;;System.out.println((r+m)%n+1)){
			n=cin.nextInt();k=cin.nextInt();m=cin.nextInt();
			if(n==0)break;
			for(r=i=0;++i<n;r%=i)r+=k;
		}
	}
}

Measured memory_bytes: 20504
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <numeric>
#include <ctype.h>
#include <cstdlib>
#include <string.h>
#include <cmath>
#include <cstdio>





using namespace std;


int main()
{
	int input;
	vector<int> vec;

	for (int i = 0; i < 10; i++)
	{
		cin >> input;
		vec.push_back(input);
	}

	sort(vec.begin(), vec.end(), greater<int>());

	for (int i = 0; i < 3; i++)
	{
		cout << vec[i] << endl;
	}
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){
   int x,n;
   cin>>x>>n;
   vector<int> p(n);
   rep(i,n) cin>>p.at(i);
   map<int,int> ans;
   rep(i,n) ans[p.at(i)]++;
   rep(i,1000){
       bool w=true;
       if(ans.count(x-i)){
           w=false;
       }
       if(w){
           cout<<x-i;
           break;
       }
       w=true;
       if(ans.count(x+i)){
           w=false;
       }
       if(w){
           cout<<x+i;
           break;
       }
   }
}

Measured memory_bytes: 3636
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int[] menu=new int[5];
		int min;
		for(int i=0;i<5;i++){
			menu[i]=sc.nextInt();
		}
		min=menu[0]+menu[3];
		if(min>menu[0]+menu[4]){
			min=menu[0]+menu[4];
		}
		if(min>menu[1]+menu[3]){
			min=menu[1]+menu[3];
		}
		if(min>menu[1]+menu[4]){
			min=menu[1]+menu[4];
		}
		if(min>menu[2]+menu[3]){
			min=menu[2]+menu[3];
		}
		if(min>menu[2]+menu[4]){
			min=menu[2]+menu[4];
		}
		System.out.println(min-50);
	}
}

Measured memory_bytes: 17308