akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using i64 = long long;

template <class T = long long int>
class Bit {
    private:
    int len;
    T *arr;
    T init;

    public:
    Bit(int length, T initialValue = 0) : len(length), init(initialValue) {
        arr = new T[length + 1];
        for (int i = 0; i <= length; i++) {
            arr[i] = initialValue;
        }
    }
    ~Bit() {
        delete[] arr;
    }
    void update(int a, T newval) {
        for (int x = a; x <= len; x += x & -x) arr[x] += newval;
    }
    T query(int a) const {
        T ret = init;
        for (int x = a; x > 0; x -= x & -x) ret += arr[x];
        return ret;
    }
};

int main() {
    std::string s;
    std::cin >> s;
    int n = s.size();

    std::vector<std::deque<int>> pos(26);
    for (int i = 0; i < n; i++) {
        pos[s[i] - 'a'].push_back(i);
    }

    int odd = std::count_if(pos.begin(), pos.end(), [](auto &q) { return q.size() % 2; });
    if (odd > 1) {
        std::cout << -1 << std::endl;
        return 0;
    }

    Bit<> bit(n + 1);
    std::vector<int> done(n);
    i64 ret = 0, c = 0;
    bool center = false;
    for (int i = 0; i < n; i++) {
        if (done[i]) continue;
        int j = s[i] - 'a';
        if (pos[j].size() == 1) {
            done[i] = 1;
            center = true;
            continue;
        }
        int orig = pos[j].back();
        int p = orig - bit.query(orig), q = n - 1 - c;
        ret += abs(p - q);
        if (center) ret++;
        bit.update(orig, 1);
        done[i] = done[orig] = 1;
        pos[j].pop_front();
        pos[j].pop_back();
        c++;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int MAXN = 1 + 1e5;
const ll oo = 1  +1e18;
typedef pair < int, int > II;
typedef pair < int, II > III;



int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a == c - 1){
        cout << 1 << '\n';
    }
    else cout << 0 << '\n';
   
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int sum = 0;
        for(int i = a;i <= b;i++) {
        	String is = String.valueOf(i);

        	boolean flag = true;
        	for(int j = 0;j < is.length()/2;j++) {
        		flag = flag && is.charAt(j) == is.charAt(is.length()-j-1);
        	}

        	sum += flag ? 1 : 0;
        }

        System.out.println(sum);
    }
}


Measured memory_bytes: 30964
def insert_sort():
    n = int(input())
    A = [int(x) for x in input().split()]
    print(*A)
    for i in range(1,n):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print(*A)



if __name__ == "__main__":
    insert_sort()

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n;cin >>n;
    vector<ll>c(n-1);
    vector<ll>s(n-1);
    vector<ll>f(n-1);
    for (int i = 0; i < n - 1; ++i) {
        cin >>c[i]>>s[i]>>f[i];
    }
    ll now=0;
    for (int i = 0; i <n-1; ++i) {
        ll j=i;
        now=0;
        while(1){
            if(j==n-1)break;
            if(now<s[j]){
                now=s[j];
            }
            ll time=(now%f[j])?f[j]-now%f[j]:0;
            now+=time;
            now+=c[j];
//            cout <<j <<" "<<now<<endl;
            j++;
        }
        cout <<now<<endl;
    }
    cout <<0<<endl;
    return 0;
}

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

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main() {
    ll a,b,c;
    cin >> a >> b >> c;
    
    ll min1 = min({a,b,c});
    ll max1 = max({a,b,c});
    
    ll cen = a+b+c-min1-max1;
    
    if(max1%2==0) cout << 0 << endl;
    else cout << min1*cen << endl;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}

main :: IO ()
main = do
    s <- getLine
    print $ solve s

solve :: String -> Int
solve cs = snd $ foldl f (0, 0) cs
  where
    f (!d, !x) 'S'             = (succ d, succ x)
    f (!d, !x) 'T' | d == 0    = (     d, succ x)
                   | otherwise = (pred d, pred x)



Measured memory_bytes: 9468
// D - Wizard in Maze
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(int)(s);i<(int)(e);++i)

pair<int, int> dhw[] = { // <h, w>
        { 1, 0},
{ 0,-1},        { 0, 1},
        {-1, 0},
{ 2,-2},{ 2,-1},{ 2, 0},{ 2, 1},{ 2, 2},
{ 1,-2},{ 1,-1},        { 1, 1},{ 1, 2},
{ 0,-2},                        { 0, 2},
{-1,-2},{-1,-1},        {-1, 1},{-1, 2},
{-2,-2},{-2,-1},{-2, 0},{-2, 1},{-2, 2}
};

int main(){
	int H, W; cin>>H>>W;
	int C[2],D[2]; cin>>C[0]>>C[1]>>D[0]>>D[1];
	C[0]--, C[1]--, D[0]--, D[1]--;
	string S[H]; rp(i, 0, H) cin>>S[i];

	vector<vi> dst(H, vi(W, -1));
	deque<tuple<int, int, int>> dq; // <h, w, gid>
	dq.push_back({C[0], C[1], 0});
	while(dq.size()){
		int h, w, gid; tie(h, w, gid) = dq.front(); dq.pop_front();
		if(h < 0 || H <= h || w < 0 || W <= w
		|| dst[h][w] >= 0 || S[h][w] == '#') continue;
		dst[h][w] = gid;
		rp(i, 0, 4) dq.push_front({h + dhw[i].first, w + dhw[i].second, gid});
		rp(i, 4, 24) dq.push_back({h + dhw[i].first, w + dhw[i].second, gid+1});
	}

	cout<< dst[D[0]][D[1]] <<endl;
}


Measured memory_bytes: 11832
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
signed main(){
  cin.tie(0);
  int n,q;
  cin>>n>>q;
  vector<int> s(n);
  for(int i=0;i<n;i++) cin>>s[i];
  string query[q];
  int a[q];
  for(int i=0;i<q;i++) cin>>query[i]>>a[i];
   
  vector<int> v=s;
  sort(v.begin(),v.end());
  map<int,int> m;
  for(int i=0;i<n;i++) m[v[i]]=i;
   
  set<int> si;
  for(int i=0;i<q;i++){
    if(query[i]=="ADD"){
      si.insert(a[i]-1);
      continue;
    }
    if(query[i]=="REMOVE"){
      si.erase(a[i]-1);
      continue;
    }
    if(a[i]==n){
      cout<<0<<endl;
      continue;
    }
    vector<int> u;
    for(int j: si) u.push_back(m[s[j]]);
    sort(u.begin(),u.end());
    u.erase(unique(u.begin(),u.end()),u.end());
    int sz=u.size();
    //for(int j=0;j<sz;j++) cout<<u[j]<<"-";cout<<endl;
     
    if(!sz || u[sz-1]+1<n-a[i]){
      cout<<"NA"<<endl;
      continue;
    }
    int l=-1,r=(1e9)+7;
    while(l+1<r){
      int x=(l+r)/2;
      int tmp=-1,cnt=0;
      for(int j=0;j<sz;j++){
	int pos=lower_bound(v.begin(),v.end(),v[u[j]]-x)-v.begin();
	if(pos<tmp) pos=tmp;
	cnt+=u[j]+1-pos;
	tmp=u[j]+1;
      }
      //cout<<x<<":"<<cnt<<"-"<<n-a[i]<<endl;
      if(cnt<n-a[i]) l=x;
      else r=x;
    }
    cout<<r<<endl;
  }
  return 0;
}

Measured memory_bytes: 57432
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double[] a = new double[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextDouble();
		}

		double tmp = 0;
		for (int i = 0; i < N; i++) {
			tmp += 1 / a[i];
		}

		double ans = 1 / tmp;

		System.out.printf("%.6f", ans);
	}
}

Measured memory_bytes: 23252
#include<cstdio>
#include<algorithm>
using namespace std;
int a[5],ans;
int main()
{
	for(int i=1;i<=3;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+3+1);
	ans+=(a[2]-a[1])/2;
	a[1]=a[2]-(a[1]%2+a[2]%2)%2;
	ans+=(a[3]-a[2]);
	a[1]=(a[3]-a[2]+a[1]);
	a[2]=a[3];
	ans+=(a[1]+a[2]+a[3])%3;
	printf("%d\n",ans);
}


Measured memory_bytes: 128
# frozen_string_literal: true

def lunlunNumber(n)
  lunlun = [1, 2, 3, 4, 5, 6, 7, 8, 9]
  return n if n <= 12

  i = 0
  while lunlun.length < n
    a = lunlun[i].to_s.chars[-1].to_i
    lunlun.push(lunlun[i] * 10 + a - 1) if a > 0
    lunlun.push(lunlun[i] * 10 + a)
    lunlun.push(lunlun[i] * 10 + a + 1) if a < 9
    i += 1
  end
  lunlun[n - 1]
end

k = gets.to_i

puts lunlunNumber(k)


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n,m,ans=0;
  cin >> n;
  vector<string> b(n);
  for(int i=0;i<n;i++)cin >> b.at(i);
  cin >> m;
  vector<string> r(m);
  for(int i=0;i<m;i++)cin >> r.at(i);
  auto calc = [&](string u){
    int buf = 0;
    for(string v : b){
      if(u == v)buf++;
    }
    for(string v : r){
      if(u == v)buf--;
    }
    return buf;
  };
  
  for(string u : b){
    ans = max(ans,calc(u));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
int main(){
  int a, b, c, d, e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if((e-a)>k)cout << ":("<<endl;
  else cout << "Yay!"<< endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#define rep(i,a,b) for(long long int i=(a);i<(b);i++)
#define se(a) a.begin(),a.end()
#define ll long long int
#define mll map<ll,ll>
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define mk make_pair
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e16
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
	ll n,k;
	cin>>n>>k;
	vector<ll> a(n);
	rep(i,0,n)
	cin>>a[i];
	vector<bool> dp(k+1);
	dp[0]=false;
	for(int i=1;i<=k;i++)
	for(int x:a)
	{
		if(i>=x&&!dp[i-x])
		dp[i]=true;
	}
	
	if(dp[k])
	cout<<"First\n";
	else
	cout<<"Second\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;

int main(){
    int n;
    cin >> n;
    ll sum=0;
    for(int i=0;i<n;i++){
        sum+=i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

ll gcd(ll a, ll b) {return(b?gcd(b,a%b):a);}

int main() {
    int n, k; cin >> n >> k;
    vint a(n);
    int mx = 0;
    rep(i,n) {
        int x; cin >> x;
        mx = max(mx,x);
        a[i] = x;
    }
    ll gd = 0;
    rep(i,n) gd = gcd(gd,a[i]);
    if (mx >= k && (mx-k) % gd == 0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std ;
 
#define int long long

#define IOS ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
 
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vp vector<pii>
#define vs vector<string>
#define all(v) v.begin(),v.end()

#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define ff  first
#define ss  second
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
 
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
     
#define pi 3.14159265358979323846//20 decimals
#define MOD 1000000007


 
int32_t main(){

   
     IOS
     int n,x,temp=0,count=0;
     cin>>n>>x;
     vi v(n),ans(n+1);
     for(int i=0;i<n;i++)
     {
       cin>>v[i];
     }
     for(int j=0;j<n+1;j++)
     {
       ans[j]=temp;
        temp+=v[j];
     }
     // for(int d:ans)
     //    cout<<d<<" ";
     for(int k=0;k<ans.size();k++)
     {
        if(ans[k]<=x)
        {
            count++;
        }
     }
     cout<<count;

return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
left = 0
right = s.count('E')
ans = left + right
for i in range(n):
    if s[i] == 'E':
        right -= 1
        ans = min(ans, left + right)
    else:
        ans = min(ans, left + right)
        left += 1
print(ans)


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
 
int main() {
  int A, B, T;
  cin >> A >> B >> T;
  cout << B * (T / A);
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int A, B;

  std::cin >> A >> B;

  std::cout << (A < 10 && B < 10 ? A * B : -1) << std::endl;
  
  return 0;
}


Measured memory_bytes: 256
program	proa
	implicit none
	integer :: a,b
    read(*,*) a,b
    if (a /= 1 .and. b /= 1) then
    	write(*,*) "1"
    else if (a /= 2 .and. b /= 2) then
    	write(*,*) "2"
    else
    	write(*,*) "3"
    end if
    
	stop
end program proa

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc113/tasks/abc113_c
#include <algorithm>
#include <cstdio>
#include <tuple>
using namespace std;

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))

// No、市、年、順位
typedef tuple<int, int, int, int> mytuple;

// int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// 年でソート（0番目から数えて2番目）
bool mycompare(const mytuple &lhs, const mytuple &rhs) {
    return get<2>(lhs) < get<2>(rhs);
}

int main() {
    int n, m, t1, t2;
    scanf("%d%d", &n, &m);
    mytuple tu[m];

    REP(i, m) {
        scanf("%d%d", &t1, &t2);
        tu[i] = make_tuple(i, t1, t2, 0);
    }
    // 年でソート
    sort(tu, tu + m, mycompare);

    // 市の出現回数をメモ
    int cnt[n + 1];
    REP(i, n + 1) cnt[i] = 0;
    REP(i, m) {
        int city = get<1>(tu[i]);
        cnt[city]++;
        tu[i] =
            make_tuple(get<0>(tu[i]), get<1>(tu[i]), get<2>(tu[i]), cnt[city]);
    }
    // 入力順でソート
    sort(tu, tu + m);
    REP(i, m) { printf("%06d%06d\n", get<1>(tu[i]), get<3>(tu[i])); }

    return 0;
}


Measured memory_bytes: 3328
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{

    class Program
    {
        private const long COMDIV = 1000000007;

        static void Main(string[] args)
        {
            var X = int.Parse(Console.ReadLine());
            if (X >= 30)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

int main()
{
	char c;
	vector<char> s;
	while (cin >> c) {
		if (!s.empty() && s.back() == 'S' && c == 'T') {
			s.pop_back();
		}
		else {
			s.push_back(c);
		}
	}
	cout << s.size() << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 2e2 + 10,mod = 998244353;
const double Pi = acos(-1.0),eps = 1e-9;

struct node {
	int x,y;
} P[N];
bool vis[N];

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

inline int fpm(int a,int b) {
	int res = 1;
	while(b) {
		if(b & 1) res = 1ll * res * a % mod;
		a = 1ll * a * a % mod,b /= 2;
	}
	return res;
}

int main() {
	int n = read(),ans = 0;
	For(i,1,n) P[i].x = read(),P[i].y = read();
	ans = (fpm(2,n) - 1 - n - 1ll * n * (n - 1) / 2) % mod;

	For(i,1,n) {
		memset(vis,0,sizeof(vis));
		For(j,1,n) if((i ^ j) && !vis[j]) {
			int cnt = 1;
			double val = atan2(P[j].y - P[i].y,P[j].x - P[i].x);
			For(k,1,n) if(k ^ i) {
				double cur = atan2(P[k].y - P[i].y,P[k].x - P[i].x);
				if(abs(cur - val) < eps || abs(cur - val - Pi) < eps || abs(cur - val + Pi) < eps)
					cnt++,vis[k] = true;
			}
			ans = (ans - 1ll * (fpm(2,cnt) - 1 - cnt - 1ll * cnt * (cnt - 1) / 2 % mod) * fpm(cnt,mod - 2)) % mod;
		}
	}

	printf("%d\n",(ans + mod) % mod);

	return 0;
}

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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 20171211;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,M;cin>>N>>M;
  vector<tuple<ll,ll> > G[N];
  for(ll i=0;i<M;i++){
    ll a,b,c;cin>>a>>b>>c;a--;b--;
    G[a].emplace_back(b,c);
    G[b].emplace_back(a,c);
  }
  ll cost[1<<N][N]={};
  for(ll S=0;S<1<<N;S++){
    for(ll i=0;i<N;i++)if(!((S>>i)&1)){
      for(auto u:G[i])if((S>>get<0>(u))&1){
        cost[S][i] += get<1>(u);
      }
    }
  }
  ll dp[1<<N][N];
  for(ll S=0;S<1<<N;S++){
    for(ll i=0;i<N;i++){
      dp[S][i]=INF;
    }
  }
  dp[1][0]=0;
  ll all = (1<<N)-1;
  for(ll S=1;S<1<<N;S+=2){
    //debug((bitset<4>)S);
    for(ll i=0;i<N;i++)if((S>>i)&1){
      //debug(i);
      //debug(dp[S][i]);
      for(auto e:G[i])if(!((S>>get<0>(e))&1)){
        ll v,c;tie(v,c)=e;
        /*
        debug(v);
        debug(c);
        debug(cost[S][v]);
        debug(dp[S|(1<<v)][v]);
        */
        dp[S|(1<<v)][v]=min(dp[S|(1<<v)][v],dp[S][i]+cost[S][v]-c);
        //debug(dp[S|(1<<v)][v]);
      }
      for(ll T=~S&all;T>0;T=(T-1)&(~S&all)){
        ll add=0;
        for(ll j=0;j<N;j++)if((T>>j)&1)add+=cost[S^(1<<i)][j];
        dp[S|T][i]=min(dp[S|T][i],dp[S][i]+add);
      }
    }
  }
  cout<<dp[all][N-1]<<endl;
  return 0;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 1000000100000000000
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define st size_t
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=2015;
const int NN=1000001;
const ll md=998244353;


int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    ll n,k;
    cin >> n >> k;
    ll ans=n;
    n=n%k;
    ans=min(ans,n);
    n=k-n;
    ans=min(ans,n);
    cout << ans << E;
    r0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
ans = "No"
for i in range(n - m + 1):
  for j in range(n - m + 1):
    S = []
    for k in range(m):
      S.append(A[i + k][j:j + m])
      if S == B:
        ans = "Yes"
print(ans)

Measured memory_bytes: 3064
N = int(input())
edges = []
nb = [[] for _ in range(N)]
maxdeg = 0
root = None
for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges.append((min(a, b), max(a, b)))
    nb[a].append(b)
    nb[b].append(a)
    if len(nb[a]) > maxdeg:
        maxdeg = len(nb[a])
        root = a
    if len(nb[b]) > maxdeg:
        maxdeg = len(nb[b])
        root = b

colors = {}
done = [False] * N
done[root] = True
for i, x in enumerate(nb[root]):
    colors[x, root] = colors[root, x] = i + 1
    stack = [(x, root, i + 1)]
    while stack:
        node, parent, pcolor = stack.pop()
        if done[node]:
            continue
        done[node] = True
        colors[node, parent] = colors[parent, node] = pcolor
        color = 0
        for c in nb[node]:
            if c != parent and not done[c]:
                color += 1
                if color == pcolor:
                    color += 1
                stack.append((c, node, color))

print(maxdeg)
for a, b in edges:
    print(colors[a, b])


Measured memory_bytes: 106140
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
x=list(map(int,input().split()))

N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

kaijo=1
for i in range(n-1):
    kaijo*=n-i-1
    kaijo%=mod
# print(kaijo)

ans=0
cnt=0
for i in range(n-1):
    y1,y2=x[i],x[i+1]
    sa=y2-y1
    cnt+=g1[n-1]*g2[i+1]*g1[i]
    ans+=cnt*sa
    # print(g1[n-1]*g2[i+1]*g1[i])
    ans%=mod
    # print(ans)
# print(g1[:10])
# print(g2[:10])
print(ans)

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

int main() {
  int n; cin >> n;
  std::vector<int> p(n);
  std::vector<int> q(n);
  rep(i,n) cin >> p[i];
  rep(i,n) cin >> q[i];

  std::vector<int> v(n);
  rep(i,n) v[i] = i + 1;

  map<std::vector<int>, int> mp;
  do {
    mp[v] = mp.size();
  } while (next_permutation(v.begin(), v.end()));

  int ans = abs(mp[p]-mp[q]);
  cout << ans << endl;
}


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

int main() {
    int A1, A2, A3;
    cin >> A1 >> A2 >> A3;
    vector <int> A = {abs(A1-A2), abs(A2-A3), abs(A1-A3)};
    sort(A.begin(), A.end());
    cout << A.at(0)+A.at(1) << "\n";
}

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

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

const pair<int, int> ds[4] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};

int main(void)
{
    int W, H;
    string S;
    cin >> H >> W;
    auto map = vcd(vector<bool>, H+2, vcd(bool, W+2, false));
    int sum = 0;
    for (int i = 1; i <= H; i++)
    {
        cin >> S;
        for (int j = 1; j <= W; j++)
        {
            map[i][j] = S[j-1] == '.';
            if (map[i][j]) sum++;
        }
    }
    queue<pair<pair<int, int>, int>> q;
    q.push({{1, 1}, 1});
    int x, y, d;
    while (!q.empty())
    {
        y = q.front().first.first;
        x = q.front().first.second;
        d = q.front().second;
        if (y == H && x == W)
        {
            cout << (sum - d) << endl;
            return 0;
        }
        q.pop();
        fa(di, ds) if (map[y+di.first][x+di.second]) { map[y+di.first][x+di.second] = false; q.push({{y+di.first, x+di.second}, d+1}); }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define s second
using namespace std;
typedef long long ll;
const int MAX=1e5+55;
int x[MAX];
int dp[100000+55];
 int n;
 int cho1=0;
 int cho2=0;
int solve(int i)
{
    //cout<<'1'<<" "<<cho1<<" "<<x[i]<<" "<<i<<" "<<last<<endl;

    if(i==n){
        return 0;
    }
    if(i==n-1)
        return abs(x[i]-x[i+1]);
    int &ret=dp[i];
    if(ret!=-1)
        return ret;
    cho1=(abs(x[i]-x[i+1])+solve(i+1));
    cho2=abs(x[i]-x[i+2])+solve(i+2);
        ret=min(cho1,cho2);
        return ret;




}
int main()
{
 cin>>n;
 memset(dp,-1,sizeof dp);
 for(int i=1;i<=n;i++)
    cin>>x[i];
 cout<<solve(1);

return 0;
}


Measured memory_bytes: 4096
# AtCoder Beginner Contest 121
# https://atcoder.jp/contests/abc121
import sys

s2nn = lambda s: map(int, s.split(' '))
ss2nn = lambda ss: map(int, ss)
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    H, W = i2nn()
    h, w = i2nn()
    n = (H - h) * (W - w)
    print(n)

main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ll A,B,Q;
    cin >> A >> B >> Q;
    vector<ll> s(A+2), t(B+2);
    s[0] = -1001001001001001001;
    s[A+1] = 1001001001001001001;
    t[0] = s[0];
    t[B+1] = s[A+1];
    for(int i=1; i<=A; ++i) cin >> s[i];
    for(int i=1; i<=B; ++i) cin >> t[i];

    for(int i=0; i<Q; ++i) {
        ll x; cin >> x;

        int ns = upper_bound(s.begin(), s.end(), x) - s.begin();
        int nt = upper_bound(t.begin(), t.end(), x) - t.begin();

        ll res = 1001001001001001001;
        for(int j=0; j<2; ++j) {
            for(int k=0; k<2; ++k) {
                ll d1 = abs(s[ns-j] - x) + abs(s[ns-j] - t[nt-k]);
                ll d2 = abs(t[nt-k] - x) + abs(s[ns-j] - t[nt-k]);
                res = min({res, d1, d2});
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  char a;
  cin >> a;
  if (a <= 'Z') {
	  cout << 'A' << endl;
	} else {
	  cout << 'a' << endl;
	}
  return 0;
}


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

int main(void){
	int N;
	cin >> N;
	int M = N/1.08 - 1;
	
	rep(i,10){
		M += 1;
		if (int(M*1.08) == N) {
			cout << M << endl;
			return 0;
		}
	}
	cout << ":(" << endl;




	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
  int K,A,B;

  cin >> K;
  cin >> A >> B;

  for(int i = K;i <= B;i = i+K){
    if(i >= A) {
      cout << "OK";
      return 0;
    }
  }

  cout << "NG";

  return 0;
}

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

int main(){
    int N, A, B, tmp, i;
    int sum = 0;
    int ans = 0;

    cin >> N >> A >> B;
    
    for (i = 1; i <= N; i++){
        tmp = i;

        while (tmp != 0){
            sum = sum + tmp % 10;
            tmp = tmp/10;
        }
        if (A <= sum && sum <= B)
            ans = ans + i;
        sum = 0;
    }


        cout << ans << endl;
    }



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

struct P {
  long long x, y;
  P() {}
  P(double x, double y) : x(x), y(y) {}
  P operator+(P p) { return P(x + p.x, y + p.y); }
  P operator-(P p) { return P(x - p.x, y - p.y); }
  P operator*(double d) { return P(x * d, y * d); }
  double dot(P p) { return x * p.x + y * p.y; }
  double det(P p) { return x * p.y - y * p.x; }
};
bool conm_x(const P &l, const P &r) {
  if(l.x != r.x) return l.x < r.x;
  return l.y < r.y;
}

long long n;
vector<P> point;

long double solve();
vector<P> convex_hull(vector<P> &ps, int n);

int main() {
  cout << fixed << setprecision(12);
  cin >> n;
  point.resize(n);
  for(int i = 0; i < n; ++i)
    cin >> point[i].x >> point[i].y;
  cout << solve() << endl;
  return 0;
}

long double solve() {
  vector<P> now;
  long long nowsize = 0;
  now.push_back({0, 0});
  now.push_back(point[0]);
  for(int i = 1; i < n; ++i) {
    if(point[i].x == point[i].y && point[i].x == 0)
      continue;
    nowsize = now.size();
    for(int j = 0; j < nowsize; ++j) {
      P nextp = now[j];
      nextp = nextp + point[i];
      now.push_back(nextp);
    }
    now = convex_hull(now, now.size());
  }
  long double ans = 0.0;
  nowsize = now.size();
  for(int i = 0; i < nowsize; ++i) {
    long double nowans = 0.0;
    nowans =
        sqrt(now[i].x * now[i].x + now[i].y * now[i].y);
    ans = max(ans, nowans);
  }
  return ans;
}

vector<P> convex_hull(vector<P> &ps, int N) {
  sort(ps.begin(), ps.end(), conm_x);
  int k = 0;
  vector<P> qs(N * 2);
  for(int i = 0; i < N; ++i) {
    while(k > 1 &&
          (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <=
              0)
      --k;
    qs[k++] = ps[i];
  };
  for(int i = N - 2, t = k; i >= 0; --i) {
    while(k > t &&
          (qs[k - 1] - qs[k - 2]).det(ps[i] - qs[k - 1]) <=
              0)
      k--;
    qs[k++] = ps[i];
  }
  qs.resize(k - 1);
  return qs;
}

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

int main(){
    int a, b, i, j, k;
    i = 2;
    j = 1;
    k = 1;
    while (k == 1){
        scanf("%d %d", &a, &b);
        if (a == 0 && b == 0){
            break;
        } else {
            while (j <= b){
                printf("#");
                j += 1;
            }
            j = 2;
            printf("\n");
            while (i <= a - 1){
                printf("#");
                while (j <= b - 1){
                    printf(".");
                    j += 1;
                }
                i += 1;
                j = 2;
                printf("#\n");
            }
            i = 2;
            j = 1;
            while (j <= b){
                printf("#");
                j += 1;
            }
            j = 1;
            printf("\n");
            printf("\n");
        }
        a = 0;
        b = 0;
    }
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  int max_divide = 10000;
  for (int i = 0; i < n; i++) {
    int a, n_divide = 0;
    cin >> a;
    
    for (; a != 0; a /= 2) {
      if (a % 2 == 0) {
        n_divide++;
      } else {
        break;
      }
    }

    if (n_divide < max_divide) {
      max_divide = n_divide;
    }
  }

  cout << max_divide << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define F first
#define S second
#define mp make_pair
using namespace std;
const int N=1e5+5;
stack<ll>st;
ll n,cnt,k,num;
pll p[N];
ll ans,sum;
bool use[N];
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>p[i].S>>p[i].F;
	sort(p,p+n);
	reverse(p,p+n);
	for(int i=0;i<n;i++)swap(p[i].F,p[i].S);
	for(int i=0;i<n;i++)
	{
		if(cnt<k)
		{
			if(use[p[i].F])
				st.push(p[i].S);
			else
				num++,use[p[i].F]=true;
			sum+=p[i].S;
			ans=max(ans,sum+num*num);
			cnt++;
		}
		else
		{
			if(st.empty())break;
			if(use[p[i].F])continue;
			use[p[i].F]=true;
			num++;
			sum-=st.top();
			sum+=p[i].S;
			st.pop();
			ans=max(ans,sum+num*num);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  string s; cin >> s;
  if (s == "SUN") cout << 7;
  if (s == "MON") cout << 6;
  if (s == "TUE") cout << 5;
  if (s == "WED") cout << 4;
  if (s == "THU") cout << 3;
  if (s == "FRI") cout << 2;
  if (s == "SAT") cout << 1;
  cout << endl;
}

Measured memory_bytes: 256
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
A = inl()
C = Counter(A)


def choose2(k):
    return k * (k - 1) // 2


def solve():
    total = 0
    for x, k in C.items():
        total += choose2(k)

    for i in range(N):
        x = A[i]
        a = total - choose2(C[x]) + choose2(C[x] - 1)
        print(a)


solve()


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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> vec(N, 0);
    for(int m=0; m<M; m++) {
        int K;
        cin >> K;
        
        for(int k=0; k<K; k++) {
            int s;
            cin >> s;
            vec[s-1] = vec[s-1]|(1<<m);
        }
    }
    int lon=0;
    for(int m=0; m<M; m++) {
        int t;
        cin >> t;
        lon = lon|(t<<m);
    }

    // for(int n=0; n<N; n++) {
    //     cout << "son" << n+1 << ": " << vec[n] << endl;
    // }
    // cout << "lon: " << lon << endl;
    
    int ans=0;
    for(int i=1; i<=(1<<N); i++) {
        int son=0;
        for(int n=0; n<N; n++) {
            if(i & (1<<n)) {
                son = son^vec[n];
            }
        }
        // cout << "ons: " << i << ", ";
        // cout << "onl: " << son << endl;
        if(lon==son) ans++;
    }
    
    cout << ans << endl;


    return 0;
    
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  string S;
  cin >> S;

  vector<int> C(3, 0);
  for (const char c : S) {
    ++C.at(c - 'a');
  }
  sort(C.begin(), C.end());
  if (C.at(2) - C.at(0) <= 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main() {
    int N;
    cin >> N;
    vector<P> v(N);
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        v[i] = P(b, a);
    }
    sort(v.begin(), v.end());
    int T = 0;
    for (int i = 0; i < N; i++) {
        T += v[i].second;
        if (T > v[i].first) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1792
//abc072_a Sandglass2


#include <iostream>
using namespace std;

int main()
{
int X;
int t;

	cin >> X;
	cin >> t;
	X -= t;
	if( X > 0 )
		cout << X << endl;
	else
		cout << 0 << endl;

	return 0;
}






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

int n, k;
vector<int> nums;
set<int> st = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int limitLen;
vector<int> anss;

int dfs(int m, int i) {
  if (i >= limitLen) return m;

  if (m >= n) return m;

  for (auto num : nums) {
    int a = dfs(m * 10 + num, i + 1);
    anss.push_back(a);
  }
}

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

  cin >> n >> k;

  limitLen = to_string(n).length() + 1;

  for (int i = 0; i < k; i++) {
    int di;
    cin >> di;

    st.erase(di);
  }

  for (int num : st) {
    nums.push_back(num);
  }

  dfs(0, 0);

  sort(anss.begin(), anss.end());

  for (auto ans : anss) {
    if (ans >= n) {
      cout << ans << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int ct0 = 0;
    int ct1 = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '0'){
            ct0++;
        }
        else{
            ct1++;
        }
    }
    cout << min(ct0, ct1) * 2 << endl;
}  

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;


int main(){
    ll N;
    cin >> N;
    string S;
    cin >> S;
    ll Lcounter=0;
    ll Rcounter=0;
    for(ll i=0;i<N;i++){
        if(S[i]=='('){Lcounter++;}
        else if(S[i]==')'){Rcounter++;}
        if(Rcounter>Lcounter){
            N++;i++;Lcounter++;
            S='('+S;
        }
    ;}
    for(ll i=0;i<Lcounter-Rcounter;i++){
        S+=')';
    ;}
    cout<<S<<endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

int main() {
	int a, b; CI a >> b;
	int c, d; CI c >> d;

	CO a* b - ((c*b)+((a-c)*d)) EN;
}

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

int main(){
    int N,P;
    cin >> N >> P;
    long long A;
    int m = 0;
    for(int i = 0; i < N;i++){
        cin >> A;
        if(A % 2 == 1)m++;
    }
    
    if(m == 0)cout << (P == 0 ? (1LL << N) : 0) << endl;
    else cout << (1LL << (N-1)) << endl;
}

Measured memory_bytes: 3548
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int n,x,y;
int dist[2010][2010];

signed main(){
    cin >> n >> x >> y;
    x--; y--;
    REP(i,n) FOR(j,i+1,n) {
        dist[i][j] = min(j-i, abs(j-y) + 1 + abs(x-i));
    }
    map<int,int> ret;
    REP(i,n) FOR(j,i+1,n) if (dist[i][j]) ret[dist[i][j]]++;
    REPS(i,n-1) cout << ret[i] << endl;
}

Measured memory_bytes: 31232
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
using namespace std;
typedef long long LL;

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

    if (s[0] == '9' || s[1] == '9') {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1000000007LL;
ll a[2000];
ll b[2000];
int main() {
	int N;
	ll x;
	cin >> N >> x;
	for (int i = 0; i < N; i++) cin >> a[i], b[i] = a[i];
	ll ans = 1LL << 60;
	for (int i = 0; i <= N - 1; i++) {
		ll sum = 0;
		for (int j = 0; j < N; j++) sum += b[j];
		ans = min(ans, i*x + sum);
		for (int j = 0; j < N; j++) {
			b[j] = min(b[j], a[(j - (i + 1) + N) % N]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
/*input
6 3 4
3
1
3
2
*/
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define MAX 100005
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define T int t;cin>>t;while(t--)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define umi unordered_map<int,int>
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int> >
#define inp(n) for(int i=0;i<n;i++)
#define N 2000005

using namespace std;
using namespace std::chrono;


signed main(){
    int n,k,q,x;
    cin>>n>>k>>q;
    int f[n+1]={};
    loop(i,0,q){
        cin>>x;
        f[x]++;
    }
    loop(i,1,n+1){
        if(k-q+f[i]>0)  cout<<"Yes\n";
        else            cout<<"No\n";
    }
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
int x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  int x3=x2+y1-y2;
  int y3=x2+y2-x1;
  int x4=x1+y1-y2;
  int y4=y1+x2-x1;
  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;

return 0;
}

Measured memory_bytes: 256
n = int(input())
S = input()

sapp = [[0] * n for _ in range(10)]
for idx, s in enumerate(S):
    sapp[int(s)][idx] = 1

from itertools import accumulate
sacc = [list(accumulate(sa)) for sa in sapp]

pins = set()
for i in range(1, n-1):
    for lnum in range(10):
        if sacc[lnum][i-1] == 0:
            continue
        for rnum in range(10):
            # i+1から最後までで出現するか
            rnumc = sacc[rnum][-1] - sacc[rnum][i]
            if rnumc > 0:
                pins.add(100*lnum + 10*int(S[i]) + rnum)

print(len(pins))


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

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

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

    ll val = 1;
    REP(i, 2, sqrt(N) + 1) if(N % i == 0) val = i;
    if (val == 1) {
        cout << N - 1 << endl;
    } else {
        cout << val + N / val - 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def chmin(a, b):
    if a < b:
        return (a)
    else:
        return (b)

ans = [100000000] * 100001
can = [1,6,9,36,81,216,729,1296,6561,7776, 46656, 59049]
ans[1] = 1
ans[6] = 1
ans[36] = 1
ans[216] = 1
ans[1296] = 1
ans[7776] = 1
ans[46656] = 1
ans[9] = 1
ans[81] = 1
ans[729] = 1
ans[6561] = 1
ans[59049] = 1

for i in range(2,100001):
    for j in can:
        if i > j:
            ans[i] = chmin(ans[i], ans[i-j]+1)

N = int(input())
print(ans[N])


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

int main() {
	long long int n, x;
	long long int min = LLONG_MAX;
	long long int max = LLONG_MIN;
	long long int sum = 0;
	cin >> n;
	for (int i = 0; i < n; i + 0) {
		cin >> x;
		if (x < min) {
			min = x;
		}
		if (x > max) {
			max = x;
		}
		sum = sum + x;
		i++;
	}
	cout << min << " " << max << " " << sum << endl;
	return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int S,T;
vector<pair<int,int>> E[101010];
ll D[2][101010];
ll pat[2][101010];
ll mo=1000000007;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	cin>>S>>T;
	S--,T--;
	FOR(i,M) {
		cin>>x>>y>>j;
		x--,y--;
		E[x].push_back({y,j});
		E[y].push_back({x,j});
	}
	
	priority_queue<pair<ll,int>> P;
	pat[0][S]=pat[1][T]=1;
	FOR(i,N) D[0][i]=D[1][i]=1LL<<60;
	D[0][S]=D[1][T]=0;
	P.push({0,S});
	P.push({0,100000+T});
	
	while(P.size()) {
		int cur=P.top().second%100000;
		int id=P.top().second/100000;
		ll co=-P.top().first;
		P.pop();
		if(D[id][cur]!=co) continue;
		FORR(e,E[cur]) {
			if(co+e.second < D[id][e.first]) {
				pat[id][e.first]=0;
				D[id][e.first] = co+e.second;
				P.push({-D[id][e.first],id*100000+e.first});
			}
			if(co+e.second == D[id][e.first]) (pat[id][e.first]+=pat[id][cur])%=mo;
			
		}
	}
	
	
	ll tot=pat[0][T]*pat[0][T]%mo;
	FOR(i,N) if(D[0][i]+D[1][i]==D[0][T]) {
		if(D[0][i]==D[1][i]) {
			tot+=mo-pat[0][i]*pat[0][i]%mo*pat[1][i]%mo*pat[1][i]%mo;
		}
		if(D[0][i]<D[1][i]) {
			FORR(e,E[i]) if(D[0][e.first]+D[1][e.first]==D[0][T] && D[0][e.first]>D[1][e.first] && D[0][e.first]==D[0][i]+e.second) {
				tot+=mo-pat[0][i]*pat[0][i]%mo*pat[1][e.first]%mo*pat[1][e.first]%mo;
			}
		}
		tot%=mo;
		
	}
	
	cout<<tot<<endl;
	
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 15984
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<numeric>
#include<sstream>
#include<cmath>
using namespace std;
long long int mod = 1e9+7;

int main(){
  string s;
  int n, k; cin >> n >> s >> k;
  char c = s[k-1];
  for(int i=0; i<n; i++) {
    if(s[i] != c) s[i] = '*';
  }
  cout << s << endl;
  return 0;
}


// EOF


Measured memory_bytes: 764
// 解き直し.
// https://img.atcoder.jp/abc161/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    
    // 1. 入力情報.
    int K;
    scanf("%d", &K);
    
    // 2. 解説通り.
    LL ans;
    queue<LL> q;
    rep(i, 9) q.push(i + 1);
    while(1){
        // Queue から 要素 を 取り出す.
        LL x = q.front();
        q.pop();
        
        // 操作を行う.
        LL r = x % 10; // 1の位を取得.
        for(LL d : {-1, 0, 1}){
            LL a = r + d; // 1の位に, -1, 0, 1 を 加算.
            if(a >= 0 && a <= 9) q.push(10 * x + a);
        }
        
        // K回目であるかチェック.
        if(!(--K)){
            ans = x;
            break;
        }
    }
    
    // 3. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 1792
#include<iostream>

using namespace std;

void call ( int n )
{
	int i = 1;
	do
	{
		int x = i;
		if ( x%3 == 0 )
		{
			cout << " " << i;
		}
		else
		{
			do
			{
				if ( x%10 == 3 )
				{
					cout << " " << i;
					break;
				}
				x /= 10;
			} while ( x );
		}
	} while ( ++i <= n );

	cout << endl;
}

int main()
{

	int n;
	cin >> n;

	call( n );

return 0;
}



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

#define Sort(ob,n) sort(ob,ob+n)
#define SorT(ob) sort(ob.begin(),ob.end())
#define rev(ob) reverse(ob.begin(),ob.end())
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define fi(start,End,I) for(int i=start; i<=End; i+=I)
#define PII pair<int,int>
#define fr first
#define se second


int main()
{
    fast;
    string s1;
    cin >> s1;
    int len = s1.size();

    fi(0,len-2,1){
        if(s1[i] == s1[i+1]){
            cout << "Bad";
            return 0;
        }
    }

    cout << "Good\n";


    return 0;
}


Measured memory_bytes: 256