akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int n=in.nextInt(),max=-1000000,min=1000000;long sum=0;
		for(int i=0;i<n;i++) {
			int a=in.nextInt();
			max=Math.max(max, a);
			min=Math.min(min, a);
			sum+=a;
		}
		out.printf("%d %d %d\n",min,max,sum);
		out.flush();
	}

}



Measured memory_bytes: 41272
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

const int INF=1e9;
int dx[4]={1,0,-1,0}; // D,R,U,L;
int dy[4]={0,1,0,-1};
int h,w,k;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);    
    cin >> h >> w >> k;
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    --x1; --y1; --x2; --y2;
    vector<string> G(h);
    REP(i,h) cin >> G[i];
    vector<VI> d(h,VI(w,INF));
    d[x1][y1]=0;
    queue<PII> q;
    q.emplace(x1,y1);
    while ( q.size() ) {
        int x=q.front().first;
        int y=q.front().second;
        q.pop();
        REP(i,4) {
            int nx=x;
            int ny=y;
            REP(_,k) {
                nx=nx+dx[i];
                ny=ny+dy[i];
                if ( nx<0||nx>=h||ny<0||ny>=w||G[nx][ny]=='@' ) break;
                if ( d[nx][ny]<=d[x][y] ) break;
                if ( d[nx][ny]>d[x][y]+1 ){
                    d[nx][ny]=d[x][y]+1;
                    q.emplace(nx,ny);
                }
            }
        }        
    }
    cout << (d[x2][y2] < INF ? d[x2][y2] : -1) << '\n';
    return 0;
}



Measured memory_bytes: 12168
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

const int MAX = 1e7;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


signed main(){
   int x,y;
   cin>>x>>y;
   ll mod=1e9+7;
   if(2*x-y<0 || (2*x-y)%3!=0 ||2*y-x<0 || (2*y-x)%3!=0){
       cout<<0<<endl;
       return 0;
   }

   int a,b; 
   a=(2*x-y)/3;
   b=(2*y-x)/3;
   COMinit();
   cout<<COM(a+b,a)<<endl;
   
    return 0;
}

Measured memory_bytes: 234624
#include<stdio.h>
int main(void){
	int A1,A2,A3,Sum;
  	scanf("%d",&A1);
	scanf("%d",&A2);
  	scanf("%d",&A3);
  	Sum = A1 + A2 + A3;
  	if(Sum>=22) printf("bust\n");
	else printf("win\n");
  	return 0;
}

Measured memory_bytes: 128
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <iomanip>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int a[100*1000];
int b[100*1000];
int N;
int main() {
	scanf("%d",&N);
	int mina=1<<30;
	int maxa=-(1<<30);
	int minb=1<<30;
	int maxb=-(1<<30);
	for(int i=0;i<N;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		a[i]=x+y;
		mina=min(mina,a[i]);
		maxa=max(maxa,a[i]);
		b[i]=x-y;
		minb=min(minb,b[i]);
		maxb=max(maxb,b[i]);
		//cout << a[i] << ", " << b[i] << endl;
	}
	int low=0;
	int hi=max(maxa-mina,maxb-minb);
	while(low+1<hi){
		int mid=(low+hi)/2;
		bool ok0=true;
		bool ok1=true;
		for(int i=0;(ok0||ok1)&&i<N;i++){
			if((a[i]-mina>mid||b[i]-minb>mid)&&
			   (maxa-a[i]>mid||maxb-b[i]>mid)){
				ok0=false;
			}
			if((a[i]-mina>mid||maxb-b[i]>mid)&&
			   (maxa-a[i]>mid||b[i]-minb>mid)){
				ok1=false;
			}
		}
		if(ok0||ok1){
			hi=mid;
		}
		else{
			low=mid;
		}
	}
	printf("%d\n",hi);
}

Measured memory_bytes: 1968
/* written by : vipin kumar */
#include<iostream>
#include<set>
#include<map>
#include<unordered_set>
#include<cmath>
#include<algorithm>
using namespace std;
#include<vector>
#define int long long int
#define mod 1000000007
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	int j,arr[n+1];
	for(j=1;j<=n;j++)
	   cin>>arr[j];
	int answer=0;
	for(j=1;j<=n;j++)
	{
		if(j%2!=0&&arr[j]%2!=0)
		   answer++;
	}
	cout<<answer<<endl;
}



Measured memory_bytes: 3632
#include<iostream>
#include<stdio.h>
#include<string>
#include <math.h>
using namespace std;
# define maxn 100000

int main(){
  // int n,m,a[maxn],b[maxn],c[maxn],cnt(0),sum(0);
  long long n,k,c[maxn]={0},cnt(0),sum(0);
  int a,p;
  cin>>a>>p;
  cout << (a*3+p)/2;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define XD (a+b+c)
using namespace std;

const int maxn=302;
bool bylo[maxn][maxn][maxn];
double dp[maxn][maxn][maxn];
int n;

double calc(int a, int b, int c)
{
	//printf("a=%d b=%d c=%d\n",a,b,c);
	if(a==-1 || b==-1 || c==-1)
		return 0;
	if(a==0 && b==0 && c==0)
		return 0;
	if(bylo[a][b][c])
		return dp[a][b][c];
	bylo[a][b][c]=true;
	dp[a][b][c]=((double)n/XD)+calc(a-1,b,c)*((double)a/XD)+calc(a+1,b-1,c)*((double)b/XD)+calc(a,b+1,c-1)*((double)c/XD);
	return dp[a][b][c];
}
     
int main()
{
	scanf("%d",&n);
	int a=0,b=0,c=0;
	for(int i=1;i<=n;i++)
	{
		int p;
		scanf("%d",&p);
    	if(p==1) ++a;
		if(p==2) ++b;
		if(p==3) ++c;
	}
	//printf("a=%d b=%d c=%d\n",a,b,c);
	printf("%.10lf",calc(a,b,c));
}

Measured memory_bytes: 241920
#include <iostream>
#include <string>

using namespace std;
typedef long long ll;

int main(){
    string s, t;
    getline(cin, s);
    getline(cin, t);
    for(int i = 0; i < s.size(); ++i){
        string tmp = s.substr(i) + s.substr(0, i);
        if(tmp == t){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    string S;
    cin >> S;
    int N = (int)S.size();
    int bestcnt = N; //cntの最小値を取る
    for(int i = 0; i < 2; i++){ //iは最初のタイルの色
        int cnt = 0; //黒白黒白・・・の場合と、白黒白黒・・・の場合で、塗り替えないといけない回数を記録
        for(int j = 0; j < N; j++){
            if((j % 2 == 0) && ((int)S.at(j) != (i + '0'))) cnt++;
            if((j % 2 == 1) && ((int)S.at(j) == (i + '0'))) cnt++;
        }
        bestcnt = min(bestcnt, cnt);
    }
    cout << bestcnt << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int dp[5005][5005];

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    string s;
    cin >> n >> s;

    for (int i = n - 1; i >= 0; --i) {
        for (int j = n - 1; j >= 0; --j) {
            if (s[i] != s[j]) dp[i][j] = 0;
            else dp[i][j] = dp[i + 1][j + 1] + 1;
        }
    }

    int res = 0;
    rep(i, n) {
        rep(j, n) {
            if (i >= j) continue;
            int now = min(dp[i][j], j - i);
            chmax(res, now);
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 98048
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a = in.nextInt();
        long b = in.nextInt();
        long lcm = a * b / gcd(a,b);
        System.out.println(lcm);
    }
    private static long gcd(long a, long b) {
        if(a==b) {
            return a;
        }
        if(b>a) {
            // swap
            long s = a;
            a = b;
            b = s;
        }
        while(true) {
            long mod = a % b;
            if(mod==0) {
                return b;
            }
            a = b;
            b = mod;
        }
    }
}


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

x = input().split()

for i in range(len(x)):
    x[i] = int(x[i])

x.sort()

if(n>=m):
    print(0)
else:
    dis = []
    for i in range(len(x)-1):
        dis.append(x[i+1] - x[i])

    dis.sort(reverse=True)
    for i in range(n-1):
        dis[i] = 0

    sum = 0
    for i in dis:
        sum += i

    print(sum)

Measured memory_bytes: 10628
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

ll dp[105][1000005];

int main(){
  int N, W;
  cin >> N >> W;
  vector<ll> w(N), v(N);
  rep(i, N) cin >> w[i] >> v[i];

  for(int i = 0; i <= N; i++){
    for(int j = 0; j < 1000005; j++) dp[i][j] = LLONG_MAX / 100;
  }

  dp[0][0] = 0;
  for(int i = 0; i < N; i++){
    for(int j = 0; j <= 1000000; j++){
      // //cerr << i << ' ' << j << endl;
      if(v[i] <= j) dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
      else dp[i + 1][j] = dp[i][j];
    }
  }

  int ans = 0;
  for(int i = 0; i <= 1000000; i++){
    if(dp[N][i] <= W) ans = i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 790784
using System;

class Program
{
  static void Main(string[] args)
  {
    int A,B,C,D,E,K;
    A = int.Parse(Console.ReadLine());
    B = int.Parse(Console.ReadLine());
    C = int.Parse(Console.ReadLine());
    D = int.Parse(Console.ReadLine());
    E = int.Parse(Console.ReadLine());
    K = int.Parse(Console.ReadLine());
    
    int[] nums = new int[]{A,B,C,D,E};
    Array.Sort(nums);
    if(nums[4] - nums[0] <= K) Console.WriteLine("Yay!");
    else Console.WriteLine(":(");
  }
}

Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
using namespace std;

int INF = 1e9 + 7;

typedef long long ll;
typedef pair<int, int> P;

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

	cout << pow(2, m) * 1900 * m + (n - m) * 100 * pow(2, m) << endl;
}

Measured memory_bytes: 384
program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,k,m,n,ans
    integer(8)::a,b,c,d
    integer(8),allocatable::x(:),y(:)
  
    read(*,*) a,b
    if(mod(a,2019)==0 .or. mod(b,2019)==0)then

        write(*,*)0
        stop
    elseif(b/2019-a/2019/=0)then
        write(*,*)0
        stop
    else
        a=mod(a,2019)
        b=mod(b,2019)
    end if
    ans=10000
    do i=a,b-1
        do j=i+1,b
            c=mod(i*j,2019)
            if(c==0)then
                write(*,*)0
                stop
            elseif(c<ans)then
                ans=c
            end if
        end do
    end do
    write(*,*)ans

    stop
end program sample
  



Measured memory_bytes: 2832
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<ll,ll>;
#define For(i,a,b)  for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define bpc __builtin_popcount
#define MOD (ll)(1e9+7)
#define INF (2e9)
#define EPS (1e-6)
#define NATHANLEE_IS_EVIL_AND_ELECTRIC true
#define int ll
#ifdef LOCAL_TEST
#define debug(...) do{\
	cerr<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<\
	" : ("#__VA_ARGS__<<") = ";\
	_OUT(__VA_ARGS__);\
}while(0)
template<typename T>void _OUT(T x){cerr<<x<<"\n";}
template<typename T,typename...I>void _OUT(T x,I ...tail){cerr<<x<<", ";_OUT(tail...);}
#else
#define debug(...)
#endif
void INIT(){
#ifdef LOCAL_TEST
	freopen("D:\\input.in","r",stdin);
	freopen("D:\\output.out","w",stdout);
	freopen("D:\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(!NATHANLEE_IS_EVIL_AND_ELECTRIC);
	cin.tie(0);
}

ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll fpow(ll b,ll p){
	b%=MOD;
	ll ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}

bool dp[100010];

int32_t main() {
	INIT();
	//code...
	int n,k; cin>>n>>k;
	vector<int> a(n);
	for(auto &i:a)
		cin>>i;
	For(i,0,k){
		dp[i]=false;
		for(auto &j:a){
			if(i>=j && !dp[i-j]) dp[i]=true;
		}
	}
	if(dp[k]) cout<<"First\n";
	else cout<<"Second\n";
	return 0;
}

Measured memory_bytes: 3712
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [0 for i in range(26)]
for i in range(1, D+1):
  inc = [s[i-1][j] - c[j]*(i-t[j-1])*(i+1-t[j-1])//2 for j in range(26)]
  max_index = inc.index(max(inc))
  t[max_index] = i
  print(max_index+1)

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

int main() {
	int n; cin >> n;
	vector<int>a(n), b(n), c(n);
	for (auto&& x : a)cin >> x;
	for (auto&& x : b)cin >> x;
	for (auto&& x : c)cin >> x;
	sort(a.begin(), a.end()); sort(c.begin(), c.end());

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		long long aNum = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
		long long cNum = c.end() - upper_bound(c.begin(), c.end(), b[i]);
		ans += aNum * cNum;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main() {
    int h, w;
    vector< pair<int, int> > m8 = {{-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}};
    cin >> h >> w;
    vector< vector<char> > s(h + 2, vector<char>(w + 2, '.'));
    for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j) cin >> s.at(i).at(j);
    for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
            if (s.at(i).at(j) - '.') cout << '#';
            else {
                int n = 0;
                for (int k = 0; k < 8; ++k) if (s.at(i + m8.at(k).first).at(j + m8.at(k).second) - '.') ++n;
                cout << n;
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
H,W=map(int,input().split())
S=[input() for i in range(H)]
A=[[0]*W for i in range(H)]
for i in range(H):
    k=0
    for j in range(W):
        if S[i][j]=="#":
            k=0
        else:
            k+=1
        A[i][j]=k
    for j in range(W-1,0,-1):
        if A[i][j-1]!=0 and A[i][j]!=0:
            A[i][j-1]=A[i][j]
B=[[0]*W for i in range(H)]
for j in range(W):
    k=0
    for i in range(H):
        if S[i][j]=="#":
            k=0
        else:
            k+=1
        B[i][j]=k
    for i in range(H-1,0,-1):
        if B[i][j]!=0 and B[i-1][j]!=0:
            B[i-1][j]=B[i][j]
ans=0
for i in range(H):
    for j in range(W):
        ans=max(ans,A[i][j]+B[i][j])
print(ans-1)


Measured memory_bytes: 125912
n, k = map(int,input().split())

if k >= 2 * n:
    print(n)
    quit()
elif k >= n and k < 2*n:
    print(abs(n-k))
    quit()
elif n > k:
    x_b = n%k
    x = abs(x_b - k)
    print(min(x_b,x))


Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
typedef pair<double,double> P;
#define eps 1e-7
#define fi first
#define sec second
int n,ans;
P circle[105];
double sq(double x){return x*x;}
double culc_dist(int s,int t)
{
	P a=circle[s],b=circle[t];
	return sqrt(sq(a.fi-b.fi)+sq(a.sec-b.sec));
}
double dist(P a,P b)
{
	return sqrt(sq(a.fi-b.fi)+sq(a.sec-b.sec));
}
bool is_intersect(int s,int t)
{
	return culc_dist(s,t)<=2.0+eps;
}
P center_pos(int s,int t)
{
	P a=circle[s],b=circle[t];
	return P((a.fi+b.fi)/2,(a.sec+b.sec)/2);
}
P normal_vector(int s,int t)
{
	P a=circle[s],b=circle[t];
	return P(a.sec-b.sec,b.fi-a.fi);
}
P expand(int s,int t)
{
	P n=normal_vector(s,t);
	double sin_x=sqrt(1-(sq(culc_dist(s,t))/4));
	double len=sqrt(sq(n.fi)+sq(n.sec));
	return P(n.fi*sin_x/len,n.sec*sin_x/len);
}
int culc_covered(P p)
{
	if(p.fi<0||p.fi>10||p.sec<0||p.sec>10)return 0;
	int ret=0;
	for(int i=0;i<n;i++)if(dist(p,circle[i])<=1.0+eps)ret++;
	return ret;
}
int main()
{
	while(1)
	{
		cin >> n;
		if(n==0)return 0;
		ans=1;
		for(int i=0;i<n;i++)scanf("%lf,%lf",&circle[i].fi,&circle[i].sec);
		for(int i=0;i<n;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(!is_intersect(i,j))continue;
				P center=center_pos(i,j);
				P orientation=expand(i,j);
				ans=max(ans,culc_covered(P(center.fi-orientation.fi,center.sec-orientation.sec)));
				if(!(abs(orientation.fi)<eps&&abs(orientation.sec)<eps))ans=max(ans,culc_covered(P(center.fi+orientation.fi,center.sec+orientation.sec)));
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}
int ans;
int main(){
    char ch[3];
    for (int i = 0; i < 3; i++){
        ch[i] = getchar();
        if (ch[i] == 'R' && ch[i-1] == 'R')
            ans++;
        else if (ch[i] == 'R')
            ans = 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int ans,h,w,n,p;
  cin>>h>>w>>n;
  p=max(w,h);
  if(n%p==0){
    ans=n/p;
  }
  else{
    ans=n/p+1;
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <iomanip>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;
 
#define ll long long
#define pii pair<int,int>
/**==Info==
*Program:3
*Problem:Small Multiply
*Date:2017-11-18
*Algorithm:Teacher's deque
*Stats:Unknown*/
 
bool debug=false;
 
template<typename T> struct pq_small{
	priority_queue<T,vector<T>,greater<T> > pq;
	void push(T x){
		pq.push(x);
	}
 
	void pop(){
		pq.pop();
	}
 
	int size(){
		return pq.size();
	}
 
	bool empty(){
		return pq.empty();
	}
 
	T top(){
		return pq.top();
	}
};
 
int dis[100005];
int main(int argc,char* argv[]){
	int k;
	cin>>k;
	deque<int> dq;
	for(int i=0;i<=k;i++) dis[i]=1e9;
	dis[1]=1;
	dq.push_front(1);
	while(!dq.empty()){
		int last=dq.front();
		dq.pop_front();
		
		if(dis[last*10%k]>dis[last]){
			dis[last*10%k]=dis[last];
			dq.push_front(last*10%k);
		}
		if(dis[(last+1)%k]>dis[last]+1){
			dis[(last+1)%k]=dis[last]+1;
			dq.push_back((last+1)%k);
		}
	}
	
	cout<<dis[0];
	return 0;
}

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

using namespace std;

int n,m,d[201][5010],it[201][20010];
long long s[5010][5010],a[5010];

void tree_build(int tree,int p,int l,int r)
{
    if (l==r)
    {
        it[tree][p]=l;
        return;
    }
    tree_build(tree,p*2,l,(l+r)/2);
    tree_build(tree,p*2+1,(l+r)/2+1,r);
    if (d[tree][it[tree][p*2]]>d[tree][it[tree][p*2+1]]) it[tree][p]=it[tree][p*2];
    else it[tree][p]=it[tree][p*2+1];
}

int get(int tree,int p,int l,int r,int a,int b)
{
    if (r<a or l>b) return 0;
    if (l>=a and r<=b)
        return it[tree][p];
    int x1=get(tree,p*2,l,(l+r)/2,a,b),x2=get(tree,p*2+1,(l+r)/2+1,r,a,b);
    if (d[tree][x1]>d[tree][x2])return x1;
    else return x2;
}

void array_build(int ind,int l,int r)
{
    if (r<l) return;
    int opt=get(ind,1,1,n,l,r);
    s[l][opt]+=d[ind][opt];
    s[l][r+1]-=d[ind][opt];
    s[opt+1][opt]-=d[ind][opt];
    s[opt+1][r+1]+=d[ind][opt];
    array_build(ind,l,opt-1);
    array_build(ind,opt+1,r);
}

int main()
{
    //freopen("input.txt","r",stdin);
    scanf("%d%d",&n,&m);
    for (int i=2;i<=n;i++)
        scanf("%lld",&a[i]),a[i]+=a[i-1];
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            scanf("%d",&d[j][i]);
    for (int i=1;i<=m;i++)
        tree_build(i,1,1,n);
    for (int i=1;i<=m;i++)
        array_build(i,1,n);
    for (int i=1;i<=n;i++)
    {
        for (int j=1;j<=n;j++)
            s[i][j]+=s[i][j-1];
        for (int j=1;j<=n;j++)
            s[i][j]+=s[i-1][j];
    }
    long long res=-1;
    for (int i=1;i<=n;i++)
        for (int j=i;j<=n;j++)
            res=max(res,s[i][j]-a[j]+a[i]);
    cout << res << "\n";
}


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

using ll = long long;
using P = pair<int, int>;
#define rep1(i,n) for (int i=1; i<=n; i++)
#define rep0(i,n) for (int i=0; i<n; i++)
#define zarray(x,n) x[n+1]; rep1(i,n) {x[i]=0;} 

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

    int aa[2020] = {0};
    
    aa[0] = 1;
    int a = 0;
    int c = 1;
    for (int j=(int)s.length()-1; j>=0; j--) {
        a += (s[j] - '0') * c;
        a %= 2019;
        aa[a]++;
        c *= 10;
        c %= 2019;
    }

    ll ans = 0;
    for(int mod : aa) {
        if (mod == 0) continue;
        ans += mod*(mod-1)/2;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3700
import sys
input = sys.stdin.readline

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

compression_dict={a: ind+1 for ind, a in enumerate(sorted(set(A)|set(B)))}

SA=sorted(A)
SB=sorted(B)

for i in range(N):
    if SA[i]>SB[i]:
        print("No")
        sys.exit()

for i in range(N-1):
    if SB[i]>=SA[i+1]:
        print("Yes")
        sys.exit()

AB=[(B[i],A[i]) for i in range(N)]
AB.sort()

DICT={a:ind for ind,a  in enumerate(SA)}

Group=[i for i in range(N)]# グループ分け.Group[i]=jのときiとjは同じグループ

def find(x):# find(a)=find(b)のとき同じグループ
    while Group[x] != x:
        x=Group[x]
    return x

def Union(x,y):  # xとyが同じグループになるよう更新
    if find(x) != find(y):
        Group[find(y)]=Group[find(x)]=min(find(y),find(x))

for i in range(N):
    _,a=AB[i]

    Union(DICT[a],i)

if len(set([find(i) for i in range(N)]))==1:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 106152
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N, M;
	cin >> N;
	cin >> M;
	vector<double> v(N, 0);
	for (int i = 0; i < N; ++i) {
		cin >> v[i];
	}
	priority_queue<double> que;
	for (auto it : v)
	{
		que.push(it);
	}
	for (int i = 0; i < M; ++i) {
		double x = que.top();
		que.pop();
		double p = x / 2.0;
		que.push(p);
	}
	long long s = 0;
	while (!que.empty()) {
		s += int(que.top());
		que.pop();
	}
	cout << s;
}

Measured memory_bytes: 2168
const input = require("fs").readFileSync("/dev/stdin", "utf8")

const lines = input.split('\n')
const [N, M] = lines[0].split(' ').map(Number)

const f = (n) => {
  let sum = 0
  for (let i = 1; i <= n; i++) {
    sum += i
  }
  return sum
}

console.log(f(N - 1) + f(M - 1))

Measured memory_bytes: 29440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
#define PI 3.14159265358979
#define MOD 998244353
const int MAX = 510000;

int main() {
  int N,W;
  cin>>N>>W;
  char s[N][W];
  int dp[N][W];
  int dx[2]={0,1};
  int dy[2]={1,0};
  rep(i,N){
  	rep(j,W){
      cin>>s[i][j];
      dp[i][j]=1000;
    }
  }
  
  dp[0][0]=0;
  if(s[0][0]=='#')dp[0][0]=1;
  for(int i=0;i<N;i++){
  	for(int j=0;j<W;j++){
    	for(int d=0;d<=1;d++){
          int ni=i+dx[d],nj=j+dy[d];
          if(ni>=N||nj>=W){continue;}
          if(s[i][j]=='.'&&s[ni][nj]=='#'){dp[ni][nj]=min(dp[i][j]+1,dp[ni][nj]);}
          else{dp[ni][nj]=min(dp[ni][nj],dp[i][j]);}
        }
    }
  }
  cout<<dp[N-1][W-1];
}

Measured memory_bytes: 256
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<string>
#include<map>
using namespace std;
typedef long long lng;
#define UP(i,a,b) for(int i=(a); i<=(b); ++i)
#define DOWN(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) UP(i,0,(n)-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //NOTE: <a> must be sorted in advance
typedef pair <string,string> P;
lng power(lng b, int n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n in O(log(n)) time

const int MOD = 1000000007; //10^9+7
const double PI = 3.1415926535897932384626;

/*********** variables ************/
int N;
string S;
map<P, int> mp;
/**********************************/


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N>>S;

    lng ans = 0;
    for(int n=0; n<(1<<N); n++) {
        string s1 = "", s2 = "";
        REP(b, N) {
            if(n&(1<<b)) {
                s1 += S[b];
            }
        }
        DOWN(b, N-1, 0) {
            if(!(n&(1<<b))) {
                s2 += S[b];
            }
        }
        mp[P(s1, s2)]++;
    }
    for(int n=0; n<(1<<N); n++) {
        string s1 = "", s2 = "";
        REP(b, N) {
            if(n&(1<<b)) {
                s1 += S[b + N];
            }
        }
        DOWN(b, N-1, 0) {
            if(!(n&(1<<b))) {
                s2 += S[b + N];
            }
        }
        ans += mp[P(s2, s1)];
    }
    cout << ans << endl;
}


Measured memory_bytes: 91904
#include <iostream>
#include <string>
using namespace std;
const int INF = 1<<30;
template<typename T1, typename T2> T1 gcd(T1 a, T2 b) { return (b ? gcd(b, a % b) : a); }
template<class Type> class BinaryTree
{
    struct Node { Type val; Node *left, *right; };
    public:
        Node *root = nullptr;
        Node *insert(Node *p, Type x)
        {
            if(p == nullptr) { Node *q = new Node; q->val = x; q->left = q->right = nullptr; if(root == nullptr) root = q; return q; }
            else { if(x < p->val) p->left = insert(p->left, x); else p->right = insert(p->right, x); return p; }
        }
        bool find(Node *p, Type x)
        {
            if(p == nullptr) return false;
            else if(x == p->val) return true;
            else if(x < p->val) return find(p->left, x);
            else return find(p->right, x);
        }
        Node *remove(Node *p, Type x)
        {
            if(p == nullptr) return nullptr;
            else if(x < p->val) p->left = remove(p->left, x);
            else if(x > p->val) p->right = remove(p->right, x);
            else if(p->left == nullptr && p->right == nullptr) { delete p; return nullptr; }
            else if(p->right == nullptr) { Node *q = p->left; delete p; return q; }
            else if(p->left == nullptr) { Node *q = p->right; delete p; return q; }
            else if(p->right->left == nullptr) { Node *q = p->right; q->left = p->left; delete p; return q; }
            else
            {
                Node *q;
                for(q = p->right; q->left->left != nullptr; q = q->left);
                Node *r = q->left;
                q->left = r->right;
                r->left = p->left, r->right = p->right;
                delete p;
                return r;
            }
            return p;
        }
        void print() { inorder(root); cout << endl; preorder(root); cout << endl; }
        void inorder(Node *p) { if(p->left != nullptr) inorder(p->left); cout << " " << p->val;if(p->right != nullptr) inorder(p->right); }
        void preorder(Node *p) { cout << " " << p->val; if(p->left != nullptr) preorder(p->left); if(p->right != nullptr) preorder(p->right); }
};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    BinaryTree<int> bt;
    for(int i = 0; i < n; i++)
    {
        string s; cin >> s;
        if(s == "print") bt.print();
        else
        {
            int x; cin >> x;
            if(s == "insert") bt.insert(bt.root, x);
            if(s == "find") cout << (bt.find(bt.root, x) ? "yes" : "no") << "\n";
            if(s == "delete") bt.remove(bt.root, x);
        }
        
    }
    return 0;
}




Measured memory_bytes: 18660
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n := scanInt()
	ps := scanInts(n)

	bit := make(BIT, n+2)
	idx := make([]int, n+1)
	for i := 0; i < n; i++ {
		idx[ps[i]] = i+1
	}

	ans := 0
	for i := 0; i < n; i++ {
		num := n-i
		base := bit.Sum(idx[num])
		r1 := sort.Search(n+1-idx[num], func(idr int) bool {
			return 1 <= bit.Sum(idx[num]+idr)-base
		})+idx[num]
		r2 := sort.Search(n+1-idx[num], func(idr int) bool {
			return 2 <= bit.Sum(idx[num]+idr)-base
		})+idx[num]

		l1 := sort.Search(idx[num], func(idl int) bool {
			return -1 < bit.Sum(idl)-base
		})
		l2 := sort.Search(idx[num], func(idl int) bool {
			return -2 < bit.Sum(idl)-base
		})

		bit.Add(idx[num], 1)

		ans += ((r1-idx[num])*(l1-l2)+(r2-r1)*(idx[num]-l1))*(num)
		// debug(num,ans)
		// debug(idx[num], l2, l1, r1, r2)
	}

	fmt.Fprintln(wr, ans)

}

// BIT type
type BIT []int

// Sum function calculates a sum to i
func (t BIT) Sum(i int) int {
	s := 0
	for i++; i > 0; i -= i & -i {
		s += t[i]
	}
	return s
}

// Add function add x to i
func (t BIT) Add(i, x int) {
	for i++; i < len(t); i += i & -i {
		t[i] += x
	}
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (long long i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;

void solve()
{
    LL mod = (LL)1e9 + 7LL;

    LL N;
    cin >> N;
    LL M;
    cin >> M;
    LL ans = 0;

    if (abs(N - M) > 1)
    {
        cout << 0 << endl;
        return;
    }

    ans = 1;
    if (N != M)
    {
        if (N < M)
            swap(N, M);
        // 以下 N = M+1 である場合のみ考える
        REP1(i, M)
        {
            ans *= ((i * i) % mod);
            ans %= mod;
        }
        ans *= (M + 1);
        ans %= mod;
        cout << ans << endl;
    }
    else
    {
        REP1(i, N)
        {
            ans *= ((i * i) % mod);
            ans %= mod;
        }
        cout << ((ans * 2LL) % mod) << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 256
n = int(input())
B = 0
A = 0
AB = 0
count = 0

for _ in range(n):
    line = list(input())
    for i in range(len(line)-1):
        if line[i] == 'A' and line[i+1] == 'B':
            count += 1
    if line[0] == 'B' and line[len(line)-1] == 'A':
        AB += 1
    elif line[0] == 'B':
        B += 1
    elif line[len(line)-1] == 'A':
        A += 1


if AB > 1:
    count += AB - 1
    if A > 0:
        count += 1
    if B > 0:
        count += 1
    if A-1 > 0 and B-1 > 0:
        count += min([A-1,B-1])
elif AB == 1:
    if A > 0:
        count += 1
    if B > 0:
        count += 1
    if A-1 > 0 and B-1 > 0:
        count += min([A-1,B-1])
else:
    count += min([A,B])

print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using 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 (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = (1ll<<31)-1;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
class LazySegTree{
    private:
        ll n;
        vector<ll> node,lazy;
    public:
        LazySegTree(vector<ll> v){
            ll sz = v.size();
            n = 1;
            while(n < sz) n *= 2;
            node.resize(2*n-1,INF);
            lazy.resize(2*n-1,-1);
            rep(i,sz) node[i+n-1] = v[i];
            for(int i = n-2;i >= 0;i--) node[i] = min(node[i*2+1],node[i*2+2]);
        }
        void eval(ll k,ll l,ll r){
            if(lazy[k] != -1){
                node[k] = lazy[k];
                if (r-l > 1){
                    lazy[2*k+1] = lazy[k];
                    lazy[2*k+2] = lazy[k];
                }
                lazy[k] = -1;
            }
        }
        void update(ll a,ll b,ll x,ll k=0,ll l=0,ll r=-1){
            if (r < 0) r = n;
            eval(k,l,r);
            if (b <= l || r <= a) return;
            if (a <= l && r <= b){
                lazy[k] = x;
                eval(k,l,r);
                return;
            }
            update(a,b,x,2*k+1,l,(l+r)/2);
            update(a,b,x,2*k+2,(l+r)/2,r);
            node[k] = min(node[2*k+1],node[2*k+2]);
        }
        ll query(ll a,ll b,ll k = 0,ll l = 0,ll r = -1){
            if (r < 0) r = n;
            if (b <= l || r <= a) return INF;
            eval(k,l,r);
            if (a <= l && r <= b) return node[k];
            ll vl = query(a,b,2*k+1,l,(l+r)/2);
            ll vr = query(a,b,2*k+2,(l+r)/2,r);
            return min(vl,vr);
        }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,q,s,t,x;
    bool c;
    cin >> n >> q;
    vector<ll> v(n,INF);
    LazySegTree p(v);
    rep(i,q){
        cin >> c;
        if (c == 0){
            cin >> s >> t >> x;
            p.update(s,t+1,x);
        }
        else{
            cin >> s >> t;
            PRINT(p.query(s,t+1));
        }
    }
}



Measured memory_bytes: 8708
# -*- coding: utf-8 -*-

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	w,h= map(int, io().split())
	w1,h1= map(int, io().split())
	return (w-w1)*(h-h1)

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

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

class pt{
public:
	int x,y;
	pt(int _x, int _y){
		x = _x;
		y = _y;
	}

	pt rot(){
		return pt(-y,x);
	}

};

int main() {
	int x,y;

	cin >> x >> y;
	pt pt1(x,y);
	cin >> x >> y;
	pt pt2(x,y);
	pt dir(pt2.x-pt1.x,pt2.y-pt1.y);
	dir = dir.rot();
	pt pt3(dir.x+pt2.x,dir.y+pt2.y);
	dir = dir.rot();
	pt pt4(dir.x+pt3.x,dir.y+pt3.y);

	printf("%d %d %d %d\n",pt3.x,pt3.y,pt4.x,pt4.y);
}


Measured memory_bytes: 256
n, m, x, y = map(int, input().split())

x_list = list(map(int, input().split()))
y_list = list(map(int, input().split()))

x_max = max(x_list)
y_min = min(y_list)

if (x_max < y_min) and (x_max+1 > x and y_min <= y):
    print('No War')
else:
    print('War')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>


void test_case()
{
    ll k;
    cin>>k;
    queue<ll> q;
    for(ll i=1;i<=9;i++)
        q.push(i);
    ll v;
    while(k--) {
        v=q.front();
        q.pop();
        if(v%10!=0)
            q.push(10*v + v%10 - 1);
        q.push(10*v + v%10);
        if(v%10!=9)
            q.push(10*v + v%10 +1);
    }
    cout<<v;
}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}


Measured memory_bytes: 4724
N, K = gets.split.map(&:to_i)
J = (N - 1) * (N - 2) / 2

if K > J
  puts -1
else
  puts (J - K + N - 1)
  puts (2 .. N).map{|v| "#{1} #{v}" }
  puts (2 .. N).to_a.combination(2).take(J - K).map{|u,v| "#{u} #{v}" }
end

Measured memory_bytes: 2428
#!/usr/bin/env python3
import sys

MOD = 2  # type: int

def solve(N: int, a: "List[int]"):
    a = [0] + a
    result = [0 for i in range(N+1)]
    for i in range(N, 0, -1):
        bai = 1

        summation = 0
        while bai * i <= N:
            summation += result[bai * i]
            bai += 1

        if a[i] == 0:
            if summation % 2 == 0:
                result[i] = 0
            else:
                result[i] = 1
        else:
            if summation % 2 == 0:
                result[i] = 1
            else:
                result[i] = 0
                
    print(sum(result))

    if sum(result) > 0:
        output = ''
        for i in range(1, N+1):
            if result[i] == 1:
                output += ' %d' % (i)
        print(output[1:])
    
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12560
#include<bits/stdc++.h>
#define int long long 
using namespace std;
int n,z[26][300000],d,l,sum,ff,flag[1000000],f[1000000],kk,ans;
char s[300000];
void putit(int x,int y){for (;x;x-=x&(-x))f[x]+=y;}
int findit(int x){int ans=0;for(;x<=l;x+=x&(-x))ans+=f[x];return ans;}
signed main(){
	scanf("%s",s);l=strlen(s);
	for (int i=0;i<l;i++)z[s[i]-'a'][++z[s[i]-'a'][0]]=i+1;
	for (int i=0;i<26;i++)ff+=z[i][0]&1;if (ff>=2)return puts("-1"),0;
	for (int i=1;i<=l;i++)putit(i-1,1),flag[i]=1;
	for (int i=1;i<=l;i++)if (flag[i]){
		kk=z[s[i-1]-'a'][z[s[i-1]-'a'][0]];z[s[i-1]-'a'][0]--;
		if (kk==i){
			ans+=(l-sum)/2;putit(i-1,-1);sum++;flag[i]=0;
		}else{
			ans+=findit(kk);putit(i-1,-1);putit(kk-1,-1);sum+=2;flag[i]=flag[kk]=0;
		}if (sum==l)break;
	}cout<<ans<<endl;
}


Measured memory_bytes: 59392
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    a = list(map(int, input().split()))

    # 偶数番目を正にする
    cost1 = 0
    sum_ = 0
    for i in range(n):
        sum_ += a[i]
        if i&1:#奇数番目 負
            if sum_ >= 0:
                tmp = -1 - sum_
                cost1 += abs(tmp)
                sum_ = -1
        else:# 偶数番目 正
            if sum_ <= 0:
                tmp = 1 - sum_
                cost1 += abs(tmp)
                sum_ = 1
    # 奇数番目を正にする
    cost2 = 0
    sum_ = 0
    for i in range(n):
        sum_ += a[i]
        if not i&1:#偶数番目 負
            if sum_ >= 0:
                tmp = -1 - sum_
                cost2 += abs(tmp)
                sum_ = -1
        else:# 奇数番目 正
            if sum_ <= 0:
                tmp = 1 - sum_
                cost2 += abs(tmp)
                sum_ = 1
    print(min(cost1, cost2))

if __name__ == "__main__":
    main()

Measured memory_bytes: 14340
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> tp;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
typedef pair<pii, int> piipi;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;
typedef pair<LL, pii> plpii;
typedef pair<LD, LD> pdd;
typedef pair<LD, int> pdi;
typedef pair<LD, LL> pdl;
typedef pair<int, LD> pid;
typedef pair<LL, LD> pld;
const int mod = 1e9 + 7;
const int hf = 999983;
const int N = 1e6;
LL dp[1<<16], cost[1<<16];
int a[16][16];
int main(){
    int n;
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            scanf("%d", &a[i][j]);
        }
    }
    for(int i=1;i<(1<<n);i++){
        for(int j=0;j<n;j++){
            if((i>>j)&1){
                for(int k=j+1;k<n;k++){
                    if((i>>k)&1){
                        cost[i] += a[j][k];
                    }
                }
            }
        }
    }
    for(int i=1;i<(1<<n);i++){
        for(int j=i;j>0;j=(j-1)&i){
            dp[i] = max(dp[i], dp[i^j] + cost[j]);
        }
    }
    printf("%lld\n", dp[(1<<n)-1]);
}

Measured memory_bytes: 1280
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

right = [0] * N
left = [0] * N

inverse = 0
for i in range(N):
    for j in range(N):
        if (i < j) and (A[i] > A[j]):
            right[i] += 1


A_rev = A[::-1]
inverse_rev = 0
for i in range(N):
    for j in range(N):
        if (i < j) and (A_rev[i] > A_rev[j]):
            left[i] += 1

ans = 0
for i in range(N):
    ans += K * (1 + K) // 2 * right[i] % MOD
    ans += (K - 1) * K // 2 * left[i] % MOD
    ans %= MOD

print(ans)


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

#define Pair make_pair
#define Push push_back
typedef long long lli;
typedef pair<lli,lli> pll;
typedef vector<lli> vcL;
typedef vector<pll> vPL;


bool cmp(pll x, pll y) {
	if ( x.second != y.second ) return x.second < y.second;
	else return x.first < y.first;
}

void solve() {
	lli n, m;
	cin >> n >> m;

	vPL num( m, Pair( 0, 0 ) );

	for (int i = 0; i < m; ++i) {
		cin >> num[i].first >> num[i].second;
	}
	
	sort( num.begin(), num.end(), cmp );
	
	lli last_end = 0, cnt = 0;
	
	for (int i = 0; i < m; ++i) {
		if ( num[i].first >= last_end ) {
			cnt++ ;
			last_end = num[i].second;
		}
	}
	
	cout << cnt << '\n';
}

int main() {
	int t = 1;
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve();
	}
	return 0;
}



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

using namespace std;

int main()
{
    string s,t;
    int counter=0;
    cin>>s>>t;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
            counter++;
    }
    cout<<counter<<endl;

    return 0;
}


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

#define ll long long int
#define T int t; scanf("%d",&t); while(t--)
#define N 1000005
#define pb push_back
#define sc(n) int n;scanf("%d",&n)

int main()
{
    sc(n);
    sc(m);
//    set<int> s,pen;
//    set<int> :: iterator it;
//    int ans=0;
//    while(m--)
//    {
//        char a[3];
//        int x;
//        scanf("%d %s", &x, a);
//        if(a[0]=='A' && x>0 && x<=n)
//            s.insert(x);
//        else
//        {
//            it=s.find(x);
//            if(it==s.end())
//                pen.insert(x);
//        }
//    }
//    for(it=pen.begin(); it!=pen.end();it++)
//    {
//        if(s.find(*it)!=s.end())
//            ans++;
//    }
//    printf("%d %d",s.size(),ans);

    int  ac[n+1]={}, wa[n+1]={}, ans=0, pen=0;
    while(m--)
    {
        int x;
        char a[3];
        scanf("%d %s", &x, a);
        if(a[0]=='A')
        {
            if(ac[x]==0)
            {
                ac[x]=1;
                pen+=wa[x];
            }
        }
        else
        {
            if(ac[x]==0)
                wa[x]++;
        }
    }
    for(int i=0;i<=n;i++)
        if(ac[i]==1) ans++;

    printf("%d %d", ans, pen);
}


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

int main(){
	int N,sum;
	cin>>N;
	sum=0;
	for (int i=0;i<N;i++){
			int l,r;
			cin>>l>>r;
			sum+=r-l+1;
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vi2;
const int INF = 1 << 30;

int solve();

int main(void) {


	while (solve()){}

	return 0;

}

int solve() {

	int n, m, s, g1, g2;

	cin >> n >> m >> s >> g1 >> g2;
	if (!(n | m | s | g1 | g2)){ return 0; }

	s--;
	g1--;
	g2--;

	//Adjacency matrix
	vi2 v(n, vi(n, -1));

	//distance
	vi2 d(n, vi(n, INF));

	//input
	for (int i = 0; i < m; i++) {

		int b1, b2, c;

		cin >> b1 >> b2 >> c;
		v[b1 - 1][b2 - 1] = c;

	}

	//Floyd???Warshall algorithm
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (v[i][j] > 0) {
				d[i][j] = v[i][j];
			}
			if (i == j) {
				d[i][j] = 0;
			}
		}
	}

	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if ( d[i][k] < INF && d[k][j] < INF )
					d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}

	//s->i,i->g1,i->g2
	int ans = INF;
	for (int i = 0; i < n; i++) {
		if (d[s][i] == INF || d[i][g1] == INF || d[i][g2] == INF) 
		{
			continue;
		}
		ans = min(d[s][i] + d[i][g1] + d[i][g2], ans);
	}

	cout << ans << endl;

	return 1;
	
}

Measured memory_bytes: 3180