akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define mod 1000000007ll

long long inv(long long n) {
    long long ans = 1;
    while (n > 1) {
        ans *= (mod - mod / n) % mod;
        ans %= mod;
        n = mod % n;
    }
    return ans;
}

long long comb_mod(long long n, long long r) {
    if (n < r) return 0;
    long long deno = 1;
    long long mole = 1;
    long long r_change = (r <= n / 2) ? r : n - r;
    for (long long i=1; i<=r_change; i++) {
        mole *= i;
        mole %= mod;
    }
    for (long long i=n-r_change+1; i<=n; i++) {
        deno *= i;
        deno %= mod;
    }
    mole = inv(mole);
    return (mole * deno) % mod;
}

int main() {
    int n = 0, k = 0;
    cin >> n >> k;
    for (int i=1; i<=k; i++) {
        cout << comb_mod(n-k+1, i) * comb_mod(k-1, i-1) % mod << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, K;
  cin >> N >> K;
  ll mod = 998244353;
  vector<ll> L(K), R(K);
  for (ll i = 0; i < K; ++i) {
    ll l, r;
    cin >> l >> r;
    L.at(i) = l;
    R.at(i) = r;
  }
  vector<ll> came(N + 1, 0), dp(N + 1, 0);
  dp.at(1) = 1;
  for (ll i = 1; i < N; ++i) {
    dp.at(i) += came.at(i);
    for (ll j = 0; j < K; ++j) {
      ll l = L.at(j), r = R.at(j);
      if (i + l <= N) {
        came.at(i + l) += dp.at(i);
        came.at(i + l) %= mod;
      }
      if (i + r + 1 <= N) {
        came.at(i + r + 1) -= dp.at(i);
        if (came.at(i + r + 1) < 0) {
          came.at(i + r + 1) += mod;
        }
        came.at(i + r + 1) %= mod;
      }
    }
    came.at(i + 1) += came.at(i);
    came.at(i + 1) %= mod;
    // for (ll i = 0; i < N + 1; ++i) {
    //   cout << dp.at(i) << " " << came.at(i) << "\n";
    // }
    // cout << "\n";
  }
  cout << came.at(N) << "\n";
}


Measured memory_bytes: 6364
#include<bits/stdc++.h>
#define LL long long
#define db long double

using namespace std;
const int N=4000+10;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
int st[N],tp,an[N];
char cc[2];
int qry(int x,int y)
{
    printf("? %d %d\n",x,y),fflush(stdout);
    scanf("%s",cc);
    return cc[0]=='Y';
}

int main()
{
    int a=rd(),b=rd(),n=a+b;
    if(a<=b){puts("Impossible");exit(0);}
    for(int i=0;i<n;++i)
    {
	if(!tp) st[++tp]=i;
	else if(qry(st[tp],i)) st[++tp]=i;
	else --tp;
    }
    int smy=st[tp];
    for(int i=0;i<n;++i) an[i]=qry(smy,i);
    printf("! ");
    for(int i=0;i<n;++i) printf("%d",an[i]);
    exit(0);
}


Measured memory_bytes: 724
#include <bits/stdc++.h>
#define LL __int128
#define ll long long
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld%lld", &a, &b)
#define ss(a) scanf("%s", a)
#define mem(a, b) memset(a, b, sizeof(a))
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PII pair<int, int>
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int a[maxn], b[maxn];
int main(){
    ios;
    int n;
    cin >> n;
    for(int i = 1; i <= n; i ++) cin >> a[i];
    for(int i = 1; i <= n; i ++) cin >> b[i];
    reverse(b + 1, b + n + 1);
    bool ok = false;
    for(int i = 1; i <= n; i ++){
        if(a[i] != b[i]) continue;
        bool f = false;
        for(int j = 1; j <= n; j ++){
            if(a[i] != b[j] && a[j] != b[i]){
                f = true;
                swap(b[i], b[j]);
                break;
            }
        }
        if(!f){
            ok=1;
           cout << "No" << endl;
           return 0;
        }
    }
    cout << "Yes" << endl;
    for(int i = 1; i <= n; i ++){
        if(i != 1)cout << " ";
        cout << b[i];
    }
    cout << endl;
    return 0;
}


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

int main(){
	string s;
	while ( getline( cin, s ) ){
		bool first = true;
		istringstream iss( s );
		while ( !iss.eof() ){
			iss >> s;
			int len = s.size();
			char c = s[ len - 1 ];
			if ( c == '.' || c == ',' ){
				s.erase( len - 1, 1 );
				len -= 1;
			}
			if ( len >= 3 && len <= 6 ){
				if ( first ){
					first = false;
					cout << s;
				}else{
					cout << " " << s;
				}
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
// Distance2.cc
// ２つのデータがどれだけ似ているかを、それらの距離で測る手法は、
// クラスタリングや分類など、様々なところで使われています。
// ここでは、２つの n 次元ベクトル x={x1,x2,...,xn} と y={y1,y2,...,yn}
// の距離を計算してみましょう。
//
// このようなデータの距離を測る指標のひとつとして、次のミンコフスキー距離が知られています。 
//   Dxy=(∑i=1 to n |xi−yi|^p ) ^ (1/p)
//
// p=1 のとき 
//   Dxy= |x1−y1| + |x2−y2| + ... + |xn−yn|
//
// となり、これはマンハッタン距離とよばれます。 
//
// p=2 のとき 
//   Dxy=sqrt ( (|x1−y1|)^2 + (|x2−y2|)^2 + ... + (|xn−yn|)^2) 
//
// となり、これは一般的に使われるユークリッド距離になります。 
//
// p=∞ のとき 
//   Dxy=max i=1 to n (|xi−yi|)
//
// となり、これはチェビシェフ距離と呼ばれます。
//
// ２つの n 次元ベクトルが与えられるので、p がそれぞれ 1、2、3、∞ の
// ミンコフスキー距離を求めるプログラムを作成してください。
//
// 【入力】
// １行目に整数 n が与えられます。２行目にベクトル x の要素 {x1,x2,...xn}、
// ３行目にベクトル y の要素 {y1,y2,...yn} が空白区切りで与えられます。
// 入力はすべて整数値です。
// 【出力】
// p がそれぞれ 1、2、3、∞ の順番にそれぞれ１行に距離を出力してください。
// ただし、0.00001 以下の誤差があってもよいものとします。
// 【制約】
// ・1≤n≤100
// ・0≤xi,yi≤1000
// 【例】
// 入力：
// 3
// 1 2 3
// 2 0 4
// 出力：
// 4.000000
// 2.449490
// 2.154435
// 2.000000
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main( void) {
  int n;
  int x[100];
  int y[100];
  double Dxy, maxDxy;

  cin >> n;

  for ( int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for ( int i = 0; i < n; i++) {
    cin >> y[i];
  }

  // p = 1の時
  Dxy = 0;
  for ( int i = 0; i < n; i++) {
    Dxy += fabs( (double)(x[i] - y[i]));
  }
  printf( "%.6lf\n", Dxy);

  // p = 2の時
  Dxy = 0;
  for ( int i = 0; i < n; i++) {
    Dxy += pow( fabs( x[i] - y[i]), 2);
  }
  Dxy = sqrt( Dxy);
  printf( "%.6lf\n", Dxy);

  // p = 3の時
  Dxy = 0;
  for ( int i = 0; i < n; i++) {
    Dxy += pow( fabs( x[i] - y[i]), 3);
  }
  Dxy = pow( Dxy, (double)1/3);
  printf( "%.6lf\n", Dxy);
  
  // p = ∞の時
  maxDxy = 0;
  for ( int i = 0; i < n; i++) {
    Dxy = fabs( (double)(x[i] - y[i]));
    if ( Dxy > maxDxy) maxDxy = Dxy;
  }
  printf( "%.6lf\n", maxDxy);

  return 0;
}



Measured memory_bytes: 3356
#include<stdio.h>
#include<stdlib.h>
#define MAX 100005
#define NIL -1

struct Node {
  int p,l,r;
};

struct Node T[MAX];
int n,D[MAX];

void print(int u){
  int i,c;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("depth = %d, ",D[u]);

  if(T[u].p==NIL)printf("root, ");
  else if(T[u].l==NIL) printf("leaf, ");
  else  printf("internal node, ");

  printf("[");

  for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
    if(i) printf(", ");
    printf("%d",c);
  }
 printf("]\n");
}

void rec(int u, int p){
  D[u]=p;
  if(T[u].r!=NIL)rec(T[u].r,p);
  if(T[u].l!=NIL)rec(T[u].l,p+1);
}


int main(){

  int i,j,d,v,c,l,r,n;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=T[i].l=T[i].r=NIL;
  }

  for(i=0;i<n;i++){
     scanf("%d",&v);
     scanf("%d",&d);
     for(j=0;j<d;j++){
       scanf("%d",&c);
       if(j==0)T[v].l=c;
       else T[l].r=c;
       l=c;
       T[c].p=v;
     }
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL)r=i;
  }
  
  rec(r,0);
  for(i=0;i<n;i++)print(i);

  return 0;
}



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

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

	vector<int> p(n); for (int i = 0; i < n; i++) { cin >> p[i]; }
	
	vector<int> p_sort(p.size()); copy(p.begin(), p.end(), p_sort.begin());	sort(p_sort.begin(), p_sort.end());

	string ans = "NO";

	if (p_sort == p) ans = "YES";

	for (int i = 0; i < n - 1; i++) {

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

			vector<int> p_swap(p.size()); copy(p.begin(), p.end(), p_swap.begin());

			p_swap[i] = p[j];
			p_swap[j] = p[i];

			if (p_sort == p_swap) ans = "YES";

		}

	}

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        double r = in.nextDouble();

        System.out.printf("%.6f %.6f", Math.PI * r * r, 2 * Math.PI * r);
        System.exit(0);
    }
}



Measured memory_bytes: 28236
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		
		boolean a = sc.next().toCharArray()[0] == 'H' ? true : false;
		boolean b = sc.next().toCharArray()[0] == 'H' ? true : false;
		
		if (a == b) {
			System.out.println("H");
		} else {
			System.out.println("D");
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 20820
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class AFiveVariables {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        vector<int> x(5);
        REP(i, 5) {
            cin >> x[i];
        }
        REP(i, 5) {
            if (x[i] == 0) {
                cout << i + 1 << endl;
            }
        }

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    AFiveVariables solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3604
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int N;
        int[] a;

        Scanner sc = new Scanner(System.in);
        N = Integer.parseInt(sc.nextLine());
        a = new int[N];
        a = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();

        int count = 0;
        int num = 1;
        for (int i = 1; i <= N; i++) {
            if (a[i - 1] != num) {
                count++;
            } else {
                num++;
            }
        }

        if (num == 1) {
            count = -1;
        }
        System.out.println(count);
    }
}


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

vector<string> v;

void build(int ii, int n, string s){
	if(ii >= n) v.push_back(s);
	else{
		string num = "12345678";
		for(int i=0; i < n; i++){
			if(ii == 0) build(ii+1, n, s+num[i]);
			else{
				bool flag = true;
				for(int j=0; j < s.size(); j++){
					if(s[j] == num[i]) flag = false;
				}
				if(flag) build(ii+1, n, s+num[i]);
			}
		}
	}
}

int bb(int l, int r, string s){
	if(l > r) return -1;
	int mid = (l+r)/2;
	if(s == v[mid]) return mid;
	else if(s < v[mid]) return bb(l, mid-1, s);
	else return bb(mid+1, r, s);
}

int main(){
	int n;
	string s1, s2;
	char c;
	cin >> n;
	for(int i=0; i < n; i++){
		cin >> c;
		s1 += c;
	}
	
	for(int i=0; i < n; i++){
		cin >> c;
		s2 += c;
	}

	build(0, n, "");
	
	
	sort(v.begin(), v.end());

	int i1 = bb(0, v.size()-1, s1);
	int i2 = bb(0, v.size()-1, s2);

	cout << abs(i1-i2) << endl;
}


Measured memory_bytes: 2424
#include <bits/stdc++.h>
using namespace std;
int vis[100005],dis[100005],fin[100005];
vector<int> v[100005];
set<int> t;

int dfs(int u){
    vis[u]=1;
    int inter=0;
    for(int i=0;i<v[u].size();i++){
        if(!vis[v[u][i]]){
            dis[v[u][i]]=dis[u]+1;
            inter=dfs(v[u][i]);
            fin[u]=max(fin[u],inter);
        }else{
            fin[u]=max(fin[u],fin[v[u][i]]-dis[v[u][i]]+1+dis[u]);    
        }
    }
    if(t.find(u)!=t.end()){
        fin[u]=dis[u];
        return dis[u];    
    }
    
    else{
        return fin[u];
    }
}


int main() {
	int n,m;
	cin>>n>>m;
	int x,y;
	for(int i=0;i<n;i++){
	    t.insert(i+1);
	}
	for(int i=0;i<m;i++){
        cin>>x>>y;
	    auto pos2=t.find(x);
	    if(pos2!=t.end())
	        t.erase(x);
            
        v[x].push_back(y);
	   
	}
	int ans=0;
	for(int i=1;i<=n;i++){
	    if(!vis[i]){
	        dis[i]=0;
	        ans=max(ans,dfs(i));
	    }
	}
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 10496
import java.util.*;

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

		if(X <= K * 500){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 21972
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())

    M = N * (N - 1) // 2 - N // 2
    print(M)
    for i in range(1, N + 1):
        for j in range(i + 1, N + 1):
            if i + j == 1 + N - N % 2:
                continue
            print(i, j)


if __name__ == "__main__":
    main()

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

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

const int inf = 1 << 25;
const ll INF = 1LL << 55;

int main()
{
  int N; cin >> N;
  string s, t;
  cin >> s >> t;
  string u = "";
  rep(i, N) u += s[i];
  int idx = -1;
  rep(i, N) {
    bool flag = true;
    rep(j, N-i) flag &= (s[i+j] == t[j]);
    if(flag) {
      idx = i;
      break;
    }
  }
  if(idx == -1) idx = N;
  reps(i, N-idx, N) u += t[i];
  cout << u.size() << endl;
  return 0;
}


Measured memory_bytes: 256
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define INF 1e18
#define MOD 1000000007

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

ll bruto(ll x) {
    ll cnt = 0;
    for(ll i = 2; i <= x; i++) {
        ll aux = x;
        while(aux >= i) {
            if(aux%i==0) aux /= i;
            else aux -= i;
        }
        if(aux == 1) cnt++;
    }
    return cnt;
}

int main() {
    ios_base::sync_with_stdio(false);

    ll n;
    cin >> n;

    ll n_ini = n;
    n--;
    ll ans = 1;
    for(ll i = 2; i * i <= n; i++) {
        ll cnt = 1;
        while(n%i==0) {
            cnt++;
            n/=i;
        }
        ans *= cnt;
    }
    if(n > 1){ 
        ans *= 2;
    }

    vll divs;
    for(ll i = 2; i * i <= n_ini; i++) {
        if(n_ini % i == 0) {
            divs.PB(i);
            if(n_ini/i != i) divs.PB(n_ini/i);
        }
    }
    for(ll d : divs) {
        ll aux = n_ini;
        while(aux%d==0) aux /= d;
        if(aux%d==1) ans++;
    }

    cout << ans << "\n";
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


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

    vector<string> A(N);
    vector<i64> B(N);
    REP(i, N) cin >> A[i] >> B[i];

    string X; cin >> X;

    i64 st = 0;
    bool on = false;
    REP(i, N) {
        if (A[i] == X) {
            on = true;
            continue;
        }
        if (!on) continue;

        st += B[i];
    }

    cout << st << endl;

    return 0;
}


Measured memory_bytes: 3628
k, x = map(int, input().split(" "))

start = x - k + 1
end   = x + k - 1

if start < -1000000:
    start = -1000000
if end > 1000000:
    end = 1000000

for i in range(start, end + 1):
    if i == end:
        print(str(i))
    else:
        print(str(i) + " ", end="")


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

int main() {
    int n;cin >> n;
    ll a[n];
    rep(i,n)cin >> a[i];
    ll min = 10000000000,max = 0;
    rep(i,n){
        if(a[i] < min)min = a[i];
        if(a[i] > max)max = a[i];
    }
    cout << max - min << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int x,y;
    while(1){
        cin >> x >> y;
        if(x==0 && y==0) break;
        if(x>y) cout << y <<' ' <<x << endl;
        else cout << x << ' ' << y << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3016
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn a() {
    let N: usize = read!(usize);

    if N == 1 {
        println!("{}", 1.0);
    }

    if N % 2 == 0 {
        println!("{}", 0.50);
    } else {
        println!("{}", (N + 1) as f64 / (2.0 * N as f64));
    }
}

fn b() {
    let (n, k) = read!(usize, usize);
    let mut h: Vec<usize> = read![[usize]];
    h.sort();
    h.reverse();

    let mut ans = 0;
    for hh in h {
        if hh >= k {
            ans += 1;
        } else {
            println!("{}", ans);
            return;
        }
    }
    println!("{}", ans);
}

fn c() {
    let n = read!(usize);
    let a: Vec<usize> = read![[usize]];

    let mut v = Vec::with_capacity(n);
    for i in 0..n {
        v.push((i + 1, a[i]));
    }
    v.sort_by_key(|&x| x.1);

    let vv = v
        .into_iter()
        .map(|x| x.0.to_string())
        .collect::<Vec<String>>();
    println!("{}", vv.join(" "));
}

fn d() {
    unimplemented!();
}

fn e() {
    unimplemented!();
}

fn f() {
    unimplemented!();
}

fn main() {
    c();
}


Measured memory_bytes: 12540
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
    int N;
    cin>>N;
    vector<string> S(N);
    for(int i=0;i<N;i++){
        cin>>S.at(i);
    }
char m=S.at(0).at(S.at(0).size()-1);
for(int i=1;i<N;i++){
    if(m!=S.at(i).at(0)){
        cout<<"No"<<endl;
        return 0;
    }
    m=S.at(i).at(S.at(i).size()-1);
}
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
               if(S.at(i)==S.at(j)){
                  cout<<"No"<<endl;
                   return 0;
               }
        }
    }
    cout<<"Yes"<<endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


struct Block {
  int pos;
  int neg;
  int depth;

  int up() const {
    return pos - neg;
  }

};

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

  vector<Block> bs;
  REP(_, N) {
    string s;
    cin >> s;
    int pos = 0, neg = 0, depth = 0;

    int d = 0;
    REP(i, s.size()) {
      if (s[i] == '(') { pos++; d++; }
      if (s[i] == ')') { neg++; d--; }
      chmin(depth, d);
    }

    bs.push_back((Block){pos, neg, depth});
  }

  sort(ALL(bs), [](const Block&a, const Block&b){
    if ((a.depth >= 0) != (b.depth >= 0)) {
      return a.depth > b.depth;
    }
    if ((a.up() > 0) != (b.up() > 0)) {
      return a.up() > b.up();
    }
    if (a.up() > 0) {
      return a.depth > b.depth;
    }
    return a.up() + b.depth > b.up() + a.depth;
  });


  bool ok = true;
  int k = 0;
  for (auto b : bs) {

    if (k + b.depth < 0) {
      ok = false;
    }
    k += b.pos - b.neg;
  }
  if (k != 0) ok = false;

  cout << (ok ? "Yes" : "No") << endl;


  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n, a[105], s = 0, acu = 0, res = 1e9;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		s += a[i];
	}

	for (int i = 0; i < n; i++) {
		acu += a[i];
		res = min(res, abs(acu - (s - acu)));
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

bool check(llong a, llong b, llong c){
    if(a==b || a==c || b==c){
        return false;
    }
    if(a+b > c && b+c>a && a+c>b){
        return true;
    }else{
        return false;
    }
}

int main(){
    llong N;
    cin >> N;
    vector<llong> L(N);
    llong cnt=0;
    for(int i=0; i<N; i++){
        cin >> L[i];
    }
    for(int i=0; i<N-2; i++){
        for(int j=i+1; j<N-1; j++){
            for(int k=j+1; k<N; k++){
                if(check(L[i], L[j], L[k])){
                    cnt = cnt + 1;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;


template<class Abel> class WeightedUnionFind{
    vector<int> par; 
    vector<int> r_size; 
    vector<int> rank; 
    vector<Abel> diff_weight;
    public:
        WeightedUnionFind(int N, Abel SUM_UNITY = 0){
            init(N, SUM_UNITY);
        }

        void init(int N, Abel SUM_UNITY = 0){
            par.resize(N); r_size.resize(N); rank.resize(N); diff_weight.resize(N);
            for(int i=0; i<N; ++i){ par[i] = i; r_size[i] = 1; rank[i] = 0; diff_weight[i] = SUM_UNITY; }
        }

        int root(int x){
            if(par[x] == x)return x;
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }

        Abel get_weight(int x){
            root(x);
            return diff_weight[x];
        }

        Abel diff(int x, int y){
            return get_weight(y) - get_weight(x);
        }

        //xとyとが所属する集合を併呑する
        //なお，weight(y) - weight(x) = wとなるようにmerge
        bool merge(int x, int y, Abel w){
            w += get_weight(x); w -= get_weight(y);
            int rx = root(x),  ry = root(y);
            if(rx == ry) return false;
            if(rank[rx] < rank[ry]) swap(rx,ry), w = -w;
            if(rank[rx] == rank[ry]) ++rank[rx];
            r_size[rx] += r_size[ry];
            par[ry] = rx;
            diff_weight[ry] = w;
            return true;
        }

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

        //素集合の大きさを返す
        int size(int x){
            return r_size[root(x)];
        }
};

int main(){
    int N, M, l, r, d;
    cin >> N >> M;
    WeightedUnionFind<int> uf(N,0);
    bool ans = true;
    rep(_,M){
        cin >> l >> r >> d;
        --l; --r;
        if(uf.same(l,r) && abs(uf.diff(l,r)) != d)ans = false;
        uf.merge(l,r,d);
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 4820
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
using i64 = int64_t;
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    set<char> s;
    for(int i = 0; i < K; i++) {
        char tmp;
        cin >> tmp;
        s.insert(tmp);
    }
    for(int n = N; true; n++) {
        string S = to_string(n);
        set<char> t = set<char>(WHOLE(S));
        set<char> u;
        set_intersection(WHOLE(s), WHOLE(t), inserter(u, u.end()));
        if(u.empty()) {
            cout << n << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	int i;
	int input;
	int mozi;
	int kazu;
	while((input=getchar())!=EOF) {
		if(input!='@')putchar(input);
		else {
			kazu=getchar();
			mozi=getchar();
			for(i='0';i<kazu;i++)putchar(mozi);
		}
	}
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+18
#define MOD 1000000007
using namespace std;



int main(){
    int a,b,c;
    cin >> a >>  b >> c;
    cout<< (a*b)/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int cnt[4005][3];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	string s;
	cin >> s;
	ll ans = 0;
	vector<char> cr = {'R', 'G', 'B'};
	rep(i, 4005) rep(j, 3) cnt[i][j] = 0;
	rep(i, n){
		rep(j, i) if(s[i] != s[j]){
			if(s[j] == 'R') cnt[i][0]++;
			if(s[j] == 'G') cnt[i][1]++;
			if(s[j] == 'B') cnt[i][2]++;
			int k = j - (i - j), f = 0;
			int nw = 0;
			rep(m, 3){
				if(s[i] != cr[m] && s[j] != cr[m]){
					nw = m;
					break;
				}
			}
			if(k >= 0 && s[k] != s[j] && s[k] != s[i]) f = 1;
			ans += cnt[j][nw] - f;
		}
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 3700
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), k = sc.nextInt();
        System.out.println(n - k + 1);
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 22608
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222


ll dp[MAX][2], a[111];

ll dfs(ll cur) {
  if (dp[m][cur%2]) return dp[m][cur % 2];
  ll ret = cur + 1;
  rep(i, n) {
    if (m - a[i] < 0) continue;
    ll x;
    m -= a[i];
    x = dfs(cur + 1);
    m += a[i];
    if (x % 2 == cur % 2) ret = cur;
  }
  return dp[m][cur % 2] = ret;
}


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


  cin >> n >> m;
  rep(i, n) cin >> a[i];
  ans = dfs(1);
  if (ans % 2) cout << "First" << endl;
  else cout << "Second" << endl;


  return 0;
}

Measured memory_bytes: 6528
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] A = new int[M];
    int total =0;
    for (int i =0; i<M; i++) {
      A[i] = sc.nextInt();
      total += A[i];
    }
    if (N - total >= 0) {
      System.out.println(N - total);
    } else {
      System.out.println(-1);
    }
  }
}

Measured memory_bytes: 38952
use permutohedron::LexicalPermutation as _;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        p: [usize; n],
        q: [usize; n]
    }
    let find_prm = |v: Vec<usize>| -> isize {
        let mut prm = (1..=n).collect::<Vec<usize>>();
        let mut prm_idx = 0;
        loop {
            prm_idx += 1;
            if v == prm {
                return prm_idx;
            }

            if !prm.next_permutation() {
                panic!();
            }
        }
    };

    println!("{}", (find_prm(p) - find_prm(q)).abs());
}


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

int main() {
  int A ,B;
  cin >> A >> B;
  int count = 0;
  if((B-1)%(A-1) == 0) {
    count = (B-1)/(A-1);
  }
  else {
    count = (B-1)/(A-1) + 1;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
def reverseNumber(arr)
	rev_arr = arr.reverse
	rev_str = ''
	rev_arr.each{|num|
		rev_str += num + " "
	}
	return rev_str.gsub(/^[ \s]*(.*?)[ \s]*$/, '\1')
end

num = gets.to_i
arr_num = gets.chomp
arr_nums = arr_num.split(' ').map(&:to_s)

puts reverseNumber(arr_nums)

Measured memory_bytes: 8688
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


def main():
    n, m = map(int, input().split())
    p = list(map(int, input().split()))
    xy = [list(map(int, input().split())) for _ in range(m)]
    tree = UnionFind(n)
    for x, y in xy:
        tree.Unite(x, y)

    root = [[] for _ in range(n+1)]
    f_root = []
    for i in range(n):
        x = tree.Find_Root(p[i])
        root[x].append(i+1)
        f_root.append(x)
    out_put = 0
    for i in range(n):
        if f_root[i]==f_root[p[i]-1]:
            out_put += 1
    print(out_put)

if __name__=="__main__":
    main()

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

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

    int n;
    cin >> n;

    vector<int> A(n), B(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
        B[i] = A[i];
    }

    sort(B.begin(), B.end());

    for(int i = 0; i < n; i++){
        if(A[i] == B[n - 1]){
            cout << B[n - 2] << endl;
        }else{
            cout << B[n - 1] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3200
N = int(input())
A = list(map(int, input().split()))
B = A.copy()
ans = [0, 0]
flag1 = True
flag2 = False
for i in range(0, N):
    if i != 0:
        A[i] += A[i-1]
    if flag1:
        if A[i] <= 0:
            ans[0] += (abs(A[i])+1)
            A[i] = 1
        flag1 = False
    else:
        if A[i] >= 0:
            ans[0] += (abs(A[i])+1)
            A[i] = -1
        flag1 = True
for i in range(0, N):
    if i != 0:
        B[i] += B[i-1]
    if flag2:
        if B[i] <= 0:
            ans[1] += (abs(B[i])+1)
            B[i] = 1
        flag2 = False
    else:
        if B[i] >= 0:
            ans[1] += (abs(B[i])+1)
            B[i] = -1
        flag2 = True
print(min(ans))


Measured memory_bytes: 14468
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int maxday = sc.nextInt();
		int task = sc.nextInt();
		int days = 0;
		for(int i = 0; i < task; i++){
			days += sc.nextInt();
		}
		maxday -= days;
		if(maxday < 0){
			maxday = -1;
		}
		System.out.println(maxday);
		
	}
}

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

// マクロ //
#define rep(i,N) for(lint i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)
#define db(i) cout << #i << " = " << i;

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;


// 関数 //
template<class T, class Q> lint gcd_(T a, Q b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T, class Q> lint lcm_(T a, Q b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

template<class T, class Q> inline bool chmin(T& a, Q b) {
    if (a > b) { 
        a = b;
        return true; 
    }
    return false;
}

template<class T, class Q> inline bool chmax(T& a, Q b) {
    if (a < b) { 
        a = b; 
        return true; 
    }
    return false;
}

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int MOD = 998244353;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);


// キーワード //
#define elif else if

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
        
    lint N, K;
    cin >> N >> K;

    vli max(N + 1);
    vli min(N + 1);
    lint tori = 0;
    rep(i, N + 1) {
        min[i] = i * (i + 1) / 2;
        max[i] = (N + N - (i + 1) + 1) * (i + 1) / 2;
    }
    for (int i = K - 1; i < N + 1; i++) {
        tori = (tori + (max[i] - min[i] + 1) % mod) % mod;
    }
    cou(tori);
}

Measured memory_bytes: 6376
n = int(input())
a = [int(input()) for i in range(n)]
a.sort()
if n % 2 == 0:
    lower = a[:n//2]
    upper = a[n//2:]
    x = 2 * sum(upper) - upper[0]
    y = 2 * sum(lower) - lower[-1]
    ans = x - y
else:
    lower = a[:n//2]
    upper = a[n//2+1:]
    mid = a[n//2]
    x = 2 * sum(upper) - 2 * sum(lower) - mid + lower[-1]
    y = 2 * sum(upper) - 2 * sum(lower) + mid - upper[0]
    ans = max(x, y)
print(ans)


Measured memory_bytes: 7756
#original submission: https://atcoder.jp/contests/abc162/submissions/11865868

MOD = 10**9 +7

N, K = map(int,input().split())

ans = 0
gcd_equal_i = [0]*(K+1) #gcd(A) == i なるAの作り方がgcd_equal_i[i]個

for D in range(K, 0, -1):
    num_of_mul = K // D
    tmp = pow(num_of_mul, N, MOD)

    i = 2
    while D*i <= K:
        tmp -= gcd_equal_i[D*i]
        i += 1
    
    gcd_equal_i[D] = tmp
    ans += D*tmp
    ans %= MOD


print(ans)


Measured memory_bytes: 11308
#include<bits/stdc++.h>
using namespace std;
int main(void) {
  int n,ans=0;
  cin >> n;
  int m = n;
  while(n>0) {
    ans = ans + (n % 10);
    n = n / 10;
  }
  if(m % ans == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define fi first
#define se second
using namespace std;

ll dp[105][100005];
ll a[1000],we[1000];
ll ans(int i, ll w){
    if(i<0 || w<0)return 0;
    if(dp[i][w]!=-1)return dp[i][w];
    dp[i][w]=ans(i-1,w);
    if(w-we[i]>=0)dp[i][w]=max(a[i]+ans(i-1,w-we[i]),dp[i][w]);
    return dp[i][w];
}
int main(){
    ll n,w;
    cin>>n>>w;
    
    for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++)dp[i][j]=-1;
    }
    for(int i=0;i<n;i++)cin>>we[i]>>a[i];
    //dp[0]=0;
    // dp[0][0]=a[0][0];
    // dp[0][1]=a[0][1];
    // dp[0][2]=a[0][2];
    // for(int i=1;i<n;i++){
    //     for(int j=0;j<3;j++){
    //         for(int k=0;k<3;k++)if(j!=k)dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
    //     }
    // }
    cout<<ans(n-1,w);
}

Measured memory_bytes: 82500
#include <stdio.h>
#include <stdbool.h>

#define conv(c) (int)(c-'A')

void swap(bool *cup1, bool *cup2)
{
  bool tmp = *cup1;
  *cup1 = *cup2;
  *cup2 = tmp;
}

int main()
{
  char input_cup[10];
  bool cups[3] = {true, false, false};

  while(fgets(input_cup, sizeof input_cup/sizeof input_cup[0], stdin)!=NULL)
    swap(&cups[conv(input_cup[0])], &cups[conv(input_cup[2])]);

  int i;
  for(i = 0; i < 3; ++i)
    if(cups[i]){
      printf("%c\n", (char)('A'+i));
      break;
    }

  return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define dd long double

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans=min(k,a);
    k-=min(k,a);
    k-=min(k,b);
    ans-=min(k,c);
    cout<<ans<<endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define INF 1000000001
#define ll long long
using namespace std;

bool comp(pair<ll, ll> a, pair<ll, ll> b)
{
  if (a.second > b.second)
  {
    return false;
  }
  return true;
}

int main()
{
  ll N;
  cin >> N;
  vector<pair<ll, ll>> se(N);
  for (ll i = 0; i < N; ++i)
  {
    ll x, l;
    cin >> x >> l;
    se.at(i) = {x - l, x + l};
  }
  sort(se.begin(), se.end(), comp);
  ll ans = 0;
  ll last = -1000000010000000000;
  for (ll i = 0; i < N; ++i)
  {
    if (se.at(i).first >= last)
    {
      ans += 1;
      last = se.at(i).second;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm> // sort

using namespace std;

void Main()
{
    int n;
    cin >> n;
    vector<int> p(n);

    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }

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

    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include<string>
#include<math.h>
using namespace std;
int main()
{
	string S ;
	
	cin >> S;

	int min = 800;
	for (int i = 0;i < S.size()-2;i++)
	{
		string j = S.substr(i,  3);
		int s = stoi(j);
		int N = abs(s - 753);
		if (min >N)min = N;
	}
	cout << min;
	
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	lli a, b;
	cin >> a >> b;
	if(b < a) cout << a-1 <<endl;
	else cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, A, B = map(int, read().split())
count = 0

for num in range(N + 1):
    total = sum(map(int, list(str(num))))
    if A <= total <= B:
        count += num

print(count)


Measured memory_bytes: 2940
#include <string>
#include <vector>
#include <iostream>

using namespace std;

bool compare(string S1, string S2)
{
	if (S1.size() != S2.size()) { return S1.size() > S2.size(); }

	return S1 > S2;
}

int main()
{
	int H, W;

	while (true)
	{
		scanf("%d", &W);
		scanf("%d", &H);

		if (H == 0 && W == 0) { break; }

		vector<string> R(H);

		for (int i = 0; i < H; i++)
		{
			cin >> R[i];
		}

		vector<vector<string> > dp(H, vector<string>(W, ""));

		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (isdigit(R[i][j]))
				{
					if (R[i][j] != '0')
					{
						dp[i][j] = R[i][j];
					}

					if (i != 0)
					{
						if (R[i][j] != '0')
						{
							if (compare(dp[i - 1][j] + R[i][j], dp[i][j]))
							{
								dp[i][j] = dp[i - 1][j] + R[i][j];
							}
						}
						else
						{
							if (compare(dp[i - 1][j] + R[i][j], dp[i][j]) && dp[i - 1][j] != "")
							{
								dp[i][j] = dp[i - 1][j] + R[i][j];
							}
						}
					}

					if (j != 0)
					{
						if (R[i][j] != '0')
						{
							if (compare(dp[i][j - 1] + R[i][j], dp[i][j]))
							{
								dp[i][j] = dp[i][j - 1] + R[i][j];
							}
						}
						else
						{
							if (compare(dp[i][j - 1] + R[i][j], dp[i][j]) && dp[i][j - 1] != "")
							{
								dp[i][j] = dp[i][j - 1] + R[i][j];
							}
						}
					}
				}
			}
		}

		string ret = "";

		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (compare(dp[i][j], ret))
				{
					ret = dp[i][j];
				}
			}
		}

		printf("%s\n", ret.c_str());
	}

	return 0;
}

Measured memory_bytes: 3380