akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
using namespace std;

long gcd(long x, long y) {
	return y ? gcd(y, x % y) : x;
}

long lcm(long x, long y) {
	return x * y / gcd(x, y);
}

int main() {
	char S[100001], T[100001];
	long N, M, tmp1, tmp2, i;
	cin >> N >> M >> S >> T;
	tmp1 = lcm(N, M);
	tmp2 = lcm(tmp1 / N, tmp1 / M);
	for (i = 0; S[i / (tmp1 / N)] != '\0' && T[i / (tmp1 / M)] != '\0'; i += tmp2) {
		if (S[i / (tmp1 / N)] != T[i / (tmp1 / M)]) {
			cout << -1;
			exit(0);
		}
	}
	cout << tmp1;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

struct Edge{
	int to, cost;
	Edge(int t, int c) : to(t), cost(c){}
};

vector<vector<Edge>> g;

vector<ll> dist;
void dfs1(int v, int p){
	for(auto nv : g[v]){
		int to = nv.to;
		int cost = nv.cost;
		if(to == p)continue;
		dfs1(to, v);
		dist[v] = max(dist[v], dist[to] + cost);
	}
}

int dfs2(int v, int p, int dist_p){
	vector<P> dist_c;
	dist_c.push_back({0, -1});
	for(auto nv : g[v]){
		int to = nv.to;
		int cost = nv.cost;
		if(to == p)dist_c.push_back({cost + dist_p, to});
		else dist_c.push_back({cost + dist[to], to});
	}

	sort(dist_c.rbegin(), dist_c.rend());
	int res = dist_c[0].first + dist_c[1].first;
	for(auto nv : g[v]){
		int to = nv.to;
		int cost = nv.cost;
		if(to == p)continue;
		int flg = dist_c[0].second == to;
		res = max(res, dfs2(to, v, dist_c[flg].first));
	}
	return res;
}

int main(){
  int n;
  cin >> n;
  g.resize(n);
  for(int i = 0; i < n - 1; ++i){
  	int a, b, w;
  	cin >> a >> b >> w;
  	g[a].push_back(Edge(b, w));
  	g[b].push_back(Edge(a, w));
  }

  dist.assign(n, 0);
  dfs1(0, -1);
  cout << dfs2(0, -1, 0) << endl;
  return 0;
}



Measured memory_bytes: 27800
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

using ll = long long;
using namespace std;
using P = pair<int,int>;
ll mod=1e9+7;

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; } //最大公倍数

int main(){
  int x,t;
  cin>>x>>t;
  if (x-t >= 0){
    cout << x-t << endl;
  }else{
    cout << 0 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import bisect
import math
def solve():
  query = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  tp ='abcdefghijklmnopqrstuvwxyz'
  n,k = (int(i) for i in input().split())
  s = input()
  a = ""
  for i in range(n):
    if i != (k-1):
     a += s[i]
    else:
     tmpo = query.find(s[i])
     a += tp[tmpo]
  print(a)
solve()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
char getGroup (int);
 
int main() {
	int x,y;
	cin >> x >> y;
	if (getGroup(x) == getGroup(y)) cout << "Yes" << endl;
	else cout << "No" << endl;
}

char getGroup(int a)
{
	if(a == 1 || a == 3 || a== 5 || a==7 || a==8 || a==10 || a==12) return 'a';
	else if (a == 4 || a==6 || a== 9 || a==11) return 'b';
	else return 'c';

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s[19];
	cin>>s;
	for(int i=0;i<19;i++)
	{
		if(i==5 || i==13){
			cout<<" ";
		}
		else{
		cout<<s[i];
		}
	}
	
}

Measured memory_bytes: 256
import Control.Applicative
import Data.Bool (bool)

main :: IO ()
main = solve <$> getLine >>= putStrLn

solve :: String -> String
solve s = bool "NO" "YES" $ s `elem` ["AKIHABARA",
                                      "KIHABARA", "AKIHBARA", "AKIHABRA", "AKIHABAR",
                                      "KIHBARA","KIHABRA","KIHABAR","AKIHBRA","AKIHBAR","AKIHABR",
                                      "KIHBRA", "KIHBAR", "KIHABR", "AKIHBR",
                                      "KIHBR"]


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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int k, x; cin >> k >> x;
    if (500 * k >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 384
x = int(input())
if x >= 400 and x <= 599: print(8)

if x >= 600 and x <= 799: print(7)

if x >= 800 and x <= 999: print(6)

if x >= 1000 and x <= 1199: print(5)

if x >= 1200 and x <= 1399: print(4)

if x >= 1400 and x <= 1599: print(3)

if x >= 1600 and x <= 1799: print(2)

if x >= 1800 and x <= 1999: print(1)

Measured memory_bytes: 9192
#include<iostream>
#include<cstdio>
#include<string>
#include<sstream>
#include<map>
#include<algorithm>
#include<functional>
using namespace std;
string str;
string maxs,mins;
int l;
map<long long int,int> v;
int main(void){
	while(1){
		long long int res;
		v.clear();
		cin >> str >> l;
		long long int sp;
		stringstream k;
		k << str;
		k >> sp;
		v[sp]=21;
		if(str=="0" && l==0)break;
		int i=1;
		while(1){
			while(str.size()<l)str+="0";
			mins=str;
			sort(mins.begin(),mins.end());
			maxs=mins;
			reverse(maxs.begin(),maxs.end());
			stringstream M;
			stringstream m;
			stringstream st;
			long long int Mn,mn;
			M << maxs;
			M >> Mn;
			m << mins;
			m >> mn;
			res=Mn-mn;
			if(v[res]>0)break;
			else v[res]=i;
			i++;
			st << res;
			st >> str;
		}
		if(v[res]==21)v[res]=0;
		cout << v[res] << " " << res << " " << i-v[res] << endl;
	}
    return 0;
}

Measured memory_bytes: 1264
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  if (n == m) cout << "Yes\n";
  else cout << "No\n";
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<unordered_set>
#include<cmath>
#include<tuple>
#include<numeric>
#include<iterator>
#include<set>
#include<unordered_map>
#include<map>
#include<queue>
#include<cstring>
#include<stdio.h>
#include<fstream>

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define foru(i , a , b) for(ll i = a ; i < b ; i++)
#define ford(i , a , b) for(ll i = a ; i >= b ; i--)
#define ain(a , n) for(ll i = 0 ; i < n ; i++) cin >> a[i]
#define aout(a , n) for(ll i = 0 ; i < n ; i++) cout << a[i] << " "
#define M 998244353
#define mp make_pair
#define mt make_tuple
#define cend cout << "\n"
#define all(x) x.begin() , x.end()
#define aout2(a , n , m) for(ll i = 0 ; i < n ; i++){for(ll j = 0 ; j < m ; j++){cout << a[i][j] << " ";} cout << endl;}
#define ain2(a , n , m) for(ll i = 0 ; i < n ; i++){for(ll j = 0 ; j < m ; j++){cin >> a[i][j];}}
#define ff first
#define ss second
#define mset(a , b) memset(a , b , sizeof(a))
#ifndef ONLINE_JUDGE
#define dbg(a) cerr << #a << ": " << a << "\n";
#else
#define dbg(a) // No more TLEs
#endif

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <char> vch;
typedef vector <string> vs;
typedef set <ll> sll;
typedef multiset <ll> msll;
typedef pair <ll , ll> pll;
typedef vector <pair <ll , ll>> vpll;

/*----------------------------- # --- MATH ALGORITHMS --- # -----------------------------*/

template <class T> T gcd(T a , T b){ while(a != 0){T temp = a; a = b % a; b = temp;}return b;}
template <class T> T egcd(T a , T b , T &x , T &y){T gcd , xt , yt;if(a == 0){gcd = b;x = 0 , y = 1;}else {gcd = egcd(b % a , a , xt , yt);x = yt - (b/a)*xt; y = xt;}return gcd;}
template <class T> T expo(T base , T exp , T mod){T res = 1;base = base % mod;while (exp > 0){if (exp & 1)res = (res*base) % mod;exp = exp>>1;base = (base*base) % mod;}return res;}
template <class T> T modinv(T a , T mod){T x , y; egcd<T>(a , mod , x , y);while(x < 0) x += mod; while(x >= mod) x -= mod; return x;}
template <class T> T modinvfermat(T a , T mod){return expo<T>(a , mod - 2 , mod);}
template <class T> bool rev(T a , T b){return a > b;}
template <class T> ll maxpower(T a , T b){ll ans = 0;while(a > 0 && a % b == 0){ans++;a /= b;}return ans;}


/*----------------------------- # --- MAIN CODE --- # -----------------------------*/
int main() {
    fastio;
#ifndef ONLINE_JUDGE
    freopen("testcase.txt", "r", stdin);
    freopen("error.txt", "w", stderr);
    freopen("output.txt", "w", stdout);
#endif
    string s; cin >> s;
    if(s == "ABC") cout << "ARC";
    else cout << "ABC";
}






















Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define fst first
#define snd second
#define pb push_back
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
using namespace std;

int n;
int k;
bool digit[15];

int main()
{
	IO
	cin>>n>>k;
	int num;
	for(int i = 0; i < k; ++i){
		cin>>num;
		digit[num] = true;
	}
	
	for(int i = n; i < 100000; ++i){
		int tmp = i;
		bool fl = true;
		while(tmp){
			if(digit[tmp%10]){
				fl = false;
				break;
			}
			tmp /= 10;
		}
		if(fl){
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
def main():
    N = input()

    hon = ['2', '4', '5', '7', '9']
    pon = ['0', '1', '6', '8']
    if N[-1] in hon:
        print('hon')
    elif N[-1] in pon:
        print('pon')
    else:
        print('bon')


if __name__ == "__main__":
    main()


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

int main(){
    int n;
    string s;
    cin>>n>>s;
    set<char>syu;
    int ans=0;
    rep(i,n){
        syu.clear();
        for(int j=0;j<=i;j++){
            for(int k=i+1;k<n;k++){
                if(s[j]==s[k])syu.insert(s[j]);
            }


        }
        int sisi=syu.size();
        ans=max(ans,sisi);
    }
    cout<<ans<<endl;


}

Measured memory_bytes: 256
'use strict'

function main(input){
  const lines = input.split('\n');
  const ABCDEF = lines.shift().split(' ').map(x => parseInt(x));
  const A = ABCDEF[0];
  const B = ABCDEF[1];

  const C = ABCDEF[2];
  const D = ABCDEF[3];

  const E = ABCDEF[4];
  const F = ABCDEF[5];

  let water = [];
  let sugers = [];
  for(var i=0;i<=F;i++){
    for(var j=0;j<=F;j++){
      let c_water = 100*(A*i+B*j);
      if(c_water<=F){ water.push(c_water); }

      let suger = C*i + D*j;
      if(suger<=F){ sugers.push(suger); }
    }
  }


//--------------
  var sugerWater = []; // とりうる砂糖水の量
  var sugerWeight = []; // とりうる砂糖の量

  // とりうる砂糖水と砂糖の量を列挙
  for(var i = 0; i <= F; i++){
    for(var j = 0; j <= F; j++){
      var sw = water[i] + sugers[j]; // 砂糖水の量
      var meltSuger = 100 * sugers[j] / water[i]; // 水に溶ける砂糖の量
      if( sw <= F && meltSuger <= E){
        sugerWater.push(sw); 
        sugerWeight.push(sugers[j]);
      }
    }
  }  
  // 各砂糖水と砂糖の量から、濃度を求める
  var noudo = 0;
  var noudoIndex = 0;
  for(var i = 0; i < sugerWater.length; i++){
    var noudoTmp = (100 * sugerWeight[i]) / sugerWater[i]; // 砂糖水の濃度
    if(noudoTmp > noudo){
      noudo = noudoTmp;
      noudoIndex = i;
    }
  }
  
  console.log(sugerWater[noudoIndex] + ' ' + sugerWeight[noudoIndex]);

return;
//--------------

  let results = [];
  for(let i=0;i<water.length;i++){
    for(let j=0;j<sugers.length;j++){      let total = water[i] + sugers[j];
      let melt_suger = 100*sugers[j]/water[i];

      if( (total <= F) && (melt_suger <= E) ){
        results.push([water[i], sugers[j]]);
      }
    }
  }

  let tmp_density = 0.0;
  let result = [];
  for(var i=0;i<results.length;i++){
      let current_density = (100*results[i][1])/(results[i][0]+results[i][1]);
      if(current_density > tmp_density){ 
        tmp_density = current_density;
        result = results[i];
      }
  }

//console.log(result);
  console.log((result[0] + result[1])+' '+result[1]);
}
main( require('fs').readFileSync( '/dev/stdin', 'utf8') );


Measured memory_bytes: 14796
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 5;
ll a[maxn] , k;
int n;
bool check (int x)
{
    int cnt = 0 , rest = k;
    for (int i = 1 ; i <= n ; i++){
        cnt = a[i] / x + (a[i] % x != 0) - 1;
        rest -= cnt;
        if (rest < 0) return false;
    }
    return true;
}
int main()
{
    ios::sync_with_stdio(false);
    cin >> n;
    cin >> k;
    for (int i = 1 ; i <= n ; i++) cin >> a[i];
    ll l = 1 , r = 1e9;
    while (l <= r){
        ll mid = l + r >> 1;
        if (check(mid)) r = mid - 1;
        else l = mid + 1;
    }
    cout << l << endl;
    return 0;
}


Measured memory_bytes: 5144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = ReadInts();
            if (s[0] <= s[1]) WriteLine(s[0]);
            else
            {
                WriteLine(s[0] - 1);
            }
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	ll A, B; cin >> A >> B;
	ll cnt = 0;
	repe(i, A, B) {
		if (i / 10000 == i % 10 && i / 10 % 10 == i / 1000 % 10) {
			cnt++;
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
ll INF = 1145141919810364;
template <typename T>
class edge
{
public:
    T cost, to, from;
    edge(T from, T to, T cost) : from(from), to(to), cost(cost) {}
};
template <typename T>
class Graph
{
public:
    vector<vector<edge<T>>> graph;

    Graph(T n, vector<T> from, vector<T> to, bool no_direction, vector<T> cost)
    {
        graph.resize(n);
        for (int i = 0; i < from.size(); i++)
        {
            edge<T> params(from[i], to[i], cost[i]);
            graph[from[i]].emplace_back(params);
            if (no_direction)
            {
                swap(params.from, params.to);
                graph[to[i]].emplace_back(params);
            }
        }
    }
    vector<ll> shortest_path;
    void Dijkstra(ll start)
    {
        shortest_path.resize(graph.size(), INF);
        shortest_path[start] = 0;
        priority_queue<P, vector<P>, greater<P>> que;
        que.emplace(0, start);
        while (!que.empty())
        {
            P p = que.top();
            que.pop();
            ll v = p.second;
            if (shortest_path[v] < p.first)
                continue;
            for (int i = 0; i < graph[v].size(); i++)
            {
                ll k = graph[v][i].to;
                ll l = graph[v][i].cost;
                if (shortest_path[k] > shortest_path[v] + l)
                {
                    shortest_path[k] = shortest_path[v] + l;
                    que.push(P(shortest_path[k], k));
                }
            }
        }
    }
    vector<vector<T>> Shortest_path;
    void Warshall_Froyd()
    {
        Shortest_path.resize(graph.size(), vector<T>(graph.size(), INF));
        for (int i = 0; i < graph.size(); i++)
        {
            for (int j = 0; j < graph[i].size(); j++)
            {
                ll To = graph[i][j].to;
                ll Cost = graph[i][j].cost;
                Shortest_path[i][To] = Cost;
            }
        }
        for (int k = 0; k < graph.size(); k++)
        {
            for (int i = 0; i < graph.size(); i++)
            {
                for (int j = 0; j < graph.size(); j++)
                {
                    Shortest_path[i][j] = min(Shortest_path[k][j] + Shortest_path[i][k], Shortest_path[i][j]);
                }
            }
        }
    }
    vector<T> dpath(T t)
    {
        vector<T> path;
        for (; t != INF; t = shortest_path[t])
            path.emplace_back(t);
        reverse(path.begin(), path.end());
        return path;
    }
};

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
vector<ll> from(n - 1), to(n - 1), cost(n - 1);
ll q,k;
for(ll i = 0; i < n - 1; i++){
    cin >> from[i] >> to[i] >> cost[i];
    from[i]--;
    to[i]--;
}
Graph<ll> g(n,from,to,true, cost);
cin >> q >> k;
g.Dijkstra(k - 1);
for(ll i = 0; i < q; i++){
    ll x,y;
    cin >> x >> y;
    x--;
    y--;
    cout << g.shortest_path[x] + g.shortest_path[y] << endl;
}
}

Measured memory_bytes: 14848
#include<iostream>
#include<vector>
using namespace std;
int cnt=0;
void input(int*,vector<int>&);
void mergeSort(vector<int>&,int,int,int);
void merge(vector<int>&,int,int,int,int);
int main(void){
    int n;
    vector<int> array;
    vector<int> &rarray = array;
    input(&n,rarray);
    mergeSort(rarray,n,0,n);
    for(int i=0;i<n;i++){
        if(i>0){
            cout << ' ';
        }
        cout << rarray[i];
    }
    cout << endl;
    cout << cnt << endl; 
    return 0;
}
void input(int *n,vector<int> &rarray){
    int k;
    cin >> *n;
    for(int i=0;i<*n;i++){
        cin >> k;
        rarray.push_back(k);
    }
}
void mergeSort(vector<int> &rarray,int n,int left,int right){
    if(left+1 < right){
        int mid = (left + right) /2;
        mergeSort(rarray,n,left,mid);
        mergeSort(rarray,n,mid,right);
        merge(rarray,n,left,mid,right);
    }
}
void merge(vector<int> &rarray,int n,int left,int mid,int right){
    int n1 = mid -left;
    int n2 = right - mid;
    int k;
    vector<int> L;
    vector<int> R;
    for(int i=0;i<n1;i++){
        k = rarray[left+i];
        L.push_back(k);
    }
     L.push_back(2000000000);
    for(int i=0;i<n2;i++){
        k = rarray[mid+i];
        R.push_back(k);
    }
    R.push_back(2000000000);
    int i =0,j=0;
    for(int k=left;k<right;k++){
        cnt++;
        if(L[i]<=R[j]){
            rarray[k]=L[i++];
        }else{
            rarray[k] = R[j++];
        }
    }
}



Measured memory_bytes: 7752
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 2e3 + 10;
int dist[MAX][MAX];
LL N, X, Y;
VI G[MAX];

void calc(int root) {
    dist[root][root] = 0;
    queue<PII> que;

    que.emplace(root, 0);
    while (!que.empty()) {
        const auto cur = que.front();
        que.pop();
        FORE(e, G[cur.first]) if (dist[root][e] == INF) {
            dist[root][e] = cur.second + 1;
            que.emplace(e, cur.second + 1);
        }
    }
}

int main(void) {
    cin >> N >> X >> Y;
    X--; Y--;

    REP(i, N - 1) {
        G[i].EB(i + 1);
        G[i + 1].EB(i);
    }
    G[X].EB(Y);
    G[Y].EB(X);

    REP(i, MAX) REP(j, MAX) {
        dist[i][j] = INF;
    }

    REP(i, N) {
        calc(i);
    }

    VI ans(N - 1);
    REP(i, N) {
        FOR(j, i + 1, N) {
            ans[dist[i][j] - 1]++;
        }
    }

    REP(i, N - 1) {
        cout << ans[i] << endl;
    }
}


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

#define pb push_back

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1e9+7;
const ll INF = 1<<30; 

int main(){
	set<ll> st;
	int n;
	cin>>n;
	bool flag = false;
	for(int i=0;i<n;i++){
		ll tmp;
		cin>>tmp;
		if(st.count(tmp))
			flag = true;
		else
			st.insert(tmp);
	}	
	(flag)?cout<<"NO\n":cout<<"YES\n";
	return 0;
}

Measured memory_bytes: 9600
let list_init n f = Array.init n f |> Array.to_list
;;

let tuple3 a b c = (a, b, c)
;;

let tuple4 a b c d = (a, b, c, d)
;;

let rec f a_list min n m list =
  if Array.length a_list == n
  then
    list
    |> List.filter_map
      (fun (a, b, c, d) -> if a_list.(b-1) - a_list.(a-1) == c then Option.some d else Option.none) 
    |> List.fold_left (+) 0
  else
    List.init (m - min + 1) ((+) min)
    |> List.map (fun min -> f (Array.append a_list [|min|]) min n m list)
    |> List.fold_left max 0
;;

let () =
  let n, m, q = Scanf.scanf "%d %d %d\n" tuple3 in
  let list = list_init q (fun _ -> Scanf.scanf "%d %d %d %d\n" tuple4) in
  let res = f [||] 1 n m list in
  Printf.printf "%d\n" res
;;

Measured memory_bytes: 5872
#include <stdio.h>

int main( ) {
  int a, b;

  scanf("%d %d", &a, &b);

  if (a == b) {
    printf("a == b\n");
  }
  else if (a > b) {
    printf("a > b\n");
  }
  else {
    printf("a < b\n");
  }

  return 0;
}

Measured memory_bytes: 580
using System;

public class hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        if (CheckP(s)) Console.WriteLine("VALID");
        else Console.WriteLine("INVALID");
    }
    public static bool CheckP (string s)
    {
        if (s.Length < 6) return false;
        var nc = 0;
        var uc = 0;
        var Lc = 0;
        for (int i = 0; i < s.Length; i++)
            if (char.IsUpper(s[i])) uc++;
            else if (char.IsLower(s[i])) Lc++;
            else nc++;
        return (nc > 0 && uc > 0 && Lc > 0);
    }
}

Measured memory_bytes: 9064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 500005

const ll INF = INT_MAX;
// const ll INF = 1234567812345678;
struct LazySegmentTree {
private:
    int nn;
    vector<ll> node, lazy;
    vector<bool> lazyFlag;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        nn = 1; while(nn < sz) nn *= 2;
        node.resize(2*nn-1);
        lazy.resize(2*nn-1, INF);
        lazyFlag.resize(2*nn-1, false);

        for(int i=0; i<sz; i++) node[i+nn-1] = v[i];
        for(int i=nn-2; i>=0; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }

    void lazyEvaluate(int k, int l, int r) {
        if(lazyFlag[k]) {
            node[k] = lazy[k];
            if(r - l > 1) {
                lazy[k*2+1] = lazy[k*2+2] = lazy[k];
                lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
            }
            lazyFlag[k] = false;
        }
    }

    void update(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = nn;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] = x;
            lazyFlag[k] = true;
            lazyEvaluate(k, l, r);
        }
        else {
            update(a, b, x, 2*k+1, l, (l+r)/2);
            update(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = min(node[2*k+1], node[2*k+2]);
        }
    }

    ll find(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = nn;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return INF;
        if(a <= l && r <= b) return node[k];
        ll vl = find(a, b, 2*k+1, l, (l+r)/2);
        ll vr = find(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    LazySegmentTree seg( vector<ll>(n, INF) );
    for(int loop=0; loop<q; loop++) {
        int query; cin >> query;
        if(query == 0) {
            int s, t, x; cin >> s >> t >> x;
            seg.update(s, t+1, x);
        }
        else {
            int s, t; cin >> s >> t;
            cout << seg.find(s, t+1) << endl;
        }
    }
    return 0;
}


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

int gcd(int a,int b){
	while(b>0){
		int t=b;
			b=a%b;
			a=t;
	}
	return a;
}

int main() 
{ 
	long long int n,sum=0;
		cin>>n;

	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++)
			for(int k=1; k<=n; k++)
				sum +=gcd(i,gcd(k,j));
	}
	cout<<sum;
	
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>  
#include<algorithm>  
#include<string>  
#include<sstream>  
#include<set>  
#include<vector>  
#include<stack>  
#include<map>  
#include<queue>  
#include<deque>  
#include<cstdlib>  
#include<cstdio>  
#include<cstring>  
#include<cmath>  
#include<ctime>  
#include<functional> 
#define INT_MAX 2147483647
#define INT_MIN -2147483648
typedef long long LL;
using namespace std;
const int maxn = 1024 + 10;
int main()
{
	//freopen("data_in.txt", "r", stdin);
	//freopen("data_out.txt", "w", stdout);
	int m = 0, n = 0;
	cin >> n >> m;
	vector<vector<LL>> vt(8, vector<LL>(n, 0));
	for (int i = 0; i < n; ++i) {
		LL a = 0, b = 0, c = 0;
		cin >> a >> b >> c;
		vt[0][i] = a + b + c;
		vt[1][i] = a + b - c;
		vt[2][i] = -a + b + c;
		vt[3][i] = a - b + c;
		vt[4][i] = -a + b - c;
		vt[5][i] = -a - b + c;
		vt[6][i] = a - b - c;
		vt[7][i] = -a - b - c;

	}
	LL res = 0;
	for (int i = 0; i < 8; ++i) {
		sort(vt[i].begin(), vt[i].end());
		int k = n - 1;
		LL t = m, r = 0;
		while (t--) {
			r += vt[i][k--];
		}
		res = max(res, r);
	}
	cout << res;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import deque

INF = float("inf")


def Topological_sorting(E):
    N = len(E)
    in_deg = [0]*N
    for i in range(N):        # ２重ループでO(E)
        for to_ in E[i]:
            in_deg[to_] += 1

    ans = [v for v in range(N) if in_deg[v] == 0]
    deq = deque(ans)

    while deq:                  # O(V+E)
        v = deq.popleft()
        for t in E[v]:
            in_deg[t] -= 1
            if in_deg[t] == 0:
                ans.append(t)
                deq.append(t)
    if len(ans) != N:
        return False
    return ans


def main():
    N = int(input())
    A = [None]*N
    for i in range(N):
        A[i] = list(map(lambda x: int(x)-1, input().split()))

    def f(i, j):
        # 0<=i<j<Nを満たすi,jの組を整数へ対応付ける
        if i > j:
            i, j = j, i
        return j-1 + (N-2)*i-i*(i-1)//2

    out = [[] for _ in range(N*(N-1)//2)]
    # 対戦カードをノードとみなし、閉路検出と最長パス探索を行う
    for i in range(N):
        for j in range(N-2):
            out[f(i, A[i][j])].append(f(i, A[i][j+1]))

    # 閉路検出
    M = (N*(N-1)//2)

    order = Topological_sorting(out)
    if order is False:
        print(-1)
        return

    # 最長パスを得る
    # パスは自分より下位の情報が必要なので、post_orderで見る
    depth = [-1]*M
    longest = -1
    for i in reversed(order):
        if depth[i] == -1:
            depth[i] = 1
        for u in out[i]:
            depth[i] = max(depth[i], 1+depth[u])
        longest = max(depth[i], longest)
    print(longest)
    # print(depth)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 139228
#include<stdio.h>
#include<stdlib.h>

int main()
{
	char str[101];
	while(scanf("%s",str)!= EOF){
		int a;
		
		if(str[0] == -1){
			break;
		}
		
		for(int i = 0; str[i] != '\0'; i++){
			if(str[i] == '@'){
				for(int j = 0; j < str[i+1]-49; j++){
					printf("%c",str[i+2]);
				}
				i+=2;
			}
			printf("%c",str[i]);
		}
		puts("");
	}
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

const int INF = 100000000;

bool isprime[1500];

vector<int> prime;

void setprime(){
	fill(isprime, isprime+1500, true);
	isprime[0] = 	isprime[1] = false;
	for(int i = 2; i < 1500; i++ ){
		if(isprime[i]){
			prime.push_back(i);
			for(int j = i*2; j < 1500; j += i){
				isprime[j] = false;
			}
		}
	}
}

int dp[15][1200] = {};
void setdp(){
	setprime();

	for(int i = 0; i < prime.size(); i++){ // i番目までの素数を使う
		for(int j = 14; j >= 1; j--){	// j個の数字を使う
			if(j == 1) dp[1][prime[i]] += 1;
			for(int k = 0; k+prime[i] < 1200; k++){
				if(!dp[j-1][k]) continue;
				dp[j][k+prime[i]] += dp[j-1][k];
			}
		}
	}
}

int main(){
	setdp();
	int n, k;
	while(cin >> n >> k, n+k){
		cout << dp[k][n] << endl;
	}

	return 0;
}

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

int array[100][100] = {0};

int main(void)
{
    int w, h, n;
    cin >> w >> h >> n;

    for(int i = 0; i < n; i++)
    {
        int x, y, a;
        cin >> x >> y >> a;

        if(a == 1)
        {
            for(int i = 0; i < x; i++)
            {
                for(int j = 0; j < h; j++)
                {
                    array[i][j] = 1;
                }
            }
        }
        else if(a == 2)
        {
            for(int i = x; i < w; i++)
            {
                for(int j = 0; j < h; j++)
                {
                    array[i][j] = 1;
                }
            }
        }
        else if(a == 3)
        {
            for(int i = 0; i < y; i++)
            {
                for(int j = 0; j < w; j++)
                {
                    array[j][i] = 1;
                }
            }
        }
        else
        {
            for(int i = y; i < h; i++)
            {
                for(int j = 0; j < w; j++)
                {
                    array[j][i] = 1;
                }
            }
        }
        
    }

    int cnt = 0;

    for(int i = 0; i < w; i++)
    {
        for(int j = 0; j < h; j++)
        {
            if(array[i][j] == 0) cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}

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

using std::min;

const int N=5e5+10;

int n,p[N],len[N];

void Init() {
	n=1;
	char ch=getchar();
	while (ch>'9' || ch<'0') ch=getchar();
	while (ch<='9' && ch>='0') {
		p[n++]=ch-'0';
		ch=getchar();
	}
}

void Solve() {
	for (int i=1;i<n;++i) p[i]=p[i]*9;
	for (int i=n-1;i>=1;--i) p[i-1]+=p[i]/10,p[i]%=10;
	int sum=0;
	for (int i=0;i<n;++i) sum+=p[i];
	for (int i=1;i<=n;++i) {
		int t=n-1; p[t]+=9; sum+=9; 
		while (p[t]>=10 && t>0) p[t-1]++,p[t]-=10,sum-=9,t--;
		if (sum<=i*9) { printf("%d\n",i); break; }
	}
}

int main() {
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int H,W;
		H = scan.nextInt();
		W = scan.nextInt();

		while(H != 0 && W != 0){
			for(int i = 0; i < H; i++){
				for(int j = 0; j < W; j++){
					if(i == 0 || j == 0 || i == H-1 || j == W-1)
						System.out.printf("#");
					else
						System.out.printf(".");
				}
				System.out.printf("\n");
			}
			System.out.printf("\n");
			H = scan.nextInt();
			W = scan.nextInt();
		}
	}
}

Measured memory_bytes: 58616
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;

int main() {
	int N, M,h=10,k=0; cin >> N >> M;
	vector<int> a(10, 0);
	vector<bool>b(10, 0);
	a[0] = 1;
	bool x = 0;
	for (int i = 0; i < M; i++) {
		int x, z; cin >> x >> z;
		if (z == 0)h = min(h,x);
		if (b[x - 1] == 1 && a[x - 1] != z) {
			cout << -1 << endl;
			return 0;
		}
		a[x - 1] = z;
		b[x - 1] = 1;
	}
	if (h==1&&N>1)cout << -1 << endl;
	else if (N == 1 && M == 0)cout << 0 << endl;
	else {
		for (int i = 0; i < N; i++)cout << a[i];
	}
	

}





Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
N,K,Q=map(int,input().split())
l=[0]*N
for _ in range(Q):
    l[int(input())-1]+=1
for i in l:
    if Q-i<K:
        print("Yes")
    else:
        print("No")



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

using namespace std;

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

#define SZ(x) ((int)x.size())

const int N = 505;
int n, a[N*N];
ii x[N];
priority_queue<int, vector<int>, greater<int> > pq;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &x[i].first), x[i].second = i;
	sort(x + 1, x + n + 1);
	x[0].first = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = x[i - 1].first + 1; j < x[i].first; ++j) pq.push(j);
		for (int j = 1; j < x[i].second; ++j) {
			if (SZ(pq)) a[pq.top()] = x[i].second, pq.pop();
			else return puts("No"), 0;
		}
		a[x[i].first] = x[i].second;
	}
	while (SZ(pq)) pq.pop();
	x[n + 1].first = n*n + 1;
	for (int i = n; i >= 1; --i) {
		for (int j = x[i + 1].first - 1; j > x[i].first; --j)
			if (!a[j]) pq.push(j);
		for (int j = 1; j <= n - x[i].second; ++j) {
			if (SZ(pq)) a[pq.top()] = x[i].second, pq.pop();
			else return puts("No"), 0;
		}
	}
	puts("Yes");
	for (int i = 1; i <= n*n; ++i) printf("%d ", a[i]);
	return 0;
}

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

using namespace std;

int dp[44][444][444];

void solve() {
    int n, A,B;
    cin >> n >> A >> B;

    memset(dp, 0x3f, sizeof dp);
    dp[0][0][0] = 0;
    int res = 0x3f3f3f3f;
    for (int i = 0; i < n; i++) {
        int x,y,z;
        cin >> x >> y >> z;
        for (int j = 0; j < 401; j++) {
            for (int k = 0; k < 401; k++) {
                dp[i+1][j][k] = dp[i][j][k];
            }
        }
        for (int j = 0; j < 401; j++) {
            for (int k = 0; k < 401; k++) {
                int& nxt = dp[i+1][j+x][k+y];
                nxt = min(nxt, dp[i][j][k]+z);
            }
        }
    }
    for (int j = 1; j < 401; j++) {
        for (int k = 1; k < 401; k++) {
            if (j*B == k*A) res = min(res, dp[n][j][k]);
        }
    }
    if (res == 0x3f3f3f3f) res = -1;
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

int main() {
  int A, B, C, D;
  // 高橋君:体力A 攻撃力B 青木君:体力C 攻撃力D 
  cin >> A >> B >> C >> D;
  
  while (A > 0) {
    C = C - B;
    if (C <= 0) {
      cout << "Yes";
      break;
    }
    else {
      A = A - D;
      if (A <= 0) {
        cout << "No";
        break;
      }
    }
  }
      
}

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        int len = S.length();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < len; i++) {
            sb.append('x');
        }
        System.out.println(sb.toString());
    }
}


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

int main() {
	int a1, a2, a3, a4, b1, b2, b3, b4, total_a, total_b;
	cin >> a1 >> a2 >> a3 >> a4 >> b1 >> b2 >> b3 >> b4;

	total_a = a1 + a2 + a3 + a4;
	total_b = b1 + b2 + b3 + b4;

	cout << (total_a > total_b ? total_a : total_b) << endl;
	return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	vector<vector<int>> x(N),y(N);
	rep(i,N){
		cin >> A[i];
		rep(j,A[i]){
			int a,b;
			cin >> a >> b;
			a--;
			b;
			x[i].push_back(a);
			y[i].push_back(b);
		}
	}
	int ans = 0;
	for(int i=0;i<(1<<N);i++){
		//i bit目が0だったら不親切 で 1だったら必ず正しい証言を行っていると仮定する
		int cnt = 0;
		vector<int> t(N,-1);
		bool f = 1;
		for(int j=0;j<N;j++){//j人目について
			if((i>>j)&1){//j人目の証言が正しいとすると
				cnt++;
				rep(k,A[j]){
					int now = x[j][k];
					int t  = y[j][k];
					if(((i>>now)&1)==t){
						continue;
					}
					else {
						f = 0;
					}
				}
			}
		}
		if(f)ans = max(ans,cnt);
	}
	cout << ans << endl;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main() {
  cin.sync_with_stdio(false);
  int a[3], k;
  cin >> a[0] >> a[1] >> a[2] >> k;
  sort(a, a + 3);
  cout << (int)(pow(2, k) * a[2]) + a[0] + a[1] << endl;
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, raw_input().split())

if n > m: 
	a = n
	n = m
	m = a

if n == 1:
	if m == 1:
		print 1
	else:
		print m - 2 
	exit(0)

black = (n - 2) * (m - 2)
print black

Measured memory_bytes: 2568
import java.util.*;
import java.math.*;

public class Main {
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int m = sc.nextInt();
			int n = sc.nextInt();
			
			if(m == 0 && n == 0) break;
			
			boolean[][] map = new boolean[n][m];
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < m; j++) {
					map[i][j] = (sc.nextInt() == 1)?true:false;
				}
			}
			
			int max = 0;
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < m; j++) {
					if(!map[i][j]) continue;
					map[i][j] = false;
					max = Math.max(dfs(new Data(map,i,j,1)),max);
					map[i][j] = true;
				}
			}
			System.out.println(max);
		}
	}
	static int[] vx = new int[] {1,0,-1,0};
	static int[] vy = new int[] {0,1,0,-1};
	static int dfs(Data a) {
		Data tmp = a;
		int max = tmp.sum;
		for(int i = 0; i < 4; i++) {
			int ty = tmp.y + vy[i];
			int tx = tmp.x + vx[i];
			if(!rcheck(ty,tx,tmp.map.length,tmp.map[0].length) || !tmp.map[ty][tx]) continue;
			tmp.map[ty][tx] = false;
			max = Math.max(dfs(new Data(tmp.map,ty,tx,tmp.sum+1)),max);
			tmp.map[ty][tx] = true;
		}
		return max;
	}
	
	
	static boolean rcheck(int y, int x, int my, int mx) {
		if(y < 0 || x < 0 || y >= my || x >= mx) return false;
		return true;
	}
	
	
	static class Data {
		boolean[][] map;
		int y;
		int x;
		int sum;
		Data(boolean[][] a, int b, int c, int d) {
			map = a;
			y = b;
			x = c;
			sum = d;
		}
	}
	
}

Measured memory_bytes: 38300
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
int main(void){
    // Your code here!
 ll i,ans,n,s;
 ans=s=0;
 cin >> n;
 ll a[n];
 for(i=0;i<n;i++)
 {
  cin >> a[i];
  s+=a[i];
 }
 for(i=0;i<n;i++)
 {
  s-=a[i];
  ans=(ans+(((s%mod)*(a[i]%mod))%mod))%mod;
 }
 cout << ans;
 return 0;
}

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

int main(void){
    int r,n,left,right,height;
    double minh;
    map<int,int> s;

    while(cin>>r>>n,r|n){
        /* ????????? */
        rep(i,21)s[i]=s[-i]=0;
        minh = 21;
        while(n--){
            cin>>left>>right>>height;
            for(int i=left;i<right;++i){
                if(s[i]<height)s[i]=height;
            }
        }

        rep(i,r)minh = min(minh,min(s[i],s[-i-1])-sqrt(r*r-i*i));
        printf("%.4f\n",minh+r);
    }

    return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int main (){
	int x,j,ans,s=9999;
	cin>>x;
	if(x==1){cout<<x;return 0;}
	for(int i=2;i*i<=x;i++){
		for(j=i;j*i<=x;j=j*i){}
		if(x-j<s) s=x-j;
	}
	ans=x-s;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
long L, R, MOD=1e9+7;
long dp[66][2][2][2];

int main() {
	scanf("%ld%ld", &L, &R);

	dp[0][0][0][0] = 1;
	bool x[3] = {1, 0, 0}, y[3] = {1, 1, 0};

	for(int i = 0; i < 60; ++i) {
		bool lb = L>>(59-i)&1, rb = R>>(59-i)&1;

		for(int l = 0; l < 2; ++l)
			for(int r = 0; r < 2; ++r)
				for(int j = 0; j < 2; ++j)

					for(int k = 0; k < 3; ++k) {
						if(!l && !x[k] && lb) continue;
						if(!r && y[k] && !rb) continue;
						if(!j && x[k] ^ y[k]) continue;
						
						int nl = (x[k] ^ lb   ? 1 : l);
						int nr = (y[k] ^ rb   ? 1 : r);
						int nj = (x[k] & y[k] ? 1 : j);

						(dp[i+1][nl][nr][nj] += dp[i][l][r][j]) %= MOD;
					}

	}
	long ans = dp[60][0][0][1] + dp[60][0][1][1] + dp[60][1][0][1] + dp[60][1][1][1];
	printf("%ld\n", ans % MOD);
    return 0;
}


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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007

#define trace1(x)                    cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;

typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,n,m;
    cin>>n;
    ll a[n+1];
    ll b[n];
    for(i=0;i<=n;i++)
    cin>>a[i];
    for(i=0;i<n;i++)
    cin>>b[i];
    ll cnt=0;
    for(i=n-1;i>=0;i--)
    {
        ll temp=min(a[i+1],b[i]);
        a[i+1]-=temp;
        b[i]-=temp;
        cnt+=temp;
        temp=min(a[i],b[i]);
        a[i]-=temp;
        b[i]-=temp;
        cnt+=temp;
    }
    cout<<cnt;
    return 0;
}

Measured memory_bytes: 1792
import sys
N = int(input())
i=0
X = [0]*N
Y = [0]*N
while i < N:
    
    X[i],Y[i] = list(map(int,input().split()))
    i = i+1
for j in range(N-2):
    if X[j]==Y[j]:
        if X[j+1]==Y[j+1]:
            if X[j+2]==Y[j+2]:
                print("Yes")
                sys.exit()
print("No")

Measured memory_bytes: 9092
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

X = n()

for x in range(1, X):
    if x * (x + 1) // 2 >= X:
        print(x)
        import sys
        sys.exit()

print(X)


Measured memory_bytes: 38512
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var seqA = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        var bucket = new long[seqA.Length + 1];
        for (int i = 0; i < seqA.Length; ++i)
        {
            ++bucket[seqA[i]];
        }

        var ps = new long[bucket.Length];
        var qs = new long[bucket.Length];
        for (int i = 1; i < bucket.Length; ++i)
        {
            ps[i] = ps[i - 1] + bucket[i] * (bucket[i] - 1) / 2;
            qs[i] = bucket[i] > 0 ? (bucket[i] - 1) * (bucket[i] - 2) / 2 : 0;
        }

        var ks = new long[seqA.Length];
        for (int i = 0; i < ks.Length; ++i)
        {
            ks[i] = ps.Last() - (ps[seqA[i]] - ps[seqA[i] - 1]) + qs[seqA[i]];
        }
        
        Console.WriteLine(string.Join(Environment.NewLine, ks));
    }
}


Measured memory_bytes: 48860
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>

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

using namespace std;

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int A, B;

int main() {
    cin >> A >> B;
    cout << 6 - A - B << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int c=0;

int* Bubble(int N, int *A){
  int flag=1, j, num;
  while(flag){
    flag=0;
    for(j=N-1 ; j>0 ; j--){
      if(A[j]<A[j-1]){
        num=A[j];
        A[j]=A[j-1];
        A[j-1]=num;
        flag=1;
        c++;
      }
    }
  }
  return A;
}

int main(void){
  int N,i;
  int *A;
  scanf("%d",&N);
  A = (int*)malloc(sizeof(int)*N);
  for(i=0 ; i<N ; i++){
    scanf("%d",&A[i]);
  }
  A=Bubble(N,A);
  printf("%d",A[0]);
  for(i=1 ; i<N ; i++){
    printf(" %d",A[i]);
  }
  printf("\n%d\n",c);
  return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
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;
}

signed main()
{
    //  以降 cin の入力元が 'input.txt' になる
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while (1)
    {
        C = C - B;
        if (C <= 0)
        {
            cout << "Yes" << endl;
            break;
        }
        A = A - D;
        if (A <= 0)
        {
            cout << "No" << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 3592