akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;

#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

ll dp[105][110005];

void Main() {
    int N, W;
    cin >> N >> W;
    vector<P> items(N);
    rep(i, N) cin >> items[i].first >> items[i].second;
    fill(dp[0], dp[104], INF);

    rep(i, N) {
        dp[i][0] = 0;
    }
    rep(i, N) {
        rep(j, N * 1100) {
            if (j - items[i].second >= 0) {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - items[i].second] + items[i].first);
            }
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }
    ll ans = INF;
    rrep(i, 110005, 0) {
        if (dp[N][i] <= W) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 90368
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), x.end()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
vector<vector<int>> ar;
vector<vector<array<int,4>>> dp;
char t[N];

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

int ok(int x, int y) {
  return 0 <= x && x < sz(ar) && 0 <= y && y < sz(ar[0]) && ar[x][y] == 0;
}

int main() {
  int h, w, k; scanf("%d %d %d", &h, &w, &k);
  int x1, x2, y1, y2;
  scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
  x1--, y1--, x2--, y2--;
  ar.resize(h); dp.resize(h);
  for (int i = 0; i < h; i++) {
    scanf("%s", t);
    ar[i].resize(w); dp[i].resize(w);
    for (int j = 0; j < w; j++) {
      ar[i][j] = t[j] == '@' ? 1 : 0;
      for (int l = 0; l < 4; l++)
        dp[i][j][l] = inf;
    }
  }
  deque<pii> pq;
  for (int i = 0; i < 4; i++)
    dp[x1][y1][i] = 0;
  pq.pb(mp(x1, y1));
  while (sz(pq)) {
    int x, y; tie(x, y) = pq.front(); pq.pop_front();
    int tmp = inf;
    for (int i = 0; i < 4; i++)
      tmp = min(tmp, dp[x][y][i]);
    for (int i = 0; i < 4; i++)
      dp[x][y][i] = tmp;
    // cout << x << " " << y << endl;
    assert(tmp != inf);
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      for (int j = 1; j <= k && ok(nx, ny) && dp[nx][ny][i] >= tmp+1; j++) {
        
        if (dp[nx][ny][i] > tmp + 1) {
          dp[nx][ny][i] = tmp + 1;
          pq.pb(mp(nx, ny));
        }
        // cout << i << " - " << j << endl;
        nx += dx[i], ny += dy[i];
      }
    }
  }
  int ans = inf;
  for (int l = 0; l < 4; l++)
    ans = min(ans, dp[x2][y2][l]);
  if (ans == inf)
    ans = -1;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 24540
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>
 
using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
 
 
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;
}
 
//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n,m,v,p;
	cin>>n>>m>>v>>p;
	Array a(n,0);
	REP(i,n){
		cin>>a[i];
	}

	sort(all(a),greater<ll>());

	auto check = [&](ll x)->bool{
		if(x<p) return true;
		if(a[x]+m<a[p-1]) return false;

		ll next=a[x]+m;
		ll b = (p-1)*m;
		for(int i=p-1;i<n;i++){
			b+=min(m,next-a[i]);
		}
		return b>=v*m;
	};

	ll l=-1;
	ll r=n;
	while(l+1<r){
		ll mid=l+r>>1;
		if(check(mid)){
			l=mid;
		}else{
			r=mid;
		}
	}
	cout<<l+1<<endl;

	return 0;
}

Measured memory_bytes: 1024
S=map(str,raw_input())
S.sort()
flag=1
SS=[]
for i in S:
    SS.append(ord(i))
for i in range(ord("a"),ord("z")+1):
    if not i in SS:
        ans=chr(i)
        print ans
        flag=0
        break
if flag==1:
    print "None"

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

int const N = 100000;
vector<int> g[N + 1];
int n, m, a[N + 1], b[N + 1], pa[N + 1], ex[N + 1];
ll sm[N + 1];
pair<int, int> x[N];

int P(int v) { return pa[v] < 0 ? v : pa[v] = P(pa[v]); }

int main(){
	scanf("%d%d", &n, &m);
	f(i, 1, n + 1)scanf("%d%d", a + i, b + i);
	f(i, 0, n)x[i] = make_pair(a[i + 1] - b[i + 1], i + 1);
	sort(x, x + n);
	f(i, 0, m){
		int a, b;
		scanf("%d%d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	pa[0] = -1;
	f(i, 0, n){
		int v = x[i].second, need = a[v] - b[v];
		sm[v] = b[v];
		ex[v] = max(0, need);
		pa[v] = -1;
		f(j, 0, g[v].size()){
			int u = P(g[v][j]);
			if (u == 0 || u == v)continue;
			sm[v] += sm[u];
			ex[v] = min((ll)ex[v], max((ll)ex[u], need - sm[u]));
			pa[u] = v;
		}
	}
	printf("%lld\n", sm[x[n - 1].second] + ex[x[n - 1].second]);
}

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

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

long long y[100005], x[100005];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, m; cin >> n >> m;

    for(int i = 0; i < n; ++i)
        cin >> x[i];
    for(int i = 0; i < m; ++i)
        cin >> y[i];

    long long bx = x[0], by = y[0], a = 0, b = 0;

    for(int i = 1; i < n; ++i){
        a += (x[i] - x[i - 1]) * i * (n - i);
        a %= MOD;
    }

    for(int i = 1; i < m; ++i){
        b += (y[i] - y[i - 1]) * i * (m - i);
        b %= MOD;
    }

    cout << a * b % MOD << "\n";

    return 0;

}


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

int main(void){
    int n;
    cin >> n;
    map<int,int> cnt;
    for (size_t i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        cnt[t]++;
    }
    int ans=0;
    for (auto i = cnt.cbegin(); i != cnt.cend(); i++)
    {
        if (i->first==i->second)continue;
        if (i->first>i->second)
        {
            ans+=i->second;
        }
        else
        {
            ans+=i->second-i->first;
        }
    }
    cout << ans <<endl;
    return 0;
}

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

#define ln '\n'
#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 FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    VI ch(256, 0);
    REP(i, 4) ch[s[i]]++;
    REP(i, 4) if (ch[s[i]] != 2) {
        cout << "No" << ln;
        return 0;
    }
    cout << "Yes" << ln;
    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            String S = in.next();
            int d = 0;
            switch (S) {
                case "SUN":
                    d = 7;
                    break;
                case "MON":
                    d = 6;
                    break;
                case "TUE":
                    d = 5;
                    break;
                case "WED":
                    d = 4;
                    break;
                case "THU":
                    d = 3;
                    break;
                case "FRI":
                    d = 2;
                    break;
                case "SAT":
                    d = 1;
                    break;
            }
            out.println(d);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

    }
}



Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

const int LGN = 60;
const int Z = 1e9+7;

void addm(int &a, int b) {
    a = a + b >= Z ? a + b - Z : a + b;
}

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

    ll l, r;
    cin >> l >> r;

    int dp[LGN+1][2][2][2];
    fill(&dp[0][0][0][0], &dp[LGN+1][0][0][0], 0);
    fill(&dp[0][0][0][0], &dp[1][0][0][0], 1);
    for (int i = 1; i <= LGN; i++) {
        bool bl = l >> (i - 1) & 1, br = r >> (i - 1) & 1;
        for (int fl = 0; fl <= 1; fl++) {
            for (int fr = 0; fr <= 1; fr++) {
                for (int sb = 0; sb <= 1; sb++) {
                    for (int cl = 0; cl <= 1; cl++) {
                        for (int cr = 0; cr <= 1; cr++) {
                            if (cl <= cr && !(sb && (cl < cr)) && !(fl && (cl < bl)) && !(fr && (cr > br))) {
                                addm(dp[i][fl][fr][sb], dp[i-1][fl&&cl==bl][fr&&cr==br][sb&&cl!=1]);
                            }
                        }
                    }
                }
            }
        }
    }

    cout << dp[LGN][1][1][1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int M = 1200000;
typedef long long ll;
int n,m,k;
string s;
short num[M];
int main(){
    cin>>s;
    n=s.size();
    fo(i,0,n-1) num[i]=s[i]-'0';
    int a[2]={num[n-1],10-num[n-1]};
    rv(i,n-2,0){
        int b[2]={a[0]+num[i],a[0]+10-num[i]};
        b[0]=min(b[0],a[1]+num[i]+1);
        b[1]=min(b[1],a[1]+9-num[i]);
        a[0]=b[0];
        a[1]=b[1];
    }
    cout<<min(a[0],a[1]+1)<<endl;
    return 0;
}

Measured memory_bytes: 3332
#include <bits/stdc++.h>  
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod=1e9+7;
const ll longINF=3e18;
const double eps=1e-8;
const double dinf=190.0;
const double pi=acos(-1);
const int INF=2e9+1;

set <int> g[200005];
int n,m;
        
int main() 
{        
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
        cin>>n>>m;
        for (int i=0;i<m;i++) {
                int a,b;
                cin>>a>>b;
                g[a].insert(b);
                g[b].insert(a);
        }
        for (auto to:g[1]) {
                if (g[to].find(n)!=g[to].end()) {
                        cout<<"POSSIBLE";
                        return 0;
                }
        }
        cout<<"IMPOSSIBLE";
        return 0;
}

Measured memory_bytes: 28416
#include<iostream>
#include<string>
using namespace std;
int main(){
    int a;
    
    int sum=0;
    cin >> a;
    int baf_a = a;

    while(baf_a != 0){
        int baf = baf_a%10;
        sum += baf;
        baf_a = baf_a/10;
    }
    if(!(a%sum)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
s = 0
for ii in range(N):
    i = ii + 1
    if i % 3 == 0 and i % 5 == 0:
        continue
    elif i % 3 == 0:
        continue
    elif i % 5 == 0:
        continue
    else:
        s += i
print(s)

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

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

    static class CLower {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int a[] = ReadInput.readIntArray(n, in);
            int ans = 0, start = 0;
            for (int i = 1; i < n; i++) {
                if (a[i] <= a[i - 1]) {
                    ans = Math.max(ans, i - start);
                } else {
                    start = i;
                }
            }
            out.println(ans);
        }

    }

    static class ReadInput {
        public static int[] readIntArray(int size, Scanner in) {
            int a[] = new int[size];
            for (int i = 0; i < size; i++) {
                a[i] = in.nextInt();
            }
            return a;
        }

    }
}



Measured memory_bytes: 51280
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
using namespace std;

int main(){
  string s,t;
  cin >> s >> t;
  ll n = s.size();
  vector<vector<ll> > a(26),b(26);
  for(ll i=0;i<n;i++){
    a[s[i]-'a'].pb(i);
    b[t[i]-'a'].pb(i);
  }
  rep(i,26){
    sort(All(a[i]));
    sort(All(b[i]));
  }
  vector<string> x,y;
  rep(i,26){
    string o,p;
    rep(j,a[i].size()){
      o += to_string(a[i][j]);
    }
    if(a[i].size()>0) x.push_back(o);
    rep(j,b[i].size()){
      p += to_string(b[i][j]);
    }
    if(b[i].size()>0) y.push_back(p);
  }
  sort(All(x));
  sort(All(y));

  if(x.size()!=y.size()){
    cout << "No" << endl;
    return 0;
  }
  rep(i,x.size()){
    if(x[i]!=y[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 6944
n = int(input())
a = [int(i) for i in input().split()]

cnt = [1, 1, 1]
ind = 0
b = []
t = False

for i in range(n):
    if (a[i] != 0):
        break
    if i == n - 1:
        t = True

if t == True:
    print('Yes')
elif n % 3 != 0:
    print('No')
else:
    a.sort()
    if a[0] != 0:
        b.append(a[0])
        for i in range(n - 1):
            if a[i] == a[i + 1]:
                cnt[ind] += 1
            else:
                ind += 1
                if ind > 2:
                    break
                b.append(a[i + 1])
        if (ind == 2) and (cnt[0] == n // 3) and (cnt[1] == n // 3) and (cnt[2] == n // 3):
            if (b[0] ^ b[1] == b[2]):
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        for i in range(n - 1):
            if a[i] == a[i + 1]:
                cnt[ind] += 1
            else:
                ind += 1
                if ind > 1:
                    break
        if (ind == 1) and (cnt[0] == n // 3) and (cnt[1] == 2 * (n // 3)):
            print('Yes')
        else:
            print('No')


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

using namespace std;

typedef long long ll;

int N;
vector<double> dp;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    dp.resize(N + 1);
    dp[0] = 1;
    for (int i = 0; i < N; i++) {
        double p;
        cin >> p;
        for (int j = N; j >= 0; j--)
            dp[j] = (j == 0 ? 0 : dp[j - 1] * p) + dp[j] * (1 - p);
    }
    double result = 0;
    for (int i = (N + 1) / 2; i <= N; i++)
        result += dp[i];
    cout << setprecision(12);
    cout << result << endl;
}


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

using namespace std;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}

vector<int> zeros, ones;

int main(){

    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    //freopen("input.txt", "r", stdin);

    int n, k;
    string s;

    // get 0 spots
    // flip K consecutive 0 spots
    // Get length

    cin >> n >> k >> s;

    for(int i = 0; i < n; ++i){
        int cur = s[i] - '0';
        if(cur == 0){
            zeros.push_back(i);
        } else {
            ones.push_back(i);
        }
        while(i < n && s[i] - '0' == cur)
            ++i;
    }

    int best = 0;
    int regions = 0;
    int left = 0;

    for(int i = 0; i < n;){
        int cur = s[i] - '0';

        if(cur == 0)
            regions++;

        while(i < n && s[i] - '0' == cur)
            ++i;

        if(regions > k){
            cur = s[left] - '0';
            while(left < n && s[left] - '0' == cur)
                ++left;
            if(cur == 1){
                cur = 0;
                while(left < n && s[left] - '0' == cur)
                    ++left;
            }
            --regions;
        }

        best = max(best, i - left);

    }

    cout << best;

    return 0;
}


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

typedef long int lint;
typedef long long int llint;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n"

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k, x, y;

  cin >> n >> k >> x >> y;
  if (n > k) cout << k * x + (n - k) * y << endl;
  else cout << n * x << endl;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = int(input())
arrayP = [int(s) for s in input().split()]
 
cnt = 0
 
for i in range(0, n-2):
    threeNums = arrayP[i:i+3]
    threeNums.sort()
    if threeNums[1] == arrayP[i+1]:
        cnt += 1
 
print(cnt)


Measured memory_bytes: 3060
module Main where

import Data.Functor

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO ()
main = do
  {[w,h,x,y,r] <- getInts
  ; putStrLn (check (w,h,x,y,r))
}

check :: (Int,Int,Int,Int,Int) -> String
check (w,h,x,y,r)
  | x < r = "No"
  | y < r = "No"
  | x > w-r = "No"
  | y > h-r = "No"
  | otherwise = "Yes"

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

using namespace std;

int main(void)
{
	int a,b,c; cin>>a>>b>>c;
	if(a+b == c) cout<<"Yes"<<endl;
	else if(a+c == b) cout<<"Yes"<<endl;
	else if(b+c == a) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    int Dif=B-A;
    REP(i,N){
        int nom=N-1-i;
        if(C*nom-D*i<=Dif&&Dif<=D*nom-C*i){
            cout << "YES" << endl;return 0;
        }
    }
    cout << "NO" << endl;
    
    return 0;
}   





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,n,ctn,i;string s;
	while(cin>>n,n){
		cin>>s;
		for(a=0;a<n;a++){
			char t=s[0];ctn=1;stringstream F;
			for(i=1;i<(int)s.length();i++)if(t==s[i])ctn++;else F<<ctn<<t,ctn=1,t=s[i];
			F<<ctn<<t,s=F.str();
		}
		cout<<s<<endl;
	}
}

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

int main(){
    char s[3],t[3];
    int sum=0;
    for(int i=0;i<3;i++) cin>>s[i];
    for(int i=0;i<3;i++) cin>>t[i];
    for(int i=0;i<3;i++){
        if(s[i]==t[i]) sum++;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;//リストを使う
class Program
{

static string[] input = Console.ReadLine().Split(' ');
static long n = long.Parse(input[0]);
static long m = long.Parse(input[1]);
static long[] result = new long[n];//頂点0を１、隣接頂点を2と、交互に塗る。
static List<long>[] nextList = new List<long>[n];//隣接リスト
static bool twoGraph = true;//２部グラフならtrue

	 static void Main()
  {
    for(long i = 0; i < n; i++) nextList[i] = new List<long>();//リストの宣言
    for(long i = 0; i < m; i++)
    {
      long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);//１行ごとに受け取る
      nextList[nums[0]-1].Add(nums[1]-1);//隣接リストへ追加。
      nextList[nums[1]-1].Add(nums[0]-1);
    }
        
          result[0] = 1;
          Spread(0);//頂点0から色を広げる

         if(twoGraph) //２部グラフのとき
         {
            long whiteNum = 0;//頂点0と同じ色の頂点数
            for (long i = 0; i < n; i++)
            {
              if(result[i] == 1) whiteNum++;
            }
            Console.WriteLine(whiteNum*(n-whiteNum)-m);
         }
         else Console.WriteLine(n*(n-1)/2-m);//２部グラフでないとき
  }

   static void Spread(long vertex)//色を広げる
  {
    long color = result[vertex];//現在の頂点の色
    
  
    for(int i = 0; i < nextList[vertex].Count(); i++)
    {
      long a = (long)((List<long>)nextList[vertex])[i];
        if(result[a] == 0)
        {
          result[a] = 3 - color;//隣接頂点は別の色で塗る
          Spread(a);//色を広げる
        }
        else if(result[a] == color) twoGraph = false;//色の矛盾がある
    }
  }
}


Measured memory_bytes: 32928
N = int(input())


def func(x):
    n = x
    if n < 5:
        return 0
    if n % 2 == 0:
        cnt = 0
        i = 1
        n = n // 2
        while 5 ** i <= x:
            n = n // 5
            cnt += n
            i += 1

        return cnt

    else:
        return 0


print(func(N))


Measured memory_bytes: 2940
use std::io::stdin;
use std::str::FromStr;
use std::cmp::min;

fn main(){
    let (n, k): (i64, i64) = get_pair();
    let xs: Vec<i64> = get_vec();
    // let mut zero = 0;
    // for i in 0..n {
    //     zero = i;
    //     if xs[i] > 0 {
    //         break;
    //     }
    // }
    // let zero = xs[0]
    // let ys: Vec<i64> = xs.iter().map(|x| x+zero).collect();
    let mut ans = 10_000_000_000;
    let kk = (k-1) as usize;
    let m = (n - kk as i64) as usize;
    for i in 0..m {
        let e = min(xs[i].abs(), xs[i+kk].abs());
        ans = min(ans, e+xs[i+kk]-xs[i]);
    }

    println!("{}", ans);
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}


Measured memory_bytes: 8444
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
double x[1007],y[1007];
double X,Y,d,e,P=0.1;
int main(){
    int n;
	scanf("%d",&n);
	for(int i=0;i<n;++i){
		scanf("%lf%lf",&x[i],&y[i]);
		X+=x[i];
		Y+=y[i];
	}
	X/=n;
	Y/=n;
	for(int i=0;i<30000;++i){
		int f=0;
		d=(X-x[0])*(X-x[0])+(Y-y[0])*(Y-y[0]);
		for(int j=1;j<n;++j){
			e=(X-x[j])*(X-x[j])+(Y-y[j])*(Y-y[j]);
			if(d<e)
                d=e,f=j;
		}
		X+=(x[f]-X)*P;
		Y+=(y[f]-Y)*P;
		P*=0.999;
	}
	printf("%.10lf",sqrt(d));
}


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

int main()
{
  int N, a;
  cin >> N;
  map<int, int>A;
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a;
    sum += a;
    A[a]++;
  }
  int Q;
  cin >> Q;
  int B, C, keep;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    if (A.count(B)) {
      keep = A[C];
      A[C] += A[B];
      sum += C*(A[C] - keep) - B*A[B];
      A.erase(B);
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 6512
#include <stdio.h>
int main(void){
   int n, m, i, j, SUM, catalog[1000]={}, tmp;
   
   while(1){
    scanf("%d %d", &n, &m);
    
    if(n==0 && m==0) break;
   
    tmp=0;
    SUM=0;
    for(i=1; i<=n; i++){
           scanf("%d", &catalog[i]);
       }
       for(i=1; i<=n; i++){
           for(j=i+1; j<=n; j++){
               tmp=catalog[i]+catalog[j];
               if(tmp<=m && tmp>SUM) SUM=tmp;
           }
       }
       if(SUM==0){
           printf("NONE\n");
       }
       else printf("%d\n", SUM);
       
   }
       return 0;
}



Measured memory_bytes: 2044
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
	char str[21];
	while(~scanf("%s",str))
	{
	   for(int i = 0; i < 19; i++)
	   {
	   	    if(str[i] == ',')
	   	      str[i] = ' ';
	   }
	   printf("%s\n",str);
	}
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int L = sc.nextInt();

		int A[][] = new int[N][M];
		int B[][] = new int[M][L];

		String buf_A[] = new String[M];
		String buf_B[] = new String[L];

		for(int row = 0; row < N; row++){
			for(int col = 0; col < M; col++){
				A[row][col] = sc.nextInt();
			}
		}

		for(int row = 0; row < M; row++){
			for(int col = 0; col < L; col++){
				B[row][col] = sc.nextInt();
			}
		}

		Long ans;

		for(int A_row = 0; A_row < N; A_row++){
			for(int B_col = 0; B_col < L; B_col++){
				ans = 0L;
				for(int B_row = 0; B_row < M; B_row++){
					ans += A[A_row][B_row]*B[B_row][B_col];
				}
				if(B_col == 0){
					System.out.printf("%d", ans);
				}else{
					System.out.printf(" %d", ans);
				}
			}
			System.out.printf("\n");
		}
	}
}




Measured memory_bytes: 81968
//#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int main(){
	int n, ac = 0, wa = 0, tle = 0, re = 0;
	char ss[5];
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> ss;
		if(strcmp(ss, "AC") == 0) ac++;
		else if(strcmp(ss, "WA") == 0) wa++;
		else if(strcmp(ss, "TLE") == 0) tle++;
		else re++;
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
	return 0;
}

Measured memory_bytes: 3624
using System;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] dlmt = " ".ToCharArray();
            string strline = Console.ReadLine();
            string[] str = strline.Split(dlmt);

            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);

            int s = a * b;
            int r = (a + b) * 2;

            Console.WriteLine(s + " " + r);
        }
    }
}



Measured memory_bytes: 15960
#include<bits/stdc++.h>
using namespace std;
#define MAXN 1000
#define MAXM 1000000

int N, M, A[MAXN + 3], idx[MAXN + 3][MAXN + 3];
int inDegree[MAXM + 3], visited[MAXM + 3];
vector<int> adj[MAXM + 3];

void generateIndex() {
    M = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            M += 1;
            idx[i][j] = idx[j][i] = M;
        }
    }
}

bool DFS(int u, int prv) {
    visited[u] = 1;

    bool cycleExist = false;
    for (auto v: adj[u]) {
        if (visited[v] == 1) {
            if (v != prv) cycleExist = true;
        } else if (visited[v] == -1) {
            cycleExist |= DFS(v, u);
        }
    }

    visited[u] = 2;

    return cycleExist;
}

bool checkCycle() {
    bool cycleExist = false;

    memset(visited, -1, sizeof(visited));
    for (int i = 1; i <= M; i++) {
        if (visited[i] == -1)
            cycleExist |= DFS(i, 1);
    }

    return cycleExist;
}

int main() {
    cin >> N;

    generateIndex();

    memset(inDegree, 0, sizeof(inDegree));
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N - 1; j++) {
            cin >> A[j];
            if (j > 1) {
                int u = idx[i][A[j - 1]];
                int v = idx[i][A[j]];
                adj[u].push_back(v);
                inDegree[v] += 1;
            }
        }
    }

    if (checkCycle()) {
        cout << -1 << endl;
        return 0;
    }

    vector<int> sources; //node with zero indegree
    for (int i = 1; i <= M; i++) {
        if (inDegree[i] == 0) sources.push_back(i);
    }

    int answer = 0;
    while (sources.size() > 0) {
        answer += 1;

        vector<int> tempSources;

        for (auto u: sources) {
            for (auto v: adj[u]) {
                inDegree[v] -= 1;
                if (inDegree[v] == 0) tempSources.push_back(v);
            }
        }

        sources.clear();
        for (auto u: tempSources) sources.push_back(u);
    }

    cout << answer << endl;
}


Measured memory_bytes: 51200
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { -1, 0, 0, 1 };
const ll dy[4] = { 0, -1, 1, 0 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
struct Accelerate_Cin {
	Accelerate_Cin() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
};
///////////////////////////////////////

//結論から言うと広義単調減少列の長さの最大値Lである。これを証明する
//数列の後ろから順にどの色で塗るかを決めていく最も後ろの要素に関しては何らかの色で
//塗る必要がありかつ他の要素に色は着いていないので適当に1色で塗っておく
//後ろから2番目以降の数Aiに関しては各色cで塗られている要素の内現在の最小の値Bcはいくつか
//を考える。まずBc<=AiならばAiをcで塗ることは条件に反するためできない。

int main() {
	ll n; cin >> n;
	vector<ll>a(n);
	REP(i, n)cin >> a[i];
	multiset<ll>s;
	for (ll i = 0; i < n; ++i) {
		ll now = a[i];
		auto itr = s.lower_bound(now);
		if (itr != s.begin())s.erase(--itr);
		s.insert(now);
	}
	cout << s.size() << endl;
	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n;
	string s;
	cin >> n >> s;
	
	int totalw = 0;
	for(int i = 0; i < n; i++) if(s[i] == 'W') totalw++;
	
	int ans = inf, white = 0;
	ans = min(totalw, n - totalw);
	
	for(int i = 0; i < n; i++) {
		if(s[i] == 'W') white++;
		
		int red = (i + 1) - white, otherw = totalw - white, otherr = n - totalw - red;
		int swp = min(white, otherr);
		ans = min(ans, swp + (white - swp + otherr - swp));
	}
	
	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 3780
#include<stdio.h>
#include<stdlib.h>
int main(void){
    int *cost,i,dmax=-1,dmax_i=0,ans=0;
    cost=(int*)malloc(sizeof(int)*5);
    for(i=0;i<5;i++){
        scanf("%d",&cost[i]);
    }
    for(i=0;i<5;i++){
        if(dmax<10-(cost[i]%10) && cost[i]%10!=0){
            dmax=10-(cost[i]%10);
            dmax_i=i;
        }
    }
    for(i=0;i<5;i++){
        if(i==dmax_i){
            continue;
        }
        if(cost[i]%10==0){
            ans+=cost[i];
        }else{
            ans+=10-(cost[i]%10);
            ans+=cost[i];
        }
    }
    printf("%d\n",ans+cost[dmax_i]);
    free(cost);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define pb push_back
const int MOD=1e9+7;
const int INF=1e15;


signed main(){
    int N,X;cin>>N>>X;
    int A[N];
    REP(i,N){
        int a;cin>>a;
        A[i]=abs(a-X);
    }
    int ans=A[0];
    REP(i,N){
        A[i];
        if(A[i]!=0)ans=__gcd(ans,A[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))



N=int(input())
A=nl()

Hsum=sum(A)
Ntop=1
topnow=1

if(A[0]>1):
    print(-1)
    sys.exit(0)

if(A[0]==1):
    if(N==0):
        print(1)
        sys.exit(0)
    else:
        print(-1)
        sys.exit(0)
    
for i in range(1,len(A)):
    if(topnow*2<=Hsum):
        topnow=topnow*2-A[i]
        if(topnow<0):
            print(-1)
            sys.exit(0)
        Hsum-=A[i]
        Ntop+=topnow+A[i]
    else:
        topnow=Hsum
        Ntop+=Hsum
        Hsum-=A[i]

print(Ntop)

Measured memory_bytes: 21640
import sys
n,x,m=map(int,input().split())
a=[0]*(m+2)
cnt=[0]*(m+2)
a[1],f=x,x
cnt[f]=1
if x==0:
  print(0)
  sys.exit()
for i in range(2,m+1):
  f=f*f%m
  a[i]=f
  if cnt[f]==0:
    cnt[f]=1
  else:
    break
ind=a[1:].index(f)+1
ans=sum(a[:ind])+sum(a[ind:i])*((n-ind+1)//(i-ind))
p=(n-ind+1)%(i-ind)
ans+=sum(a[ind:ind+p])
print(ans)

Measured memory_bytes: 66908
package main

import (
	"fmt"
)

func main() {
	var n, d, x int
	fmt.Scan(&n, &d, &x)

	listA := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&listA[i])
	}

	total := x

	for i := 0; i < n; i++ {
		for j := 0; j < d; j++ {
			if listA[i]*j+1 <= d {
				total++
			}
		}
	}

	fmt.Println(total)

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;
const int MAX_L = 500001;

int a[MAX_N];
int k[MAX_N];
multimap<int,int> mp;
ll t[MAX_N];
int n,L;

int main()
{
	scanf("%d%d",&n,&L);
	rep(i,n){
		scanf("%d",&a[i]);
		k[i] = a[i];
		mp.emplace(a[i],i);
	}
	sort(a,a+n,greater<int>());
	int id = 0;
	while(id<n){
		auto p = mp.equal_range(a[id]);
		auto it = p.first;
		int i = 0;
		while(it != p.second){
			int prev = it->second;
			if(prev!=0&&prev!=n-1){
				if(k[prev] > k[prev-1] && k[prev] > k[prev+1]){
					t[prev] = L-a[id];
				}else if(k[prev] < k[prev-1] && k[prev] > k[prev+1]){
					t[prev] = t[prev-1] + L-a[id];
				}else if(k[prev] > k[prev-1] && k[prev] < k[prev+1]){
					t[prev] = t[prev+1] + L-a[id];
				}else{
					t[prev] = max(t[prev-1],t[prev+1])+L-a[id];
				}
			}else if(prev==0){
				if(k[0] > k[1]){
					t[0] = L-a[id];
				}else{
					t[0] = t[1] + L-a[id];
				}
			}else{
				if(k[n-1] > k[n-2]){
					t[n-1] = L-a[id];
				}else{
					t[n-1] = t[n-2] + L-a[id];
				}
			}
			it++;
			i++;
		}
		id += i;
	}
	printf("%lld\n",*max_element(t,t+n));
	return 0;
}

Measured memory_bytes: 9536
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<iomanip>
#include<fstream>
#include<ctime>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;

struct punktInt {
	int x;
	int y;
};

punktInt tab[105];
int a, b, i, bestL, bestR, j, n;
double res[105];

double len123(punktInt& a, punktInt& b) {
	int dx = a.x - b.x;
	int dy = a.y - b.y;
	return sqrt(dx * 1LL * dx + dy * 1LL * dy);
}

long long detInt (punktInt& a, punktInt& b, punktInt& c) {
    return a.x*1LL*b.y + b.x*1LL*c.y + c.x*1LL*a.y - a.x*1LL*c.y - b.x*1LL*a.y - c.x*1LL*b.y;
}

// funkcja sprawdza czy przechodząc z a do b i c skręcamy w lewo(1), w prawo(-1) czy punkty są współlniowe(0)
int ccwInt (punktInt& a, punktInt& b, punktInt& c) {
        long long d=detInt(a,b,c);
        if (d>0) return 1;
        if (d<0) return -1;
        return 0;
}

bool isMostL(int w1, int w2) {
	for (int i=0;i<n;i++) if (i != w1 && i != w2 && ccwInt(tab[w1], tab[w2], tab[i]) > 0) return false;
	return true;
}

bool isMostR(int w1, int w2) {
	for (int i=0;i<n;i++) if (i != w1 && i != w2 && ccwInt(tab[w1], tab[w2], tab[i]) < 0) return false;
	return true;
}

bool allTheSameDir(int w) {
	int dx = -2;
	int dy = -2;
	for (int i=0;i<n;i++) if (i != w) {
		if (dx == -2) {
			if (tab[i].x > tab[w].x) dx = 1; else if (tab[i].x < tab[w].x) dx = -1; else dx = 0;
			if (tab[i].y > tab[w].y) dy = 1; else if (tab[i].y < tab[w].y) dy = -1; else dy = 0;
			continue;
		}
		if (tab[i].x > tab[w].x && dx != 1) return false;
		if (tab[i].x < tab[w].x && dx != -1) return false;
		if (tab[i].x == tab[w].x && dx != 0) return false;
		if (tab[i].y > tab[w].y && dy != 1) return false;
		if (tab[i].y < tab[w].y && dy != -1) return false;
		if (tab[i].y == tab[w].y && dy != 0) return false;
	}
	return true;
}

int main() {
scanf("%d", &n);
for (i=0;i<n;i++) {
	scanf("%d %d", &tab[i].x, &tab[i].y);
}
for (i=0;i<n;i++) {
	bestL = bestR = -1;
	for (j=0;j<n;j++) if (j != i) {
		if (bestL == -1 && isMostL(i, j)) bestL = j;
		if (bestR == -1 && isMostR(i, j)) bestR = j;
	}
	//printf("%d %d %d\n", i, bestL, bestR);
	if (bestL == -1) {
		res[i] = 0.0;
		continue;
	}
	if (bestL == bestR) {
		if (allTheSameDir(i)) res[i] = 0.5; else res[i] = 0.0;
		continue;
	}
	
	if (ccwInt(tab[bestL], tab[i], tab[bestR]) <= 0) {
		res[i] = 0.0;
		continue;
	}
	double det = detInt(tab[bestL], tab[i], tab[bestR]);
	double a1 = len123(tab[bestL], tab[i]);
	double a2 = len123(tab[bestR], tab[i]);
	double a3 = len123(tab[bestL], tab[bestR]);
	det /= a1;
	det /= a2;
	if (a1 * a1 + a2 * a2 < a3 * a3) res[i] = asin(det) / (2 * M_PI); else res[i] = (M_PI - asin(det)) / (2 * M_PI);
}
for (i=0;i<n;i++) printf("%.9lf\n", res[i]);
return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main(){
    int n, w;
    while(cin >> n >> w, n||w){
        double g[2000] = {0};
        int mx = 0, my = 0;
        rep(i,n){
            int j = 0;
            double a;
            cin >> a;
            while(true){
                if(a >= w * j && a < w * (j + 1)){
                    g[j]++;
                    mx = mx > j ? mx : j;
                    my = my > g[j] ? my : g[j];
                    break;
                }
                j++;
            }
        }
        mx++;
        double sum = 0;
        rep(i,mx - 1){
            sum += (mx - 1 - i) * g[i] / my / (mx - 1);
        }
        sum+=0.01;
        cout << fixed << setprecision(6) << sum << endl;
    }
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define sz(x) ((int)x.size())
#define mp(x, y) make_pair(x, y)
using namespace std;

int n;
vector<pair<int, int> > tmp, ans;

int main(){
    scanf("%d", &n);
    if(n & 1){
        for(int i = 1; i <= (n - 1)/2; i ++)
            tmp.push_back(mp(i, n - i));
        for(int i = 0; i < sz(tmp); i ++){
            int x = tmp[i].first;
            int y = tmp[i].second;
            ans.push_back(mp(n, x));
            ans.push_back(mp(n, y));
        }
        for(int i = 1; i < sz(tmp); i ++){
            for(int j = 0; j < i; j ++){
                int x = tmp[i].first;
                int y = tmp[i].second;
                int p = tmp[j].first;
                int q = tmp[j].second;
                ans.push_back(mp(x, p));
                ans.push_back(mp(x, q));
                ans.push_back(mp(y, p));
                ans.push_back(mp(y, q));
            }
        }
    }
    else{
        for(int i = 1; i <= n/2; i ++)
            tmp.push_back(mp(i, n - i + 1));
        for(int i = 1; i < sz(tmp); i ++){
            for(int j = 0; j < i; j ++){
                int x = tmp[i].first;
                int y = tmp[i].second;
                int p = tmp[j].first;
                int q = tmp[j].second;
                ans.push_back(mp(x, p));
                ans.push_back(mp(x, q));
                ans.push_back(mp(y, p));
                ans.push_back(mp(y, q));
            }
        }
    }
    cout << sz(ans) << '\n';
    for(int i = 0; i < sz(ans); i ++)
        cout << ans[i].first << ' ' << ans[i].second << '\n';
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  if(b%a==0) cout<<a+b<<'\n';
  else cout<<b-a<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define dip ll t;cin>>t;while(t--)
#define dip1 int t;t=1;while(t--)
bool comp(pair<ll,ll>&a,pair<ll,ll>&b){
return min(2*a.first,a.second)-a.first > min(2*b.first,b.second)-b.first;
}
ll mod=1e9+7;
ll moc(ll w,ll z){
    return ((w%mod)*(z%mod))%mod;
}
int main(){
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    int t;
    t=1;
    cin>>t;
    int dp[3]={0};
    for(int m=0;m<t;m++){
      int a[3],b[3]={0};
      for(int i=0;i<3;i++){
        cin>>a[i];
      }
        for(int i=0;i<3;i++){
          for(int j=0;j<3;j++){
            if(i!=j){
              b[j]=max(b[j],dp[i]+a[j]);
             
            }

          }

        }
        for(int i=0;i<3;i++){
          dp[i]=b[i];
         }
      }
    cout<<max({dp[0],dp[1],dp[2]});
   return 0;
} 


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    static long[] P = new long[51];
    static long[] B = new long[51];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long X = sc.nextLong();
        sc.close();
        // レベルiバーガーに含まれるパティの枚数
        P[0] = 1L;
        // レベルiLバーガーの層の総数
        B[0] = 1L;
        for(int i = 1; i <= 50; i++){
            P[i] = P[i - 1] * 2 + 1L;
            B[i] = B[i - 1] * 2 + 3L;
        }

        System.out.println(f(N, X));
    }

    // レベルNバーガーの下からX層に含まれるパティの枚数を返却する
    private static long f(int N, long X){
        if(N == 0){
            // レベル0バーガーの時
            if(X > 0){ return 1L; } else { return 0L;}
        } else if(X <= 1 + B[N-1]){
            // 食べる層数Xがバン＋レベルN-1バーガー以下の時
            return f(N-1, X-1);
        } else {
            // 食べる層数Xがバン＋レベルN-1バーガーより多い時（一つ目のレベルN-1バーガーを食べきってそれ以降のパティとレベルN-1バーガーを食べるとき）
            return P[N-1] + 1L + f(N-1, X-B[N-1]-2L);
        }

    }
}



Measured memory_bytes: 23764
from collections import deque

v, e = map(int,input().split())
edges = [[] for _ in range(v)]
in_num = [0 for _ in range(v)]

for _ in range(e):
    s,t = map(int, input().split())
    edges[s].append(t)
    in_num[t] += 1

q = deque()

for i in range(len(in_num)):
    if in_num[i] == 0:
        q.append(i)

ans = []
while q:
    node = q.popleft()
    ans.append(node)
    for v in edges[node]:
        in_num[v] -= 1
        if in_num[v] == 0:
            q.append(v)

for i in ans:
    print(i)


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

int N, M, Q, ans;
vector<vector<int>> ABCD;

void dfs(vector<int> A, int pre) {
  if (A.size() == N) {
    int sum = 0;
    for (auto a : ABCD) if (A[a[1]] - A[a[0]] == a[2]) sum += a[3];
    ans = max(ans, sum);
    return;
  }
  for (int i = pre; i <= M; i++) {
    A.push_back(i);
    dfs(A, i);
    A.pop_back();
  }
}

int main() {
  cin >> N >> M >> Q;
  for (int a, b, c, d; cin >> a >> b >> c >> d;) ABCD.push_back({--a, --b, c, d});
  vector<int> A;
  dfs(A, 1);
  cout << ans << "\n";
}

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

int func(int n, int m){
	if(m==n)return 1;
	else{
		int cnt=0;
		for(int i=1;i<=3 && m+i<=n;++i){
			cnt += func(n,m+i);
		}
		return cnt;
	}
}

int main(){
	int n;
	while(cin>>n,n){
		cout << func(n,0)/10/365+1 << endl;
	}
}

Measured memory_bytes: 1160