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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

void solve() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    bool check = true;
    for (Int i = 0; i < n; i++) {
        if (a[i] % 2 == 1) {
            check = false;
        }
    }
    print(not check ? "first" : "second");
}

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


Measured memory_bytes: 3976
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int n;
    while(cin>>a[0]>>a[1]>>a[2]){
        ll ans;
        sort(a, a+3);
        ans=a[0]+a[1];
        cout<<ans<<endl;
    }
  return 0;
}




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

int main()
{

    //freopen("Input.txt","r",stdin);
    // ios_base :: sync_with_stdio(false);
   string s;
   ll one=0,zero=0;
   cin>>s;
   for(int i=0;i<s.size();i++)
   {
       if(s[i]=='0')
       {
           zero++;

       }
       if(s[i]=='1')
       {
           one++;

       }
   }
   ll ans=min(zero,one);
   cout<<ans*2<<endl;
}


Measured memory_bytes: 512
//secreterror
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0;i<n;i++)
#define rev(i, n) for(ll i=n-1;i>=0;i--)
#define forr(i, x, y) for(ll i=x;i<y;i++)
#define f first
#define s second
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vpii vector<pair<int,int>>

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

    vector<ll>arr(n);
    rep(i,n) cin>>arr[i];

    vector<ll>dp(n+1,INT_MAX);

    dp[0]=0;
    dp[1]=0;
    dp[2]=abs(arr[0]-arr[1]);

    for(int i=3;i<=n;i++){
        for(int j=1;j<=k;j++){

            if(i-j>=1){
                dp[i]=min(dp[i],dp[i-j]+abs(arr[i-1]-arr[i-j-1]));
            }

        }
    }
    cout<<dp[n]<<endl;

}

Measured memory_bytes: 1792
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

ll h, w;
char a[1000][1000];
ll d[1000][1000];


void bfs(P s) {
    queue<P> que;
    que.push(s);
    while (!que.empty()) {
        P p = que.front();
        que.pop();
        if (p.first + 1 < h && a[p.first + 1][p.second] == '.') {
            if (d[p.first + 1][p.second] == 0) que.push(P(p.first + 1, p.second));
            d[p.first + 1][p.second] += d[p.first][p.second];
            d[p.first + 1][p.second] %= mod;
        }
        if (p.second + 1 < w && a[p.first][p.second + 1] == '.') {
            if (d[p.first][p.second + 1] == 0) que.push(P(p.first, p.second + 1));
            d[p.first][p.second + 1] += d[p.first][p.second];
            d[p.first][p.second + 1] %= mod;
        }
    }
}


int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        cin >> h >> w;
        rep(i, h)rep(j, w) cin >> a[i][j];
        rep(i, h)rep(j, w) d[i][j] = 0;
        d[0][0] = 1;
        bfs(P(0, 0));
        cout << d[h - 1][w - 1] << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 9088
mod = 10**9+7
n,a,b = map(int,input().split())
ans = pow(2,n,mod)-1

comb1 = 1 
for i in range(n-a+1,n+1):
  comb1 *= i
  comb1 %= mod
for i in range(1,a+1):
  comb1 *= pow(i,mod-2,mod)
  comb1 %= mod

comb2=1
for i in range(n-b+1,n+1):
  comb2 *= i
  comb2 %= mod
for i in range(1,b+1):
  comb2 *= pow(i,mod-2,mod)
  comb2 %= mod
  
ans -= (comb1+comb2)
ans %= mod
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>
int main() {
    long long A, B, N, x, ans = 0;
    scanf("%lld %lld %lld", &A, &B, &N);
    x = B - 1 <= N ? B - 1 : N;
    ans = floor(A * x * 1.0 / B) - A * floor(x * 1.0 / B);
    printf("%lld\n", ans);
    return 0;
}

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

const int D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];

int main(){
    int n; ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> s;
    vector<int> ord(n+1,-1);
    int c = 1, l=0;
    {
        int v = 1;
        while(ord[v]==-1){
            ord[v] = s.size();
            s.push_back(v);
            v = a[v-1];
        }
        c = s.size() - ord[v];
        l = ord[v];
    }
    if(k<l) cout << s[k] << endl;
    else{
        k -= l;
        k %= c;
        cout << s[l+k] << endl;
    }
    return 0;
}


Measured memory_bytes: 5852
#include <stdio.h>
#include <math.h>

int main(){
    double x1, y1, x2, y2;
    double distance;

    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    distance = sqrt(pow(fabs(x2-x1),2)+pow(fabs(y2-y1),2));
    printf("%.8lf\n", distance);
}



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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)

typedef long long ll;

int main() {
    int K;
    cin >> K;
    int x = 7 % K;
    set<int> s;
    int cnt = 1;
    while (s.count(x) == 0) {
        if (x == 0) {
            cout << cnt << endl;
            return 0;
        }
        s.insert(x);
        x = (x * 10 + 7) % K;
        cnt++;
    }
    cout << "-1" << endl;
    return 0;
}


Measured memory_bytes: 50460
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>=n;i--)
#define INF 999999999
#define INF_M 2147483647
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;

int main() {
	int n;
	while(cin >> n) {
		cout << n * (n + 1) / 2 + 1 << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
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;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, k, c[100100], res;
string s;

signed main() {
	cin >> n >> k >> s;
	reps(i,1,n) c[i] += c[i-1] + (s[i]!=s[i-1]);
	rep(l,n) {
		int r;
		if (s[l]=='0') r = lower_bound(c, c+n, c[l]+k*2) - c;
		else r = lower_bound(c, c+n, c[l]+k*2+1) - c;
		chmax(res, r-l);
	}
	cout << res << endl;
}

Measured memory_bytes: 848
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

func Solve(){
  var N, K, C int
  NextInt(&N, &K, &C)
  S := NextLine()
  H := make([]bool, N)
  for i, s := range S {
    H[i] = s == 'x'
  }
  W := make([]int, 0)
  for i := 0; i < N; i++ {
    if H[i] { continue }
    W = append(W, i)
    i += C
  }
  if K < len(W) { return }
  L := make([]int, K)
  k := K - 1
  for i := N - 1; 0 <= i; i-- {
    if H[i] { continue }
    L[k] = i
    k--
    i -= C
  }
  for i := range L {
    if W[i] == L[i] { Write(W[i] + 1) }
  }
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 10496
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define pb        emplace_back
#define fi        first
#define se        second
#define outl(x)   cout << (x) << '\n'
#define rep(i,n)     for(int i=0; i<(n); ++i)
typedef pair<int,int> pii;

int V, E;
vector<pii> G[100010];

int prim()
{
    vector<bool> used(V+1, false);
    priority_queue< pii, vector<pii>, greater<pii> > pq;
    int sum = 0;
    pq.emplace(pii(0,0));

    while ( !pq.empty() ) {
        const auto now = pq.top(); pq.pop();
        if (used[now.se]) continue;

        sum += now.fi;
        used[now.se] = true;
        for (const auto &e : G[now.se]) {
            pq.emplace(e);
        }
    }
    return sum;
}

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

    cin >> V >> E;
    rep(i, E) {
        int s, t, w;
        cin >> s >> t >> w;
        G[s].pb(pii(w, t));
        G[t].pb(pii(w, s));
    }

    outl(prim());
}




Measured memory_bytes: 9876
#include<stdio.h>

int main(void)
{
    int N,K,X,Y;

    scanf("%d %d %d %d",&N,&K,&X,&Y);
    if(((N>=1&&N<=10000)&&(K>=1&&K<=10000))&&((Y>=1&&Y<=10000)&&(X>=1&&X<=10000)))
    {
        if(N>K){
            printf("%d\n",(K*X)+(Y*(N-K)));
        }
        else
            printf("%d\n",N*X);
    }
    return 0;
}


Measured memory_bytes: 128
from fractions import gcd
A, B, C, D = (map(int, input().split()))


s = int(C * D // gcd(C, D))

p  = B - A + 1 - int((B // C - (A - 1) // C) + (B // D - (A - 1) // D) - (B // s - (A - 1) // s))
print(p)


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

const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, m; cin >> n >> m;
	int l = 0, r = 1001001001;
	rep(i,m){
		int a, b; cin >> a >> b;
		l = max(l, a);
		r = min(r, b);
	}
	if(r - l < 0) cout << 0;
	else cout << r - l + 1;
} 

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string>


int main(void){
    int y,m,d;
    char s1,s2;
scanf("%d%c%d%c%d",&y,&s1,&m,&s2,&d);
if(y>2019){printf("TBD");

}
else if(y=2019 && m>=5){printf("TBD");}
else{printf("Heisei");}

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,i,c,a,b;
  while(cin>>n,n){
    cin>>c;
    int y=0;
    for(i=0;i<c;i++){
      cin>>a>>b;
      y+=b-a;
    }
    if(y>=n)cout<<"OK"<<endl;
    else cout<<n-y<<endl;
  }
}

Measured memory_bytes: 3012
class UnionFind(object):
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]


    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])


    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)
def compute_mst_kruskal(N, edges):#N = 頂点数、edges 0-indexed
    edges = sorted(edges, key = lambda x:x[2])
    UF = UnionFind(N)
    cost = 0
    for edge in edges:
        x, y, w = edge
        if not UF.same(x, y):
            UF.unite(x, y)
            cost+=w
    return cost
N = int(input())
ixy = []
for i in range(N):
    x, y = map(int, input().split())
    ixy.append((i, x, y))
xy_x = sorted(ixy, key = lambda x:x[1])
xy_y = sorted(ixy, key = lambda x:x[2])
edges = []
for i in range(N-1):
    i1, x1, y1 = xy_x[i]
    i2, x2, y2 = xy_x[i+1]
    edges.append((i1, i2, x2-x1))
    i1, x1, y1 = xy_y[i]
    i2, x2, y2 = xy_y[i+1]
    edges.append((i1, i2, y2-y1))
ans = compute_mst_kruskal(N, edges)
print(ans)


Measured memory_bytes: 52456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    public static void main(String[] args) throws IOException {
        Main main = new Main();
        main.solve();
    }
    void solve() throws IOException {
        Set<Integer> set = new HashSet<>();
        for(int i=0;i<3;i++) set.add(sc.nextInt());
        String ans = set.size()==2?"Yes":"No";
        System.out.println(ans);
    }
}



Measured memory_bytes: 21972
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
		long X_2 = X * X;
		int p;
		ArrayList<Long> primeNumbers = new ArrayList<Long>();

		primeNumbers.add((long) 2);
		if (X == 2) {
			System.out.println(2);
		} else {
			for (long i = 3; i < X_2; i++) {
				boolean flag = true;
				long limit = (long) Math.sqrt(i) + 1;
				for (int j = 0; primeNumbers.get(j) < limit; j++) {
					if (i % primeNumbers.get(j) == 0) {
						flag = false;
					}
				}
				if (flag) {
					if (i >= X) {
						primeNumbers.add(i);
						break;
					}
					primeNumbers.add(i);
				}
			}
			System.out.println(primeNumbers.get(primeNumbers.size()-1));
		}
	}

}


Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s; cin>>s;
  char n[s.size()];
  for (int i = 0; i < s.size(); i++) n[i]=s.at(i);
  for (int i = 0; i < (s.size())/2; i++){
    if(n[i]!=n[s.size()-1-i]){
      cout<<"No"<<endl;
      exit(0);
    }
  }
  for (int i = 0; i < (s.size())/2/2; i++){
    if(n[i]!=n[s.size()/2-i-1]){
      cout<<"No"<<endl;
      exit(0);
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll int
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll sm[200002];
ll tt[200002];

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

  ll N , C;
  cin >> N >> C;
  vector<ll> s,t,c;
  rep(i,N){
    ll inps, inpt, inpc;
    cin >> inps >> inpt >> inpc;
    s.pb(inps), t.pb(inpt), c.pb(inpc);
  }
  for(ll i = 1;i <= C;i++){
    rep(j,200002) tt[j]=0;
    rep(j,N)if(c[j]==i)tt[s[j]*2-1]++,tt[t[j]*2]--;
    FOR(j,1,200002)tt[j]+=tt[j-1];
    for(ll j=0; j<200002;j++) if(tt[j]>0) sm[j]++;
  }

  ll ans = 0;
  rep(i,200002) ans = max(ans,sm[i]);
  cout << ans << endl;

  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 3308
import java.util.*;
public class Main
{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        String a = t.substring(0,t.length()-1);
        if(s.equals(a)){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35652
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

long calc(long n) {
    // n/m = n%m = k とおく
    // 商が k で、余りが k ということなので
    // n = mk + k
    //   = k(m + 1)
    // と表せる。
    // m は、n の約数から 1 を引いた数、というのが分かる。
    // n の約数は sqrt(n) で列挙できる。

    long ans = 0;
    for (long i = 1; i * i <= n; i++) {
        if (n % i == 0) { // m の候補
            foreach (m; [i - 1, n / i - 1]) {
                if (m > 0 && n / m == n % m) {
                    ans += m;
                }
            }
        }
    }

    return ans;
}

void main() {
    long n = read!long;
    writeln(calc(n));
}


Measured memory_bytes: 256
#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-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};


int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	while(1){
		int n,m;
		cin>>n>>m;
		vi a(n),b(m);
		for(int i=0;i<n;i++) cin>>a[i];
		for(int i=0;i<m;i++) cin>>b[i];
		int res=inf;
		for(int x=0;x<2;x++){
			vi c(n);
			int id=0;
			for(int i=0;i<m;i++) for(int j=0;j<b[i];j++) c[id++]=(i+x)%2;
			int t=0;
			for(auto i:a) t+=i;
			for(auto i:c) t-=i;
			if(t) continue;
			vi d(n),used(n);
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++) if(!used[j]&&a[i]==c[j]){
					used[j]=1;
					d[i]=j;
					break;
				}
			}
			int tmp=0;
			for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) if(d[i]>d[j]) tmp++;
			res=min(res,tmp);
		}
		cout<<res<<endl;
		break;
	}
}


Measured memory_bytes: 3216
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = []
for i in range(q):
    bc.append(list(map(int, input().split())))

s = sum(a)
count = [0] * (10**5+1)
for i in range(n):
    count[a[i]] += 1

for i in range(q):
    deg = bc[i][1] - bc[i][0]
    s += deg*count[bc[i][0]]
    count[bc[i][1]] += count[bc[i][0]]
    count[bc[i][0]] = 0
    print(s)

Measured memory_bytes: 32104
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//ソートすればいいんですか？
//???
int dp[3000];

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


	int N, T;
	scanf("%d", &N);
	scanf("%d", &T);
	int AB[3000];
	rep(i, N) {
		int a, b;
		scanf("%d %d", &a, &b);
		AB[i] = (a << 12) + b;
	}
	sort(AB, AB + N);

	int saidai = 0;
	rep(i, N) {
		int a = AB[i] >> 12;
		auto dp2 = dp + a;
		int b = AB[i] & ((1 << 12) - 1);
		chmax(saidai, dp[0] + b);
		rep(j, T - a) {
			chmax(dp[j], dp2[j] + b);
		}
	}
	printf("%d", saidai);

	Would you please return 0;
}

Measured memory_bytes: 128
Q, H, S, D = map(int, input().split())
N = int(input())

array = [[Q*8, Q*4, 1], [H*4, H*2, 1], [S*2, S, 1], [D, D, 2]]

array.sort()

total = 0
for i in range(4):
    total += N // array[i][2] * array[i][1]
    N %= array[i][2]
    
print(int(total))

Measured memory_bytes: 3064
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
S = str(input())

c = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

ans = []
for i in range(len(S)):
    n_c = c[((c.index(S[i]))+ N)% 26]
    ans.append(n_c)

print("".join(ans))

Measured memory_bytes: 10972
object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  sc.useDelimiter("\n")
  val A1 = sc.next().split(' ').map(_.toInt).toList
  val A2 = sc.next().split(' ').map(_.toInt).toList
  val A3 = sc.next().split(' ').map(_.toInt).toList
  val A = Seq(A1, A2, A3)
  val N = sc.nextInt()
  val b = for (i <- 0 until N) yield sc.nextInt()
  // 存在するを0と置く
  val result = A.map(l => l.map(a => if(b.contains(a)) 0 else a)).toList
  if (exists(result)) {
    println("Yes")
  } else {
    println("No")
  }

  def exists(b: List[List[Int]]): Boolean = {
    b match {
      case List(List(0, 0, 0), List(a, b, c), List(d, e, f)) => true
      case List(List(a, b, c), List(0, 0, 0), List(d, e, f)) => true
      case List(List(a, b, c), List(d, e, f), List(0, 0, 0)) => true
      case List(List(0, a, b), List(0, c, d), List(0, e, f)) => true
      case List(List(a, 0, b), List(c, 0, d), List(e, 0, f)) => true
      case List(List(a, b, 0), List(c, d, 0), List(e, f, 0)) => true
      case List(List(0, a, b), List(c, 0, d), List(e, f, 0)) => true
      case List(List(a, b, 0), List(c, 0, d), List(0, e, f)) => true 
      case _ => false
    }
  }

}

Measured memory_bytes: 55328
#include <bits/stdc++.h>
#define ULL unsigned long long
#define LL long long
#define LD long double
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define loop(i,a,b) for(int i=a;i<=b;++i)
#define pool(i,a,b) for(int i=a;i>=b;--i)
#define int long long
using namespace std; const int N = 100 + 5, N2 = 50000 + 5, LOG = 9 + 1, INF = 1e9;

void no(){ cout<<"-1\n"; exit(0); }
bool g[N][N];

signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,k; cin>>n>>k;
	loop(j,2,n) g[1][j]=g[j][1]=1;

	int cur=((n-1)*(n-2))/2;
	int a=2, b=3;
	while(cur>k){
		--cur;
		while(g[a][b]){
			++b;
			if(b==n+1) ++a, b=a+1;
			if(b==n+1) no();
		}
		g[a][b]=g[b][a]=1;
	}
	if(cur!=k) no();
	int nb=0; loop(i,1,n) loop(j,1,n) nb+=g[i][j];
	cout<<nb/2<<'\n';
	loop(i,1,n-1) loop(j,i+1,n) if(g[i][j]) cout<<i<<" "<<j<<'\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int n, x, y, i;
    x = 100000;
    cin >> n;

    for (i = 0; i <= n; i++) {
        y = ((i / (6 * 6 * 6 * 6 * 6 * 6)) % 6)
            + ((i / (6 * 6 * 6 * 6 * 6)) % 6)
            + ((i / (6 * 6 * 6 * 6)) % 6)
            + ((i / (6 * 6 * 6)) % 6)
            + ((i / (6 * 6)) % 6)
            + ((i / (6)) % 6)
            + (i % 6)
            + ((n - i) / (9 * 9 * 9 * 9 * 9)) % 9 
            + ((n - i) / (9 * 9 * 9 * 9)) % 9 
            + ((n - i) / (9 * 9 * 9)) % 9 
            + ((n - i) / (9 * 9)) % 9 
            + ((n - i) / (9)) % 9 
            + (n - i) % 9;
        if (y < x)
            x = y;
    }   
    cout << x << endl;
    return 0;
}


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

int main () {

 int w,h,x,y,r;

 cin >> w >> h >> x >> y >>  r;

 if (x >= r && y >= r && y+r <= h && x+r <= w) {
  cout << "Yes" <<endl;
 } else {
  cout << "No" << endl;
 }
 return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main()
{
    int n; cin >> n;
    bool arr[n];
    int temp;

    REP(i, n) {
        cin >> temp;
        if (i + 1 == temp) {
            arr[i] = false;
        } else {
            arr[i] = true;
        }
    }

    int steps = 0;
    REP(i, n) {
        if (!arr[i]) {
            steps++;
            arr[i] = true;
            arr[i+1] = true;
        }
    }
    cout << steps;
}




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

using namespace std;

int main() {
  int N, cnt = 0;
  cin >> N;
  vector<vector<int>> v(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    cin >> v[i][0] >> v[i][1];
  }

  for (int i = 0; i < N; i++) {
    if (v[i][0] == v[i][1]) {
      cnt++;
    } else {
      cnt = 0;
    }
    if (cnt == 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3632
x1, y1, x2, y2 = map(int, input().split())

x3 = x2 - (y2-y1)
y3 = y2 + (x2-x1)
x4 = x1 - (y2-y1)
y4 = y1 + (x2-x1)

a = [str(x3),str(y3),str(x4),str(y4)]
b = ' '.join(a)
print(b)

Measured memory_bytes: 3060
#include <bits/stdc++.h>  
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- "
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long  
#define p(x)               cout << x << "\n" ; 
#define MOD                100000007
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define mi                 map <int,int> 
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             x.begin(),x.end() 
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set ; 
const int N = 2e5;  
const double pie = 3.14159265358979323846 ;
// limit for array size 
double dist(double Ax,double X,double Ay, double Y){
  double best = (Ax-Ay)*(Ax-Ay) + (X-Y)*(X-Y) ;
  best = sqrt(best) ;
  return best ;
}
int tests(){ 
  // vector <vector <int>> M(3,vector <int> (3,271)) ;
  int A,B; 
  cin >> A >> B ; 
  int i ;
  forn(i,1,10004){ 
    int num1 = (i*8)/100 ;
    int num2 = (i)/10 ;
    if(num1 == A && num2 == B)
      return cout << i << '\n',0 ; 
    }   
    cout << -1 ; 
  return 0 ;
}
int main(){
    I__O ;  
    int cases = 1 ;
    // cin >> cases ; 
    while(cases--)
      tests(); 
    return 0 ; 
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

typedef pair<int, int> PII;
typedef long long LL;

int main() {
  LL X;
  scanf("%lld", &X);
  LL moves = X / 11;
  X -= moves * 11;
  moves *= 2;
  if (X > 6) moves += 2;
  else if (X > 0) moves += 1;
  printf("%lld\n", moves);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  int s,f;cin>>s>>f;
  if(f >= s){
    cout<<"unsafe"<<endl;
  }else{
    cout<<"safe"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3616
N = int(input())
kazuof3 = N // 3
kazuof5 = N // 5
kazuof15 = N//15

ans = N * (N + 1) // 2 - kazuof3 * (kazuof3 + 1) * 3 //2 - kazuof5 * (kazuof5 + 1) * 5 // 2 + kazuof15 * (kazuof15 + 1) * 15 // 2
print(ans)

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

int main(){
  int n;
  cin >> n;
  int a[n];
  int ans = 0;
  for(int i=0; i<n; i++){
    cin >> a[i];
    ans += a[i]-1;
  }
  cout << ans << endl;
}

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

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
//#define int long long

using namespace std;

const int N = (1e5 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);

main()
{
	int n;
	cin >> n;
	cout << (n - 1) / 2;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	string s; cin >> s;
	int ret;
	if (s=="RRR") ret = 3;
	else if (s=="RRS"||s=="SRR") ret = 2;
	else if (s=="SSS") ret = 0;
	else ret = 1;
	cout << ret << endl;
	return 0;
}


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

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

  map<string, int> ans;

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

    ans[s]++;
  }

  cout << "AC x " << ans["AC"] << endl;
  cout << "WA x " << ans["WA"] << endl;
  cout << "TLE x " << ans["TLE"] << endl;
  cout << "RE x " << ans["RE"] << endl;

  return 0;
}

Measured memory_bytes: 3632
k = int(input())
arr = list(map(int,input().split()))
arr.reverse()

lower = 2
upper = 2
flag = True
for i in range(k):
    lowm = lower//arr[i]
    upm = upper//arr[i]

    if upm == 0:
        flag = False
    if arr[i] * lowm < lower:
        lowm += 1
        if lowm > upm:
            flag = False
    lower = arr[i] * lowm
    upper = arr[i] * upm + arr[i]-1
    # print(lowm,upm)
    # print(lower,upper)
    # print("##########")



if flag:
    print(lower,upper)
else:
    print(-1)


Measured memory_bytes: 14224
#include <iostream>
using namespace std;
 
bool isInclude3(int n)
{
  while(n){
    if(n % 10 == 3) return true;
    n /= 10;
  }
  return false;
}
 
int main()
{
  int n;
  cin >> n;
  for(int i=1; i<=n; i++){
    if(i % 3 == 0 || isInclude3(i)) cout << " " << i;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1164
#include <cstdio>

int main()
{
  int n;
  scanf("%d", &n);
  int acc[2][101];
  acc[0][0] = acc[1][0] = 0;

  for (int i = 0; i < 2; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
      int a;
      scanf("%d", &a);
      acc[i][j + 1] = acc[i][j] + a;
    }
  }
  
  int ans = 0;
  for (int i = 0; i < n; ++i)
  {
    if (ans < acc[0][i + 1] + acc[1][n] - acc[1][i])
    {
      ans = acc[0][i + 1] + acc[1][n] - acc[1][i];
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
A,B,C = [int(x) for x in input().split()]
D = max(A,B,C)
ans = 0

ans += (D-A)//2
A += 2*((D-A)//2)
ans += (D-B)//2
B += 2*((D-B)//2)
ans += (D-C)//2
C += 2*((D-C)//2)

if max(A,B,C) != (A+B+C)/3:
    if A+B+C+1 == max(A,B,C)*3:
        ans +=2
    else:
        ans +=1

print(ans)


Measured memory_bytes: 3064
#include<cstdio>
#include<queue>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

typedef pair<int,int> pii;

class Line{
	public:
	Line(){}
	
	int stx;
	int sty;
	int rot;
	bool firstin;
	
	vector<pii> pos;
	void add(pii p){
		if(pos.size()==0){
			stx = p.first;
			sty = p.second;
		}
		
		pos.push_back(pii(p.first-stx, p.second-sty));
	}
	
	void rotate(){
		rep(i,pos.size()){
			pos[i] = pii(-pos[i].second, pos[i].first);
		}
	}
	
	void hoge(){
		int rcont = 0;
		if(pos[1].second>0)rcont=3;
		if(pos[1].first<0)rcont=2;
		if(pos[1].second<0)rcont=1;
		
		rep(i,rcont)rotate();
	}
	
	bool equal(Line line){
		if(pos.size()!=line.pos.size())return false;
		
		rep(i,pos.size()){
			if(pos[i]!=line.pos[i])return false;
		}
		
		return true;
	}
};


int main(){
	
	A:;
	int n;
	cin>>n;
	
	if(n==0)return 0;
	
	vector<Line> lines;
	
	Line master;
	
	rep(i,n+1){
		int t;
		cin>>t;
		
		Line line;
		rep(j,t){
			int a,b;
			cin>>a>>b;
			
			line.add(pii(a,b));
		}
		line.hoge();
		
		Line line2;
		rep(j,t){
			line2.add(line.pos[t-j-1]);
		}
		line2.hoge();
		
		
		if(i==0){
			master = line;
		}else{
			lines.push_back(line);
			lines.push_back(line2);
		}
	}
	
	int count = 0;
	rep(i,lines.size()){
		if(master.equal(lines[i])){
			printf("%d\n",(i/2)+1);
			count++;
		}
	}
	printf("+++++\n");
	
	goto A;
}

/*
5
5
0 0
2 0
2 1
4 1
4 0
5
0 0
0 2
-1 2
-1 4
0 4
5
0 0
0 1
-2 1
-2 2
0 2
5
0 0
0 -1
2 -1
2 0
4 0
5
0 0
2 0
2 -1
4 -1
4 0
5
0 0
2 0
2 1
4 1
4 0

*/

Measured memory_bytes: 1208
#include<iostream>
#include<vector>
#include<string>
#include<set>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, N;
    cin >> X >> N;
    vector<int> P(N);
    for (auto& p : P) {
        cin >> p;
    }
    set<int> S;
    for (auto& p : P) {
        S.insert(p);
    }
    int diff = 1 << 30;
    int ans = 1 << 30;
    rep(i, 0, 102) {
        if (S.count(i)) {
            continue;
        }
        if (chmin(diff, abs(X - i))) {
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h> 
#define ll long long 
using namespace std; 
long long n,a,b,p=1000000007,k,k1,k2;
long long modPow(long long base, long long power) 
{
    long long result=1;
    while(power>0) 
	{
        if(power % 2 == 1) 
		{ 
            result=(result*base) % p;
        }
        base = (base * base) % p;
        power = power / 2; 
    }
    return result;
}
long long modBinomial(long long n, long long k,long long p) 
{
    long long numerator = 1; 
    for (long long i=0; i<k; i++) 
	{
        numerator=(numerator*(n-i))%p;
	}
    long long denominator=1;
    for (int i=1; i<=k; i++) 
	{
        denominator=(denominator*i)%p;
    }
    return (numerator*modPow(denominator,p-2))%p;
}

int main() 
{ 
 	cin>>n>>a>>b;
 	//cout<<f_p(2,n)%p<<" ";
 	//cout<<modBinomial(n,a,p);
 	long long bb=2;
 	cout<<(modPow(bb,n)-modBinomial(n,a,p)-modBinomial(n,b,p)-1+5*p)%p<<endl;
} 

Measured memory_bytes: 384
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

struct edge { LL to, cost; };
int start;
LL d[100100];
vector<edge> vec[100100];
 
void dijkstra() {
	for (int i = 0; i < 100100; i++)d[i] = HINF<LL>();
	priority_queue<pair<LL, int>, std::vector<pair<LL, int>>, std::greater<pair<LL, int>>> pq;
	d[start] = 0;
	pq.push(make_pair(d[start], start));//cost,to
	while (!pq.empty()) {
		pair<LL, int> p = pq.top();
		pq.pop();
		int i = p.second;
		if (d[i] < p.first)continue;
		for (int k = 0; k < (int)vec[i].size(); k++) {
			edge e = vec[i][k];
			if (d[e.to] <= d[i] + e.cost)continue;
			d[e.to] = d[i] + e.cost;
			pq.push(make_pair(d[e.to], e.to));
		}
	}
}
 
int n, m;
int l, r, c;
 
int main(){
    cin >> n >> m;
    REP(i, m){
        cin >> l >> r >> c;
        l--, r--;
        vec[l].emplace_back(edge{r, c});
    }
    for(int i = 1;i < n;i++){
        vec[i].emplace_back(edge{i - 1, 0});
    }
    dijkstra();
    LL ans = d[n - 1];
    cout << (ans == HINF<LL>() ? -1 : ans) << endl;
}

Measured memory_bytes: 9464
/* Author: Dhruv Rastogi */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 998244353
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

int dp[2][3005];
int a[3005];
void solve(){  	
	dp[0][0]=1;
	int n,s;
	cin>>n>>s;
	rep(i,0,n) cin>>a[i];
	rep(i,0,n){
		rep(j,0,s+1){
			dp[(i+1)%2][j]=0;
		}
		rep(j,0,s+1){
			dp[(i+1)%2][j]+=2*dp[i%2][j]%hell;
			dp[(i+1)%2][j]%=hell;
			if(j+a[i]<=s){
				dp[(i+1)%2][j+a[i]]+=dp[i%2][j];
				dp[(i+1)%2][j+a[i]]%=hell;
			}
		}
	}
	cout<<dp[n%2][s]<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3716
#include<iostream>
#include<vector>
#include<complex>
#include<algorithm>
using namespace std;
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(n);i++)
typedef complex<double> C;
double cross(const C a, const C b)
{
    return imag(conj(a)*b);
}
double dot(const C a, const C b)
{
    return real(conj(a)*b);
}
int contains(const vector<C>& ps, const C p)
{
    bool flag = false;
    rep(i,ps.size()) {
        C a = ps[i] - p, b = ps[(i+1)%ps.size()] - p;
        if (imag(a) > imag(b)) swap(a, b);
        if (imag(a) <= 0 && 0 < imag(b)){
            if (cross(a, b) < 0) flag = !flag;
        }
        if (cross(a, b) == 0 && dot(a, b) <= 0) return 1;
  }
  return flag ? 2 : 0;
}

int main(){
    int n;
    while(cin>>n&&n!=0){
        vector<C>v;
        vector<C>s;
        vector<int>x;
        vector<int>y;
        rep(i,n){
            int a,b;
            cin >> a >> b;
            x.push_back(a);
            y.push_back(b);
            v.push_back(C((double)a,(double)b));
        }
        rep(i,4){
            int a,b;
            cin >> a >> b;
            x.push_back(a);
            y.push_back(b);
            s.push_back(C((double)a,(double)b));
        }
        sort(x.begin(),x.end());
        sort(y.begin(),y.end());
        x.erase(unique(x.begin(),x.end()),x.end());
        y.erase(unique(y.begin(),y.end()),y.end());
        long long sm = 0;
        for(int i=0;i<x.size()-1;i++){
            for(int j=0;j<y.size()-1;j++){
                double xx = (double)(x[i]+x[i+1])/2.0;
                double yy = (double)(y[j]+y[j+1])/2.0;
                if(contains(v,C(xx,yy))==2){
                    if(contains(s,C(xx,yy))!=2){
                        sm += (long long)(x[i+1]-x[i])*(long long)(y[j+1]-y[j]);
                        
                    }
                }
            }
        }
        cout << sm << endl;
    }   
    return 0;
}


Measured memory_bytes: 3160
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

ll MODP = 998244353;


int main(){
  ll N;
  cin >> N;
  vector<ll>  num(N+10),nummin(N+10,INFL);
  for(int i = 1;i <= N;i++)cin >> num[i];
  for(int i = 1;i <= N;i++){
    if(num[i] < nummin[i-1])nummin[i] = num[i];
    else nummin[i] = nummin[i-1];
  }
  ll ans = 0;
  for(int i = 1;i <= N;i++){
    if(nummin[i] >= num[i])ans++;
  }
  cout << ans << endl;
  return 0;
}


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

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

int main() {
    int n,k;cin>>n>>k;
    int ans = 1;
    ans+=(n-k)/(k-1);
    if((n-k)%(k-1)!=0)ans++;

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

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
ll a[20][20];

ll dp[1<<17];

ll solve() {
    //fill_n(dp, 1<<17, -1e15);
    for (int i = 1; i < (1<<n); i++) {
        ll res = 0;
        for (int j = 0; j < n; j++) {
            for (int k = j+1; k < n; k++) {
                if (((i>>j)&1) && ((i>>k)&1))
                    res += a[j][k];
            }
        }
        
        for (int j = i; j > 0; j = (j-1) & i) {
            if (j == i) continue;
            res = max(res, dp[j] + dp[i^j]);
        }
        dp[i] = res;
    }
    return dp[(1<<n)-1];
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> a[i][j];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 768