akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef long long ll;

long long mod=1000000007;

int dsort(const void *A,const void *B){return *(ll*)A<*(ll*)B?1:0;}

int main(void){
    ll n,m,ans=1;
    scanf("%lld%lld",&n,&m);
    ll a[n],b[m];
    for (int i=0; i<n; i++){
        scanf("%lld",&a[i]);
    }
    for (int i=0; i<m; i++){
        scanf("%lld",&b[i]);
    }
    qsort (a,n,sizeof(ll),dsort);
    for (int i=0; i<n-1; i++){
        if (a[i]==a[i+1]){
            printf("0\n");
            return 0;
        }
    }
    qsort (b,m,sizeof(ll),dsort);
    for (int i=0; i<m-1; i++){
        if (b[i]==b[i+1]){
            printf("0\n");
            return 0;
        }
    }
    ll countn=0,countm=0,occ=0,grid=0,countx=0,county=0;
    for (int i=n*m; i>0; i--){
        if (countn==n){
            countn--;
        }
        if (countm==m){
            countm--;
        }
        if (a[countn]==i && b[countm]==i){
            countn++;
            countm++;
            grid+=countx+county+1;
            countx++;
            county++;
            occ++;
        } else if (a[countn]==i){
            countn++;
            ans=(ans*county)%mod;
            grid+=county;
            countx++;
            occ++;
        } else if (b[countm]==i){
            countm++;
            ans=(ans*countx)%mod;
            grid+=countx;
            county++;
            occ++;
        } else {
            ans=(ans*(grid-occ))%mod;
            occ++;
        }
        //printf("%lld %lld %lld\n",ans,grid,occ);
    }
    printf("%lld\n",ans);
    return 0;
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int N, A, B; cin >> N >> A >> B;
    cout << min( N * A, B ) << endl;

}


Measured memory_bytes: 256
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def nPr(n: int, r: int) -> int:
    return math.factorial(n) // math.factorial(n - r)


def nCr(n: int, r: int) -> int:
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def solve(N: int, M: int):
    return (nCr(N, 2)if N > 1 else 0) + (nCr(M, 2) if M > 1 else 0)


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    print(f'{solve(N, M)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 75192
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D[] = new int[N];
		for(int i = 0; i < N; i++) {
			D[i] = sc.nextInt();
		}
		int M = sc.nextInt();
		int T[] = new int[M];
		for(int i = 0; i < M; i++) {
			T[i] = sc.nextInt();
		}
		Arrays.sort(D);
		Arrays.sort(T);
		int cnt = 0;
		out : for(int i = 0; i < M; i++) {
			for(int j = cnt; j < N; j++) {
				if(T[i] == D[j]) {
					if(i == M - 1) {
						System.out.println("YES");
						return;
					} else {
						cnt = j + 1;
						continue out;
					}
				}
			}
			System.out.println("NO");
			return;
		}
	}
}


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

#define DEBUG_MSG_off

int N;
vector<string> s_list;
vector<int> v_list;
priority_queue<int> pque;

int main() {
  cin >> N;
  s_list.resize(N);
  for(int i=0;i<N;i++) {
    int tmp;cin >> tmp;
    pque.push(tmp);
  }

  int arc_last = -1;
  int abc_last = -1;
  for (int i=0;i<(N/2);i++) {
    if (i!=(N/2-1)) {
      pque.pop();
    } else {
      arc_last = pque.top();
      pque.pop();
    }
  }
  abc_last = pque.top();
  int res = arc_last - abc_last;
  cout << res << "\n";
#ifdef DEBUG_MSG
  cerr << arc_last << " " << abc_last << endl;
#endif

#ifdef DEBUG_MSG
  cerr << N << "\n";
  while(!pque.empty()) {
    cerr << pque.top() << " ";
    pque.pop();
  }
  cerr << endl;
#endif
  return 0;
}

Measured memory_bytes: 1660
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define RREP(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define ALL(vector) vector.begin(), vector.end()

const int mod = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll 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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, C, D;
    cin>>A>>B>>C>>D;
    mint ans;
    vector< vector<mint> > DP0(C+1, vector<mint>(D+1, 0));
    vector< vector<mint> > DP1(C+1, vector<mint>(D+1, 0));
    for(ll i = A; i < C+1; i++){
        for(ll j = B; j < D+1; j++){
            if(i==A & j==B){
                DP1[i][j]=1;
                continue;
            }
            DP0[i][j] = DP0[i-1][j]*j + DP1[i-1][j]*j;
            DP1[i][j] = DP0[i][j-1] + DP1[i][j-1]*i;
        }
    }
    ans = DP0[C][D] + DP1[C][D];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 144068
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

int N, T, A;
vector<vector<int>> adj;
vector<int> depth, parent, deepest;

void dfs(int node, int par) {
    parent[node] = par;
    depth[node] = par < 0 ? 0 : depth[par] + 1;
    deepest[node] = 0;

    for (int neighbor : adj[node])
        if (neighbor != par) {
            dfs(neighbor, node);
            deepest[node] = max(deepest[node], deepest[neighbor] + 1);
        }
}

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

    cin >> N >> T >> A;
    T--; A--;
    adj.assign(N, {});

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

    depth.resize(N);
    parent.resize(N);
    deepest.resize(N);
    dfs(A, -1);

    int start = depth[T];
    int up = (start - 1) / 2;

    for (int i = 0; i < up; i++)
        T = parent[T];

    cout << depth[T] + deepest[T] - 1 << '\n';
}


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

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

typedef long long ll;

int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    n = min(n,b-1);
    cout<<a*n/b-a*(n/b)<<endl;
    return 0;
}

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

using namespace std;

int main(void) {
     int n;
    cin >> n;
    vector<string> free;
    //int ans = 0;

    for(int i = 0; i < n; i++){
        string tmp;
        cin >> tmp;
        free.push_back(tmp);
    }
    sort(free.begin(), free.end());
    auto itr = unique(free.begin(), free.end());
    free.erase(itr, free.end());

    cout << free.size() << endl;

    return 0;
}


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

int main() {
	int n, depth = 0;
	string s, ans;
	cin >> n >> s;
	for(int i = 0; i < n; i++){
		if (s[i] == '(') depth++;
		else if(depth) depth--;
			else ans = "(" + ans; 
		ans += s[i];
	}
	if (depth) for(int i = 0; i < depth; i++) ans += ")";
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using pii = pair<int, int>;
const int MOD = (int)1e9 + 7, INF = (1 << 27); const ll INFLL = (1LL << 55);
#define FOR(i,a,b) for(int (i)=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
template<typename T> void dbg(T x) { cout << x << "\n"; }
template<typename T, typename U> static void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void chmax(T &x, U y) { if (x < y) x = y; }



int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    int n; cin >> n;
    static ll d[333][333];
    rep(i, n) rep(j, n) cin >> d[i][j];

    bool ignore[333][333] = {{0},{0}};
    bool ng = false;
    rep(i, n) FOR(j, i + 1, n) rep(k, n) {
        if (k == i || k == j) continue;
        ll ld = d[i][k] + d[k][j];
        if (ld < d[i][j]) ng = true;
        if (ld == d[i][j]) ignore[i][j] = ignore[j][i] = true;
    }

    ll ans = 0;
    rep(i, n) FOR(j, i + 1, n) if (!ignore[i][j]) ans += d[i][j];
    cout << (ng ? -1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string a[3] = {"Sunny", "Cloudy", "Rainy"};
  string s;
  string ans;
  cin >> s;
  for (int i=0; i<3; i++) {
    if (s==a[i]) ans = a[(i+1)%3];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <limits>

int main() {

    int64_t N;
    std::cin >> N;

    std::map<std::string, int64_t> goods;

    for (int64_t i = 0; i < N; ++i) {
        std::string S;
        std::cin >> S;
        goods[S] = 0;
    }

    std::cout << goods.size() << std::endl;

    return 0;
}

Measured memory_bytes: 19116
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

b = [[0]*w for _ in range(h)]

def dfs(i=0, j=0):
    if not (0 <= i < h and 0 <= j < w):
        return
    elif a[i][j] == ".":
        return
    elif b[i][j]:
        return
    else:
        b[i][j] = 1
        dfs(i+1, j)
        dfs(i, j+1)
        for i in range(h):
            for j in range(w):
                if a[i][j] == "#" and b[i][j] == 0:
                    print("Impossible")
                    exit()
        print("Possible")
        exit()

dfs()

Measured memory_bytes: 38384
#include <iostream>
#include <string.h>


using namespace std;

int sum,ans;
int map[3][3];
int dp[3][3][15];
int move(int x,int y,int n)
{
  int a = 0;
  //  cout<<x<<" "<<y<<" "<<n<<" "<<endl;
  if(dp[x][y][n]!=-1)
    return dp[x][y][n];
  if(n==0)
    {
      if(map[y][x]==1)
	return 1;
      else return 0;
    }


  if(x-1>=0 && map[y][x-1]!=-1)
     a+= move(x-1,y,n-1);
  else
    a+=  move(x,y,n-1);

  if(y-1>=0 && map[y-1][x]!=-1)
     a+= move(x,y-1,n-1);
  else
    a+=  move(x,y,n-1);

  if(x+1<3 && map[y][x+1]!=-1)
    a+=  move(x+1,y,n-1);
  else
    a+=  move(x,y,n-1);

  if(y+1<3 && map[y+1][x]!=-1)
    a+=  move(x,y+1,n-1);
  else
    a+=  move(x,y,n-1); 

  dp[x][y][n]=a;

  return a;
}

int main()
{
  int n;

  for(;;)
    {
      cin>>n;
      if(n==0)
	break;
      char s,t,b;
      sum=0;
      ans=0;
      cin>>s>>t>>b;
      memset(map,0,sizeof(map));
      memset(dp,-1,sizeof(dp));
      int x,y,tm;
      tm=t-'A';
      x=tm%3;
      y=tm/3;
      map[y][x]=1;
      tm=b-'A';
      x=tm%3;
      y=tm/3;
      map[y][x]=-1;

      tm=s-'A';
      ans = move(tm%3,tm/3,n);
      sum=4;
      for(int g=1;g<n;g++)
	sum *=4;
      cout<<(double)ans/sum<<endl;  
    }
}

Measured memory_bytes: 1232
n = int(input())
S = [int(l) for l in input().split(' ')]
kn = int(input())
T = [int(l) for l in input().split(' ')]

def binary_search(k,A,n):
  left = 0
  right = n
  while left < right:
    mid = (left + right)//2
    if A[mid] == k:
      return True
    elif A[mid] < k:
      left = mid + 1
    else:
      right = mid
  return False

sum = 0
for t in T:
  if binary_search(t,S,n):
    sum += 1
print(sum)


Measured memory_bytes: 16900
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int x; cin >> x;
    int ans = 1;

    rep(i,x-2){
        int tmp = i+2;
        while(tmp <= x){
            tmp *= i+2;
            if(tmp <= x) ans = max(ans,tmp);
        }
    }

    cout << ans << endl;
}
    

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

using namespace std;

int main(void) {
	int t;
	char txt[100];
	scanf("%d", &t);
	scanf("%s", txt);

	int tmp = strlen(txt);

	if(t >= tmp)
		printf("%s\n", txt);
	else {
		for(int i=0; i<t; i++) {
			printf("%c", txt[i]);
		}
		printf("...\n");
	}

	return 0;
}

Measured memory_bytes: 3764
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <climits>
#include <cmath>
#include <algorithm>
#include <cassert>

#define TEST_ASSERT(msg, cond) do { if (cond) { cout << msg << " => pass" << endl;} else { cout << msg << " => failed" << endl;} } while(0)

using namespace std;

int main() {

  int n;
  cin >> n;
  vector<int> A(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  int cnt = 0;
  while (true) {
    bool isAllEven = true;
    for (int i = 0; i < A.size(); i++) {
      if (A[i] & 0x1) {
        isAllEven = false;
      }
    }
    if (!isAllEven) break;

    for (int i = 0; i < A.size(); i++) {
      A[i] = A[i] >> 1;
    }
    cnt++;
  }
  cout << cnt << endl;

  return 0;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    int r,s,p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    int a = t.size();
    int ans = 0;
    for(int i = k;i < n;i++){
        if(t[i] == t[i-k])t[i] = 'm';
    }
    rep(i,a){
        if(t[i] == 'r') ans += p;
        if(t[i] == 's') ans += r;
        if(t[i] == 'p') ans += s;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int main(){
	boost;
	int m,d;
	cin>>m>>d;
	int ans=0;
	for (int i = 1; i <= m; ++i)
		for (int j = 10; j <= d; ++j)
			if(((j/10)*(j%10))==i&&(j/10)>=2&&(j%10)>=2)ans++;
	cout<<ans;
	return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

#define MAX_N (1<<18) //260000
template<typename T>
struct segtree{
    int n;
    T dat[2*MAX_N-1];
    T cnt[2*MAX_N-1];

    void init(int n_){
        n = 1;
        while(n < n_) n *= 2;
        for(int i = 0; i < 2*n-1; i++) dat[i] = 0;
        for(int i = 0; i < 2*n-1; i++) cnt[i] = 0;
    }

    void update(int k, T a){
        k += n-1;
        dat[k] = a;
        cnt[k]++;
        while(k > 0){
            k = (k-1)/2;
            dat[k] = dat[k*2+1] + dat[k*2+2];
            cnt[k] = cnt[k*2+1] + cnt[k*2+2];
        }
    }

    //(a,b,0,0,seg.n)で呼ぶ
    T query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return 0;
        if(a <= l && r <= b) return dat[k];
        else{
            T vl = query(a,b,k*2+1,l,(l+r)/2);
            T vr = query(a,b,k*2+2,(l+r)/2,r);
            return vl + vr;
        }
    }

    int bin(int k, int mid){
        if (k >= n-1) {
            return k-(n-1);
        }
        if (cnt[k*2+1] >= mid) bin(k*2+1, mid);
        else bin(k*2+2, mid - cnt[k*2+1]);
    }
};

int q;
int q1 = 0;
ll a[200000], b[200000];
int o[200000];
set<pl> s;
map<pl, int> pos;
int rpos[200000];
segtree<ll> seg;

int main() {
    cin >> q;
    seg.init(q);
    rep(i,q) {
        cin >> o[i];
        if (o[i] == 1) {
            cin >> a[q1] >> b[q1];
            s.insert(pl(a[q1],i)); q1++;
        }
    }
    {
        int i = 0;
        for (auto it = s.begin(); it != s.end(); it++) {
            rpos[i] = (*it).first;
            pos[*it] = i++;
        }
    }
    q1 = 0;
    ll B = 0;
    rep(i,q) {
        if (o[i] == 1) {
            //cerr << pos[a[q1]] << " " << a[q1] << endl;
            seg.update(pos[pl(a[q1],i)], a[q1]);
            B += b[q1];
            q1++;
        } else {
            int pos = seg.bin(0, (q1+1)/2);
            cout << rpos[pos] << " ";
            if (q1%2) {
                cout << B + -1 * seg.query(0, pos, 0, 0, seg.n) + seg.query(pos+1, seg.n, 0, 0, seg.n) << endl;;
            } else {
                cout << B + -1 * seg.query(0, pos+1, 0, 0, seg.n) + seg.query(pos+1, seg.n, 0, 0, seg.n) << endl;;
            }
            //cout << seg.bin()+B << endl;
        }
    }
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"
#define int ll

double getper(int a,int b){
  return 1.*(100*b)/(a+b);
}

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

  int A,B,C,D,E,F;
  cin>>A>>B>>C>>D>>E>>F;
  vector<int>AB;
  for(int i=0;i*A*100<=F;i++){
    for(int j=0;j*B*100<=F;j++){
      if(i*A+j*B>F)continue;
      if(i==0&&j==0)continue;
      AB.push_back(i*A+j*B);
    }
  }
  sort(rng(AB));
  ll ansAB=0;
  ll ansCD=0;
  double per=0;
  for(int i=0;i<=3000;i++){
    for(int j=0;j<=3000;j++){
      int CD=i*C+j*D;
      auto it=lower_bound(rng(AB),1.*CD/E);
      if(it==AB.end())continue;
      if(*it*100+CD>F)continue;
      if(per<=getper(*it*100,CD)){
        ansAB=*it;
        ansCD=CD;
        per=getper(*it*100,CD);
      }
    }
  }
  cout<<ansAB*100+ansCD<<" "<<ansCD<<endl;
  return 0;
}


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

int main()
{
	int n;
	cin >> n;
	vector<long long> dp(n + 1, 1);
	for (int i = 2; i <= n; i++) {
		dp[i] = dp[i - 2] + dp[i - 1];
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)1e5 + 7;
const int infint = (int)1e9;
string s;
int a[26];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> s;
	for (int i = 0; i < s.size(); i++)
		a[s[i] - 'a'] = 1;
	for (int i = 0; i < 26; i++)
		if(a[i] == 0)
		{
			cout << s;
			cout << (char)('a' + i);
			return 0;
		}
	vector<int> p, q;
	for (int i = 0; i < s.size(); i++)
		p.push_back(s[i] - 'a'), q.push_back(s[i] - 'a');
	if(next_permutation(p.begin(), p.end()) == 0)
		return cout << -1, 0;
	for (int i = 0; i < p.size(); i++)
	{
		cout <<(char)(p[i] + 'a');
		if(p[i] != q[i])
			break;
	}
}

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

int main(){
    int n,x[100],y[100];
    double sum[4];
    cin >> n;
    for(int i=0;i<n;i++) cin >> x[i];
    for(int j=0;j<n;j++) cin >> y[j];
    for(int k=0;k<4;k++) sum[k] = 0.0;
    for(int p=1;p<4;p++){
        for(int i=0;i<n;i++){
            sum[p] += pow(fabs(x[i]-y[i]),p);
        }
        sum[p] = pow(sum[p],1.0/p);
    }
    for(int i=0;i<n;i++){
        sum[0] = (sum[0]<fabs(x[i]-y[i])?fabs(x[i]-y[i]):sum[0]);
    }
    printf("%f\n%f\n%f\n%f\n",sum[1],sum[2],sum[3],sum[0]);
    return 0;
}


Measured memory_bytes: 3340
#include<bits/stdc++.h>
#define rank Gacho_0716
#define M 1000000007
using namespace std;

class UF{
public:
  int V;
  vector<int> par,rank;
  UF(){}
  UF(int V):V(V),par(V),rank(V,0){for(int i=0;i<V;i++)par[i]=i;}
  
  int find(int x){
    assert(x < V);
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(rank[x]<rank[y])par[x]=y;
    else{
      par[y]=x;
      if(rank[x]==rank[y])rank[x]++;
    }
  }

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

set<int> memo;

int main(){
  
  while(1){
    
    int n, m;
    
    cin>>n>>m;
    if(!n&&!m) break;
    
    UF uf = UF(n);
    
    for(int i=0;i<m;i++){
      int a, b;
      cin>>a>>b;
      a--, b--;
      uf.unite(a,b);
    }
    
    memo.clear();
    
    for(int i=0;i<n;i++) memo.insert(uf.find(i));
    
    int x=1, y=1;
    
    for(int i=0;i<n;i++) x=x*2%M;
    
    for(int i=0;i<memo.size();i++) y=y*2%M;

    cout<<(y%M + (x!=y))%M<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 8644
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <list>
#include <ctime>
#include <random>
using namespace::std;
 
int main(){
	int d, n; cin >> d >> n;
	if(d==0){
		if(n!=100) cout << n;
      	else cout << 101;
	} else if(d==1){
		if(n!=100) cout << 100*n;
      	else cout << 10100;
	} else{
		if(n!=100) cout << 10000*n;
      	else cout << 1010000;
	}
 
 
	return 0;
 
}

Measured memory_bytes: 256
using System;

namespace ABC086A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            if (a*b%2==0)
                Console.WriteLine("Even");
            else
                Console.WriteLine("Odd");

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  if(S.at(0) != S.at(1) && S.at(0) != S.at(2) && S.at(1) != S.at(2)){
  cout << "Yes";
  }else{
  cout << "No";
  }
}


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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n); i >= 0; i--)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define RREP(i, a, n) for(int i = (int)(n); i >= a; i--)
#define all(x) (x).begin(),(x).end()

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; }

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    if( s[2] == s[3] && s[4] == s[5] ) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1<<30;
const ll MOD = 1000000007;

int main(void) {

    int n; cin >> n;
    cout << n*n << endl;
    return 0;
}

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

void main()
{
    auto N = readln.chomp.to!int;
    auto T = new int[][N];
    foreach (_; 1..N) {
        auto ab = readln.split.to!(int[]);
        auto a = ab[0]-1;
        auto b = ab[1]-1;
        T[a] ~= b;
        T[b] ~= a;
    }
    int p1, max_l;
    void run1(int i, int p, int l) {
        if (max_l < l) {
            max_l = l;
            p1 = i;
        }
        foreach (j; T[i]) if (j != p) run1(j, i, l+1);
    }
    run1(0, -1, 0);
    int run2(int i, int p, int l) {
        int ll = l;
        foreach (j; T[i]) if (j != p) ll = max(ll, run2(j, i, l+1));
        return ll;
    }
    auto len = run2(p1, -1, 1);
    writeln((len-2)%3 == 0 ? "Second" : "First");
}

Measured memory_bytes: 36040
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	string s, t,temp;
	cin >> s >> t;
	temp = s;
	for (int i = 0; i < s.length(); i++) {
		if (s == t) {
			cout << "Yes" << endl;
			return 0;
		}
		
		s = temp[temp.length()-1] + temp.substr(0, temp.length() - 1);
		temp = s;
	}


	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int N;
int ta[1000][2];

int main(){
    long long t,a;
    cin >> N;
    for(int i=0;i<N;i++) cin >> ta[i][0] >> ta[i][1];
    t = ta[0][0];
    a = ta[0][1];
    long long sum = t + a;
    long long m;
    int tas;
    for(int i=1;i<N;i++){
        tas = ta[i][0] + ta[i][1];
        if(sum % tas != 0){
            m = tas - (sum % tas);
            sum += m;
        }
        long long tt = sum / tas * ta[i][0];
        long long aa = sum / tas * ta[i][1];
        if(tt >= t && aa >= a){
            t = tt;
            a = aa;
            continue;
        }
        long long ttt = (t - tt) / ta[i][0];
        if((t - tt)%ta[i][0] != 0) ttt++;
        long long aaa = (a - aa) / ta[i][1];
        if((a - aa)%ta[i][1] != 0) aaa++;
        sum += tas * max(ttt,aaa);
        t = sum / tas * ta[i][0];
        a = sum / tas * ta[i][1];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const double eps=1e-7;
const int N=250005;
ll gcd(ll a,ll b)
{
  return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
	return (a*b/gcd(a,b));
}
int main()
{
   ll a,b,c,d,e,ans1,ans2,ans3,ans;
   cin>>a>>b>>c>>d;
   e=lcm(c,d);//cd的最小公倍数//6
   ans1=(a-1)/c+(a-1)/d-(a-1)/e;//前面的
   ans2=b/c+b/d-b/e;//后面的
   ans3=ans2-ans1;//中间的
   ans=b-a+1-ans3;
   cout<<ans<<endl;
   return 0;
}
//1 7 2 3


Measured memory_bytes: 256
main :: IO ()
main = do
  n <- readLn
  if n == -1
    then return ()
    else do
      print $ solve n
      main

solve :: Int -> Int
solve n
  | n <= 10 = 4280 - 1150
  | n <= 20 = 4280 - (1150 + 125 * (n - 10))
  | n <= 30 = 4280 - (2400 + 140 * (n - 20))
  | otherwise = 4280 - (3800 + 160 * (n - 30))

Measured memory_bytes: 3908
#include <bits/stdc++.h>
#define int long long int
#define endl "\n"
#define mod 1000000007
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x
  
using namespace std;
signed main()
{

  std::ios::sync_with_stdio(false);
  cin.tie(); cout.tie();
  int t;
  cin>>t;
  if(t){
    cout<<0<<endl;
  }
  else cout<<1<<endl;
  return 0;
}

Measured memory_bytes: 3648
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
string ma[58];
int main()
{
	int h,w;
	cin>>h>>w;
	rep(i,h) cin>>ma[i];
	rep(i,h) rep(j,w){
		if(ma[i][j]=='#') continue;
		int sum=0;
		REP(x,i-1,i+2) REP(y,j-1,j+2){
			if(x<0 || x>=h || y<0 || y>=w) continue;
			if(ma[x][y]=='#') sum++;
		}
		ma[i][j]=('0'+sum);
	}
	rep(i,h) cout<<ma[i]<<endl;
}


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

using namespace std;

int main(){
	long long int t,n;
	cin>>t>>n;
	long long int count=0;
	while(t--){
		long long int x,y;
		cin>>x>>y;
		if(sqrt(x*x+y*y)<=n)	count++;
	}
	cout<<count<<endl;
}

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

int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < s.size()-1; i++) {
        if(s[i] == s[i+1]) {
            puts("Bad");
            return 0;
        }
    }
    puts("Good");
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] w = new String[n];
    w[0] = in.readLine();
    boolean flg = true;
    for(int i=1; i<n; i++) {
      w[i] = in.readLine();
      if(!w[i-1].substring(w[i-1].length()-1,w[i-1].length()).equals(w[i].substring(0,1))){
        flg = false;
        break;
      }
      for(int j=0; j<i; j++) {
        if(w[i].equals(w[j])){
          flg = false;
          break;
        }
      }
    }
    System.out.println(flg==true?"Yes":"No");
  }
}

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

using namespace std;

#define INF 1000000007
#define LINF 1000000000000000007

typedef long long i64;
typedef pair<i64,i64> P;


int a[26];

int main(){
	int cnt = 0;
	for(int i = 0; i < 4; i++){
		char c;
		cin >> c;
		a[c-'A']++;
		if(a[c-'A'] == 2) cnt++;
	}
	
	if(cnt == 2) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

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

int main(){
    int K,A,B;
    cin >> K >> A >> B;
    if(A/K != B/K){
        cout << "OK" << endl;
    }else if((A % K == 0)||(B % K == 0)){
        cout << "OK" << endl;
    }else{
       cout << "NG" << endl; 
    }
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  int res = 0;
  for (int bith = 0; bith < (1 << H); bith++) {
    for (int bitw = 0; bitw < (1 << W); bitw++) {
      vector<vector<int>> grid(H, vector<int>(W, 0));
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          if (S[i][j] == '.') grid[i][j] = -1;
        }
      }
      for (int i = 0; i < H; i++) {
        if ((bith >> i) & 1) {
          for (int j = 0; j < W; j++) {
            grid[i][j] = -1;
          }
        }
      }
      for (int i = 0; i < W; i++) {
        if ((bitw >> i) & 1) {
          for (int j = 0; j < H; j++) {
            grid[j][i] = -1;
          }
        }
      }
      int cnt = 0;
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          if (grid[i][j] == 0) cnt++;
        }
      }
      if (cnt == K) res++;
    }
  }
  cout << res << '\n';
  return 0;
}


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

typedef long long ll;
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define endl '\n'
const int N = 1e5 + 10;
using namespace std;
int n;
ll colour[N];
vector<pair<int, int>> a[N];

void dfs(int u, int p) {
    for (auto child:a[u]) {
        if (child.first == p) continue;
        colour[child.first] = colour[u] + child.second;
        dfs(child.first, u);
    }
}

int main() {
    IO;
    cin >> n;
    int u, v, w;
    for (int i = 0; i < n - 1; ++i) {
        cin >> u >> v >> w;
        a[u].push_back({v, w});
        a[v].push_back({u, w});
    }
    dfs(1, -1);
    for (int i = 1; i <= n; ++i) {
        cout << colour[i] % 2 <<endl;
    }


}


Measured memory_bytes: 12680
#include<stdio.h>
#include<stdlib.h>
int main(){
	long long sum=0;
	int k,n,max=0;
	int a[200000]={0};
	scanf("%d%d",&k,&n);
	for(int i=0;i<n;i++) {
		scanf("%d",&a[i]);	
		if(i>=1){
			sum+=a[i]-a[i-1];
			if(a[i]-a[i-1]>max) {
				max=a[i]-a[i-1];
			}
		}
	}	
	sum+=(k-a[n-1])+a[0];
	if((k-a[n-1])+a[0]>max) {
		max=(k-a[n-1])+a[0];
	}
	printf("%lld",sum-max);
	return 0;
}

Measured memory_bytes: 896
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a + b >= c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
l,r = list(map(int, input().split()))
if l//2019 != r//2019:
    print(0)
else:
    ans = float("inf")
    for i in range(l,r):
        for j in range(i+1,r+1):
            ans = min(ans,(i*j)%2019)
    print(ans)

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

int main(){
    char x;
    cin >> x;
    if(isupper(x)){
        cout << "A" << endl;
    }else{
        cout << "a" << endl;
    }
}

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

class LinearSearch {
public:
	int n, q;
	vector< int > S, T;
	
	LinearSearch() {}
	
	void solve() {
		int ans = 0;
		
		for (int i = 0; i < q; ++i) {
			int tar = T[i];
			
			for (int j = 0; j < n; ++j) {
				if (S[j] == tar) {
					++ans;
					break;
				}
			}
		}
		
		cout << ans << endl;
	}
};

int main() {
	LinearSearch ls;
	
	cin >> ls.n;
	ls.S.assign(ls.n, 0);
	for (int i = 0; i < ls.n; ++i) cin >> ls.S[i];
	
	cin >> ls.q;
	ls.T.assign(ls.q, 0);
	for (int i = 0; i < ls.q; ++i) cin >> ls.T[i];
	
	ls.solve();
}

Measured memory_bytes: 1228
#include <cstdio>
#include <cstdint>
#include <cctype>
#include <cassert>
#include <vector>
#include <algorithm>
#include <string>

struct Node {
  Node *left=nullptr, *right=nullptr;
  int value;
  Node() {}
  Node(int value): value(value) {}
};

Node *parse(const std::string &s, size_t &i) {
  assert(s[i] == '(');
  Node *cur=new Node;
  if (s[i+1] == ')') {
    i += 2;
  } else {
    cur->left = parse(s, ++i);
    assert(s[i] == ')');
    ++i;
  }
  assert(s[i] == '[');
  ++i;
  assert(isdigit(s[i]));
  int v=s[i]-'0';
  while (++i < s.length() && isdigit(s[i]))
    v = v*10+s[i]-'0';
  cur->value = v;
  assert(s[i] == ']');
  ++i;
  assert(s[i] == '(');
  if (s[i+1] == ')') {
    i += 2;
  } else {
    cur->right = parse(s, ++i);
    assert(s[i] == ')');
    ++i;
  }
  return cur;
}

void dfs(Node *a, Node *b) {
  if (!a || !b) {
    printf("()");
    return;
  }
  if (a->left && b->left) {
    printf("(");
    dfs(a->left, b->left);
    printf(")");
  } else {
    printf("()");
  }
  printf("[%d]", a->value+b->value);
  if (a->right && b->right) {
    printf("(");
    dfs(a->right, b->right);
    printf(")");
  } else {
    printf("()");
  }
}

int main() {
  char buf[1024];
  scanf("%s", buf);
  std::string s=buf;
  scanf("%s", buf);
  std::string t=buf;

  size_t i=0;
  Node *ts=parse(s, i);
  assert(i == s.length());
  i = 0;
  Node *tt=parse(t, i);
  assert(i == t.length());
  dfs(ts, tt);
  printf("\n");
}



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

struct node{
    int key;
    node *p,*l,*r;
};

int n;
node *N;

void tree_insert(node *z){
    node *y=NULL;
    node *x=N;
    while(x!=NULL){
        y=x;
        if(x->key>z->key)x=x->l;
        else if(x->key<z->key)x=x->r;
    }
    z->p=y;
    if(y==NULL)N=z;
    else if(y->key<z->key)y->r=z;
    else y->l=z;
}

void tree_find(int num){
    node *x=N;
    while(x!=NULL){
        if(x->key==num){
            cout<<"yes"<<endl;
            return;
        }
        if(x->key>num)x=x->l;
        else x=x->r;
    }
    cout<<"no"<<endl;
}

void in(node *x){
    if(x->l!=NULL)in(x->l);
    cout<<" "<<x->key;
    if(x->r!=NULL)in(x->r);
}

void pre(node *x){
    cout<<" "<<x->key;
    if(x->l!=NULL)pre(x->l);
    if(x->r!=NULL)pre(x->r);
}

void print(){
    node *x=N;
    in(x);
    cout<<endl;
    pre(x);
    cout<<endl;
}

int main()
{
    N=NULL;
    cin>>n;
    int i;
    for(i=0;i<n;i++){
        string s;
        cin>>s;
        if(s=="insert"){
            int num;
            cin>>num;
            node *z=new node();
            z->key=num;z->l=z->r=z->p=NULL;
            tree_insert(z);
        }
        if(s=="find"){
            int num;
            cin>>num;
            tree_find(num);
        }
        if(s=="print"){
            print();
        }
    }
    return 0;
}

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

static bool ab_array[20'000];
static bool ac_array[20'000];
static bool bc_array[20'000];

static void process(const string &a, const string &b, bool *const ab) {
    const int len_a = a.length();
    const int len_b = b.length();

    for (int pos = -len_b + 1; pos <= len_a - 1; pos++) {
        int ib = (pos < 0 ? -pos : 0);
        int ia = (pos < 0 ? 0 : pos);
        int n = min(len_b - ib, len_a - ia);

        for (int i = 0; i < n; i++, ia++, ib++) {
            if (b[ib] == '?' || a[ia] == '?' || b[ib] == a[ia])
                continue;

            ab[pos] = true;
            break;
        }
    }
}

int main() {
    string a, b, c;
    cin >> a >> b >> c;

    auto *const ab = ab_array + 10'000;
    auto *const ac = ac_array + 10'000;
    auto *const bc = bc_array + 10'000;

    const int len_a = a.length();
    const int len_b = b.length();
    const int len_c = c.length();

    process(a, b, ab);
    process(a, c, ac);
    process(b, c, bc);

    int len_min = 100'000;

    // Fix a's position
    const int pos_a = 0;
    for (int pos_b = -len_b - len_c; pos_b <= len_a + len_c; pos_b++) {
        if (ab[pos_b])
            continue;

        for (int pos_c = -len_b - len_c; pos_c <= len_a + len_b; pos_c++) {
            if (ac[pos_c])
                continue;
            if (bc[pos_c - pos_b])
                continue;

            // cerr << "a" << pos_a << "b" << pos_b << "c" << pos_c << "\n";
            auto begin = min({pos_a, pos_b, pos_c});
            auto end = max({pos_a + len_a, pos_b + len_b, pos_c + len_c});
            if (end - begin < len_min) {
                len_min = end - begin;
            }
        }
    }
    cout << len_min << "\n";
    return 0;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:108777216")
#define _FORTIFY_SOURCE 0
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <utility>
#include <algorithm>
#include <ctime>
using namespace std;

int const MAX_N = 128 * 1024;

void my_gets(char * st) {
	int len = 0;
	char ch = getc(stdin);
	while (ch != '\n' && ch != '\r' && ch != 0 && !feof(stdin)) {
		st[len++] = ch;
		ch = getc(stdin);
	}
	st[len] = 0;
}

int n, q;
int s[MAX_N], x[MAX_N];
long long suf_sum[MAX_N], ods[MAX_N];

inline long long get_odd_sum(int p) {
	if (p < 0)
		return 0LL;

	return ods[p];
}

void get_window(int X, int moves_taken, int &a, int &b) {
	if (X >= s[n - 1]) {
		b = n - 1;
		a = b - moves_taken + 1;
		return;
	}
	if (X <= s[0]) {
		a = 0;
		b = a + moves_taken - 1;
		return;
	}

	int down = 0, up = n;
	while (up > down) {
		int mid = (up + down) / 2;
		if (s[mid] >= X) up = mid;
		else down = mid + 1;
	}
	int p_before = down;

	down = 0, up = min(moves_taken, p_before) + 1;
	while (up > down) {
		int mid = (up + down) / 2;
		int go_left = mid;
		int L = p_before - go_left;

		//long long dist = X - s[L];
		//long long max_val = X + dist;

		int R = p_before + (moves_taken - mid) - 1;
		int Ok = 1;
		
		if (R + 1 < n && s[R + 1] - X < X - s[L])
			Ok = 0;
		/*if (R < n)
			if (s[R] < max_val)
				Ok = 0;
*/
		if (!Ok) up = mid;
		else down = mid + 1;
	}
	down--;
	int go_left = down;
	int L = p_before - go_left;
	int R = p_before + (moves_taken - down) - 1;
	a = L;
	b = R;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &q);
	for (int i = 0; i < n; i++) scanf("%d", &s[i]);
	for (int i = 0; i < q; i++) scanf("%d", &x[i]);

	long long odd_sum = 0;
	for (int i = n - 1; i >= 0; i -= 2)
		odd_sum += s[i];

	suf_sum[n - 1] = s[n - 1];
	for (int i = n - 2; i >= 0; i--)
		suf_sum[i] = suf_sum[i + 1] + s[i];

	ods[0] = s[0];
	for (int i = 2; i < n; i += 2)
		ods[i] = ods[i - 2] + s[i];
	ods[1] = s[1];
	for (int i = 3; i < n; i += 2)
		ods[i] = ods[i - 2] + s[i];

	for (int t = 0; t < q; t++) {
		int X = x[t];

		int down = 0, up = n / 2 + 10;
		while (up > down) {
			int mid = (up + down) / 2;
			int a, b;
			get_window(X, mid, a, b);
			int c, d = n - 1;
			c = d - mid + 1;
			if (max(a, c) <= min(b, d))
				up = mid;
			else
				down = mid + 1;
		}
		down--;

		if (down < 0) {   // X > an or nearest to X is an
			printf("%lld\n", odd_sum);
			continue;
		}
		else {
			int a, b;
			get_window(X, down, a, b);
			int c, d = n - 1;
			c = d - down + 1;

			long long taken = suf_sum[c];
			if (b + 1 == c) {
				taken += get_odd_sum(a - 1);
			}
			else {
				taken += s[b + 1];
				taken += get_odd_sum(a - 2);
			}

			printf("%lld\n", taken);
		}
	}
	return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <vector>

const std::vector<int>
    ans{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

void solve() {
    int k;
    std::cin >> k;
    std::cout << ans[k - 1] << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}


Measured memory_bytes: 256
for x in range(300):
    a, b,c = input().split()
    if b=='?' : break
    a,c=int(a),int(c)
    if b=='+':
        print(a+c)
    elif b=='-' :
        print(a-c)
    elif b=='*':
        print(a*c)
    else :
        print(a//c)
    


Measured memory_bytes: 5600
package main

import (
	"fmt"
	"math"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)

	num := 753
	ans := 999

	for i := 0; i < len(s) - 2; i++{
		tmpStr := string([]rune(s)[i:i+3])
		tmpNum,_ := strconv.Atoi(tmpStr)
		ans = int(math.Min(float64(ans),math.Abs(float64(num-tmpNum))))
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007 

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A[i]; 

  unordered_map<int, int> m;
  m[0] = 3;
  int ans=1;
  for(int i=0; i<N; i++) {
     ans = (ans * m[A[i]]) % MOD;
     m[A[i]+1]++;
     m[A[i]]--;
     if(m[A[i]]==0) m.erase(A[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4492
fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main() {
    val (n, k) = longList()
    val r = n - k
    val m = (1e9 + 7).toLong()
    buildString {
        repeat(k.toInt()) {
            val t = (mnCr(r + 1, it + 1L, m) * mnCr(k - 1, it.toLong(), m)) % m
            appendln(t)
        }
    }.let {
        println(it.trimIndent())
    }
}

fun mnCr(n: Long, r: Long, m: Long): Long {
    val nc = (n - r + 1).until(n + 1).fold(1L) { a, b ->
        (a * (b)) % m
    }
    val rc = 0.until(r).fold(1L) { a, b ->
        (a * (r - b)) % m
    }
    return (nc * mPow(rc, m - 2, m)) % m
}

fun mPow(n: Long, ex: Long, m: Long): Long {
    var x = n
    var remain = ex
    var result = 1L
    while (remain > 0) {
        if (remain % 2L == 1L) {
            result = (result * x) % m
        }
        x = (x * x) % m
        remain /= 2
    }
    return result
}


Measured memory_bytes: 42436
import math

def distance(a, b):
  return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)

n = int(input())
towns = []
for i in range(n):
  towns.append(list(map(int, input().split())))

distanceSum = 0
for i in range(len(towns)):
  for j in range(i + 1, len(towns)):
    distanceSum += distance(towns[i], towns[j])

print(distanceSum * (math.factorial(n- 1) * 2) / math.factorial(n))

Measured memory_bytes: 3064