akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")

using namespace std;

typedef long long ll;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int M = 998244353;

inline int add(int a, int b) {
    int res = a + b;
    if (res < 0) res += M;
    if (res >= M) res -= M;
    return res;
}

inline int mul(int a, int b) {
    return (a * (ll) b) % M;
}

inline int bin(int a, int n) {
    int res = 1;
    while (n) {
        if (n % 2 == 0) {
            a = mul(a, a);
            n /= 2;
        } else {
            res = mul(res, a);
            n--;
        }
    }
    return res;
}

inline int inv(int x) {
    return bin(x, M - 2);
}

inline int dv(int a, int b) {
    return mul(a, inv(b));
}

int main()
{
#ifdef iq
    freopen("a.in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int sum = 0;
    for (auto c : s) sum += c - '0';
    vector <vector <int> > g(n);
    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int ans = 1e9;
    for (int i = 0; i < n; i++) {
        vector <int> sz(n);
        vector <int> d(n);
        vector <int> f(n);
        function<void(int,int)> dfs = [&] (int v, int pr) {
            sz[v] = s[v] - '0';
            d[v] = 0;
            vector<pair<int, int> > ss;
            for (int i : g[v])
                if (i != pr) {
                    dfs(i, v);
                    sz[v] += sz[i];
                    d[v] += d[i] + sz[i];
                    ss.push_back({d[i] + sz[i], i});
                }
            if (ss.empty()) {
                f[v] = 0;
            } else {
                sort(ss.rbegin(), ss.rend());
                f[v] = 1e9;
                for (auto i : ss) {
                    f[v] = min(f[v], f[i.second] + sz[i.second] - (d[v] - i.first));
                    break;
                }
                f[v] = max(0, f[v]);
            }
        };
        dfs(i, -1);
        if (f[i] == 0 && d[i] % 2 == 0) ans = min(ans, d[i] / 2);

    }
    if (ans == (int) (1e9)) {
        cout << -1 << '\n';
    } else {
        cout << ans << '\n';
    }
}


Measured memory_bytes: 640
arr = gets.split('').map(&:to_i)

n = arr.shift
count = 1
ans = 'No'
arr.each do |e|
  if n == e
    count += 1
    if count >= 3
      ans = 'Yes'
      break
    end
  else
    count = 1
    n = e
  end
end

puts  ans


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int MOD = 1000000007;

int main(){
    ll n,k;
    cin >> n >> k;
    ll ans;
    if(k%2==1){
        ll x = n/k;
        ans = x*x*x;
    }else{
        ll x = 2*n/k;
        ll a = x/2;
        ll b = x-a;
        ans = a*a*a + b*b*b;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
main()
{
	int n = 0;
	int i = 0;
	scanf("%d", &n);
	
	int a[n];
	for(i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	
	for(i = n - 1; i >= 0; i--)
	{
		if(i == 0)
		{
			printf("%d\n", a[i]);
		}
		else 
		{
			printf("%d ", a[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
using namespace std;
int main()
{
  string str;
  cin >> str;
  int leng = str.size();
  if (leng % 2 != 0) {
    cout << "No";
    return 0;
  }
  for (int i = 0; i < leng; i++) {
    if (i % 2 == 0) {
      if (str[i] != 'h') {
        cout << "No";
        return 0;
      }
    } else {
      if (str[i] != 'i') {
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define pb push_back
#define si second
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  mod 1000000007
#define double long double
#define all(o) o.begin(),o.end()
using namespace std;
int power(int x, int y)
{
    int res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1; // y = y/2
        x = (x*x) % mod;
    }
    return res%mod;
}
int inv(int n)
{
    return power(n,mod-2)%mod;
}

int32_t main(){
	fast
	string s;
	cin>>s;
	int n=s.length();
	int ans=0;
	int i=0;
	while(i<n )
	{
		char ch=s[i];
		int c=0;
		while(i<n && ch==s[i])
			i++,c++;
		if(ch=='R')
		ans=max(ans,c);
	}
	cout<<ans<<"\n";
}




Measured memory_bytes: 3648
n=int(input())
a=[int(i) for i in input().split()]
MOD = int(1e9+7)
ans=0
for k in range(60):
  x=0
  t=1<<k
  for i in range(n):
    if a[i]&t:
      x+=1
  c=x*(n-x)*2**k
  ans+=c
print(ans%MOD)



Measured memory_bytes: 122808
#include <stdio.h>

int main(void)
{
    int n, a, b;
    scanf("%d%d%d", &n, &a, &b);

    int i;
    long c = 0;
    for (i = 1; i <= n; i++) {
        int sum = (i / 10000) + (i % 10000 / 1000) + (i % 1000 / 100) + (i % 100 / 10) + (i % 10);
        if ((a <= sum) && (sum <= b)) {
            c += i;
        }
    }
    printf("%ld\n", c);
    return 0;
}

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

int main(){
	string s;
	while(cin>>s){
		int a[10][10];
		for(int i=0;i<10;i++){
			a[0][i]=s[i]-'0';
		}
		for(int i=1;i<10;i++){
			for(int j=0;j<10-i;j++){
				a[i][j] = (a[i-1][j]+a[i-1][j+1])%10;
			}
		}
		cout<<a[9][0]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1180
s = input()

flg = 0
for i, c in enumerate(s):
  if i%2!=0:
    if c in ["L", "U", "D"]:
      continue
    else:
      flg = 1
      break
  else:
    if c in ["R", "U", "D"]:
      continue
    else:
      flg = 1
      break

ans = "Yes" if not flg else "No"
print(ans)

Measured memory_bytes: 3060
Module module1
  Sub main()
    Dim N as integer = Console.ReadLine()
    Dim L() = split(Console.ReadLine())
    
    Dim i, j, k
    
    Dim ans as Integer = 0
    
    for i = 0 To N - 3
    for j = i + 1 To N - 2
    for k = j + 1 To N - 1
    
    if Cint(L(i)) = Cint(L(j)) Or Cint(L(j)) = Cint(L(k)) Or Cint(L(k)) = Cint(L(i)) then
    else
      if Cint(L(i)) + Cint(L(j)) > Cint(L(k)) And Cint(L(j)) + Cint(L(k)) > Cint(L(i)) And Cint(L(k)) + Cint(L(i)) > Cint(L(j)) then
        ans = ans + 1
      end if
    end if
  next
next
next
Console.Write(ans)
end sub
end module

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int A,B,X; cin >> A >> B >> X;
    cout << (A <= X && X <= A+B ? "YES" : "NO") << endl;
    return 0;
}

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();
		String S = sc.next();
		int sum = 0;
		int max = 0;

		char [] strS = S.toCharArray();

		for (int i = 0; i < N; i++) {
			if (strS[i] == 'I') {
				sum += 1;
				if (sum > max) {
					max = sum;
				}
			} else if (strS[i] == 'D') {
				sum -= 1;
				if (sum > max) {
					max = sum;
				}
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 21840
#include<stdio.h>
#include<string.h>
int main()
{
	int i,n,c,t;
	char b[10010]={};
	while(~scanf("%d",&n)){
		getchar();
		gets(b);
		c=strlen(b);
		for(i=0;i<c;i++){
			if(b[i]+n>90){
				t=90-b[i];
				b[i]=64+n-t;
			}else{
				b[i]+=n;
			}
			printf("%c",b[i]);
		}printf("\n");
	}
//	for(i='A';i<='Z';i++){
//		printf("%d %c\n",i,i);
//	}
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#define int long long
using namespace std;
long long T, N, a, b, c, d, e, f;
int money[200100];
int seq[200100];
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a>> N;
	int i;
	for (i = 0; i < a; i++)
		cin >> money[i + 1];
	int now = 1;
	int p = 0;
	while (money[now]<=a)
	{
		seq[p] = now;
		p++;
		int nex = money[now];
		money[now] = a+p;
		now = nex;
		if (p == N)
		{
			cout << now;
			return 0;
		}
	}
	long long star = money[now] - a-1;
	long long en = p;
	N -= star;
	N %= (en - star);
	cout << seq[N+star];
}

Measured memory_bytes: 6360
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<string>
using namespace std;

int main() {

	int a, b;
	int gcd;
	int i;
	while (cin >> a >> b) {
		gcd = 1;
		i = 2;
		while (i <= a && i <= b) {
			if (a % i == 0 && b % i == 0) {
				gcd *= i;
				a /= i;
				b /= i;

			}
			else i++;
		}
		printf("%d\n", gcd);


	}
	//system("pause");
	return 0;
}


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

using namespace std;
const int maxn = 150;
int n, k;
int arr[maxn];
int dp[100005];
const int MOD = 1e9 + 7;
/// dp[i][j] - how many ways to get to j candies
int pref[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    for(int i = 0; i < n; i ++){
        cin >> arr[i];
    }
    memset(dp, 0, sizeof dp);
    dp[0] = 1;
    for(int at = 0; at < n; at ++){
        memset(pref, 0, sizeof pref);
        for(int rem = k; rem >= 0; rem --){
            int L = rem + 1;
            int R = rem + min(arr[at], k - rem);
            if(L <= R){
                pref[L] += dp[rem];
                pref[L] %= MOD;
                pref[R + 1] -= dp[rem];
                if(pref[R + 1] < 0){
                    pref[R + 1] += MOD;
                }

            }
        }
        int sum = 0;
        for(int i = 0; i <= k; i ++){
            sum += pref[i];
            sum %= MOD;
            dp[i] += sum;
            dp[i] %= MOD;
        }

    }
    cout << dp[k] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int a[10001],ans=0,bns=0,n;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=2*n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+2*n);    
    for(int i=1;i<=2*n;i+=2){
        bns+=a[i];
    } 
    printf("%d\n",bns);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#include <unordered_map>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

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 SWAP(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void SWAP(int& a, int& b) { a ^= b; b ^= a; a ^= b; }



class D {
	int n, x, y;
	vi a;

public:
	D()
	{
		cin >> n >> x >> y;
		a.resize(n);
		
		REP(i, n)
			cin >> a[i];

		
	}


	void solve()
	{
		if (n == 1)
			cout << abs(a[0] - y) << endl;

		else
			cout << max(abs(a[n - 1] - y), abs(a[n - 1] - a[n - 2])) << endl;
	}
};


int main()
{
	D solution;
	solution.solve();

	return 0;
}

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

using namespace std;

struct UnionFind
{
    // par[i]はiの親の番号
    vector<int> par;
    // 根ノードiに含まれるノードの数
    vector<int> sizes;

    // 最初は全てが根、サイズは0
    UnionFind(int N) : par(N), sizes(N)
    {
        for (int i = 0; i < N; i++)
        {
            par[i] = i;
            sizes[i] = 0;
        }
    }

    // xが属する木の根を再帰で得る
    int find(int x)
    {
        if (par[x] == x)
            return x;
        return par[x] = find(par[x]);
    }

    // データ xが含まれる木のサイズを返す
    int size(int x)
    {
        return sizes[find(x)];
    }

    // データxとデータyが同じグループにあるか判定する
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }

    // 同じ親を持つならばマージする
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);

        if (x == y)
            return;

        if (size(x) < size(y))
        {
            par[x] = y;
            sizes[y] += sizes[x] + 1;
            sizes[x] = 0;
        }
        else
        {
            par[y] = x;
            sizes[x] += sizes[y] + 1;
            sizes[y] = 0;
        }
    }
};

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N, M;
    cin >> N >> M;
    vector<unsigned int> A(M);
    vector<unsigned int> B(M);
    vector<long long int> result(M);
    for (int i = 0; i < M; i++)
    {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }

    UnionFind UF(N);
    result[M - 1] = (long long)N * (N - 1) / 2;
    for (int i = M - 1; i > 0; i--)
    {
        long long int size_a;
        long long int size_b;
        if (!UF.same(A[i], B[i]))
        {
            size_a = UF.size(A[i]) + 1;
            size_b = UF.size(B[i]) + 1;
        }
        else
        {
            size_a = 0;
            size_b = 0;
        }

        UF.unite(A[i], B[i]);
        result[i - 1] = result[i] - size_a * size_b;
    }
    for (int i = 0; i < M; i++)
        cout << result[i] << endl;

    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
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;}

void solve(){
  int A, B, C, X; cin >> A >> B >> C >> X;
  int ans = 0;
  for(int a=0;a<=A;a++){
    for(int b=0;b<=B;b++){
      for(int c=0;c<=C;c++){
        if(500*a+100*b+50*c==X)ans++;
      }
    }
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 3624
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=500500,oo=1e9+10,mod=1e9+7;
struct L{
	int k,b,id;
}a[maxn];
struct QJ{
	int l,r;
}b[maxn];
inline bool cmpk(const L &x,const L &y){return x.k<y.k;}
inline bool cmpb(const L &x,const L &y){return x.b<y.b;}
inline bool operator<(const QJ &x,const QJ &y){return x.r!=y.r?x.r<y.r:x.l<y.l;}
int n;
long long f[maxn],s[maxn];
inline char getc()
{
	static char buf[1048576],*p1=buf,*p2=buf;
	if(p1!=p2)return *p1++;
	p2=(p1=buf)+fread(buf,1,1048576,stdin);
	if(p1!=p2)return *p1++;
	return EOF;
}
inline int rd()
{
	int ans=0,f=1;char ch=getc();
	while((ch<'0'||ch>'9')&&(ch!='-'))ch=getc();
	if(ch=='-'){f=-1;ch=getc();}
	while('0'<=ch&&ch<='9'){ans=ans*10+ch-'0';ch=getc();}
	return ans*f;
}
int main()
{
	std::ios::sync_with_stdio(false);
	n=rd();
	for(int i=1;i<=n;i++)
	{	a[i].b=rd();
		a[i].k=rd();
	}
	sort(a+1,a+n+1,cmpk);
	for(int i=1;i<=n;i++)
		a[i].id=i;
	sort(a+1,a+n+1,cmpb);
	int in=oo;
	for(int i=n;i>=1;i--)
	{	in=min(in,a[i].id);
		b[a[i].id].l=in;
	}
	int ax=0;
	for(int i=1;i<=n;i++)
	{	ax=max(ax,a[i].id);
		b[a[i].id].r=ax;
	}
	sort(b+1,b+n+1);
	/*cerr<<"b: "<<endl;
	for(int i=1;i<=n;i++)
		cerr<<b[i].l<<" "<<b[i].r<<endl;
	cerr<<endl;*/
	int p=0;
	for(int i=1;i<=n;i++)
	{	while(p<b[i].r-1)
		{	++p;
			s[p]=(s[p-1]+f[p])%mod;
		}
		(f[b[i].r]+=f[b[i].r]+s[b[i].r-1]-(b[i].l>=2?s[b[i].l-2]:0)+mod)%=mod;
		if(b[i].l==1)
			(f[b[i].r]+=1)%=mod;
	}
	cout<<f[n]<<endl;
	/*int p=1,ans=0;
	for(int i=1;i<=n;i++)
	{	while(b[p].r<b[i].l-1) 
			p++;
		f[i]=(s[i-1]-s[p-1]+mod)%mod;
		if(b[i].l==1)
			f[i]=(f[i]+1)%mod;
		s[i]=(s[i-1]+f[i])%mod;
		if(b[i].r==n)
			ans=(ans+f[i])%mod;
		//cerr<<A[i].l<<" "<<A[i].r<<endl;
	}
	cout<<ans<<endl;*/
	return 0;
}
/*
3
2 5
6 1
3 7
*/
/*
考虑污染第i条河产生的贡献，对于第j条河，如果bj<bi,kj>ki，j和i一定会在之后相交
对于所有的x，kj>kx>ki，不论bx的值，第x条河最终一定会被i或j污染
将所有直线按k值排序，找到ri表示kj>ki且bj<bi的最大的j
li表示kj<ki且bj>bi的最小的j
如果第i条河被污染区间li-ri中所有的河都会被污染并且区间外的河不会被污染
原问题化为给定n个区间，问有多少种挑选出一些区间的方案使得全集被覆盖
f[i]表示恰好覆盖1-i的方案数
将所有区间按r排序，依次更新
*/

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

int main() {
	int n, y;
	cin >> n >> y;
	y /= 1000;
	int x = y - n;
	int a, b, c;
	int t = 7 * (y - n) / 9;

	a = 4 * t - 3 * x, b = 7 * x - 9 * t, c = n - a - b;
	if (a < 0 || b < 0 || c < 0)
		a = -1, b = -1, c = -1;
	cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#include <algorithm>
#include<vector>
#include<climits>
#include<set>
#include<string>
#include<map>
#define ll long long
#define fr(j,p) for (int i=j; i<p ;i++)
#define fastScan ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define inp(x,n) fr(0,n) cin>>x[i];
#define out(x,n) fr(0,n) cout<<x[i]<<" ";
#define test int t; cin>>t; while(t--)
#define YESF if(flag==0)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define yesf if(flag==0)cout<<"Yes"<<endl; else cout<<"No"<<endl; 
const long long md=1e9+7;
using namespace std;
int main()
{
  
  int n , x, y;
  cin>>n>>x>>y;

  int dp[n][n];
  x--,y--;

  memset(dp,0,sizeof(dp));

  for(int i=0; i< n ; i++)
  {
    dp[i][i]=0;
  }

  for(int i=0; i<n-1  ; i++)
  {
    dp[i][i+1]=1;
  }

  dp[x][y] = 1; 


 

  for(int i=0; i<n ; i++){
    for(int j=i+1; j<n ; j++)
    {
      
      int temp1 = x -i ;
      int temp2 = j-y;

      if(temp1 >=0 && temp2 >=0)
      {
        dp[i][j]=1+temp1+temp2;
      }
      else if(temp1 < 0 && temp2 >=0)
      {
        dp[i][j] = min(i-x + 1 + temp2, j-i);

      }
      else if(temp1 >=0 && temp2<0)
        dp[i][j]= min(j-i, 1+ temp1 - temp2 );
      else
        dp[i][j] = min(j-i , 1 - temp1 -temp2);
      



    }
      

    }
    
  




  // for(int i=0; i<n ; i++){
  //   for(int j=0; j<n ; j++)
  //   {
  //     cout<<dp[i][j]<<" ";

  //   }
  //   cout<<endl;
  // }

  vector<int> ans(n,0);


   for(int i=0; i<n ; i++){
    for(int j=0; j<n ; j++)
    {
      ans[dp[i][j]]++;

    }

  }

  for(int i=1; i<n ; i++)
    cout<<ans[i]<<endl;




  
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main(){
// ここに処理を記述

    int N;
    cin >> N;
    float ans;

    if(N%2==1){
        ans = ( (N / 2) + 1 ) / (1.0 * N);
    }
    else{
        ans = 0.5;
    }

    cout << fixed;
    cout << setprecision(10) << ans << "\n";

return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
a_list = list(map(int, input().split()))
a_list = sorted(a_list)
 
cnt = 0
 
for i in range(N):
    if a_list[i] >= sum(a_list)/(4*M):
        cnt += 1
 
if cnt >= M:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 8968
#include<cstdio>
#include<algorithm>
#define int long long
const int N=200003;
int x[N],ans[N],g[N],n,m,k,used[N],siz;
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)scanf("%lld",x+i),g[i]=i;
	for(int i=n;i;i--)x[i]-=x[i-1];
	scanf("%lld%lld",&m,&k);
	for(int i,j=1;j<=m;j++)scanf("%lld",&i),std::swap(g[i],g[i+1]);
	for(int i=1,j,v;i<=n;i++)if(!used[i]){
	  siz=1;
	  for(j=g[i];j!=i;j=g[j])
		siz++;
	  j=i;
	  for(int id=1;id<=k%siz;id++)j=g[j];
	  ans[i]=x[j],used[j]=1;
	  for(j=g[j],v=g[i];!used[j];j=g[j],v=g[v])
		ans[v]=x[j],used[j]=1;
	}
	for(int i=1;i<=n;i++)printf("%lld\n",ans[i]+=ans[i-1]);
	return 0;
}

Measured memory_bytes: 6528
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>	
#include <time.h>
#include <vector>
#include <stdio.h>
#include <memory.h>
#include <string>
#include <string.h>
#include <map>
#include <algorithm>
#include <bitset>
#include <queue>
#include <set>
#include <time.h>
#include <assert.h>
#include <sstream>
//#include <unordered_map>
#include <bitset>
#include <utility>
#include <iomanip>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <math.h>
#include <cmath>
#include <complex>
using namespace std;
typedef long long ll;


int main() {


	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	int x = abs(a - b) - 1;
	if(x % 2 == 1)
		puts("Alice");
	else
		puts("Borys");

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
    int a,b ;
    cin >> a >> b;

    if(a == b){
        cout << "a == b"<< endl;
    } else if ( a < b){
        cout << "a < b"  << endl;
    } else {
        cout << "a > b" << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
    long long a,b,m,k=1;
    cin>>a>>b;
    m=__gcd(a,b);
    for(long long d=2;d*d<=m;d++)
    {
        if(m%d==0)
        {
            k++;
        while(m%d==0)
            m/=d;
        }

    }
    if(m!=1)
        k++;
    cout<<k;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  char ch = fgetc(stdin), ans;
  if		(ch == 'A') { ans = 'T'; }
  else if	(ch == 'C') { ans = 'G'; }
  else if	(ch == 'G') { ans = 'C'; }
  else if	(ch == 'T') { ans = 'A'; }
  printf("%c\n", ans);
  return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n, k;
	cin >> n >> k;
	vi l(n);
	rep(i, n) cin >> l[i];

	sort(all(l));
	reverse(all(l));
	int ans = 0;
	rep(i, k) ans += l[i];

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

Measured memory_bytes: 256
import heapq
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]
        self.rank = [0] * n
    
    def find(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y: return
        
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            self.rank[x] += (self.rank[x] == self.rank[y])

def kruskal(n, edge):
    ans = 0
    uf = UnionFind(n)
    while True:
        d, v, u = heapq.heappop(edge)
        
        if uf.find(v) != uf.find(u):
            uf.union(v, u)
            n -= 1
            ans += d
        if n < 2: return ans
    return ans

n = int(input())
x, y = [None]*n, [None]*n

for i in range(n):
    a, b = map(int, input().split())
    x[i] = (a, i)
    y[i] = (b, i)

x.sort(key=lambda x:x[0])
y.sort(key=lambda y:y[0])

edge = []
for i in range(n-1):
    heapq.heappush(edge, (x[i+1][0]-x[i][0], x[i][1], x[i+1][1]))
    heapq.heappush(edge, (y[i+1][0]-y[i][0], y[i][1], y[i+1][1]))

del x, y
print(kruskal(n, edge))

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

using namespace std;
int main(){
  int H,W;
  cin >> H >> W ;
  //H++; W++;
  int h,w;
  cin >> h >> w;
  
  int ans;
  ans = (H - h) * (W - w);
  
  cout << ans << endl;      
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<utility>
#include<fstream>
#include<queue>
#include <iomanip>
#include<numeric>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define rep(i, k) for (i = 0; i < k; i++) 
typedef long long ll;
typedef pair<ll, ll> l_l;
int i, j;

int main() {
	int a,b,k,z=0;
	cin >>a>>b>> k;
	int c = 0;
	for (i = a; i >0 ;i--) {
		if (a % i == 0 && b % i == 0) {
			c++;
		//	cout << i << "\n";
		}
		if (c == k) {
			z = i;
			break;
		}
	}
	cout << z;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
#include <algorithm>

int main(void){
	int x, a;
	std::cin >> x >> a;
	if(x < a){
		std::cout << 0 << std::endl;
	}
	else{
		std::cout << 10 << std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0;i<n;i++)
int main()
{
    int d;
    cin >> d;
    cout << "Christmas ";
    rep(i,25-d) cout << "Eve ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int kaga[2][10]={
	{0,1,2,3,4,5,6,7,8,9},
	{0,2,4,6,8,1,3,5,7,9}
};
int main(){
	int n,m;
	int d[10]={0};
	string str;
	int sum=0;
	int gaga[2]={0};
	int dp[10][10]={0};
	int flag=1;
	cin>>n>>str>>m;
	for(int i=0;i<m;i++)cin>>d[i];
	reverse( str.begin(), str.end() );
	for(int i=0;i<str.size();i++){
		if(str[i]!='*'){
			sum+=kaga[i%2][str[i]-'0'];
			sum%=10;
		}
		else gaga[i%2]++;
	}
	
	for(int l=0;l<2;l++){
		for(int i=0;i<gaga[l];i++){
			for(int j=0;j<m;j++){
				//kaga[l][d[j]]
				if(flag==1){
					dp[flag][kaga[l][d[j]]]++;
				}
				else{
					for(int k=0;k<10;k++){
						dp[flag][(kaga[l][d[j]]+k)%10]+=dp[flag-1][k];
					}
				}
			}
			//for(int j=0;j<10;j++)cout<<dp[flag][j]<<" ";
			//cout<<endl;
			flag++;
		}
	}
	
	cout<<dp[flag-1][(10-sum)%10]<<endl;
	
	return 0;
}


Measured memory_bytes: 1332
from heapq import heappop,heappush
def dijkstra(s):
    d = [float("inf")]*n
    used = [True]*n
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heappush(edgelist,e)
    while len(edgelist):
        short_edge = heappop(edgelist)
        if not used[short_edge[1]]:
            continue
        v = short_edge[1]
        d[v] = short_edge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heappush(edgelist,[e[0]+d[v],e[1]])
    return d

n = int(input())
edge = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = map(int,input().split())
    edge[a-1].append([c,b-1])
    edge[b-1].append([c,a-1])

q,k = map(int,input().split()) 
d = dijkstra(k-1)
for i in range(q):
    x,y = map(int,input().split())
    print(d[x-1]+d[y-1])


Measured memory_bytes: 55960
#include <iostream> 
#include <algorithm> 
#include <cstring> 
#include <cstdio>
#include <vector> 
#include <queue> 
#include <cstdlib> 
#include <iomanip>
#include <cmath> 
#include <ctime> 
#include <map> 
#include <set> 
using namespace std; 
#define lowbit(x) (x&(-x)) 
#define max(x,y) (x>y?x:y) 
#define min(x,y) (x<y?x:y) 
#define MAX 100000000000000000 
#define MOD 1000000007
#define pi acos(-1.0) 
#define ei exp(1) 
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f 
#define mem(a) (memset(a,0,sizeof(a))) 
typedef long long ll;
set<int>s,v;
int n,m,x,y;
int main()
{
    scanf("%d%d",&n,&m);
    s.insert(1);
    v.insert(n);
    while(m--)
    {
        scanf("%d%d",&x,&y);
        if(x==1) s.insert(y);
        if(y==1) s.insert(x);
        if(x==n) v.insert(y);
        if(y==n) v.insert(x);
    }
    for(set<int>::iterator it=s.begin();it!=s.end();it++)
    {
        if(v.count(*it)==1)
        {
            puts("POSSIBLE");
            return 0;
        }
    }
    puts("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 9600
// D - Blue and Red Balls

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const int MOD = 1e9 + 7;

class Comb {
private:
	int MOD;
	long long* fac;
	long long* finv;
	long long* inv;
public:
	// 事前にテーブルを作成
	Comb(int MAX, int MOD) {
		this->MOD = MOD;

		fac = new long long[MAX + 1];
		finv = new long long[MAX + 1];
		inv = new long long[MAX + 1];

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

	~Comb() {
		delete[] fac, finv, inv;
	}

	// 二項係数計算
	long long calc(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;
	}
};

int main(){
	int N, K;
	cin >> N >> K;

	Comb comb = Comb(N, MOD);

	for (int i=1; i<=K; i++) {
		// 赤の並べ方
		// (N - (K + i - 1))個を(i + 1)ヶ所に分配（0も可）
		ll red = comb.calc(N - K + 1, i);

		// 青の並べ方
		// K個をiヶ所に分配（0は不可）
		ll blue = comb.calc(K - 1, i - 1);

		cout << (red * blue) % MOD << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const double pi = 3.141592653589793;



int main(){
    ll A, B;
    cin>>A>>B;
    cout<<A*B<<endl;
    return 0;
}

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

int main(void) {
    string a;
    map<string, int> data;

    while (cin >> a)
        ++data[a];

    int max_count = 0;
    string max_str = "";
    int max_len = 0;
    string max_len_str = "";

    for (auto itr = data.begin(); itr != data.end(); ++itr) {
        const pair<string, int>& hoge = *itr;
        if (hoge.second > max_count) {
            max_count = hoge.second;
            max_str = hoge.first;
        }
        if (hoge.first.length() > max_len) {
            max_len = hoge.first.length();
            max_len_str = hoge.first;
        }
    }

    cout << max_str << " " << max_len_str << endl;

    return 0;
}



Measured memory_bytes: 3080
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <LL,LL>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,k,len=0,to[100010],num=0,sum=0,ans=0;
pii a[100010];
vector <pii> v[100010];
vector <LL> fliu,flid;
bool has[100010];

int main()
{
	cin>>n>>k;
	rep(i,n) scanf("%lld%lld",&a[i].se,&a[i].fi);
	sort(a,a+n);
	rep(i,n)
	{
		if(!has[a[i].se])
		{
			has[a[i].se]=true;
			to[a[i].se]=len++;
		}
		v[to[a[i].se]].pb({a[i].fi,i});
	}
	rep(i,len)
	{
		sort(v[i].begin(),v[i].end());
		rep(j,v[i].size())
		{
			if(v[i][j].se>=n-k&&j<v[i].size()-1) flid.pb(v[i][j].fi);
			if(v[i][j].se<n-k&&j==v[i].size()-1) fliu.pb(v[i][j].fi);
			if(v[i][j].se>=n-k&&j==v[i].size()-1) num++;
			if(v[i][j].se>=n-k) sum+=v[i][j].fi;
		}
	}
	ans=max(ans,sum+sqr(num));
	sort(fliu.begin(),fliu.end());
	sort(flid.begin(),flid.end());
	for(int i=fliu.size()-1,j=0;i>=0&&j<flid.size();i--,j++)
	{
		num++;
		sum+=fliu[i]-flid[j];
		ans=max(ans,sum+sqr(num));
	}
	cout<<ans<<endl;
	rt0;
}

Measured memory_bytes: 8828
#include <bits/stdc++.h>
using namespace std;
long long n, ans=0;
long long a[16], x[16][16], y[16][16], human[16]={0};
bool judge(void){
    int i, j;
    for(i=0;i<n;i++){
        if(human[i]==1){
            for(j=0;j<a[i];j++){
                if(y[i][j]==1 && human[x[i][j]]==0) return false; 
                else if(y[i][j]==0 && human[x[i][j]]==1) return false;
            }
        }
    }
    return true;
}
int dfs(long long cnt, long long honest){
    int i;
    if(cnt==n){
        if(judge()) ans=max(honest, ans);
        return 0;
    }
    cnt++;
    human[cnt-1]=0;
    dfs(cnt, honest);
    human[cnt-1]=1;
    dfs(cnt, honest+1);
}
int main(){
    long long i, j;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a[i];
        for(j=0;j<a[i];j++){
           cin >> x[i][j] >> y[i][j];
           x[i][j]--;
        }
    }
    dfs(0, 0);
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
def getDepth(x):
    global nodes
    p = nodes[x][0]
    c = 0
    while p != -1:
        c += 1
        p = nodes[p][0]

    return c


def getHeight(x):
    global nodes
    h1, h2 = 0, 0
    if nodes[x][1] != -1:
        h1 = getHeight(nodes[x][1])+1
    if nodes[x][2] != -1:
        h2 = getHeight(nodes[x][2])+1

    return max(h1, h2)


n = int(input())
nodes = []

for i in range(n):
    nodes.append([-1])


for i in range(n):
    a = list(map(int, input().split()))
    if a[1] != -1:
        nodes[a[1]][0] = a[0]
    if a[2] != -1:
        nodes[a[2]][0] = a[0]
    
    nodes[a[0]] += a[1:]

for i in range(n):
    par = nodes[i][0]
    sib = nodes[par][1]

    if nodes[par][1] == i:
        sib = nodes[par][2]

    if par == -1:
        sib = -1

    deg = 0
    if nodes[i][1] != -1:
        deg +=1
    if nodes[i][2] != -1:
        deg +=1

    dep = getDepth(i)
    hei = getHeight(i)

    typ = ' internal node'
    if hei == 0:
        typ = ' leaf'
    if par == -1:
        typ = ' root'

    print('node ' + str(i) + ': parent = ', end= '')
    print(str(par) + ', sibling = ', end= '')
    print(str(sib) + ', degree = ', end= '')
    print(str(deg) + ', depth = ', end= '')
    print(str(dep) + ', height = ', end = '')
    print(str(hei) + ',' + typ)



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


void solve(long long N, std::vector<long long> A, std::vector<long long> B){

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;cin >> N;
    long long A[N+1]; for(long long i = 0;i < N+1;i++) cin >> A[i];
    long long B[N+1] = {0}; for(long long i = 0;i < N;i++) cin >> B[i];

    long long ans = 0;

    for(long long i = 0;i <= N;i++){
        if(i == 0){
            if(A[0] > B[0]){
                ans += B[0];
                B[0] = 0;
            }else{
                ans += A[0];
                B[0] -= A[0];
            }
            /*
            for(long long i = 0;i < N+1;i++) cout << A[i] << " ";
            cout << endl;
            for(long long i = 0;i < N+1;i++) cout << B[i] << " ";
            cout << endl;
            */
            continue;

        }

        if(B[i - 1] > A[i]){
            ans += A[i];
            A[i] = 0;
        }else{
            ans += B[i-1];
            A[i] -= B[i - 1];
        }

        if(A[i] > B[i]){
            ans += B[i];
            B[i] = 0;
        }else{
            ans += A[i];
            B[i] -= A[i];
        }
        /*
            for(long long i = 0;i < N+1;i++) cout << A[i] << " ";
            cout << endl;
            for(long long i = 0;i < N+1;i++) cout << B[i] << " ";
            cout << endl;
            continue;
        */

    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string s;
void input(){
    fast_io();
    cin >> s;
}

int solve(){
    vector<bool> used(30,false);
    for (size_t i = 0; i < s.length(); i++) used[s[i]-'a'] = true;
    if(s.length()<26){
        string t=s;
        for (char c = 'a'; c <='z'; c++)
        {
            if(used[c-'a']) continue; 
            t += c;
            break;
        }
        cout << t << endl;
    } else {
        bool ch = false;
        for (int i = 0; i < s.length()-1; i++)
        {
            if(s[i]<s[i+1]) {
                ch = true;
                break;
                }
        }
        if(!ch) {cout << -1 << endl; return 0;}
        
        string t = s;
        next_permutation(s.begin(),s.end());
        for (int i = 0; i < s.length(); i++)
        {
            if(t[i]==s[i]) continue;
            s = s.substr(0,i+1);
            break;
        }
        
        cout << s << endl;
    }
    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env php
<?php
function solve(int $a, int $b)
{
    if ($a == $b) {
        echo $a * 2;
    } elseif ($a > $b) {
        echo $a * 2 - 1;
    } else {
        echo $b * 2 - 1;
    }
    echo PHP_EOL;
}

fscanf(STDIN, '%d %d', $a, $b);
solve($a, $b);



Measured memory_bytes: 4732
#include<bits/stdc++.h>
using namespace std;
const int N=620;
int n,D1,D2;
int t1[N][N],t2[N][N];
void Solve(int D,int t[N][N])
{
	int i,j,k,K,len,x,y;
	K=0;
	while(D%2==0) K++,D>>=1;
	if(K&1)
	{
		len=1<<((K+1)>>1);
		for(i=0;i<2*n;i+=len)
		{
			for(j=0;j<(len>>1)&&i+j<2*n;j++)
			{
				for(k=0;k<n*2;k++)
				{
					t[i+j][k]=1;
				}
			}
		}
	}
	else
	{
		len=(1<<((K+2)>>1));
		for(i=0;i<2*n;i++)
		{
			for(j=0;j<2*n;j++)
			{
				x=((i%len)>=(len>>1));y=((j%len)>=(len>>1));
				if((x+y)&1) t[i][j]=1;
			}
		}
	}
}
int main()
{
	int a,b,i,j,num;
	scanf("%d%d%d",&n,&D1,&D2);
	Solve(D1,t1);
	Solve(D2,t2);
	/*
	for(i=0;i<2*n;i++)
	{
		for(j=0;j<2*n;j++)
		{
			printf("%d ",t2[i][j]);
		}
		putchar('\n');
	}
	return 0;
	*/
	for(a=0;a<2;a++)
	{
		for(b=0;b<2;b++)
		{
			num=0;
			for(i=0;i<2*n;i++)
			{
				for(j=0;j<2*n;j++)
				{
					if(t1[i][j]==a&&t2[i][j]==b) num++;
				}
			}
			if(num>=n*n)
			{
				num=0;
				for(i=0;i<2*n;i++)
				{
					for(j=0;j<2*n;j++)
					{
						if(t1[i][j]==a&&t2[i][j]==b) 
						{
							num++;
							if(num<=n*n) printf("%d %d\n",i,j);
						}
					}
				}
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n, m;
    cin >> n >> m;
    
    priority_queue<ll> a;
    ll in;
    FOR(i, 0, n) {
        cin >> in;
        a.push(in);
    }

    ll s;
    for (int i = 0; i < m; i++) {
        s = a.top(); a.pop();
        s /= 2;
        a.push(s);
    }

    ll ans = 0;
    while (!a.empty()) {
        ans += a.top();
        a.pop();
    }
    cout << ans << "\n";
}


Measured memory_bytes: 1400
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
const int inf = 1000000007;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % inf;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), inf - 2, inf) % inf * mod_pow(kai(y), inf - 2, inf) % inf;
}

signed main() {
	int a, b;
	cin >> a >> b;
	cout << a - b + 1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
string s;
int a[26];
int tmp[26];
string miss = "zyxwvutsrqponmlkjihgfedcba";
int main() {
  cin >> s;
  if(s.size() == 26) {
    if(s == miss) {
      cout << "-1" << endl;
      return 0;
    }
    char cur = '0';
    int j = 0;
    for(int i = s.size() - 1; i >= 0; i--) {
      if(cur < s[i]) {
	cur = s[i];
	tmp[s[i] - 'a']++;
      }
      else {
	for(int k = s[i] - 'a' + 1; k < 26; k++) {
	  if(tmp[k]) {
	    s[i] = k + 'a';
	    break;
	  }
	}
	j = i;
	break;
      }
    }
    for(int i = 0; i <= j; i++) cout << s[i];
    cout << endl;
  }
  else {
    for(int i = 0; i < s.size(); i++) {
      a[s[i] - 'a']++;
    }
    char cur;
    for(int i = 0; i < 26; i++) {
      if(!a[i]) {
	cur = i + 'a';
	break;
      }
    }
    cout << s + cur << endl;
  }
}
	
	



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f;
const int MOD = 111546435;
const int maxn = 2e5 + 10;
char S[maxn];
int cnt[2][2019];
int main()
{
    scanf("%s", S);
    int len = strlen(S);
    LL ans = 0;
    for(int i = 0, o = 0; i < len; i++, o ^= 1)
    {
        ans += cnt[o][2019 - (S[i] - '0')];
        memset(cnt[o^1], 0, sizeof(cnt[o^1]));
        for(int j = 0; j < 2019; j++)
            cnt[o^1][(j + S[i] - '0') * 10 % 2019] += cnt[o][j];
        cnt[o^1][(S[i] - '0') * 10]++;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3916
n = gets.to_i

n.times do
    x1, y1, x2, y2, x3, y3 = gets.split.map{|item| item.to_f}
    a1 = 2*(x2-x1)
    a2 = 2*(x3-x1)
    b1 = 2*(y2-y1)
    b2 = 2*(y3-y1)
    c1 = x1*x1-x2*x2+y1*y1-y2*y2
    c2 = x1*x1-x3*x3+y1*y1-y3*y3
    x = (b1*c2-b2*c1)/(a1*b2-a2*b1)
    y = (c1*a2-c2*a1)/(a1*b2-a2*b1)
    r  = Math::sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1))
    
printf("%.3f %.3f %.3f\n", x, y, r)

end

# n = gets.to_i
# for i in 1..n
# これでも可能


Measured memory_bytes: 6896
use std::io::stdin;
#[allow(dead_code)]
fn input() -> String {
    let mut s = String::new();
    stdin() .read_line(&mut s) .unwrap();
    s.trim().to_string()
}
#[allow(dead_code)]
fn get_value<T: std::str::FromStr>() -> T {
    input().parse().ok().unwrap()
}
#[allow(dead_code)]
fn get_values_for<T: std::str::FromStr>(times: u64) -> Vec<T> {
    (0..times).map(|_| get_value()).collect()
}
#[allow(dead_code)]
fn get_vector<T: std::str::FromStr>() -> Vec<T> {
    input().split_whitespace().map(|v| v.parse().ok().unwrap()).collect()
}
#[allow(dead_code)]
fn get_vectors_for<T: std::str::FromStr>(times: u64) -> Vec<Vec<T>> {
    (0..times).map(|_| get_vector()).collect()
}

fn main() {
    let input: Vec<u64> = get_vector();
    let mut tmp = input[0];
    let mut ans = 0;
    while tmp <= input[1] {
        ans += 1;
        tmp *= 2;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>

int main()
{
	int i, N;
	char a[502][502];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%s", &(a[i][1]));

	int j, sum[502] = {}, flag[502] = {}, max = 0, ans;
	for (i = 1; i <= N; i++) {
		for (j = 1; j <= N; j++) {
			if (a[i][j] != '.') {
				sum[i]++;
				flag[j] = 1;
			}
		}
	}
	for (i = 1; i <= N; i++) if (sum[i] + flag[i] > max) max = sum[i] + flag[i];
	if (max == 0) printf("-1\n");
	else {
		ans = N * 2 - max + 1;
		for (j = 1; j <= N; j++) {
			for (i = 1; i <= N; i++) if (a[i][j] != '#') break;
			if (i > N) ans--;
		}
		printf("%d\n", ans);
	}
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1980
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> a(h + 1, vector<char>(w + 1));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> a[i][j];
        }
    }
    int x = 0, y = 0;
    a[0][0] = '.';
    while (x != w - 1 || y != h - 1) {
        if (a[y][x + 1] == '#') {
            ++x;
            a[y][x] = '.';
        } else if (a[y + 1][x] == '#') {
            ++y;
            a[y][x] = '.';
        } else {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (a[i][j] == '#') {
                cout << "Impossible" << endl;
                return 0;
            }
        }
    }
    cout << "Possible" << endl;
    return 0;
}

Measured memory_bytes: 256