akhauriyash/Code-Regression huggingface dataset:
n,m=map(int,input().split())
L1=[]
Ln=[]
for i in range(m):
    a,b=map(int,input().split())
    if a==1:
        L1.append(b)
    if b==n:
        Ln.append(a)
print('IMPOSSIBLE' if set(L1)&set(Ln) ==set() else 'POSSIBLE')

Measured memory_bytes: 21824
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    rep(i,h) cin >> a[i];
    rep(i, w+2) {
        cout << '#';
        if(i == w + 1) cout << endl;
    }
    for(int i = 0; i < h; i++) {
        cout << '#' << a[i] <<'#' << endl;
    }
    rep(i, w+2) {
        cout << '#';
        if(i == w + 1) cout << endl;
    }
}

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

int main() {
    long long N,K,Q;
    cin>>N>>K>>Q;
    vector<long long>A(Q);
    for (long long i=0; i<Q; i++) cin >> A.at(i);

    vector<long long>B(N,K-Q);

    for (long long i=0; i<Q; i++) {
        long long x=A.at(i)-1;
        B.at(x)+=1;
    };

    for (long long i=0; i<N; i++) {
        if (B.at(i)<=0) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    };
}

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

int main() {
    std::ios_base::sync_with_stdio(0);
    std::string s,t,u;
    int a,b;
    std::cin >> s >> t >> a >> b >> u;
    if (s == u) --a;
    else if (t == u) --b;
    std::cout << a << " " << b << std::endl;
    return 0;
}

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

int main(void) 
{

  int a;
    if(scanf("%d", &a) == 1);
  
  if(a == 7 || a == 5|| a == 3){
    printf("YES");
  }else{
	printf("NO");
  }
    

    return 0;
}

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

int main(){
    int n;
    cin>>n;
    
    int max=0;//絶対値最大のやつ
    int maxindex=0;//それの番号
    
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(abs(a)>=abs(max)){
            max=a;
            maxindex=i;
        }
    }
    
    maxindex++;//1-indexedに変換
    
    int m=2*n-1;//操作の回数
    cout<<m<<endl;
    
    //Step 1:絶対値最大のやつを他に足して符号を揃える
    for(int i=1;i<=n;i++){
        cout<<maxindex<<" "<<i<<endl;
    }
    
    //Step 2:前or後ろから順に足していく
    if(max>=0){
        for(int i=1;i<n;i++){
            cout<<i<<" "<<i+1<<endl;
        }
    }else{
        for(int i=n;i>1;i--){
            cout<<i<<" "<<i-1<<endl;
        }
    }
    
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

#define INF (1e9)

int N;

int main() {
    cin >> N;

    vvvi A(N, vvi(2, vi(0)));
    for (int i = 0; i < N; i++) {
        int M;
        cin >> M;
        for (int j = 0; j < M; j++) {
            int x, y;
            cin >> x >> y;
            x--;
            A[i][y].push_back(x);
        }
    }

    int ans = 0;
    for (int mask = 0; mask < (1 << N); mask++) {
        bool isAble = true;
        int nTrue = 0;
        for (int i = 0; i < N; i++) {
            if ((mask >> i) & 1) {
                nTrue++;
                for (int j = 0; j < A[i][0].size(); j++) {
                    if (((mask >> A[i][0][j]) & 1) != 0) {
                        isAble = false;
                        break;
                    }
                }
                for (int j = 0; j < A[i][1].size(); j++) {
                    if (((mask >> A[i][1][j]) & 1) != 1) {
                        isAble = false;
                        break;
                    }
                }
            }
            if (!isAble) break;
        }
        if (isAble) ans = max(ans, nTrue);
    }

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


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

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int A = input.nextInt();
		int B = input.nextInt();
		int C = input.nextInt();
		int D = input.nextInt();
		while (C>0&&A>0) {
			C-=B;
			A-=D;
		}
		System.out.println(C<=0? "Yes":"No");
	}
}

Measured memory_bytes: 27040
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<vector<long long>> A;
	A.resize(N);
	for (int i = 0; i < N; ++i) {
		A[i].resize(2);
		cin >> A[i][0];
		A[i][1] = i;
	}
	sort(A.begin(), A.end());
	long long count = 0;
	for (int i = 0; i < N; ++i) {
		if (A[i][1] % 2 != i % 2) {
			++count;
		}
	}
	cout << count / 2 << endl;
	return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	ll N, A, B; cin >> N >> A >> B;
	vector<int>vec(N);
	rep(i, 0, N)cin >> vec[i];
	ll ans = 0, x = vec[0];
	rep(i, 0, N - 1) {
		ans += min((vec[i + 1] - vec[i]) * A, B);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3668
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
typedef long long ll;
using namespace std;

ll const MAX = (1 << 20);
ll a[MAX], b[MAX];
ll d[MAX], cost[MAX];
ll cost1[MAX], cost2[MAX];
map<ll, ll> m1, m2;

int main() {
	ll n, ma, mb;
	cin >> n >> ma >> mb;
	REP(i, 1, n) {
		ll x, y, z;
		cin >> x >> y >> z;
		ll v = x * mb - y * ma;
		d[i] = v;
		cost[i] = z;
	}
	ll n1 = n / 2;
	ll n2 = n - n1;
	ll n1_ = (1 << n1) - 1;
	ll n2_ = (1 << n2) - 1;
	REP(i, 0, n2_) {
		b[i] = cost2[i] = 0;
		REP(j, 0, n2 - 1) {
			if (((i >> j) & 1) == 1) {
				b[i] += d[j + 1 + n1];
				cost2[i] += cost[j + 1 + n1];
			}
		}
		ll t = m2[b[i]];
		if (t == 0) {
			m2[b[i]] = cost2[i];
		}
		else {
			m2[b[i]] = min(t, cost2[i]);
		}
	}
	REP(i, 0, n1_) {
		a[i] = cost1[i] = 0;
		REP(j, 0, n1 - 1) {
			if (((i >> j) & 1) == 1) {
				a[i] += d[j + 1];
				cost1[i] += cost[j + 1];
			}
		}
		a[i] *= -1;
		ll t = m1[a[i]];
		if (t == 0) {
			m1[a[i]] = cost1[i];
		}
		else {
			m1[a[i]] = min(t, cost1[i]);
		}
	}
	sort(a, a + n1_ + 1);
	sort(b, b + n2_ + 1);
	ll ans = 10000000000;
	REP(i, 0, n1_) {
		if (a[i] == 0) {
			if (m1[0] > 0 && m2[0] > 0) {
				ans = min(ans, min(m1[0], m2[0]));
			}
			else if(m1[0]>0||m2[0]>0){
				ans = min(ans, max(m1[0], m2[0]));
			}
		}
		else if (m2[a[i]] != 0) {
			ans = min(ans, m1[a[i]] + m2[a[i]]);
		}
	}
	if (ans == 10000000000) { ans = -1; }
	cout << ans << endl;
}

Measured memory_bytes: 37248
n,a=map(int,raw_input().split())
for x in range(n+1):
    for y in range(n+1):
        z = n-(x+y)
        if a==(10000*x)+(5000*y)+(1000*z) and z >= 0:
            print '%d %d %d' % (x,y,z)
            quit()
print '-1 -1 -1'

Measured memory_bytes: 2820
#include<stdio.h>
int main(void)
{
  int W, a, b;
  scanf("%d %d %d", &W, &a, &b);
  if(b > (a + W)){
    int answer = b - (a + W);
    printf("%d\n", answer);
  } else if((a <= b && (a + W) >= b) ||
   (a <= (b + W) && (b + W) <= (a + W))){
    printf("0\n");
  } else if(a > (b + W)){
    int answer = a - (b + W);
    printf("%d\n", answer);
  }
  return 0;
}



Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int psize;
int prime[200000];
bool bprime[200000];
int cand[200000];

int main() {
  MEMSET(bprime, true);
  bprime[0] = bprime[1] = false;
  REP(i, 200000) {
    if (!bprime[i]) { continue; }
    prime[psize++] = i;
    for (int j = i + i; j < 200000; j += i) {
      bprime[j] = false;
    }
  }
  int n, p;
  while (scanf("%d %d", &n, &p), n != -1 && p != -1) {
    int s = 0;
    REP(i, psize) {
      if (n < prime[i]) { s = i; break; }
    }
    int m = 0;
    REP(i, 100) REP(j, i + 1) {
      cand[m++] = prime[s + i] + prime[s + j];
    }
    sort(cand, cand + m);
    printf("%d\n", cand[p - 1]);
  }
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll T1, T2, A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    if (A1 < B1) {
        swap(A1, B1);
        swap(A2, B2);
    }
    // A1 > B1
    ll sum1 = T1 * A1 + T2 * A2, sum2 = T1 * B1 + T2 * B2;
    if (sum1 > sum2) {
        cout << 0 << endl;
    } else if (sum1 == sum2) {
        cout << "infinity" << endl;
    } else {
        ll rem = T1 * A1 - T1 * B1;
        ll diff = sum2 - sum1;
        ll ans = 2 * ((rem + diff - 1) / diff) - 1;
        if (rem % diff == 0) {
            ans++;
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e10
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<lli>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using lli = long long int;
template<typename T> bool chmax(T &a, T &b){ if(a<b) { a=b; return 1; }}
template<typename T> bool chmin(T &a, T &b){ if(b<a) { a=b; return 1; }}
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T arrdebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    lli n;
    lli h[500];

    cin >> n;
    rep(i, n){
        cin >> h[i];
    }

    int ans = 0;

    while(true){
        int cnt=0;
        bool flg=true;
        rep(i, n){
            if(h[i]!=0){
                h[i]--;
                cnt=1;
                flg=false;
            }else{
                ans+=cnt;
                cnt=0;
            }
        }
        ans += cnt;
        if(flg) break;
    }

    cout << ans << endl;

    return 0;
}

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

const int INF = 1001001001;
const int NV=100100;

int main() {
  int64_t H,W,ans;
  cin>>H>>W;
  if((H*W)%2==0){
    ans=H*W/2;
  }
  else{
    ans=(H*W+1)/2;
  }
  if(H!=1&&W!=1){
    cout<<ans<<endl;
  }
  else{
    cout<<1<<endl;
  }
}

Measured memory_bytes: 256
/// @file
/// @copyright 2018 thousand
/// @version Accepted.
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::vector;

namespace {
void DeriveLucasNumbers(vector<int64_t>* L) {
  L->push_back(2);
  L->push_back(1);
  for (int i = 2; i <= 86; ++i)
    L->push_back((*L)[i - 1] + (*L)[i - 2]);
}
}  // namespace

int main() {
  vector<int64_t> L;
  DeriveLucasNumbers(&L);
  int N;
  cin >> N;
  cout << L[N] << endl;
}


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

int N;
int A[200];

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

  int count = 0;

  while(true) {
    for(int i = 0; i < N; i++) {
      if(A[i] % 2 == 0) A[i] /= 2;
      else goto END;
    }
    count++;
  }
  END:

  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

ans = 0
previous = 0
same_count = 0
for i in range(N):
    if previous != a[i]:
        previous = a[i]
        if same_count != 0:
            ans += (same_count + 1) // 2
            same_count = 0
    else:
        previous = a[i]
        same_count += 1

    if i == N-1 and same_count != 0:
        ans += (same_count + 1) // 2

print(ans)

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

using namespace std;

using ll = long long;


int main(){
    ll n; cin >> n;
    ll a = 0, w = 0, t = 0, r = 0;
    while(n--){
        string s; cin >> s;
        if(s[0] == 'A')a++;
        else if(s[0] == 'T')t++;
        else if(s[0] == 'W')w++;
        else r++;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;

    return 0;

}


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

long long a, b, c, d, ans = 0;

int main() {
  cin >> a >> b >> c >> d;
  if(c != -1 && d != -1)
    ans = c - d;
  else
    ans = b - a;
  if(ans > 0)
    cout << "Alice" << endl;
  else if(ans == 0)
    cout << "Draw" << endl;
  else
    cout << "Bob" << endl;
  return 0;
}


Measured memory_bytes: 3088
import java.io.IOException;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
         Scanner sc = new Scanner(System.in);
         int a = sc.nextInt();
         int b = sc.nextInt();
         int c = sc.nextInt();
         
         if(a<=b && b<=c){System.out.println(a+" "+b+" "+c);}
         else if(a<=b && b>=c && a>=c){System.out.println(c+" "+a+" "+b);}
         else if(a<=b && b>=c && a<=c){System.out.println(a+" "+c+" "+b);}
         else if(a>=b && b>=c){System.out.println(c+" "+b+" "+a);}
         else if(a>=b && b<=c && a>=c){System.out.println(b+" "+c+" "+a);}
         else if(a>=b && b<=c && a<=c){System.out.println(b+" "+a+" "+c);}
	}

}

Measured memory_bytes: 26232
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
int main() {
	ll k;
	cin >> k;
	cin >> n;
	vector<ll> a(n);
	vector<ll> b(n);
	rep(i, n) {
		cin >> a[i];
	}
	ll m = -1;
	rep(i, n-1) {
		b[i] = a[i+1] - a[i];
		chmax(m, b[i]);
	}
	b[n - 1] = (k - a[n - 1]) + a[0];
	chmax(m, b[n-1]);
	cout << k - m << endl;
}



Measured memory_bytes: 3328
use io::*;
use proconio::{fastout, input};
use std::*;

#[fastout]
fn main() {
    input! {
        x : i32,
        n : usize,
    }
    if n == 0 {
        println!("{}", x);
        return;
    }
    input! {
        p : [i32; n]
    }
    let s: collections::HashSet<i32> = p.into_iter().collect();
    for i in 0..200 {
        if !s.contains(&(x - i)) {
            println!("{}", x - i);
            return;
        }
        if !s.contains(&(x + i)) {
            println!("{}", x + i);
            return;
        }
    }
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
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);
        ICoins solver = new ICoins();
        solver.solve(1, in, out);
        out.close();
    }

    static class ICoins {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            double[] dp = new double[n + 1];
            Arrays.fill(dp, 0);
            dp[0] = 1;

            for (int i = 0; i < n; i++) {
                double p = in.nextDouble();
                for (int j = dp.length - 1; j >= 0; j--) {
                    if (j > 0) {
                        dp[j] = dp[j] * (1 - p) + dp[j - 1] * p;
                    } else {
                        dp[0] *= (1 - p);
                    }
                }
            }

            double res = 0;
            for (int i = (n + 1) / 2; i <= n; i++) {
                res += dp[i];
            }
            out.println(res);

        }

    }
}



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

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

  for (int i = 0; i < N; i++){
    string s;
    cin >> s;
    
    if (s != "Y"){
      if (i == N-1){
      cout << "Three" << endl;
      }
    }
    if (s == "Y"){
      cout << "Four" << endl;
      break;
    }
    
  }// ここにプログラムを追記
}



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

int main() {
    ll n;
    cin >> n;
    //ansはでかい数で初期化
    ll ans = 1e18;
    for(ll i = 1; i*i <= n; i++) {
        //割り切れた場合のみ通過
        if(n % i != 0) continue;
        ll j = n/i;
        //最小値を探索し続ける
        ans = min(ans, i + j - 2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	bool ok=false;
	range(i,1,n-1){
		ll e=max(a+c*i, b+c*(n-i-1));
		ll f=min(a+d*i, b+d*(n-i-1));
		ok|=f>=e;
	}
	YN(ok);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int A, B; cin >> A >> B;
	if (A % 2 == 1 && B % 2 == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll a, b, h;
  cin >> a >> b >> h;

  cout << (a+b)*h/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;
using pli = pair<long long, int>;
using vpli = vector<pli>;

int main() {
  ll N;
  cin >> N;
  
  if (N % 2 == 0)
    cout << N / 2 - 1 << endl;
  else
    cout << (N - 1) / 2 << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int n, m; cin >> n >> m;
	vector<int> x(m);
	vector<int> diff;
	if (n >= m) {
		cout << 0 << endl;
		return;
	}
	for (int i = 0; i < m; ++i) cin >> x[i];
	sort(all(x));
	for (int i = 0; i < (m - 1); ++i) {
		diff.push_back(abs(x[i] - x[i + 1]));
	}
	sort(all(diff));
	int64 ans = 0;
	for (int i = 0; i < diff.size() - (n - 1); ++i) {
		ans += diff[i];
	}
	cout << ans << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
    int n,a,b;
    cin>>n>>a>>b;
    int ans=0;

    for(int i=1;i<=n;i++){
        int sum=0;
        int tmp=i;
        while(tmp){
            sum= sum + tmp%10;
            tmp=tmp/10;
        }
        if(a<=sum && sum<=b) ans+=i;
    }

    cout<<ans<<endl;
}

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

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


string a, b;
int main() {
	cin >> a;
	cin >> b;
	reverse(a.begin(), a.end());
	if(a == b) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	char c;
	cin>>c;
	cout<<(char)(c+1)<<endl;;
}


Measured memory_bytes: 256
/*
 * atcoder/abc130/a.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int N;
double X[10];
string U[10];

void input() {
  cin >> N;
  loop(n,0,N) cin >> X[n] >> U[n];
}

void solve() {
  double total = 0.0;
  loop(n,0,N) {
    if (U[n] == "BTC") {
      total += X[n] * 380000.0;
    } else {
      total += X[n];
    }
  }
  cout << total << endl;
}

int main() {
  // cout.precision(15);
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <climits>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int H, W, K;
vector<string> S;

vector<pair<int, int>> decodePattern(int pattern, int length) {
  vector<pair<int, int>> dec;
  int prev = 0;
  int count = 0;
  while (pattern) {
    if (pattern % 2) {
      dec.emplace_back(prev, count);
      prev = count + 1;
    }
    pattern /= 2;
    count++;
  }
  if (count != length) dec.emplace_back(prev, length - 1);
  return dec;
}

int greedyCheck(int pattern) {
  vector<pair<int, int>> decY = decodePattern(pattern, S.size());
  int ynum = decY.size();
  int cut = ynum - 1;
  vector<int> white(ynum, 0);
  vector<int> cur_white(ynum, 0);
  for (int x = 0; x < W; ++x) {
    bool need_cut = false;

    for (int y = 0; y < ynum; ++y) {
      int y1 = decY[y].first;
      int y2 = decY[y].second;
      cur_white[y] = 0;
      for (int i = y1; i <= y2; ++i) {
        cur_white[y] += (S[i][x] == '1') ? 1 : 0;
      }
      if (cur_white[y] > K)
        return INT_MAX;
      else if ((white[y] + cur_white[y]) > K)
        need_cut = true;
    }

    if (need_cut) cut++;
    for (int y = 0; y < ynum; ++y) {
      if (need_cut) {
        white[y] = cur_white[y];
      } else {
        white[y] += cur_white[y];
      }
    }
  }
  return cut;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin >> H >> W >> K;
  S.resize(H);
  rep(i, H) { cin >> S[i]; }
  int answer = INT_MAX;
  for (int pattern = 0; pattern < (1 << (H - 1)); ++pattern) {
    answer = min(answer, greedyCheck(pattern));
  }
  cout << answer << endl;
  return 0;
}


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

bool is_prime(int x){
  bool prime = true;
  for(int i = 2; i*i <= x; i++){
    if(x%i == 0) prime = false;
  }
  return prime;
}
  
int main(){
  int x; cin >> x;
  int ans;
  for(int i = x; i <= 2*x; i++){
    if(is_prime(i)){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
/*int main()
{
    char s[4];
    cin>>s;
    if((s[0]=='7')|| (s[1]=='7') || (s[2]=='7'))
    {
         cout<<"YES";
    }
    else{
         cout<<"NO";
    }*/
int main()
{
    char s[4];
    scanf("%s",s);
    if(s[0]=='7'||s[1]=='7'||s[2]=='7')
        puts("Yes");
    else
        puts("No");
  return 0;
}


Measured memory_bytes: 3764
#include<iostream>
using namespace std;
int main() {
    int h, r;
    cin >> h >> r;
    if(h >= r||-h<r)
        cout << 1 << endl;
    else if(-h > r)
        cout << -1 << endl;
    else if(-h == r)
        cout <<0<< endl;
}


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

using namespace std;

int n;

void solve(){
    int ans[5] = {0};
    for(int i = 0;i < 3;i++){
        int a,b;
        cin >> a >> b;
        ans[a]++;
        ans[b]++;
    }
    for(int i = 1;i < 5;i++){
        if(ans[i]%2==0){
            cout << "YES" << endl;
            return;
        }
    }
    cout << "NO" << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 256
while True:
    list_input = input().split()
    calculate = {'+': lambda a, b: a + b,
                 '-': lambda a, b: a - b,
                 '/': lambda a, b: a // b,
                 '*': lambda a, b: a * b,
                 }
    if list_input[1] == '?':
        break
    else:
        print(calculate[list_input[1]](int(list_input[0]), int(list_input[2])))



Measured memory_bytes: 5600
from itertools import product

n = int(input())
query = []
for i in range(n):
    query.append(list(map(int, input().split())))
query.sort(key=lambda x: x[2], reverse=True)

for cx, cy in product(range(101), range(101)):
    h_pred = query[0][2] + abs(cx-query[0][0]) + abs(cy-query[0][1])
    flag = True
    for x,y,h in query[1:]:
        if max(h_pred - abs(x-cx) - abs(y-cy), 0) != h:
            flag =False
            break
    if flag:
        print(cx, cy, h_pred)
        exit()

Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int x;
  cin >> x;
  if(x >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

const int MAX_N = 150;
int N, P[MAX_N];
std::string S[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N;

    for (int i = 1; i <= N; i++) {
        std::cin >> S[i] >> P[i];
    }

    std::vector<int> vec;
    for (int i = 1; i <= N; i++) {
        vec.push_back(i);
    }

    std::sort(vec.begin(), vec.end(),
        [&](const int i, const int j) {
            if (S[i] != S[j]) {
                return S[i] < S[j];
            }
            return P[i] > P[j];
        }
    );

    for (int i : vec) {
        std::cout << i << std::endl;
    }


    return 0;
}

Measured memory_bytes: 256
a=[list(map(int,input().split())) for i in range(3)]
n=int(input())

for i in range(n):
  b=int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k]==b:
        a[j][k]=-1

ans='No'
for i in a:
  if list(i)==[-1,-1,-1]:
    ans='Yes'
for i in zip(*a):
  if list(i)==[-1,-1,-1]:
    ans='Yes'
if a[0][0]+a[1][1]+a[2][2]==-3:
  ans='Yes'
if a[0][2]+a[1][1]+a[2][0]==-3:
  ans='Yes'


print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            // 整数の入力
            int N = int.Parse(Console.ReadLine());
            // スペース区切りの整数の入力
            //string[] input = Console.ReadLine().Split(' ');
            //int a = int.Parse(input[0]);
            //int b = int.Parse(input[1]);
            //int c = int.Parse(input[2]);
            string rtn = "ABC";
            if (N>=1000)
            {
                rtn = "ABD";
            }
            
            // 文字列の入力
            //string s = Console.ReadLine();
            //string aaa ="Odd";
            //if (a%2==0 ||b%2==0)
            //{
            //    aaa = "Even";
            //}
            //出力
            Console.WriteLine(rtn);
            //Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
s, (x, y) = raw_input().split('T'), map(int, raw_input().split())
cx, cy = len(s[0]), 0
for _ in sorted([len(_) for _ in s[2::2]])[::-1]:
    cx += _ if cx < x else -_
for _ in sorted([len(_) for _ in s[1::2]])[::-1]:
    cy += _ if cy < y else -_
print 'Yes' if (cx, cy) == (x, y) else 'No'


Measured memory_bytes: 2820
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
#include <limits>
#include <math.h>
#include <queue>
#include <tuple>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <memory>

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0033

using namespace std;

// #define TEST

#ifdef TEST
static const string g_SAMPLE = R"(2
3 1 4 2 5 6 7 8 9 10
10 9 8 7 6 5 4 3 2 11)";
static FILE* g_IN_FP;
static const char* g_IN_FN = "in.txt";
#define scanf(...) fscanf(g_IN_FP, __VA_ARGS__)
#endif // TEST

int main() {
#ifdef TEST
    g_IN_FP = fopen(g_IN_FN, "w");
    fwrite(g_SAMPLE.c_str(), 1, g_SAMPLE.size(), g_IN_FP);
    fclose(g_IN_FP);
    g_IN_FP = fopen(g_IN_FN, "r");
#endif // TEST
    int N;
    scanf("%d", &N);
    for (int n = 0; n < N; n++) {
        vector<int> balls;
        for (int i = 0; i < 10; i++) {
            int ball;
            scanf("%d", &ball);
            balls.push_back(ball);
        }
        bool foundGoodBits = false;
        for (int bits = 0; bits < (1 << 10); bits++) {
            if (bits > (~bits & ((1 << 10) - 1))) {
                continue;
            }
            function<bool(int)> isGoodBits = [&balls](int bits) -> bool {
                int zeroTop = 0;
                int oneTop = 0;
                for (int bit = 0; bit < 10; bit++) {
                    int* topPtr = (bits & (1 << bit)) != 0 ? &oneTop : &zeroTop;
                    if (balls[bit] <= *topPtr) {
                        return false;
                    } else {
                        *topPtr = balls[bit];
                    }
                }
                return true;
            };
            if (isGoodBits(bits)) {
                foundGoodBits = true;
                break;
            }
        }
        if (foundGoodBits) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    return 0;
}



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

int main(){
  ll x ;
  cin >> x ;
  ll start = 100 ;
  int count = 0  ;
  while( start < x ){
	 start *= 1.01 ;
     count++ ;
  }
  cout << count << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll X, K, D;
    cin >> X >> K >> D;
    ll q, l;
    X = abs(X);
    q = X / D;
    l = X % D;
    if( K >= q ){
        if( (K-q) % 2 == 0 ){
            printf("%lld\n", l);
        }
        else{
            printf("%lld\n", D - l);
        }
    }
    else{
        printf("%lld\n", X - K * D);
    }
}

Measured memory_bytes: 3760
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 1000010
#define LL long long
char a[N];
int b[N],t1[N],t2[N];
LL s1[N],s2[N];
int main()
{
    int i,j,k,n,m;
    int x,y,z,d;
    LL s,ans;
    scanf("%d%s",&n,a+1);
    s1[0]=0;
    s2[0]=0;
    t1[0]=0;
    t2[0]=0;
    k=0;
    for(i=1;i<=n;i++)
    {
        s1[i]=s1[i-1];
        s2[i]=s2[i-1];
        t1[i]=t1[i-1];
        t2[i]=t2[i-1];
        if(a[i]=='M')
        {
            t1[i]++;
            s1[i]++;
        }
        else
        if(a[i]=='D')
            b[k++]=i;
        else
        if(a[i]=='C')
        {
            t2[i]++;
            s2[i]=s2[i]+s1[i];
        }
    }
    scanf("%d",&m);
    while(m--)
    {
        scanf("%d",&d);
        ans=0;
        for(i=0;i<k;i++)
        {
            j=min(b[i]+d-1,n);
            s=max((LL)0,s2[j]-s2[b[i]]-((LL)t1[b[i]]*(t2[j]-t2[b[i]])));
            ans=ans+s;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 28544
#include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
	int i = 0, maxV = INT_MIN, A[30] = {};
	for (int k; cin >> k; ) {
		A[i++] = k;
		if (maxV < k)
			maxV = k;
	}
	int s = maxV + 1;
	vector<long> vP(s, 0);
	int c = 0, j;
	for (int k = 2; k < s; ++k){
		if (vP[k] == 0){
			vP[k] = ++c;
			for (j = 2; j * k < s; ++j)
				vP[j * k] = -1;
		}
		else if (vP[k] == -1)
			vP[k] = c;		
	}
	for (j = 0; j < i; ++j)
		cout << vP[A[j]] << "\n";
	return 0;
}

Measured memory_bytes: 8984
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()

def prime_factorization(n):
    assert(n>1)
    factor=[]
    sqrt=int(n**.5)
    for d in range(2,sqrt+1):
        while(n%d==0):
            n//=d
            factor.append(d)
    if n!=1: factor.append(n)
    return factor

from collections import defaultdict

def resolve():
    n=int(input())
    C=defaultdict(int)
    for x in range(2,n+1):
        for p in prime_factorization(x):
            C[p]+=1
    ans=1
    for v in C.values():
        ans*=v+1
        ans%=MOD
    print(ans)
resolve()

Measured memory_bytes: 42588
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    String ans = "NO";
    if(a.charAt(a.length() - 1) == b.charAt(0) && b.charAt(b.length() - 1) == c.charAt(0)) ans = "YES";
    System.out.println(ans);
  }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(v) (v).begin(),(v).end()

int main() {

	int N;
	cin >> N;
	string S;
	cin >> S;

	char now = S[0];
	int ans = 1;
	for(int i=1; i<N; i++) {
		if(S[i] != now) {
			ans++;
			now = S[i];
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
#define vec2(a,y,x) vector<vector<int>> a(y,vector<int>(x))
#define vec1(a,n) vector<int> a(n);rep(i,n)cin>>a[i]

int main(){
string x;
  cin>>x;
  int y =x.size();
  rep(i,y)cout<<"x";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

int main(void)
{
    int n, a[3];
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        bool flag = false;
        scanf("%d %d %d", &a[0], &a[1], &a[2]);
        for (int j = 0; j < 3; ++j) {
            if (a[j] * a[j] == a[(j + 1) % 3] * a[(j + 1) % 3] + a[(j + 2) % 3] * a[(j + 2) % 3]) {
                flag = true;
            }
        }
        if (flag) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1008
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

typedef long long ll;

int n;
vector<int> a, b1, b2, ans;

inline int Solve() {
  for (int i = 0; i < b1.front(); ++i)
    ans.push_back(1);
  for (int i = n - 1; i > b1.back(); --i)
    ans.push_back(i - b1.front() + 1);
  for (int i = 1; i <= b1.size() - 1; ++i) {
    int range = (b1[i] - b1[i - 1]) >> 1;
    for (int j = range; j > 0; --j)
      ans.push_back(j + 1);
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  int max_pos = max_element(a.begin(), a.end()) - a.begin();
  ll sum;
  if (a[max_pos] <= 0) {
    b1.push_back(max_pos);
    sum = a[max_pos];
  } else {
    ll sum1 = 0, sum2 = 0;
    for (int i = 0; i < n; i += 2) {
      if (a[i] > 0) {
        b1.push_back(i);
        sum1 += a[i];
      }
    }
    for (int i = 1; i < n; i += 2) {
      if (a[i] > 0) {
        b2.push_back(i);
        sum2 += a[i];
      }
    }
    if (sum2 > sum1) {
      swap(b2, b1);
      sum = sum2;
    } else sum = sum1;
  }
  Solve();
  cout << sum << "\n" << ans.size() << "\n";
  for (int x : ans)
    cout << x << "\n";
  cout << flush;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n, k = map(int, input().split())
a = list(map(int, input().split()))

def f(x):
    cnt = 0
    for i in a:
        cnt += (i-1) // x
        if cnt > k:
            return False
    return True
            
ok = 10**9
ng = 0
while ok - ng > 1:
    mid = (ok + ng) // 2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok)

Measured memory_bytes: 104292
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

int main() {
    string s,t; cin >> s >> t;
    int n = s.size();
    int ans = 0;
    rep(i,n){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
}




Measured memory_bytes: 3912
#!/usr/bin/env python3

import sys

DEBUG = False

def solve():
    return


def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().rstrip().split(sep)]

def read_int():
    return int(sys.stdin.readline())

def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return


def main():
    n, blue, red = read_int_list()
    ans = 0
    nr_cycle = n // (blue + red)
    ans += nr_cycle * blue
    n = n % (blue + red)
    if blue < n:
        ans += blue
    else:
        ans += n
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int s1=0,s2=0,s3=0,s4=0;
	s1++;
	if(s[1]==s[0])
	{
		s1++;
		if(s[2]!=s[1]&&s[2]==s[3])
		{
			cout<<"Yes";
		}
		else
		{
			cout<<"No";
		}
	}
	else
	{
		if((s[2]==s[1]&&s[3]==s[0])||(s[2]==s[0]&&s[3]==s[1]))
		{
			cout<<"Yes";
		}
		else
		{
			cout<<"No";
		}
	}
    return 0;
} 	

Measured memory_bytes: 256