akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int h = sc.nextInt();
    int w = sc.nextInt();
    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < w+2; i++){
      sb.append("#");
    }
    sb.append("\n");
    String tmp = sb.toString();
    for(int i = 0; i < h; i++){
      sb.append("#");
      sb.append(sc.next());
      sb.append("#\n");
    }
    sb.append(tmp);
    System.out.print(sb.toString());
  }
}


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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

char A[22][22] = {};
int f[22][22] = {};
int W, H;

bool isinrange(int i, int j) {
	return 0 <= i&&i < H && 0 <= j&&j < W;
}

int di[] = { 1,0,-1,0 };
int dj[] = { 0,1,0,-1 };
void dfs(int i, int j) {
	if (isinrange(i, j) == false)return;
	if (A[i][j] == '#')return;
	if (f[i][j])return;
	f[i][j] = true;
	rep(k, 0, 4) {
		int ii = i + di[k];
		int jj = j + dj[k];
		dfs(ii, jj);
	}
}

signed main() {
	for (; cin >> W >> H&&W&&H;) {
		memset(f, 0, sizeof(f));
		memset(A, 0, sizeof(A));
		int ai, aj;
		rep(i, 0, H) rep(j, 0, W) {
			cin >> A[i][j];
			if (A[i][j] == '@') {
				ai = i, aj = j;
			}
		}
		dfs(ai, aj);
		int ans = 0;
		rep(i, 0, H)rep(j, 0, W) {
			if (f[i][j]) {
				ans++;
				dump(i);
				dump(j);
			}
		}
		cout << ans << endl;
		rep(i, 0, H)dumpc(f[i]);
	}
	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

const lint INF = 1e18;
lint dp1[300][300];
lint dp2[300][300];

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

    fill(dp1[0], dp1[300], INF);
    for(lint i=0; i<m; i++) {
        lint a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        dp1[a][b] = dp1[b][a] = c;
    }

    for(lint k=0; k<n; k++)
    for(lint i=0; i<n; i++)
    for(lint j=0; j<n; j++)
        dp1[i][j] = min(dp1[i][j], dp1[i][k] + dp1[k][j]);

    fill(dp2[0], dp2[300], INF);
    for(lint i=0; i<n; i++)
    for(lint j=0; j<n; j++)
        if(dp1[i][j] <= l)  dp2[i][j] = 1;

    for(lint k=0; k<n; k++)
    for(lint i=0; i<n; i++)
    for(lint j=0; j<n; j++)
        dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j]);

    lint q;
    cin >> q;

    vector<pair<lint, lint>> query(q);
    for(auto& e : query) {
        cin >> e.first >> e.second;
        e.first--, e.second--;
    }

    for(auto e : query) {
        lint s = e.first;
        lint t = e.second;
        cout << (dp2[s][t] == INF ? -1 : dp2[s][t]-1) << endl;
    }
}

Measured memory_bytes: 3328
n,m = map(int,input().split())

iriguti,deguti = 0,n
for i in range(m):
	l,r = map(int,input().split())
	iriguti = max(iriguti,l)
	deguti = min(deguti,r)
if iriguti > deguti:
	print(0)
else:
	print(deguti-iriguti+1)

Measured memory_bytes: 3060
n,k=map(int,input().split())
g=[int(o) for o in range(1,n+1)]
for i in range(k):
    d=int(input())
    a=list(map(int,input().split()))
    for j in range(1,n+1):
        if a.count(j)>=1 and g.count(j)==1:
            g.remove(j)
print(len(g))


Measured memory_bytes: 68020
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll maxSubArraySum(int a[], int size)
{
         ll max_so_far = 0, max_ending_here = 0;
   for (int i = 0; i < size; i++)
   {
       max_ending_here = max_ending_here + a[i];
       if (max_ending_here < 0)
           max_ending_here = 0;

       /* Do not compare for all elements. Compare only
          when  max_ending_here > 0 */
       else if (max_so_far < max_ending_here)
           max_so_far = max_ending_here;
   }
                return max_so_far;
}
int main()
{
	int h,n;
	cin>>h>>n;
	vector<pair<ll,ll>> v;
	for(int i=1;i<=n;i++)
	{
		ll a,b;
		cin>>a>>b;
		v.push_back({a,b});
		
	}
	ll dp[h+1][n+1];
	ll maxi=10000000000000;
	for(int i=1;i<=h;i++)
	{
		dp[i][0]=maxi;
	}
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=n;j++)
		{
			
				
				if(i>=v[j-1].first)
					dp[i][j]=min(dp[i][j-1],dp[i-v[j-1].first][j]+(v[j-1].second));
				else
					dp[i][j]=min(dp[i][j-1],v[j-1].second);
				
			
			
		}
	}
	cout<<dp[h][n]<<endl;
}



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

pair<string, int> str[1025];
vector<pair<string, int> > v;
int maxarray;

void f(string in)//入力関数
{
	for(int i=0;i<1025;++i)
	{
		if(str[i].first == in)
		{
			++str[i].second;
			return;
		}
		if(str[i].first.empty())
		{
			str[i].first = in;
			str[i].second = 1;
			maxarray = i;
			return;
		}
	}
}

void insert(int index)
{
	if(v.empty())
	{
		v.push_back(str[index]);
		return;
	}
	for(int i=0;i<v.size();++i)
	{
		if(v[i].second < str[index].second)
		{
			v.insert(v.begin()+i,str[index]);
			return;
		}
	}
	v.push_back(str[index]);
}

int main(void)
{
	string input;
	string in;
	char k;
	int n;
	while(cin >> n , n)
	{
		v.clear();
		for(int i=0;i<1025;++i)
		{
			str[i].first = "";
			str[i].second = 0;
		}
		getline(cin,input);
		for(int num=0;num<n;++num)
		{
			getline(cin,input);
			string::size_type index=0;
			string::size_type nextindex = input.find(" ");//次のスペースの場所
			while(1)
			{
				f(input.substr(index,nextindex-index));
				index = nextindex+1;
				nextindex = input.find(" " ,nextindex+1);
				if(nextindex == string::npos)
				{
					f(input.substr(index));
					break;
				}
			}
		}
		sort(str,str+maxarray+1);
		cin >> k;//頭文字の入力
		bool flag = false;
		for(int i=0;i<=maxarray;++i)
		{
			if(str[i].first.at(0) == k)
			{
				insert(i);
			}
		}
		if(v.empty())
			cout << "NA" << endl;
		for(int i=0;i<5 && i<v.size();++i)
		{
			if(i==4 || i==v.size()-1)
			{
				cout << v[i].first << endl;
				break;
			}
			cout << v[i].first << ' ';
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y) {
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
int main(){
  ll h,w;
  cin >> h >> w;
  vector<vector<char>> vec(h,vector<char>(w));
  vector<vector<ll>> sum(h,vector<ll>(w,INFLONG));
  rep(i,h){
    rep(j,w){
      cin >> vec[i][j];
    }
  }
  rep(i,h){
    rep(j,w){
      if(vec[i][j] == '#'){
        t1 = 1;
      }else{
        t1 = 0;
      }
      if(i == 0 && j == 0){
        sum[i][j] = t1;
      }
      if(j != 0) {
        if (vec[i][j - 1] == '.' && t1 == 1) {
          chmin(sum[i][j], sum[i][j - 1] + 1);
        } else {
          chmin(sum[i][j], sum[i][j - 1]);
        }
      }
      if(i != 0){
        if(vec[i-1][j] == '.' && t1 == 1){
          chmin(sum[i][j],sum[i-1][j]+1);
        }else{
          chmin(sum[i][j],sum[i-1][j]);
        }
      }
      //cout << sum[i][j] << " ";
    }
    //cout << endl;
  }
  cout << sum[h-1][w-1] << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<map>
using namespace std;
int main(){
  map<char,int> mp;
  char s[5];
  cin>>s;
  for(int i=0;i<4;i++)
    mp[s[i]]++;
  bool flag=false;
  if(mp.size()==2){
    for(auto o :mp){
      if(o.second==2) flag=true;
    }
  }
  if(flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
#define sz(c) int((c).size())

bool palindrome(string& s)
{
  int i = 0, j = sz(s) - 1;
  while (i <= j) {
    if (s[i++] != s[j--])
      return false;
  }
  return true;
}

int main(int argc, char **argv)
{
  string s;
  int accm = 0;
  while (cin >> s) {
    if (palindrome(s))
      accm++;
  }
  cout << accm << endl;
  return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#define eps 1e-6
#define ll long long
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#define int long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define fi first
#define se second
#define endl "\n"
#define pii pair<int,int>
#define fi first
#define se second
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll Max(ll a,ll b){return a>=b?a:b;}
ll Min(ll a,ll b){return a<=b?a:b;}
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res,t;res=1;t=a%c;while(b){if(b&1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
using namespace std;
//head file

int n;
int a[105];

int main(){
	cin >> n;
	for(int i=0;i<n;i++)cin >> a[i];
	ll ans = 0;
	sort(a,a+n);
	
	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(a[i] != a[j] && a[j]!= a[k] && a[i] != a[k] && a[i] + a[j] > a[k])ans++;
			}
		}
	}
	cout<< ans << endl;
	
	
	return 0;
} 







Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
int A, B, C, D, E;
int a, b, c, d, e;
int main(){
  cin >> A >> B >> C >> D >> E;
  if (A%10 ==0){
    a =A;
  }
  else a=(A-A%10)+10;
  if (B%10 ==0){
    b =B;
  }
  else b=(B-B%10)+10;
  if (C%10 ==0){
    c =C;
  }
  else c=(C-C%10)+10;
  if (D%10 ==0){
    d =D;
  }
  else d=(D-D%10)+10;
  if (E%10 ==0){
    e =E;
  }
  else e=(E-E%10)+10;
  int ans = min(a+b+c+d+E, a+b+c+D+e);
  ans= min(ans, a+b+C+d+e);
  ans= min(ans, a+B+c+d+e);
  ans= min(ans, A+b+c+d+e);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include <bits/stdc++.h>
#include <vector> 
#include <algorithm> 
#include <string>
#include <cmath>
#include <iomanip> 
#include<climits> 
#include <utility>   
#include <set>
#include <numeric> 
#include <iterator>
#include <map> 
using namespace std; 
#define ll long long int
//typedef pair<ll,ll> p; 
int main()
{
      ll x;
      cin>>x;
      ll ans=0;
      ll p=x/500;
      ans=ans+ p*1000;
      p=x%500;
      p=p/5;
      ans=ans+ p*5;
      cout<<ans<<endl;
      
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        double sum = 0;
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
            sum += (double) 1 / a[i];
        }
        System.out.println(1.0 / sum);
        sc.close();
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n;
    cin >> n;
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    b-=a;
    long long inf,sup;
    for(int i = 0;i<=n-1;i++){
        inf = c*i-(n-1-i)*d;
        sup = d*i-(n-1-i)*c;
        if(inf<=b && b<=sup){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
/**
 * @author      : omgursocute
 * @created     : 23/02/2020
 * @task        : B
 */

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int intlog(int base, int x) {
	return (int)((ld)log(x) / (ld)log(base));
}

int main() {
	// freopen("B.inp", "r", stdin);
	// freopen("B.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	int n, k;
	cin >> n >> k;
	cout << intlog(k, n) + 1;

	return 0;
}



Measured memory_bytes: 640
function Main(input) {
    L = input.split(' ')[0] * 1
    R = input.split(' ')[1] * 1
    arr = []
    for (i = L; i <= R && i < L + 2019; i++) {
        arr.push(i % 2019)
    }
    arr = arr.sort((a, b) => {
        return a - b
    })
    ans = 2018
    for (i = 0; i<arr.length - 1; i++) {
        for (j = i + 1; j<arr.length; j++) {
            m = (arr[i] * arr[j]) % 2019
            if (ans > m) {
                ans = m
            }
        }
    }
    console.log(ans)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7748
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template<typename T>
inline T mod(T n, T mod){ T res = n%mod; if(res < 0) res += mod; return res; }

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

const int MOD = 1e9+7;

int main(){
	fastio;
	int n, m;
	cin >> n >> m;
	vector<vector<char>> grid(n+1, vector<char>(m+1));
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cin >> grid[i][j];
		}
	}
	vvi dp(n+1, vi(m+1, 0));
	dp[1][1] = 1;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(grid[i][j] == '#') continue;
			dp[i][j] += dp[i-1][j] + dp[i][j-1];
			dp[i][j] = mod(dp[i][j], MOD);
		}
	}
	cout << dp[n][m] << endl;
	return 0;
}

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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)

int main(void){
  int a,b,k;
  cin>>a>>b>>k;
  

  if(a+k>b-k){
    for(int i=a;i<=b;i++){
      cout<<i<<endl;
    }
  }else{
    r(i,k)cout<<a+i<<endl;
    for(int i=b-k+1;i<=b;i++)cout<<i<<endl;
  }


return 0;}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,a,b;
int main()
{
	cin >> n >> a >> b;
	int res = 0;
	for(int i=0;i<n;i++){
		int x; cin >> x;
		res += (a>x || b<=x);
	}
	cout << res << endl;
}

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


int main() {
    Int N;
    cin >> N;
    Int M = N / 2;
    M = N - M;
  
    double ans = (double)M / (double)N;
  
    cout << setprecision(10);
    cout << ans << endl;
}

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

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

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

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

/* do your best */

int main() {
  
  int n; cin >> n;
  vector<lint> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  map<lint, lint> mp;
  lint ans = 0;
  for (int i = n; i >= 1; i--) { 
    lint A = a[i - 1];
    lint left = A + i;
    ans += mp[left];

    mp[i - A]++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 27452
import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace

main :: IO ()
main = do
  as <- getLine

  putStrLn $ if (maximum (map length $ group as)) >= 2 then "Bad" else "Good"


Measured memory_bytes: 380
#include<stdio.h>
int main()
{
	int k,n,a,b,st1,st2,max,i;
	while(~scanf("%d %d",&k, &n))
	{
		max = 0;
		scanf("%d", &a);
		st1=a;
		for(i=1; i<n; i++)
		{
			scanf("%d", &b);
			if(b-a>max)
				max = b-a;
			a = b;
		}
		st2 = k - a;
		if(st1+st2>max)
			max = st1 + st2;
		printf("%d\n", k - max);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}

//typedef long long ll;
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}

//配列のSIZEは問題ごとに定義する必要がある。
const int SIZE = 100'010;
long long inv[SIZE+1];//各iの逆元を格納する配列。
long long kai[SIZE+1];//i!のmodを格納する配列。
long long invkai[SIZE+1];//各i!の逆元を格納する配列。
const int MOD=i_7;
void invinit(){//上の配列を初期化する関数。
    inv[1]=1;
    for(int i=2;i<=SIZE;i++){
        inv[i] = MOD - ((MOD/i)*inv[MOD%i])%MOD;
    }
    
    kai[0]=invkai[0]=1;
    for(int i=1;i<=SIZE;i++){
        kai[i]=(kai[i-1]*i)%MOD;
        invkai[i]=(invkai[i-1]*inv[i])%MOD;
    }
}

long long comb(long long a, long long b){
    if(b<0 || a<b){
        return 0;
    }
    return mod(kai[a]*mod(invkai[b]*invkai[a-b]));
}

int main(){
  invinit();
  using namespace std;
  long long n, k;
  cin>>n>>k;
  long long a[n];
  REP(i,n){
    cin>>a[i];
  }
  sort(a, a+n);
  long long ans = 0;
  for(long long i = 0; i<n; i++){
    long long p, m;
    p = comb(i, k-1) * a[i];
    p = mod(p);
    m = comb(n-(i+1), k-1) * a[i];
    m = mod(m);
    long long temp = p - m;
    temp = mod(temp);
    ans += temp;
    ans = mod(ans);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3328
import java.util.*;

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

        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        int sum = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                sum += arr[i] * arr[j];
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>

ll INF = 1000000007;


//-----------------//
  #define amin main
//-----------------//


int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i,j;
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans = max(a*c,max(b*d,max(a*d,b*c)));
	cout<<ans<<endl;

	
	
	


	
	return 0;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <algorithm>
#include <map>
#include <cstring>

#include <queue>
using namespace std;
typedef long long ll;
int n;
ll perm[11];
int dist[4000000];
bool check[4000000];
map<ll,int> ma;

void permutation2(){
	for(int i=0;i<n;i++){
		perm[i]=i;
	}
	int j=0;
	do{
		ll d=0;
		ll p=1;
		for(int i=0;i<n;i++){
			d+=perm[i]*p;
			p*=10LL;
		}
		ma[d]=j;
		j++;
	}while(next_permutation(perm,perm+n));
}


int a[11];
ll tmp[11];
ll ten[11];

int bfs2(ll s){
	queue<ll> que;
	que.push(s);
	dist[ma[s]]=0;
	int res=n-1;
	while(que.size()){
		ll v=que.front();
		que.pop();
		int lv=ma[v];
		if(dist[lv]==4)continue;
		ll nv=v;
		for(int i=0;i<n;i++){
			tmp[i]=nv%10LL;
			nv/=10LL;
		}
		ll dv=v;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				ll uv=dv;
				for(int k=0;i+k<j-k;k++){
					uv+=tmp[i+k]*(ten[j-k]-ten[i+k])+tmp[j-k]*(ten[i+k]-ten[j-k]);
				}
				int nexv=ma[uv];
				if(dist[nexv]==-1){
					dist[nexv]=dist[lv]+1;
					que.push(uv);
				}else if(check[nexv]){
					res=min(res,dist[lv]+dist[nexv]+1);
				}
			}
		}
	}
	return res;
}

int bfs(ll s){
	queue<ll> que;
	que.push(s);
	memset(dist,-1,sizeof(dist));
	memset(check,false,sizeof(check));
	dist[ma[s]]=0;
	check[ma[s]]=true;
	while(que.size()){
		ll v=que.front();
		que.pop();
		int lv=ma[v];
		if(lv==0)return dist[lv];
		if(dist[lv]==4)continue;
		ll nv=v;
		for(int i=0;i<n;i++){
			tmp[i]=nv%10LL;
			nv/=10LL;
		}
		ll dv=v;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				ll uv=dv;
				for(int k=0;i+k<j-k;k++){
					uv+=tmp[i+k]*(ten[j-k]-ten[i+k])+tmp[j-k]*(ten[i+k]-ten[j-k]);
				}
				int nexv=ma[uv];
				if(dist[nexv]==-1){
					dist[nexv]=dist[lv]+1;
					check[nexv]=true;
					que.push(uv);
				}
			}
		}
	}
	return -1;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		a[i]--;
	}
	ll s=0;
	ll p=1;
	for(int i=0;i<n;i++){
		s+=(ll)p*a[i];
		ten[i]=p;
		p*=10LL;
	}
	permutation2();
	int re=bfs(s);
	if(re!=-1)printf("%d\n",re);
	else{
		sort(a,a+n);
		s=0;
		p=1;
		for(int i=0;i<n;i++){
			s+=(ll)p*a[i];
			p*=10LL;
		}
		printf("%d\n",bfs2(s));
	}
	return 0;
}

Measured memory_bytes: 250736
package main

import "fmt"

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	var n int
	fmt.Scan(&n)
	ts := make([]int, n)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&ts[i], &as[i])
	}

	a := as[0]
	t := ts[0]
	for i := range ts {
		d := max((t-1)/ts[i]+1, (a-1)/as[i]+1)
		a = d * as[i]
		t = d * ts[i]
	}
	fmt.Println(a + t)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 100100;
long long n, a[N], s;

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

	cin >> n;

	for(long long i = 1; i<= n; i++)
		cin >> a[i], s += a[i];
	
	long long p = n * (n + 1) / 2;

	if(s % p != 0) return cout << "NO\n", 0;

	long long cnt = s / p, nr = 0;
	a[n + 1] = a[1];

	for(long long i = 1; i <= n; i++) {
		long long dif = a[i + 1] - a[i];
		long long x = cnt - dif;

		if(x < 0 || x % n != 0) return cout << "NO\n", 0;
		x /= n;
		nr += x;
	}

	if(nr == cnt)
		cout << "YES\n";
	else cout << "NO\n";
}	

	

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::string S, T;
int ST[30], TS[30];

bool can(){
    int N = S.size();

    for(int i=0;i<N;++i){
        int u = S[i] - 'a', v = T[i] - 'a';

        if(ST[u] == -1){
            ST[u] = v;
        }else if(v != ST[u]){
            return false;
        }

        if(TS[v] == -1){
            TS[v] = u;
        }else if(u != TS[v]){
            return false;
        }
    }

    return true;
}

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

    std::cin >> S >> T;

    memset(ST, -1, sizeof(ST));
    memset(TS, -1, sizeof(TS));

    if(can()){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}

Measured memory_bytes: 916
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n,m;
	cin>>n>>m;
	ll a1=((n)*(n-1))/2;
	ll a2=((m)*(m-1))/2;
	cout<<(a1+a2)<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n,x,i=0;
    for(;;){
        cin >> n >> x;
        if(n!=0||x!=0){
            for(int a=0;a<n-2;a++){
                for(int b=a+1;b<n-1;b++){
                    for(int c=b+1;c<n;c++){
                        if(a+b+c+3==x)
                            i++;
                    }
                }
            }
        }
        else break;
        cout << i << endl;
        i=0;
    }

    return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<string> a;
    vector<string> b;
    for(int i=0;i<n;i++){
        string t;
        cin>>t;
        a.push_back(t);
    }
    for(int i=0;i<m;i++){
        string t;
        cin>>t;
        b.push_back(t);
    }
    int ans=0;
    for(int i=0;i<=n-m;i++){
        for(int j=0;j<=n-m;j++){
            for(int k=0;k<m;k++){
                for(int l=0;l<m;l++){
                    if(a[i+k][j+l]!=b[k][l]){
                        k=l=114514;
                    }
                    if(k+1==m&&l+1==m){
                        ans++;
                    }
                }
            }
        }
    }
    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include <iosfwd>
#include<limits.h>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <limits>
#include<stdio.h>
#include <queue>
#include <stack>
#include <math.h>
#include<string.h>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include<vector>
#include <chrono>
#include <random>
using namespace std;
#define fr(i,j,n)   for(lli i=j;i<(n);++i)
#define bk(i,j,n)   for(lli i=j;i>=n&&j>=n;--i)
#define pb push_back
#define m_p make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define mem(p,v) memset(p,v,sizeof(p))
#define present(c,x)    ((c).find(x) != (c).end())
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define ub upper_bound
#define lb lower_bound
typedef long long int lli;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<lli> vl;
typedef pair<lli,lli> pl;
inline lli max(lli a,lli b){ return a>b?a:b;}
inline lli min(lli a,lli b){ return a<b?a:b;}
const long long inf = 9e18;
double pie = 2*acos(0.0);
void show(vector<lli> v){fr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;}
void show(vector<int> v){fr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;}
void show(int a[], int arraysize){for (int i = 0; i < arraysize; ++i)cout << a[i] << " ";cout<<endl;}
void show(lli a[], lli arraysize){for (lli i = 0; i < arraysize; ++i)cout << a[i] << " ";cout<<endl;}
void show(bool a[], lli arraysize){for (lli i = 0; i < arraysize; ++i)cout << a[i] << " ";cout<<endl;}
void show(set<int> s){for (auto it = s.begin(); it != s.end(); it++){cout << *it << " ";}cout<<endl;}
void show(map<lli,lli> mp){for (auto it = mp.begin(); it != mp.end(); it++){cout << it->first << " "<<it->second<<endl;}cout<<endl;}

lli modpow(lli x,lli n){lli res=1;while(n>0){if(n&1) res=((res%MOD)*(x%MOD))%MOD;x=((x%MOD)*(x%MOD))%MOD;n>>=1;}return res;}
lli power(lli x, lli n){lli res=1;while(n>0){if(n&1) res=res*x;x=x*x;n>>=1;}return res;}

/////// ------ Main code starts here ------ /////
void solve()
{
    lli n,k;
    cin>>n>>k;
    lli a[n];
    fr(i,0,n)
    {
        cin>>a[i];
    }
    lli dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    fr(i,2,n)
    {
        dp[i]=inf;
        fr(j,1,k+1)
        {
            if(i-j>=0)
                dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
            else
                break;
        }
    }
    cout<<dp[n-1]<<endl;
}
int main()
{
    run;cout<<fixed<<setprecision(12);
    int t;
    t=1;
    while(t){solve();t--;}
    return 0;
}


Measured memory_bytes: 5100
#include <cstdio>
#include <algorithm>
using namespace std;
long long int arr[110000]={};
int inp[110000]={};
int main(){
	int n,t;
	long long int l;
	scanf("%d %lld",&n,&l);
	for(int i=1;i<=n;i++){
		scanf("%d",&inp[i]);
	}
	for(int i=1;i<n;i++){
		arr[i]=inp[i]+inp[i+1];
	}
	t=max_element(arr+1,arr+n)-arr;
	if(arr[t]>=l){
		printf("Possible\n");
		for(int i=1;i<t;i++){
			printf("%d\n",i);
		}
		for(int i=n-1;i>t;i--){
			printf("%d\n",i);
		}
		printf("%d\n",t);
	}
	else{
		printf("Impossible\n");
	}
}


Measured memory_bytes: 1920
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    b = [0]*n
    for i in range(n-1):
        if a[i] < a[i+1]:
            b[i] = 1        #次のほうが高い日
        elif a[i] > a[i+1]:
            b[i] = -1       #次のほうが安い日
    c = [0]*n
    if b[0] == 1:
        c[0] = 1
    elif b[0] == -1:
        c[0] = -1
    for i in range(1,n-1):
        if (b[i-1]==0 or b[i-1]==-1) and b[i] == 1:       #もし今日が前と同じか下がってて、次上がるなら
            c[i] = 1       #株を買うべき
        elif (b[i-1]==0 or b[i-1] ==1) and b[i] == -1:  #もし今日が前と同じかあがってて、次さがるなら
            c[i] = -1      #株を売るべき
    kab = 0
    money = 1000
    for i in range(n):
        if c[i] == -1:
            money += kab*a[i]
            kab = 0
        elif c[i] == 1:
            kab += money//a[i]
            money %= a[i]
    money += kab*a[-1]
    print(money)
resolve()

Measured memory_bytes: 9272
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1ll << 50;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define itn int
#define asn ans
bool dbg = false;

int N;
vector<vi> G;
int SIZE[202020];
int seen[202020];
int cnt[202020];

void solve() {
    FOR(N)
    SIZE[i] = G[i].size();
    queue<int> que;
    int ans = 0;
    FOR(N) {
        if (SIZE[i] == 1)
            que.push(i);
    }
    while (!que.empty()) {
        int a = que.front();
        que.pop();
        seen[a] = 1;
        for (auto b : G[a]) {
            if (seen[b])
                continue;
            if (SIZE[b] >= 3) {
                cnt[b]++;
            }
            if (SIZE[b] == 2)
                que.push(b);
            if (SIZE[b] == 1) {
                cout << 1 << endl;
                return;
            }
        }
    }
    FOR(N) {
        cerr << i << " : " << cnt[i] << endl;
        if (cnt[i] >= 2) {
            ans += cnt[i] - 1;
        }
    }
    if (ans == 0) {
        cout << 1 << endl;
        return;
    }
    cout << ans << endl;
}

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

    cin >> N;
    G.resize(N);
    FOR(N - 1) {
        itn a, b;
        cin >> a >> b;
        G[a].eb(b);
        G[b].eb(a);
    }

    solve();
    return 0;
}


Measured memory_bytes: 10880
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cctype>
#define REP(i,a,b) for(register int i=(a); i<(b); i++)
#define REPE(i,a,b) for(register int i=(a); i<=(b); i++)
#define PERE(i,a,b) for(register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
char buf[1<<21], *p1=buf, *p2=buf;
#define getchar() (p1==p2 && (p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <class T> inline void read(T&x) {
	x=0; char ch; do ch=getchar(); while(ch<=' ');
	while(ch>' ') {x=x*10+ch-'0'; ch=getchar();}
}
#define MAXN 200007
int n,k;
int p[MAXN];
int main() {
	read(n); read(k);
	REP(i,0,n) {read(p[i]); p[i]++;}
	REP(i,1,n) p[i]+=p[i-1];
	PERE(i,n-1,k) p[i]-=p[i-k];
	int ans=0;
	REP(i,k-1,n) {
		ans = max(ans, p[i]);
	}
	printf("%lf\n", ans/2.0);
	return 0;
}



Measured memory_bytes: 1920
#include<stdio.h>
int main(){
  int n,a,b,p=0,g=0,i;
  char s[100010];
  scanf("%*d %d %d %s",&a,&b,s);
  for(i=0;s[i];i++){
    if(s[i]=='a'){
      if(p<a+b){
	printf("Yes\n");
	p++;
      }
      else printf("No\n");
    }
    if(s[i]=='b'){
      if(p<a+b&&g<b){
	printf("Yes\n");
	p++;
	g++;
      }
      else printf("No\n");
    }
    if(s[i]=='c')printf("No\n");
  }
  return 0;
}


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

typedef struct{
        int x,y;
    }point;

int main(void){
    int n,m;
    point student[50],checkpoint[50];
    
    cin >> n >> m;
    for(int i=0;i<n;i++){
        cin >> student[i].x >> student[i].y;
    }
    for(int i=0;i<m;i++){
        cin >> checkpoint[i].x >> checkpoint[i].y;
    }
    
    for(int i=0;i<n;i++){
        int temp = abs(student[i].x - checkpoint[0].x) + abs(student[i].y - checkpoint[0].y);
        int num=0;
        for(int j=0;j<m;j++){
            int l;
            l = abs(student[i].x - checkpoint[j].x) + abs(student[i].y - checkpoint[j].y);
            if(temp > l){
                num=j;
                temp = l;
            }
        }
        cout << num+1 << endl;
    }
}

Measured memory_bytes: 256
# coding: utf-8
while 1:
    d,e=map(int,input().split())
    if d==0:
        break
    data=[]
    for i in range(0,101):
        for j in range(0,101):
            data.append((abs(((i*i+j*j)**0.5)-e),i,j))
    for p in sorted(data):
        if p[1]+p[2]==d:
            print(p[0])
            break


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void ioinit() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); }
i64 gcd(i64 a, i64 b) { if (a % b == 0) return b; else return gcd(b, a % b); }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
template <class T> bool amax(T &x, T y) { if (x < y) { x = y; return 1; } else return 0; }
template <class T> bool amin(T &x, T y) { if (x > y) { x = y; return 1; } else return 0; }
template <class T> i64 lbi(vector<T> &v, T e) { return lower_bound(all(v), e) - v.begin(); }
template <class T> i64 ubi(vector<T> &v, T e) { return upper_bound(all(v), e) - v.begin(); }

int dp[10010];

int main() {
  ioinit();
  int n, m;
  cin >> n >> m;
  vi32 a(m);
  rep(i, m) cin >> a[i];
  map<int, int> honsu = {
    { 1, 2 },
    { 2, 5 },
    { 3, 5 },
    { 4, 4 },
    { 5, 5 },
    { 6, 6 },
    { 7, 3 },
    { 8, 7 },
    { 9, 6 },
  };
  {
    rep(i, 10010) dp[i] = -1e9;
    dp[0] = 0;
    rep(i, n) rep(j, m) amax(dp[i + honsu[a[j]]], dp[i] + 1);
  }
  sort(all(a));
  reverse(all(a));
  {
    int i = n;
    while (i > 0) {
      rep(j, m) {
        if (i - honsu[a[j]] < 0) continue;
        if (dp[i] - 1 != dp[i - honsu[a[j]]]) continue;
        cout << a[j];
        i -= honsu[a[j]];
        break;
      }
    }
    cout << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define maxn 505050
using namespace std;
vector <int> h[maxn];
int n,dis[maxn],rt,d;

void dfs(int u,int fa){
    for (auto v:h[u]){
        if (v==fa) continue;
        dis[v]=dis[u]+1;
        dfs(v,u);
    }
}

int main(){
    cin >> n;
    for (int i=1;i<n;i++){
        int u,v;
        cin >> u >> v;
        h[u].pb(v);
        h[v].pb(u);
    }
    memset(dis,0,sizeof(dis));
    dis[1]=1; dfs(1,0); rt=1;
    for (int i=1;i<=n;i++) if (dis[rt]<dis[i]) rt=i;
    memset(dis,0,sizeof(dis));
    dis[rt]=1; dfs(rt,0);
    for (int i=1;i<=n;i++) d=max(d,dis[i]);
    if (d%3!=2) puts("First"); else puts("Second");
    return 0;
}


Measured memory_bytes: 29696
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int c,g,a,b;
	while(scanf("%d%d",&a,&b)!=EOF)
	{
		c=0;
		g=a+b;
		while(1)
		{
			if(g/10>=1)
				c++;	
			else 
				break;
			g/=10;
		}		
		cout<<c+1<<endl;
	}
	return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N, M; cin >> N >> M;
    if(N == M) cout << "Yes" << endl;
    else cout << "No" << endl;
        return 0;
}

Measured memory_bytes: 256
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def pan(n):
    if len(n) == 0 or len(n) == 1:
        return True
    
    if n[0] != n[-1]:
        return False
    else:
        return pan(n[1:-1])



def solve():
    a,b = f()
    ans = 0
    for i in range(a, b+1):
        if pan(str(i)):
            ans += 1
    
    print(ans)

solve()


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

int main() {
  int N, Q;
  cin >> N >> Q;
  vector<ll> a(N), x(Q);
  rep(i, N) cin >> a.at(i);
  rep(i, Q) cin >> x.at(i);

  rep(i, Q) {
    ll target = x.at(i);
    ll res = 0;
    int right = 0;
    ll sum = 0;
    for (int left = 0; left < N; left++) {
      while (right < N && sum + a.at(right) <= target) {
        sum += a.at(right);
        right++;
      }
      res += right - left;

      if (right == left) {
        right++;
      } else {
        sum -= a.at(left);
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 3544
#ABC 86 C - travelling
n = int(input())
A = [[int(el) for el in input().split(' ')] for i in range(n)]

A.insert(0, [0, 0, 0])

for i in range(1,n+1):
    t = A[i][0] - A[i-1][0]
    d = abs(A[i][1] - A[i-1][1]) + abs(A[i][2] - A[i-1][2])
    if (d <= t) & (d % 2 == t % 2):
        pass
    else:
        print('No')
        break
else:
    print('Yes')


Measured memory_bytes: 21156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N,L;
    cin >> N >> L;
    vl A(N);
    rep(i, N) cin >> A[i];
    bool isok = false;
    ll m;
    rep(i,N-1){
        if(A[i]+A[i+1]>=L){
            isok = true;
            m = i+1;
            break;
        }
    }
    if(!isok){
        cout << "Impossible" << endl;
        return 0;
    }

    cout << "Possible" << "\n";
    repe(i, 1, m) cout << i << "\n";
    reper(i, m + 1, N) cout << i << "\n";
    cout << m << "\n";
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

double dp[16][3][3];
int n, dx[] = {0,-1,0,1}, dy[] = {-1,0,1,0};
char cs, ct, cb;
int s, t, b;

int main(){
  while(scanf("%d", &n) && n){
    memset(dp, 0.0, sizeof(dp));
    scanf("\n%c %c %c", &cs, &ct, &cb);
    s = cs - 'A';
    t = ct - 'A';
    b = cb - 'A';
    //    fprintf(stderr, "%c\n", cs);
    dp[0][s/3][s%3] = 1.0;

    rep(i, n) rep(y, 3) rep(x, 3){
      if(dp[i][y][x] == 0) continue;
      rep(d, 4){
	int ny = y + dy[d], nx = x + dx[d];
	if(ny < 0 || nx < 0 || ny >= 3 || nx >= 3 || ny*3+nx == b) dp[i+1][y][x] += dp[i][y][x]*0.25;
	else dp[i+1][ny][nx] += dp[i][y][x]*0.25;
      }
    }

    printf("%.8lf\n", dp[n][t/3][t%3]);
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  string s; cin >> s;
  int n = s.size();

  {
    bool f = true;
    char c = s[0];
    reps(i, n - 1) if (c != s[i]) f = false;
    if (f) {
      cout << n << '\n';
      return;
    }
  }

  if (n % 2 == 0) {
    int ans = 1e9;
    repi(i, n / 2, n) {
      if (s[i - 1] != s[i]) {
        amin(ans, i);
      }
    }
    reps(i, n / 2) {
      if (s[i - 1] != s[i]) {
        amin(ans, n - i);
      }
    }
    cout << ans << '\n';
  } else {
    int ans = 1e9;
    repi(i, n / 2 + 1, n) {
      if (s[i - 1] != s[i]) {
        amin(ans, i);
      }
    }
    reps(i, n / 2) {
      if (s[i - 1] != s[i]) {
        amin(ans, n - i);
      }
    }
    cout << ans << '\n';
  }
}


Measured memory_bytes: 512
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,x = LI()
    s = LI()
    s.sort()
    dp = [[0]*(n+1) for i in range(x+1)]
    for i in range(n):
        si = s[i]
        ni = i+1
        for j in range(x+1):
            dp[j][0] = j
            nd = (dp[j%si][i]+i*dp[j][i])%mod
            dp[j][ni] += nd
    print(dp[x][n]%mod)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 200460