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

using namespace std;

#define ll long long
#define fi first
#define se second

const int maxn = 1e6 + 10, INF = 1000000009;

ll a[maxn];
bool flg = false;
vector<pair<int,ll> > E[maxn];

void init() {
    for(int i = 0;i < maxn;i++) a[i] = INF;
}
int n,m;
bool vis[maxn];

void dfs(int idx) {
    for(int i = 0;i < E[idx].size();i++) {
        int to = E[idx][i].fi;
        int v = E[idx][i].se;
        if(vis[to]) continue;
        if(a[to] != INF) {
            if(a[to] - a[idx] != v) {
                flg = true;
                return ;
            }
        } else {
            a[to] = a[idx] + v;
            dfs(to);
            if(flg) return;
        }
    }
    vis[idx] = true;
    if(flg) return;

}
int L[maxn];
int main(){
    ios_base::sync_with_stdio(0);

    cin>>n>>m;
    for(int i = 0;i < m;i++) {
        int l,r,d;cin>>l>>r>>d;
        L[i] = l;
        E[l].push_back(make_pair(r,d));
        E[r].push_back(make_pair(l,-d));
    }
    init();
    for(int i = 0;i < n;i++) {
        if(E[L[i]].size() >= 1) {
            if(vis[L[i]]) continue;
            a[L[i]] = 0;
            dfs(L[i]);
            if(flg) break;
        }
    }
    if(flg) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 48256
let s = read_line () in
let n = String.length s in
let rec loop i mode =
    if i = n then false else
        match mode with
        | 0 -> if s.[i] = 'C' then loop (i + 1) 1 else loop (i + 1) mode
        | _ -> if s.[i] = 'F' then true else loop (i + 1) mode
in
print_endline @@ if loop 0 0 then "Yes" else "No"

Measured memory_bytes: 384
#include<iostream>

using namespace std ;

int ans = 0 ;

bool answer( int n ,long num[] ,int p )
{
	if( n == num[ p ] )
	{
		ans++ ;
		return true ;
	}
	return false ;
}

int main()
{
	int s ,t ,n ;

	cin >> s ;
	long num[ s ] ;

	for( int i = 0 ; i < s ; i++ )
		cin >> num[ i ] ;

	cin >> t ;
	for( int i = 0 ; i < t ; i++ )
	{
		int p = 0 ,pp = s ;
		cin >> n ;
		while( true )
		{
			int a = p + ( ( pp - p ) / 2 ) ;
			if( answer( n ,num ,a ) )
				break ;
			else if( n > num[ a ] )
			{
				if( answer( n ,num ,a + 1 ) )
					break ;
				p = a + 1 ;
				if( p == pp )
					break ;				
			}
			else if( answer( n ,num ,a - 1 ) )
				break ;
			else
			{
				pp = a - 2 ;
				if( pp <= p )
					break ;
			}
		}
	}

	cout << ans << endl ;

	return 0 ;
}

Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int NIL = -1;
const int INF = (1<<21);
const long long MOD = 1e9+7;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};


int main() {
  int N, K; cin >> N >> K;
  vector<int> v(N);
  for (int i = 0; i < N; ++i) cin >> v[i];
  int ans = 0;
  for (int l = 0; l <= K; ++l) {
    for (int r = 0; l + r <= K; ++r) {
      if (l + r > N) continue;
      int d = K - (l + r);
      vector<int> s;
      int now = 0;
      for (int i = 0; i < l; ++i) {
        now += v[i];
        s.push_back(v[i]);
      }
      for (int i = N-1; i >= N-r; i--) {
        now += v[i];
        s.push_back(v[i]);
      }
      sort(s.begin(), s.end());
      for (int i = 0; i < d; ++i) {
        if (i >= s.size()) break;
        if (s[i] > 0) break;
        now -= s[i];
      }
      ans = max(now, ans);
    }
  }
  cout << ans << endl;
}


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

using namespace std;
using ll = long long;

int main() {
    int n,k;
    cin>>n>>k;
    vector<pair<ll,ll>> d;
    set<ll> xs,ys;
    for(int i = 0; i < n; ++i){
        ll a,b;
        cin>>a>>b;
        d.emplace_back(a,b);
        xs.insert(a);
        ys.insert(b);
    }
    auto itxl=xs.begin();
    ll ans=5000000000000000000LL;
    while(itxl!=xs.end()) {
        auto itxr=itxl;
        ++itxr;
        while(itxr!=xs.end()) {
            auto ityl=ys.begin();
            while(ityl!=ys.end()) {
                auto ityr=ityl;
                ++ityr;
                while(ityr!=ys.end()) {
                    ll xl=*itxl,xr=*itxr,yl=*ityl,yr=*ityr;
                    int cnt=0;
                    for(int i = 0; i < n; ++i){
                        if(xl<=d[i].first&&d[i].first<=xr&&yl<=d[i].second&&d[i].second<=yr)++cnt;
                    }
                    if(cnt>=k) {
                        ans=min(ans,(xr-xl)*(yr-yl));
                        //break;
                    }
                    ++ityr;
                }
                ++ityl;
            }
            ++itxr;
        }
        ++itxl;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<stdio.h>
using namespace std;

int main(){
	int a;
	int b;
	int c;
	
	cin >> a;
	cin >> b;
	cin >> c;
	
	if(a < b && b < c){
		printf("Yes\n");
	}
		else{
			printf("No\n");
		}
	

	return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<class V, int NV> struct LazySegTree { // [L,R)
    vector<V> dat, lazy; LazySegTree() { dat.resize(NV * 2, def); lazy.resize(NV * 2, ldef); }
    void update(int a, int b, V v, int k, int l, int r) { push(k, l, r); if (r <= a || b <= l) return;
        if (a <= l && r <= b) { setLazy(k, v); push(k, l, r); } else {
        update(a, b, v, k * 2 + 1, l, (l + r) / 2); update(a, b, v, k * 2 + 2, (l + r) / 2, r);
        dat[k] = comp(dat[k * 2 + 1], dat[k * 2 + 2]);}}
    V get(int a, int b, int k, int l, int r) { push(k, l, r); if (r <= a || b <= l) return def;
        if (a <= l && r <= b) return dat[k]; auto x = get(a, b, k * 2 + 1, l, (l + r) / 2);
        auto y = get(a, b, k * 2 + 2, (l + r) / 2, r); return comp(x, y);}
    void update(int a, int b, V v) { update(a, b, v, 0, 0, NV); }
    V get(int a, int b) { return get(a, b, 0, 0, NV); }
    // ---- Template ---------------------------------------------------------------------------------
    
    // 区間add, 区間max
    const V def = 0, ldef = 0;
    V comp(V l, V r) { return max(l, r); }
    void setLazy(int i, V v) { lazy[i] += v; }
    void push(int k, int l, int r) {
        dat[k] += lazy[k];
        if (r - l > 1) { setLazy(k * 2 + 1, lazy[k]); setLazy(k * 2 + 2, lazy[k]); }
        lazy[k] = ldef;
    }
};


int N, M;
LazySegTree<ll, 1 << 18> dp;
vector<pair<int, int>> R[201010];

int main() {
    cin >> N >> M;
    rep(i, 0, M) {
        int l, r, a; cin >> l >> r >> a;
        l--; r--;
        R[r].push_back({ l,a });
    }

    rep(r, 0, N) {
        ll opt = dp.get(0, r);
        dp.update(r, r + 1, opt);
        fore(p, R[r]) {
            int l, a; tie(l, a) = p;
            dp.update(l, r + 1, a);
        }
    }

    ll ans = dp.get(0, N);
    cout << ans << endl;
}

Measured memory_bytes: 22516
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>


#define rep(i,p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

int main(void) {
	string s;
	cin >> s;
	char a, b;
	b = '1';
	a = s[0];
	ll aCount = 0, bCount = 0;
	string ans = "Yes";
	rep(i, 0, 4) {
		if (a == s[i]) aCount++;
		else if (b == '1') b = s[i];
		else if(s[i] != b)ans = "No";
	}
	if (ans == "Yes") {
		rep(i, 0, 4) {
			if (s[i] == b) bCount++;
		}
	}
	if (aCount != 2 || bCount != 2) ans = "No";
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
int main(){
    ll n,k; cin >> k >> n;
    vector<ll> a(n);
    ll ans = 0;
    rep(i,n){
        cin >> a[i];
        
    }
    rep(i,n-1)chmax(ans, a[i+1] - a[i]);
    chmax(ans, k + a[0] - a[n-1]);
    cout << k - ans << endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {

    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h1 = sc.nextInt();
		int m1 = sc.nextInt();
		int h2 = sc.nextInt();
		int m2 = sc.nextInt();
		int k = sc.nextInt();
		
		int h = getHoursToMinutes(h1, h2);
		int m = getMinutes(m1, m2);
	
		int mergin = (h + m) - k;
		// 出力
		System.out.println(mergin);
	}
	
	private static int getHoursToMinutes(int h1, int h2) {
	    return (h2 - h1) * 60;
	}
	
	private static int getMinutes(int m1, int m2) {
	    return m2 - m1;
	}
		
}

Measured memory_bytes: 35784
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int N, M;
    cin >> N >> M;
    string A[N], B[M];
    rep(i,N) cin >> A[i];
    rep(i,M) cin >> B[i];
    int sub = N-M;
    bool ans = true;
    for(int i=0; i<=sub; i++){
        for(int j=0; j<=sub; j++){
            ans = true;
            for(int k=0; k<M; k++){
                for(int l=0; l<M; l++){
                    if(A[i+k][j+l]!=B[k][l]){
                        ans=false;
                    }
                    if(!ans) break;
                }
                if(!ans) break;
            }
            if(ans) break;
        }
        if(ans) break;
    }
    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

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

using namespace std;

typedef long long int ll;

void solve()
{
	int a, b, c, d;
	string s, s1, s2;
	cin >> a;
	cout << fixed << setprecision(10) << 3.14159 * 2 * a << "\n";
}

int main()
{
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
	return 0;
}



Measured memory_bytes: 3784
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

ll n, a[100000 + 10], ans;

int main() {
	rd(n);
	repi(i, 0, n) {
		ll t;
		rd(t);
		if (t > 0) a[t - 1]++;
		a[t]++;
		a[t + 1]++;
	}
	repi(i, 0, 100000 + 10) {
		ans = max(ans, a[i]);
	}
	wrln(ans);
	return 0;
}

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

int main() { 
    int N; cin >> N;
    vector<int> V;
    for (int i=0; i<N; i++) {
        int v; cin >> v;
        V.push_back(v);
    }
    int maxP = 0;
    for (int i=0; i<N; i++) {
        int c; cin >> c;
        if (V[i]-c>0) maxP += (V[i]-c);
    }

    cout << maxP << endl;
    
    return 0;
}

Measured memory_bytes: 888
num = list(input())
n = len(num) - 1

for i in range(2**n):
    temp = [0]*(len(num)+n)
    lst = ["-"]*n
    for j in range(n):
        if i&(1<<j):
            lst[j] = "+"
    temp[::2] = num
    temp[1::2] = lst
    wa = eval("".join(temp[:]))
    if wa == 7:
        print("".join(temp[:]) + "=7")
        exit()

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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define ll long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    int n, m;
    cin >> m >> n;
    vector<int> v(n);
    int sm = 0;
    for(int i=0;i<n;i++)
    {
    	cin >> v[i];
    	sm += v[i];
    }
    if(sm <= m) cout << m - sm  <<  "\n";
    else cout << "-1\n";
    return 0;
}



Measured memory_bytes: 3724
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i), i--;
    vector<vector<int>> G(n);
    int ans = 0;
    if(v.front()) ans++;
    for (int i = 1; i < n; ++i) {
        G[i].emplace_back(v[i]);
        G[v[i]].emplace_back(i);
    }
    deque<int> Q;
    stack<int> s;
    int cnt = 0;
    vector<int> visited(n, 0), num(n);
    s.emplace(0);
    while(!s.empty()){
        int a = s.top(); s.pop();
        visited[a]++;
        num[a] = cnt++;
        Q.emplace_front(a);
        for (auto &&i : G[a]) {
            if(!visited[i]) s.emplace(i);
        }
    }
    vector<int> dp(n, 1);
    while(!Q.empty()){
        int a = Q.front(); Q.pop_front();
        if(!a) continue;
        for (auto &&i : G[a]) {
            if(num[i] > num[a]){
                int p = dp[i]+1;
                if(p > k){
                    ans++;
                    p = 1;
                }
                dp[a] = max(dp[a], p);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 8320
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

const int dy[4]={1,0,-1,0};
const int dx[4]={0,1,0,-1};
int main(){
    int H,W; cin>>H>>W;
    vector<vector<char>>a(H,vector<char>(W));
    vector<vector<int>>dist(H,vector<int>(W,-1));
    queue<pair<int,int>>q;
    rep(i,H){
        rep(j,W){
            cin>>a[i][j];
            if(a[i][j]=='#'){
                dist[i][j]=0;
                q.push(make_pair(i,j));
            }
        }
    }
    int cnt=0;
    while(!q.empty()){
        int y=q.front().first,x=q.front().second;
        q.pop();
        rep(k,4){
            int ny=y+dy[k],nx=x+dx[k];
            if(ny<0||nx<0||ny>=H||nx>=W)continue;
            if(dist[ny][nx]!=-1)continue;
            dist[ny][nx]=dist[y][x]+1;
            q.push(make_pair(ny,nx));
        }
        cnt++;
    }
    //cout<<cnt<<endl;
    int mx=0;
    rep(i,H){
        rep(j,W){
            mx=max(mx,dist[i][j]);
        }
    }
    cout<<mx<<endl;
}


Measured memory_bytes: 13456
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class APoisonousCookies {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int untastyAntidotes = in.nextInt(), tastyAntidotes = in.nextInt(), tastyPoison = in.nextInt();

            int answer = 0;

            answer += Math.min(tastyPoison, untastyAntidotes + tastyAntidotes + 1);
            answer += tastyAntidotes;

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22612
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
s = ["#"*(W+2)] + ["#"+input()+"#" for _ in range(H)] + ["#"*(W+2)]

white = 0
for i in range(1, H+1):
	for j in range(1, W+1):
		if s[i][j] == ".":
			white += 1

dy = [1, 0, -1, 0]
dx = [0, -1, 0, 1]

q = deque()
q.append((1, 1))
dist = [[-1]*(W+2) for _ in range(H+2)]
dist[1][1] = 0
cnt = 0
while q:
	y, x = q.popleft()
	for i in range(4):
		ny = y+dy[i]
		nx = x+dx[i]
		if s[ny][nx] == "." and dist[ny][nx]==-1:
			dist[ny][nx] = dist[y][x]+1
			q.append((ny, nx))

print(white-dist[H][W]-1 if dist[H][W] != -1 else -1)


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

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

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

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

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

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

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

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

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

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

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

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

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

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

int main(){
	ll K;
	cin >> K;


	ll c = 7;
	repn(i, K+1) {
		if (c % K == 0) { cout << i << endl; return 0; }
		c %= K;
		c = c * 10 + 7;
	}
	cout << -1 << endl;


}



Measured memory_bytes: 3616
import java.io.*;
import java.util.*;

public class Main{
    
    public static void main(String[] args) throws IOException {
        int K = in.nextInt();
        int S = in.nextInt();
        int ans = 0;
        for(int X = 0; X <= K; X++){
            for(int Y = 0; Y <= K; Y++){
                int Z = S - (X+Y);
                if(Z >= 0 && Z <= K){
                    ans++;        
                }
            }
        }
        println(ans);
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);
    static void read(int arr[], int N) throws IOException{ for(int i = 0; i < N; i++){ arr[i] = in.nextInt(); } }
    static void read(long arr[], int N) throws IOException{ for(int i = 0; i < N; i++){ arr[i] = in.nextLong(); } }
    static void read(String arr[], int N) throws IOException{ for(int i = 0; i < N; i++){ arr[i] = in.next(); } }
    static void print(Object O){ out.print(O); }
    static void println(Object O){ out.println(O); }
    static void print(int arr[]){ for(int i = 0; i < arr.length; i++){ print(arr[i]+" "); } println(""); }
    static void print(int arr[][]){ for(int i = 0; i < arr.length; i++){ print(arr[i]); } }
    static void debug(Object O){ System.out.println(O); }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) { 
            tokenizer = new StringTokenizer(reader.readLine()); 
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException { 
        return Integer.parseInt(next()); 
    }
    
    double nextDouble() throws IOException { 
        return Double.parseDouble(next());
    }
    
    long nextLong() throws IOException { 
        return Long.parseLong(next()); 
    }
    
    String nextLine() throws IOException { 
        return reader.readLine(); 
    }
    
    void close() throws IOException { 
        reader.close(); 
    }
}

Measured memory_bytes: 22868
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
 
#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
#define setpr(x) cout << setprecision((x))
#define PI atan(1)*4
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mk(a , b) { min((a) , (b)) , max((a) , (b)) }
#define flush cout.flush()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endc "\n"
#define MOD 998244353
#define meme(x) memset((x), 0, sizeof((x)))
#define memo(x) memset((x),-1, sizeof((x)))
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

// #define int ll

ll egcd(ll a, ll b, ll &x, ll &y){
    if (a == 0LL){  
        x = 0LL;  
        y = 1LL;  
        return b;  
    }
    ll xx, yy;
    ll val = egcd(b % a, a, xx, yy);  
    x = yy - (b / a) * xx;  
    y = xx;  
    return val;
}

ll gcd(ll a, ll b){
    while(true){
        if(a>b)
            swap(a,b);
        if (a == 0) 
            return b; 
        ll p = b % a  , q = a;
        a = p;
        b = q;
    }
}
 
ll powerMod(ll x,ll y){
    ll res = 1;
    x %= MOD;
    while(y > 0){
        if(y & 1)res = (res*x)%MOD;
        y = y >> 1;
        x = (x * x)%MOD;
    }
    return res%MOD;
}

//  ==========     //\\       //||     ||====//||
//      ||        //  \\        ||     ||   // ||
//      ||       //====\\       ||     ||  //  ||
//      ||      //      \\      ||     || //   ||
//  ========== //        \\  ========  ||//====|| 
//  code

void solve(){
    int n,i,j,k,l,p;
    cin >> n;
    vector<int> dp(n, 0), h(n);
    for(auto &i : h){
        cin >> i;
    }

    for(int i = 1; i < n; i++){
        dp[i] = dp[i - 1] + abs(h[i - 1] - h[i]);
        if(i >= 2){
            dp[i] = min(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
        }
    }

    cout << dp[n - 1] << endc;
}

int32_t main(){
    init;
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    ll x;
    cin >> x;
    int cnt = 0;
    ll cur = 100;
    while (true)
    {
        cur = floor(cur * 1.01);
        cnt++;
        if (cur >= x)
            break;
    }
    //int ans = ceil(log(x * 1.0 / 100) / log(1.01));
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 3760
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

// Manages Weighted Union-Find Forest.
class WeightedUnionFindForest {
  std::vector<int> parent_;
  std::vector<int> rank_;
  std::vector<int> size_;
  std::vector<int> weight_;

 public:
  // Initialize forest.
  // parent_[i]=i, rank_[i]=0, size_[i]=1, weight_[i]=0.
  WeightedUnionFindForest(int n);
  // Get the number of the root of the node q.
  int Root(int q);
  // Return true if the roots of x and y is same.
  bool IsSame(int x, int y);
  // Unite the tree x and tree y(weight is w).
  // If x and y already have been united, return false.
  // Weight(y)-Weight(x)=w
  bool Unite(int x, int y, int w);
  // Get the number of nodes which are the same group as node q.
  int Size(int q);
  // Get the weight of node q.
  int Weight(int q);
  // Get the weights' difference of node x and y(Weight(y)-Weight(x)).
  int Diff(int x, int y);
};

WeightedUnionFindForest::WeightedUnionFindForest(int n) {
  for (int i = 0; i < n; i++) {
    parent_.push_back(i);
    rank_.push_back(0);
    size_.push_back(1);
    weight_.push_back(0);
  }
}
int WeightedUnionFindForest::Size(int q) {
  return size_[Root(q)];
}
int WeightedUnionFindForest::Root(int q) {
  if (parent_[q] == q) {
    return q;
  } else {
    int r = Root(parent_[q]);
    weight_[q] += weight_[parent_[q]];
    return parent_[q] = r;
  }
}

bool WeightedUnionFindForest::IsSame(int x, int y) {
  return Root(x) == Root(y);
}

int WeightedUnionFindForest::Weight(int q) {
  Root(q);  // compress path
  return weight_[q];
}
int WeightedUnionFindForest::Diff(int x, int y) {
  if (Root(x) != Root(y)) {
    cerr << "WeightedUnionFindForest: Error" << endl;
    cerr << "Roots of node x and y aren't same" << endl;
    return INT32_MAX;
  }
  return Weight(y) - Weight(x);
}

bool WeightedUnionFindForest::Unite(int x, int y, int w) {
  w += Weight(x);
  w -= Weight(y);
  x = Root(x);
  y = Root(y);

  if (x == y) return false;
  if (rank_[x] < rank_[y]) {
    weight_[x] = w * (-1);
    parent_[x] = y;
    size_[y] += size_[x];
    size_[x] = 0;

  } else {
    weight_[y] = w;
    parent_[y] = x;
    size_[x] += size_[y];
    size_[y] = 0;
    if (rank_[x] == rank_[y]) rank_[x]++;
  }
  return true;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;

  WeightedUnionFindForest WUFF(n + 1);
  for (int i = 0; i < m; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    if (WUFF.IsSame(l, r)) {
      if (WUFF.Diff(l, r) == d) {
        // no conflict
      } else {
        // conflict
        cout << "No" << endl;
        exit(0);
      }
    } else {
      WUFF.Unite(l, r, d);
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

using namespace std;

string s;
int a,b; 
bool ism(int k){
        return (0 < k && k <=12);
}
 
int main(){

        cin >> s;
 
        a = (s[0] - '0')*10 + s[1]-'0';
        b = (s[2] - '0')*10 + s[3]-'0';

        if (ism(a) && ism(b)) {
                cout << "AMBIGUOUS" << endl;
        } else if (ism(a)) {
                cout << "MMYY" << endl;
        } else if (ism(b)) {
                cout << "YYMM" << endl;
        } else {
                cout << "NA" << endl;
        }
 
 
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    vector<int> A(200000);
    vector<int> B(200000);
    cin >> N;
    for(int i=0;i<N-1;i++){
        cin >> A.at(i);
        B.at(A.at(i)-1)++;
    }
    for(int i=0;i<N;i++){
        cout <<B.at(i)<<endl;
    }
}


Measured memory_bytes: 4664
import scala.io.StdIn.readLine

object Main {

  def loop(max:Int, sum:Int, i:Int):Int = {
    i match {
      case 0 => if( sum > max ) sum else max
      case i =>
        val m = readLine().toInt
        val (x,y) =
          if(sum < 0 && m > sum) (max,m)
          else if(m < 0 && sum > max) (sum,sum+m)
          else (max, sum+m)
        loop(x,y,i-1)
    }
  }

  def main(args: Array[String]) = {
    val b = new StringBuilder

    var n = readLine().toInt
    while(n!= 0) {
      b.append(loop(-100000, readLine().toInt, n-1).toString)
      b.append("\n")
      n = readLine().toInt
    }

    print(b.result)
  }
}

Measured memory_bytes: 44044
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>
long a,b,s;
int main(){
scanf("%ld %ld",&a,&b);
b-=a;
s=0;
for(int i=0;i<b;i++){
s+=i;
}
printf("%ld",s-a);
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

vector<vector<int> > graph;
int n, m;

int main(){
  cin >> n >> m;
  graph.resize(n);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  bool ans = false;
  rep(i, graph[0].size()){
    int t = graph[0][i];
    rep(j, graph[t].size()){
      if(graph[t][j] == n - 1) ans = true;
    }
  }

  if(ans) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 12016
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long int ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const int MOD = 1000000007;
const int INF = INT_MAX;

int main(int argc, char const *argv[])
{
    int n;
    string s;
    cin >> n >> s;


    int cnt = 0;
    for (int i=0; i < n-2; i++){
        if (s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') cnt++;
    }


    cout << cnt << endl;
    

    return 0;
}




//              g++ -std=c++1z  

Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stdio.h>

using namespace std;


long long a[100005]; 
int main()
{
    long long n,k;
    cin>>n>>k;
    for(long long i=0;i<n;i++)
    cin>>a[i];
    cout<<(n-1)/(k-1)+((n-1)%(k-1)!=0)<<endl;
   // system("pause");
    return 0;
}   
    

Measured memory_bytes: 1024
#include <iostream>
#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 <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

struct UnionFind{
    
    vector<int> M_par;
    vector<int> M_rank;
    vector<int> M_size;

private:
    void init(int n = 1){
        M_par.resize(n);
        M_rank.resize(n);
        M_size.resize(n);
        for(int i = 0; i < n; i++){
            M_par[i] = i;
            M_rank[i] = 0;
            M_size[i] = 1;
        }
    }

public:

    UnionFind(size_t n = 1){
        init(n);
    }

    size_t find(size_t x){
        if(M_par[x] == x) return x;
        size_t r = find(M_par[x]);
        return M_par[x] = r;
    }
    
    bool same(size_t x, size_t y){
        return find(x) == find(y);
    }

    bool unite(size_t x, size_t y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(M_rank[x] < M_rank[y]) swap(x, y);
        if(M_rank[x] == M_rank[y]) M_rank[x]++;
        M_par[y] = x;
        M_size[x] = M_size[x] + M_size[y];
        return true;
    }

    size_t size(size_t x){
        return M_size[find(x)];
    }

};

int main() {
  

  int n, q; cin >> n >> q;
  UnionFind uf(n);
  for (int i = 0; i < q; i++) {
    int t; cin >> t;
    int u, v; cin >> u >> v;
    if (t == 0) {
      uf.unite(u, v);
    } else {
      cout << uf.same(u, v) << endl;
    }
  }
  return 0;
}


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

// clang-format off
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<string> v;
    map<string, int> mp;
    rep (i, n) {
        string s;
        cin >> s;
        sort(all(s));
        mp[s]++;
    }
    int ans = 0;
    repall (e, mp) {
        int x = e.second;
        ans += x * (x - 1) / 2;
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <set>
#include <queue>
#include <stdbool.h>

#define LL long long
#define inf 0x3f3f3f3f
using namespace std;
const int MAXN=200005;
typedef struct Node{
    int val;
    int index;
}Node;

bool cmp(Node a,Node b)
{
    return a.val < b.val;
}
int n;
Node a[MAXN];

int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++) {
        cin >> a[i].val;
        a[i].index = i;
    }
    sort(a+1,a+1+n,cmp);
    int cnt = n;
    int j = 1;
    while (cnt--)
    {
        int i = n;
        while (a[i].index == j)
        {
            i--;
        }
        printf("%d\n",a[i].val);
        j++;
    }
    return 0;
}

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

using namespace std;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 8;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

int main(){
//	freopen("ex.in", "r", stdin);
//	freopen("ex.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	long long n; cin >> n;
	vector<long long> a(n * 3);
	for(long long i = 0; i < n * 3; i++){
		cin >> a[i];
	}
	
	sort(a.begin(), a.end());
	
	long long l = 0, r = n * 3 - 1, ans = 0;
	while(l + 1 < r){
		ans += a[r - 1];
		l++;
		r -= 2;
	}
	
	cout << ans;
	return 0;
}


Measured memory_bytes: 2560
N = int(input())
D, X = map(int, input().split())

A = [int(input()) for _ in range(N)]
ans = [0]*(D+1)
for i in range(N):  
  day = 1
  cnt = 0
  while day <= D:
    ans[day] += 1
    cnt += 1
    day = cnt*A[i]+1
  
print(sum(ans)+X)    
    

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>

using namespace std;

typedef pair<int, int> pii;

struct edge {
    int to, cost;
    edge(int to, int cost) : to(to), cost(cost) {}
};

struct UF {
    vector<int> data;

    UF(int n) {
        data.resize(n, -1);
    }

    int root(int i) {
        return data[i] < 0 ? i : data[i] = root(data[i]);
    }

    int size(int i) {
        return -data[root(i)];
    }

    void unite(int x, int y) {
        x = root(x), y = root(y);

        if (x == y) return ;

        if (size(x) < size(y)) swap(x, y);

        data[x] += data[y];
        data[y] = x;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

vector<edge> G[1010];

int N, M;

int main()
{
    while (cin >> N >> M, N) {
        UF uf(N);

        vector<pair<int, pii>> edges;

        for (int i = 0; i < M; ++i) {
            int s, t, c; cin >> s >> t >> c;

            --s, --t;

            G[s].push_back(edge(t, c));
            G[t].push_back(edge(s, c));

            edges.push_back(make_pair(c, pii(s, t)));
        }

        sort(begin(edges), end(edges));

        vector<int> a;

        for (pair<int, pii> e : edges) {
            int cost = e.first;
            pii info = e.second;
            if (!uf.same(info.first, info.second)) {
                uf.unite(info.first, info.second);
                a.push_back(cost);
            }
        }

        sort(begin(a), end(a));

        cout << a[a.size() / 2] << endl;
    }
}

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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define VS vector<string>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const int INF = 1e9;
const int MOD = 1000000007;
const int N = 22055;
const int M = 15;

void solve() {
    ll n,a,b;
    cin >> n >> a >> b;

    if ((b-a) % 2 == 0){
        cout << (b-a) / 2;
        return;
    }

    ll x = b - 1;
    ll y = n - a;
    ll z;
    if (n-b+1 > a){
        b -= a;
        z = a;
        a = 1;
        z += (b-a+1)/2;
    } else {
        a += n-b+1;
        z = n-b+1;
        b = n;
        z += (b-a+1)/2;
    }

    cout << min(x, min(y,z));

}

int main() {
    //ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) { cin >> A[i]; }

  int right = 0;
  int sum = 0;
  int64_t answer = 0;
  rep(left, N) {
    while (right < N && (sum ^ A[right]) == (sum + A[right])) {
      sum += A[right];
      ++right;
    }
    answer += (int64_t)(right - left);
    sum -= A[left];
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string S;
    cin>>S;
    
    stack<char> stk;
    for(int i=0;i<S.size();i++){
        if(stk.empty())stk.push(S[i]);
        else if(S[i]=='S')stk.push(S[i]);
        else if(S[i]=='T'&&stk.top()=='S')stk.pop();
        else stk.push(S[i]);
    }
    
    cout<<stk.size();
}


Measured memory_bytes: 644
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;


int main(void){
 int X,Y;

 cin>>X>>Y;
 std::cout<<X+Y/2<<std::endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int judge(int S[], int n, int key){
  int i = 0;
  S[n] = key;
  while(S[i] != key) i++;
  return i != n;
}

int main(){
  int S[10001], i, n, q, key, sum = 0;
  scanf("%d",&n);
  for( i = 0; i < n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for( i = 0; i < q; i++){
    scanf("%d",&key);
    if(judge(S, n, key)) sum++;
  }
  printf("%d\n",sum);
  
  return 0;
}

Measured memory_bytes: 636
n = int(input())
lis = [str(input()) for i in range(n)]
lis.sort()
cnt = 1
li = []
for i in range(n-1):
    if lis[i] == lis[i+1]:
        cnt += 1
    else:
        li.append([lis[i],cnt])
        cnt = 1
li.append([lis[-1],cnt])
li.sort(key = lambda x:x[0])
li.sort(key = lambda x:x[1],reverse = True)
num = li[0][1]
for i in range(len(li)):
    if num == li[i][1]:
        print(li[i][0])

Measured memory_bytes: 40484
#include <iostream>
#include <string>
#include <stack>
int main(void)
{
	int i;
	double a,b;
	std::stack <double> num;
	std::string str;
	getline(std::cin,str);
	while(!str.empty()){
		if(str[0]=='+'||str[0]=='-'||str[0]=='*'||str[0]=='/'){
			if(str[0]=='-'&&1<str.size()&&str[1]!=' '){
				num.push(std::stoi(str));
			}
			else{
				a=num.top();num.pop();
				b=num.top();num.pop();
				if(str[0]=='+') num.push(b+a);
				else if(str[0]=='-') num.push(b-a);
				else if(str[0]=='*') num.push(b*a);
				else if(str[0]=='/') num.push(b/a);
			}
		}
		else if(str[0]!=' ') num.push(std::stoi(str));
		for(i=0;i<str.size()&&str[i]!=' ';i++){}
		if(i<str.size()) str=str.substr(i+1);
		else str=str.substr(i);
	}
	std::cout << num.top() << std::endl;
	return 0;
}

Measured memory_bytes: 1264
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h> 
typedef unsigned long long ll;
#define length 100000   //10万
#define kw_len 10
ll factor[300];
ll memory[300]; 
/*素朴法で計算
factorは必ずmemset(factor,0,sizeof(factor));
グローバルであるmemoryに個数を書き込む
memory配列の走査にはfactorの要素を使う*/
void primefac(ll num){
    int i = 0,kosuu=0;
    while(*(factor+i) != 0){
        while(num % *(factor+i)==0){
            num /= *(factor+i);
            memory[*(factor+i)] +=1;
        }
        if(num==1)break;
        i++;
    }
}
/*グローバルにあるfactorに素数書き込む.個数を返すので配列は-1しろ*/
int elast(ll number){    
    ll tmp=0;
    int flag=0;
    *factor = 2;
    for(int i=3;i <= number;i++){
        flag=0;
        for(int j=0;j <= tmp ;j++){
            if(i % (*(factor+j)) == 0){
                flag=1;
                break;
            }
        }
        if(flag)continue;
        tmp += 1;
        *(factor+tmp) = i;
    }
        return tmp+2;
}

int compare(const int*a,const int *b){
    if(*a<*b)
      return -1;
    else if(*a>*b)
      return 1;
    return 0;
}

ll nCr(int n,int r){
  ll val=1;
  int i;
  if(r==0)return 1;
  for(i=0;i<n-r;i++){
		val *= (n-i);
		val /= (i+1);
	}
  return val;
}

ll nPr(int n,int r){
  ll val=1;
  int i;
  for(i=0;i<r;i++){
    val *= (n-i);
  }
  return val;
}
/*
qsort(array,length,sizeof(int),(int(*)(const int*, const int*))compare);
使う時これをコピペ
*/
int main(){
    ll N,K,i,j,flag;
    int *inp;
    ll sum=99999999999999;
    scanf("%llu",&N);
    for(i=1;i<1000006;i++){
        if(N%i==0){
          if(sum > (i+(N/i)-2)){
              sum = (i+(N/i)-2);
              flag = 1;
          }  
        }
    }
    if(flag){
        printf("%llu",sum);
    }
    else{
        printf("%llu",N-1);
    }
    return 0;
}


Measured memory_bytes: 128