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

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

  int ans = 0;
  for (int i = 0; i < (int)N.size(); i++) {
    ans += stoi(N.substr(i,1));
  }
  if (ans%9==0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3756
package main

import "fmt"

func main() {
	var str string
	fmt.Scan(&str)
	S := []byte(str)
	if S[0] != 'A' {
		fmt.Println("WA")
		return
	}
	S[0] = 'a'
	foundC := false
	for i := 2; i < len(S)-1; i++ {
		if S[i] == 'C' {
			S[i] = 'c'
			foundC = true
			break
		}
	}
	if !foundC {
		fmt.Println("WA")
		return
	}
	for i := 0; i < len(S); i++ {
		if 'A' <= S[i] && S[i] <= 'Z' {
			fmt.Println("WA")
			return
		}
	}
	fmt.Println("AC")
}


Measured memory_bytes: 1768
#include<bits/stdc++.h>
#define f(i,a,b) for(long long i=a;i<b;i++)
#define pb(i) push_back(i)
#define mk(x,y) make_pair(x,y)
#define F first
#define S second
#define accu(i) fixed<<setprecision(i)
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
using namespace std;

int main(){
	ll n,k,a,cnt=0;cin>>n>>k;
	while(n--){
		cin>>a;
		if(a>=k) cnt++;
	}
	cout<<cnt<<"\n";
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, wo string
	fmt.Scanln(&a)
	an := 1
	for i := 0; i < len(a); i++ {
		wo = a[i : i+1]
		if i%2 == 0 && wo != "R" && wo != "U" && wo != "D" {
			an = 0
		} else if i%2 != 0 && wo != "L" && wo != "U" && wo != "D" {
			an = 0
		}
	}
	if an != 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

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

using namespace std;

template<typename T> T gcd(T a, T b){return (a % b)? gcd(b, a % b) : b;}
template<typename T> T lcm(T a, T b){return a * b / gcd(a, b);}

void solve_127C(){
    int n, m;
    cin >> n >> m;
    int L = 1, R = n;
    REP(i,m){
        int l, r;
        cin >> l >> r;
        if(L <= l) L = l;
        if(r <= R) R = r;
    }
    cout << (R - L + 1 > 0? R - L + 1 : 0) << endl;
}

int main(void){
    solve_127C();
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int n;
set<string> ss;
string s;
void dfs(string t, vector<queue<int>> q,int ps){
    if(t.size()==3){
        ss.insert(t);
        return;
    }
    rep(i,10){
        vector<queue<int>> qq=q;
        int pos=ps;
        while(qq[i].size()&&qq[i].front()<=pos){
            qq[i].pop();
        }
        if(qq[i].size()){
            pos=qq[i].front();
            qq[i].pop();
            dfs(t+(char)('0'+i),qq,pos);
        }
    }
    return;
}
int main(){
    cin >> n >> s;
    vector<queue<int>> q(10);
    rep(i,n){
        int num=(s[i]-'0');
        q[num].push(i);
    }
    dfs("",q,-1);
    cout << (int)ss.size() << endl;
    return 0;
}

Measured memory_bytes: 1428
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int  a,int b){
	return a>b;
}
int r[100000],g[100000],c1[100000];
int s[300000];
int main(){
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	long long ans=0;
	for(int i=1;i<=a;i++){
		cin>>r[i];
	}
	for(int i=1;i<=b;i++){
		cin>>g[i];
	}
	for(int i=1;i<=c;i++){
		cin>>c1[i];
	}
	sort(r+1,r+1+a,cmp);
	sort(g+1,g+1+b,cmp);
	sort(c1+1,c1+1+c,cmp  );
	int cnt=0;
	for(int i=1;i<=x;i++){
		s[++cnt]=r[i];
	}
	for(int i=1;i<=y;i++){
		s[++cnt]=g[i];
	}
	sort(s+1,s+1+cnt);
	int cnt1=1;
	for(int i=1;i<=c;i++){
		if(c1[i]>s[cnt1])
		{s[cnt1]=c1[i];
		cnt1++;
		}
	}
	for(int i=1;i<=cnt;i++){
		ans=ans+s[i];
	}
	cout<<ans<<endl;
	
	
	
	
	
}

Measured memory_bytes: 2176
#include <sstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define REP(i, a) for (int i = 0, _a = (a); i < _a; ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define double long double
typedef pair<int, int> II;
#define PI (2 * acos((double)0))
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(a,x) memset(a, x, sizeof(a))
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define y0 u9cqu3jioajc

double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); }
int GI(int& x) { return scanf("%lld", &x); }

const int MN = 3011;
int f[MN], a[MN];
int n;
vector<int> ke[MN];

void dfs(int u, int fu) {
    f[u] = 0;
    for(int v : ke[u]) {
        if (v == fu) continue;
        dfs(v, u);

        if (f[v] == 0 && a[v] < a[u]) {
            f[u] = 1;
        }
    }
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << (fixed) << setprecision(9);
    while (GI(n) == 1) {
        FOR(i,1,n) GI(a[i]);
        FOR(i,1,n) ke[i].clear();
        FOR(i,2,n) {
            int u, v; GI(u); GI(v);
            ke[u].push_back(v);
            ke[v].push_back(u);
        }

        FOR(i,1,n) {
            dfs(i, -1);
            if (f[i]) cout << i << ' ';
        }
        cout << endl;
    }
}


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

int main() {
	int D, T, S;
	cin >> D >> T >> S;
	if (D <= T*S) {
		std::cout << "Yes" << '\n';
	} else {
		std::cout << "No" << '\n';
	}
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <vector>
 
typedef long long ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
const double PI=3.14159265358979323846;
 
using namespace std;
 
int main() {

	string s;
	cin >> s;

	int a = s.find('C');
	int b = s.rfind('F');

	string ans = "No";

	if (a != string::npos && b != string::npos) {
		if (a < b)
			ans = "Yes";
	}

	cout << ans << endl;
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  long long n, m;
  cin >> n >> m;
  long long ans = 1900 * m + (n - m) * 100;
  cout << ans * (1ll << m) << '\n';
  return 0;
}

Measured memory_bytes: 3648
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

ret = 0
for i in range(N) :
    if B[i] > A[i] :
        B[i] -= A[i]
        ret += A[i]
        A[i] = 0
        
    else :
        A[i] -= B[i]
        ret += B[i]
        B[i] = 0
        
    if B[i] > A[i+1] :
        B[i] -= A[i+1]
        ret += A[i+1]
        A[i+1] = 0
        
    else :
        A[i+1] -= B[i]
        ret += B[i]
        B[i] = 0
        
print(ret)

Measured memory_bytes: 81892
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array

# 時々使う
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

# 再帰の制限設定
sys.setrecursionlimit(10000000)


def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
                    for _ in range(n)]


def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
                    for _ in range(n)]


def lcm(x, y): return (x * y) // math.gcd(x, y)


# MOD = 10 ** 9 + 7
MOD = 998244353
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    xyh = [il() for _ in range(N)]

    for cx in range(0, 101):
        for cy in range(0, 101):
            tmp_x, tmp_y, tmp_h = -1, -1, -1
            for x, y, h in xyh:
                if h == 0:
                    continue
                tmp_x, tmp_y = cx, cy
                tmp_h = h + abs(x - cx) + abs(y - cy)
                break

            if tmp_h != -1:
                for x, y, h in xyh:
                    if h != max(tmp_h - abs(x - tmp_x) - abs(y - tmp_y), 0):
                        break
                else:
                    print(tmp_x, tmp_y, tmp_h)
                    exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9568
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>

int main() {
	int n, m;
	cin >> n >> m;
	vector<int>a(n);
	int w(0),s(0);
	rep(i, m) {
		int buffer;
		string result;
		cin >> buffer >> result;
		if (a[buffer - 1] != -1) {
			if (result == "WA") {
				++a[buffer - 1];
				//cout << a[buffer - 1] << endl;
			}
			else {
				w += a[buffer-1];
				a[buffer - 1] = -1;
				++s;
			}
		}
	}
	cout << s << ' ' << w << endl;
	return 0;
}

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

int main()
{
    double N, K, score;
    cin >> N >> K;

    double kakuritu = 0;
    
    for (int i = 1; i <= N; i++)
    {
        double tmp = 1 / N;
        score = i;

        while (score < K)
        {
            tmp /= 2;
            score *= 2;
        }
        kakuritu += tmp;
    }
    cout << fixed << setprecision(10) << kakuritu;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s;
        cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    ll a[4] = {};
    ll b[4] = {};
    rep(i,4){
        scanf("%lld",&a[i]);
        if(a[i]==1){
            b[0]++;
        }
        if(a[i]==9){
            b[1]++;
        }
        if(a[i]==7){
            b[2]++;
        }
        if(a[i]==4){
            b[3]++;
        }
    }
    if(b[0]==1&&b[1]==1&&b[2]==1&&b[3]==1)yn;
    



    

    return 0;
}
 
 


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

int n,q,a,b,p[100010],p1;
bool f[100010];
int main(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)
		p[i]=i;
	f[1]=true;
	f[2]=true;
	p1=1;
	for(int i=0;i<q;i++){
		scanf("%d%d",&a,&b);
		int t=p[a];
		p[a]=p[b];
		p[b]=t;
		if(a==p1)
			p1=b;
		else if(b==p1)
			p1=a;
		f[p[p1-1]]=f[p[p1]]=f[p[p1+1]]=true;

	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(f[i])ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
package main

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

/* 一つ読み */
func scanText() string {
	sc.Scan()
	return sc.Text()
}
func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}
func scanFloat() float64 {
	sc.Scan()
	a, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		fmt.Println(err)
	}
	return a
}

/* 複数読み */
func scanTextSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = scanText()
	}
	return a
}
func scanSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}
func scanFloatSlice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = scanFloat()
	}
	return a
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := scanInt()

	ac := 0
	wa := 0
	tle := 0
	re := 0
	for i := 0; i < n; i++ {
		judge := scanText()
		switch judge {
		case "AC":
			ac++
		case "WA":
			wa++
		case "TLE":
			tle++
		case "RE":
			re++
		}
	}

	fmt.Println("AC x", ac)
	fmt.Println("WA x", wa)
	fmt.Println("TLE x", tle)
	fmt.Println("RE x", re)
}

Measured memory_bytes: 1776
N,M = map(int,input().split())
PS = [input().split() for i in range(M)]
penas = {}
acs = set()
pena = 0
for p,s in PS:
    if s=='AC':
        if p in acs: continue
        acs.add(p)
        if p in penas:
            pena += penas[p]
    else:
        if p in penas:
            penas[p] += 1
        else:
            penas[p] = 1
print(len(acs), pena)

Measured memory_bytes: 38292
n = int(input())
a = [0]*n
b = [0]*n

for i in range(n):
    a[i], b[i] = map(int, input().split())

ans = 0
for i in range(n-1, -1, -1):
    if (a[i]+ans) % b[i] != 0:
        ans += b[i] - (a[i]+ans) % b[i]

print(ans)


Measured memory_bytes: 16764
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}

class ModCom {
    public:
        ModCom(int _n, long long _mod){
            assert(_n>=2);
            n = _n+1;
            mod = _mod;
            fac.assign(n,0);
            finv.assign(n,0);
            inv.assign(n,0);
            init();
        }

        long long com(int _n, int k){
            if(_n < k){return 0;}
            if(_n < 0 || k < 0){return 0;}
            return fac.at(_n) * (finv.at(k) * finv.at(_n - k) % mod) % mod;
        }

    private:
        int n;
        long long mod;
        vector<long long> fac;
        vector<long long> finv;
        vector<long long> inv;

        void init(void){
            fac.at(0) = fac.at(1) = 1;
            finv.at(0) = finv.at(1) = 1;
            inv.at(1) = 1;
            for(int i = 2;i < n; i++){
                fac.at(i) = fac.at(i - 1) * i % mod;
                inv.at(i) = mod - inv.at(mod % i) * (mod / i) % mod;
                finv.at(i) = finv.at(i - 1) * inv.at(i) % mod;
            }
            return;
        }
};

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ModCom com(5000000,MOD);
    ll x,y;cin>>x>>y;
    if (2*x-y<0 || 2*y-x<0) {
        cout << 0 << endl;
        return 0;
    }
    if ((2*x-y)%3!=0 || (-x+2*y)%3!=0) {
        cout << 0 << endl;
        return 0;
    }
    cout << com.com((x+y)/3, (2*x-y)/3) << endl;
    return 0;
}


Measured memory_bytes: 117504
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Scanner;
import java.util.OptionalInt;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B1DimensionalWorldsTale solver = new B1DimensionalWorldsTale();
        solver.solve(1, in, out);
        out.close();
    }

    static class B1DimensionalWorldsTale {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt(), x = in.nextInt(), y = in.nextInt();
            int xm = IntStream.range(0, n).map(o -> in.nextInt()).max().orElse(0);
            int z = IntStream.range(0, m).map(o -> in.nextInt()).min().orElse(0);
            if (xm < z && x < z && z <= y) {
                out.println("No War");
            } else {
                out.println("War");
            }
        }

    }
}



Measured memory_bytes: 28372
H, W, M = map(int, input().split())

HW = set()
sum_h = [0]*H; sum_w = [0]*W
max_sum_h = max_sum_w = 0
for _ in range(M):
    h, w = map(lambda x:int(x)-1, input().split())
    HW.add((h, w))
    sum_h[h] += 1
    sum_w[w] += 1
    max_sum_h = max(max_sum_h, sum_h[h])
    max_sum_w = max(max_sum_w, sum_w[w])

hs = []; ws = []
for i in range(H):
    if sum_h[i] == max_sum_h: hs.append(i)
for i in range(W):
    if sum_w[i] == max_sum_w: ws.append(i)

ans = max_sum_h + max_sum_w - 1
for h in hs:
    for w in ws:
        if (h, w) in HW: continue
        print(ans + 1)
        exit()
print(ans)


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

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

int main(){ 
  ll n,k;
  cin >> n >> k;

  vector<double> p(n);
  rep(i,n) cin >> p[i];

  vector<double> sum(n,0.0);
  double b = 0.0;
  rep(i,n){
    sum[i] = (p[i]+1)/2 + b;
    b = sum[i];
  }

  double ans = sum[k-1];
  rep(i,n-k){
    ans = max(ans, sum[i+k]-sum[i]);
  }
  cout << fixed;
  cout << setprecision(10) << ans << endl;

  // rep(i,n){
  //   cout << sum[i] << endl;
  // }
  return 0;
}



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

using namespace std;

int main ()
{
  int a, b, c;
  cin >> a >> b >> c;
  for (int i = b; i <= c; i++)
    if (i % a == 0) {
      cout << "OK";
      return 0;
    }
  cout << "NG";
  
  return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int t = sc.nextInt();
		int ans = 0;
		for (int i = 1; a * i <= t + 0.5; i++) {
			ans += b;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
import java.util.*;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
	
		for(;;){
			String str = sc.nextLine();
			String[] data = str.split(" ");
			int num[] = new int[data.length];
			for(int i = 0; i < data.length; i++){
				num[i] = Integer.parseInt(data[i]);
			}

			int x = num[0];
			int y = num[1];

			if(x == 0 && y == 0){
				break;
			} else{
				if(x >= y) {
					System.out.println(y + " " + x);
				} else {
					System.out.println(x + " " + y);
				}
			}
		}
	}
}


Measured memory_bytes: 35152
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int x,y;

int main(){
	cin>>x>>y;
	cout<<(x>y?"safe":"unsafe")<<endl;
}

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

using namespace std;

const long long INF = (1ll << 61);

int main(){
  int D;
  cin >> D;
  
  int n = 26;
  
  vector<int> c(n);
  for(int i = 0; i < n; i++) cin >> c[i];
  
  vector<vector<int>> s(D, vector<int>(n));
  for(int d = 0; d < D; d++){
    for(int i = 0; i < n; i++){
      cin >> s[d][i];
    }
  }
  
  vector<int> t(D, 0);
  
  vector<int> last(n, -1);
  
  for(int d = 0; d < D; d++){
    long long satisfaction = 0;
    for(int i = 0; i < n; i++){
      satisfaction -= c[i] * (d - last[i]);
    }
    
    long long maximum = -INF;
    int contest = -1;
    for(int i = 0; i < n; i++){
      if(maximum <= satisfaction + s[d][i] + c[i] * (d - last[i])){
        maximum = satisfaction + s[d][i] + c[i] * (d - last[i]);
        contest = i;
      }
    }
    
    last[contest] = d;
    t[d] = contest + 1;
  }
  
  for(int d = 0; d < D; d++){
    printf("%d\n", t[d]);
  }
  
  return 0;
}

Measured memory_bytes: 3776
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, q, s, t, x, d;
vector<pair<pair<int, int>, pair<int, int> > > vec;
set<pair<pair<int, int>, pair<int, int> > > st1, st2, tmp;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> s >> t >> x;
		vec.pb(make_pair(make_pair(s - x, s), make_pair(t, x)));
	}
	sort(vec.begin(), vec.end());
	int cur = 0;
	while (q--) {
		cin >> d;
		tmp.clear();
		for (auto p : st2) {
			if (p.fi.fi <= d) tmp.insert(p);
			else break;
		}
		for (auto p : tmp) {
			//assert(st1.count(make_pair(make_pair(p.se, p.fi.se), p.fi.fi)) == 1);
			st1.erase(make_pair(make_pair(p.se.se, p.fi.se), p.se));
			st2.erase(p);
		}
		while (1) {
			if (cur >= n) break;
			if (vec[cur].fi.fi > d) break;
			if (vec[cur].se.fi - d > vec[cur].se.se) {
				st2.insert(make_pair(make_pair(vec[cur].se.fi - vec[cur].se.se, vec[cur].fi.se), vec[cur].se));
				st1.insert(make_pair(make_pair(vec[cur].se.se, vec[cur].fi.se), vec[cur].se));
			}
			cur++;
		}
		if (!st1.empty()) {
			auto p = st1.begin();
			cout << (*p).fi.fi << "\n";
		}
		else cout << "-1\n";
	}
	//system("pause");
	return 0;
}


Measured memory_bytes: 29420
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n, x, t; cin>>n>>x>>t;
    cout<<(n+x-1)/x*t<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <sstream>

#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>

#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

#include <chrono>
#include <random>

using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<i64>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<i64, i64>;

//////////////////////////////////////////////////

int main(){
    int n;
    cin >> n;
    vl a(n);
    for(auto&& x:a)cin >> x;
    i64 ret = 0;
    int nval = 0;
    vl b(n);
    for(int i=0;i<n;i++){
        b[i] = max(a[i], -a[i]);
        ret += b[i];
        if(a[i] < 0) nval++;
    }
    sort(b.begin(), b.end());
    cerr << nval << " " << ret << endl;
    if(nval & 1){
        cout << ret - 2 * b[0] << endl;
    }else{
        cout << ret << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
import sys
s=input()
N=len(s)
if s[-1]=='1':
    print(-1)
    sys.exit()
if s[0]=='0':
    print(-1)
    sys.exit()
t=s[:N-1]
t=t[::-1]
if s[:N-1]!=t:
    print(-1)
    sys.exit()
u=s[:N-1]
ans=[]
x=1
y=1
for i in range(N-1):
    if u[i]=='0':
        y+=1
        ans.append((x,y))
    else:
        y+=1
        ans.append((x,y))
        x=y
for x,y in ans:
    print(x,y)

Measured memory_bytes: 52000
package main

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

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m, c := getInt(), getInt(), getInt()

	b := make([]int, m)
	a := make([][]int, n)

	for i := range b {
		b[i] = getInt()
	}

	for i := range a {
		a[i] = make([]int, m)
		for j := 0; j < m; j++ {
			a[i][j] = getInt()
		}
	}

	ans := 0
	for i := 0; i < n; i++ {
		v := c
		for j := 0; j < m; j++ {
			v += a[i][j] * b[j]
		}
		if v > 0 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

namespace ProgramingStudying2
{
    class Program
    {

        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(long.Parse).ToArray();

            long Solve(long first)
            {
                long sum = first;
                long ans = 0;

                for(int i = 1; i < n; i++)
                {
                    if (sum > 0)
                    {
                        sum += a[i];
                        if (sum >= 0)
                        {
                            ans += sum + 1;
                            sum = -1;
                        }
                    }

                    else if(sum < 0)
                    {
                        sum += a[i];
                        if (sum <= 0)
                        {
                            ans += -sum + 1;
                            sum = 1;
                        }
                    }
                }
                return ans;
            }

            if(a[0] > 0)
            {
                Console.WriteLine(Math.Min(Solve(a[0]), Solve(-1) + a[0] + 1)); 
            }
            else if(a[0] < 0)
            {
                Console.WriteLine(Math.Min(Solve(a[0]), Solve(1) - a[0] + 1));
            }
            else
            {
                Console.WriteLine(Math.Min(Solve(1) + 1, Solve(-1) + 1));
            }
        }
    }
}


Measured memory_bytes: 39172
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE OverloadedStrings #-} 
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as TIO
import Data.Monoid
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU


main = do
  input <- TIO.getContents
  let ls = T.lines input 
      n = ls !! 0
      l :: VU.Vector Int
      l =  VU.convert $ fmap ( read .T.unpack) $  V.fromList $ T.words $ ls !! 1      
      (!s0,!s2,!s4) = VU.foldl f (0,0,0) l
        where f  (s0,s2,s4) a  | (a `mod` 4) == 0 = (s0, s2, s4 + 1)
                               | (a `mod` 2 ) == 0 =  (s0, s2 + 1, s4)
                               | otherwise =  (s0 + 1, s2 , s4)
      getR (s0,s2,s4) | (s0<=s4) || ( s0 == s4+1 && s2 == 0 ) = "Yes"  
                      | otherwise = "No"
  Prelude.putStr $  getR (s0,s2,s4)
  
  --TIO.putStr $ h `cons`  len `snoc`  l 


Measured memory_bytes: 7932
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d;
  if(a > b){
    e = b;
  }
  else{
    e = a;
  }
  if(c > d){
    f = d;
  }
  else{
    f = c;
  }
  
  cout << e + f << "\n";
}
    
  

Measured memory_bytes: 3544
#include <math.h>
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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

  int N; cin>>N;
  vi A(N-1),B(N-1);
  REP(i,N-1) {
    cin>>A[i]>>B[i];
    A[i]--;B[i]--;
  }

  vvi eg(N);
  map<pii, int> col;
  vector<pii> vec;
  REP(i,N-1) {
    eg[A[i]].push_back(B[i]);
    eg[B[i]].push_back(A[i]);
    col[pii(A[i],B[i])] = -1;
    col[pii(B[i],A[i])] = -1;
    vec.push_back(pii(A[i],B[i]));
  }

  queue<int> que;
  que.push(0);
  int colMax = 0;
  vb vis(N, false);
  while(!que.empty()) {
    int x = que.front(); que.pop();
    vis[x] = true;

    // 移動してきた辺の色を調べる
    int pcl=-1;
    for(int nx : eg[x]) {
      if (vis[nx]) pcl = col[pii(x,nx)];
    }

    // 各辺に色を割り当てる
    int cl = 1;
    for(int nx : eg[x]) {
      if (vis[nx]) continue; 
      
      if (cl == pcl) cl++;

      col[pii(x,nx)] = cl;
      col[pii(nx,x)] = cl;
      colMax = max(colMax, cl);
      cl++;
      que.push(nx);
    }
  }

  cout << colMax << endl;  
  for(pii v : vec) cout << col[v] << endl;

  return 0;
}


Measured memory_bytes: 20212
N = int(input())
A = list(map(int, input().split()))
d = dict()
total = sum(A)
for a in A:
    d[a] = d.get(a, 0) + 1
Q = int(input())
res = [-1] * Q
for i in range(Q):
    b, c = map(int, input().split())
    cnt = d.get(b, 0)
    total -= (b - c) * cnt
    d[c] = d.get(c, 0) + cnt
    d[b] = 0
    res[i] = total
print(*res, sep='\n')

Measured memory_bytes: 25988
a, b = input().split()

if a == 'A' :
    a = 11
elif a == 'B' :
    a = 12
elif a == 'C' :
    a = 13
elif a == 'D' :
    a = 14
elif a == 'E' :
    a = 15
elif a == 'F' :
    a = 16

if b == 'A' :
    b = 11
elif b == 'B' :
    b = 12
elif b == 'C' :
    b = 13
elif b == 'D' :
    b = 14
elif b == 'E' :
    b = 15
elif b == 'F' :
    b = 16

if a > b :
    print('>')
elif a < b :
    print('<')
else:
    print('=')

Measured memory_bytes: 3064
program main
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,i,j,ans=0
    integer(int32), allocatable:: a(:), b(:), c(:),d(:)
    logical,allocatable:: used(:)

    read*, n
    allocate(a(n),b(n),c(n),d(n))
    allocate(used(n),source=.false.)

    do i=1,n
        read*, a(i), b(i)
    end do
    do i=1,n
        read*, c(i),d(i)
    end do

    call double_sort(c,d,1,n)
    c(:) = c(n:1:-1)
    d(:) = d(n:1:-1)
    call double_sort(b,a,1,n)


    do i=1,n
        do j=1,n
            if (c(i) > a(j) .and. d(i) > b(j)) then
                if (.not.(used(j))) then
                    used(j) = .true.
                    ans=ans+1
                    exit
                end if
            end if
        end do
    end do
    print'(i0)', ans

    contains
    recursive subroutine double_sort(ar1, ar2, fst, lst)
        integer(4),intent(inout):: ar1(:),ar2(:)
        integer(4),intent(in):: fst,lst
        integer(4):: mdl

        if (lst - fst < 2) then
            if (ar1(fst) < ar1(lst)) then
                call swap(ar1(fst), ar1(lst))
                call swap(ar2(fst), ar2(lst))
            end if
            return
        end if

        mdl = (fst+lst)/2

        call double_sort(ar1,ar2,fst,mdl)
        call double_sort(ar1,ar2,mdl+1,lst)
        call double_merge_(ar1,ar2,fst,mdl,lst)
    end subroutine


    subroutine double_merge_(ar1,ar2,fst,mdl,lst)
        integer(4),intent(inout):: ar1(:),ar2(:)
        integer(4),intent(in):: fst,mdl,lst
        integer(4),allocatable:: t1(:),t2(:)
        integer(4):: li,ri,ti

        allocate(t1(lst-fst+1), t2(lst-fst+1))

        li=fst
        ri=mdl+1
        ti=1

        do while(li <= mdl .and. ri <= lst)
            if (ar1(li) >= ar1(ri)) then
                t1(ti) = ar1(li) 
                t2(ti) = ar2(li)
                li=li+1
            else
                t1(ti) = ar1(ri)
                t2(ti) = ar2(ri)
                ri=ri+1
            end if
            ti=ti+1
        end do

        if (li <= mdl) then
            t1(ti:) = ar1(li:mdl)
            t2(ti:) = ar2(li:mdl)
        else
            t1(ti:) = ar1(ri:lst)
            t2(ti:) = ar2(ri:lst)
        end if

        ar1(fst:lst) = t1(:)
        ar2(fst:lst) = t2(:)

        deallocate(t1,t2)
    end subroutine

    
    subroutine swap(x,y)
        integer(4),intent(inout):: x,y
        integer(4):: tmp
        tmp = x
        x = y
        y = tmp
    end subroutine

    

end program main

Measured memory_bytes: 2864
import bisect
n, q = map(int, input().split())
S = list(input())
X = []
for i in range(n-1):
    if S[i] == 'A' and S[i+1] == 'C':
        X.append(i)
for j in range(q):
    l, r = map(int, input().split())
    a = bisect.bisect_left(X, l-1)
    b = bisect.bisect_left(X, r-1)
    print(b-a)


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

int main()
{
	int n;
	int ans=0;
	
	cin >> n;
	
	while(n)
	{
		int tmp=n%10;
		if(tmp==2)ans++;
		n/=10;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define mp make_pair
#define ll long long
using namespace std;
const int N=2e5+5;
int n,o;
int p[N],f[N];
ll ans;
struct P{
	int x0,x1;
	bool operator<(const P &a)const{
		return x1?(a.x1?(ll)x0*a.x1<(ll)x1*a.x0:1):0;
	}
}a[N];
set<pair<P,int>>A;
int F(int x){return x==f[x]?x:f[x]=F(f[x]);}
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	fo(i,2,n)cin>>p[i];
	fo(i,1,n)cin>>o,o?a[i].x1=1:a[i].x0=1,f[i]=i;
	fo(i,2,n)A.insert(mp(a[i],i));
	for(;!A.empty();){
		auto x=*A.rbegin();
		A.erase(x);
		int y=x.second,fa=F(p[y]);
		f[y]=fa;
		ans+=(ll)a[fa].x1*a[y].x0;
		if(fa!=1)A.erase(mp(a[fa],fa));
		a[fa].x0+=a[y].x0;
		a[fa].x1+=a[y].x1;
		if(fa!=1)A.insert(mp(a[fa],fa));
	}
	cout<<ans;
}

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

int main(){
  int N;
  int all = 0;
  int l[1100], r[1100];
  cin >> N;
  for(int i = 0; i < N; ++i){
    cin >> l[i] >> r[i];
    all += r[i] - l[i] + 1;
  }
  cout << all << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int A, B; cin >> A >> B;
  int C, D; cin >> C >> D;
  auto takahasi = (C + B - 1) / B;
  auto aoki = (A + D - 1) / D;
  auto ans = takahasi <= aoki;
  cout << (ans ? "Yes" : "No") << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.Integer.parseInt;

/**
 * Problem B: Prime Gap
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		boolean[] ps = new boolean[1299709 + 1];

		Arrays.fill(ps, 2, ps.length, true);

		for (int i = 2; i <= Math.sqrt(ps.length); i++) {
			if (ps[i]) {
				for (int j = i * 2; j < ps.length; j += i) {
					if (ps[j]) ps[j] = false;
				}
			}
		}

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int k = parseInt(line);
			if (k == 0) break;

			int from = 0, to = 0;
			if (!ps[k]) {
				// from
				for (int i = k; ; i--) {
					if (ps[i]) {
						from = i;
						break;
					}
				}
				// to
				for (int i = k; ; i++) {
					if (ps[i]) {
						to = i;
						break;
					}
				}
			}
			System.out.println(to - from);

		} //end while
	} //end main
}

Measured memory_bytes: 27192
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
 
struct Point{
    double x,y,z;
    Point(double x, double y, double z):x(x), y(y), z(z){}
    Point(){}
    Point &operator +=(const Point &a){ x+=a.x; y+=a.y; z+=a.z; return *this; }
    Point &operator -=(const Point &a){ x-=a.x; y-=a.y; z-=a.z; return *this; }
    Point &operator *=(const double &a){ x*=a; y*=a; z*=a; return *this; }
    Point operator +(const Point &a) const{ return Point(x+a.x, y+a.y, z+a.z); }
    Point operator -(const Point &a) const{ return Point(x-a.x, y-a.y, z-a.z); }
    Point operator *(const double &a) const{ return Point(a*x, a*y, a*z); }
};
struct Obj{
    Point p;
    double r;
    Obj(Point &p, double r):p(p), r(r){}
    Obj(){}
};
 
double dot(const Point &a, const Point &b){
    return a.x*b.x +a.y*b.y +a.z*b.z;
}
Point cross(const Point &a, const Point &b){
    return Point(a.y*b.z -a.z*b.y, a.z*b.x -a.x*b.z, a.x*b.y -a.y*b.x);

}
double Length(const Point &a){
    return sqrt(dot(a, a));
}
 
int main(){
    int x,y,z;
    cin >> x >> y >> z;
    Point s(x,y,z);
    cin >> x >> y >> z;
    Point t(x,y,z);
    vector<Point> tri(3);
    for(int i=0; i<3; i++){
        cin >> x >> y >> z;
        tri[i] = Point(x,y,z);
    }

    Point n = cross(tri[1]-tri[0], tri[2]-tri[0]);
    n *= 1/Length(n);
    bool shut = false;
    if(abs(dot(n, t-s)) > EPS){
        double A = dot(s-tri[0], n);
        double B = dot(t-tri[0], n);
        if(A*B < EPS){
            Point m = s + (t-s)*(abs(A)/(abs(A)+abs(B)));
            double area = Length(cross(tri[1]-tri[0], tri[2]-tri[0]));
            double area2 = 0;
            for(int i=0; i<3; i++){
                area2 += Length(cross(tri[i]-m, tri[(i+1)%3]-m));
            }
            if(abs(area -area2) < EPS){
                shut = true;
            }
        }
    }
    if(shut){
        cout << "MISS" << endl;
    }else{
        cout << "HIT" << endl;
    }
    return 0;
}


Measured memory_bytes: 3156
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef istringstream ISS;
typedef ostringstream OSS;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define FOR( v, c ) for ( auto &v : c )
#define EACH( it, c ) for ( auto it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define DRANGE( c, p ) (c).begin(), (c).begin() + p, (c).end()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

#include <complex>
typedef complex<double> Point;
const double EPS = 1e-8;

// 入力ストリームから実数二つをとって Point へ
istream& operator >> ( istream &s, Point &a )
{
	double r, i;
	s >> r >> i;
	a = Point( r, i );
	return s;
}

// 単位ベクトル
Point unitVector( const Point &a )
{
	return a / abs( a );
}

// 法線ベクトル
Point normalVector1( const Point &a )
{
	return a * Point( 0, 1 );
}
Point normalVector2( const Point &a )
{
	return a * Point( 0, -1 );
}
Point ( *normalVectors[] )( const Point& ) = { normalVector1, normalVector2 };

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

	for ( int n; cin >> n, n; )
	{
		vector<Point> ps( n );
		REP( i, 0, n )
		{
			cin >> ps[i];
		}

		int res = 1;
		REP( i, 0, n )
		{
			REP( j, 0, i )
			{
				const Point &a = ps[i], &b = ps[j];
				if ( 2 + EPS < abs( a - b ) )
				{
					continue;
				}
				REP( k, 0, 2 )
				{
					const Point c = ( a + b ) / Point( 2, 0 ) + unitVector( normalVectors[k]( a - b ) ) * sqrt( 1 - pow( abs( a - b ) / 2., 2. ) );
					int tmp = 2;
					REP( l, 0, n )
					{
						if ( l == i || l == j )
						{
							continue;
						}
						tmp += abs( c - ps[l] ) <= 1. + EPS;
					}
					res = max( res, tmp );
				}
			}
		}
		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define sort(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())

using namespace std;

int main() {
	int n;
	int inf = 1000000007;
	cin >> n;
	vector<i64> data(n);
	ff(i, 0, n) {//input A_n
		cin >> data.at(i);
	}
	i64 ans = 0;
	ff(i, 0, 60) {//for each bit
		i64 z = 1;
		ff(j, 0, i) {
			z *= 2;
			z %= inf;
		}
		i64 x, y;
		x = 0;//num of 1
		y = n;//num of 0
		ff(j, 0, n) {
			bitset<60> k(data.at(j));
			if (k.test(i)) {
				x++;
				y--;
			}
		}
		z %= inf;
		i64 a = z * x;
		a %= inf;
		a *= y;
		a %= inf;
		ans += a;
		ans %= inf;
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

int f(int n)
{
  if(n%2) return 3*n+1;
  else return n/2;
}

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

  int ans = 1;
  map<int, int> m;
  while(m[s] == 0){
    m[s]++;
    s = f(s);
    ans++; 
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a, b, c, d;
	int t;

	scanf("%d %d %d %d", &a, &b, &c, &d);

	if(a <= c && b <= d){
		t = b - c;
	}else if(a <= c && b >= d){
		t = d - c;
	}else if(a >= c && b <= d){
		t = b - a;
	}else if(a >= c && b >= d){
		t = d - a;
	}
	
	if(t < 0){
		printf("0");
	}else{
		printf("%d", t);
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,a[222222];
int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++){
		scanf("%d",&a[i]);
		a[i] -= i;
	}
	sort(a+1,a+n+1);
	long long int res = 0;
	int x = a[(n+1)/2];
	for(int i=1; i<=n; i++)
		res += labs(a[i] - x);
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1024
n, m, q = map(int, input().split())

t = []
for _ in range(q):
   a, b, c, d = map(int, input().split())
   t.append([a-1, b-1, c, d])

#t = sorted(t, key=lambda x:x[1])

tmp = [i for i in range(1, m+1)]

from itertools import combinations_with_replacement

ans = 0
for v in combinations_with_replacement(tmp, n):
   A = list(v)
   score = 0
   for i in range(q):
      a, b, c, d = t[i]
      if A[b] - A[a] == c:
         score += d
   ans = max(ans, score)

print(ans)


Measured memory_bytes: 9212