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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)-form-)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };


inline int ri() { int in; int y = scanf("%d", &in); return in; }
inline LL rl() { LL in; int y = scanf("%lld", &in); return in; }
inline void oi(int i) { printf("%d\n", i); }
inline void od(double i) { printf("%.9f\n", i); }


int main() {
	int N = ri();
	vector<LL> a(N);
	set<PLL>se;
	for (int i = 0; i < N; ++i) {
		a[i] = rl();
		se.insert(PLL(a[i], i));
	}
	VL sub(N, 1);
	auto NG = []() {
		cout << -1 << endl;
		exit(0);
	};
	vector<vector<int>>G(N);
	while (SZ(se) > 1) {
		auto it = se.end();
		--it;
		PLL a = *it;
		se.erase(it);
		LL sa = a.first;
		int v = a.second;
		DD(de(sa, v));
		LL parval = sa + 2 * sub[v] - N;
		auto parnode = se.lower_bound(PLL(parval, 0));
		if (parnode->first != parval)NG();
		int par = parnode->second;
		sub[par] += sub[v];
		G[par].push_back(v);
	}

	function<LL(int)> f = [&](int v) {
		LL ret = 0;
		for (auto nx : G[v]) {
			ret += f(nx) + sub[nx];
		}
		return ret;
	};
	LL res = f(se.begin()->second);
	if (res != se.begin()->first)NG();
	FOR(i, 0, N) {
		for (auto nx : G[i]) {
			printf("%d %d\n", i + 1, nx + 1);
		}
	}

}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int K, A, B;
  cin >> K >> A >> B;

  ll ans = K + 1;

  if (A < B) {
    if (A - 1 + 2 <= K) {
      K -= A - 1;
      ans = max(ans, (ll)(B - A) * (K / 2) + (K % 2) + A);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
n, k = (input().split())
n = list(map(int, n));
dSet = set(map(int, input().split()))
okList = [i for i in range(10) if i not in dSet]
i = len(n)
while i >= 0:
    i -= 1
    if n[i] in okList:
        continue
    for y in okList:
        if n[i] < y:
            n[i] = y
            j = i+1
            while j < len(n):
                n[j] = okList[0]
                j += 1

            break
    else:
        if i - 1 < 0:
            n = [0] + n
            i += 1
        n[i - 1] += 1
        j = i
        while j < len(n):
            n[j] = okList[0]
            j += 1
print(int("".join(list(map(str, n)))))


Measured memory_bytes: 9244
#include <bits/stdc++.h>
typedef long long int ll;
#define vaibhavv06               \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(0);
#define int long long
#define MM(a,b) memset(a,b,sizeof(a))
const ll MOD = 1000000007;
using namespace std;



int32_t main(){
    vaibhavv06;
	int n; cin>>n;
	string s; cin>>s;
	int sum=0;
	for(int i=0;i+2<n;i++){
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') sum++;
	}
	cout<<sum<<endl;
}

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 FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
using namespace std;
typedef long long ll;
const ll INF = 1e15;
int main() {
  ll h, w;
  cin >> h >> w;
  vector<vector<ll>> c(10, vector<ll>(10, INF));
  REP(i, 10) REP(j, 10) { cin >> c[i][j]; }

  REP(k, 10) REP(i, 10) REP(j, 10) {
    c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
  }

  ll ans = 0;
  REP(i, h) REP(j, w) {
    ll a;
    cin >> a;
    if (a == -1) continue;
    ans += c[a][1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

template<typename T> void cinpb(vector<T>& x) { T n; cin >> n; x.push_back(n); }
ull gcd(ull a, ull b) { return b ? gcd(b, a%b) : a; }
ull lcm(ull m, ull n) {	return ((0 == m) || (0 == n)) ? 0 : ((m / gcd(m, n)) * n); }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


//

int main()
{
	int n, x;
	vector<int> x_list;

	cin >> n >> x;

	rep(i, n)
	{
		int xn;
		cin >> xn;
		x_list.pb(xn);
	}
	
	x_list.pb(x);

	sort(x_list.begin(), x_list.end());

	int ans = 1000000001;

	int prev = x_list[0];
	for (int i = 1; i < x_list.size(); i++)
	{
		int diff = abs(prev - x_list[i]);

		if ( ans == 1000000001 )
		{
			ans = diff;
		}
		else
		{
			ans = gcd(ans, diff);
		}

		prev = x_list[i];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 892
S = input()
flg = True
for i, s in enumerate(S):
    if (i+1)%2==1 and s=='L':
        flg = False
        break
    elif (i+1)%2==0 and s=='R':
        flg = False
        break
if flg:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x % i == 0)return false;
	}
	return true;
}

int a, b, q, s[100010], t[100010];
int ans = inf;

signed main() {
	cin >> a >> b >> q;
	rep(i, a)cin >> s[i];
	rep(i, b)cin >> t[i];
	sort(s, s + a);
	sort(t, t + b);
	int x;
	rep(i, q) {
		cin >> x;
		int c, d, e, f;
		e = min(s[a - 1], *lower_bound(s, s + a, x));
		f = min(t[b - 1], *lower_bound(t, t + b, x));
		c = max(s[0], *(lower_bound(s, s + a, x) - 1));
		d = max(t[0], *(lower_bound(t, t + b, x) - 1));
		if (c <= x && d <= x)ans = min(ans, x - min(c, d));
		if (e >= x && f >= x)ans = min(ans, max(e, f) - x);
		if (c <= x && f >= x)ans = min(ans, x - c + f - x + min(x - c, f - x));
		if (d <= x && e >= x)ans = min(ans, x - d + e - x + min(x - d, e - x));
		cout << ans << endl;
		ans = inf;
	}
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
int n,m,q,l,r,c[501][501];
int main() {
	cin>>n>>m>>q;
	for(int i=0; i<m; ++i) {
		cin>>l>>r;
		for(int j=r; j<501; ++j) c[l][j]++;
	}
	for(int i=0; i<q; ++i) {
		int ans=0;
		cin>>l>>r;
		for(int j=l; j<=r; ++j) ans+=c[j][r];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1920
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
const ll nmax = 1e9 + 7;
const ll MOD = 998244353;
const double PI = 2 * asin(1);

int main(){
  int N, A, sum = 0; cin >> N >> A;
  vector <int> X(N);
  for (int i = 0; i < N; i++){
    cin >> X[i]; sum += X[i];
  }

  ll DP[N + 1][N + 1][sum+ 1];

  for (int i = 0; i < N + 1; i++){
    for (int j = 0; j < N + 1; j++){
      for (int k = 0; k < sum + 1; k++){
        DP[i][j][k] = 0;
      }
    }
  }
  DP[0][0][0] = 1;
  
  for (int i = 1; i < N + 1; i++){
    for (int j = 0; j < N + 1; j++){
      for (int k = 0; k < sum + 1; k++){
        if (k - X[i - 1] >= 0){
          DP[i][j][k] += DP[i - 1][j - 1][k - X[i - 1]];
        }
        DP[i][j][k] += DP[i - 1][j][k];
      }      
    }
  }

  ll ans = 0;
  for (int i = 1; i < N + 1 && i * A <= sum; i++){
    ans += DP[N][i][i * A];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 51072
#include <iostream>
#include <iomanip>
#include <queue>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <bitset>

#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x, y) memset(x, y, sizeof(x))
#define pb push_back
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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

using namespace std;
using ll = long long;

const int kInf = 1e9;
const ll kLInf = 1e18;

int gcd (int a, int b) {
   return b ? gcd(b, a % b) : a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N;
double dp[305][305][305];

double REC(int i, int j, int k)
{
   if (dp[i][j][k] >= 0) return dp[i][j][k];
   double val = 0;
   if (!i && !j && !k) return dp[i][j][k] = 0;
   if (i) val += REC(i-1, j, k) * i;
   if (j) val += REC(i+1, j-1, k) * j;
   if (k) val += REC(i, j+1, k-1) * k;
   val += N;
   val /= i+j+k;
   return dp[i][j][k] = val;
}

int main()
{
   cout << fixed << setprecision(10);
   cin >> N;
   REP(i, N+2) REP(j, N+2) REP(k, N+2) dp[i][j][k] = -1;
   int one=0, two=0, three=0;
   int val;
   REP(i, N) {
      cin >> val;
      if (val==1) one++;
      else if (val==2) two++;
      else three++;
   }
   cout << REC(one, two, three) << endl;
   return 0;
}


Measured memory_bytes: 221440
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
			System.out.printf("%d %d\n",a*b,2*(a+b));
			
			sc.close();
		}
	}



Measured memory_bytes: 26228
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = INT32_MAX;
const long long int Mod = 1000000007;
using ll = long long int; //long long int は64bit
using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using pii = pair<int,int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
#define np nullptr
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
//       cin.tie(0);ios::sync_with_stdio(false);
void cinit(){cin.tie(0);ios::sync_with_stdio(false);}
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////

const int MAX = 210000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % Mod;
        inv[i] = Mod - inv[Mod%i] * (Mod/i) % Mod;
        finv[i] = finv[i-1] * inv[i] % Mod;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod;
}

vector<pair<ll,ll> > prime_fact(ll n){
	vector<pair<ll,ll> > ans;
	for(ll i=2;i*i<=n;i++){
		if(n%i!=0)continue;
		ll num = 0;
		while(n%i==0){num++;n/=i;}
		ans.pb(mp(i,num));
	}
	if(n!=1)ans.pb(mp(n,1));
	return ans;
}

int main(){
	int n,m;
	cin>>n>>m;
	vector<pair<ll,ll>> v = prime_fact(m);
	COMinit();
	ll ans = 1;
	for(auto vv : v){
		ans = (ans*COM((int)vv.second+n-1,n-1))%Mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5120
/*Author Sanjay shukla 
verdict Ac
*/
#include<iostream>
#include<string.h>
#define endl ("\n")
#define pi (3.141592653589)

// #define int long long
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) cc.begin(), c.end()
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr);
using namespace std;
// long long moduloMultiplication(long long a, 
//                             long long b, 
//                             long long mod) 
// { 
//     long long res = 0; // Initialize result 
  
//     // Update a if it is more than 
//     // or equal to mod 
//     a %= mod; 
  
//     while (b) 
//     { 
//         // If b is odd, add a with result 
//         if (b & 1) 
//             res = (res + a) % mod; 
  
//         // Here we assume that doing 2*a 
//         // doesn't cause overflow 
//         a = (2 * a) % mod; 
  
//         b >>= 1; // b = b / 2 
//     } 
  
//     return res; 
// } 


int32_t main(){
    fast
    char s;
    cin>>s;
    int s1= s;
    cout<<(char)++s1<<endl;
    return 0;
}



Measured memory_bytes: 3556
#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 FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

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

  int cnt = 0;
  REP(i,1000){
    string s;
    if(i==0){
      s="000";
    }else if(i<10){
      s="00"+to_string(i);
    }else if(i<100){
      s="0"+to_string(i);
    }else{
      s=to_string(i);
    }

    int x = 0;
    int flag=0;
    REP(j,S.size()){
      if(S.at(j)==s.at(x)){
        x++;
      }
      if(x==3){
        flag=1;
        break;
      }
    }

    if(flag==1){
      cnt++;
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
k = n//2
d = dict()
d[(-2,0)] = 0
for i in range(n):
    nxt = dict()
    discard = []
    for (prev, cnt), score in d.items():
        if i-prev == 1:
            continue
        if cnt == k:
            continue
        nprev = i
        ncnt = cnt+1
        nscore = score+a[i]
        tmp = (nprev, ncnt)
        if tmp not in nxt or nxt[tmp] < nscore:
            nxt[tmp] = nscore
        r = n-1-i
        if cnt + (r+1)//2 < k:
            discard.append((prev, cnt))
    for key, value in nxt.items():
        d[key] = value
    for key in discard:
        d.pop(key)
ans = -float("inf")
for key, value in d.items():
    if key[1] == k:
        ans = max(ans, value)
print(ans)


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

int main(){
 ll a,b,n; cin >> a >> b >> n;
 ll p;
 if(n<b)p=n;
 else{
   ll d=n/b; p=d*b-1;
 }
 ll flr1=(a*p)/b; ll flr2=p/b;
 ll ans=flr1-a*flr2;
 cout << ans << endl;
}


Measured memory_bytes: 3628
import sys 
import math
#sys.stdin = open('input.txt', 'r')
#sys.stdout = open('output.txt', 'w')
a, b, h, m = map(int,input().split())
rad = math.pi*2*((h/12.0) + (m/60.0)/12.0 - (m/60.0))
ans = math.sqrt(a*a + b*b - (2*a*b*math.cos(rad)))
print(ans)

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

int main(){
    long long w, h, x, y;
    cin >> w >> h >> x >> y;
    if (x * 2 == w && y * 2 == h){
        cout << setprecision(15) << (double)1.0 * w * h / 2 << " " << 1 << endl;
    }
    else cout << setprecision(15) << (double)1.0 * w * h / 2 << " " << 0 << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

//Long Distance Taxi
public class Main{

	class E{
		int t, c;
		public E(int t, int c) {
			this.t = t;
			this.c = c;
		}
	}
	
	Map<String, Integer> ref;
	int ID, INF = 1<<29, M = 2001;
	int reg(String s){
		if(ref.containsKey(s))return ref.get(s);
		ref.put(s, ID);
		return ID++;
	}

	Set<E>[] adj;
	int[] d;
	boolean[] gas;
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		d = new int[6000*2001];
		adj = new Set[6000];
		gas = new boolean[6000];
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt(), cap = sc.nextInt();
			if((n|m|cap)==0)break;
			ref = new HashMap<String, Integer>();
			ID = 0;
			int S = reg(sc.next()), T = reg(sc.next());
			for(int i=0;i<6000;i++)adj[i]=new HashSet<E>();
			while(n--!=0){
				int s = reg(sc.next()), t = reg(sc.next()), D = sc.nextInt();
				adj[s].add(new E(t, D)); adj[t].add(new E(s, D));
			}
			Arrays.fill(gas, false);
			while(m--!=0)gas[reg(sc.next())]=true;
			for(int i=0;i<ID;i++)for(int j=0;j<=10*cap;j++)d[i*M+j]=INF;
			PriorityQueue<Integer> q = new PriorityQueue<Integer>(ID, new Comparator<Integer>() {
				public int compare(Integer o1, Integer o2) {
					return d[o1]-d[o2];
				}
			});
			d[S*M+10*cap] = 0;
			q.add(S*M+10*cap);
			int res = -1;
			while(!q.isEmpty()){
				int v = q.poll();
				int p = v/M, c = v%M;
				if(p==T){
					res = d[v]; break;
				}
				for(E e:adj[p]){
					if(c-e.c<0)continue;
					int w = d[v]+e.c;
					if(gas[e.t]){
						if(w < d[e.t*M+10*cap]){
							d[e.t*M+10*cap] = w; q.add(e.t*M+10*cap);
						}
					}
					else{
						if(w < d[e.t*M+c-e.c]){
							d[e.t*M+c-e.c] = w; q.add(e.t*M+c-e.c);
						}
					}
				}
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
int main(void){

  int N,i;
  int *data;

  scanf("%d",&N);

  data = (int*)malloc(sizeof(int)*N);
  for(i=0;i<N;i++){
    scanf("%d",&data[i]);
  }
  int j = 0;
  for(i=0;i<N;i++){
    if(data[i]%2 == 0 && data[i]%3 != 0 && data[i]%5 != 0){
      j += 1;
    }
  }
  if(j == 0){
    printf("APPROVED");
  }
  else printf("DENIED");

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

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

  long long sum = accumulate(t.begin(), t.end(), 0);

  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    long long ans = sum;
    int p, x;
    cin >> p >> x;
    ans = ans - t[p-1] + x;
    cout << ans << endl;
  }
  return 0;
}


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

vector<vector<int>> graph;
vector<int> dive, ascend;// subtree_size info

int k = 0;
void DFS(int v, int parent_v = -1){
    dive[v] = k;
    k += 1;

    for(int child_v : graph[v]){
        if(child_v == parent_v) continue;
        DFS(child_v, v);
    }
    ascend[v] = k;
}

bool compare(int a, int b){
    return dive[a] > dive[b];
}

vector<int> data_bit;
struct BIT{
    void init(int n){
        data_bit.assign(n+1, 0);// 1-indexed [1,n]
    }

    void add(int i, int x){
        while(i < data_bit.size()){
            data_bit[i] += x;
            i += (i & -i);
        }
    }

    int sum(int i){
        int s = 0;
        while(i > 0){
            s += data_bit[i];
            i -= (i & -i);
        }
        return s;
    }
};

int main(){
    long long int n;
    cin >> n;

    graph.resize(n);
    dive.resize(n);
    ascend.resize(n);

    vector<vector<int>> color(n);
    for(int i=0; i<n; i++){
        int c;
        cin >> c;
        c -= 1;
        color[c].push_back(i);
    }

    for(int i=0; i<n-1; i++){
        int a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    DFS(0);
    //for(int i=0; i<n; i++) cout << dive[i] << " ";
    //cout << endl;
    //for(int i=0; i<n; i++) cout << ascend[i] << " ";
    //cout << endl;

    BIT bit; 
    bit.init(n);
    for(int i=0; i<n; i++){
        bit.add(i+1, 1);
    }

    for(int i=0; i<n; i++){
        long long int ans = n * (n-1) / 2 + n;

        sort(color[i].begin(), color[i].end(), compare);// deeper nodes first
        vector<pair<int, int>> rec;

        for(int v : color[i]){
            int count = 1;// subtraction in BIT

            for(int child_v : graph[v]){
                if(dive[child_v] < dive[v]) continue;

                long long int subtree_size = bit.sum(ascend[child_v]) - bit.sum(dive[child_v]);
                ans   -= subtree_size * (subtree_size - 1) / 2 + subtree_size;
                count += subtree_size;
            }

            bit.add(dive[v]+1, -count);
            rec.push_back({dive[v]+1, count});
        }
        long long int subtree_size = bit.sum(n);
        ans -= subtree_size * (subtree_size - 1) / 2 + subtree_size;
        cout << ans << endl;

        for(auto r : rec) bit.add(r.first, r.second);// avoid TLE due to "for(int i=0; i<n; i++) bit.add(i,1)" everytime
    }
    return 0;
}

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

typedef long long ll;

int main(void)
{
    //freopen("input.txt", "r", stdin);

    ll k;
    string s;
    cin>>k>>s;
    if(s.size() > k)
    {
        for(int i = 0; i < k; i++)
        {
            cout<<s[i];
        }
        cout<<"...\n";
    }
    else
        cout<<s<<"\n";

    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include<string>
#include<vector>
using namespace std;

int main() {
    int N,L;
    string s;
    vector<string> sList;
    string ans;
    cin>>N>>L;
    for(int i=0;i<N;++i){
        cin>>s;
        sList.push_back(s);
    };
    sort(sList.begin(),sList.end());
    reverse(sList.begin(),sList.end());
    for(int i=0;i<N;++i){
        ans+=sList.back();
        sList.pop_back();
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
main = do
  s <- getContents
  let l = takeWhile (\[x,y,z]->not (x== -1 && y== -1 && z== -1) )  $ (map (map (read::String->Int) . words) . lines) $ s
  mapM putStrLn $ map rst l

rst :: [Int] -> String
rst [m,f,r]
  | m == -1 || f == -1   = "F"
  | m + f >= 80          = "A"
  | m + f >= 65          = "B"
  | m + f >= 50          = "C"
  | m + f >= 30 && r>=50 = "C"
  | m + f >= 30          = "D"
  | otherwise            = "F"

Measured memory_bytes: 4108
all_cards=[]
for i in range(1,52+1):
    if i<=13:
        all_cards.append('S {}'.format(i))
    elif i <=26:
        all_cards.append('H {}'.format(i-13))
    elif i <=39:
        all_cards.append('C {}'.format(i-26))
    else:
        all_cards.append('D {}'.format(i - 39))


my_cards_sum=int(input())


for i in range(0,my_cards_sum):
    del_cards=input()
    if del_cards in all_cards:
        all_cards.remove(del_cards)

[print(i) for i in all_cards]


Measured memory_bytes: 5600
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <set>
#include <map>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long ll;


typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

vector<int> G[100005];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
std::vector<P> tree[100010];
struct edge{int to,cost;};


int main(){
	ll i,j,k;
	ll a,b,c;
	ll h,w,n;
	cin>>h>>w>>n;
	map<pair<ll,ll>,ll> cnt;
	for(i=0;i<n;i++){
		cin>>a>>b;
		for(j=-1;j<=1;j++){
			for(k=-1;k<=1;k++){
				if(a+j>=2 && a+j<=h-1 && b+k>=2 && b+k<=w-1){
					cnt[make_pair(a+j,b+k)]++;
				}
			}
		}
	}
	ll ans[10];
	fill(ans,ans+10,0ll);
	ans[0]=(h-2)*(w-2);
	for(auto x=cnt.begin();x!=cnt.end() ; x++){
		ans[0]--;
		ans[x->second]++;
	}
	for(i=0;i<=9;i++){
		cout<<ans[i]<<endl;
	}
	return 0;
}

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

int main() {
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++)
    cin>>arr[i];
    int dp[n];
    dp[0]=0;
    dp[1]=abs(arr[0]-arr[1]);
    for(int i=2;i<n;i++)
    {   dp[i]=INT_MAX;
        for(int j=1;j<=k&&i-j>=0;j++)
        {   
            dp[i]=min(dp[i],dp[i-j]+abs(arr[i-j]-arr[i]));
        }
        //cout<<dp[i]<<endl;
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define mp make_pair
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;
const int N=3e3+5;
int dp[N][N],n;
int pre[N][N];
string s;

int Calc(int x,int l,int r);
int find(int x,int y);
int find2(int x,int y);

int32_t main(){
    IOS;
    cin>>n;
    cin>>s;
    memset(dp,-1,sizeof(dp));
    memset(pre,-1,sizeof(dp));
    int ans=0;
    for(int i=1;i<=n;i++){
        ans=(ans+find(n,i))%M;
    }
    cout<<ans<<endl;
}

int Calc(int x,int l,int r){
    return((find2(x,r)-find2(x,l-1)+M)%M);
}

int find(int x,int y){
    if(y<1||y>x) return(0);
    if(dp[x][y]!=-1) return(dp[x][y]);
    if(x==1) return(dp[x][y]=1);
    int res=0;
    char c=s[x-2];
    if(c=='<'){
        res=(res+Calc(x-1,(int)1,y-1))%M;
    }
    else{
        res=(res+Calc(x-1,y,x-1))%M;
    }
    return(dp[x][y]=res);
}

int find2(int x,int y){
    if(y==0){return(0);}
    if(pre[x][y]!=-1){return(pre[x][y]);}
    return(pre[x][y]=(find(x,y)+find2(x,y-1))%M);
}


Measured memory_bytes: 141696
#include<bits/stdc++.h>
using namespace std;
int32_t main()
{
  long long a,b;cin>>a>>b;
  if(a%b==0)cout<<0;
  else if(a<b)cout<<min(b-a,a);
  else cout<<min(abs(b-(a%b)),a%b);
 
           return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
template <typename T>
T pow(T a, ll n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
 
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
 
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
 
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};
 
using mint = ModInt<1000000007>;
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, x, t; cin >> n >> x >> t;
    int ans = (n + x - 1) / x * t;
    cout << ans << endl;
}

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

namespace ABC120 {
	class ABC120_B {
		static void Main(string[] args) {
			var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			var A = input[0];
			var B = input[1];
			var K = input[2];

			var loop = A > B ? B : A;
			var div = new List<int>();
			for (int i = 1; i <= loop; i++) {
				if (A % i != 0) {
					continue;
				}
				if (B % i != 0) {
					continue;
				}
				div.Add(i);
			}
			div.Reverse();
			Console.WriteLine(div.Take(K).Last());
		}
	}
}


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

int main(){
    int x, y, a;
    for(int i = 0;i < 3000;i++){
        cin >> x >> y;
        if(y < x){
            a = x;
            x = y;
            y = a;
        }
        if(x == 0 && y == 0){
            break;
        }
        cout << x << " " << y << endl;
    }
    return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i = n;i >= 0;--i)
#define FOR(i,m,n) for(int i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void)
{
    ll mod = 1e9+7;
    ll sum = 0;
    int n;
    cin >> n;
    vector<ll> a(n);
    REP(i,n){
        cin >> a[i];
    }

    ll a_max = *max_element(all(a));
    int e_max = log2(a_max);

    unsigned long long int pow2 = 1;
    REP(i,e_max+1){
        ll one_cnt = 0;
        ll zero_cnt = 0;

        REP(j,n){
            if(pow2 & a[j]){
                one_cnt++;
            }
            else{
                zero_cnt++;
            }
        }

        sum += (pow2%mod*one_cnt%mod*zero_cnt%mod)%mod;
        pow2<<=1;
    }

    cout << sum % mod << endl;

    return 0;
}

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

int main() {
  unsigned long long N, x;
  std::cin >> N >> x;
  std::vector<unsigned long long> a(N);
  for (unsigned i = 0; i < N; ++i) { std::cin >> a[i]; }
  unsigned long long ans = 0ull;
  for (unsigned i = 1; i < N; ++i) {
    if (a[i - 1] + a[i] > x) {
      if (a[i - 1] < x) {
        ans += a[i] + a[i - 1] - x;
        a[i] -= a[i] + a[i - 1] - x;
      } else {
        ans += a[i];
        a[i] = 0;
        ans += a[i - 1] - x;
      }
    }
  }
  std::cout << ans;
  return 0;
}



Measured memory_bytes: 1024
//Volume5-0523
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

class Main {

	private static ArrayList<Integer> taro   = new ArrayList<Integer>(),
                                      hanako = new ArrayList<Integer>();

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		while(true){
			int       n      = sc.nextInt();
			if(n==0){break;}
			int       l      = n * 2 + 1;
			boolean[] flg    = new boolean[l];
			Arrays.fill(flg, true);

			taro.clear(); hanako.clear();

			int t;
			for(int i=0;i<n;i++){
				t = sc.nextInt();
				taro.add(t);
				flg[t] = false;
			}
			for(int i=1;i<l;i++){
				if(flg[i]){
					hanako.add(i);
				}
			}
			Collections.sort(taro);
			int board = taro.remove(0);
			ArrayList<Integer> turn = hanako;
			boolean find = false;
			while(true){
				find = false;
				for(int i=0;i<turn.size();i++){
					if(board<turn.get(i)){
						board=turn.remove(i);
						find = true;
						break;
					}
				}
				if(!find)         {board = 0    ;}
				if(turn.size()==0){break        ;}
				if(turn==hanako)  {turn = taro  ;}
				else              {turn = hanako;}
			}
			System.out.printf("%d\n%d\n",hanako.size(),taro.size());
		}
	}
}

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

using namespace std;
string s;
int main(){
    cin >> s;
    sort(s.begin(), s.end());
    
    if(s[0] == s[1] && s[1] == s[2] && s[2] == s[3]){
        cout << "No";
    }else if(s[0] == s[1] && s[2] == s[3]){
        cout << "Yes";
    }else{
        cout << "No";
    }
}


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

#define MAX 200

int sp = MAX;
int stack[MAX];

static void push(int a) {
	if (sp > 0) {
		stack[--sp] = a;
	} else {
		fprintf(stderr, "push error\n");
	}
}

static int pop() {
	if (sp < MAX) {
		return stack[sp++];
	} else {
		return 0;
	}
}


int main() {
	char s[MAX];
	int x = 0, y = 0;

	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			push(pop() + pop());
		} else if (s[0] == '-') {
			y = pop();
			x = pop();
			push(x - y);
		} else if (s[0] == '*') {
			push(pop() * pop());
		} else {
			push(atoi(s));
		}
	}

	printf("%d\n", pop());

	return 0;
}

Measured memory_bytes: 548
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

sum=0
for i in range(N):
    if B[i]<=A[i]:
        sum+=B[i]
    else:
        sum+=A[i]
        B[i]-=A[i]
        sum+=min(A[i+1],B[i])
        A[i+1]-=min(B[i],A[i+1])
print(sum)

Measured memory_bytes: 19116
A,B,C,D,E,F = list(map(int,input().split()))
A = 100*A
B = 100*B

a = int(F/A)
b = int(F/B)

hoge = 0

water = [[0 for i in range(a+1)]for i in range(b+1)]
sugar = [[0 for i in range(a+1)]for i in range(b+1)]

noudo = [[0 for i in range(a+1)]for i in range(b+1)]

for i in range(a+1):
    for j in range(b+1):
        if A*i+B*j < F:
            water[j][i] = A*i+B*j
       


        c = int(E*water[j][i]/(100*C))
        d = int(E*water[j][i]/(100*D))
        for k in range(c+1):
            for m in range(d+1):
                if C*k+D*m <= F-water[j][i]  and C*k+D*m <= E*water[j][i]/100:
                    sugar[j][i] = max(sugar[j][i],C*k+D*m)

for i in range(a+1):
    for j in range(b+1):
        if water[j][i] != 0 and sugar[j][i] != 0:
            noudo[j][i] = sugar[j][i]/(water[j][i]+sugar[j][i])
        if hoge <= noudo[j][i]:
            res_i = i
            res_j = j
            hoge = noudo[j][i]

print(water[res_j][res_i]+sugar[res_j][res_i],sugar[res_j][res_i])



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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//----------------------------------------------------------------

int main(void) {
  int x;
  cin >> x;
  if(x>=30){
    prt("Yes");
  } else {
    prt("No");
  }
}


Measured memory_bytes: 3592
public class Main {

  private static void solve() {
    char[] s = ns();
    int n = s.length;

    long ret = (long) n * (n - 1) / 2 + 1;

    long[] cnt = new long[26];
    for (int i = 0; i < n; i++) {
      int d = s[i] - 'a';
      ret -= cnt[d];
      cnt[d]++;
    }

    System.out.println(ret);

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 25300
h,w=map(int,input().split())
l=[["#"]*(w+2)]
for i in range(h):
    l.append(list(str(input())))
    l[i+1].append("#")
    l[i+1].insert(0,"#")
l.append(["#"]*(w+2))
for k in range(len(l)):
    print("".join(l[k]))


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;

int main()
{

	double ans;
	int n;
	cin >> n;
	if(n==1){
		ans = 1;
	}
	if (n % 2 == 0) {
		ans = (double)(n / 2) / n;
	}
	else {
		ans= (double)((int)(n / 2)+1) / n;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <climits>

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

using namespace std;

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

int w, h;
int white, black;
int tmp_count;
char tmp_color;
char a[55][55];

void dfs(int y, int x){
	if(y<0 || h<=y || x<0 || w<=x) return;
	if(a[y][x] == '*') return;
	if(a[y][x] == 'W' || a[y][x] == 'B'){
		if(tmp_color == NULL) tmp_color = a[y][x];
		else if(tmp_color != a[y][x]) tmp_count = -INF;
		return;
	}

	a[y][x] = '*';
	tmp_count++;
	rep(i, 4){
		dfs(y+dy[i], x+dx[i]);
	}
}

int main(void){
	while(1){
		cin >> w >> h;
		if(!w && !h) break;
	
		fill(a[0], a[54], '\0');
		rep(i, h){
			cin >> a[i];
		}

		white = black = 0;
		rep(i, h){
			rep(j, w){
				tmp_count = 0;
				tmp_color = NULL;
				if(a[i][j] == '.'){
					dfs(i, j);
					if(0 < tmp_count){
						if(tmp_color == 'W') white += tmp_count;
						else if(tmp_color == 'B') black += tmp_count;
					}
				}
			}
		}
		cout << black << " " << white << endl;
	}
	return 0;
}


Measured memory_bytes: 3124
# -*- coding: utf-8 -*-
### 幅優先探索により矛盾を探す
import sys
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int,readline().split())
graph = [[] for _ in range(N)]
for _ in range(M):
    L,R,D = map(int,readline().split())
    graph[L-1].append((R-1,D))
    graph[R-1].append((L-1,-D))

dist = [0]*N
done = [0]*N  
def bfs(i):
    q = deque([i])
    while q:
        x = q.popleft()
        for y,d in graph[x]:
            if done[y] == 0:
                done[y] = 1
                dist[y] = dist[x]+ d
                q.append(y)
            else:
                if dist[y] != dist[x]+d:
                    return 0
    return 1

for i in range(N):
    if done[i] == 0:
        done[i] = 1
        if bfs(i) == 0:
            print('No')
            sys.exit()
print('Yes')

Measured memory_bytes: 71300
from collections import deque
import math

#入力
h,w,k=map(int,input().split())
a=[input() for i in range(h)]

#Sの位置の捜索
for i in range(h):
    for j in range(w):
        if a[i][j]=='S':
            sy,sx=i,j

#各種パラメータの初期設定
d=deque([[sy,sx]])
dist=[]
inf=-1
m=1000
for i in range(h):
    dist.append([inf]*w)
dist[sy][sx]=0

#一回目の魔法で移動できる範囲を幅優先探索
while len(d)!=0:
    b=d.popleft()
    p,q=b[0],b[1]
    for i in [[1,0],[0,-1],[-1,0],[0,1]]:
        by,bx=b[0]+i[0],b[1]+i[1]
        if bx>=0 and bx<w and by>=0 and by<h and a[by][bx]!='#' and dist[by][bx]==-1 and dist[p][q]<k:
            #訪問先が配列内かつ壁でなく未訪問、訪問元の距離がk以下のとき訪問
            d.append([by,bx])
            dist[by][bx]=dist[p][q]+1

#一回目で移動できる各地点からの魔法の使用回数を計算
for i in range(h):
    for j in range(w):
        if dist[i][j]!=-1:
            m=min(m,0--min(i,h-1-i,j,w-1-j)//k)

print(m+1)


Measured memory_bytes: 61916
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <cstring>
#include <fstream>

using namespace std;


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

	int m1, d1, m2, d2;

	cin >> m1 >> d1;
	cin >> m2 >> d2;

	if (m1 == m2)
	{
		cout << 0 << '\n';
	}
	else
	{
		cout << 1 << '\n';
	}

	return 0;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
        PROGRAM-ID. AtCoder.
      
        ENVIRONMENT DIVISION.
      
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 INP PIC X(100).
        01 A PIC 9(10).
        01 B PIC 9(10).
      	01 C PIC 9(10).
      	01 t PIC 9(10).
	    01 temp1 PIC 9(11).
        01 temp2 PIC 9(11).
        01 N PIC 9(11).
      
        PROCEDURE DIVISION.
      	MAIN.
			ACCEPT A.
      		MOVE 0 to t.
      		PERFORM VARYING B FROM 1 BY 1 UNTIL B = 10
      			PERFORM VARYING C FROM 1 BY 1 UNTIL C = 10
      			IF B * C = A THEN
      				MOVE 1 to t
      			END-IF
      			END-PERFORM
      		END-PERFORM.
			IF t = 1 THEN
				DISPLAY "Yes"
			ELSE 
				DISPLAY "No"
			END-IF.
		STOP RUN.

Measured memory_bytes: 384
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solve():
    n = II()
    H = LI()

    ans = 0
    cnt = 0
    for j in range(1, n):
        i = j - 1
        hi = H[i]
        hj = H[j]
        # print(hi, hj, hi>=hj)
        if hi >= hj:
            cnt = cnt + 1
        else:
            ans = max(ans, cnt)
            cnt = 0
    ans = max(ans, cnt)
    print(ans)


if __name__ == '__main__':
    solve()


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

#define all(x) (x).begin(), (x).end()

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

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



void _main() {
        int n; cin >> n;
        vector<int> d(n); cin >> d;
        int ans = 0;
        for (int i = 0; i < n; i++)
                for (int j = i + 1; j < n; j++)
                        ans += d[i] * d[j];

        cout << ans;
}



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

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 

int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int d,n;cin>>d>>n;
  int ans=1;
  rep(i,d)ans*=100;
  ans*=n;
  if(d==0&&n==100)ans++;
  if(d==1&&n==100)ans+=100;
  if(d==2&&n==100)ans+=10000;
  cout(ans);
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
antennas = [0]* 5
for i in range(5):
    antennas[i] = int(input())
k = int(input())
connectable = True
for i in range(5):
    for j in range(i+1, 5):
        if (antennas[j] - antennas[i]) > k:
            connectable = False
if connectable:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3060