akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
//const lint MOD = pow(10, 9) + 7;

int main() {
	int N;
	cin >> N;
	string A, B;
	int a = 0, b = 0;
	rep(i, N) {
		cin >> A >> B;
		if (A > B)a += 3;
		else if (A < B)b += 3;
		else {
			a++;
			b++;
		}
	}
	cout << a << ' ' << b << endl;
}


Measured memory_bytes: 3164
using System;

class Program
{
    static void Main(string[] args)
    {
        var sp = Console.ReadLine().Split(' ');
        int a = int.Parse(sp[0]);
        int b = int.Parse(sp[1]);
        if (a <= 8 && b <= 8) Console.WriteLine("Yay!");
        else Console.WriteLine(":(");
    }
}


Measured memory_bytes: 13140
#pragma GCC optimize("O3", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC optimize("tree-vectorize")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")

#include <iostream>
#include <algorithm>

using namespace std;

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

  int N;
  cin >> N;

  pair<pair<string, int>, int> p[N];

  for (int i = 0; i < N; ++i) {
    string s;
    int point;

    cin >> s >> point;

    p[i] = make_pair(make_pair(s, -point), i + 1);
  }

  sort(p, p + N);

  for (int j = 0; j < N; ++j) {
    cout << p[j].second << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define LEN 1000005

typedef struct node {
	int key;
	struct node* next;
	struct node* prev;
}NODE;

NODE* nil;

void init() {
	nil = (NODE*)malloc(sizeof(NODE));
	nil->next = nil;
	nil->prev = nil;
}

void insert(int key) {
	NODE* x = (NODE*)malloc(sizeof(NODE));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

NODE* listSearch(int key) {
	NODE* cur = nil->next;
	while (cur != nil && cur->key != key) {
		cur = cur->next;
	}
	return cur;
}

void deleteNode(NODE* t) {
	if (t == nil) return;
	t->next->prev = t->prev;
	t->prev->next = t->next;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void delteKey(int x) {
	deleteNode(listSearch(x));
}

void printNode() {
	NODE* x = nil->next;
	int isf = 0;
	while (x != nil) {
		if (isf++ > 0) printf(" ");
		printf("%d", x->key);
		x = x->next;
	}
	printf("\n");
}

int main() {
	int i;
	int n;
	int key;
	char com[20];
	scanf("%d", &n);

	init();
	for (i = 0; i < n; i++) {
		scanf("%s%d", com, &key);
		if (strcmp(com, "insert") == 0) {
			insert(key);
		} else if(strcmp(com, "delete") == 0){
			delteKey(key);
		} else if(strcmp(com,"deleteFirst") == 0){
			deleteFirst();
		} else if(strcmp(com, "deleteLast") == 0){
			deleteLast();
		}
	}
	printNode();
	return 0;
}


Measured memory_bytes: 32920
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<tgmath.h>
using namespace std;

#define lld long long

int main(){
    string S;
    cin >> S;
    if(S[2] == S[3] && S[4] == S[5]){
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }
}

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

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	constexpr int num = 2019;
	string S;
	int ans = 0;
	vector<vector<int>> r;
	
	cin>>S;
	
	r.resize(2, vector<int>(num));
	
	
	for(int i = 0; i < S.size(); i++){
		int y = S[i] - '0';
		r[(i+1)%2][y]++;
		
		for(int j = 0; j < num; j++){
			int x = (j * 10 + y) % num;
			r[(i+1)%2][x] += r[(i)%2][j];
			r[(i)%2][j] = 0;
		}
		
		ans += r[(i+1)%2][0];
	}
	
	cout<<ans<<endl;
	// cout<<r[S.size()][0]<<endl;
	
	return 0;
}

Measured memory_bytes: 3736
#include <stdio.h>

int main()
{
  int A[100], N, a, count=0, i, j, minj;

  scanf("%d",&N);
  for(j = 0 ; j < N ; j++){
    scanf("%d",&A[j]);
  }
  
  for(i = 0 ; i < N-1 ; i++){
    minj = i;
    for(j = i ; j <= N-1 ; j++){
      if(A[j] < A[minj]){
	minj = j;
      }
    }
    a = A[i];
    A[i] = A[minj];
    A[minj] = a;
    if(i != minj){
    count++;
    }
  }

  for(i = 0 ; i < N-1 ; i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[N-1]);
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int main()
{
	int n,m;
	while(~scanf("%d%d",&n,&m))
	{
		if(m<10&&m>=0&&n<10&&n>=0)
		{
			if(n<m)
			printf("0\n");
			else
			printf("10\n");
		}
	}
	return 0;
 } 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A, B;
		A = sc.nextInt();
		B = sc.nextInt();
		sc.close();

		for (int b = 1; b < 9999999; b++) {
			if (Math.floor(b * 0.08) == A && Math.floor(b * 0.1) == B) {
				System.out.println(b);
				return;
			}
		}
		System.out.println(-1);
	}
}


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


int main()
{
  string s;
  cin >> s;
  for(int bit=0; bit < (1<<s.size() - 1); ++bit){
    int ans = s[0] - '0';
    for(int i = 0; i<s.size()-1; i++){
      if (bit&(1<<i)) ans += s[i+1] - '0'; 
      else ans -= s[i+1] - '0';
    }
    if(ans == 7){
      for(int i = 0; i < s.size(); i++){
        cout << s[i];
        if(i < s.size() - 1){
        if(bit&(1<<i)) cout << '+';
        else cout << '-';
        }
      }
      cout << "=7" << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int N;
    cin >> N;

    ll sum = 0;
    vi count(1000000);
    rep(i, N)
    {
        int a;
        cin >> a;
        count[a]++;
        sum += a;
    }

    int Q;
    cin >> Q;

    rep(i, Q)
    {
        int b, c;
        cin >> b >> c;

        sum += (ll)c * (ll)count[b];
        sum -= (ll)b * (ll)count[b];

        cout << sum << endl;

        count[c] += count[b];
        count[b] = 0;
    }

    return 0;
}

Measured memory_bytes: 7152
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}

string aki = "AKIHABARA";
string S;
int dfs(int dep,string str){
  if(str == aki && dep == (int)S.size()) return 1;
  if(str.size() >= aki.size()) return 0;
  if(dep < (int)S.size() && dfs(dep+1,str + S[dep])) return 1;
  if(dfs(dep,str + 'A')) return 1;
  return 0;
}

signed main(){

  cin>>S;
  int ans = dfs(0,"");  

  
  cout<<(ans?"YES":"NO")<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n, a=0, b=0, c=0, d=0, m=0;
 
  while(scanf("%d", &n)!=EOF){

  for(d=0;d<=9;d++){

    for(c=0;c<=9;c++){

      for(b=0;b<=9;b++){

	for(a=0;a<=9;a++){

	  if(a+b+c+d==n)m=m+1;

	}
      }

    }

  }
  printf("%d\n", m);
  m=0;
  }



  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
using namespace std;
int n,p,a,o,e;
long long ans;

long long combination(int n,int k){
    long long r=1;
    k=min(k,n-k);
    for(int i=0;i<k;i++){
        r*=(n-i);
        r/=(i+1);
    }
    return r;
}

int main(){
    cin>>n>>p;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a%2) o++;
        else e++;
    }
    for(int i=p;i<=o;i+=2){
        ans+=combination(o,i);
    }
    for(int i=0;i<e;i++){
        ans*=2;
    }
    cout<<ans;
}

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

template <typename T>
using lim = numeric_limits<T>;

const int MAXN = 100;
int arr[MAXN];

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

	int n; cin >> n;
	int total = 0;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		total += arr[i];
	}

	int ave = total/n;

	int ans = 0;
	int ans2 = 0;
	for (int i = 0; i < n; i++){
		ans += (arr[i]-ave)*(arr[i]-ave);
		ans2 += (arr[i]-ave-1)*(arr[i]-ave-1);
	}

	cout << min(ans, ans2) << "\n";

}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<long> prime, sieve(31622, 1);
    for(long i = 2; i < 31622; ++i)
        if(sieve[i]){
            prime.push_back(i);
            for(auto j = i * i; j < 31622; j += i)sieve[j] = 0;
        }

    vector<long> a(N + 1);
    for(auto& i : a)cin >> i;
    long u{0};
    for(const auto i : a)u = __gcd(u, abs(i));

    vector<long> ans;
    for(const auto p : prime)
        if(u % p == 0){
            ans.push_back(p);
            while(u % p == 0)u /= p;
        }else if(p <= N){
            vector<long> v(p);
            for(unsigned long j = 0, k = 0; j < N; ++j){
                v[k] += a[j];
                if(++k == p - 1)k = 0;
            }
            [&]{
                if(a[N] % p)return;
                for(auto j : v)if(j % p)return;
                ans.push_back(p);
            }();
        }
    for(const auto i : ans)cout << i << endl;
    if(u != 1)cout << u << endl;
}

Measured memory_bytes: 768
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define llong long long
#define ldouble long double
#define uint unsigned int
#define ullong unsigned long long
#define udouble unsigned double
#define uldouble unsigned long double
#define modinc(x) {if(x>=P) x-=P;}
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>
#define piiii pair<pair<int,int>,pair<int,int> >
#define pli pair<llong,int>
#define pll pair<llong,llong>
#define Memset(a,x) {memset(a,x,sizeof(a));}
using namespace std;

const int N = 4e6;
const int P = 1e9+7;
struct Point
{
	llong x,y;
	Point() {}
	Point(llong _x,llong _y) {x = _x,y = _y;}
} a[8],b[4],c[4];
llong fact[N+2];
llong finv[N+2];

Point operator +(Point x,Point y) {return Point(x.x+y.x,x.y+y.y);}
Point operator -(Point x,Point y) {return Point(x.x-y.x,x.y-y.y);}

llong comb(llong x,llong y) {return x<0 || y<0 || x<y ? 0ll : fact[x]*finv[y]%P*finv[x-y]%P;}
llong calc0(llong x,llong y) {return x<0 || y<0 ? 0ll : comb(x+y,x);}
llong calc(Point x,Point y) {Point tmp = y-x; return calc0(tmp.x,tmp.y);}

llong quickpow(llong x,llong y)
{
	llong cur = x,ret = 1ll;
	for(int i=0; y; i++)
	{
		if(y&(1ll<<i)) {y-=(1ll<<i); ret = ret*cur%P;}
		cur = cur*cur%P;
	} return ret;
}

int main()
{
	fact[0] = 1ll;
	for(int i=1; i<=N; i++) fact[i] = fact[i-1]*i%P;
	finv[N] = quickpow(fact[N],P-2);
	for(int i=N-1; i>=0; i--) finv[i] = finv[i+1]*(i+1)%P;
	for(int i=1; i<=6; i++) scanf("%lld",&a[i].x);
	for(int i=1; i<=6; i++) scanf("%lld",&a[i].y);
	b[0] = a[1]-Point(1,1); b[1] = Point(a[2].x,a[1].y-1); b[2] = a[2]; b[3] = Point(a[1].x-1,a[2].y);
	c[0] = a[5]; c[1] = Point(a[6].x+1,a[5].y); c[2] = a[6]+Point(1,1); c[3] = Point(a[5].x,a[6].y+1);
//	for(int i=0; i<4; i++) printf("b%d %lld %lld\n",i,b[i].x,b[i].y);
//	for(int i=0; i<4; i++) printf("c%d %lld %lld\n",i,c[i].x,c[i].y);
	llong ans = 0ll;
	for(int i=0; i<4; i++)
	{
		for(int j=0; j<4; j++)
		{
			llong Coe = ((i+j)&1) ? P-1ll : 1ll; llong delta = 0ll;
			Point s = b[i],t = c[j];
			for(int k=a[4].y; k>=a[3].y; k--)
			{
				llong tmp = calc(s,Point(a[3].x,k)-Point(1,0))*calc(Point(a[3].x,k),t)%P;
				delta += tmp*(P-k-a[3].x); delta %= P;
			}
			for(int k=a[3].x; k<=a[4].x; k++)
			{
				llong tmp = calc(s,Point(k,a[3].y)-Point(0,1))*calc(Point(k,a[3].y),t)%P;
				delta += tmp*(P-k-a[3].y); delta %= P;
			}
			for(int k=a[3].x; k<=a[4].x; k++)
			{
				llong tmp = calc(Point(k,a[4].y)+Point(0,1),t)*calc(s,Point(k,a[4].y))%P;
				delta += tmp*(a[4].y+k+1); delta %= P;
			}
			for(int k=a[4].y; k>=a[3].y; k--)
			{
				llong tmp = calc(Point(a[4].x,k)+Point(1,0),t)*calc(s,Point(a[4].x,k))%P;
				delta += tmp*(a[4].x+k+1); delta %= P;
			}
			ans += Coe*delta; ans%=P;
//			printf("b%lld %lld c%lld %lld delta%lld Coe%lld\n",b[i].x,b[i].y,c[j].x,c[j].y,delta,Coe);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 62720
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n, m, k;
    cin >> n >> m >> k;
    if(k>n){
        long long diff=k-n;
        n=0;
        m-=diff;
        if(m<0){
            m=0;
        }
    }else{
        n-=k;
    }
    cout << n << " " << m << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    x,n=map(int, input().split())
    l=list(map(int,input().split()))
    for i in range(100):
        if x-i not in l:
            print(x-i)
            break
        elif x+i not in l:
            print(x+i)
            break
resolve()


Measured memory_bytes: 9120
from collections import deque

N = int(input())
abc = [list(map(int, input().split())) for _ in range(N-1)]
q, K = map(int, input().split())

graph = [[] for i in range(N+1)]
for i,j,k in abc:
    graph[i].append((j,k))
    graph[j].append((i,k))
    
r = [-1 for i in range(N+1)] 
Q = deque()
Q.append(K)
r[K] = 0

while Q:
    x = Q.popleft()
    for to, dis in graph[x]:
        if r[to] == -1:
            r[to] = r[x] + dis
            Q.append(to)
            
for _ in range(q):
    x, y = map(int, input().split())
    print(r[x] + r[y])

Measured memory_bytes: 59212
N, W = map(int, input().split())

wv = []
for _ in range(N):
    wv.append(tuple(map(int, input().split())))

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    wi, vi = wv[i]

    for j in range(wi):
        dp[i+1][j] = dp[i][j]

    for j in range(wi, W+1):
        dp[i+1][j] = max(dp[i][j], dp[i][j-wi] + vi)

print(dp[N][W])


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

int main(){
  int N,D,ans=0;
  cin >> N >> D;
  vector<vector<int>> vec(N,vector<int>(D,0));
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin >> vec.at(i).at(j);
    }
  }
  double cnt=0;
  for(int k=0;k<N;k++){
    for(int l=0;l<N;l++){
      if(k>=l)
        continue;
      else{
        for(int m=0;m<D;m++){
          cnt+=pow(vec.at(k).at(m)-vec.at(l).at(m),2);
        }
          cnt=pow(cnt,0.5);
          if(ceil(cnt)==floor(cnt))
            ans++;
          cnt=0;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        while(true) {
            int N = stdIn.nextInt();
            if(N == 0) break;
            int[] k = new int[N];
             
            for(int i = 0; i < N; i++) {
                k[i] = stdIn.nextInt();
            }
            int max = 0;
            int s = 0;
            for(int i = 0; i < N; i++) {
                if(max < k[i]) max = k[i];
                if(k[i] != 0) {
                    s++;
                }
            }
             
            if(max < 2) {
                System.out.println("NA");
            }
            else {
                System.out.println(s+1);
            }
        }
    }
         
}

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

int main() {
	int N;
    string A, B, C;
    cin >> N >> A >> B >> C;

    int a[100];
    int b[100];
    int c[100];

    for(int i = 0; i < N; ++i){
    	a[i] = A[i] - '0';
    	b[i] = B[i] - '0';
    	c[i] = C[i] - '0';
    }

    int count = 0;

    for(int i = 0; i < N; ++i){
    	if((a[i] == b[i]) && (b[i] == c[i])){
    		count = count + 0;
    	}else if((a[i] == b[i]) && (c[i] != a[i])){
    		count++;
    	}else if((a[i] == c[i]) && (b[i] != a[i])){
    		count++;
    	}else if((b[i] == c[i]) && (a[i] != b[i])){
    		count++;
    	}else{
    		count = count + 2;
    	}
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;

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

int main() {
	int N,K; cin >> N>>K;
	vector<int> h(N),dp(N,1e9);
	for (int i = 0; i < N; i++)cin >> h[i];
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 1; j <= K; j++) {
			if (i + j == N)break;
			chmin(dp[i + j], dp[i] + abs(h[i] - h[j+i]));
		}
	}
	cout << dp[N - 1] << endl;
}





Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    sort(all(a));
    reverse(all(a));

    if(n%2==0){
        ll ans=0;
        rep(i,n/2-1) ans+=2*a[i];
        ans+=a[n/2-1];
        ans-=a[n/2];
        for(int i=n/2+1;i<n;i++) ans-=a[i]*2;
        cout<<ans<<endl;
    }
    else{
        ll ans1=0;
        rep(i,n/2-1) ans1+=a[i]*2;
        ans1+=a[n/2-1]+a[n/2];
        for(int i=n/2+1;i<n;i++) ans1-=a[i]*2;

        ll ans2=0;
        rep(i,n/2) ans2+=a[i]*2;
        ans2-=a[n/2]+a[n/2+1];
        for(int i=n/2+2;i<n;i++) ans2-=a[i]*2;

        cout<<max(ans1,ans2)<<endl;
    }
}

Measured memory_bytes: 4052
///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair <int, int> pii;
#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
char c[2005][2005];
int v[2005][2005], eh[2005][2005], ev[2005][2005];
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	cout.tie(0);
	int n, m, q, x1 , x2, y1, y2;
	cin >> n >> m >> q;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++){
			cin >> c[i][j];
			v[i][j] = v[i - 1][j] + v[i][j - 1] - v[i - 1][j - 1];
			if(c[i][j] == '1')
				v[i][j]++;
			eh[i][j] = eh[i - 1][j] + eh[i][j - 1] - eh[i - 1][j - 1];
			if(c[i][j] == '1' && c[i - 1][j] == '1')
				eh[i][j]++;
			ev[i][j] = ev[i - 1][j] + ev[i][j - 1] - ev[i - 1][j - 1];
			if(c[i][j] == '1' && c[i][j - 1] == '1')
				ev[i][j]++;
		}
	while(q--){
		cin >> x1 >> y1 >> x2 >> y2;
		int ans1 = 0, ans2 = 0, ans3 = 0;
		ans1 = v[x2][y2] - v[x2][y1 - 1] - v[x1 - 1][y2] + v[x1 - 1][y1 - 1];
		ans2 = eh[x2][y2] - eh[x2][y1 - 1] - eh[x1][y2] + eh[x1][y1 - 1];
		ans3 = ev[x2][y2] - ev[x2][y1] - ev[x1 - 1][y2] + ev[x1 - 1][y1];
     // cout << ans1 << " " << ans2 << " " << ans3 << endl;
		cout << ans1 - ans2 - ans3 << endl;
	}
	return 0;
}


Measured memory_bytes: 99968
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>

int main() {
	int N;
	std::vector<int> H;
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		int H_i;
		scanf("%d", &H_i);
		H.push_back(H_i);
	}

	for (int i = N - 1; i > 0; --i) {
		if (H[i - 1] - H[i] >= 2) {
			printf("No");
			return 0;
		} else if (H[i - 1] - H[i] == 1) {
			H[i - 1] -= 1;
		}
	}

	printf("Yes");
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, t; cin>>n>>t;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin>>a[i];
  long int ans=a[0];
  for(int i=0;i<n-1;i++){
    int val=0;
    if(a[i+1]-a[i]>=t)
      val=t;
     else
       val=a[i+1]-a[i];
    ans+=val;
  }
  ans+=t;
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll INF = 1LL << 58;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;
 
	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}
 
	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}
 
	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}
 
	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}
 
		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);
 
		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;
 
		return true;
	}
};
//x以下の要素への最小index
template <class T> int former(const vector<T> &v, T x) {
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素への最小index
template <class T> int latter(const vector<T> &v, T x) {
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
//vector書き出し
template <class T1>
void cout_vec(const int n, vector<T1> &vec1){
  rep(i, n){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}
//nCk
ll comb(ll n,ll k){
    ll ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}
//a,bの最大公約数
ll gcd(ll a,ll b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
    }
    ll k=*max_element(a.begin(),a.end());
    ll ans=0;
    rep(i,len(a)){
        if(abs(2*a[i]-k)<abs(2*ans-k)){
            ans=a[i];
        }
    }
    cout<<k<<' '<<ans<<endl;
}

Measured memory_bytes: 1024
n, X = map(int, input().split())
A = [int(x) for x in input().split()]

A = sorted(A)

def solve(a, x, j):
    cnt = 0
    f = False
    for i in range(j, n):
        if x >= a[i]:
            x -= a[i]
            cnt += 1
        else:
            cnt += 1
            f = True
        if f or x == 0:
            break
    if x == 0:
        return cnt
    else:
        return cnt - 1
    
res = 0
for i in range(n):
    res = max(res, solve(A[::-1], X, i))
    res = max(res, solve(A, X, i))
print(res)


Measured memory_bytes: 3064
import numpy as np

N, K = map(int, input().split())
# print(K, N)

locations = input().split()
dists = []
prev_location = None

for location in locations:
  if prev_location is None:
    prev_location = int(location)
  else:
	  dists.append(int(location) - prev_location)  
	  prev_location = int(location)
dists.append(N - int(locations[-1]) + int(locations[0]))

# print(dists)
print(N - np.array(dists).max())

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }


int main(){
  ll i, j, k;
  ll n;
  ll c;
  cin >> n >> c;
  ll d[c][c], a[n][n], s[c][3];
  for(i = 0; i < c; i++)
    for(j = 0; j < c; j++)
      cin >> d[i][j];
  
  for(i = 0; i < n; i++)
    for(j = 0; j < n; j++)
      cin >> a[i][j];
  
  for(i = 0; i < c; i++){
    for(j = 0; j < 3; j++)
      s[i][j] = 0;
  }
  
  for(i = 0; i < c; i++){
    for(j = 0; j < n; j++)
      for(k = 0; k < n; k++){
        if(a[j][k] != i + 1){
          s[i][(j + k) % 3] += d[a[j][k] - 1][i];
        }
      }
  }
  ll result = INF;
  
  for(i = 0; i < c; i++)
    for(j = 0; j < c; j++)
      if(i != j)
        for(k = 0; k < c; k++)
          if(i != k && j != k)
            chmin(result, s[i][0] + s[j][1] + s[k][2]);
  
    
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a=sc.nextInt();
    int b=sc.nextInt();
    if (a%3==0 || b%3==0 || (a+b)%3==0){
      System.out.println("Possible");
    } else {
      System.out.println("Impossible");
    }
  }
}

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

struct Node{
  int p, l, r;
};

struct Node T[MAX];
int n;
int D[MAX], H[MAX];

int getDepth(int u){
  int d = 0;
  while(1){
    u = T[u].p;
    if ( u == NIL ) break;
    d++;
  }
  return d;
}

int getSibling(int u){
  if ( T[u].p == NIL ) return NIL;
  if ( T[T[u].p].l != u && T[T[u].p].l != NIL ) return T[T[u].p].l;
  if ( T[T[u].p].r != u && T[T[u].p].r != NIL ) return T[T[u].p].r;
  return NIL;
}

void print(int u){
  printf("node %d: ", u);

  printf("parent = %d, ", T[u].p);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if ( T[u].l != NIL ) deg++;
  if ( T[u].r != NIL ) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if ( T[u].p == NIL ){
    printf("root\n");
  } else if ( T[u].l == NIL && T[u].r == NIL ){
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}

main(){
  int i, v, l, r;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    T[i].p = NIL;
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if ( l != NIL ) T[l].p = v;
    if ( r != NIL ) T[r].p = v;
  }

  for ( i = 0; i < n; i++ ){
    D[i] = getDepth(i);
    H[i] = 0;
  }

  for ( i = 0; i < n; i++ ){
    if ( T[i].l == NIL && T[i].r == NIL ) { // is leaf
      H[i] = 0;
      int p = T[i].p;
      int c = 1;
      while(1){
	if ( p == NIL ) break;
	if ( H[p] < c ) H[p] = c;
	c++;
	p = T[p].p;
      }
    }
  }

  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}


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

public class Main {

	static int cost[];
	static int time[];
	static int edge_c[][];
	static int edge_t[][];
	static boolean use[][];

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n,i,a,b,k,m;
		while(true){
			n=sc.nextInt();
			m=sc.nextInt();
			if(n+m==0) break;
			cost=new int[m+1];
			time=new int[m+1];
			edge_c=new int[m+1][m+1];
			edge_t=new int[m+1][m+1];
			use=new boolean[2][m+1];

			for(i=0;i<=m;i++){
				Arrays.fill(edge_c[i], 1<<20);
				Arrays.fill(edge_t[i], 1<<20);
			}
			for(i=0;i<n;i++){
				a=sc.nextInt();
				b=sc.nextInt();
				edge_c[a][b]=edge_c[b][a]=sc.nextInt();
				edge_t[a][b]=edge_t[b][a]=sc.nextInt();
			}
			k=sc.nextInt();
			int p,q,r;
			for(i=0;i<k;i++){
				p=sc.nextInt();
				q=sc.nextInt();
				r=sc.nextInt();
				Arrays.fill(cost, 1<<20);
				Arrays.fill(time, 1<<20);
				Arrays.fill(use[0], false);//cost_use
				Arrays.fill(use[1], false);
				dijkstra(p,m,r);
				if(r==0){
					System.out.println(cost[q]);
				}
				else{
					System.out.println(time[q]);
				}
			}
		}
	}
	static void dijkstra(int start,int m,int r){
		int min;
		cost[start]=0;
		time[start]=0;
		if(r==0){
			while(true){
				min=-1;
				for(int i=1;i<=m;i++){
					if(!use[0][i]){
						if(min==-1 || cost[i]<cost[min]) min=i;
					}
				}
				if(min==-1) break;
				use[0][min]=true;
				for(int i=1;i<=m;i++){
					cost[i]=Math.min(cost[i], cost[min]+edge_c[min][i]);
				}

			}
		}
		else{
			while(true){
				min=-1;
				for(int i=1;i<=m;i++){
					if(!use[1][i]){
						if(min==-1 || time[i]<time[min]) min=i;
					}
				}
				if(min==-1) break;
				use[1][min]=true;
				for(int i=1;i<=m;i++){
					time[i]=Math.min(time[i], time[min]+edge_t[min][i]);
				}
			}
		}
	}
}

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

int main() {
  ll n,a,b;
  cin>>n>>a>>b;
  if ((b-a)%2==0) cout<<(b-a)/2<<endl;
  else cout<<min(a-1,n-b)+1+(b-a-1)/2<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
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 (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
int main(){
    int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;cin >> k;
    cout << a[k-1] << endl;
}

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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

void solve() {
  int n; cin >> n;
  int a = n/15;
  cout << n*800-200*a << '\n';

  return;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 3612
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;

const int N = 2e5 + 5;
const int M = 1e6 + 5;
const ll P = 998244353LL;

int n, m = 0, a[N], pCnt = 0, phi[M];
ll num[M], inv[M], f[M], g[M], h[M];
bool vis[M];

template <typename T>
inline void read(T &X) {
    char ch = 0; T op = 1; 
    for (X = 0; ch > '9' || ch < '0'; ch = getchar())
        if (ch == '-') op = -1;
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        X = (X * 10) + ch - '0';
    X *= op;
}

template <typename T>
inline void chkMax(T &x, T y) {
	if (y > x) x = y;
}

inline void inc(ll &x, ll y) {
    x += y;
    if (x >= P) x -= P;
} 

inline void dec(ll &x, ll y) {
    x -= y;
    if (x < 0) x += P;
}

inline ll fpow(ll x, ll y) {
    ll res = 1;
    for (; y > 0; y >>= 1) {
        if (y & 1) res = res * x % P;
        x = x * x % P;
    }
    return res;
}

inline void sieve() {
    h[1] = 1;
    for (int i = 2; i <= m; i++) {
        if (!vis[i]) {
            vis[i] = 1;
            phi[++pCnt] = i;
            h[i] = inv[i], dec(h[i], 1LL);
        }
        for (int j = 1; j <= pCnt && i * phi[j] <= m; j++) {
            vis[i * phi[j]] = 1;
            if (i % phi[j] == 0) {
                h[i * phi[j]] = h[i] * inv[phi[j]] % P;
                break;
            } else h[i * phi[j]] = h[i] * h[phi[j]] % P;
        }
         
    }
}

inline void prework() {
    inv[1] = 1;
    for (int i = 2; i <= m; i++) inv[i] = (P - P / i) * inv[P % i] % P;
    sieve();
    
    for (int i = 1; i <= m; i++)
        for (int j = i; j <= m; j += i)
            inc(g[i], 1LL * j * num[j] % P);

/*    for (int i = 1; i <= m; i++) printf("%lld%c", 1LL * inv[i] % P, " \n"[i == m]);
    for (int i = 1; i <= m; i++) printf("%lld%c", num[i], " \n"[i == m]);
    for (int i = 1; i <= m; i++) printf("%lld%c", 1LL * i * num[i] % P, " \n"[i == m]);
    for (int i = 1; i <= m; i++) printf("%lld%c", g[i], " \n"[i == m]);
    for (int i = 1; i <= m; i++) printf("%lld%c", h[i], " \n"[i == m]);     */
}

int main() {
    read(n);
    for (int i = 1; i <= n; i++) {
        read(a[i]);
        ++num[a[i]];
        chkMax(m, a[i]);
    }

    prework();

    ll ans = 0LL;
    for (int i = 1; i <= m; i++) inc(ans, g[i] * g[i] % P * h[i] % P);
    for (int i = 1; i <= n; i++) dec(ans, 1LL * a[i]);
    ans = ans * inv[2] % P;

    printf("%lld\n", ans);
    return 0;
}

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

int main(void){
	int d, t, s;
	string ans;
	cin >> d >> t >> s;
	if(d <= t*s){
		ans = "Yes";
	} else {
		ans = "No";
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3592
#include <iostream> // cout, endl, cin
#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> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
const ll  MOD = 1000000007;

int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	while (true) {
		c -= b;
		if (c <= 0) {
			cout << "Yes";
			return 0;
		}
		a -= d;
		if (a <= 0) {
			cout << "No";
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3632
import collections
n = int(input())

s = []
ans = []

for _ in range(n):
    s.append(input())

c = collections.Counter(s)
max_c = max(c.values())

for si, vi in c.items():
    if vi == max_c:
        ans.append(si)

ans2 = sorted(ans)

for s2 in ans2:
    print(s2)

Measured memory_bytes: 35572
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int a[100001];

int main() {

	ll n;
	ll a[200002];
	ll c[200002]={};

	cin>>n;
	if(n==1){
		cin>>a[1];
		cout<<a[1]<<endl;
	}else{
		for(ll i=1; i<n+1; i++){
			cin>>a[i];
		}
		for(ll j=n; j>=1; j--){
			cout<<a[j]<<" ";
			c[j]=1;
			j--;
		}
		for(ll i=1; i<n-1; i++){
			if(c[i]==0){
				cout<<a[i]<<" ";
			}
		}
		cout<<a[n-1]<<endl;
	}
	return 0;
}


Measured memory_bytes: 5248
#include<cstdio>
#include<map>
using namespace std;
int beg[100100],nex[200100],tto[200100],e;
void putin(int s,int t){
	tto[++e]=t;
	nex[e]=beg[s];
	beg[s]=e;
}
bool vis[100100][2];
int cnt[3];
void dfs(int u,int zt){
	if(vis[u][zt]) return;
	vis[u][zt]=1;
	for(int i=beg[u];i;i=nex[i])
		dfs(tto[i],zt^1);
}
int main(){
//	freopen("A.in","r",stdin);
	int n,m;
	scanf("%d%d",&n,&m);
	int s,t;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&s,&t);
		putin(s,t);
		putin(t,s);
	}
	dfs(1,0);
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		if(vis[i][0]) cnt[0]++;
		if(vis[i][1]) cnt[1]++;
		if(vis[i][0]&&vis[i][1]) cnt[2]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i][0]&&vis[i][1]) ans=ans+cnt[0]+cnt[1]-cnt[2]-1;
		else if(vis[i][0]) ans=ans+cnt[1];
		else if(vis[i][1]) ans=ans+cnt[0];
	}
	ans=ans/2;
	ans=ans-m;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3968
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const long MOD = 1000000007;

int N, C;
int D[31][31];
int t[3][31];

int calc(int a, int b, int c) {
  int value = 0;
  for (int i = 1; i <= C; i++) {
    value += t[0][i] * D[i][a];
  }
  for (int i = 1; i <= C; i++) {
    value += t[1][i] * D[i][b];
  }
  for (int i = 1; i <= C; i++) {
    value += t[2][i] * D[i][c];
  }
  return value;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> C;
  // fill(D[0], D[32], 0);
  // fill(t[0], t[4], 0);
  for (int i = 1; i <= C; i++) {
    for (int j = 1; j <= C; j++) {
      cin >> D[i][j];
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      int c;
      cin >> c;
      t[(i + j) % 3][c]++;
    }
  }

  int ans = INT_MAX;
  for (int i = 1; i <= C; i++) {
    for (int j = 1; j <= C; j++) {
      if (i == j) {
        continue;
      }
      for (int k = 1; k <= C; k++) {
        if (i == k || j == k) {
          continue;
        }

        ans = min(ans, calc(i, j, k));
      }
    }
  }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    double x;
    cin>>x;
    int m=(x+1)/2;
    cout<<fixed<<setprecision(6)<<m/x;
    return 0;
}


Measured memory_bytes: 256
/*
    Problem 95
    https://atcoder.jp/contests/abc149/tasks/abc149_b
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll A, B, K;
    cin >> A >> B >> K;
    ll tmp = A;
    A = max(A - K, 0LL);
    K = max(K - tmp, 0LL);
    B = max(B - K, 0LL);
    cout << A << ' ' << B << '\n';
}

Measured memory_bytes: 3552
import java.io.*;
import java.util.*;

public class Main {
  private static int solve(int n, int[] as) {
    int sum = 0;
    for (int a : as) {
      sum += a - 1;
    }
    return sum;
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    int[] as = reader.nextInt(n);
    out.println(solve(n, as));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public 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();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
long long int dp[100000];
long long int n,k;
long long int func(long long int a[ ],int ind){

	long long int ans=1e9 + 7;
	if(ind>=n-1) return 0;
	if(dp[ind]!=-1)	return dp[ind];

	
	for(int i=0;i<k;i++){
		if(ind+i<n)
		ans = min( ans, abs(a[ind+i+1]-a[ind]) + func(a,ind+i+1));
	}
	dp[ind]=ans;
	return dp[ind];
}
int main(){



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


memset(dp,-1,sizeof(dp));
cin>>n>>k;
long long int a[n];
for(int i=0;i<n;i++)
cin>>a[i];



long long int p=0;
p=func(a,0);
cout<<p;
}

Measured memory_bytes: 14524
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main(){
    int N;
    cin >> N;
    vector<ll> a;
    REP(i, 3 * N)
    {
    	ll t;
    	cin >> t;
    	a.push_back(t);
    }

    ll sum_front[N + 1] = { 0 };
    priority_queue<ll, vector<ll>, std::greater<ll>> que_front;
    // a[0] ~ a[N - 1] を優先度付きキューに追加
   	for (int i = 0; i < N; ++i)
    {
    	que_front.push(a[i]);
    	sum_front[0] += a[i];
    }
    
    for(int k = 1; k <= N; ++k)
    {
    	que_front.push(a[N - 1 + k]);
    	ll min_element = que_front.top();
    	que_front.pop();
    	sum_front[k] = sum_front[k - 1] + a[N - 1 + k];
    	sum_front[k] -= min_element;

    }

    ll sum_back[N + 1] = { 0 };
    priority_queue<ll> que_back;
    // a[2 * N] ~ a[3 * N -1] を優先度付きキューに追加
   	for (int i = 0; i < N; ++i)
    {
    	que_back.push(a[2 * N + i]);
    	sum_back[N] += a[2 * N + i];
    }

    for (int k = 1; k <= N; ++k)
    {
    	que_back.push(a[2 * N - k]);
    	ll max_element = que_back.top();
    	que_back.pop();
    	sum_back[N - k] = sum_back[N - k + 1] + a[2 * N - k];
    	sum_back[N - k] -= max_element;
    }

    ll diff_max = sum_front[0] - sum_back[0];
    for(int k = 1; k <= N; ++k)
    {
    	ll diff = sum_front[k] - sum_back[k];
    	diff_max = max(diff_max, diff);
    }

    cout << diff_max << endl;
}


Measured memory_bytes: 8172
from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    n,k=MI()
    ans=k*pow(k-1,n-1)
    print(ans)

main()


Measured memory_bytes: 3316
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    let mut ans = 0;
    for i in 1 .. n+1 {
       let mut c = 0;
       let mut x = i;
       while x > 0 {
           c += 1;
           x /= 10;
       }
       if c % 2 != 0 {
           ans += 1;
       }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#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 CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int a[SIZE],b[SIZE];
int main(){
    int A,B,M;
    R(A,B,M);
    FOR(i,1,A)R(a[i]);
    FOR(i,1,B)R(b[i]);
    int an=*min_element(a+1,a+A+1)+*min_element(b+1,b+B+1);
    REP(i,M){
        int x,y,c;
        R(x,y,c);
        an=min(an,a[x]+b[y]-c);
    }
    W(an);
    return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <set>

int main() {
  int k;
  std::cin >> k;
  int x = 7 % k;
  int i = 1;
  std::set<int> s;
  while (s.find(x) == s.end()) {
    if (x == 0) {
      std::cout << i << std::endl;
      return 0;
    }
    s.insert(x);
    x = 10 * x + 7;
    x %= k;
    ++i;
  }
  std::cout << -1 << std::endl;
}


Measured memory_bytes: 49964