akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
double X1[20];
double Y1[20];
double X2[20];
double Y2[20];
double dp[1<<14][14][2];
int main(){
	int T=0;
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%lf%lf%lf%lf",X1+i,Y1+i,X2+i,Y2+i);
		for(int i=0;i<(1<<a);i++)for(int j=0;j<a;j++)for(int k=0;k<2;k++)
			dp[i][j][k]=999999999;
		for(int i=0;i<a;i++){
			dp[1<<i][i][0]=dp[1<<i][i][1]=0;
		}
		for(int i=0;i<(1<<a);i++){
			for(int j=0;j<a;j++){
				for(int k=0;k<2;k++){
					if(dp[i][j][k]>99999999)continue;
					for(int l=0;l<a;l++){
						if(i&(1<<l))continue;
						if(!k){
							dp[i+(1<<l)][l][0]=min(dp[i+(1<<l)][l][0],dp[i][j][k]+sqrt((X1[l]-X2[j])*(X1[l]-X2[j])+(Y1[l]-Y2[j])*(Y1[l]-Y2[j])));
							dp[i+(1<<l)][l][1]=min(dp[i+(1<<l)][l][1],dp[i][j][k]+sqrt((X2[l]-X2[j])*(X2[l]-X2[j])+(Y2[l]-Y2[j])*(Y2[l]-Y2[j])));
						}else{
							dp[i+(1<<l)][l][0]=min(dp[i+(1<<l)][l][0],dp[i][j][k]+sqrt((X1[l]-X1[j])*(X1[l]-X1[j])+(Y1[l]-Y1[j])*(Y1[l]-Y1[j])));
							dp[i+(1<<l)][l][1]=min(dp[i+(1<<l)][l][1],dp[i][j][k]+sqrt((X2[l]-X1[j])*(X2[l]-X1[j])+(Y2[l]-Y1[j])*(Y2[l]-Y1[j])));
						}
					}
				}
			}
		}
		double ret=999999999;
		for(int i=0;i<a;i++){
			ret=min(ret,dp[(1<<a)-1][i][0]);
			ret=min(ret,dp[(1<<a)-1][i][1]);
		}
		for(int i=0;i<a;i++)ret+=sqrt((X1[i]-X2[i])*(X1[i]-X2[i])+(Y1[i]-Y2[i])*(Y1[i]-Y2[i]));
		printf("Case %d: %.5f\n",++T,ret);
	}
}

Measured memory_bytes: 4680
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
int W[101];
int main(){
	cin>>N;
	int a=0;
	int b=0;
	REP(i,N){
		cin>>W[i];
		b+=W[i];
	}
	int ans=10000000;
	REP(i,N){
		a+=W[i];
		b-=W[i];
		ans=min(ans,abs(b-a));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
check=dict()
#ttfは235、chaはabc

def dfs_sub(n,ttf,cha):
    global check,d

    #-1ずつしていく場合
    check[0]=min(check[n]+n*d,check[0])

    #最寄りまで-してく場合
    x1,x2=n//ttf,n%ttf
    if x1 in check:
        if check[x1]>check[n]+x2*d+cha:
            check[x1]=check[n]+x2*d+cha
            dfs(x1)
    else:
        check[x1]=check[n]+x2*d+cha
        dfs(x1)

    #最寄りまで+1してく場合
    x1,x2=n//ttf+1,ttf-n%ttf
    if x1 in check:
        if check[x1]>check[n]+x2*d+cha:
            check[x1]=check[n]+x2*d+cha
            dfs(x1)
    else:
        check[x1]=check[n]+x2*d+cha
        dfs(x1)


def dfs(n):
    global b
    for i,j in zip([2,3,5],b):
        dfs_sub(n,i,j)

t=int(input())
for i in range(t):
    N,*b,d=map(int,input().split())
    check={N:0,0:N*d}
    dfs(N)
    print(check[0])


Measured memory_bytes: 127512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define REP(i,a,b) for (int i = a ; i <= b ; i++)
#define REPI(i,a,b) for (int i = a ; i >= b ; i--)
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e5+7;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("teleport.in","r",stdin);
    //freopen("teleport.out","w",stdout);

    int a,b;
    cin >> a >> b;
    if (b%a == 0) cout << a+b << endl;
    else cout << b-a << endl;

    return 0;
}


Measured memory_bytes: 256
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include <bits/stdc++.h>
using namespace std;
#define fi			first
#define se			second
#define fz(i,a,b)	for(int i=a;i<=b;i++)
#define fd(i,a,b)	for(int i=a;i>=b;i--)
#define foreach(it,v) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define put(x)		putchar(x)
#define eoln        put('\n')
#define space		put(' ')
#define y1			y_chenxiaoyan_1
#define y0			y_chenxiaoyan_0
inline int read(){
	int x=0,neg=1;char c=getchar();
	while(!isdigit(c)){
		if(c=='-')	neg=-1;
		c=getchar();
	}
	while(isdigit(c))	x=x*10+c-'0',c=getchar();
	return x*neg;
}
inline void print(int x){
	if(x<0){
		putchar('-');
		print(abs(x));
		return;
	}
	if(x<=9)	putchar(x+'0');
	else{
		print(x/10);
		putchar(x%10+'0');
	}
}
inline int qpow(int x,int e,int _MOD){
	int ans=1;
	while(e){
		if(e&1)	ans=ans*x%_MOD;
		x=x*x%_MOD;
		e>>=1;
	}
	return ans;
}
int n=read(),a[200005],b[200005],s[200005],t[200005];
bool ok[200005][32];
unsigned long long hs1[200005],hs2[200005],hsb=571,P[200005];
inline int get1(int l,int r){
	if(l>r)	return 0;
	return hs1[r]-hs1[l-1]*P[r-l+1];
}
inline int get2(int l,int r){
	if(l>r)	return 0;
	return hs2[r]-hs2[l-1]*P[r-l+1];
}
signed main(){
	P[0]=1;fz(i,1,n)	P[i]=P[i-1]*hsb;
	fz(i,1,n)	a[i]=read();
	fz(i,1,n)	b[i]=read();
	fz(i,0,30){
		fz(j,1,n)	s[j]=a[j]>>i&1;
		fz(j,1,n)	t[j]=b[j]>>i&1;
//		fz(j,1,n)	cout<<s[j];puts("");
//		fz(j,1,n)	cout<<t[j];puts("");
		memset(hs1,0,sizeof(hs1));
		memset(hs2,0,sizeof(hs2));
		fz(j,1,n){
			hs1[j]=(hs1[j-1]*hsb)+s[j];
			hs2[j]=(hs2[j-1]*hsb)+t[j];
		}
		fz(j,1,n){
			if(get1(1,j)==get2(n-j+1,n)&&get1(j+1,n)==get2(1,n-j))
				ok[j][i]=1;
		}
		fz(j,1,n)	s[j]^=1;
//		fz(j,1,n)	cout<<s[j];puts("");
//		fz(j,1,n)	cout<<t[j];puts("");
		memset(hs1,0,sizeof(hs1));
		memset(hs2,0,sizeof(hs2));
		fz(j,1,n){
			hs1[j]=(hs1[j-1]*hsb)+s[j];
			hs2[j]=(hs2[j-1]*hsb)+t[j];
		}
		fz(j,1,n){
			if(get1(1,j)==get2(n-j+1,n)&&get1(j+1,n)==get2(1,n-j))
				ok[j][i]=1;
		}
	}
	fz(i,0,n-1){
		bool flag=1;
		int ind=i;
		if(i==0)	ind=n;
		fz(j,0,30){
			if(!ok[ind][j])	flag=0;
		}
		if(flag)	cout<<i<<" "<<(a[ind]^b[n])<<endl;
	}
	return 0;
}

Measured memory_bytes: 17536
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 260010
#define H 510
class UnionFind{
public:
	int p[N],s[N];
	int Par(int x){
		int a=x,t;
		while(a!=p[a])a=p[a];
		while(x!=a){
			t=p[x];
			p[x]=a,s[a]+=s[x],s[x]=0;
			x=t;
		}
		return a;
	}
	int Num(int y,int x){return y*H+x;}
	void Unite(int y1,int x1,int y2,int x2){
		int a=Num(y1,x1),b=Num(y2,x2);
		a=Par(a),b=Par(b);
		if(a==b)return;
		p[a]=b,s[b]+=s[a],s[a]=0;
	}
	void Init(){
		lol(i,N)p[i]=i,s[i]=1;
	}
};
int res[2][N],lev[2][N],siz[2];
int d[H][H];
vector<pair<int,pair<int,int> > >v;
UnionFind uf;
int main(){
	int n,h,w,f,g;
	while(cin>>n&&n){
	lol(k,2){cin>>w>>h>>f>>g;f--,g--;
		uf.Init();
		f=uf.Num(g,f);
		v.clear();
		lol(i,h)lol(j,w){
			cin>>d[i][j];
			v.push_back(make_pair(d[i][j],make_pair(i,j)));
		}
		sort(v.begin(),v.end());
		lol(i,v.size()){
			int cost=v[i].first;
			int y=v[i].second.first;
			int x=v[i].second.second;
			int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
			lol(j,4){
				int xx=x+dx[j],yy=y+dy[j];
				if(xx<0||xx==w||yy<0||yy==h)continue;
				if(d[yy][xx]<=cost)uf.Unite(yy,xx,y,x);
			}
			res[k][i+1]=uf.s[uf.Par(f)];
			lev[k][i+1]=cost;
		}
		res[k][0]=0,lev[k][0]=0;
		siz[k]=v.size()+1;
	}
	int ans=mod;
	lol(i,siz[0]){
		if(res[0][i]+res[1][siz[1]-1]<n)continue;
		int l=-1,r=siz[1],m;
		while(l<r-1){
			m=(l+r)/2;
			if(res[0][i]+res[1][m]>=n)r=m;
			else l=m;
		}
		ans=min(ans,lev[0][i]+lev[1][r]);
	}
	cout<<ans<<endl;
	}
	return 0;
}



Measured memory_bytes: 12948
# 解説AC
MOD = 10**9 + 7
m = 10**5 + 5
fac = [0] * m
finv = [0] * m
inv = [0] * m


def COMBinitialize(m):
    fac[0] = 1
    finv[0] = 1
    if m > 1:
        fac[1] = 1
        finv[1] = 1
        inv[1] = 1
        for i in range(2, m):
            fac[i] = fac[i-1] * i % MOD
            inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
            finv[i] = finv[i - 1] * inv[i] % MOD


COMBinitialize(m)


def main():
    N, K = (int(i) for i in input().split())
    edge = [[] for _ in range(N)]
    for i in range(N-1):
        a, b = (int(i) for i in input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
    acc = [1]*N
    from collections import deque

    def bfs(G, s):
        dist = [-1 for _ in range(N)]
        que = deque()
        dist[s] = 0
        c = len(edge[s]) - 1
        d = len(edge[s]) + 1
        if K < d:
            acc[s] = 0
            return
        acc[s] = fac[K] * finv[K - d]
        acc[s] %= MOD
        que.append(s)
        while que:
            u = que.popleft()
            c = len(edge[u]) - 1
            if K-2 < c:
                acc[u] = 0
                return
            if dist[u] >= 1 and c > 0:
                acc[u] = fac[(K-2)] * finv[(K-2) - c]
                acc[u] %= MOD
            for v in G[u]:
                if dist[v] != -1:
                    continue
                dist[v] = dist[u] + 1
                que.append(v)

    bfs(edge, 0)
    ans = 1
    for a in acc:
        ans *= a
        ans %= MOD
    print(ans % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 76192
def examA():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    X = I()
    G = gcd(X,360)
    ans = 360//G
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return


from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examA()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 76884
#include <bits/stdc++.h>
#define MOD 100000007

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

vector<int> adjList[101010];

int dfs(int cur, int par, int dist, int * ar) {
  int children = 1;
  ar[cur] = dist;
  for (int nxt : adjList[cur])
    if (nxt != par)
      children += dfs(nxt, cur, dist + 1, ar);
  return children;
}

int main() {
  int n;
  cin >> n;
  int a, b;
  for (int ctr1 = 1; ctr1 < n; ctr1++) {
    cin >> a >> b;
    a--, b--;
    adjList[a].push_back(b);
    adjList[b].push_back(a);
  }
  int dista[n], distb[n];
  dfs(0, -1, 0, dista);
  dfs(n - 1, -1, 0, distb);
  int n1 = -1, n2 = -1;
  int rez = 0;
  for (int ctr1 = 0; ctr1 < n; ctr1++) {
    if (dista[ctr1] == distb[ctr1] && (dista[ctr1] + distb[ctr1] == dista[n - 1]))
      n1 = ctr1;
    if ((dista[ctr1] == distb[ctr1] + 2) && (dista[ctr1] + distb[ctr1] == dista[n - 1]))
      n2 = ctr1;
  }
  if (n1 != -1 && n2 != -1) {
    rez = dfs(n1, n2, 0, dista);
  }
  for (int ctr1 = 0; ctr1 < n; ctr1++) {
    if ((dista[ctr1] + 1 == distb[ctr1]) && (dista[ctr1] + distb[ctr1] == dista[n - 1]))
      n1 = ctr1;
    if ((dista[ctr1] == distb[ctr1] + 1) && (dista[ctr1] + distb[ctr1] == dista[n - 1]))
      n2 = ctr1;
  }
  if (n1 != -1 && n2 != -1) {
    rez = dfs(n1, n2, 0, dista);
  }
  if (rez > n - rez)
    cout << "Fennec\n";
  else cout << "Snuke\n";
  return 0;
}

Measured memory_bytes: 14336
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int number = 0;
        int sumSales = 0;
        int sumQuantity = 0;
        while(sc.hasNextLine()){
            String sales[] = sc.nextLine().split(",");
            number++;
            sumSales += Integer.parseInt(sales[0]) * Integer.parseInt(sales[1]);
            sumQuantity += Integer.parseInt(sales[1]);
        }
        double average = (double)sumQuantity / number;
        System.out.println(sumSales);
        System.out.println(Math.round(average));
    }
}


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

int main()
{
	// Variable declaration
	int n;
	string inptn;
	int innum;
	bool cards[4][13];

	// cards initializ. To all false.
	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 13; j++)
		{
			cards[i][j] = false;
		}
	}

	// Input n
	cin >> n;

	// n times loop
	for (int i = 0; i < n; i++)
	{
		// Input inptn and innum
		cin >> inptn >> innum;

		if (innum < 1 || innum > 13)
		{
			i--;
			continue;
		}
		// If there is a card. To the true from the false
		if (inptn == "S")
		{ // Case of Spades
			cards[0][innum - 1] = true;
		}
		else if (inptn == "H")
		{ // Case of Hearts
			cards[1][innum - 1] = true;
		}
		else if (inptn == "C")
		{ // Case of Clubs
			cards[2][innum - 1] = true;
		}
		else if (inptn == "D")
		{ // case of Diamonds
			cards[3][innum - 1] = true;
		}
		else
		{
			i--;
			continue;
		}
	}

	// 4 times loop
	for (int i = 0; i < 4; i++)
	{
		// 13 times loop
		for (int j = 0; j < 13; j++)
		{
			if (cards[i][j] == false)
			{
				// output
				switch (i)
				{
					case 0: // Case of Spades
						cout << "S " << j + 1 << endl;
						break;

					case 1: // Case of Hearts
						cout << "H " << j + 1 << endl;
						break;

					case 2: // Case of Clubs
						cout << "C " << j + 1 << endl;
						break;

					case 3: // Case of Diamonds
						cout << "D " << j + 1 << endl;
						break;
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool Fr = 0;
template<class T>inline void Read(T &x) {
	x = Fr = 0;
	T f = 1;
	char p = getchar();
	for(; !isdigit(p); p = getchar()) {
		if(p == EOF)
			return;
		if(p == '-')
			f = -1;
	}
	for(; isdigit(p); p = getchar())
		x = x * 10 + (p - 48);
	x *= f, Fr = 1;
}
/*================Header Template==============*/
const int maxn = 2e5 + 5;
int n;
string s;
int main() {
	ios :: sync_with_stdio(false);
	cin >> s;
	n = s.length();
	int cnt = 0;
	string pre = "";
	for(int i = 0; i < n; ++ i) {
		++ cnt;
		string now = "";
		now += s[i];
		if(pre == now)
			++ i, now += s[i];
		if(i == n) {
			-- cnt;
			break;
		}
		pre = now; 
	}
	cout << cnt << endl;
	
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

int dp[3001][3001];
char str[3001][3001];
char match[3001][3001];

int main() {
	
	string s, t;
	cin>>s;
	cin>>t;
	
	int a = max((int)s.size(), (int)t.size());
	int b = min((int)s.size(), (int)t.size());
	
	for (int i = 0;i <= b;++i) {
		for (int j = 0;j <= a;++j) {
			dp[i][j] = 0;
			str[i][j] = '.';
			match[i][j] = '.';
		}
	}
	
	string s1, s2;
	if (s.size() > t.size()) {
		s1 = s;
		s2 = t;
	}
	else {
		s1 = t;
		s2 = s;
	}
	
	for (int i = 1;i <= b;++i) {
		for (int j = 1;j <= a;++j) {
			
			if (s2[i-1] == s1[j-1]) {
				dp[i][j] = dp[i-1][j-1] + 1;
				str[i][j] = '0';
				match[i][j] = s2[i-1];
			}
			else if (dp[i-1][j] > dp[i][j-1]){
				dp[i][j] = dp[i-1][j];
				str[i][j] = '1';
			}
			else {
				dp[i][j] = dp[i][j-1];
				str[i][j] = '2';
			}
		}
	}

	/*
	for (int i = 1;i <= b;++i) {
		for (int j = 1;j <= a;++j) {
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
	* */

	function<void(int i, int j)> trace = [&] (int i, int j) {
		if (i < 1 || j < 1) {
			return;
		}
		if (str[i][j] == '0') {
			trace(i-1, j-1);
			cout<<match[i][j];
		}
		else if (str[i][j] == '1') {
			trace(i-1, j);
		}
		else {
			trace(i, j-1);
		}
	};
	
	trace(b, a);
	return 0;
}


Measured memory_bytes: 53248
#include <stdio.h>
typedef long long ll;
int main() {
	int x;
	scanf("%d", &x);
	for (int a = -6178; a < 6178; a++) {
		for (int b = -6178; b < 6178; b++) {
			if (x == (ll)a * a * a * a * a - (ll)b * b * b * b * b) {
				printf("%d %d\n", a, b);
				return 0;
			}
			// printf("%d %d %d\n", a, b, a * a * a * a * a - b * b * b * b *
			// b);
		}
	}
	return 0;
}

Measured memory_bytes: 1724
def euler_phi(n):
    phi = n
    for i in set(prime_factorize(n)):
        phi *= (1 - (1 / i))
    return phi

def prime_factorize(n):
    # Return list of prime factorized result
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())
print(int(euler_phi(n)))


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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            int b = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');

           
            for(int i = 0; i < b; i++)
            {
                Console.Write(str[0][i]);
                Console.Write(str[1][i]);
            }
            Console.WriteLine();
           


            //ここまで
        }
    }
}


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

/// Typedef
typedef long long           ll;
typedef unsigned long       ul;
typedef unsigned long long  ull;
typedef vector<int>         vi;
typedef vector<vi>          vvi;
typedef vector<ll>          vll;
typedef pair<int,int>       pii;
typedef pair<ll,ll>         pll;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define loop(i, y)          for(int i=0; i<int(y); i++)
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x); i>=int(y); i--)
#define all(c)              c.begin(), c.end()
#define sz(c)               int(c.size())
#define clr(x, y)           memset(x, y, sizeof(x))
#define si(x)               scanf("%d", &x)
#define sii(x, y)           scanf("%d %d", &x, &y)
#define siii(x, y, z)       scanf("%d %d %d", &x, &y, &z)
#define sl(x)               scanf("%lld", &x)
#define sll(x, y)           scanf("%lld %lld", &x, &y)

///START
/// Constants
#define MAX     200005
#define MOD     1000000007
#define base    1000000007
#define eps     1e-9
#define INF     1llu<<61    // 2,305,843,009,213,693,952
#define inf     1<<29       // 536,870,912
#define PI      acos(-1.0)  // 3.1415926535897932
// #define      INF 0x3f3f3f3f3f3f3f3f
// #define      inf 0x3f3f3f3f
double po(int p){
    double ans = 1;
    while(p--)ans*=(0.5);
    return ans;
}
int main(){
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n,k;
    sii(n,k);
    double res=0;
    FOR(i,1,n+1){
        double temp = (1.0/n);
        int tmp=i;
        while(tmp<k){
            tmp*=2;
            temp/=2.0;
        }
        res+=temp;
    }
    pf("%.10f\n",res);
    #ifdef VAMP
        printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[105];
int dp[100005];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	dp[0]=0;
	for(int i=1;i<=k;i++){
		dp[i]=0;
		for(int j=0;j<n&&a[j]<=i;j++){
			dp[i]|=dp[i-a[j]]^1;
		}
	}
	cout<<((dp[k])?"First":"Second");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    string s;
    cin >> s;
    int n = sz(s);
    vector<int> dp0(20), dp1(20, -INF);
    rep(i, n) {
        rep(j, 10) {
            if (j < (s[i] - '0')) {
                chmax(dp1[i + 1], dp0[i] + j);
            }
            if (j == (s[i] - '0')) {
                chmax(dp0[i + 1], dp0[i] + j);
            }
            chmax(dp1[i + 1], dp1[i] + j);
        }
    }
    cout << max(dp0[n], dp1[n]) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;

//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007

const int MAX_N = 200010;
long long N,K;
long long pref[MAX_N];
long long currpref[MAX_N];
long long dp[210][MAX_N];
long long a[MAX_N];

int add(int a, int b) {
    a += b;
    if(a >= MOD) {
        a -= MOD;
    }
    return a;
}
int sub(long long a, long long b) {
    a -= b;
    if(a < 0) {
        a += MOD;
    }
    return a;
}
void add_self(long long& a, long long b) {
    a = add(a, b);
}
void sub_self(long long& a, long long b) {
    a = sub(a, b);
}

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> K;
    for (long long i = 1; i<=N; i++) {
        cin >> a[i];
        a[i];
    }
    dp[0][0] = 1;
    for (long long i = 0; i<=K; i++) {
        // pref[i+1]=(pref[i+1]+pref[i])%MOD;
        add_self(pref[i+1], pref[i]);
        // pref[i+1]=(pref[i+1]+dp[0][i])%MOD;
        add_self(pref[i+1], dp[0][i]);
    }
    for (long long i = 1; i<=N; i++) {
        for (long long j = 0; j<=K; j++) {
            dp[i][j] = sub(pref[j+1], pref[max((long long)0, j-a[i])]);
            // dp[i][j] = (pref[j+1]-pref[max((long long)0, j-a[i])]+MOD)%MOD;
            add_self(currpref[j+1], currpref[j]);
            // currpref[j+1] = (currpref[j+1]+currpref[j])%MOD;
            // currpref[j+1] = (currpref[j+1]+dp[i][j])%MOD;
            add_self(currpref[j+1], dp[i][j]);
        }
        for (int j = 0; j<=K+1; j++) {
            pref[j] = currpref[j];
            currpref[j] = 0;
        }
    }
    cout << dp[N][K] << endl;
    return 0;
}



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

ll dp[1001][1001];
ll fact[1001], D[1001];
ll mod_pow(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)res = (res*a) % MOD;
		a = (a*a) % MOD;
		b >>= 1;
	}
	return res;
}
ll ppow(ll a) {
	return mod_pow(a, MOD - 2);
}
ll perm(ll a, ll b) {
	return (fact[a] * D[a - b]) % MOD;
}
ll calc(ll a, ll b, ll c) {
	return (((perm(a, b*c)*mod_pow(D[c], b)) % MOD)*D[b]) % MOD;
}
int main() {
	fact[0] = 1; D[0] = 1;
	int n, a, b, c, d; scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
	for (int i = 1; i <= n; i++) {
		fact[i] = (fact[i - 1] * i) % MOD;
		D[i] = ppow(fact[i]);
	}
	rep(i, n)dp[i][0] = 1;
	for (int i = a - 1; i < b; i++) {
		for (int j = 0; j <= n; j++) {
			if (j)(dp[i + 1][j] += dp[i][j]) %= MOD;
			if (j - c*(i + 1) < 0)continue;
			for (int k = c; j - k*(i + 1) >= 0 && k <= d; k++) {
				ll o = calc(n - (j - k*(i + 1)), k, i + 1);
				(dp[i + 1][j] += dp[i][j - k*(i + 1)] * o) %= MOD;
			}
		}
	}
	cout << dp[b][n] << endl;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;

int main() {
  int N;

  cin >> N;
  int l, r;
  int ttl = 0;
  rep(i, N) {
    cin >> l >> r;
    ttl += r - l + 1;
  }
  cout << ttl << endl;
}


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

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T*)array, (T*)(array + N), val);
}

const int INF = (1 << 21);

int n;
int m[100][100];

void dijikstra()
{
  int minv;
  int d[100], color[100];

  fill(d, d + 100, INF);
  fill(color, color + 100, 0);

  d[0] = 0;
  color[0] = 1;
  while (true) {
    minv = INF;
    int u = -1;
    for (int i = 0; i < n; i++) {
      if (minv > d[i] && color[i] != 2) {
        u = i;
        minv = d[i];
      }
    }
  
    if (u == -1) break;
    color[u] = 2;
  
    for (int v = 0; v < n; v++) {
      if (color[v] != 2 && m[u][v] != INF) {
        if (d[v] > d[u] + m[u][v]) {
          d[v] = d[u] + m[u][v];
          color[v] = 1;
        }
      }
    }
  }
  
  for (int i = 0; i < n; i++) {
    cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
  }
}

signed main()
{
  int k, u, v, c;

  Fill(m, INF);

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      m[u][v] = c;
    } 
  }

  dijikstra();

  return (0);
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define double long double
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = a; i < (int)(b); ++i)
#define all(x) x.begin(), x.end()
#define deb(x) cout << (#x) << " is " << (x) << endl;
const int mod = 1000 * 1000 * 1000 + 7;
using namespace std;

inline int add(int a, int b){
	a += b;
	// if(a >= mod)
    //     a -= mod;
    a %= mod;
	return a;
}
 
inline int sub(int a, int b){
    if (a < 0) {
        a /= 0;
    }
	a -= b;
	if(a < 0) {
        a += mod;
        // a /= 0;
    }
    // a %= mod;
	return a;
}

int32_t main() {
    int n, k;
    cin >> n >> k;
    int a[n + 1];
    FOR(i, 1, n + 1) {
        cin >> a[i];
    }
    int d[n + 1][k + 1];
    int p[n + 1][k + 1];
    memset(d, 0, sizeof(int) * (n + 1) * (k + 1));
    memset(p, 0, sizeof(int) * (n + 1) * (k + 1));
    FOR(i, 0, a[1] + 1) {
        d[1][i] = 1;
    }
    p[1][0] = d[1][0];
    FOR(i, 1, k + 1) {
        p[1][i] = add(p[1][i - 1], d[1][i]);
    }
    FOR(i, 2, n + 1) {
        FOR(j, 0, k + 1) {
            if (j - a[i] > 0) {
                d[i][j] = sub(p[i - 1][j], p[i - 1][j - a[i] - 1]);
            }
            else {
                d[i][j] = p[i - 1][j];
            }

            if (j > 0)
                p[i][j] = add(p[i][j - 1], d[i][j]);
            else 
                p[i][j] = d[i][j];
                
        }
    }
    cout << d[n][k];
    return 0;
}

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

using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define ll long long

const int INF = 2e9 + 1;
const ll INFLL = 1e18 + 1;
const int MAXN = 1e5 + 10;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    bool f = true;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x % 2 == 1) continue;
        if (x % 3 != 0 && x % 5 != 0) f = false;
    }
    if (f) cout << "APPROVED";
    else cout << "DENIED";
    return 0;
}


Measured memory_bytes: 3604
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, K = sc.nextInt()
    val H = Array.fill(N)(sc.nextInt())
    val Inf = Long.MaxValue / 10
    val dp = Array.fill(N)(Inf)

    dp(0) = 0L
    var i = 0
    while (i < N) {
      var k = 1
      val Upper = N min (i + K + 1)
      while (i + k < Upper) {
        dp(i + k) =
          (dp(i) + Math.abs(H(i) - H(i + k))) min
            dp(i + k)
        k += 1
      }
      i += 1
    }
    println(dp(N-1))
  }

}

Measured memory_bytes: 53648
n = int(input())
p = list(map(int, input().split()))

ans = 0
i = 0
while i < n - 1:
    if p[i] == i + 1:
        if p[i + 1] == i + 2:
            i += 1
        ans += 1
    i += 1
if i == n - 1:
    if p[n - 1] == n:
        ans += 1

print(ans)

Measured memory_bytes: 14008
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main()
{
	int i,j,n,k=0,c;
	cin>>n;
	c=1+n/4;
	for(i=0;i<=c;i++)
	{
		for(j=0;j<=c;j++)
		if(i*4+j*7==n)
		{
			printf("Yes\n");
			k=1;
			break;
		}
		if(k==1)
		break;
	}
	if(k==0)
	printf("No\n");
	return 0;
}

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

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

using namespace std;
typedef long long ll;

int main()
{
    int n,m,a;
    while(cin >> n >> m >> a) {
        if(n == 0 && m == 0 && a == 0) break;
        
        vector<pair<int,pair<int,int> > > v;

        rep(i,m) {
            int h,p,q;
            cin >> h >> p >> q;
            p--;
            q--;

            v.push_back(make_pair(h,make_pair(p,q)));
        }

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

        int d[105];
        memset(d,0,sizeof(d));

        rep(i,n) d[i] = i;
               
        rep(i,v.size()) {
            swap(d[v[i].second.first],d[v[i].second.second]);
        }

        rep(i,n) {
            if(d[i] == a-1) cout << i+1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1224
#include <stdio.h>
 
int main()
{
  double a,b,c,d,e,f,t;
  while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF){
    t=a*e-b*d;
    printf("%.3lf %.3lf\n",(e*c-b*f)/t+0.0,(a*f-d*c)/t+0.0);
  }
  return 0;
}

Measured memory_bytes: 652
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(int i=a; i<n; i++)
#define loop(i,a,n)	for(int i=a; i>=n; i--)

int main() 
{	
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	long long int a,b,c;
	cin>>a>>b>>c;
	long long int d=(a)/(b+c),e=d*(b+c),f=a-e;
	if(f>b)	f=b;
	cout<<(d*b+f);
		
	return 0;	
}

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

long ans=1,aaa,mod=1000000007,invele;
string l;

long modpow(long modpow_x,long modpow_y) {
  long modpow_return=1;
  for(long i=1;i<=modpow_y;i*=2) {
    if(modpow_y/i%2==1) modpow_return=modpow_return*modpow_x%mod;
    modpow_x=modpow_x*modpow_x%mod;
  }
  return modpow_return;
}

int main() {
  cin >> l;
  invele=modpow(3,mod-2);
  for(long i=0;i<l.size();i++) ans=ans*3%mod;
  aaa=ans*invele%mod*2%mod;
  for(long i=1;i<l.size();i++) {
    if(l[i]=='1') {
      aaa=aaa*invele%mod*2%mod;
    } else {
      ans=(ans+(mod-aaa*invele%mod*2%mod))%mod;
      aaa=aaa*invele%mod;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
N = int(input())
H = list(map(int, input().split()))
for _ in range(10):
    H.append(10**9)
dp = [10**9] * (N+2)
dp[0] = 0
# 配る方式
for i in range(N):
    dp[i+1] = min(dp[i] + abs(H[i]-H[i+1]),dp[i+1])
    dp[i+2] = min(dp[i] + abs(H[i]-H[i+2]), dp[i+2])
print(dp[N-1])



Measured memory_bytes: 13900
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i

}

type node struct {
	item int
	prev *node
	rank int
}

func (n *node) root() *node {
	var parent *node
	for parent = n; parent.prev != nil; parent = parent.prev {
		continue
	}
	if parent != n {
		n.prev = parent
	}
	return parent
}

func issame(nodeX, nodeY *node) bool {
	return nodeX.root() == nodeY.root()

}

func merge(nodeX, nodeY *node) {
	parentX := nodeX.root()
	parentY := nodeY.root()
	if parentX.item == parentY.item {
		return
	}

	if nodeX.rank < nodeY.rank {
		nodeX, nodeY = nodeY, nodeX
	}

	if nodeX.rank == nodeY.rank {
		nodeX.rank += 1
	}

	if parentX.prev != nil || parentY.prev != nil {
		panic(fmt.Sprintf("%v, %v", parentX, parentY))
	}

	parentY.prev = parentX

}

func main() {
	sc.Split(bufio.ScanWords)
	var n, q int
	fmt.Scanf("%d %d", &n, &q)

	groups := make([]*node, n)
	for i := 0; i < n; i++ {
		groups[i] = &node{item: i, prev: nil, rank: 0}
	}

	for i := 0; i < q; i++ {
		com, x, y := next(), next(), next()
		if com == 0 {
			merge(groups[x], groups[y])

		} else {
			if issame(groups[x], groups[y]) {
				fmt.Println("1")
			} else {
				fmt.Println("0")
			}
		}
	}

}




Measured memory_bytes: 2716
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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

// 無限大の値
const ll  LINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int n, k, x, y;
  cin >> n >> k >> x >> y;

  int ans=0;

  for (int i = 1; i <= n; i++){
    if(i<=k) ans += x;
    else ans += y;
  }
  cout << ans << endl;
  return 0;
}

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

const int MAXN=1e5+5;

map<int,int>ma;
vector<int>vec1[MAXN],vec2[MAXN];
int fa[MAXN],rk[MAXN],n,m,x,y;

inline int find(int x){
	return fa[x]==x?x:fa[x]=find(fa[x]);
}

inline void merge(int x,int y){
	if((x=find(x))==(y=find(y)))return;
	if(rk[x]<rk[y])fa[x]=y;
	else{
		fa[y]=x;
		if(rk[x]==rk[y])rk[x]++;
	}
}

void makeset(int n){for(int i=1;i<=n;i++)fa[i]=i;}

struct data{
	int num,id;
}d[MAXN];

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",&d[i].num);
		d[i].id=i;
	}
	makeset(n);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		merge(x,y);
	}
	for(int i=1;i<=n;i++){
		int now=find(i);
		vec1[now].push_back(d[i].num);
		vec2[now].push_back(d[i].id);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(vec1[i].size()){
			sort(vec1[i].begin(),vec1[i].end()),sort(vec2[i].begin(),vec2[i].end());
			int l=0,r=0,sz=vec1[i].size();
			while(l<sz&&r<sz){
				if(vec1[i][l]==vec2[i][r]){l++,r++,ans++;}
				else if(vec1[i][l]<vec2[i][r]){l++;}
				else r++;
			}	
		}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12672
#Python

N = input()
A = map(int, raw_input().split())

#print A
i=0
free_color_counts=0
colors=[]
while i<N:
	if A[i]>=1 and A[i]<=399:
		c='Hai'
		colors.append(c)
	elif A[i]>=400 and A[i]<=799:
		c='Cha'
		colors.append(c)
	elif A[i]>=800 and A[i]<=1199:
		c='Midori'
		colors.append(c)
	elif A[i]>=1200 and A[i]<=1599:
		c='Mizu'
		colors.append(c)
	elif A[i]>=1600 and A[i]<=1999:
		c='Ao'
		colors.append(c)
	elif A[i]>=2000 and A[i]<=2399:
		c='Ki'
		colors.append(c)
	elif A[i]>=2400 and A[i]<=2799:
		c='Dai'
		colors.append(c)
	elif A[i]>=2800 and A[i]<=3199:
		c='Aka'
		colors.append(c)
	elif A[i]>=3200:
		free_color_counts+=1

	i+=1


#print colors
#print list(set(colors))

if len(list(set(colors)))==0:
	print 1,
	print free_color_counts
else:
	print len(list(set(colors))),
	print len(list(set(colors)))+ free_color_counts


Measured memory_bytes: 2696
N, M = [int(_) for _ in input().split()]
H = [0] + [int(_) for _ in input().split()]
C = [[] for i in range(N+1)]
for i in range(M):
    A, B = [int(_) for _ in input().split()]
    C[A].append(H[B])
    C[B].append(H[A])
cnt = 0
for i in range(1, N+1):
    if len(C[i]) == 0 or H[i] > max(C[i]):
        cnt += 1
print(cnt)


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

using namespace std;
using ll = long long;

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

int main() {
    ll x;
    cin >> x;
    ll ans = x;
    while (!is_prime(ans)) ++ans;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * Created by hiramekun at 20:40 on 2020-05-10.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

double calc(double num) {
    double ret = 0;
    for (ll i = 1; i <= num; ++i) {
        ret += i / num;
    }
    return ret;
}

void solve() {
    ll n, k;
    cin >> n >> k;
    vl p(n);
    cin >> p;
    vl d(n + 1);
    d[0] = 0;
    rep(i, n) d[i + 1] += d[i] + p[i];
    ll mx = 0;
    ll l = -1, r = -1;
    rep(i, n - k + 1) {
        if (d[i + k] - d[i] > mx) {
            mx = d[i + k] - d[i];
            l = i, r = i + k - 1;
        }
    }
    double ans = 0;
    for (ll i = l; i <= r; ++i) {
        ans += calc(p[i]);
    }
    cout << fixed << setprecision(10) << ans << endl;
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

int n;
ll k;
int a[200010],f[200010];

bool calc(ll mid, ll cnt=k){
    rep(i,n){
        cnt-=max(0LL,a[i]-(mid/f[i]));
    }
    return cnt>=0;
}

int main(){
    cin>>n>>k;
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>f[i];
    sort(a,a+n);
    sort(f,f+n);
    reverse(f,f+n);
    ll l=-1,r=1e12+1;
    while(r-l>1){
        ll mid=(l+r)/2;
        if(calc(mid))r=mid;
        else l=mid;
    }
    cout<<r<<endl;
}

Measured memory_bytes: 5196
#include <bits/stdc++.h>
#define FOR(i, n) for(ll i = 0; i < n; i++)
#define FORR(i, n) for(ll i = n; i >= 0; i--)
#define FORS(i, m, n) for(int i = m;i < n;i++)
#define ALL(v) accumulate(v.begin(),v.end(),0)
#define SORT(v) sort(v.begin(),v.end())
#define OUT(n) (cout << n << endl)
#define IN1(a) (cin >> a)
#define IN2(a,b) (cin >> a >> b)
#define IN3(a,b,c) (cin >> a >> b >> c)
#define IN4(a,b,c,d) (cin >> a >> b >> c >> d)
using namespace std;
typedef long long ll;

int main(){
  int n;
  IN1(n);
  vector<double>varray(n);
  FOR(i,n){
    cin >> varray[i];
  }
  SORT(varray);
  double ans = varray[0];
  FORS(i,1,n){
    ans = (ans + varray[i]) / 2;
  }
  cout << fixed << setprecision(10);
  OUT(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main() {
	cin>>a>>b;
	for(int i=1;i<=100000;i++)
	{
		int na=(int)(i*0.08),nb=(int)(i*0.1);
		if(na==a&&nb==b){ printf("%d\n",i);return 0;}
	} 
	puts("-1");
	return 0;
}

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

using namespace std;
using ll = long long;

#define eb emplace_back
#define pb push_back
// #define mp make_pair
#define ff first
#define ss second

#ifdef LOCAL
    #include "debug.h"
#else
    #define debug(...) 42
#endif

void io(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);     
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <ext/rope>
// using namespace __gnu_pbds; 
// using namespace __gnu_cxx;
// template<typename T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;
// template<typename T> using MinPriorityQueue = priority_queue <T, vector <T>, greater <T> >;
// template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);}


template <typename A>
istream& operator>>(istream& input,vector<A>& x) { for(auto& i:x) input>>i; return input; }
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {  for(auto& i:x) output<<i<<' '; return output; }
template<typename T, typename U> 
istream& operator>>(istream& is, pair<T, U>& p){is >> p.first >> p.second;        return is;}
template<typename T, typename U> 
ostream& operator<<(ostream& os, pair<T, U>& p){os << p.first << ' ' << p.second; return os;}

const int mod = 1e9 + 7;
const int N = 1e6 + 5;



int main () {
    io();
    ll n, m, k;
    cin >> n >> m >> k;
    ll a[n], b[m];

    vector<ll> pre1(n), pre2(m);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(i)
            pre1[i] += pre1[i - 1];
        pre1[i] += a[i];
    }
    for(int i = 0; i < m; i++) {
        cin >> b[i];
        if(i)
            pre2[i] += pre2[i - 1];
        pre2[i] += b[i];
    }
    int ans = 0;
    for(int i = 0; i < m; i++) {
        if(k >= pre2[i]) {
            ans = i + 1;
        }
    } 
    for(int i = 0; i < n; i++) {
        if(pre1[i] > k) break;
        int rem = k - pre1[i];
        auto it = upper_bound(pre2.begin(), pre2.end(), rem);
        if(it == pre2.begin()) {
            ans = max(ans, i + 1);
            continue;
        }
        else {
            ans = max(ans, (int)(it - pre2.begin() + i + 1));
            debug(ans);
        }
    }
    cout << ans;
}

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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	int n;
	int a;
	cin >> n >> a;
	n = n % 500;
	if (n > a) {
		cout << "No" << "\n";
		return 0;
	}
	cout << "Yes" << "\n";
}


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

using namespace std;

int main()
{
  int n; cin >> n;
  long long dp[3005][3005]; for(int i = 0; i < n; i++) cin >> dp[1][i];
  
  for(int len = 2; len <= n; len++) for(int i = 0; i + len <= n; i++)
    dp[len][i] = max(dp[1][i+len-1]-dp[len-1][i], dp[1][i]-dp[len-1][i+1]);
  
  cout << dp[n][0] << endl;
  return 0;
}

Measured memory_bytes: 70656
#include<cstdio>
int a,b,c,_a,_b,_c;
int main(){
	scanf("%d%d%d",&a,&b,&c); 
	int t=0;
	while (!(a&1)  && !(b&1) && !(c&1)){
		t++; _a=(b+c)>>1; _b=(a+c)>>1; _c=(a+b)>>1;
		if (a==_a && b==_b && c==_c) {
			puts("-1");
			return 0;
		}
		a=_a; b=_b; c=_c;
		
	}
	printf("%d\n",t);
	return 0;
} 

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

void solve() {
    int n;
    cin >> n;
    VI d(n);
    REP(i,0,n) cin >> d[i];
    sort(all(d));
    int ans = 1;
    REP(i,1,n) if (d[i] > d[i-1]) ++ans;
    cout << ans << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

ll calc_gcd(ll x, ll y) {
    if (x == 0) {
        return y;
    }
    return calc_gcd(y % x, x);
}

int main(void) {
    ll A, B;
    cin >> A >> B;

    ll gcd;
    if (A < B) {
        gcd = calc_gcd(A, B);
    } else {
        gcd = calc_gcd(B, A);
    }

    cout << A * B / gcd << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



int main() {
  int n;
  cin >> n;
  vector<int> c(n-1), s(n-1), f(n-1);
  rep(i, n-1)
    cin >> c[i] >> s[i] >> f[i];

  rep(i, n) {
    int t = 0;
    for(int j=i; j<n-1; j++) {
      if(s[j] > t) {
        t = s[j] + c[j];
      } else if(t % f[j] == 0) {
        t += c[j];
      } else {
        t = t + (f[j]-(t%f[j])) + c[j];
      }
    }
    cout << t << endl;
  }


  return 0;
}

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        System.out.println( solve(N, A) );
    }

    private static long solve(int N, int[] A) {
        // pairを探して max * max2

        // reverseってないんかな...
        Arrays.sort(A);
        int prev = -1;
        int max = 0;
        for (int i = N-1; i >=0 ; i--) {
            if( A[i] == prev ) {
                if( max == 0 ) {
                    max = A[i];
                    prev = -1;

                } else {
                    return (long)max * A[i];
                }

            } else {
                prev = A[i];
            }
        }
        return 0;
    }
}


Measured memory_bytes: 49436
{-# OPTIONS_GHC -Wall #-}

import Text.Printf

readInt :: String -> Int
readInt = read

-- g=gcd(a,b), および ax+by=g の特殊解を (g,x0,y0) の形で返す
extgcd :: Int -> Int -> (Int,Int,Int)
extgcd a b = fst $ f ((a,1,0),(b,0,1))
    where
        f (tup0,tup1@(0,_,_)) = (tup0,tup1)
        f ((r0,s0,t0),(r1,s1,t1)) = f ((r1,s1,t1),(r2,s2,t2))
            where
                (q1,r2) = r0 `divMod` r1
                s2 = s0 - q1*s1
                t2 = t0 - q1*t1

main :: IO ()
main = do
    [a,b] <- fmap (map readInt . words) getLine

    let (_,x0,y0) = extgcd a b

    printf "%d %d\n" x0 y0



Measured memory_bytes: 3756