akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
using namespace std; int n;
double SIN(double p) { return sin(p*acos(-1) / 180); }
int main() {
	while (cin >> n, n) {
		if (n % 3 == 0)n /= 3;
		double D = sqrt(3.0)*(SIN(60.0 + 60.0 / n) / (SIN(60.0 + 60.0 / n) + SIN(60.0 / n))) - sqrt(0.75);
		printf("%.99lf\n", sqrt(0.25 + D*D)*SIN(60.0 / n)*n);
	}
	return 0;
}

Measured memory_bytes: 3496
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int main(){
	int W, H, x, y;
	cin >> W >> H >> x >> y;


	cout << .5*W*H << " ";

	if(2*x==W && 2*y==H){
		cout << 1 << endl;
	}else{
		cout << 0 << endl;
	}

	return 0;

}




Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    B[i] = A[i] - (i + 1);
  }
  sort(B.begin(), B.end());

  ll median = B[(B.size() + 1) / 2 - 1];
  ll ans = 0;
  for (int i = 0; i < N; i++) ans += abs(B[i] - median);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    S = input()
    if S[2] == S[3] and S[4] == S[5]:
        print('Yes')
    else:
        print('No')
    

if __name__ == '__main__':
    main()

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    string w; cin >> w;
    map<char,int> A;
    REP(i,w.size()){
        A[w[i]]++;
    }
    for(auto c: A){
        if(c.second%2!=0){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int a, b, c;
	cin >> a >> b >> c;
	if ((a == b && b != c) || (a == c && b != c) || (b == c) && a != b) cout << "Yes" << endl;
	else cout << "No" << endl;
    
    return 0;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll int64_t
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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 dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin>>n;
    vector<int> S(n);
    REP(i,n) cin>>S[i];
    cin>>q;
    vector<int> T(q);
    REP(i,q) cin>>T[i];
    int ans=0;
    REP(i,q){
        REP(j,n){
            if(T[i]==S[j]){
                ans++;
                break;
            }
        }
    }
    cout<<ans<<endl;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define int long long

#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

const int N=3e5+5;

int n;
string s;

int dp(int i, int j)
{
	if(i>=j)
		return 0;
	if(s[i]==s[j])
		return dp(i+1, j-1);
	if(s[i]!=s[j])
	{
		if(s[i]=='x')
			return 1+dp(i+1, j);
		else if(s[j]=='x')
			return 1+dp(i, j-1);
		else
			return -1e6;
	}
}

int32_t main()
{
	IOS;
	cin>>s;
	n=s.size();
	int ans=dp(0, n-1);
	if(ans<0)
		cout<<"-1";
	else
		cout<<ans;
}


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

long long ji,n,m;
char s1[100010],s2[100010];
map<long long,char> mp;
int pd=0;
inline long long gcd(long long x,long long y)
{
	return y?gcd(y,x%y):x;
}
int main()
{
	scanf("%lld%lld",&n,&m);
	scanf("%s",s1);
	scanf("%s",s2);
	ji=m*n/gcd(n,m);
	for(long long i=0;i<=n-1;++i)
	mp[ji/n*i+1]=s1[i];
	for(long long i=0;i<=m-1;++i)
	{
		if(mp[ji/m*i+1]!=0&&mp[ji/m*i+1]!=s2[i])
		{
			pd=1;
			break;
		}
	}
	if(pd==1)
	printf("-1\n");
	else
	printf("%lld\n",ji);
	return 0;
}

Measured memory_bytes: 10880
import sys 

n = int(input())
ans = 111
if n <= 111:
  print(ans)
elif n <= 222:
  print(ans*2)
elif n <= 333:
  print(ans*3)
elif n <= 444:
  print(ans*4)
elif n <= 555:
  print(ans*5)
elif n <= 666:
  print(ans*6)
elif n <= 777:
  print(ans*7)
elif n <= 888:
  print(ans*8)
elif n <= 999:
  print(ans*9)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define	mp make_pair
#define	pb push_back
#define sz(a) int((a).size())
#define all(a)  a.begin(), a.end()
#define	debug(ccc)	cout << #ccc << " = " << ccc << endl;
#define present(c,x) ((c).find(x) != (c).end())
const double eps = 1e-8;
#define EQ(a,b) (fabs((a)-(b))<eps)
inline int max(int a,int b){return a<b?b:a;}
inline int min(int a,int b){return a>b?b:a;}
inline ll max(ll a,ll b){return a<b?b:a;}
inline ll min(ll a,ll b){return a>b?b:a;}
const int mod = 1e9+7;
const int N = 1e6+10;
const ll inf = 1e18;

ll power(ll a,ll n){
	if(n==0){
		return 1;
	}
	ll b = power(a,n/2);
	b = b*b%mod;
	if(n%2) b= b*a%mod;
	return b;
}

int add(int a,int b){ return (a+b)%mod;}
int mul(int a,int b){ return (ll)a*b%mod;}


char s[N];
int A[N],B[N];

int main(){
 // 	freopen("nice.in","r",stdin);
 // freopen("nice.out","w",stdout);
	int n; scanf("%d %s",&n,s);
	REP(i,n) A[i] = (s[i]=='x');
	REP(i,2) REP(j,2){
		B[0] = i, B[1] = j;
		REPP(k,2,n){
			B[k] = A[k-1]^B[k-2]^B[k-1]; 
		}
		int f = 1;
		REP(k,2*n){
			if(B[k%n]!= B[(k-1+n)%n]^B[(k-2+n)%n]^A[(k-1+n)%n]) f=0;
		}
		if(f){
			REP(i,n){
				if(!B[i]) printf("S");
				else printf("W");
			}
			printf("\n");return 0;
		}
	}
	printf("-1\n");
	return 0;
}




Measured memory_bytes: 6912
import java.util.Scanner;

public class Main
{
    public static void main(String[] args){
        Scanner scan =new Scanner(System.in);
        double N=scan.nextDouble();
        double X=0,x=0;
        double min=2147483647;
        double[] a=new double[200000];

        for(int i=0;i<N;i++){
            a[i]=scan.nextInt();
            x+=a[i];
        }

        for(int i=0;i<N;i++)
        {
            X+=a[i];
            if(i+1<N){
                min=Minimum(min,Math.abs(x-2*X));
            }
        }

        System.out.println((int)min);
    }

    public static double Minimum(double a, double b)
    {
        if(a>b) return b;
        else return a;
    }
}

Measured memory_bytes: 85880
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, m;
string s;

int main(){
	cin >> s;
	if(s[0] == s[1] && s[2] == s[3] && s[0] != s[2]){
		cout << "Yes" << endl;
		return 0;
	}
	if(s[0] == s[2] && s[1] == s[3] && s[0] != s[1]){
		cout << "Yes" << endl;
		return 0;
	}
	if(s[0] == s[3] && s[1] == s[2] && s[0] != s[2]){
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

{-
 - Next lexicographical permutation algorithm
 - by Project Nayuki, 2016. Public domain.
 - https://www.nayuki.io/page/next-lexicographical-permutation-algorithm
 -
 - Computes the next lexicographical permutation of the specified finite
 - list of numbers.
 - Returns Nothing if the argument is already the highest permutation.
 -}
nextPermutation :: Ord a => [a] -> Maybe [a]
nextPermutation xs =
  let
    len = length xs
    -- Reverse of longest non-increasing suffix
    revSuffix = findPrefix (reverse xs)
    suffixLen = length revSuffix
    prefixMinusPivot = take (len - suffixLen - 1) xs
    pivot = xs !! (len - suffixLen - 1)
    suffixHead = takeWhile (<= pivot) revSuffix
    newPivot : suffixTail = drop (length suffixHead) revSuffix
    newSuffix = suffixHead ++ (pivot : suffixTail)
  in
    if suffixLen == len
    then Nothing
    else Just (prefixMinusPivot ++ (newPivot : newSuffix))
  where
    findPrefix [] = []
    findPrefix (x:xs) =
      x : (if xs /= [] && x <= (head xs) then (findPrefix xs) else [])

main = do
  _ <- getInt
  [p', q'] <- replicateM 2 getIntList
  let (p, q) = if (p' <= q') then (p', q') else (q', p')
  print $ solve p q 0
  where
    solve p q m | p == q = m
                | otherwise = let p' = (fromJust . nextPermutation) p
                              in solve p' q (m + 1)

Measured memory_bytes: 892
#include<iostream>
#include<algorithm>
#include<vector>
using lint=int64_t;
using namespace std;

class BiCoef
{
	public:
	int64_t size;
	int64_t Mod;
	vector<int64_t> fac;
	vector<int64_t> inv;
	vector<int64_t> finv;

	BiCoef(){};
	void init(int64_t tsize,int64_t tMod)
	{
		size=tsize;
		Mod=tMod;
		fac.resize(size+10,1);
		inv.resize(size+10,1);
		finv.resize(size+10,1);
		for(int64_t i=2;i<=size;i++)
		{
			fac[i]=i*fac[i-1]%Mod;
			inv[i]=Mod-(Mod/i)*inv[Mod%i]%Mod;
			finv[i]=inv[i]*finv[i-1]%Mod;
		}
	}

	int64_t comb(int64_t n,int64_t r)
	{
		if(n<r || n<0 || r<0)return (int64_t)0;
		return fac[n]*(finv[r]*finv[n-r]%Mod)%Mod;
	}

	int64_t perm(int64_t n,int64_t r)
	{
		return fac[r]*comb(n,r)%Mod;
	}

	int64_t rcomb(int64_t n,int64_t r)
	{
		if(n==0 && r==0)return (int64_t)1;
		return comb(n+r-1,r);	
	}
};

const lint mod=1e9+7;
BiCoef bc;

lint N,K;
vector<vector<lint>> edges;
lint ans;

void dfs(lint d,lint cur,lint prev)
{
	lint c=0;
	for(auto& i:edges[cur])
	{
		if(i==prev)continue;
		c++;
		dfs(d+1,i,cur);
	}

	if(d==0)ans=ans*bc.perm(K-1,c)%mod;
	else ans=ans*bc.perm(K-2,c)%mod;
	return;
}

int main()
{
	bc.init(100000,mod);

	cin >> N >> K;
	edges.resize(N);	
	for(int i=0;i<N-1;i++)
	{
		lint a,b;
		cin >> a >> b;
		a--;b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}

	ans=K;
	dfs(0,0,-1);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 13952
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI 3.14159265358979
 
lli dp[100000];
 
bool compareHeight(const pair<lli,lli> &a,const pair<lli,lli> &b){
	if(a.first!=b.first)return a.first < b.first;
	else return a.second > b.second;
}
 
signed main(){
 
	lli n,t;
	cin>>n>>t;
 
	vector<pair<lli,lli>> me(n);
 
	REP(i,0,n)cin>>me[i].first>>me[i].second;
 
	sort(me.begin(),me.end(),compareHeight);
 
	if(DEBUG){
		REP(i,0,n)cout<<me[i].first<<" "<<me[i].second<<endl;
	}
 
	REP(i,0,100000)dp[i]=0;
 
	REP(i,0,n){
		for(lli j=t-1;j>=0;j--){
			if(dp[j]){
				if(DEBUG)cout<<"i="<<i<<" j="<<j<<"dp[j]="<<dp[j]<<endl;
				dp[j+me[i].first] = max(dp[j+me[i].first],dp[j] + me[i].second);
			}
		}
		dp[me[i].first] = max(dp[me[i].first],me[i].second);
	}
 
	lli ans = 0;
	REP(i,0,100000){
		if(DEBUG)if(dp[i])cout<<"i="<<i<<" dp[i]"<<dp[i]<<endl;
		ans = max(ans,dp[i]);
	}
	cout<<ans<<endl;
 
	return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    s = list(set(S()))
    lis = [chr(i) for i in range(ord("a"), ord("z") + 1)]
    for si in s:
        if si in lis:
            lis.remove(si)
        # print(si,lis)
    lis.sort()
    if lis == []:
        print("None")
    else:
        print(lis[0])
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 46192
#include <iostream>
#include<string.h>
using namespace std;

int main() {
int n,count=0;
cin>>n;
int a[n][2];
for(int i=0;i<n;i++){
    cin>>a[i][0]>>a[i][1];
}
for(int i=0;i<n-2;i++){
    if(a[i][0]==a[i][1] && a[i+1][0]==a[i+1][1] && a[i+2][0]==a[i+2][1])
  { count=1;
  break;
  }
}
if(count==1)
 cout<<"Yes";
 else 
 cout<<"No";

	return 0;
}

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

int c[10][10];

int get_top(int n) {
    int v = n;
    while (v / 10 != 0) {
        v /= 10;
    } 
    
    return v % 10;
}

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

    for (int i = 1; i <= N; ++i) {
        const int first = get_top(i);
        const int last  = i % 10; 
        c[first][last] += 1;
    }

    uint64_t cnt = 0;
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            cnt += c[i][j] * c[j][i];
        }
    }

    std::cout << cnt << std::endl;

    return 0;
}


Measured memory_bytes: 256
import sys

R, C, K = map(int, input().split())
item = [[0] * (C + 1) for _ in range(R + 1)]  # dp配列と合わせるために, 0行目, 0列目を追加している.
for s in sys.stdin.readlines():
    r, c, v = map(int, s.split())
    item[r][c] = v

dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)]
for i in range(R + 1):
    for j in range(C + 1):
        for k in range(4):
            here = dp[k][i][j]
            # 次の行に移動する場合
            if i + 1 <= R:
                # 移動先のアイテムを取らない場合
                dp[0][i + 1][j] = max(dp[0][i + 1][j], here)
                # 移動先のアイテムを取る場合
                dp[1][i + 1][j] = max(dp[1][i + 1][j], here + item[i + 1][j])
            # 次の列に移動する場合
            if j + 1 <= C:
                # 移動先のアイテムを取らない場合
                dp[k][i][j + 1] = max(dp[k][i][j + 1], here)
                # 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能
                if k < 3:
                    dp[k + 1][i][j + 1] = max(dp[k + 1][i][j + 1], here + item[i][j + 1])
ans = 0
for k in range(4):
    ans = max(ans, dp[k][-1][-1])
print(ans)

Measured memory_bytes: 430084
H, W = map(int, input().split())
S = [0 for i in range(H)]

for i in range(H):
    S[i] = input()

X=[[0 for j in range(W)] for i in range(H)]

for i in range(H):
    for j in range(W):
        if(S[i][j]=='#'):
            X[i][j] = -100
            if(i>0):
                if(j>0):
                    X[i-1][j-1]+=1
                X[i-1][j]+=1
                if(j<W-1):
                    X[i-1][j+1]+=1
            if(j>0):
                X[i][j-1]+=1
            if(j<W-1):
                X[i][j+1]+=1
            if(i<H-1):
                if(j>0):
                    X[i+1][j-1]+=1
                X[i+1][j]+=1
                if(j<W-1):
                    X[i+1][j+1]+=1

for i in range(H):
    for j in range(W):
        print(X[i][j] if X[i][j]>=0 else '#', end='')
    print()


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
	using T = tuple<int64, int64, int64>;
	using P = pair<int64, T>;
	int64 X[3], K;
	REP(i, 3) cin >> X[i];
	cin >> K;
	vector<vector<int64>> V(3);
	REP(i, 3) {
		V[i].resize(X[i]);
		REP(j, X[i]) cin >> V[i][j];
		sort(all(V[i]), greater<int64>());
	}
	priority_queue<P> pq;
	map<T, bool> used;
	pq.push(P(V[0][0] + V[1][0] + V[2][0], T(0, 0, 0)));
	used[T(0, 0, 0)] = 1;
	REP(_, K) {
		T t;
		int64 sum, idx[3];
		tie(sum, t) = pq.top(); pq.pop();
		tie(idx[0], idx[1], idx[2]) = t;
		cout << sum << endl;
		REP(i, 3) {
			int64 ni[3];
			REP(j, 3) ni[j] = idx[j]+(i==j);
			if (ni[i] < X[i] && !used[T(ni[0], ni[1], ni[2])]) {
				pq.push(P(V[0][ni[0]]+V[1][ni[1]]+V[2][ni[2]], T(ni[0], ni[1], ni[2])));
				used[T(ni[0], ni[1], ni[2])] = 1;
			}
		}
	}
}


Measured memory_bytes: 1152
#include<stdio.h>
int main(void){
int W,H,x,y,r;
scanf("%d %d %d %d %d\n",&W,&H,&x,&y,&r);
if(x-r>=0&&x+r<=W&&y-r>=0&&y+r<=H){printf("Yes\n");}
else{printf("No\n");}
return 0;
}

Measured memory_bytes: 584
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];

    int[] as, bs;
    int t = 1, cnt;
    foreach_reverse (i; 1..M+1) if (i%2 == 1) {
        as ~= t++;
        ++cnt;
    }
    t += cnt-1;
    foreach (i; 1..M+1) if (i%2 == 1) {
        bs ~= t--;
    }
    t += cnt+1;
    cnt = 0;
    foreach_reverse (i; 1..M+1) if (i%2 == 0) {
        as ~= t++;
        ++cnt;
    }
    t += cnt;
    foreach (i; 1..M+1) if (i%2 == 0) {
        bs ~= t--;
    }
    foreach (i, a; as) {
        auto b = bs[i];
        writeln(a, " ", b);
    }
}

Measured memory_bytes: 3752
#import math
#import bisect
#import numpy as np
#import itertools
#import copy
import sys

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n, k = list(map(int,ipti().split()))
    h = list(map(int,ipti().split()))
    dp = [INF] * n
    dp[0] = 0

    for i in range(1, n):
        for j in range(1, k+1):
            if i - j >= 0:
                temp = abs(h[i] - h[i-j]) + dp[i-j]
                dp[i] = min(dp[i], temp)

    print(dp[n-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 55516
//073
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(void){
    int n,l,r;
    cin >> n;
    int cnt=0;
    rep(i, n){
        cin >> l >> r;
        cnt += (r-l+1);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import numpy as np
a,b,h,m=list(map(int,input().split()))

c_angle=np.abs((h+m/60)*30-m*6)
if c_angle>=180:
    c_angle=360-c_angle
c_angle=c_angle/360*2*np.pi
print(str(np.sqrt(a**2+b**2-2*a*b*np.cos(c_angle))))

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

/* -128 ~ 127 */
using i8  = int8_t;
/* 0 ~ 255 */
using u8  = uint8_t;
/* -32,768 ~ 32,767 */
using i16 = int16_t;
/* 0 ~ 65,535 */
using u16 = uint16_t;
/* -2,147,483,648 ~ 2,147,483,647 */
using i32 = int32_t;
/* 0 ~ 4,294,967,295 */
using u32 = uint32_t;
/* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using i64 = int64_t;
/* 0 ~ 18,446,744,073,709,551,615 */
using u64 = uint64_t;
/* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f32 = float;
/* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f64 = double;
using f80 = __float80;

template <class T>
using Vec = vector<T>;

template <typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template <typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

/* 定数 */
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;

#define fn auto
#define ALL(v) v.begin(), v.end()

#define GCD(a, b) __gcd(a, b) // 最大公約数
#define LCM(a, b) a / __gcd(a, b) * b // 最小公倍数

fn Main() {
    u32 A, B;
    cin >> A >> B;
    string S;
    cin >> S;
    string result = "Yes";
    if (S[A] != '-')
        result = "No";
    else {
        for (int i = 0; i < A; i++) {
            if (!isdigit(S[i]))
                result = "No";
        }
        for (int i = A + 1; i < A + 1 + B; i++) {
            if (!isdigit(S[i]))
                result = "No";
        }
    }
    cout << result << endl;
}

fn main() -> int {
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    int n,ans=0;
    cin >> n;
    if(n<10){
        ans= n;
    } else if(n<100){
        ans=n%10;
    } else if(n<1000){
        ans=n%100;
        ans%=10;
    }
    if(ans==3){
        cout << "bon";
    } else if(ans==0||ans==1||ans==6||ans==8){
        cout << "pon";
    } else {
        cout <<"hon";
    }
    return 0;
}

Measured memory_bytes: 3632
// https://tenka1-2019-beginner.contest.atcoder.jp/tasks/tenka1_2019_a

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <regex>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-7)
#define INF (1e9)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if (a < c && c < b || b < c && c < a) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
A, B = map(int, input().split())
import math
C = []
D = []
for i in range(10, 11000):
    if math.floor(i * 0.08) == A:
        C.append(i)

for i in range(10, 11000):
    if math.floor(i * 0.1) == B:
        D.append(i)

for c in C:
    if c in D:
        print(c)
        exit()

print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

int main() {
    int N, M;  cin >> N >> M;
    vector<int> X(M);
    rep(i, M)  cin >> X[i];

    if (N >= M) {
        print(0);
    } else {
        sort(X.begin(), X.end());
        vector<int> L;
        rep(i, M-1) {
            L.push_back(X[i+1] - X[i]);
        }
        sort(L.begin(), L.end());
        reverse(L.begin(), L.end());
        int sum = 0;
        rep(i, N-1) {
            sum += L[i];
        }
        print(X[M-1] - X[0] - sum);
    }
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a;
  cin >> a;
  int b=0;
  int c=a.size();
  for(int i=0;i<c;i++){
    if(i%2==0){
      if(a.at(i)=='L')
    b++;
    }
    if(i%2==1){
      if(a.at(i)=='R')
    b++;
      
    }
    
  }
  if(b>0)
    cout <<"No"<<endl;
  if(b==0)
    cout <<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<queue>
int main()
{
    int a,b,c,Mx=0;
    scanf("%d%d%d",&a,&b,&c);
    if(a>Mx)Mx=a;
    if(b>Mx)Mx=b;
    if(c>Mx)Mx=c;
    printf("%d\n",a+b+c-Mx);
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
const int N = 300005;
int c[2], A, B, C, n;
struct node{
	int v, k;
	bool operator < (const node &rhs) const { return v > rhs.v; }
}a[N];
int main(){
	scanf("%d%d%d%d%d", &c[0], &c[1], &A, &B, &C);
	for (register int i = 1; i <= A; ++i) scanf("%d", &a[++n].v), a[n].k = 0;
	for (register int i = 1; i <= B; ++i) scanf("%d", &a[++n].v), a[n].k = 1;
	for (register int i = 1; i <= C; ++i) scanf("%d", &a[++n].v), a[n].k = 2;
	std::sort(a + 1, a + 1 + n);
	int s[3] = {0, 0, 0};
	long long sum = 0;
	for (register int i = 1; i <= n; ++i){
		if (a[i].k == 2 || s[a[i].k] < c[a[i].k]) ++s[a[i].k], sum += a[i].v;
		if (s[0] + s[1] + s[2] >= c[0] + c[1]) break;
	}
	printf("%lld\n", sum);
}

Measured memory_bytes: 2560
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	long T1, T2, A1, A2, B1, B2;
	std::cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;

	if (T1*A1+T2*A2 == T1*B1+T2*B2) {
		std::cout << "infinity\n";
		return 0;
	}

	if (T1*A1+T2*A2 < T1*B1+T2*B2) {
		// A の方が漸近的に速くなるように入れ替える
		std::swap(A1, B1);
		std::swap(A2, B2);
	}

	if (A1 > B1) {
//std::cerr << "nothing\n";
		std::cout << "0\n";
		return 0;
	}

	long x = T1*(B1-A1);
	long y = T2*(A2-B2);
//std::cerr << "x = " << x << "\ny = " << y << "\n";
	long n = (y-1) / (y-x);
	long m = (x-1) / (y-x);
	long l = x % (y-x) == 0 ? 1 : 0;

	std::cout << (n + m + l) << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
  int n, a[114514];
  int i, j, s;
  
  while(1){
    scanf("%d", &n);
    if(n==0)
	{
      break;
    }
 
    int  m=1000000;
	
    for(i=0;i<n;i++)
	{
      scanf("%d", &a[i]);
    }
    for(i=0;i<n-1;i++)
	{
      for(j=i+1;j<n;j++)
	  {
    s=a[i]-a[j];
    if(s<0)
	{
      s*=-1;
    }
    if(m>s)
	{
      m=s;
    }
      }
    }
    printf("%d\n", m);
  }
  return 0;
}


Measured memory_bytes: 2036
import bisect

n, m, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))


sa = [0] * (n + 1)
for i in range(n):
  sa[i + 1] = sa[i] + a[i]

sb = [0] * (m + 1)
for j in range(m):
  sb[j + 1] = sb[j] + b[j]

anses = [0]
for i in range(n + 1):
  if sa[i] > k:
    continue
  anses.append(i + bisect.bisect(sb, k - sa[i]) - 1)

print(max(anses))


Measured memory_bytes: 48648
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

exist = True

if max(a) - min(a) > 1:
    exist = False
    
elif max(a) >= n:
    exist = False
    
elif max(a) - min(a) == 1:
    if a.count(min(a)) < max(a) and 2*(max(a)-a.count(min(a))) <= a.count(max(a)):
        exist = True
    else:
        exist = False
        
elif max(a) == min(a):
    if 2*a[0] <= n or a[0]+1 == n:
        exist = True
    else:
        exist = False
        
print("Yes") if exist else print("No")

Measured memory_bytes: 13304
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
 
#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>
 
#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 210;

int n;
char s[N][N];
int d[N][N];
int vis[N];

void dfs(int u) {
  for (int v = 1; v <= n; ++v)
    if (s[u][v] == '1')
      if (!vis[v]) {
        vis[v] = -vis[u];
        dfs(v);
      } else if (vis[v] == vis[u]) {
        puts("-1");
        exit(0);
      }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%s", s[i] + 1);
  vis[1] = 1;
  dfs(1);
  for (int i = 1; i <= n; ++i)
    fill(d[i] + 1, d[i] + n + 1, n);
  for (int i = 1; i <= n; ++i)
    d[i][i] = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (s[i][j] == '1')
        d[i][j] = 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      for (int k = 1; k <= n; ++k)
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    ans = max(ans, *max_element(d[i] + 1, d[i] + n + 1));
  printf("%d\n", ans + 1);
  return 0;
}


Measured memory_bytes: 512
import math 

X = int(input())
A =[]
if X == 1:
    print(1)
else:
    for i in range(30):
        b = i+2
        B = math.log(X+0.01,b)
        if math.floor(B) != 1:
            A.append(b**math.floor(B))
    print(max(A))



Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <stdint.h>
#include <vector>
using namespace std;

class union_find {
public:
    union_find(int n)
    {
        for (int i = 0; i < n; i++) {
            v.push_back(i);
        }
    }

    void unite(int a, int b)
    {
        v[find(a)] = find(b);
    }

    int find(int i)
    {
        if (v[i] == i)
            return i;
        return v[i] = find(v[i]);
    }

    vector<int> v;
};

int main()
{
    cin.tie(0);

    int n;
    cin >> n;
    vector<pair<int64_t, int64_t>> ps(n);
    for (auto& p : ps)
        cin >> p.first >> p.second;

    vector<int> xord(n), yord(n);
    for (int i = 0; i < n; i++) {
        xord[i] = i;
        yord[i] = i;
    }

    sort(xord.begin(), xord.end(), [&](int a, int b) { return ps[a].first < ps[b].first; });
    sort(yord.begin(), yord.end(), [&](int a, int b) { return ps[a].second < ps[b].second; });

    vector<pair<int64_t, pair<int, int>>> g;
    for (int i = 0; i < n; i++) {
        if (i > 0) {
            g.push_back(make_pair(ps[xord[i]].first - ps[xord[i - 1]].first, make_pair(xord[i], xord[i - 1])));
            g.push_back(make_pair(ps[yord[i]].second - ps[yord[i - 1]].second, make_pair(yord[i], yord[i - 1])));
        }
        if (i + 1 < n) {
            g.push_back(make_pair(ps[xord[i + 1]].first - ps[xord[i]].first, make_pair(xord[i + 1], xord[i])));
            g.push_back(make_pair(ps[yord[i + 1]].second - ps[yord[i]].second, make_pair(yord[i + 1], yord[i])));
        }
    }

    union_find uf(n);
    sort(g.begin(), g.end());

    int64_t ans = 0;

    for (int i = 0; i < g.size(); i++) {
        int a = g[i].second.first;
        int b = g[i].second.second;
        if (uf.find(a) == uf.find(b))
            continue;
        uf.unite(a, b);
        ans += g[i].first;
    }

    cout << ans << endl;

    /*
    vector<bool> done(n, false);
    done[0] = true;

    int xmin = ps[0].first;
    int xmax = xmin;
    int ymin = ps[0].second;
    int ymax = ymin;

    int xl, xr, yl, yr;
    for (int i = 0; i < n; i++) {
        if (xord[i] == 0) {
            xl = xr = i;
        }
        if (yord[i] == 0) {
            yl = yr = i;
        }
    }

    int64_t ans = 0;
    for (int i = 1; i < n; i++) {
        int best_t = -1;
        int64_t best_d = 0x7fffffffL;
        if (xl - 1 >= 0) {
            best_t = 0;
            best_d = ps[xord[xl]].second - ps[xord[xl - 1]].second;
        }
        if (xr + 1 < n && ps[xord[xr + 1]].second - ps[xord[xr]].second < best_d) {
            best_t = 0;
            best_d = ps[xord[xr + 1]].second - ps[xord[xr]].second;
        }
        if (yl - 1 >= 0 && ps[yord[yl]].second - ps[yord[yl - 1]].second < best_d) {
            best_t = 0;
            best_d = ps[yord[yl]].second - ps[yord[yl - 1]].second;
        }
        if (yr + 1 < n && ps[yord[yr + 1]].second - ps[yord[yr]].second < best_d) {
            best_t = 0;
            best_d = ps[yord[yr + 1]].second - ps[yord[yr]].second;
        }

        ans += best_d;
        if (best_t == 0) {
            done[] = true;
            xl--;
        }
    }
*/

    return 0;
}


Measured memory_bytes: 12908
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int,int> > adj[MAX];

void dijkstra(){
  priority_queue<pair<int,int> > PQ;
  int color[MAX];
  int d[MAX];
  for(int i = 0; i<n;i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  PQ.push(make_pair(0,0));
  color[0] = GRAY;

  while(!PQ.empty()){
    pair<int,int> f = PQ.top();
    PQ.pop();
    int u = f.second;
    color[u] = BLACK;

    if(d[u]<f.first * (-1)) continue;

    for(int j = 0; j<adj[u].size(); j++){
      int v = adj[u][j].first;
      if(color[v] == BLACK) continue;
      if(d[v]>d[u]+adj[u][j].second){
	d[v] = d[u]+adj[u][j].second;
	PQ.push(make_pair(d[v]*(-1),v));
	color[v] = GRAY;
      }
    }
  }
  for(int i = 0; i < n; i++){
    cout << i<<" "<<(d[i] == INFTY?-1:d[i])<<endl;
  }
}

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

  cin>>n;
  for(int i = 0; i<n; i++){
    cin>>u>>k;
    for(int j = 0; j<k; j++){
      cin>>v>>c;
      adj[u].push_back(make_pair(v,c));
    }
  }
  dijkstra();
  return 0;
}



Measured memory_bytes: 7992
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long ll;
const int INF = 1<<30;

int main(){
  int n;cin>>n;string s;cin>>s;
  int ans=0;
  for(int i=1;i<n;i++){
    string a=s.substr(0, i), b=s.substr(i, n-i);
    map<char, int> mp;int count=0;
    for(int j=0;j<i;j++){
      mp[a[j]]=1;
    }
    for(int j=0;j<n-i;j++){
      if(mp[b[j]]==1){count++;mp[b[j]]++;}
    }
    ans=max(ans, count);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){

  ll X, Y; cin >> X >> Y;
  int cnt = 0;
  while(X <= Y){
    X = X * 2;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////
ll N;

void out1(ll x){
	cout << "?";
	rep(i, N) {
		cout << " " << x + i;
	}
	cout << endl << flush;
}

void out2(ll r, ll x) {
	cout << "?";
	repn(i, N-1) {
		cout << " " << r-1+i;
	}
	
	cout << " " << x;
	cout << endl << flush;
}

void out3(ll r, ll x) {
	cout << "?";
	repn(i, N - 1) {
		if (i < r-1) { cout << " " << i; }
		else { cout << " " << N + 1 + i; }
	}
	cout << " " << x;
	cout << endl << flush;
}

string ret;



int main() {
	cin >> N;

	out1(1);
	string s1;
	cin >> s1;

	ll l = 1;
	ll r = N+1;
	while (r - l > 1) {
		ll m = (r + l) / 2;
		out1(m);
		cin >> ret;
		if (s1 == ret) { l = m; }
		else { r = m; }
	}

	vector<char> ans(2 * N + 1);
	
	repn(i, 2 * N) {
		if (i < r || i >= r + N - 1) { out2(r, i); }
		else { out3(r, i); }
		cin >> ret;
		if (ret == "Red") { ans[i] = 'R';}
		else { ans[i] = 'B'; }
	}

	cout << "! ";
	repn(i, 2 * N) { cout << ans[i]; }
	return 0;

	system("PAUSE");
}


Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
 
long long calc(int n, int c1, int c2, int s1, int s2, const vector<int>& options,
               int d, int nt, int ot) {
  int b1(d-1), a1(d+1), b2(d-1), a2(d+1);
  while (b1 >= 0 && options[b1] != nt) b1--;
  while (b2 >= 0 && options[b2] != ot) b2--;
  while (a1 < n && options[a1] != nt) a1++;
  while (a2 < n && options[a2] != ot) a2++;
  int x1(d-b1-1), y1(a1-d-1), z1(a1-b1-1), x2(d-b2-1), y2(a2-d-1), z2(a2-b2-1);
  int diff1 = z1*(z1+1)/2-x1*(x1+1)/2-y1*(y1+1)/2;
  int diff2 = z2*(z2+1)/2-x2*(x2+1)/2-y2*(y2+1)/2;
  return (long long) diff1 * c1 - (long long) diff2 * c2 + s1 - s2;
}
 
int main() {
  int n;
  cin >> n;
  vector<int> c(26), last(26, -1);
  vector<array<int, 26>> s(n);
  
  for (int i = 0; i < 26; ++i) cin >> c[i];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < 26; ++j)
      cin >> s[i][j];
  
  long long total(0);
  vector<int> options(n);
  
  for (int i = 0; i < n; ++i) {
    int neg(0), test(-1), max_score(-1e9);
    for (int j = 0; j < 26; ++j) neg -= c[j] * (i - last[j]);
    for (int j = 0; j < 26; ++j) {
      int ss = s[i][j] + neg + c[j] * (i - last[j]);
      if (ss > max_score) {
        max_score = ss;
        test = j;
      }
    }
    total += max_score;
    options[i] = test;
    last[test] = i;
  }
  
  for (int t = 1; t <= 500; ++t) {
    bool entered = false;
    for (int dd = 0; dd < n; ++dd) {
      for (int tt = 0; tt < 26; ++tt) {
        if (tt == options[dd]) continue;
        int ot = options[dd];
        long long ns = calc(n, c[tt], c[ot], s[dd][tt], s[dd][ot],
                            options, dd, tt, ot);
        //cout << ns << endl;
        if (ns > 0) {
          entered = true;
          total += ns;
          options[dd] = tt;
    	}
      }
    }
    if (!entered) break;
  }
  // stochastic
  for (int t = 1; t <= 200000; ++t) {
    int dd = rand() % n;
    int tt = rand() % 26;
    int ot = options[dd];
    while (ot == tt) tt = rand() % 26;
    long long ns = calc(n, c[tt], c[ot], s[dd][tt], s[dd][ot],
                        options, dd, tt, ot);
    if (ns < 0) {
      options[dd] = ot;
    } else {
      total += ns;
    }
  }
  for (const int& i: options) cout << i + 1 << endl;
  
  return 0;
}

Measured memory_bytes: 3624
n,m=map(int,input().split())
l=[]
for i in range(m):
  l.append(int(input()))
l=set(l)
L=[0 for i in range(n+1)]
L[0]=1
if 1 in l:
  L[1]=0
else:
  L[1]=1
for i in range(2,n+1):
  if i in l:
    L[i]=0
  else:
    L[i]=L[i-1]+L[i-2]
    L[i]%=1000000007
print(L[n])

Measured memory_bytes: 13216
#include<bits/stdc++.h>
using namespace std;
#define F(n) for(int i=0;i<n;++i)
#define Fj(n) for(int j=0;j<n;++j)
const int MOD=1e9+7;

int main()
{
    long n;
    cin >> n;
    const long N=n;
    long a[N];
    F(n) cin >> a[i];
    long sl=0,sr=0;
    long i=0,j=n-1;
    while(i<=j){
        if(sl<=sr){
            sl+=a[i];
            ++i;
        }
        else{
            sr+=a[j];
            --j;
        }
    }
    long ans;
    if(sl>=sr) ans=sl-sr;
    else ans=sr-sl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main{
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        boolean flag = false;
        for(int i = a; i<=b; i++){
            if(i%k == 0){
                flag = true;
                break;
            }
        }
        if(flag){
            System.out.println("OK");
        } else {
            System.out.println("NG");
        }
    }
}

Measured memory_bytes: 35788
#include<iostream>

using namespace std;
  
int main(){

  int ans;
  int x,y,s;

  while(1){

    cin>>x>>y>>s;
    if(x==0&&y==0&&s==0) break;

    ans=0;
    for(int i=1;i<s;i++){
      for(int j=i;j<s;j++){
	if(i*(x+100)/100+j*(x+100)/100==s){
	  if(ans<i*(y+100)/100+j*(y+100)/100){
	    ans=i*(y+100)/100+j*(y+100)/100;
	  }
	}
      }
    }
    cout<<ans<<endl;
  }

}

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


int main()
{
    int n , A,B;
    cin>>n>>A>>B;
    string s;
    cin>>s;
    int currPass =0;
    int rankB = 0;
    for(int i=0;i<s.length() ;i++)
    {
        if( s[i] =='a'&& currPass <A+B)
        {
                currPass++;
                cout<<"Yes\n";
        }
        else if( s[i] =='b')
        {
            rankB++;
            if( currPass< A+B && rankB <= B )
            {
                currPass++;
                cout<<"Yes\n";
            }
            else cout<<"No\n";
        }
        else {
            cout<<"No\n";
        }
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define SYAMU(ary) memset(ary,0,sizeof(ary))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define pb push_back
#define eb emplace_back
#define mp make_pair

int main() {
    vint v;
    rep(i,3) {
        int a;cin>>a;v.pb(a);
    }
    sort(ALL(v));
    if(v[0]==5 and v[1]==5 and v[2]==7)
        puts("YES");
    else
        puts("NO");


    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
h_array = gets.chomp.split(" ").map(&:to_i)
@mizuyari_num = 0

def self.mizuyari(target_array)
  slice_h_array = []
  temp_array = []
  target_array.each do |h|
    if h == target_array.min
      if !temp_array.empty?
        slice_h_array.push(temp_array)
        temp_array = []
      end
    else
      temp_array.push(h - target_array.min)
    end
  end
  # 最後追加されてなかったら追加する
  if !temp_array.empty?
    slice_h_array.push(temp_array)
  end
  # 水やり完了
  @mizuyari_num += target_array.min
  if slice_h_array.flatten.empty?
    # 終わり
  else
    slice_h_array.each { |h|
      mizuyari(h)
    }
  end
end

mizuyari(h_array)
print("#{@mizuyari_num}\n")

Measured memory_bytes: 2044