akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <functional>
#include <math.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ld INF = 1e18;
typedef pair< ld, int > P;
const ll mod = 1e9+7;

struct UnionFind {

  vector<int> par, height, size;

  UnionFind(int N) {
    init(N);
  }

  void init(int N) {
    par.resize(N);
    for (int i = 0; i < N; i++) par[i] = i;
    height.resize(N);
    size.resize(N, 1);
  }

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

  int getsize(int x) {
    return size[root(x)];
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (height[x] < height[y]) {
      par[x] = y;
      size[y] += size[x];
    } else {
      par[y] = x;
      size[x] += size[y];
    }
  }

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

};

vector<ll> slide_min(vector<ll>& a, int k) {
  int n = a.size();
  vector< ll > b(n-k+1);
  deque<ll> deq;
  for (int i = 0; i < n; i++) {
    while(!deq.empty() && a[i] <= a[deq.back()]) deq.pop_back();
    deq.push_back(i);
    if (i-k+1 >= 0) {
      b[i-k+1] = a[deq.front()];
      if (deq.front() == i-k+1) deq.pop_front();
    }
  }
  return b;
}

vector<ll> slide_max(vector<ll>& a, int k) {
  int n = a.size();
  vector< ll > b(n-k+1);
  deque<ll> deq;
  for (int i = 0; i < n; i++) {
    while(!deq.empty() && a[i] >= a[deq.back()]) deq.pop_back();
    deq.push_back(i);
    if (i-k+1 >= 0) {
      b[i-k+1] = a[deq.front()];
      if (deq.front() == i-k+1) deq.pop_front();
    }
  }
  return b;
}

int main() {
  int N, K; cin >> N >> K;
  vector<ll> P(N);
  for (int i = 0; i < N; i++) cin >> P[i];
  UnionFind uf1(N), uf2(N);
  for (int i = 0; i < N-1; i++) {
    if (P[i] < P[i+1]) uf1.unite(i, i+1);
  }
  vector<int> vs;
  for (int i = 0; i+K <= N; i++) {
    if (uf1.same(i, i+K-1)) vs.push_back(i);
  }
  if (vs.size() > 1) {
    for (int i = 0; i < vs.size()-1; i++) uf2.unite(vs[i], vs[i+1]);
  }
  vector<ll> m = slide_min(P, K), M = slide_max(P, K);
  for (int i = 0; i+K < N; i++) {
    if (P[i] == m[i] and P[i+K] == M[i+1]) uf2.unite(i, i+1);
  }
  unordered_set<int> s;
  for (int i = 0; i+K <= N; i++) s.emplace(uf2.root(i));
  cout << s.size() << endl;
}


Measured memory_bytes: 17864
import math
a, b, deg = map(float, raw_input().split(" "))

c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(deg)))
L = a + b + c
s = (a + b + c) / 2.0
S = math.sqrt(s*(s-a)*(s-b)*(s-c))
h = 2 * S / a

print(str(S) + " " + str(L) + " " + str(h))

Measured memory_bytes: 6788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 2000001
#define vmax 10000
constexpr int inf = 100000000;

int main(){
    unsigned short *a,*b;
    int c[vmax+1];
    int n;
    cin>>n;
    a=(unsigned short *)malloc(sizeof(short)*n+1);
    b=(unsigned short *)malloc(sizeof(short)*n+1);
    for(int i=0;i<=vmax;i++)c[i]=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        c[a[i]]++;
    }
    for(int i=1;i<=vmax;i++){
        c[i]=c[i]+c[i-1];
    }
    for(int i=1;i<=n;i++){
        b[c[a[i]]]=a[i];
        c[a[i]]--;
    }
    for(int i=1;i<=n;i++){
        if(i>1){
            cout<<" ";
        }
        cout<<b[i];
    }
    cout<<endl;
}












Measured memory_bytes: 10952
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

#define MAX 100000

int dp[MAX+2] = {0};
int done[MAX+2] = {0};

void f(int n){
	//n回で支払える金額をdpに埋める。
	if(done[n] == 1) return;

	if(n == 1){
		dp[1] = 1;
		int u = 1;
		for(u = 1; u <= MAX; ){
			u = u*6;
			if(u <= MAX){ dp[u] = 1; }
		}
		for(u = 1; u <= MAX; ){
			u = u*9;
			if(u <= MAX){ dp[u] = 1; }
		}
	}
	else if(n > 1){
		f(n - 1);
		for(int i = 1; i <= MAX; i++){
			if(dp[i] == n -1){
				if(dp[i+1] == 0){ dp[i+1] = n; }
				int u;
				for(u = 1; i + u <= MAX;){
					u = u*6;
					if(i + u <=MAX && dp[i + u] == 0){ dp[i + u] = n; }
				}
				for(u = 1; i + u <= MAX;){
					u = u*9;
					if(i + u <= MAX && dp[i + u] == 0){ dp[i + u] = n; }
				}
			}
		}
	}
	done[n] = 1;
}

int main(int argc, char* argv[]){
	int N;
	cin >> N;

	for(int i=1; ; i++){
		f(i);
		if(dp[N] != 0) break;
	}
	cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int N, M, r, q;
bool use[1261] = {false};

class Log {
private:
    int t_;
    int n_;
    int m_;
    int s_;
public:
    Log(int t, int n, int m, int s) :
        t_(t), n_(n), m_(m), s_(s) {}

    int t() {
        return t_;
    }

    int n() {
        return n_;
    }

    int m() {
        return m_;
    }

    int s() {
        return s_;
    }
};

class Question {
private:
    int ts_;
    int te_;
    int m_;
public:
    Question(int ts, int te, int m) :
        ts_(ts), te_(te), m_(m) {}
};

int solve(vector<Log>& logs, int ts, int te, int m) {
    int ans = 0;
    vector<int> login;
    vector<int> logout;

    for (int i = 0; i < 1261; ++i) {
        use[i] = false;
    }

    for (int i = 1; i < N + 1; ++i) {
        for (auto& e : logs) {
            if (e.m() == m && e.s() == 0 && e.n() == i) {
                logout.push_back(e.t());
            }
            else if (e.m() == m && e.s() == 1 && e.n() == i) {
                login.push_back(e.t());
            }
        }
    }

    const int size = login.size();

    // for (int i = 0; i < size; ++i) {
    //     cout<<login[i]<<" - "<<logout[i]<<endl;
    // }
    

    for (int i = 0; i < size; ++i) {
        for (int j = login[i]; j < logout[i]; ++j) {
            use[j] = true;
        }
    }

    for (int time = 540; time <= 1260; ++time) {
        if  (use[time] && ts <= time && time < te) {
            ans++;
            //cout<<"time : "<<time<<", ans : "<<ans<<endl;
        }
    }

    return ans;
}

int main() {
    int t, n, m, s;
    int ts, te;
    vector<Log> log;

    while(cin>>N>>M, N||M) {
        cin>>r;
        for (int i = 0; i < r; ++i) {
            cin>>t>>n>>m>>s;
            log.push_back(Log(t, n, m, s));
        }

        cin>>q;
        for (int i = 0; i < q; ++i) {
            cin>>ts>>te>>m;
            cout<<solve(log, ts, te, m)<<endl;
        }
        
        log.clear();
    }

    return 0;
}

Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi; 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int mod = 1e9+7;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
ll n,a,b,sum;
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	ll ans=0;
	cin>>n>>a>>b;
	sum=a+b;
	ans=n/sum*a;
	n%=sum;
	if(n<=a) ans+=n;
	else ans+=a;
	cout<<ans<<'\n';
    return 0;
}


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

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

using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;
constexpr int MAX = 2000200;
constexpr double EPS = 1E-11;

using namespace std;

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

	char x = s[k - 1];
	rep(i, n) {
		if (s[i] != x) {
			s[i] = '*';
		}
	}
	cout << s << endl;
}




Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


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

    long long int min;
    if ((a-b)%2 == 0){
        min = (a-b)/2;
        if (a-b < 0) min *= -1;
    }
    else{
        min = (a+b-1)/2;
        if (n+(-a-b+1)/2 < min){
            min = n+(-a-b+1)/2;
        }
    }


    printf("%lld\n", min);
    

    return 0;
} 



Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		String s = fs.next();
		System.out.println(s.replace("2017", "2018"));
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 20820
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

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

int m;

string reverse(string a) {
	string b = "";
	int n = a.length();
	for (int i = n - 1; i >= 0;i--) {
		b += a[i];
	}
	return b;
}


int main()
{
	cin >> m;
	for (int i = 0; i < m; i++) {
		string a;
		cin >> a;

		int n = a.length();

		set<string>s;

		for (int j = 1; j < n; j++) {
			string af = "";
			string ab = "";
			for (int k = 0; k < n; k++) {
				if (k < j)af += a[k];
				else ab += a[k];
			}
			string b = af + ab;
			string c = af + reverse(ab);
			string d = reverse(af) + ab;
			string e = reverse(af) + reverse(ab);
			string f = ab + af;
			string g = reverse(ab) + af;
			string h = ab + reverse(af);
			string i = reverse(ab) + reverse(af);
			s.insert(b);
			s.insert(c);
			s.insert(d);
			s.insert(e);
			s.insert(f);
			s.insert(g);
			s.insert(h);
			s.insert(i);
			
		}

		cout << s.size() << endl;
	}



	return 0;
}



Measured memory_bytes: 3244
using System;
using System.Collections.Generic;
					
public class my
{
	public static void Main()
	{
		string t;
		
		
		var cntRec = 0;
		var cntLoz = 0;
		while( null != (t= Console.ReadLine()) ) {
			var n = my.GetIntArray(',', t);
			
			if(n[0]*n[0] + n[1]*n[1] == n[2]*n[2])	cntRec++;
			if(n[0] == n[1])	cntLoz++;
		}
		
		Console.WriteLine(cntRec);
		Console.WriteLine(cntLoz);
	}
	
	private static void Swap(int[] A, int i, int j)
	{
		int tmp = A[i];
		A[i] = A[j];
		A[j] = tmp;
	}
	
	private static int GetInt()
	{
		return int.Parse(Console.ReadLine());
	}
	
	private static int[] GetIntArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
	}

	private static int[] GetIntArray(int n)
	{
		var A = new int[n];
		var s = Console.ReadLine().Split(' ');

		for(int i = 0; i < n; i++) {
			A[i] = int.Parse(s[i]);
		}
		return A;
	}
	
	private static int[] GetIntArray(int n, string t)
	{
		var A = new int[n];
		var s = t.Split(' ');

		for(int i = 0; i < n; i++) {
			A[i] = int.Parse(s[i]);
		}
		return A;
	}

	private static int[] GetIntArray(char c)
	{
		return Array.ConvertAll(Console.ReadLine().Split(c), int.Parse);
	}
	
	private static int[] GetIntArray(char c, string s)
	{
		return Array.ConvertAll(s.Split(c), int.Parse);
	}
	
	private static int[] GetIntArray(string s)
	{
		return Array.ConvertAll(s.Split(' '), int.Parse);
	}
	
	private static double[] GetDoubleArray()
	{
		return Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
	}
	
	public static string Reverse(string s)
	{
		var c = s.ToCharArray();
		Array.Reverse(c);
		
		return new String(c);
	}
	
	private static void WriteArray(int[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}

	private static void WriteArray(long[] a)
	{
		Console.WriteLine(string.Join(" ", Array.ConvertAll( a, x=>x.ToString() ) ) );
	}
	
	private static void WriteVector(Vector v)
	{
		Console.WriteLine(string.Format("{0:f8} {1:f8}", v.X, v.Y));
	}
}

public struct Vector
{
	public double X,Y;
}

Measured memory_bytes: 9164
//Have a nice day:)
#include<bits/stdc++.h>
using namespace std;
#define LL long long

inline int read();

const int maxn=600+2;
const int mod=1e9+7;
int n, k, ans;
int mn[20][maxn], mx[20][maxn], lg[maxn];
int emp[maxn], g[maxn], dp[maxn][maxn];

void Init()
{
    for(int i=2; i<=n; ++i) lg[i]=lg[i>>1]+1;

    for(int i=0; i<=10; ++i)
        for(int j=1; j<=n; ++j) mn[i][j]=1e9;
    
    for(int i=1; i<=k; ++i) 
    {
        int u=read(), v=read();
        if(u>v) swap(u, v); 
        emp[u]=-1, emp[v]=-1;
        mx[0][u]=v, mn[0][v]=u;
    }

    for(int i=1; i<=10; ++i)
        for(int j=1; j+(1<<i)-1<=n; ++j)
        {
            mx[i][j]=max(mx[i-1][j], mx[i-1][j+(1<<(i-1))]);
            mn[i][j]=min(mn[i-1][j], mn[i-1][j+(1<<(i-1))]);
        }

    for(int i=1; i<=n; ++i) emp[i]+=emp[i-1]+1;

    g[0]=1;
    for(int i=2; i<=n; i+=2) g[i]=1ll*g[i-2]*(i-1)%mod;
}

int Query_Max(int l, int r)
{
    int LG=lg[r-l+1];
    return max(mx[LG][l], mx[LG][r-(1<<LG)+1]);
}

int Query_Min(int l, int r)
{
    int LG=lg[r-l+1];
    return min(mn[LG][l], mn[LG][r-(1<<LG)+1]);
}

void Work()
{
    n=read()*2, k=read();
    Init();

    for(int i=1; i<=n; ++i)
    {
        for(int j=i+1; j<=n; ++j)
        {
            if(Query_Min(i, j)<i) break;
            if(Query_Max(i, j)>j || (i&1)==(j&1)) continue;
            dp[i][j]=g[emp[j]-emp[i-1]];
            for(int k=i+1; k<=j-1; ++k)
            {
                dp[i][j]=(dp[i][j]-1ll*dp[i][k]*g[emp[j]-emp[k]]%mod)%mod;
            }
            ans=(ans+1ll*dp[i][j]*g[emp[n]-emp[j]+emp[i-1]]%mod)%mod;
        }
    }

    printf("%d", ans);
}

int main()
{
   

    Work();

    return 0;
}

inline int read()
{
    char c; bool type=1;
    while((c=getchar())<'0' || c>'9')
        if(c=='-') type=0;
    int ans=c^48;
    while((c=getchar())>='0' && c<='9')
        ans=(ans<<3)+(ans<<1)+(c^48);
    return type?ans:-ans;
}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,k,n) for(int i = k; i < n; i++)  
#define repp(i,k,n) for(int i = k; i <= n; i++) 
#define per(i,k,n) for(int i = k; i >= n; i--)

#define int long long
#define all(a) a.begin(),a.end()       

#define pb push_back
typedef long long ll; 
typedef pair<int, int> ii;
typedef pair<int,ii > iii; 
typedef vector<ii> vii;
typedef vector<char> vchar;
typedef vector<int> vi;
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound

#define mem(a, b) memset(a, b, sizeof(a));
#define mem0(a) memset(a, 0, sizeof(a));

#define INF 1000000000
//#define mod 998244353
#define mod 1000000007
#define endl "\n"


   //=\/=\/=\/=\/=\/=\/=\/=\/=\/=\        Jai Hind Dosto        /=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\\
  //=\/=\/=\/=\                    ̿̿ ̿̿ ̿̿ ̿'̿'\̵͇̿̿\з= ( ▀ ͜͞ʖ▀) =ε/̵͇̿̿/’̿’̿ ̿ ̿̿ ̿̿ ̿̿                             /=\/=\/=\/=\\
 //=\/=\/=\/=\                                                                               /=\/=\/=\/=\\
//=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\/=\\



int modPow(int a, int b);    



                
void solve(){
    int n; cin >> n;
    
    int remain = 7%n;
    int cnt =1;
    int preremo = 0;
    rep(i,0,10000004){
        if(remain==0){
            cout << cnt;
            return;
        }
        cnt++;
        remain *=10;
        remain+=7;
        remain%=n;
    }
    cout << "-1"<<endl;
        
}






signed main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed;
    //cout <<setprecision(6);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
   // int test=1; cin >> test; while(test--)
    solve();
}

int modPow(int a, int b){
    if(b==0)return 1;
    if(b%2==0){
        int x = a*a;
        x%=mod;
        return modPow(x,b/2);
    }
    return (a*modPow(a,b-1))%mod;
}




Measured memory_bytes: 3620
from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


def main():
  N = int(input())
  G = [[] for _ in range(N)]
  dic = {}
  for i in range(N-1):
    a, b = map(lambda x: int(x)-1, input().split())
    G[a].append(b)
    G[b].append(a)
    dic[(a, b)] = i
    dic[(b, a)] = i

  color = [0]*(N-1)
  upcol = [0]*(N)
  upcol[0] = None
  visited = set()
  q = deque([0])
  max_col = 0

  while len(q):

    now = q.popleft()
    visited.add(now)
    c = 0

    for next_ in G[now]:
      if next_ not in visited:
        c += 1
        if upcol[now] is None or not(upcol[now] == c):
          color[dic[(now, next_)]] = c
          upcol[next_] = c
        else:
          c += 1
          color[dic[(now, next_)]] = c
          upcol[next_] = c
        q.append(next_)

    max_col = max(max_col, c)

  print(max_col)
  print(*color, sep='\n')


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 130620
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}




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


  ll N; cin >> N; 

  rep(h,3501)rep(n,3501){
    if(h == 0) continue;
    if(n == 0) continue;
    if(4*h*n-n*N-h*N == 0) continue; 
    ll w = (N*h*n) / (4*h*n-n*N-h*N);
    if(w < 0) continue;
    
    if(((N*h*n) % (4*h*n-n*N-h*N) == 0)){
      cout << h << " " << n << " " << (N*h*n) / (4*h*n-n*N-h*N) << endl;
      return 0;
    }
    
  }
  



  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc141/tasks/abc141_d
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll N,M; cin>>N>>M;
    // vector<ll> an(N);
    // for(auto&& a:an){
    //     cin>>a;
    // }
    priority_queue<ll> an;
    REP(i,N){
        ll a; cin>>a;
        an.push(a);
    }
    for(ll i=0;i<M;++i){
        ll tmp = an.top(); an.pop();
        tmp /= 2; 
        an.push(tmp);
    }
    ll ans= 0;
    while(!an.empty()){
        ans += an.top(); an.pop();
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;

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

template <typename T> inline string toString(const T &a){ostringstream oss; oss<<a; return oss.str();};

int main(){
    int k; cin>>k;
    if(k%2==0) cout << (k/2)*(k/2) << endl;
    else{
        int n=k/2;
        cout << n*(k-n) << endl;
    }
}

Measured memory_bytes: 256
def solve(digits, pos, x, y):
    if pos == len(digits):
        return x + y
    a = solve(digits, pos + 1, x + y, digits[pos])
    b = solve(digits, pos + 1, x, 10 * y + digits[pos])
    return a + b

digits = list(map(int, list(raw_input())))
result = solve(digits, 1, 0, digits[0])
print(result)


Measured memory_bytes: 8944
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        int N = int.Parse(Console.ReadLine());
        string[] str = Console.ReadLine().Split(' ');
        long[] A = new long[3*N];
        for(int i=0;i<3*N;i++){
            A[i] = int.Parse(str[i]);
        }
        Array.Sort(A);
        long sum = 0;
        for(int i=0;i<N;i++){
            sum += A[2*i+N];
        }
        sb.Append(sum+"\n");
    }
}

Measured memory_bytes: 39884
#include <stdio.h>

int main()
{
	int i, N, V[21], C[21];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(V[i]));
	for (i = 1; i <= N; i++) scanf("%d", &(C[i]));
	
	int sum = 0;
	for (i = 1; i <= N; i++) if (V[i] > C[i]) sum += V[i] - C[i];
	printf("%d\n", sum);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1728
use std::io::*;
use std::str::FromStr;
//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn calc(t: u64, c: u64, s: u64, f: u64) -> u64 {
    let ret;
    if t <= s {
        ret = s + c;
    } else {
        if t % f == 0 {
            ret = t + c;
        } else {
            ret = t + c + (f - t % f);
        }
    }
    ret
}

fn main() {
    let n: usize = read();
    let mut c: Vec<u64> = Vec::new();
    let mut s: Vec<u64> = Vec::new();
    let mut f: Vec<u64> = Vec::new();

    for _ in 0..n - 1 {
        c.push(read());
        s.push(read());
        f.push(read());
    }

    let mut times = vec![0; n];
    for i in 0..n - 1 {
        times[i] = s[i] + c[i];
        for j in i + 1..n - 1 {
            times[i] = calc(times[i], c[j], s[j], f[j]);
        }
    }

    for i in 0..n - 1 {
        println!("{}", times[i]);
    }
    println!("0");
}


Measured memory_bytes: 2152
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define int long long
#define str string
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define INF 1LL<<60
#define inf INF
#define out(i) cout<<i<<endl;
int min(int a,int b){if(a>b)return b;return a;}
int max(int a,int b){if(a>b)return a;return b;}

bool graphs[10][10];
int res;
void dfs(int s,int n,bool visited[]){
  bool all=true;
  rep(i,n)if(!visited[i])all=false;
  if(all)res++;
  rep(i,n){
    if(!graphs[s][i])continue;
    if(visited[i])continue;
    visited[i]=true;
    dfs(i,n,visited);
    visited[i]=false;
  }
}
signed main(){
  int n,m;
  cin>>n>>m;
  vint a(m),b(m);
  rep(i,m){
    cin>>a[i]>>b[i];
    a[i]--,b[i]--;
    graphs[a[i]][b[i]]=true;
    graphs[b[i]][a[i]]=true;
  }
  bool visited[n]={false};
  visited[0]=true;
  dfs(0,n,visited);
  out(res);

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
ll powmod(ll x,ll n){
    if(n == 0)return 1;
    if(n & 1)return x * powmod(x,n-1) % MOD;
    else    return powmod(x*x % MOD, n/2);
}
ll divmod(ll a,ll b){
    return ((a%MOD) * (powmod(b,MOD-2)%MOD)) % MOD;
}
main(){
    int N;
    cin >> N;
    N++;
    vector<int> A(N);

    set<int> st;
    int l,r;
    for(int i = 0;i < N;i++){
        cin >> A[i];
        if(!st.insert(A[i]).second)r = i;
    }
    for(int i = 0;i < N;i++)if(A[i] == A[r]){
        l = i;
        break;
    }

    vector<ll> t1(N),t2(N);
    int m =  N - (r - l + 1);
    //cout << l << " " << r << " " << m<< endl;
    t1[0] = N;
    t2[0] = 1;
    for(int i = 2;i <= N;i++){
        t1[i-1] = divmod((N-i+1) * t1[i-2],i);
    }
    for(int i = 1;i <= m;i++){
        t2[i] = divmod((m-i+1) * t2[i-1],i);
    }
    for(int i = 0;i < N;i++){
        cout << (t1[i] - t2[i] + MOD) % MOD<< endl;
    }
}

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

int main(void){
     long long int l;
     long long int r;
     long long int a, b;
     long long int n=0;
     int min=10000000;
     
     cin >> l >> r;
     if(r-l > 2020){
         
         cout << "0" << endl;
         return 0;
         
     }
     
     for(a=l; a<r; a++){
         
         for(b=l+1; b<r+1; b++){
         
         n = a * b % 2019;
         
           if(n < min){
              min = n;
           }
         
         }
        
     }
     
     cout << min << endl;
     
     return 0;
}

Measured memory_bytes: 256
/*
容易发现，若将异或值视为 n + 1 位的序列元素，
整个操作就等价于不断将 x (1 <= x <= n) 位置与 n + 1 位置的元素交换
解决方法非常神仙：
若 ai != bi，则从 ai 向 bi 连边
最终答案 = 总边数 + 连通块数 - 1
注意这里的总边数是不考虑 n + 1 的
大小为 x 连通块需要 x - 1 次，块与块之间 n + 1 位置的转换需要 1
对于第 n + 1 个位置单独考虑，若它独一个点则是要考虑到连通块里的
*/
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int N = 2e5 + 10;
typedef long long ll;
ll n, a[N], b[N], ta[N], tb[N], x, y, h[N], tot, ans, fa[N];

int getfa(int x) {
    return fa[x] == x ? x : fa[x] = getfa(fa[x]);
}

void merge(int x, int y) {
    x = getfa(x), y = getfa(y);
    if (x != y) fa[x] = y;
}

int main() {
    cin >> n;
    rep(i, 1, n) scanf("%lld", &a[i]), x ^= a[i];
    rep(i, 1, n) scanf("%lld", &b[i]), y ^= b[i];
    ++n;
    a[n] = x, b[n] = y;
    memcpy(ta, a, sizeof(a));
    memcpy(tb, b, sizeof(b));
    sort(ta + 1, ta + n + 1);
    sort(tb + 1, tb + n + 1);
    rep(i, 1, n) if (ta[i] != tb[i]) return puts("-1"), 0;

    rep(i, 1, n) {
        if (a[i] != b[i] || (i == n))
            h[++tot] = a[i], h[++tot] = b[i];
    }
    sort(h + 1, h + tot + 1);
    tot = unique(h + 1, h + tot + 1) - h - 1;
    rep(i, 1, tot) fa[i] = i;
    rep(i, 1, n) {
        if (a[i] != b[i]) {
            a[i] = lower_bound(h + 1, h + tot + 1, a[i]) - h;
            b[i] = lower_bound(h + 1, h + tot + 1, b[i]) - h;
            merge(a[i], b[i]);
            if (i < n) ++ans;
        }
    }
    rep(i, 1, tot) if (fa[i] == i) ++ans;
    --ans;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 13868
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

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

    vector<ll> A(N);
    rep (i, N) { cin >> A[i]; }

    sort(A.begin(), A.end(), greater<ll>());

    ll ans = 0;

    const auto N1 = N / 2;
    rep (i, N1) { ans += A[i]; }

    const auto N2 = (N - 1) / 2;
    rep (i, N2) { ans += A[i + 1]; }

    cout << ans << endl;

    return 0;
}


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

using namespace std;
#define int long long
#define N 666666
#define mod 1000000007
int n,k;
int arr[N];
int pre[N],sum[N];
map<int,int> vis,mp;
signed main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) scanf("%lld",&arr[i]);
	mp[arr[n]]++;
	int ans=0;
	for(int i=n-1;i>=1;i--){
		int tot=0;
		for(int j=1;j<arr[i];j++){
			tot+=mp[j]; 
		}
		pre[i]=tot;
		mp[arr[i]]++;
	}
	for(int i=1;i<=n;i++){
		int tot=0;
		for(int j=1;j<arr[i];j++){
			tot+=mp[j];
		}
		sum[i]=tot;
	}
	int temp;
	temp=(k+1)*k/2;
	temp-=k;
	temp%=1000000007;
	for(int i=1;i<=n;i++){
		int b=sum[i];
		int a=pre[i];
		ans+=(((k)*a)%mod+(b*(temp)%mod+mod)%mod)%mod;
		ans=ans%mod;
	}
	cout<<ans;
	return 0;
}

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

public class Main {

    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();
        List<Integer> list = new ArrayList<>();
        if (s.charAt(0) == '0') {
            list.add(0);
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (i == 0 || s.charAt(i) == s.charAt(i - 1)) {
                cnt++;
            } else {
                list.add(cnt);
                cnt = 1;
            }
        }
        list.add(cnt);
        if (list.size() % 2 == 0) {
            list.add(0);
        }
        int ans = 0;
        for (int i = 0; i < list.size(); i += 2) {
            int left = i;
            int right = Math.min(i + k * 2 + 1, list.size());
            int num = 0;
            for (int j = left; j < right; j++) {
                num += list.get(j);
            }
            if (ans < num) {
                ans = num;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 27504
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();
        int M = scanner.nextInt();
        scanner.nextLine();
        String S = scanner.nextLine();
        String T = scanner.nextLine();

        long lcm = lcm(N, M);
        long n = lcm / N;
        long m = lcm / M;
        char[] sArray = S.toCharArray();
        char[] tArray = T.toCharArray();
        long nm = n * m;
        for (long i = 0; i < lcm; i+=nm) {
            if (sArray[(int) (i/n)] != tArray[(int) (i/m)]) {
                System.out.println(-1);
                return;
            }
        }

        System.out.println(lcm);
    }

    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (long)(c/b);
    }


}


Measured memory_bytes: 27324
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
signed main(){
	int a,b,c;
	cin>>a>>c>>b;
	int n=a+b+c;
	vvi in(n,vi(3));
	rep(i,n)rep(j,3)cin>>in[i][j];
	sort(all(in),[](vi x,vi y){
		return x[0]-x[1]>y[0]-y[1];
	});

	
	vi d(b+1);
	priority_queue<pii>q;
	int sum=0;
	rep(i,n)sum+=in[i][2];
	rep(i,a)q.push({-in[i][0]+in[i][2],i}),sum+=in[i][0]-in[i][2];
	d[0]=sum;
	rep(i,b){
		q.push({-in[a+i][0]+in[a+i][2],i+a});
		pii t=q.top();
		q.pop();
		sum+=in[a+i][0]-in[a+i][2];
		sum+=t.first;
		d[i+1]=sum;
	}
	
	while(!q.empty())q.pop();
	sum=0;
	rep(i,c)q.push({-in[n-1-i][1]+in[n-1-i][2],n-1-i}),sum+=in[n-1-i][1]-in[n-1-i][2];
	int out=d[b]+sum;
	rep(i,b){
		q.push({-in[n-c-1-i][1]+in[n-c-1-i][2],n-c-1-i});
		pii t=q.top();
		q.pop();
		sum+=in[n-c-1-i][1]-in[n-c-1-i][2];
		sum+=t.first;
		out=max(out,d[b-1-i]+sum);
	}
	
	cout<<out<<endl;
	
}









Measured memory_bytes: 8052
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<vector<int>> next(60, vector<int>(n));
  rep(i, n){
    cin >> next[0][i];
    next[0][i]--;
  }
  for (int i = 0; i + 1 < 60; i++){
    rep(j, n){
      next[i + 1][j] = next[i][next[i][j]];
    }
  }
  int now = 0;
  rep(i, 60){
    if(k & (1ll << i)) now = next[i][now];
  }
  cout << now + 1 << endl;
}

Measured memory_bytes: 51032
use proconio::input;

fn main() {
    input! {
        s: String,
    }

    let ans = match &s.as_str() {
        &"RRR" => 3,
        &"RRS" => 2,
        &"SRR" => 2,
        &"RSS" => 1,
        &"SRS" => 1,
        &"SSR" => 1,
        &"RSR" => 1,
        _ => 0,
    };

    println!("{}", ans);
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << "\n"
#define INF 1000000000
typedef long long ll;

using namespace std;

int n, A[50];

int solve(int i, int m)
{
    if ( m==0)
        return 1;
    if (i >= n)
        return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int q, M;

    cin >> n;
    REP(i, n) { cin >> A[i]; }
    cin >> q;
    REP(i, q) 
    { 
        cin >> M;
        if (solve(0, M))
            cout << "yes\n";
        else
            cout << "no\n";
    }
}



Measured memory_bytes: 3212
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
    
int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
  int a,b,c;
  cin >> a >> b >> c;
  if (c>=a&&c<=b)
  {
    cout << "Yes" << endl;
  }else
  {
    cout << "No" << endl;
  }
  
  

  
 
//////////////////////////////////////////////////////
return 0;}

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

int sumsum(int N) {
    string stN;
    stN = to_string(N);
    int sum = 0;
    for (int i = 0; i < stN.size(); i++) {
        sum += (int)(stN.at(i) - '0');
    }
    return sum;
}

int main(){
    int N, A, B;
    cin >> N >> A >> B;

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        if (sumsum(i) >= A && sumsum(i) <= B) {
            ans += i;
        }
    }

    cout << ans << endl;
    // cout << sumsum(11) << endl;

    return 0;
}

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

int main() {
    int A,B,C,X,Y,p1,p2,p3,t;
    cin >> A >> B >> C >> X >> Y;

    p1 = A*X+B*Y;
    p2 = C*max(X,Y)*2;

    t = min(X,Y);
    p3 = C*t*2+(max(X,Y)-t)*((X>Y) ? A : B);

    cout << min(p1, min(p2, p3)) << endl;
}

Measured memory_bytes: 256
K = int(input())

ans = [i + 1 for i in range(9)]

i = 0
while len(ans) <= K:
    s = str(ans[i])
    t = int(s[-1])
    d = [-1, 0, 1]
    if t == 0:
        d = [0, 1]
    elif t == 9:
        d = [-1, 0]

    for x in d:
        ans.append(s + str(t + x))
    i += 1
print(ans[K-1])

Measured memory_bytes: 10136
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
#include <set>
#include <queue>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
#define pb(x) push_back(x)
typedef long long ll;
typedef unsigned long long ull;
const int mod=1e9+7;
const double eps=1e-6;
const int INF=0x3f3f3f3f;
const int N=100+5;
int main()
{
    int n,k;
    cin>>n>>k;
    int cnt=n,sum=0;
    vector<int> a(n);
    for(int i=0; i<n; i++)
        cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=n-1; i>=0; i--)
    {
        if(sum+a[i]<k) sum+=a[i];
        else cnt=i;
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int mod=1e9+7;

int main() {
        int a,b;
        cin>>a>>b;
  vector<int> c(999,0),d(1000,0);
  for(int i=0;i<999;i++){
          c.at(i)=i+1;
  }
  for(int i=1;i<1000;i++){
          d.at(i)=c.at(i-1)+d.at(i-1);
  }
  for(int i=2;i<1000;i++){
          if(d.at(i)-d.at(i-1)==b-a){
                  cout<<d.at(i)-b<<endl;
                  return 0;
          }
  }
}


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

const ll INF = 1e18;

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

  vector<int> aaa;
  int b = 0;
  rep(i,9){
    b += 111;
    aaa.push_back(b);
  }

  for(int i : aaa){
    if(n<=i){
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}

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

using namespace std;

int q1(int A, int B)
{
	int ret = max(A * B, max(A + B, A - B));
	return ret;
}

int main() {
	int A, B;
	cin >> A >> B;

	cout << q1(A, B) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define set0(x) memset(x,0,sizeof(x))
#define sort_uniq(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define uniq(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace __gnu_pbds;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
int isPowerof2(int x) { return (x && !(x & x-1)); }

int32_t main(){
    boost;
    int r;
    cin>>r;
    double ans=2*PI*r;
    cout<<fixed<<setprecision(10)<<ans; 
    return 0;
}

Measured memory_bytes: 3808
class UnionFind:
    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def is_connected(self, x: int, y: int) -> bool:
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x


import sys

readline = sys.stdin.buffer.readline

N, Q = map(int, readline().split())
tree = UnionFind(N)
res = []
for _ in range(Q):
    t, u, v = map(int, readline().split())
    if t:
        res.append(int(tree.is_connected(u, v)))
    else:
        tree.unite(u, v)
print("\n".join(map(str, res)))


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

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

using namespace std;

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

int main() {
  int n;
  cin >> n;
  map<string, int> s;
  rep(i, n) {
    string tmp;
    cin >> tmp;
    s[tmp] += 1;
  }
  int m;
  cin >> m;
  map<string, int> t;
  rep(i, m) {
    string tmp;
    cin >> tmp;
    t[tmp] += 1;
  }

  int result = INT_MIN;
  for (const auto &v:s) {
    int tmp = 0;
    string key = v.first;
    if ((s[key] - t[key]) > 0) {
      tmp = s[key] - t[key];
    }
    result = max(tmp, result);
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ps push_back
#define mod 1000000007
#define fi first
#define so second
#define pii pair<int,int>
#define TT int tt;cin>>tt;while(tt--)

int res(int n)
{
    int a=n;
    int b=(n*(n-1));
    int c=(b*(n-2))/6;
    return a+b+c;
}

signed main()
{
    int n,i;
    cin>>n;
    string s;
    cin>>s;
    for(i=0;i<n;i++)
    {
        if(s[i]=='R') s[i]='0';
        if(s[i]=='G') s[i]='1';
        if(s[i]=='B') s[i]='2';

    }
    int dp[n][3];
    for(i=0;i<n;i++) dp[i][0]=dp[i][1]=dp[i][2]=0;
    if(s[0]=='0') dp[0][0]=1;
    if(s[0]=='1') dp[0][1]=1;
    if(s[0]=='2') dp[0][2]=1;
    for(i=1;i<n;i++)
    {
        if(s[i]=='0') dp[i][0]=1;
        if(s[i]=='1') dp[i][1]=1;
        if(s[i]=='2') dp[i][2]=1;
        dp[i][0]+=dp[i-1][0];
        dp[i][1]+=dp[i-1][1];
        dp[i][2]+=dp[i-1][2];
    }
    int ans=0;
    for(i=0;i<n;i++) for(int j=i+2;j<n;j++)
    {
        if(s[i]==s[j]) continue;
        int mid=(i+j)/2,id=3-((s[j]-'0')+(s[i]-'0'));
        //cout<<id<<" for "<<i<<","<<j<<endl;
        ans+=dp[j-1][id]-dp[i][id];
        if((mid-i)==(j-mid) && s[mid]==char(48+id)) ans--;
    }
    cout<<ans;
}


Measured memory_bytes: 3720
#include <stdio.h>

int main()
{
  int n, x, i, j, k, count;
  while (true) {
    count = 0;
    scanf("%d %d", &n, &x);
    if (n == 0 && x == 0) break;
    if (n >= 3 && n <= 100) {
      if (x >= 0 && x <= 300) {
        for (i = 1; i <= n; i++) {
          for (j = i + 1; j <= n; j++) {
            for (k = j + 1; k <= n; k++) {
              if (i + j + k == x) count++;
            }
          }
        }
      }
      printf("%d\n", count);
    }
  }
}



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


int min(int a, int b)
{
	return (a < b ? a : b);
}
int abso(int x)
{
	return (x >= 0 ? x : -x);
}
static const int INF = 1e9;
int main()
{
	int n,K;
	cin >> n >> K;
	vector<int> h(n+1);
	vector<int> dp(n + 1);
	for (int i = 0; i < n; i++)cin >> h[i+1], dp[i]=INF;
	dp[n] = INF;
	dp[1] = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= K;j++)
			if (i + j <= n)dp[i + j] = min(dp[i + j], dp[i] + abso(h[i] - h[i + j]));
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>

using namespace std;


int main(){
  int a, b;
  cin >> a >> b;
  int s = 0;
  for(int i = 0; i < 2; ++i){
    if(a >= b){
      s += a;
      a--;
    } else {
      s+=b;
      b--;
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 256
S=int(input())
if S==1 or S==2:
  print(0)
  exit()
mod=10**9+7
mod=10**9+7
n=10**6
inv_t=[0]+[1]
for i in range(2,n):
  inv_t+=[inv_t[mod%i]*(mod-int(mod/i))%mod]

kai=[1,1]
rev_kai=[1,inv_t[1]]
for i in range(2,n):
  kai.append(kai[-1]*i%mod)
  rev_kai.append(rev_kai[-1]*inv_t[i]%mod)

def cmb(n,r):
  return kai[n]*rev_kai[r]*rev_kai[n-r]%mod

def prm(n,r):
  return kai[n]*rev_kai[n-r]%mod
a=S//3
ans=0
for i in range(1,a+1):
  d=S-3*i
  ans+=cmb(d+i-1,i-1)
  ans%=mod
print(ans)

Measured memory_bytes: 127704
using System;

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string Date = Console.ReadLine();
                string[] date = (Date.Split(' '));
                int a = int.Parse(date[0]);
                string op = date[1].ToString();
                int b = int.Parse(date[2]);
                int c = 0;

                //op????????????\?????????
                if (op == "?")
                {
                    break;
                }
                if (op == "+")              //?????????
                {
                    c = a + b;
                    Console.WriteLine(c);
                }
                else if (op == "-")
                {
                    c = a - b;
                    Console.WriteLine(c);
                }
                else if (op == "*")
                {
                    c = a * +b;
                    Console.WriteLine(c);
                }
                else if (op == "/")
                {
                    c = a / b;
                    Console.WriteLine(c);
                }
            }
        }
    }
}

Measured memory_bytes: 9096