akhauriyash/Code-Regression huggingface dataset:
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<stdio.h>
using namespace std;
namespace MCF {
	// required <string.h> <vector> <queue> <algorithm>
	#define MAXN 500
	#define MAXM 10000
	#define wint int
	#define cint long long
	const wint wEPS = 0;
	const wint wINF = 1001001001;
	const cint cEPS = 0;
	const cint cINF = 1001001001001001LL;
	int n, m, ptr[MAXN], next[MAXM], zu[MAXM];
	wint capa[MAXM], tof;
	cint cost[MAXM], toc, d[MAXN], pot[MAXN];
	int vis[MAXN], pree[MAXN];
	void init(int _n) {
		n = _n; m = 0; memset(ptr, ~0, n * 4);
	}
	void ae(int u, int v, wint w, cint c) {
		next[m] = ptr[u]; ptr[u] = m; zu[m] = v; capa[m] = w; cost[m] = +c; ++m;
		next[m] = ptr[v]; ptr[v] = m; zu[m] = u; capa[m] = 0; cost[m] = -c; ++m;
	}
	bool solve(int src, int ink, wint flo = wINF) {
		int i, u, v;
		wint f;
		cint c, cc;
		memset(pot, 0, n * sizeof(cint));
		//*
		for (bool cont = 1; cont; ) {
			cont = 0;
			for (u = 0; u < n; ++u) for (i = ptr[u]; ~i; i = next[i]) if (capa[i] > wEPS) {
				if (pot[zu[i]] > pot[u] + cost[i] + cEPS) {
					pot[zu[i]] = pot[u] + cost[i]; cont = 1;
				}
			}
		}
		//*/
		for (toc = 0, tof = 0; tof + wEPS < flo; ) {
			typedef pair<cint,int> node;
			priority_queue< node,vector<node>,greater<node> > q;
			for (u = 0; u < n; ++u) { d[u] = cINF; vis[u] = 0; }
			for (q.push(make_pair(d[src] = 0, src)); !q.empty(); ) {
				c = q.top().first; u = q.top().second; q.pop();
				if (vis[u]++) continue;
				for (i = ptr[u]; ~i; i = next[i]) if (capa[i] > wEPS) {
					cc = c + cost[i] + pot[u] - pot[v = zu[i]];
					if (d[v] > cc + cEPS) { q.push(make_pair(d[v] = cc, v)); pree[v] = i; }
				}
			}
			if (!vis[ink]) return 0;
			f = flo - tof;
			for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v]; f=min(f,capa[i]); }
			for (v = ink; v != src; v = zu[i ^ 1]) { i = pree[v]; capa[i] -= f; capa[i ^ 1] += f; }
			tof += f;
			toc += f * (d[ink] - pot[src] + pot[ink]);
			for (u = 0; u < n; ++u) pot[u] += d[u];
		}
		return 1;
	}
}
int G[110][110];
int inf=99999999;
vector<pair<int,int> >g[110];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)for(int j=0;j<a;j++){
		if(i!=j)G[i][j]=999999999;
	}
	for(int i=0;i<b;i++){
		int p,q,r;
		scanf("%d%d%d",&p,&q,&r);
		g[p].push_back(make_pair(q,r));
		G[p][q]=-r;
	}
	for(int k=0;k<a;k++)for(int i=0;i<a;i++)for(int j=0;j<a;j++)
		G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
	MCF::init(a+2);
	int s=a;
	int t=a+1;
	MCF::ae(s,a-1,inf,-G[0][a-1]);
	MCF::ae(0,t,inf,0);
	for(int i=0;i<a;i++){
		for(int j=0;j<g[i].size();j++){
			MCF::ae(g[i][j].first,i,inf,-g[i][j].second);
			MCF::ae(g[i][j].first,i,1,-g[i][j].second-100000000);
		}
	}
	MCF::solve(s,t,100000);
//	printf("%lld\n",MCF::toc);
	printf("%d\n",(MCF::toc+(long long)b*100000000)%100000000);
}

Measured memory_bytes: 1244
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		double C = Math.toRadians(scan.nextDouble());
		double S = a * b * Math.sin(C) / 2;
		double c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2  * a * b * Math.cos(C));
		double h = b * Math.sin(C);
		double L = a + b + c;
		String line_sep = System.getProperty("line.separator");
		System.out.println(S + line_sep + L + line_sep + h);
	}
}

Measured memory_bytes: 27984
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;

int main(){
	
	int x, y, ans=MOD;
	cin >> x >> y;
	
	if(y+x+1>0){
		ans=y+x+1;
	}
	if(y-x>0){
		ans=min(ans, y-x);
	}
	if(-y-x+1>0){
		ans=min(ans, -y-x+1);
	}
	if(-y+x+2>0){
		ans=min(ans, -y+x+2);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) std::cerr<<"L: "<<__LINE__<<" f("<<__FUNCTION__<<") Var: "<<#x<<" Val: "<<x<<"\n";
typedef long long ll;
const int inf = 0x7f7f7f7f;

inline void gettime() {
	debug(clock());
}
inline int read() {
	static char c;
	static int x;
	while (c = getchar(), !isdigit(c));
	x = c - '0';
	while (c = getchar(), isdigit(c))
		x = (x << 1) + (x << 3) + c - '0';
	return x;
}
inline char achar() {
	static char c;
	while (c = getchar(), !isalpha(c));
	return c;
}

int n;
int ns[200100];

int main() {
#ifndef ONLINE_JUDGE
	std::atexit(gettime);
#endif

	n = read();
	for (int i = 1; i <= n; ++i)
		ns[i] = read() - i;
	std::sort(ns + 1, ns + 1 + n);
	int k = ns[(1 + n) / 2];
	ll ans = 0;
	for (int i = 1; i <= n; ++i)
		ans += std::abs(ns[i] - k);
	printf("%lld\n", ans);
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	a-=b;
	printf("%d\n",a-a/c*c);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define gc getchar()
#define debug(x) cerr<<#x<<"="<<x
#define sp <<" "
#define ln <<endl
#define lint long long
#define db double
#define N 300010
#define mod 998244353
using namespace std;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
int fac[N],facinv[N];
inline int C(int n,lint m)
{
	return (lint)fac[n]*facinv[m]%mod*facinv[n-m]%mod;
}
inline int fast_pow(int x,int k,int ans=1)
{	for(;k;k>>=1,x=(lint)x*x%mod) (k&1)?ans=(lint)ans*x%mod:0;return ans;	}
int main()
{
	int n=inn(),A=inn(),B=inn(),ans=0;lint k;scanf("%lld",&k);
	for(int i=fac[0]=1;i<=n;i++) fac[i]=(lint)fac[i-1]*i%mod;
	facinv[n]=fast_pow(fac[n],mod-2);
	for(int i=n-1;i>=0;i--) facinv[i]=facinv[i+1]*(i+1ll)%mod;
	for(int x=0;x<=n;x++)
		if((k-A*x)%B==0&&k-A*x>=0&&(k-A*x)/B<=n)
			(ans+=(lint)C(n,x)*C(n,(k-A*x)/B)%mod)%=mod;
	return !printf("%d\n",ans);
}

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

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

  int a[1000000];
  int i = 1;
  a[0] = s;

  while(i < 1000000){
    if(a[i - 1] % 2 == 0){
      a[i] = a[i - 1] / 2;
    }
    else{
      a[i] = 3 * a[i - 1] + 1;
    }
    i++;
  }

  int j = 2;

  while(j != -1){
    for(int k = j - 1; k >= 0; k--){
      if(a[j] == a[k]){
	cout << j+1 << endl;
	j = -1;
	break;
      }
      else if(k == 0){
	j++;
      }
    }
  }

  return 0;
}


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

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int INF = int (1e9) + int (1e5);
const ll INFL = ll(2e18) + ll(1e10);
const ui MOD = 1E9 + 7;
const double EPS = 1e-9;
#define FOR(i,n) for (int i=0;i<(n);i++)
#define FOR2(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
#define MP make_pair
#define FAST ios_base::sync_with_stdio(false); cin.tie(0)

template<class T,class U>
ostream &operator<<(ostream &os,const pair<T,U> &x) {
    return os<<"("<<x.first<<","<<x.second<<")";
}

template<class T>
ostream &operator<<(ostream &os,const vector<T> &x) {
    os << '[';
    if ( !x.empty() ) {
        std::copy (x.begin(), x.end(), std::ostream_iterator<T>(os, ","));
        os << "\b";
    }
    os << "]";
    return os;
}
template<class T>
ostream &operator<<(ostream &os,const vector<vector<T> > &x) {
    os << '[';
    if ( !x.empty() ) {
        for (auto v: x) os << v << ",";
        os << "\b";
    } else os << "[]";
    os << "]";
    return os;
}


int main() {
 //   freopen("in.txt","r",stdin);
    string s;
    int k;
    cin >> s>>k;
    int n=s.size();
    set<string> ret;
    for (int i=0;i<n;i++){
        string ss="";
        for (int j=i;j<n;j++){
            ss += s[j];
            if (ret.size()<k)
                ret.insert(ss);
            else if (ss>=*(ret.rbegin())) break;
            else if (ret.count(ss)==0){
                ret.erase(*(ret.rbegin()));
                ret.insert(ss);
            }
        }
    }
    cout << *(ret.rbegin());

    return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    N = int(input())
    values = sorted([int(n) for n in input().split()], reverse=True)
    ret = 0
    while len(values) > 1:
        tmp = (values[-1] + values[-2]) / 2
        del values[-1]
        values[-1] = tmp
    print(values[0])

Measured memory_bytes: 3060
# https://atcoder.jp/contests/abc131/tasks/abc131_c

a, b, c, d  = gets.split.map(&:to_i)
am1 = a - 1

lcm = c.lcm(d)
puts b - a + 1 - ((b / c - am1 / c) + ( b / d - am1 / d) - (b / lcm - (am1 / lcm )) )


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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x));
#define umin(m, x) (m = min(m, x));

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

using ll = long long int;

using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;

using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;

inline void yn(bool f) { cout << (f ? "Yes" : "No") << endl; }


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

    cout << r * 2 * 3.141592 << endl;

    return 0;
}


Measured memory_bytes: 3804
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    sheets = list(map(string_to_int, inputs))
    count = 0
    for s in sheets:
        count += s[1] - s[0] + 1
    return count


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)


Measured memory_bytes: 41452
from collections import Counter
import sys
sys.setrecursionlimit(10 ** 6)


def factorization(n):
    arr = Counter()
    temp = n
    for i in range(2, int(-(-n**0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt

    if temp != 1:
        arr[temp] = 1

    if len(arr.keys()) == 0 and n != 1:
        arr[n] = 1

    return arr


def dfs(i, x):
    global N, M, ans
    if i == len(primeKeys):
        if M // x >= N:
            ans = max(ans, x)
    else:
        for j in range(primes[primeKeys[i]] + 1):
            nx = x * (primeKeys[i] ** j)
            if M // nx >= N:
                dfs(i + 1, nx)
            else:
                break


N, M = map(int, input().split())
primes = factorization(M)
# primeList = list(primes.elements())
primeKeys = list(primes.keys())

ans = 1
dfs(0, 1)

print(ans)


Measured memory_bytes: 3444
package main

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

var (
	BufferSize = 10 * 10 * 10 * 10 * 10 * 10 * 10
)

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}

	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}

	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	n := scanInt(sc)
	d := scanInt(sc)

	table := make([][]int, n, n)

	for i := 0; i < n; i++ {
		table[i] = make([]int, d, d)
		for j := 0; j < d; j++ {
			table[i][j] = scanInt(sc)
		}
	}

	ok := 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			sqSum := 0.0
			for k := 0; k < d; k++ {
				sqSum += math.Pow(float64(table[i][k]-table[j][k]), 2)
			}
			sum := math.Sqrt(sqSum)
			trunc := math.Trunc(sum)
			if sum == trunc {
				ok++
			}
		}
	}
	fmt.Printf("%d\n", ok)
}


Measured memory_bytes: 2944
#include <stdio.h>
int main() {
	char c;
	char v[] = "aiueo";
	scanf("%c", &c);
	for (int i = 0; i < 5; i++) {
		if (c == v[i]) {
			printf("vowel\n");
			return 0;
		}
	}
	printf("consonant\n");
	return 0;
}

Measured memory_bytes: 128
fn main() {
    let d: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };
    let c: Vec<i64> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        iter.map(|x| x.parse().unwrap()).collect()
    };
    let mut s: Vec<Vec<i64>> = Vec::with_capacity(d);
    for _ in 0..d {
        let a: Vec<i64> = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            let iter = buf.split_whitespace();
            iter.map(|x| x.parse().unwrap()).collect()
        };
        s.push(a);
    }
    let s = s;

    let mut ans: i64 = 0;
    let mut last: Vec<usize> = vec![0; 26];
    for i in 1..=d {
        let t: usize = {
            let mut buf = String::new();
            std::io::stdin().read_line(&mut buf).unwrap();
            buf.trim_end().parse::<usize>().unwrap() - 1
        };
        ans += s[i - 1][t];
        last[t] = i;
        for j in 0..26 {
            ans -= c[j] * ((i - last[j]) as i64);
        }
        println!("{}", ans);
    }
}

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

#define ll long long
#define mx 200005
int n,m;
int ar[mx];
ll dp[mx],dp1[mx];
bool visit[mx][3];



int main()
{
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        scanf("%d",&ar[i]);
    }
    ll re;
    if(n%2==0)
    {
        re=-1e18;
        for(int i=0; i<n/2; i++)
        {
            dp[i+1]=dp[i]+ar[i*2];
            dp1[i+1]=dp1[i]+ar[i*2+1];
        }
        for(int i=0; i<=n/2; i++)
        {
            re=max(re,dp[i]+(dp1[n/2]-dp1[i]));
        }
    }
    else
    {
        ll sum=ar[0];
        for(int i=1; i<=n/2; i++)
        {
            dp[i]=ar[i*2]+max(dp[i-1],dp1[i-1]);
            dp1[i]=max(sum,ar[i*2-1]+dp1[i-1]);
            sum+=ar[2*i];
        }
        re=max(dp[n/2],dp1[n/2]);
    }
    printf("%lld\n",re);
    return 0;

}


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

x = []
for i in range(m):
    a,b = list(map(int,input().split()))
    x.append([a-1,b-1])


a = [1 for i in range(n)]
b = [0 for i in range(n)]
b[0] = 1
for i in x:
    a[i[0]] -= 1
    a[i[1]] += 1
    if b[i[0]] == 1:
        b[i[1]] = 1
    if a[i[0]] == 0:
        b[i[0]] = 0
print(sum(b))

Measured memory_bytes: 21668
int b[5];main(i,s){for(s=i=0;i-5&&scanf("%d",b+i);s|=1<<--b[i++]);if(i=*b<0)return 0;for(;printf("%d\n",s-1&&s-2&&s-4&&s-7?b[i]-(s-5?s-6?0:1:2)?2:1:3)&&++i-5;);main();}

Measured memory_bytes: 600
#include <cstdio>
#include <vector>
#include <algorithm>

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

using namespace std;

int main()
{
    int no_of_sticks, snake_sticks;
    scanf("%d %d", &no_of_sticks, &snake_sticks);

    vector <int> stick_length(no_of_sticks);
    for(int i = 0; i < no_of_sticks; i++)
    {
        scanf("%d", &stick_length[i]);
    }

    sort(all(stick_length));
    reverse(all(stick_length));

    int max_length = 0;
    for(int i = 0; i < snake_sticks; i++)
        max_length += stick_length[i];


    printf("%d\n", max_length);
    return 0;
}


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

using namespace std;
map<vector<int>, int> m;

void bfs(){
    vector<int> v, prev;
    queue<vector<int> > que;
    for(int i=0;i<8;i++)v.push_back(i);
    m[v] = 1;
    que.push(v);
    while(que.size()){
        int zero_idx;
        vector<int> prev=que.front();que.pop();
        for(int i=0;i<8;i++)if(prev[i]==0)zero_idx=i;
        for(int i=0;i<8;i++)v[i] = prev[i];
        swap(v[zero_idx], v[(zero_idx+4)%8]);
        if(m[v]==0){
            m[v]=m[prev]+1;
            que.push(v);
        }
        swap(v[zero_idx], v[(zero_idx+4)%8]);
        if(zero_idx%4!=0){
            swap(v[zero_idx], v[zero_idx-1]);
            if(m[v]==0){
                m[v]=m[prev]+1;
                que.push(v);
            }
            swap(v[zero_idx], v[zero_idx-1]);
        }
        if(zero_idx%4!=3){
            swap(v[zero_idx], v[zero_idx+1]);
            if(m[v]==0){
                m[v]=m[prev]+1;
                que.push(v);
            }
            swap(v[zero_idx], v[zero_idx+1]);
        }
    }
}

int main(){
    bfs();
    int a;
    vector<int> v;
    while(cin >> a){
        v.clear();
        v.push_back(a);
        for(int i=1;i<8;i++){
            cin >> a;
            v.push_back(a);
        }
        cout << m[v]-1 << endl;
    }
}



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

typedef vector<int> V;

typedef struct{
  int t,n,m,s;
} Record;

int main(){
  int n,m,r,q;
  
  while(cin >> n >> m ,n + m){
    const int MAX = 1260-540;

    cin >> r;
    Record d[r];
    vector<V> v(m,V(MAX+1,-1)),cnt(m,V(MAX+1,0));
    int use[1001] = {0};

    for(int i = 0 ; i < r ; i++){
      cin >> d[i].t >> d[i].n >> d[i].m >> d[i].s;
      if(d[i].s){
	use[d[i].n-1] = d[i].t;
      }
      else{
	for(int j = use[d[i].n-1] ; j < d[i].t ; j++){
	  cnt[d[i].m-1][j-540] = 1;
	}

      }
    }

    int ts,tt,sn;
    cin >> q;
    for(int i = 0 ; i < q ; i++){
      cin >> ts >> tt >> sn;

      sn--;
      bool flg = true;
      int ans = 0;
      for(int i = ts ; i < tt ; i++){
	if(cnt[sn][i-540] != 0){
	  ans++;
	}
      } 
      cout << ans << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 56300
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    
        var sc = new Scanner(System.in);
        
        int x = Integer.parseInt(sc.next());
        if(x == 0){
            System.out.println(1);
        }else{
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 35704
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long m = sc.nextLong();
        
        long count = 0;
        
        if (n * 2 == m) {
            count = n;
        } else if (n * 2 < m) {
            count = (n + m / 2) / 2;
        } else {
            count = m / 2;
        }
        
        System.out.println(count);
    }
}


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

namespace _0034_Railway_Lines
{
    class Program
    {
        static void Main(string[] args)
        {
            string str;
            while ((str = Console.ReadLine()) != null)
            {
                double[] num = str.Split(',').Select(double.Parse).ToArray();
                double[] distance = new double[10];
                double[] velocity = new double[2];
                double allLength = 0;
                double nowLength = 0;

                for (int i = 0; i < 10; i++)
                {
                    distance[i] = num[i];
                    allLength += distance[i];
                }

                velocity[0] = num[10];
                velocity[1] = num[11];

                double time = allLength / (velocity[0] + velocity[1]);
                double PassLength = velocity[0] * time;

                for (int i = 0; i < 10; i++)
                {
                    nowLength += distance[i];
                    if (nowLength >= PassLength)
                    {
                        Console.WriteLine(i + 1);
                        break;
                    }
                }
            }

        }
    }
}



Measured memory_bytes: 14304
# input
L = [int(x) for x in list(input())]
ans = 0

if L[0] + L[1] + L[2] + L[3] == 7:
    print("%d+%d+%d+%d=7" % (L[0], L[1], L[2], L[3]))
else:
    if L[0] - L[1] + L[2] + L[3] == 7:
        print("%d-%d+%d+%d=7" % (L[0], L[1], L[2], L[3]))
    else:
        if L[0] + L[1] - L[2] + L[3] == 7:
            print("%d+%d-%d+%d=7" % (L[0], L[1], L[2], L[3]))
        else:
            if L[0] + L[1] + L[2] - L[3] == 7:
                print("%d+%d+%d-%d=7" % (L[0], L[1], L[2], L[3]))
            else:
                if L[0] - L[1] - L[2] + L[3] == 7:
                    print("%d-%d-%d+%d=7" % (L[0], L[1], L[2], L[3]))
                else:
                    if L[0] - L[1] + L[2] - L[3] == 7:
                        print("%d-%d+%d-%d=7" % (L[0], L[1], L[2], L[3]))
                    else:
                        if L[0] + L[1] - L[2] - L[3] == 7:
                            print("%d+%d-%d-%d=7" % (L[0], L[1], L[2], L[3]))
                        else:
                            if L[0] - L[1] - L[2] - L[3] == 7:
                                print("%d-%d-%d-%d=7" % (L[0], L[1], L[2], L[3]))



Measured memory_bytes: 3064
import java.util.Scanner;

public class Main
{

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

        int a = scan.nextInt();
        int b = scan.nextInt(); 

        System.out.print(a * b + " ");
        System.out.println((a + a)+(b + b));
    }
}



Measured memory_bytes: 26100
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
typedef long long ll;
using namespace std;

long double ave(long double a){
    return (a+1) / 2;
}

int main()
{
    cout << fixed << setprecision(10);//小数点以下10桁出力
    int n,k;
    cin >> n >> k;
    vector<long double> p(n);
    rep(i,n){
        int in;
        cin >> in;
        p.at(i) = in;
    }
    vector<long double> sum(n + 1,0);
    for(int i = 1;i <= n;i++){
        sum.at(i) = ave(p.at(i - 1)) + sum.at(i - 1);
    }
    long double max = 0;
    for(int i = k;i <= n;i++){
        if(max < sum.at(i) - sum.at(i - k)){
            max = sum.at(i) - sum.at(i - k);
        }
    }
    cout << max << endl;

    return 0;
}

Measured memory_bytes: 6528
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){ 
  int x, n; cin >> x >> n;
  vector<int> P(n); rep(i, n) cin >> P[i];

  if(n==0)cout << x << ln;
  else{
    int plus = x, minus = x, res= INF;
    while(1){
      auto iter = find(all(P), plus);
      if(iter == P.end())break;
      plus++;
    }
    while(1){
      auto iter = find(all(P), minus);
      if(iter == P.end())break;
      minus--;
    }
    if(abs(plus-x)< abs(minus-x)) cout << plus << ln;
    else cout << minus << ln;
  }
}


Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1e9 + 7;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N) cin >> A[i];
    int x = A[0];
    rep(i, 0, N) x = gcd(x, A[i]);
    int ans = 0;
    while (x % 2 == 0) {
        ans++;
        x /= 2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int i,ans=0,k,n;
	cin>>n>>k;
	int a[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(i=n-k;i<n;i++)
	{
		//cout<<a[i]<<endl;
		ans+=a[i];
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	int a[200005]={0};
	int b[200005]={0};
	cin>>n;
	for(int i=1; i<=n; i++) cin>>a[i];
	for(int i=1; i<=n; i++){
		b[i] = i-a[i];
		a[i]+=i;
	}
	long long ret = 0;
	map<int,int>m;
	map<int,int>::iterator it;
	for(int i=1; i<=n; i++){
		it = m.find(b[i]);
		if(it!=m.end()) ret+=it->second;
		
		it = m.find(a[i]);
		if(it!=m.end()) it->second+=1;
		else m.insert(make_pair(a[i],1));
	}
	cout<<ret;
}

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

int map[101];

int main(){
	int n;
	while( cin >> n ){
		map[n]++;
	}
	int max=0;
	for( int i=1; i<=100; i++ )
		if( max < map[i] )	max = map[i];
	for( int i=1; i<=100; i++ )
		if( max == map[i] )	cout << i << endl;
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define v(i) vector<i>
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORE(i,a,b) for(i=a;i<=b;i++)
#define FORV(i,a,b) for(i=a;i>b;i--)
#define FOREV(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define look(v) for(auto c:v) cout<<c<<" "; cout<<"\n";
#define dfdc int i,j,k,m,n,ct=0;string s;
#define ppl(a,st,end) for(i=st;i<=end;i++)cin>>a[i];
#define fz(a) memset(a,0,sizeof a);
#define dp_1(n) int dp[n];fz(dp);
#define dp_2(m,n) int dp[m][n];fz(dp);
#define arpt(a,s,e) for(i=s;i<=e;i++) cout<<a[i]<<" ";cout<<"\n";
#define tk int t;cin>>t;while(t--)
 
using namespace std;
 
typedef long long int ll;
 
 
int main(){
    fastio
    string s;
    cin>>s;
    int ans = 0;
    for(char c:s){
        ans = ans + c - '0';
    }
    if(ans%9==0){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
    return 0;
}

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

int main()
{
    string s;
    cin>>s;
    int p;
    cin>>p;
    deque<char> q;
    int rev_count =0 ;
    for(int i=0;i<s.length();i++){
        q.push_back(s[i]);
    }
    bool k = true;
    for(int i=0;i<p;i++){
        int a;char c;int f;
        cin>>a;
        if(a==1){

            rev_count++;
        }
        else{
            cin>>f>>c;
            if(f==1){
                if(rev_count%2==0)q.push_front(c);
                else q.push_back(c);
            }
            else{
                if(rev_count%2==0)q.push_back(c);
                else q.push_front(c);
            }
        }

    }

    if(rev_count%2==0){
        for(int i=0;i<q.size();i++){
            cout<<q[i];
        }
    }
    else{
        for(int i =q.size()-1;i>=0;i--){
            cout<<q[i];
        }
    }

    return 0 ;
}


Measured memory_bytes: 896
double P[102][101];L[101],B[101],N,T,l,b,t,n,k;main(x){for(;scanf("%d%d%d%d",&N,&T,&l,&b),N;printf("%f\n",P[T][N])){
for(n=0;n<=N;n++)for(L[n]=B[n]=t=0;t<=T;t++)P[t][n]=0;
for(;l--;)scanf("%d",&x),L[x]=1;
for(;b--;)scanf("%d",&x),B[x]=1;
for(P[t=0][0]=1;t<T;P[t+1][N]+=P[t][N],t++)for(n=0;n<N;n++)for(k=1;k<=6;k++)x=n+k,x=x>N?2*N-x:x,x=B[x]?0:x,P[t+1+L[x]][x]+=P[t][n]/6;
}exit(0);}

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

int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if(x >= r && x <= W - r && y >= r && y <= H - r){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3112
import java.util.Scanner;

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

		// 入力値の取得
		String S = sc.next();
		
		// 結果の出力
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < S.length(); i++) {
			sb.append("x");
		}
		System.out.println(sb.toString());
		
		sc.close();
	}
}


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

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

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

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long n;
    cin >>n;
    vector<bool>ans(1000000001,false);
    for(long long i=0;i<n;i++){
        long long x;
        cin >>x;
        if(ans[x]){
            cout <<"NO"<<endl;
            return 0;
        }else{
            ans[x]=true;
        }
    }
    cout <<"YES"<<endl;
}


Measured memory_bytes: 125228
#include<iostream>
    #include<cmath>
    using namespace std;
    int main(){
      int N,X,tmp,flg;
      cin >> N;
      X = N*100/108;
      tmp = X;
      flg = 0;
      while(flg == 0){
        if(tmp*108/100 == N){
          flg = 1;
        }
        else{
          if(tmp*108/100 > N ){
            flg = 2;
          }
          tmp++;
        }
      }
      X = tmp;
      if (flg ==1){
        cout << X << endl;
      }
      if (flg == 2){
        cout << ":(" << endl;
      }
      return 0;
    }

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

using namespace std;

typedef long long ll;

const int MX = 18;
const ll oo = 1231231231231231231;

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

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

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

int n;
vector<ll> src;
map<pair<int, int>, ll> mp[MX][MX];

ll calc(int l, int r, int vl, int vr)
{
	if(l > r) return 0;
	auto it = mp[l][r].find(make_pair(vl, vr));
	if(it != mp[l][r].end()) return it->second;
	ll ret = +oo;
	for(int i=l; i<=r; i++) cmin(ret, calc(l, i-1, vl, vl+vr)+calc(i+1, r, vl+vr, vr)+src[i]*(vl+vr));
	mp[l][r][make_pair(vl,vr)] = ret;
	return ret;
}

int main()
{
	read(n);
	for(int i=0; i<n; i++)
	{
		ll x;
		read(x);
		src.emplace_back(x);
	}
	printf("%lld\n", calc(1, n-2, 1, 1)+src[0]+src[n-1]);
	return 0;
}


Measured memory_bytes: 16640
A=[int(input()) for _ in range(5)]
A_1=[(i,i%10) for i in A]
A_1.sort(key=lambda x:x[1])
ans=0
count=0
for a,b in A_1:
    if not b==0 and count==0:
        count=b
    if b==0:
        ans+=a
    else:
        ans+=a+abs(10-b)
if count==0:
    print(ans)
else:
    print(ans-abs(10-count))

Measured memory_bytes: 3064
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 705
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int n,m,mp[maxn][maxn],cnt,vis[maxn],col[maxn],f;
int t[maxn][2],dp[maxn];
bitset <maxn*4> s;

inline void dfs(int u)
{
	t[cnt][col[u]]++; vis[u]=1;
	for(int i=1;i<=n;i++)
	{
		if(i==u) continue;
		if(mp[u][i]==0&&vis[i]==0) col[i]=col[u]^1,dfs(i);
		else if(mp[u][i]==0&&col[i]==col[u]) {f=1; return;}
	}
}

inline int cal(int x,int y){return x*(x-1)/2+y*(y-1)/2;}

int main()
{
	n=read(); m=read();
	for(int i=1;i<=m;i++) {int u=read(),v=read(); mp[u][v]=mp[v][u]=1;}
	for(int i=1;i<=n;i++) if(!vis[i]) cnt++,dfs(i); s[0]=1;
	for(int i=1;i<=cnt;i++)
	{
		//for(int j=n;j>=0;j--)
		//{
			//if(j>=t[i][0]) dp[j]|=dp[j-t[i][0]];
			//if(j>=t[i][1]) dp[j]|=dp[j-t[i][1]];
			s=(s<<t[i][0])|(s<<t[i][1]);
		//}
	}
	int ans=inf;
	for(int i=0;i<=n;i++) if(s[i]) ans=min(ans,cal(i,n-i));
	if(f==1) puts("-1"); else cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2176
maxs=[]
while(True):
    max=-1
    
    b=list(map(int,input().split()))
    n=b[0]
    m=b[1]
    if(n == 0 and m == 0):
        break
    a=list(map(int,input().split()))
    for i in range(n):
        for j in range(i+1,n):
            sum=a[i]+a[j]
            if(sum>max and sum<=m):
                max=sum
    maxs.append(max)

for i in maxs:
    if i==-1:
        print("NONE")
    else:
        print(i)




Measured memory_bytes: 5712
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n],i,f[65][n],c[65][n],j;
    memset(f,0,sizeof(f));
    memset(c,0,sizeof(c));
    for(i=0;i<n;i++)
    cin>>a[i];
    for(i=0;i<n;i++)
    {
        int p=a[i],k=0;
        while(p>0)
        {
            f[k][i]=p%2;
            c[k++][i]=p%2;
            p/=2;
        }
        if(i>0)
        {
            for(j=0;j<65;j++)
            f[j][i]+=f[j][i-1];
        }
    }
    for(i=0;i<n;i++)
    {
        int sum=0;
        for(j=0;j<65;j++)
        {
            sum+=pow(2,j)*((f[j][n-1]-c[j][i])%2==1);
        }
        cout<<sum<<' ';
    }
    return 0;
}

Measured memory_bytes: 208608
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<random>

//使い方がよくわからない
#include<stack>
#include<queue>
#include<bitset>
#include<sstream>

using namespace std;

/*
ソート：sort(v.begin(),v.end(), 0)
合計：accumulate(v.begin(),v.end(), 0)
最小値：*min_element(v.begin(),v.end())
最大値：*max_element(v.begin(),v.end())
最大公約数：__gcd(a,b)
stringに変換：std::to_string()
*/


int main(int argc, char const *argv[]){
    long long n, answer=0;
    cin >> n;

    string ns = to_string(n);

    for(int i=0;i<pow(2,ns.length()-1);i++){
        stringstream ss;
        ss << bitset<10>(i);
        string s = ss.str();
        long long mul = 1;
        //cout << s << endl;
        for(long long j=0;j<ns.length();j++){
            answer += mul*(int(ns[ns.length()-1-j])-int('0'));
            if(s[s.length()-1-j]=='0'){
                mul*=10;
            }else{
                mul=1;
            }
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

bool dp[1000010];

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(all(a));
  rep(i,1e6+1) dp[i]=true;
  int ans=0;
  rep(i,n){
    if(dp[a[i]]==false) continue;
    ans++;
    for(int j=a[i];j<=1e6;j+=a[i]){
      dp[j]=false;
    }
    if(i+1<n&&a[i]==a[i+1]) ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 5104
import sys
import math
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#######ここから天ぷら########
s=deque(list(input()))
q=int(input())
rev=0
for _ in range(q):
    a=input()
    if a=="1": 
        rev=1-rev
        continue
    n,m,p=map(str,a.split())
    if m=="1":
        if rev==1:
            s.append(p)
        else:
            s.appendleft(p)
    else:
        if rev==1:
            s.appendleft(p)
        else:
            s.append(p)
if rev==1:
    print("".join(list(s)[::-1]))
else:
    print(("".join(list(s))))

Measured memory_bytes: 10340
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
LL gcd(LL a,LL b){
  if(!a||!b) return a+b;
  else return gcd(b,a%b);
}
pair<LL,LL> deg(string s){
  if(s=="north") return make_pair(0,1);
  if(s=="west") return make_pair(90,1);
  pair<LL,LL> cen;
  if(s[0]=='n'){
    cen=deg(string(s.begin()+5,s.end()));
  }else if(s[0]=='w'){
    cen=deg(string(s.begin()+4,s.end()));
  }
  cen.first*=2;
  cen.second*=2;
  if(s[0]=='n') cen.first-=90;
  if(s[0]=='w') cen.first+=90;
  return cen;
}
int main(void)
{
  for(;;){
    string s;
    cin >> s;
    if(s=="#") return 0;
    pair<int,int> a=deg(s);
    int g=gcd(a.first,a.second);
    a.first/=g;
    a.second/=g;
    cout << a.first;
    if(a.second>1) cout << '/' << a.second;
    cout << endl;
  }
}

Measured memory_bytes: 3112
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

P v[100100];
ll u[100100];
int n,dp[100100],segtree[410410];

int query(int a, int b, int i=0, int l=0, int r=n+1){
	if(b<=l || r<=a){
		return 0;
	}else if(a<=l && r<=b){
		return segtree[i];
	}else{
		return max(query(a,b,i*2+1,l,(l+r)/2),query(a,b,i*2+2,(l+r)/2,r));
	}
}

void update(int p, int x, int i=0, int l=0, int r=n+1){
	if(!(l<=p && p<r)){
		return;
	}else if(r-l>1){
		update(p,x,i*2+1,l,(l+r)/2);
		update(p,x,i*2+2,(l+r)/2,r);
		segtree[i] = max(segtree[i*2+1],segtree[i*2+2]);
	}else{
		segtree[i] = max(segtree[i],x);
	}
}

int main(void){
	int i,p,ans=0;
	ll x,l;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> x >> l;
		v[i] = P(x-l,x+l);
		u[i] = x+l;
	}
	sort(v,v+n); sort(u,u+n);
	for(i=0; i<n; ++i){
		p = (upper_bound(u,u+n,v[i].first)-u);
		dp[i] = query(0,p)+1;
		p = (lower_bound(u,u+n,v[i].second)-u);
		update(p,dp[i]);
		ans = max(ans,dp[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3968
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

int main()
{
    int X, N;
    cin >> X >> N;
    set<int> p;
    rep(i, N) {
        int tmp;
        cin >> tmp;
        p.insert(tmp);
    }
    rep(diff, 1e3) {
        int tgt = X - diff;
        if (p.find(tgt) == p.end()) {
            cout << tgt << endl;
            break;
        }
        tgt = X + diff;
        if (p.find(tgt) == p.end()) {
            cout << tgt << endl;
            break;
        }
    }

    return 0;
}


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

int x[10];
int y[10];

double dis(int i , int j){
	double dx = x[i] - x[j];
	double dy = y[i] - y[j];
	return pow(dx*dx + dy*dy, 0.5);
}

double fact(int n){
	if(n == 1) return 1;
	int res = n*fact(n - 1);
	return res;
}

int main(){
  int n;
  cin >> n;
  rep(i,n) cin >> x[i + 1] >> y[i + 1];

  double sum = 0;
  double count = fact(n);;
  vector<int> num(n);
  rep(i,n) num[i] = i + 1;
  do {
    rep(i,n - 1) sum += dis(num[i], num[i + 1]);
 } while (next_permutation(num.begin(), num.end()));
 double ans = sum/count;
 cout << fixed << setprecision(10);
 cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
dp=[1]
for i in range(1,10**5+1):
  dp.append(dp[-1]*i%(10**9+7))
if n==m:
  print((2*(dp[n]**2))%(10**9+7))
elif n+1==m:
  print(dp[n]*dp[m]%(10**9+7))
elif m+1==n:
  print(dp[m]*dp[n]%(10**9+7))
else:
  print(0)

Measured memory_bytes: 70924
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int K; scanf("%d", &K);
    ll ans = 0;
    for(int i=1; i<=K; i++) {
        for(int j=1; j<=K; j++) {
            for(int k=1; k<=K; k++) {
                int g = __gcd(i, j);
                g = __gcd(g, k);
                ans += g;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(ll i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

set<ll>val[100005];
ll cnt[100005], valc[100005];

int main() {
	ll n, m; scanf("%lld%lld", &n, &m);
	rep(i, n) {
		ll x; scanf("%lld", &x);
		val[x%m].insert(x); cnt[x%m]++; valc[x]++;
	}
	ll sum = cnt[0] / 2;
	if (m % 2 == 0)sum += cnt[m / 2] / 2;
	for (ll i = 1; i + i < m; i++) {
		ll c1 = 0, c2 = 0;
		for (ll j : val[i])c1 += valc[j] / 2;
		for (ll j : val[m - i])c2 += valc[j] / 2;
		ll Max = 0;
		for (ll j = 0; j <= c1; j++)for (ll k = 0; k <= c2; k++) {
			Max = max(Max, min(cnt[i] - j * 2, cnt[m - i] - k * 2) + j + k);
		}
		sum += Max;
	}
	printf("%lld\n", sum);
}

Measured memory_bytes: 11136
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    cin >> N;
    int L[N];
    for (int i = 0; i < N; i++)
    {
        cin >> L[i];
    }
    int triangles = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            for (int k = j + 1; k < N; k++)
            {
                if (L[i] == L[j] || L[j] == L[k] || L[k] == L[i])
                {
                    continue;
                }
                if(abs(L[i]-L[j]) < L[k] && L[k] < L[i]+L[j]){
                    triangles++;
                }
            }
        }
    }

    cout << triangles;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>

using namespace std;

int main(void) {
	int i, j = 0, w = 0;
	long long ans = 0;
	string s;
	cin >> s;
	for (i = 0; i < s.size(); i++) {
		if (s[i] == 'W') {
			ans += i - j;
			j++;
		}
	}
	cout << ans << "\n";
	return 0;
}

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll N, K;
	cin >> N >> K;

	ll A[N];
	rep(i, N) cin >> A[i];

	// 各ビットごとの1の個数を調べる
	ll b[61] = {};
	for(int i = 60; i >= 0; i--){
		ll y = 1LL << i;
		int cnt = 0;
		rep(i, N){
			if(A[i] & y) cnt++;
		}
		b[i] = cnt;
	}

	int MAX_DIGITS = 50;
	ll dp[MAX_DIGITS+1][2];
	// dp[i][j] : 桁DP。上からi桁目までのところを使ったときの最大値
	//            j = 1のとき、XはKより真に小さい
	memset(dp, -1, sizeof(dp));
	dp[0][0] = 0;

	for(int i = 0; i < MAX_DIGITS; i++){
		ll y = 1LL << (MAX_DIGITS - i - 1);
		ll point0 = b[MAX_DIGITS - i - 1] * y;
		ll point1 = (N - b[MAX_DIGITS - i - 1]) * y;

		if(dp[i][1] != -1){
			// 1 -> 1 : なんでもよい
			// cout << "1 " << i << " " << dp[i][1] << " " << (dp[i][1] + max(point0, point1)) <<  endl;
			dp[i+1][1] = max(dp[i+1][1], dp[i][1] + max(point0, point1));
		}

		if(dp[i][0] != -1){
			// 0 -> 1 : Kのi桁目は1, Xのi桁目は0
			// if(K & y) cout << "2 " << i << " " << dp[i][0] << " " << (dp[i][0] + point0) <<  endl;
			if(K & y) dp[i+1][1] = max(dp[i+1][1], dp[i][0] + point0);
		}

		if(dp[i][0] != -1){
			// 0 -> 0 : Kそのまま
			// cout << "3 " << i << " " << dp[i][0] << " " << (dp[i][0] + ((K & y) ? point1 : point0)) <<  endl;
			dp[i+1][0] = max(dp[i+1][0], dp[i][0] + ((K & y) ? point1 : point0));
		}
	}

	cout << max(dp[MAX_DIGITS][0], dp[MAX_DIGITS][1]) << endl;
}


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

int main(){
	int a;
	cin >> a;
	int b;
	cin >> b;
	
	for(int i=0; i<20; i++){
		if(a*i+1-i >= b){
			cout << i << endl;
            break;
		}
	}
}

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

int main(){
  int N,x,o,n;o=32;n=0;
  cin >> N;
  for(int i=0;i<N;i++){
    n=0;
    cin >> x;
    while(x%2==0){
      x/=2;
      n++;
    }
    if(n<o)
      o=n;
  }
  cout << o;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long M =1e6+10,MOD=1000000000;
typedef long long ll;
ll a[M],b[M];
ll tot=0;
map<ll,ll>mp;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
       cin>>a[i];
       mp[a[i]]++;
    }
    for(auto it : mp)
    {
      tot+=(it.second*(it.second-1))/2;
    }
    for(int i=0;i<n;i++)
    {
      cout<<tot-(mp[a[i]]-1)<<endl;
    }
   
 
    return 0;
  }

Measured memory_bytes: 13568
// AOJ ALDS1_12_B Single Source Shortest Path I
// 2018.5.1 bal4u
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define QMAX 15000
typedef struct { int t, s; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int s, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF   0x30303030
#define MAX_V 102
int hi[MAX_V], *to[MAX_V], *dd[MAX_V];
int dist[MAX_V];

void dijkstra(int n, int start)
{
	int i, s, e, t, nt;

	memset(dist, INF, n << 2);
	qsize = 0;
	dist[start] = 0, enq(start, 0);
	while (qsize) {
		s = que[0].s, t = que[0].t, deq();
		if (dist[s] < t) continue;
		for (i = 0; i < hi[s]; i++) {
			e = to[s][i], nt = t + dd[s][i];
			if (dist[e] > nt) dist[e] = nt, enq(e, nt);
		}
	}
}

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
 
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}
 
int main()
{
	int n, i, j, k, u;
 
	n = in();
	for (i = 0; i < n; i++) {
		u = in(), hi[u] = k = in();
		to[u] = malloc(k<<2);
		dd[u] = malloc(k<<2);
		for (j = 0; j < k; j++) {
			to[u][j] = in(), dd[u][j] = in();
		}
	}
	dijkstra(n, 0);
	for (i = 0; i < n; i++) printf("%d %d\n", i, dist[i]);
	return 0;
}


Measured memory_bytes: 2120