akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
int compare_int_small(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
// 公約数
long long int gcd(long long int a, long long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long long int lcm(long long int a, long long int b){
  return a * b / gcd(a, b);
}

#define TRUE 1
#define FALSE 0
#define MAX_NUM 100002
typedef struct pp{
  char c;
  int h;
  int w;
}P;

int top = 0;
P *Stack = NULL;
P *tmp = NULL;


void initialize(){
  Stack = (P *)calloc(MAX_NUM, sizeof(P));
  top = 0;
}

void finalize(){
  if(Stack != NULL){
    free(Stack);
    Stack = NULL;
  }
}

int isEmpty(){
  if(top <= 0){
    return TRUE;
  }else{
    return FALSE;
  }
}

int isFull(){
  if(top > MAX_NUM - 1){
    return TRUE;
  }else{
    return FALSE;
  }
}

int push(P x){
  fprintf(stderr, "pushするのは%c (h, w) = (%d, %d)\n", x.c, x.h, x.w);
  //printf("push x = %d\n",x);
  if(isFull() != FALSE){
    //    fprintf(stderr, "pushしたのは%d top = %d\n", Stack[top], top);
    printf("Error! Overfllow\n");
    return 0;
  }else{
    top++;
    if(Stack != NULL){
      Stack[top] = x;
    }
    return 0;
  }
}

P pop(){
  if(isEmpty() != FALSE){
    printf("Error! Underfllow\n");
    return *tmp;
  }else{
    top--;
    // return では取りだす値を返す
    //    fprintf(stderr, "popしたのは%d top = %d\n", Stack[top + 1], top);
    return Stack[top+1];
  }
}

long double total_distance = 0;//そこまでの距離
int n = 0;
int x[10];
int y[10];
int check_town[10]; //訪れたかどうか


// 戻り値：スタート後、cnt番目以降に訪れることができるパターン数
// now : これから行く街
// pre : いま居たところ（最初は-1）
// cnt : これから訪れる街がcnt番目(0-indexed)
int check(int now, int pre, int cnt, long double distance){

  if (cnt > 0) {
    int dx = 0, dy = 0;
    //fprintf(stderr, "%d",  root[i]);
    dx = x[now] - x[pre];
    dy = y[now] - y[pre];
    distance += sqrt((dx * dx) + (dy * dy));
  }

  if(cnt == n-1){
    total_distance += distance;
    return 1;
  }else{
    int ret = 0;
    // for文で少しずつ考えていく
    for(int i = 0; i < n; i++){//値を一つずつ比較する時に使用
      // 行ったことのない街へ行く
      if (check_town[i] == 0) {
        check_town[i] = 1;
        ret += check(i, now, cnt + 1, distance);
        check_town[i] = 0;
      }
    }
    return ret;
  }
}




// min
int main(void){

  double d[30500];
  long double ans = 0;
  int pattern = 0;

  scanf("%d", &n);

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

  // 経路の数
  for (int i = 0; i < n; ++i) {
    check_town[i] = 1;
    pattern += check(i, -1, 0, 0);
    check_town[i] = 0;
  }

  fprintf(stderr, "distance = %Lf pattern = %d\n", total_distance, pattern);
  // 経路の数で割る
  ans = total_distance / pattern;
  
  printf("%Lf\n", ans);

  return 0;

}


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

public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int min = 753;
		for(int i = 0; i < s.length()-2; i++) {
			String num = s.substring(i, i+3);
			int n = Integer.parseInt(num);
			min = Math.min(min, Math.abs(753-n));
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  vector<int> group1 = {1, 3, 5, 7, 8, 10, 12};
  vector<int> group2 = {4, 6, 9, 11};

  int x, y;
  cin >> x >> y;
  bool is_ok = false;
  rep(i, 7) rep(j, 7)
  {
    if(group1[i] == x && group1[j] == y)
      is_ok = true;
  }

  rep(i, 4) rep(j, 4)
  {
    if (group2[i] == x && group2[j] == y)
      is_ok = true;
  }

  printYesNo(is_ok);
  return 0;
}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto s = sread(), c = "RGB";
    long color = 3, count;
    auto pair = new long[][](n + 1, color);
    foreach(i; iota(n))
    {
        foreach (j; iota(color))
        {
            pair[i + 1][j] = pair[i][j] + (s[i] == c[j]);
        }
    }

    foreach (i; iota(n - 2))
    {
        foreach (j; iota(i + 1, n - 1))
        {
            if(s[i] == s[j])
                continue;


            auto tmp = color.iota.sum() - c.countUntil(s[i]) - c.countUntil(s[j]);
            count += pair[n][tmp] - pair[j + 1][tmp];
            if(j + (j - i) < n && c[tmp] == s[j + (j - i)])
                count--;
        }
    }
    count.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 2740
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

signed main(){
    
    while(1){

    int m, mi, ma; cin >> m >> mi >> ma;
    if(m == 0) break;
    vector<int> p(m);
    for(int i = 0; i < m; i++) cin >> p[i];
    sort(p.rbegin(), p.rend());

    int ans = 0;
    int ans_n;

    for(int n = mi; n <= ma; n++){
        int tmp = 0;
        tmp = p[n - 1] - p[n];
        if(tmp >= ans){
            ans = tmp;
            ans_n = n;
        }
    }

    cout << ans_n << endl;
    }
    return 0;

}




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

using namespace std;
//State
//dp[i][j]: The maximum value we can get by using blocks from
// 0...i and sum of blocks in the tower = j

//Initialization
//dp[0][W[0]] = V[0]

//Transitions
//dp[i][j] = max(V[j]+dp[i-W[0]][j-1], dp[i][j-1])

//Order of evaluation
//Rowise or Columnwise

//Answer: argmax(dp[0...W_max][N])

struct B{
	long long w;
	long long s;
	long long v;
};

vector<vector<long long>> dp(20004,vector<long long>(1004,0));

bool compare(B b1, B b2){
	return (b1.w+b1.s<=b2.w+b2.s);
}

int main(){
	long long N;
	cin >> N;
	vector<B> boxes(N);
	for(long long i=0; i<N; i++){
	    long long w, s, v;
		cin >> w >> s >> v;
		boxes[i].w = w;
		boxes[i].s = s;
		boxes[i].v = v;
	}
	sort(boxes.begin(), boxes.end(), compare);
	long long W_max = 20004;
	dp[boxes[0].w][0] = boxes[0].v;
	for(int i=0; i<W_max; i++){
	    if(i>=boxes[0].w){
	        dp[i][0] = boxes[0].v;
	    }
	}
	for(long long j=1; j<N; j++){
		for(long long i=0; i<W_max; i++){
			if(i-boxes[j].w>=0 && boxes[j].s+boxes[j].w-i>=0){
				dp[i][j] = max(dp[i-boxes[j].w][j-1]+boxes[j].v, dp[i][j-1]);
			}
			else{
				dp[i][j] = dp[i][j-1];
			}
		}
	}
	long long result = 0;
	for(long long i=0; i<W_max; i++){
	    if(result<dp[i][N-1]) result = dp[i][N-1];
	}
	cout << result << endl;
}







Measured memory_bytes: 160800
def modpow(a, n, mod):
  res = 1
  while n > 0:
    if (n & 1):
      res = res * a % mod
    a = a * a % mod
    n >>= 1
  return res

DIV = 10**9 + 7
h, w, a, b = map(int, input().split())
ans = 0
#最大h+w!までの元と逆元の階乗テーブルを求めておく
#逆元をFermatの小定理により計算
#p-2乗は二分累乗法にて高速に計算可能
table = [1 for i in range(h + w + 1)]
inv_table = [1 for i in range(h + w + 1)]
temp = 1
for i in range(1, h + w + 1):
  temp = temp * i % DIV
  table[i] = temp
  inv_table[i] = modpow(temp, DIV - 2, DIV)

for i in range(w - b):
  n1 = table[h + i + b - a - 1] * inv_table[b + i] * inv_table[h - a - 1] % DIV
  n2 = table[w + a - b - 2 - i] * inv_table[a - 1] * inv_table[w - b - 1 - i] % DIV
  ans += n1 * n2 % DIV
ans = int(ans)
print(ans%DIV)

Measured memory_bytes: 55628
import queue
N=int(input())
a=[0 for i in range(N-1)]
b=[0 for i in range(N-1)]
c=[0 for i in range(N-1)]
VL=[dict() for i in range(N)]
for i in range(N-1):
    a[i],b[i],c[i]=map(int,input().split())
    a[i]-=1
    b[i]-=1
    VL[a[i]][b[i]]=c[i]
    VL[b[i]][a[i]]=c[i]
Q,K=map(int,input().split())
K-=1
x=[0 for i in range(Q)]
y=[0 for i in range(Q)]
for i in range(Q):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
reached=[False for i in range(N)]
dist=[0 for i in range(N)]
q=queue.Queue()
q.put(K)
reached[K]=True
while(not(q.empty())):
    r=q.get()
    for v in VL[r]:
        if not(reached[v]):
            q.put(v)
            dist[v]=VL[r][v]+dist[r]
            reached[v]=True
for i in range(Q):
    print(dist[x[i]]+dist[y[i]])


Measured memory_bytes: 63836
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n=100,k=0,x;
	cin>>x;
	while(1)
	{
		n=n+n/100;
		k++;
		if(n>=x)
		{
			cout<<k<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n,m,q;
  cin >> n >> m >> q;
  vector<vector<int>> data(550, vector<int>(550,0));
  rep(i,m){
    int l,r; cin>>l>>r;
    data[l][r]++;
  }
  rep(i,n+1){ rep(j,n+1){
    data[i][j+1] += data[i][j];
  }}
  rep(i,q){
    int l,r; cin>>l>>r;
    int ans=0;
    for(int j=l; j<=r; j++){ ans += data[j][r]; }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>> //a(縦行,vector<ll>(横列));
#include<algorithm>//__gcd(a,b)
#include <iostream>
#include <vector>
#include <cstdlib>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

int main(){
    ll n,k;cin>>n>>k;
    vector<long double> p(n);rep(i,n)cin>>p[i];
    vector<long double> ki(n);rep(i,n)ki[i]=(p[i]+1)*p[i]/(2*p[i]);
    vector<long double> s(n);s[0]=ki[0];for(ll i=1;i<n;i++)s[i]=s[i-1]+ki[i];

    long double max=s[k-1];
    rep(i,n-k){
        if(s[i+k]-s[i]>=max)max=s[i+k]-s[i];
    }

    cout<<fixed<<setprecision(10);
    cout<<max<<endl;

}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define ld long double
#define ll long long
using namespace std;
template <typename T> void chkmax(T &x, T y) {x = x > y ? x : y;}
template <typename T> void chkmin(T &x, T y) {x = x < y ? x : y;}
template <typename T> void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	while (!isdigit(c)) {if (c == '-') f = -1; c = getchar();}
	while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); x *= f;
}
const int N = 3010; const double pi = acos(-1);
double a[N];
int main() {
	int n, L; read(n), read(L);
	for (int i = 1; i <= n; i++) read(a[i]);
	double sx = 0, sy = 0;
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++) {
			sx += cos(pi * (a[i] + a[j]) / L) * (n - (j - i + 1));
			sx += cos(pi * (a[i] + a[j] + L) / L) * (j - i - 1);
			sy += sin(pi * (a[i] + a[j]) / L) * (n - (j - i + 1));
			sy += sin(pi * (a[i] + a[j] + L) / L) * (j - i - 1);
		}
	double sum = 1.0l * n * (n - 1) * (n - 2) / 6; sx /= sum, sy /= sum;
	cout << fixed << setprecision(10) << sx << ' ' << sy << '\n';
	return 0;
}

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

 using namespace std;

 int main() {
   int N, M, i, j, S1, S2, S3;
   bool clear;

   cin >> N >> M;

   if (M == 0) {
     if (N == 1) cout << 0 << endl;
     else cout << pow(10, N - 1) << endl;
   }

   else {
     vector<int> s(M + 1);
     vector<int> c(M + 1);
     clear = true;

     for(i = 1; i <= M; i++) cin >> s.at(i) >> c.at(i);

     for (i = 1; i <= M; i++) {
       if (s.at(i) > N || (N > 1 && s.at(i) == 1 && c.at(i) == 0)) {
         cout << -1 << endl;
         clear = false;
         break;
       }
     }

     if (clear == true) {
      for (i = 1; i <= M - 1; i++) {
        for (j = i + 1; j <= M; j++) {
          if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
            cout << -1 << endl;
            clear = false;
            break;
          }
        }
        if (clear == false) break;
      }
     }

    if (clear == true) {
        if (N == 1) cout << c.at(1) << endl;
        else if (N == 2) {
          S1 = 1;
          S2 = 0;
          for (i = 1; i <= M; i++) {
            if (s.at(i) == 1) S1 = c.at(i);
            else if (s.at(i) == 2) S2 = c.at(i);
          }
          cout << S1 << S2 << endl;
        }
        else if (N == 3) {
          S1 = 1;
          S2 = 0;
          S3 = 0;
          for (i = 1; i <= M; i++) {
            if (s.at(i) == 1) S1 = c.at(i);
            else if (s.at(i) == 2) S2 = c.at(i);
            else if (s.at(i) == 3) S3 = c.at(i);
          }
          cout << S1 << S2 << S3 << endl;
        }
     }

   }
 }


Measured memory_bytes: 256
//This is the Property of Rishabh Agarwal
#include <bits/stdc++.h>
#define F first
#define S second
#define MAX 10000003
using namespace std;

typedef long long int ll;
const ll mod = 1e9+7;
ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    ll temp=power(a,b/2)%mod;
    if(b%2==0){
        return (temp*temp)%mod;
    }
    else{
        return ((a*temp)%mod*temp)%mod;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    //cin>>t;
    t=1;
    while(t--){
        ll n,k;
        cin>>n>>k;
        ll a[n];
        a[0]=0;
        for(ll x=0; x<n; x++){
            cin>>a[x];
        }
        ll dp[n];
        dp[0]=0;
        dp[1]=abs(a[1]-a[0]);
        for(ll x=2; x<n; x++){
            dp[x]=1e18;
            for(ll y=1; y<=min(k,x); y++){
                dp[x]=min(dp[x],dp[x-y]+abs(a[x]-a[x-y]));
            }
        }
        cout<<dp[n-1]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <vector>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll nmax=50;

bool visited[nmax+1][nmax+1];
ll field[nmax+1][nmax+1];

ll h,w;

ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,1,-1};


int main() {
    string s;
    ll ans;
    while(true){
        cin>>s;
        if(s=="0")break;
        ans=0;
        for(ll i=0;i<s.length();i++){
            ans+=(s[i]-'0');
        }
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 3208
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		sc.close();

		int c = 1;
		int w = 1;
		List<Hen> list = new ArrayList<>();
		while (w * 2 <= l && c < 19) {
			c++;
			list.add(new Hen(c - 1, c, 0));
			list.add(new Hen(c - 1, c, w));
			w *= 2;
		}

		int n = c + 1;
		int rem = l;
		while (w > 0) {
			while (w <= rem) {
				rem -= w;
				list.add(new Hen(c, n, rem));
			}
			w /= 2;
			c--;
		}

		int m = list.size();
		System.out.println(n + " " + m);
		for (Hen h : list) {
			System.out.println(h.a + " " + h.b + " " + h.w);
		}
	}

	static class Hen {
		int a, b, w;

		public Hen(int a, int b, int w) {
			this.a = a;
			this.b = b;
			this.w = w;
		}
	}
}


Measured memory_bytes: 21844
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int n,k,t,d,ret,yum,kind;
vi neta;
priority_queue<pi,vpi,greater<pi>> eat,must_eat;
priority_queue<pi> sug;

signed main(){
    I(n); I(k);
    neta.resize(n+1);

    REP(i,n){
        I(t); I(d);
        sug.emplace(d,t);
    }
    REP(i,k){
        auto p = sug.top();
        sug.pop();
        eat.push(p);
        yum += p.first;
        if(!neta[p.second]) kind++;
        neta[p.second]++;
    }
    ret = max(ret, yum + kind*kind);
    while( !sug.empty() && !eat.empty() ){
        auto p = sug.top();
        sug.pop();
        if (neta[p.second]) continue;
        yum += p.first;
        neta[p.second]++;
        kind++;

        auto q = eat.top();
        eat.pop();
        while ( neta[q.second] == 1 && !eat.empty() ) {
            must_eat.push(q);
            q = eat.top();
            eat.pop();
        }
        if (eat.empty() && neta[q.second] == 1 ) break;
        neta[q.second]--;
        yum -= q.first;

        ret = max(ret, yum + kind*kind);
    }
    cout << ret << endl;
}

Measured memory_bytes: 5616
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int mod = 1e9+7;
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;}
};

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  vector<mint> fact(n, 1), cum(n, 0);
  for (int i = 1; i < n; i++) cum[i] = cum[i - 1] + (mint)1 / i;
  for (int i = 1; i < n; i++) fact[i] = fact[i - 1] * i;
  mint res = 0;
  for (int i = 1; i < n; i++) {
    res += mint(x[i] - x[i - 1]) * cum[i];
  }
  res *= fact[n - 1];
  cout << res.x << endl;
  return 0; 
}


Measured memory_bytes: 5104
#include<bits/stdc++.h>
using namespace std;
// To check whether each node is visited or not
bool visited[100005];

// To store the path that we have to take from each node
// i.e the signposts that have to be placed in each room
int path[100005];

// To store the graph
vector<int>adj[100005];

// Helps in BFS
queue<int>q;
int main()
{
	memset(visited, sizeof(visited), false);
	int n,m;
	cin>>n>>m;
	int x,y;
	bool flag=false;
	for(int i=0;i<m;i++){
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
		// To check whether there is an edge between 1 and any other node
		// If there is no connection between 1 and any other node it means that 1 is completely disconnected 
		// from the rest of the graph
		if(x==1 || y==1)
			flag=true;
	}
	// If 1 has no connections then print NO
	if(!flag){
		cout<<"No";
		return 0;
	}
	q.push(1);
	while(q.size()){
		int x=q.front();
		q.pop();
		if(!visited[x]){

			// Make sure that it is visited
			visited[x]=true;

			// Do a for loop over it's children
			for(int i=0;i<adj[x].size();i++){
				// Push their children into the queue
				q.push(adj[x][i]);
				// This is to check whether the path has been updated or not
				// If it has not been updated then set it to the parent variable
				if(path[adj[x][i]]==0)
					path[adj[x][i]]=x;
			}
		}
	}
	cout<<"Yes"<<"\n";
	for(int i=2;i<=n;i++)
		cout<<path[i]<<"\n";	
	return 0;
}

Measured memory_bytes: 11112
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<set>
#include<cmath>
#include<stack>
#include<iomanip>
#include<cstdio>
using namespace std;
int main()
{
    int n,k,temp,ans,max=-1;
    vector<int> all;
    cin>>k>>n;
    for(int i = 0;i<n;i++)
    {
        cin>>temp;
        all.push_back(temp);
    }
     sort(all.begin(),all.end());
    for(int i = 0;i<n-1;i++)
    {
        temp=all.at(i+1)-all.at(i);
        if(temp>max)
            max=temp;
    }
    temp=k+all.at(0)-all.at(n-1);
   if(temp>max)
       max=temp;
    ans=k-max;
    cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1400
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
vector<int> dir = { 0, 1, 0, -1 };
int H, W;
int main() {
	while (cin >> W >> H, H) {
		vector<vector<int> > x(H, vector<int>(W));
		int p2 = -1, p3 = -1, p4 = -1;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cin >> x[i][j];
				if (x[i][j] == 2) p2 = i * W + j;
				if (x[i][j] == 3) p3 = i * W + j;
				if (x[i][j] == 4) p4 = i * W + j;
			}
		}
		priority_queue<vector<int> > que; que.push({ 0, p4, p2 });
		vector<vector<int> > dp(H * W, vector<int>(H * W, 999999999)); dp[p4][p2] = 0;
		while (!que.empty()) {
			vector<int> u = que.top(); que.pop();
			int sx = u[1] % W, sy = u[1] / W, fx = u[2] % W, fy = u[2] / W;
			for (int i = 0; i < 4; i++) {
				int tx = sx + dir[i], ty = sy + dir[i ^ 1];
				if (0 <= tx && tx < W && 0 <= ty && ty < H && x[ty][tx] != 1) {
					if (tx != fx || ty != fy) {
						if (dp[ty * W + tx][u[2]] > dp[u[1]][u[2]]) {
							dp[ty * W + tx][u[2]] = dp[u[1]][u[2]];
							que.push({ -dp[ty * W + tx][u[2]], ty * W + tx, u[2] });
						}
					}
					else {
						int zx = tx + dir[i], zy = ty + dir[i ^ 1];
						if (0 <= zx && zx < W && 0 <= zy && zy < H && x[zy][zx] != 1) {
							if (dp[ty * W + tx][zy * W + zx] > dp[u[1]][u[2]] + 1) {
								dp[ty * W + tx][zy * W + zx] = dp[u[1]][u[2]] + 1;
								que.push({ -dp[ty * W + tx][zy * W + zx], ty * W + tx, zy * W + zx });
							}
						}
					}
				}
			}
		}
		int ret = 999999999;
		for (int i = 0; i < H * W; i++) ret = min(ret, dp[i][p3]);
		cout << (ret != 999999999 ? ret : -1) << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int X[100010];
    rep(i, m) cin >> X[i];
    sort(X, X + m);
    vector<int> v;
    int sum = 0;
    rep(i, m - 1) {
        v.push_back(X[i + 1] - X[i]);
        sum += X[i + 1] - X[i];
    }
    sort(v.begin(), v.end(), greater<int>());
    rep(i, min((int)v.size(), n - 1)) sum -= v[i];
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
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++)
typedef long long ll;

int main(){
	int N,K,R,S,P;
	cin >> N >> K >> R >> S >> P;
	string T;
	cin >> T;
	
	ll ans = 0;
	
	rep(i,N-K){
		if (T[i] == T[i+K]){
			T[i+K] = '0';
		}
	}
	
	rep(i,N){
			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<iostream>
 
int main()
{
  char c;
  std::cin >> c;
  switch(c)
  {
    case 'a':
    case 'i':
    case 'u':
    case 'e':
    case 'o':
      std::cout << "vowel";
    break;
    default:
      std::cout << "consonant";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction
 
///using namespace __gnu_pbds;
using namespace std;
 
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

typedef pair<ll,ll>ii; 
const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    ll n,k;
    while(sf("%lld %lld",&n,&k)==2)
    {
        vector<ii>vec;
        for(int i=0;i<n;i++)
        {
            ll a,b;
            sf("%lld %lld",&a,&b);
            vec.push_back(ii(a,b));
        }

        sort(vec.begin(),vec.end());
        ll sum=0; 
        for(int i=0;i<vec.size();i++)
        {
            if(sum+vec[i].second>=k)
            {
                pf("%lld\n",vec[i].first);
                break;
            }
            sum+=vec[i].second;
        }
    }
    return 0;
}
 









 




























Measured memory_bytes: 2420
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int W = scan.nextInt();
    int H = scan.nextInt();
    int x = scan.nextInt();
    int y = scan.nextInt();
    int r = scan.nextInt();
    int f = 0;
    if(x+r>W) f=1;
    if(y+r>H) f=1;
    if(r>x) f=1;
    if(r>y) f=1;
    if(f==0) System.out.println("Yes");
    else System.out.println("No");
  }
}



Measured memory_bytes: 26420
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define MOD 1e9+7
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int ans=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='A')
		{
			for(int j=s.size()-1;j>i;j--)
			{
				if(s[j]=='Z')
				{
					cout << j-i+1;
					break;
				}
			}
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 720
/*

    author : s@if

*/

#include<bits/stdc++.h>
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			99999999
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)


bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hr[]={-2,-2,-1,+1,+2,+2,-1,+1};
int hc[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)1e5+9;

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    ll i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    cin>>n>>m;

    ll lft = 0, rgt = n+9;

    while(m--)
    {
        cin>>l>>r;

        lft = max(lft,l);
        rgt = min(rgt,r);
    }

    if(lft>rgt)
        cout<<0<<endl;
    else
    cout<<rgt-lft+1<<endl;

   // main();

    return 0;
}


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

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

  cout << (n-1)*(m-1) << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		//System.out.print(" ");
		Scanner scan = new Scanner(System.in);
		String moji =scan.nextLine();
		char[] ichimoji = moji.toCharArray();
		int nagasa = moji.length();

		for(int i=0; i<nagasa; i++){
			if (Character.isUpperCase(ichimoji[i])){
				ichimoji[i] = Character.toLowerCase(ichimoji[i]);
			}
			else if(Character.isLowerCase(ichimoji[i])){
				ichimoji[i] = Character.toUpperCase(ichimoji[i]);
			}
			else{}
			System.out.print(ichimoji[i]);
		}
		System.out.println("");
	}
}

Measured memory_bytes: 26588
#include <stdio.h>

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

int main(){
	int N;
	scanf("%d",&N);
	int i;
	int a;
	a=N;
	for(i=0;i<=N;i++){
		int j;
		int k;
		int l;
		j=0;
		k=i;
		l=N-i;
		while(k>0){
			j=j+k%6;
			k=k/6;
		}
		while(l>0){
			j=j+l%9;
			l=l/9;
		}
		a=min(a,j);
	}
	printf("%d",a);
}


Measured memory_bytes: 128
#include <iostream>

int main(int argc, const char * argv[]) {
    // insert code here...
    int a,b,c;
    std::cin>>a>>b>>c;
    if(a+b+c==17){
        if(a==7|| b==7 || c==7){
            if(a==5||b==5||c==5){
                std::cout<<"YES"<<std::endl;
            }else std::cout<<"NO"<<std::endl;
        }else std::cout<<"NO"<<std::endl;
    }
    else std::cout<<"NO"<<std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
// modは一気にやってはいけない。だんだんです。
// なので一個ずつやります。

int main(){
    int n;
    long long int sum = 0;
    int mod = 1000000007;
    cin >> n;
    vector<int>num(n);
    for(int i = 0; i < n; i++){
        cin >> num[i];
        sum += num[i];

        // 足し算する前に各項をmodしとく
        sum %= mod;
    }

    long ans = 0;

    for(int i = 0; i < n; i++){
        sum -= num[i]; //減らしていく
        if(sum < 0) sum += mod;
        ans += num[i]*sum;
        ans %= mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4044
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

// 二項係数計算

/*int main() {
    // 前処理
    COMinit();

    // 計算例
    cout << COM(100000, 50000) << endl;
}*/

void solve()
{
	//COMinit();
	int n;
	cin >> n;
	vector<int> a(n);
	set<int> appr;
	map<int, ll> cnt;
	rep(i, n)
	{
		cin >> a[i];
		appr.insert(a[i]);
		cnt[a[i]]++;
	}
	auto itr = appr.begin();
	vector<ll> app;
	while (itr != appr.end())
	{
		app.push_back(*itr);
		itr++;
	}
	//cout<<"a";
	ll tmp = 0;
	map<int, ll> dis, now;
	rep(i, app.size())
	{

		tmp += cnt[app[i]] * (cnt[app[i]] - 1) / 2;
		now[app[i]] = cnt[app[i]] * (cnt[app[i]] - 1) / 2;
		dis[app[i]] = (cnt[app[i]] - 1) * (cnt[app[i]] - 2) / 2;
	}
	rep(i, n)
	{
		ll ans = tmp - now[a[i]] + dis[a[i]];
		cout << ans << endl;
	}
}

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


Measured memory_bytes: 33012
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;


int main (int argc, char const *argv[])
{
    int N,L;
    cin>>N>>L;
    //vector<型の種類> 名前(個数)
    vector<string> S(N);
    
    for(int i = 0; i < N; i++)
    {
        cin>>S[i];
    }
    //並び変え
    sort(S.begin(), S.end());
    
    for(int i = 0; i < N; i++)
    {
        cout<<S[i];
    }
    

    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n,x,a=0,i,j,k;
    while(1){
        scanf("%d %d",&n,&x);
        if(n==0 && x==0){
            break;
        }
        for(i=1; i<=n; i++){
            for(j=1; j<=n; j++){
                for(k=1; k<=n; k++){
                    if((i+j+k)== x && i != j && j != k && k != i){
                        a+=1;
                }
            }
        }
    }
        printf("%d\n",a/6);
        a=0;
    }

     return 0;
}



Measured memory_bytes: 2100
#include<stdio.h>
void main(){
    int n=0;
    int ac,wa,tle,re;
    ac=0;
    wa=0;
    tle=0;
    re=0;
    scanf("%d",&n);
    
    for(int i=0;i<n;i++){
        char input[5];
        scanf("%s",input);
        if(!strcmp(input,"AC"))ac++;
        if(!strcmp(input,"WA"))wa++;
        if(!strcmp(input,"TLE"))tle++;
        if(!strcmp(input,"RE"))re++;
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",ac,wa,tle,re);
}

Measured memory_bytes: 1732
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

count = 0
last = None
for i in range(N):
    count += B[A[i]-1]
    if last and A[i] == last + 1:
        count += C[last-1]
    last = A[i]

print(count)


Measured memory_bytes: 9080
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;

ll N;

bool isValid(vector<ll>& a, vector<ll>& b, ll sum)
{
    ll cntPlus1 = 0, cntPlus2 = 0;
    rep(i, N)
    {
        if (a[i] > b[i]) {
            cntPlus1 += a[i] - b[i];
        }
        if (a[i] < b[i]) {
            ll tmp = b[i] - a[i];
            cntPlus2 += (tmp + 1) / 2;
        }
    }
    return cntPlus1 <= sum && cntPlus2 <= sum;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    vector<ll> a(N), b(N);
    ll sumA = 0, sumB = 0;
    rep(i, N)
    {
        cin >> a[i];
        sumA += a[i];
    }
    rep(i, N)
    {
        cin >> b[i];
        sumB += b[i];
    }

    if (isValid(a, b, sumB - sumA)) {
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;

int main()
{
    string s;
    int n;

    cin >> s >> n;

    for (int i = 0; i < n; i++) {
        string order;
        int a, b;
        cin >> order >> a >> b;
        if (order == "replace") {
            string str;
            cin >> str;
            s.replace(a, b-a+1, str);
        }
        else if (order == "reverse") {
            reverse(s.begin() + a, s.begin() + b+1);
        }
        else if (order == "print") {
            for (int j = a; j <= b; j++) {
                cout << s[j];
            }
            cout << endl;
        }
    }

}




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

#define REP(i,n,m) for(int i=n;i<m;i++)
#define REPR(i,n,m) for(int i=n;i>m;i--)
#define ALL(v) v.begin(),v.end()
#define elif else if
using ll=long long;

int gcd(int x,int y){
    int a;
    while(y!=0){
        a=x%y;
        x=y;
        y=a;
    }
    return x;
}

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

/*----------template----------*/

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

    cout<<t<<s<<endl;
}


Measured memory_bytes: 256
//BeTogether.cpp (C)
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main(){
  int N,Ans,Amin;
  Amin = 4400000;
  cin >> N;
  int a[N];
  map<int, int> chk;

  for(int i = 0; i < N; i++){
    cin >> a[i];
    chk[a[i]]++;
  }
  Ans = 0;
  for(int i = -100; i <= 100; i++){
    for(auto X: chk){
      Ans += (X.first - i)*(X.first - i)*X.second;
    }
    Amin = min(Ans,Amin);
    Ans = 0;
  }
  printf("%d\n", Amin);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <complex>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

int arr[3];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(3);
    arr[0] = 1;

    char a, b;
    while (scanf("%c,%c", &a, &b) != EOF)
    {
        if ((a == 'A' && b == 'B') || (a == 'B' && b == 'A'))
        {
            swap(arr[0], arr[1]);
        }
        else if ((a == 'A' && b == 'C') || (a == 'C' && b == 'A'))
        {
            swap(arr[0], arr[2]);
        }
        else
        {
            swap(arr[1], arr[2]);
        }
    }
    if (arr[0] == 1)
    {
        cout << "A" << endl;
    }
    else if (arr[1] == 1)
    {
        cout << "B" << endl;
    }
    else
    {
        cout << "C" << endl;
    }
    return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <math.h>
#include <map>
#include <queue>

#define say(s) cout << s << endl
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define vec vector

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

int a[1001001];

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

  a[0]=100;
  a[1]=7%k;
  for(int i=2; i<=k; i++) {
    a[i] = (a[i-1]*10+7) % k;
  }

  rep(i, k+1) {
    if (a[i]==0) {
      say(i);
      return 0;
    }
  }
  say(-1);

  return 0;
}


Measured memory_bytes: 6996
#include "bits/stdc++.h"
using namespace std;

int main() {
    string N;
    cin >> N;
    if (N.size() == 1) cout << stoi(N) << endl;
    else if (N.size() == 2) cout << 9 << endl;
    else if (N.size() == 3) cout << 9 + stoi(N) - 99 << endl;
    else if (N.size() == 4) cout << 909 << endl;
    else if (N.size() == 5) cout << 909 + stoi(N) - 9999 << endl;
    else cout << 90909 << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a, a+3);
    if (a[0]+a[1]==a[2]) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
S = [tuple(map(int, input().split())) for _ in range(N)]

S.sort(key=lambda x: -x[1])
st = set()
first_acc, other_acc = [0], [0]
for t, d in S:
    if t in st:
        other_acc.append(other_acc[-1] + d)
    else:
        st.add(t)
        first_acc.append(first_acc[-1] + d)

ans = 0
for i in range(K + 1):
    if len(first_acc) <= i or len(other_acc) <= K - i:
        continue
    ans = max(ans, first_acc[i] + other_acc[K - i] + i * i)
print(ans)


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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; 
constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    i64 N = input(), K = input();
    N %= K;
    
    cout << min(N, K - N) << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


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

using namespace std;

int main(){
  int a,b,c,k,ans=0;
  cin>>a>>b>>c>>k;
  if(k>a){
    k-=a;ans+=a;
    if(k>b){
      k-=b;
      ans-=k;
    }
  }
  else{
    ans=k;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
    int N,K;
    cin >> N >> K;
    vector<int> l(N);
    for(int i=0;i<N;i++)cin >> l.at(i);
    sort(l.begin(),l.end());
    reverse(l.begin(),l.end());
    int sum=0;
    for(int i=0;i<K;i++){
        sum+=l.at(i);
    }    
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	int count=0;
	for(int i=n;i>=3;i--)
	{
		for(int j=i-1;j>=2;j--)
		{
			if(a[j]+a[j-1]<=a[i])
			{
				break;
			}
			for(int m=j-1;m>=1;m--)
			{
				if(a[j]+a[m]>a[i])
				{
					count++;
				}
			}
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include <string>
#include <math.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
int main(){
  int n,x; cin >>n>>x;
  vector<int> l(n);
  cinf(n,l);
  int cnt=1;
  int sum=0;
  for(int i=0;i<n;i++){
    sum+=l[i];
    if(sum<=x)cnt++;
    else break;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class CTravelingSalesmanAroundLake {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int k = s.nextInt(), n = s.nextInt(), ans = Integer.MAX_VALUE;
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = s.nextInt();
            for (int i = 0; i < n; i++) {
                int dis = a[(i + 1) % n] - a[i] + k;
                dis %= k;
                ans = Math.min(ans, k - dis);
            }
            w.println(ans);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
long int luca(int a,vector<long int> &memo){
    if(memo[a] != -1) return memo[a];
    if(a == 0){
        memo[a] = 2;
        return memo[a];
    }
    else if(a == 1){
        memo[a] = 1;
        return memo[a];
    }
    memo[a] = luca(a - 1, memo) + luca(a - 2, memo);
    return memo[a];
}
int main(){
    int N;
    cin >> N;
    vector<long int> memo(N + 1,-1);
    cout << luca(N,memo) << endl;
}

Measured memory_bytes: 3596