akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<30)
#define LLINF (1LL<<60)
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
    int n,num[1000];
    string s[100005];
    cin>>n>>num['A']>>num['B']>>num['C'];
    rep(i,n)cin>>s[i];
    if(num['A']+num['B']+num['C']==0)No;
    else if(num['A']+num['B']+num['C']==1){
        vector<char> ans;
        rep(i,n){
            char t1=s[i][0],t2=s[i][1];
            if(num[t1]==0&&num[t2]==0){
                No;
                return 0;
            }
            else if(num[t1]==1&&num[t2]==0){
                num[t1]--;
                num[t2]++;
                ans.pb(t2);
            }
            else if(num[t1]==0&&num[t2]==1){
                num[t1]++;
                num[t2]--;
                ans.pb(t1);
            }
        }
        Yes;
        rep(i,ans.size())cout<<ans[i]<<endl;
    }
    else{
        vector<char> ans;
        rep(i,n){
            char t1=s[i][0],t2=s[i][1];
            if(num[t1]==0&&num[t2]==0){
                No;
                return 0;
            }
            else if(num[t2]==0){
                num[t1]--;
                num[t2]++;
                ans.pb(t2);
            }
            else if(num[t1]==0){
                num[t1]++;
                num[t2]--;
                ans.pb(t1);
            }
            else{
                if(i!=n-1&&s[i]!=s[i+1]){
                    char now1=s[i][0],now2=s[i][1],next1=s[i+1][0],next2=s[i+1][1];
                    if(now1==next1||now1==next2){
                        num[now1]++;
                        num[now2]--;
                        ans.pb(now1);
                    }
                    else if(now2==next1||now2==next2){
                        num[now2]++;
                        num[now1]--;
                        ans.pb(now2);
                    }
                }
                else{
                    num[t1]++;
                    num[t2]--;
                    ans.pb(t1);
                }
            }
        }
        Yes;
        rep(i,n)cout<<ans[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 6896
function main(input) {
    input = input[0].split(' ');
    w = parseInt(input[0], 10);
    h = parseInt(input[1], 10);
    x = parseInt(input[2], 10);
    y = parseInt(input[3], 10);
    // var smallH = x*h>(w-x)*h?(w-x)*h:x*h, smallW = y*w>(h-y)*w?(h-y)*w:y*w;
    // if (smallH == smallW) console.log(smallH, 1);
    // else console.log(smallH>smallW?smallH:smallW, 0);
    console.log(w*h/2, w/2==x&&h/2==y?1:0);
    
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 7628
using System;
using System.Linq;

namespace abc135_b
{
    static class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine().ToInteger();
            var p = Console.ReadLine().ToIntArray();

            var order = p.OrderBy(m => m).ToArray();

            var count = 0;
            for (int i = 0; i < p.Length; i++)
            {
                if (p[i] != order[i])
                {
                    count++;
                    if (count > 3)
                    {
                        break;
                    }
                }
            }

            Console.WriteLine($"{(count <= 2 ? "YES" : "NO")}");
        }

        static int ToInteger(this string s)
        {
            return int.Parse(s);
        }

        static int[] ToIntArray(this string s, char separator = ' ')
        {
            return s.Split(separator).Select(m => m.ToInteger()).ToArray();
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	long long h, w;
	cin >> h >> w;


	long long ans = min({
		((h+2)/3 - h/3) * w,
		((w+2)/3 - w/3) * h
	});

	// cout << ans << endl;

	for (int i = 0; i <= w; i++) {
		long long s1 = h * i;
		long long s2 = h / 2 * (w - i);
		long long s3 = (w - i) * h - s2;
		long long tmp = max({s1, s2, s3}) - min({s1, s2, s3});
		ans = min(ans, tmp);
		// printf("w %d %lld: s %lld %lld %lld\n", i, tmp, s1, s2, s3);
	}

	for (int i = 0; i <= h; i++) {
		long long s1 = w * i;
		long long s2 = w / 2 * (h - i);
		long long s3 = (h - i) * w - s2;
		long long tmp = max({s1, s2, s3}) - min({s1, s2, s3});
		ans = min(ans, tmp);
		// printf("w %d %lld: s %lld %lld %lld\n", i, tmp, s1, s2, s3);
	}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define int long long
#define pb push_back
#define mp make_pair
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define sorta(v) stable_sort(v.begin(),v.end())
#define sortd(v) stable_sort(v.begin(),v.end(),greater <> ())
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define I(a) insert(a)
#define F first
#define S second
const int N=1e9+7;

int power(int x, int y){ 
    int res = 1; 
    while (y > 0){
        if (y & 1) 
            res = ((res) * (x));
        res %= N; 
        y = y >> 1; 
        x = ((x) * (x)); 
    }
    return res; 
}

int powmod(int a,int b,int n){
    int x=1, y=a; 
    while (b > 0) {
        if (b%2 == 1) {
            x = (x*y) % n;
        }
        y = (y*y) % n; 
        b /= 2;
    
    }
    return x % n;
}

int32_t main(){
    fastIO
    int t=1;
    //cin>>t;
    while(t--){
        int h,w;
        cin>>h>>w;
        vector<vector<char>>v(h+1,vector <char> (w+1));
        vector<vector<int>>dp(h+1,vector <int> (w+1,0));
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++)
                cin>>v[i][j];
        }
        
        dp[1][1]=1;
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                if(v[i][j]=='.'){
                    if(i==1 && j!=1){
                        dp[i][j]=(dp[i][j-1])%N;
                    }
                    else if(j==1 && i!=1){
                        dp[i][j]=(dp[i-1][j])%N;
                    }
                    else if(i!=1 && j!=1){
                        dp[i][j]=(dp[i-1][j]+dp[i][j-1])%N;
                    }
                }
            }
        }
        cout<<dp[h][w]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 9216
x, n = map(int, input().split())
p = set(list(map(int, input().split())))

if x not in p:
    print(x)
    exit()

sa = 1
while True:
    if x-sa not in p:
        print(x-sa)
        exit()
    if x+sa not in p:
        print(x+sa)
        exit()
    sa += 1

Measured memory_bytes: 61648
#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()




using namespace std;

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

  int m = 60 * H + M;

  double radH = 2* M_PI * m/(12 * 60);
  double radM = 2* M_PI * m/60;

  double x1 = A*cos(radH),y1 = A * sin(radH);
  double x2 = B*cos(radM),y2 = B* sin(radM);

  double ans = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
  ans = sqrt(ans);

  printf("%.16f\n",ans);



  
  return 0;
}

Measured memory_bytes: 4084
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
A = [I() for i in range(5)]
num = min(A)

print(4 + math.ceil(N/num))

Measured memory_bytes: 12484
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

int main() {
    int N, W; cin >> N >> W;
    vector<int> w(N), v(N);
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];
    map<long long, int> cur;
    cur[0] = 0;
    for (int i = 0; i < N; i++) {
        map<long long, int> nxt;
        for (auto &p: cur) {
            chmax(nxt[p.first], p.second);
            if (p.first + w[i] <= W) chmax(nxt[p.first + w[i]], p.second + v[i]);
        }
        swap(cur, nxt);
    }
    int ma = 0;
    for (auto &p: cur) chmax(ma, p.second);
    cout << ma << endl;
    return 0;
}

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

int main() {
	int h,n;
	cin>>h>>n;
	long long int ans = 0;
	
	for(int i=0;i<n;++i){
	    int temp;
	    cin>>temp;
	    ans += temp;
	}
	
	if(ans>=h)
	    cout<<"Yes";
	else
	    cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cmath>
#include <list>
#include <assert.h>

using namespace std;

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) (v).erase( unique(all(v), (v).end() );
#define SZ(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define SUM(v) accumulate((v).begin(), (v).end(), (ll)0)
#define INF 1000000000000
#define MOD 1000000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

using ll = long long;
using ull = unsigned long long;

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

const char newl = '\n';

ll qp(ll a,ull b){ll ans=1;do{if(b&1u)ans*=a;a*=a;}while(b>>=1u);return ans;}
ll qp(ll a,ull b,ll mod){ll ans=1;do{if(b&1u)ans=ans*a%mod;a=a*a%mod;}while(b>>=1u);return ans;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


int main() {
    ll n; cin >> n;
    ll x; cin >> x;
    ll t; cin >> t;

    cout << setprecision(10) << ceil((double)n / x) * t << newl;

    return 0;
}


Measured memory_bytes: 3324
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)

int main(){
    ll n,ans=0;
    cin>>n;
    for (ll i = 1; i*i < n; ++i) {
        if(n%i==0&&n/i-1>i){
            ans+=n/i-1;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long

class UnionFind
{
    std::vector<int> data;

  public:
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x != y)
        {
            if (data[y] < data[x])
                std::swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool find(int x, int y)
    {
        return root(x) == root(y);
    }
    int root(int x)
    {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    ll size(int x)
    {
        return -data[root(x)];
    }
};

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

  ll n, m;
  cin >> n >> m;
  ll a[m], b[m];
  
  REP(i, m){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  
  ll rec = (n * (n - 1)) / 2;
  vector<ll> ans;
  ans.push_back(rec);
  UnionFind uf(n);
  for(ll i = m - 1; i >= 0; i--){
    if(!uf.find(a[i], b[i])){
      ll tmp = uf.size(a[i]) * uf.size(b[i]);
      uf.unite(a[i], b[i]);
      rec -= tmp;
    }
    ans.push_back(rec);
  }

  for(int i = m - 1; i >= 0; i--) cout << ans[i] << endl;
  return 0;
}

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

int n;
int x;
int m_all = 0;
int m_min = 1000000;
int ans;

void solve() {
  ans = n + (x - m_all) / m_min;
  cout << ans << endl;
}

int main() {
  cin >> n >> x;
  for (int i = 0; i < n; ++i) {
    int m;
    cin >> m;
    m_all += m;
    if (m < m_min) m_min = m;
  }
  solve();
}

Measured memory_bytes: 256
# def gcd(a_gcd, b_gcd):
#     while b_gcd != 0:
#         a_gcd, b_gcd = b_gcd, a_gcd % b_gcd
#     return a_gcd
#
#
# def lcm(a_lcm, b_lcm):
#     return a_lcm * b // gcd(a_lcm, b_lcm)
#
#
# def max_sum(N_max_sum, a_max_sum):
#     dp = [0] * (N_max_sum + 1)
#     for i in range(N_max_sum):
#         dp[i + 1] = max(dp[i], dp[i] + a_max_sum[i])
#     return dp[N]
#
#
# def knapsack(N_knapsack, W, weight, value):
#     inf = float("inf")
#     dp = [[-inf for _ in range(W+1)] for j in range(N_knapsack + 1)]
#     for i in range(W+1):
#         dp[0][i] = 0
#
#     for i in range(N_knapsack):
#         for w in range(W+1):
#             if weight[i] <= w:
#                 dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w])
#             else:
#                 dp[i+1][w] = dp[i][w]
#     return dp[N_knapsack][W]
#
#
# class UnionFind:
#     def __init__(self, n):
#         self.par = [i for i in range(n+1)]
#         self.rank = [0] * (n+1)
#
#     # 検索
#     def find(self, x):
#         if self.par[x] == x:
#             return x
#         else:
#             self.par[x] = self.find(self.par[x])
#             return self.par[x]
#
#     # 併合
#     def union(self, x, y):
#         x = self.find(x)
#         y = self.find(y)
#         if self.rank[x] < self.rank[y]:
#             self.par[x] = y
#         else:
#             self.par[y] = x
#             if self.rank[x] == self.rank[y]:
#                 self.rank[x] += 1
#
#     # 同じ集合に属するか判定
#     def same_check(self, x, y):
#         return self.find(x) == self.find(y)
#
# S = input()
# N = int(input())
# A = list(map(int, input().split()))
# X = [int(input()) for _ in range(N)]

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

if A >= 13:
    print(B)
elif A <= 5:
    print(0)
else:
    print(int(B/2))



ans = 0





# print(ans)















Measured memory_bytes: 38384
import sys


def slove():
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    g = 0
    p = 0
    for i in range(len(s)):
        if s[i] == "g":
            g += 1
        else:
            p += 1
    pp = len(s) // 2
    cnt = 0
    for i in range(len(s)):
        if pp != 0:
            pp -= 1
            if s[i] == "g":
                cnt += 1
        else:
            if s[i] == "p":
                cnt -= 1
    print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 40176
from itertools import combinations
a,(n,d)=0,list(map(int,input().split()))
for i in [sum([abs(i[0][j]-i[1][j])**2for j in range(d)])**0.5for i in list(combinations([list(map(int,input().split()))for i in range(n)],2))]:
  if i.is_integer():a+=1
print(a)

Measured memory_bytes: 38768
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 string S;
  cin>>S;
  if(S[0]!='A') {
cout<<"WA"<<endl;
    return 0;
  }
  ll count=0;
  ll index;
  for(ll i=2;i<S.size()-1;i++) {
    if(S[i]=='C') {
index=i;
      count++;
    }
  }
  
  if(count!=1) {
cout<<"WA"<<endl;
    return 0;
  }
  for(ll i=1;i<S.size();i++) {
if(i==index) {
continue;
}
    if(S[i]-'a'<0) {
cout<<"WA"<<endl;
      return 0;
    }
  }
  
  
  cout<<"AC"<<endl;
}
  
  

  
  
  
  
  


Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
typedef long long ll;
typedef unsigned long long ull;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()ss		
#define debug system("pause")				//デバッグ用

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

	int n;
	cin >> n;
	vector < pair<string, pair<int,int>>> s(n);

	for (int i = 0; i < n; i++)
	{
		cin >> s[i].first >> s[i].second.first;
		s[i].second.second = i;
	}

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

	for (int i = 0; i < n-1; i++)
	{
		for (int j = i; j < n; j++)
		{
			if (s[i].first == s[j].first)
			{
				if (s[i].second < s[j].second)
				{
					int tmp = s[i].second.second;
					s[i].second.second = s[j].second.second;
					s[j].second.second = tmp;

				}
			}
			else
			{
				break;
			}
		}
	}

	rep(i, n)
	{
		cout << s[i].second.second+1 << endl;
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

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

int n;

#define MAX 1000000
vector<int> tri;

int dp[MAX];
int odd_dp[MAX];

void gentri()
{
	for (int i = 1;; i++) {
		int t = i*(i+1)*(i+2)/6;
		if (t >= MAX) break;
		tri.push_back(t);
	}
}

int main(void)
{
	gentri();

	dp[0] = 0;
	odd_dp[0] = 0;
	for (int i = 1; i < MAX; i++) {
		dp[i] = i;
		odd_dp[i] = i;
		
		rep(j, tri.size()) {
			int t = i-tri[j];
			if (t < 0) break;
			dp[i] = min(dp[i], dp[t]+1);

			if (tri[j]%2!=0)
				odd_dp[i] = min(odd_dp[i], odd_dp[t]+1);
		}
	}
	
	while(cin >> n, n) {
		cout << dp[n] << " " << odd_dp[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 9028
A, B, K = map(int, input().split())
if A >= K:
  ans_a = A - K
  ans_b = B
elif A < K and A + B >= K:
  K = K - A
  ans_a = 0
  ans_b = B - K
else:
  ans_a = 0
  ans_b = 0
print(str(ans_a) + " " + str(ans_b))

Measured memory_bytes: 9064
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

M, K = lr()

if 2**M <= K or (M == 1 and K == 1):
    print(-1); exit()

if K == 0:
    answer = [x//2 for x in range(2**(M+1))]

else:
    answer = []
    A = [x for x in range(2**M) if x != K]
    answer.extend(A)
    if K != 0:
        answer.append(K)
    answer.extend(A[::-1])
    if K != 0:
        answer.append(K)

print(*answer)


Measured memory_bytes: 19408
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    string S;
    int64_t K;
    cin >> S >> K;
    char so = '1', ans;
    int i = 0;
    while(so == '1'){
        if (S.at(i) == '1'){
            if (i == K - 1){
                ans = S.at(i);
                break;
            }
            else i++;
        }
        else{
            ans = S.at(i);
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
main(){

  int i, j, N, flag, nbuf, nbuf2;
  char copy[37][2], bub[37][2], sel[37][2], str[3], cbuf, cbuf2, mini;

  scanf("%d",&N);

  for(i = 1; i <= N; i++){
    scanf("%s",str);
    copy[i][0] = str[0];
    copy[i][1] = atoi(&str[1]);
    sel[i][0] = str[0];
    sel[i][1] = atoi(&str[1]);
    bub[i][0] = str[0];
    bub[i][1] = atoi(&str[1]);
  }

  for(i = 1; i <= N; i++)
    for(j = N; j > i; j--)
      if(bub[j-1][1] > bub[j][1]){
        nbuf2 = bub[j][0];
        cbuf = bub[j][1];
        bub[j][0] = bub[j-1][0];
        bub[j][1] = bub[j-1][1];
        bub[j-1][0] = nbuf2;
        bub[j-1][1] = cbuf;
      }

  for(i = 1; i < N; i++){
    mini = i;
    for(j = i; j <= N; j++)
      if(sel[j][1] < sel[mini][1])
        mini = j;
     
    if(sel[i][1] > sel[mini][1]){
      nbuf = sel[i][0];
      cbuf2 = sel[i][1];
      sel[i][0] = sel[mini][0];
      sel[i][1] = sel[mini][1];
      sel[mini][0] = nbuf;
      sel[mini][1] = cbuf2;
    }
  }
 
  flag = 1;
  for(i = 1; i < N; i++){
    printf("%c%d ",bub[i][0],bub[i][1]);
    if(flag == 1 && i > 0 && bub[i-1][1] == bub[i][1])
      for(j = 1; j <= N; j++){
    if(copy[j][0] == bub[i-1][0] && bub[i-1][1] == copy[j][1])
          break;
        if(copy[j][1] == bub[i][1] && copy[j][0] == bub[i][0]){
          flag = 0;
      break;
        }
      }
  }

  if(i == N)
    printf("%c%d",bub[i][0],bub[i][1]);
  printf("\n");
  if(flag == 1)
    printf("Stable\n");
  if(flag == 0)
    printf("Not stable\n");

  flag = 1;
  for(i = 1; i < N; i++){
    printf("%c%d ",sel[i][0],sel[i][1]);
    if(flag == 1 && i > 0 && sel[i-1][1] == sel[i][1])
      for(j = 1; j <= N; j++){
        if(copy[j][0] == sel[i-1][0] && sel[i-1][1] == copy[j][1])
          break;
        if(copy[j][1] == sel[i][1] && copy[j][0] == sel[i][0]){
      flag = 0;
      break;
        }
      }
  }

  if(i == N)
    printf("%c%d",sel[i][0],sel[i][1]);
  printf("\n");
  if(flag == 1)
    printf("Stable\n");
  if(flag == 0)
    printf("Not stable\n");

  return 0;
}

Measured memory_bytes: 0
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            //var N = long.Parse(Console.ReadLine());
            //var S = Console.ReadLine();

            var inp = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var a = inp[0];
            var b = inp[1];

            
            if(a < b)
            {
                var ans = new long[b];
                for (int i = 0; i < b; i++)
                {
                    ans[i] = a;
                }
                Console.WriteLine(String.Join("",ans));
            }
            else
            {
                var ans = new long[a];
                for (int i = 0; i < a; i++)
                {
                    ans[i] = b;
                }
                Console.WriteLine(String.Join("", ans));
            }
            
            
        }

    }
}


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

class UnionFind{
    public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> parent;

    //-1で初期化。最初はすべてバラバラ
    UnionFind(int N){
        parent = vector<int>(N,-1);
    }

    //Aがどのグループに属しているか(Aの根)を調べる
    int root(int A){
        if(parent[A] < 0) return A;
        return parent[A]=root(parent[A]);
    }

    //自分のいるグループの頂点数を調べる
    int size(int A){
        return -parent[root(A)];
    }

    //AとBをくっつける
    bool unite(int A, int B) {
    //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        //既にくっついているからくっつけない
        if(A == B) return false; 

        //大きいほう(A)に小さいほう(B)をくっつける
        //大小が逆ならひっくり返す
        if(size(A) < size(B)) swap(A,B);

        //Aのサイズを更新する
        parent[A] += parent[B];
        //Bの親をAに変更する
        parent[B] = A;

        return true;
    }

    //AとBが同じグループならtrueを返す
    bool same(int A, int B){
        return root(A)==root(B);
    } 
};

vector<vector<int>> v(100010);
bool used[100010];

int dfs(int p){
    used[p] = true;
    int x = 0;
    for(auto i:v[p]){
        if(!used[i]){
            x ^= dfs(i) + 1;
        }
    }
    return x;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
 
    int n;
    cin>>n;
    UnionFind uni(n);
    for(int i=1;i<n;i++){
        int a,b; cin>>a>>b;
        a--,b--;
        v[a].push_back(b);
        v[b].push_back(a);
        uni.unite(a,b);
    }
    ll ans = dfs(0);
    cerr << ans << endl;
    for(int i=1;i<n;i++){
        if(!uni.same(0,i) && i==uni.root(i)){
            ans ^= 1;
        }
    }
    cerr << ans << endl;
    if(ans){
        cout << "Alice" << endl;
    }
    else cout << "Bob" << endl;
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
#define int long long
using namespace std;
main(){
  int x;
  cin>>x;
  bitset<32>b(x);
  cout<<b<<endl;
  cout<<(~b)<<endl;
  cout<<(b<<1)<<endl;
  cout<<(b>>1)<<endl;
}


Measured memory_bytes: 3168
#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
using namespace std;

string s;
int n,k;
queue <int> q;
int ans,sum;

int main()
{
    cin>>n>>k>>s;
    int flag=1,cnt_now=0;
    for (size_t i=0;i<s.size();i++)
    {
        if (s[i]-'0'!=flag)
        {
            q.push(cnt_now);
            sum+=cnt_now;
            if (flag) ans=max(ans,sum);
            if (q.size()==2*k+1)
            {
                sum-=q.front();
                q.pop();
            }
            cnt_now=0;
            flag^=1;
        }
        cnt_now++;
    }
    q.push(cnt_now);
    sum+=cnt_now;
    if (flag) ans=max(ans,sum);
    else
    {
        if (q.size()==2*k+1)
        {
            sum-=q.front();
            q.pop();
        }
        ans=max(ans,sum);
    }
    cout<<ans;
    getchar(); getchar();
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  ll a,b;
  cin >> a >> b;
  ll ans = a*b;
  if(a > b) swap(a,b);
  while(b%a!=0) {
    b = b%a;
    swap(a,b);
  }
  ans /= a;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void){
  	char a;
  char b;
  char c;
  char d;
  	for(int i=0;i<6;i++){
  	scanf("%*c%*c%c%c%c%c",&a,&b,&c,&d);
    }
  if((a==b)&&(c==d)){
  	printf("Yes");
  }
  	else{
    	printf("No");
    }
  
}


Measured memory_bytes: 128
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mp make_pair
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

  vector<ll> ans(n);

  ll sum = 0, fugou = 1;
  rep(i, n){
    sum += fugou * v[i];
    fugou *= -1;
  }

  ans[0] = sum;
  reps(i, n - 1){
      ans[i] = 2 * v[i-1] - ans[i-1];
  }

  rep(i, n){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (ll i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (ll i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;

template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (int i = 0; i < v.size(); ++i)
    {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    for (int i = 0; i < v.size() - 1; ++i)
    {
        os << v[i] << " ";
    }
    if (v.size() > 0)
    {
        os << v[v.size() - 1] << endl;
    }
    return os;
}

int main()
{
    int n,m;
    cin >> n >> m;
    string s;
    cin >> s;
    set<int> se;
    REP(i,s.size()){
        if (s[i] == '0'){
            se.emplace(i);
        }
    }
    int now = s.size() - 1;
    vint ans;
    while (now > 0)
    {
        int to = max(now - m, 0);
        auto ite = se.lower_bound(to);
        if (*ite == now)
        {
            ans.emplace_back(-1);
            break;
        }
        else
        {
            ans.emplace_back(now - *ite);
            now = *ite;
        }
    }
    if (ans[ans.size()-1] == -1){
        cout << -1 << endl;
    }else{
        reverse(ans.begin(), ans.end());
        cout << ans;
    }
}

Measured memory_bytes: 5752
#include<iostream>
using namespace std;
int main(){
	int h, w; cin >> h >> w;
	char map[101][101];
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++) {
			cin >> map[i][j];
		}
	for (int i = 0; i < h; i++){
		bool b = false;
		int s = -1;
		for (int j = 0; j < w; j++){
			if (j)cout << ' ';
			if (map[i][j] == 'c') {
				b = true;
				s = j;
			}
			if (!b)cout << "-1";
			else cout << j - s;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3072
list = [100,101,102,103,104,105]
# a = [list[i] * 2000 for i in range(len(list))]

N = int(input())

dp = [0 for i in range(N+1)]
dp[0] = 1

for i in range(N):
    if dp[i] == 1:
        for j in range(len(list)):
            if i + list[j] <= len(dp)-1:
                
                dp[i+list[j]]=1


print(dp[-1])


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


int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}
	vector<double> kitaichi(1001);
	double sum = 0;
	for (int i = 1; i < 1001; i++) {
		sum += i;
		kitaichi[i] = sum / (double)i;
	}
	vector<double> S(n);
	rep(i, n) {
		if (i == 0) S[i] = kitaichi[a[i]];
		else S[i] = S[i - 1] + kitaichi[a[i]];
	}
	double ans = 0;
	for (int i = k - 1; i < n; i++) {
		double t;
		if (i == k - 1) {
			t = S[i];
		}
		else {
			t = S[i] - S[i - k];
		}
		ans = max(ans, t);
	}
	cout <<setprecision(12)<< ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
#define RI register int
using namespace std;
typedef long long LL;
const int N=205;
struct Linear_Basis
{
	LL p[63];
	inline void clear(void)
	{
		for (RI i=0;i<63;++i) p[i]=0;
	}
	inline void insert(LL x)
	{
		for (RI i=62;~i;--i) if ((x>>i)&1)
		{
			if (!p[i]) return (void)(p[i]=x); x^=p[i];
		}
	}
	inline bool exist(LL x)
	{
		for (RI i=62;~i;--i) if ((x^p[i])<x) x^=p[i]; return !x;
	}
}l;
int t,n; LL a[N]; char s[N];
int main()
{
	for (scanf("%d",&t);t;--t)
	{
		RI i; for (scanf("%d",&n),i=1;i<=n;++i) scanf("%lld",&a[i]);
		scanf("%s",s+1); if (s[n]=='1') { puts("1"); continue; }
		bool flag=0; for (l.clear(),i=n;i;--i) if (s[i]=='1')
		{
			if (!l.exist(a[i])) { flag=1; break; }
		} else l.insert(a[i]);
		puts(flag?"1":"0");
	}
	return 0;
}

Measured memory_bytes: 1608
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_10_B
 */
#include <iostream>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

const double PI = 3.1415926535897932;

int
main()
{
    ios::sync_with_stdio(false);
    constexpr int d = numeric_limits<float>::max_digits10;
    
    double a, b;
    int C;
    cin >> a >> b >> C;

    double c = C * PI / 180;
    cout << setprecision(d) << fixed;
    cout << a * b * sin(c) / 2 << endl;
    cout << a + b + sqrt(a * a + b * b - 2 * a * b * cos(c)) << endl;
    cout << b * sin(c) << endl;

    return 0;
}

Measured memory_bytes: 3568
#include <unordered_set>
#include <queue>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>


int main(int argc, char const *argv[]) {
    int H, W;
    std::cin >> H >> W;
    std::vector<std::string> A(H);
    for (int i = 0; i < H; i++) {
        std::string A_row;
        std::cin >> A_row;
        A[i] = A_row;
    }

    std::queue<std::tuple<int, int, int>> black_mass;
    int count = 0;
    std::unordered_set<int> is_checked;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (A[i][j] == '#') {
                std::tuple<int, int, int> tp = std::make_tuple(count, i, j);
                black_mass.push(tp);
            }
        }
    }
    while (!black_mass.empty()) {
        auto tp = black_mass.front();
        int& c = std::get<0>(tp);
        int& i = std::get<1>(tp);
        int& j = std::get<2>(tp);

        int pos = i * W + j;
        if (is_checked.find(pos) != is_checked.end()) {
            black_mass.pop();
            continue;
        } else {
            is_checked.insert(pos);
            count = c;

            if (i >= 1 && is_checked.find((i - 1) * W + j) == is_checked.end()) {
                black_mass.push(std::make_tuple(count + 1, i - 1, j));
            }
            if (j >= 1 && is_checked.find(i * W +  j - 1) == is_checked.end()) {
                black_mass.push(std::make_tuple(count + 1, i, j - 1));
            }
            if (i < H - 1 && is_checked.find((i + 1) * W + j) == is_checked.end()) {
                black_mass.push(std::make_tuple(count + 1, i + 1, j));
            }
            if (j < W - 1 && is_checked.find(i * W + j + 1) == is_checked.end()) {
                black_mass.push(std::make_tuple(count + 1, i, j + 1));
            }
            black_mass.pop();
        }
    }
    std::cout << count << std::endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) cin >> d[i];
  sort(d.begin(), d.end());
  int ans = d[n/2]-d[n/2-1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int n, m;
    cin >> n >> m;
    int mal, mir;
    mir = INT_MAX;
    mal = -1;
    for (int i = 0; i < m; i++)
    {
        int l, r;
        cin >> l >> r;
        mal = max(l, mal);
        mir = min(r, mir);
    }
    if (mal <= mir)
        cout << (mir - mal + 1) << endl;
    else
        cout << 0 << endl;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
h,w=map(int,input().split())
distance=[]
for _ in range(10):
   distance.append(list(map(int,input().split())))

for k in range(10):
   for j in range(10):
      for i in range(10):
         distance[i][j]=min(distance[i][j],distance[i][k]+distance[k][j])

ans=0
for _ in range(h):
   A=list(map(int,input().split()))
   for a in A:
      if a!=-1:
         ans+=distance[a][1]
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
   int r;
   cin >> r;
   if(r>=2800){
       cout<<"AGC"<<endl;
   }else if(r>=1200){
       cout<<"ARC"<<endl;
   }else{
       cout<<"ABC"<<endl;
   }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int index(char c) {
	if(c == 'J') return 2;
	if(c == 'O') return 1;
	else return 0;
}
int main() {
	int n;
	string str;
	cin >> n >> str;
	int dp[1001][1<<3] = {};
	//  I 1
	// O  2
	// OI 3
	//J   4
	//J I 5
	//JO  6
	//JOI 7
	for(int i = 0; i < (1 << 3); i++) {
		if(i & 4 && i & 1 << index(str[0])) {
			dp[0][i] = 1;
		}
	}
	for(int i = 1; i < n; i++) {
		for(int j = 0; j < 1 << 3; j++) {
			if(!(j & 1 << index(str[i]))) continue;
			for(int k = 0; k < 1 << 3; k++) {
				if(!(j & k)) continue;
				dp[i][j] += dp[i-1][k];
				dp[i][j] %= 10007;
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < 1 << 3; i++) {
		ans += dp[n-1][i];
		ans %= 10007;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

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

int n,ans;
int p[100100];

int main(){
    scanf("%d", &n);
    for (int i=0; i<n; i++){
        scanf("%d", &p[i]);
    }
    ans = 0;
    for (int i=0; i<n; i++){
        if (i+1 == p[i]){
            ans++;
            if (i<n-1) swap(p[i], p[i+1]);
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int main() {
    int N; cin >> N;
    vector<vector<int>> adj(N);
    rep(i, N) adj[i].resize(N);
    rep(i, N) { rep(j, N) adj[i][j] = 0; }

    rep(i, N) {
        int u, k; cin >> u >> k; u--;
        rep(j, k) {
            int v; cin >> v; v--;
            adj[u][v] = 1;
        }
    }
    rep(i, N) {
        rep(j, N) {
            cout << adj[i][j] << (j < N-1 ? " " : "");
        }
        cout << endl;
    }
}



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

using namespace std;

typedef long long ll;
typedef pair<int,int> Pair;
typedef pair< ll, int > pli;
const int Nmax = 2e5 + 5, Mod = 1e9 + 7;

vector<int> wA, wB;
vector< ll > dA, dB;

int i, n, x, y, dist, A, B, m;
vector< Pair > v[Nmax];
priority_queue < pli, vector< pli >, greater < pli > > heap;
pair < Pair, int > edge[Nmax];
bool inQueue[Nmax];

void dijk(int node, vector<ll> &d, vector<int> &ways)
{
    d.resize(n+2); ways.resize(n+2);
    for(i=1; i<=n; ++i) d[i] = LLONG_MAX / 4, inQueue[i] = 0, ways[i] = 0;

    d[node] = 0;
    ways[node] = 1;
    heap.push({0, node});
    inQueue[node] = 1;

    while(heap.size())
    {
        node = heap.top().second;
        inQueue[node] = 0;
        heap.pop();

        for(auto e : v[node])
        {
            int to = e.first;
            if(d[to] > d[node] + e.second)
            {
                d[to] = d[node] + e.second;
                if(!inQueue[to]) heap.push({ d[to], to }), inQueue[to] = 1;
            }
        }
    }

    for(i=1; i<=n; ++i) heap.push({ d[i], i });

    while(heap.size())
    {
        node = heap.top().second;
        heap.pop();

        for(auto e : v[node])
            if(d[e.first] == d[node] + e.second)
                ways[e.first] = (ways[e.first] + ways[node]) % Mod;
    }
}

int sq(int x)
{
    return (ll) x * x % Mod;
}

int main()
{
    cin.sync_with_stdio(false);

    cin >> n >> m >> A >> B;
    for(i=1; i<=m; ++i)
    {
        cin >> x >> y >> dist;
        v[x].push_back({y, dist});
        v[y].push_back({x, dist});
        edge[i] = { {x, y}, dist };
    }

    dijk(A, dA, wA);
    dijk(B, dB, wB);

    ll ans = sq(wA[B]);

    for(i=1; i<=n; ++i)
        if(i != A && i != B)
            if(dA[i] + dB[i] == dA[B] && dA[i] == dB[i])
            {
                ans -= sq( (ll) wA[i] * wB[i] % Mod);
                if(ans < 0) ans += Mod;
            }

    for(i=1; i<=m; ++i)
    {
        x = edge[i].first.first;
        y = edge[i].first.second;
        dist = edge[i].second;

        if(dA[x] + dist + dB[y] == dA[B])
        {
            ll start1 = dA[x], finish1 = dA[x] + dist, start2 = dB[y], finish2 = dB[y] + dist;

            if(!(finish1 <= start2 || finish2 <= start1))
            {
                ans -= sq( (ll) wA[x] * wB[y] % Mod );
                if(ans < 0) ans += Mod;
            }
        }

        swap(x, y);

        if(dA[x] + dist + dB[y] == dA[B])
        {
            ll start1 = dA[x], finish1 = dA[x] + dist, start2 = dB[y], finish2 = dB[y] + dist;

            if(!(finish1 <= start2 || finish2 <= start1))
            {
                ans -= sq( (ll) wA[x] * wB[y] % Mod );
                if(ans < 0) ans += Mod;
            }
        }
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 17648
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main(){
    ll N,X,T;
    cin >> N >> X >> T;
    cout << ll(std::ceil(N / double(X))) * T << endl;
}

int main(int argc, char const *argv[])
{
    Main();
    return 0;
}

void yesno(bool state){
    if(state)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    REP(i,N) cin >> A[i];

    auto isok = [&](const int l) {
        int cnt = 0;
        REP(i,N) {
            cnt += A[i] / l-1;
            if (A[i] % l != 0) cnt++;
        }
        return cnt <= K;
    };

    int ok = *max_element(ALL(A)), ng = 0;

    while(ok > ng+1) {
        int mid = (ok + ng) / 2;
        if (isok(mid)) ok = mid;
        else ng = mid;
    }

    OUT(ok)

    return 0;
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

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

	
	if (s.size() < 26) {
		bool f[26] = {};
		REP(i, s.size()) f[s[i]-'a'] = true;
		REP(i, 26) if (!f[i]) { s += 'a' + i; break; }
		cout << s << endl;
	}
	else {
		for (int i = s.size() - 1; i >= 0; i--) {
			char c = '~';
			FOR(j, i + 1, s.size()) if (s[j] > s[i]) chmin(c, s[j]);
			if (c != '~') {
				s[i] = c;
				cout << s.substr(0, i + 1) << endl;
				return 0;
			}
		}
		puts("-1");
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0; i<(int)(n); ++i)
#define REP(i,m,n) for(ll i=(ll)(m); i<(ll)(n); ++i)
#define F first
#define S second
const double PI=acos(-1);
//fixed<<setprecision(11)<<

int main(){
  int a,b,c,d;cin>>a>>b>>c>>d;
  int tmp1=a,tmp2=c;
  while(true){
    tmp2-=b;
    if(tmp2<=0){
      cout<<"Yes"<<endl;
      break;
    }
    tmp1-=d;
    if(tmp1<=0){
      cout<<"No"<<endl;
      break;
    }
  }
return 0;
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double EPS = 1e-8;

int main(){
  int bits[3];
  for(int i=0;i<3;i++){
    scanf("%d",&bits[i]);
  }
  if(bits[0] == 1){
    if(bits[1] == 0){
      //100
      printf("Close\n");
    }
    else if(bits[1] == 1){
      //110
      printf("Open\n");
    }
  }
  else if(bits[0] == 0){
    if(bits[2] == 0){
      //010
      //000
      printf("Close\n");
    }
    else if(bits[2] == 1){
      //001
      printf("Open\n");
    }
  }
}

Measured memory_bytes: 1168