akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 5100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int H,W; cin >> H >> W;
  vector<string> a(H);
  rep(h,H) cin >> a[h];
  int cnt_4 = (H/2)*(W/2);
  int cnt_2,cnt_1;
  if((H*W)%2 == 1) cnt_1 = 1;
  else cnt_1 = 0;
  cnt_2 = (H*W - cnt_4*4 - cnt_1)/2;
  //printf("%d %d %d\n", cnt_4,cnt_2,cnt_1);

  map<char,int> C;
  rep(h,H) rep(w,W) C[a[h][w]]++;
  vi v;
  for(auto c : C) {
    int num = c.second;
    v.pb(num);
  }

  for(auto i : v) {
    while(i-4 >= 0 && cnt_4 > 0){
      i -= 4;
      cnt_4--;
    }
    while(i-2 >= 0 && cnt_2 > 0){
      i -= 2;
      cnt_2--;
    }
    while(i-1 >= 0 && cnt_1 > 0){
      i -= 1;
      cnt_1--;
    }
  }

  if(cnt_1 == 0 && cnt_2 == 0 && cnt_4 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define PI acos(-1)
#define mp make_pair
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sdl(x) scanf("%lld",&x)
#define sd2l(x,y) scanf("%lld%lld",&x,&y)
#define maxn 100010
#define S second
#define ll long long int
#define inf 1000002014
#define infl 1000000000000020000ll
#define mod 100000000
#define sz(x) (int) x.size()
#define pi pair< int,int >
#define pii pair<int,pi>
#define pu push
#define ld long double
#define ull unsigned long long int
#define trace1(x)  cerr << #x << ": " << x << endl
#define trace2(x, y)  cerr << #x << ": " << x << " | " << #y << ": " << y << endl
int arr[maxn];
int main(int argc, char const *argv[])
{
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    int n;
    sd(n);
    ll s1 = n*1ll*(n+1);
    s1/=2;
    ll s2 = 0;
    int fl = 1;
    for (int i = 0; i < n; ++i)
    {
        sd(arr[i]);
        s2+=arr[i];
    }
    if(s2%s1!=0)
    {
        puts("NO");
        return 0;
    }
    else
    {
        ll k = s2/s1;
        for (int i = 0; i < n; ++i)
        {
            int d = arr[(i+1)%n]-arr[i];
            if(k < d || (k-d)%n!=0)
            {
                fl = 0;
                break;
            }
        }
    }
    if (fl)
    {
        puts("YES");
    }
    else
    {
        puts("NO");
    }
    return 0;
}   

Measured memory_bytes: 640
N, A, B = list(map(int, input().split()))
X= list(map(int, input().split()))

I = []
for i in range(N-1):
    I.append(X[i+1]-X[i])

M = X[N-1]-X[0]
I_srt = sorted(I)
I_srt.reverse()

I_sum = [0]
for i in range(N-1):
    I_sum.append(I_srt[i]+I_sum[i])


ans = min([(M-I_sum[i])*A + B*i for i in range(N)])

print(ans)



Measured memory_bytes: 20524
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ll N,D;
    cin>>N>>D;
    
    VEC2(ll,X,N,D);
    REP(i,N){
        REP(j,D){
            cin>>X[i][j];
        }
    }
    
    ll cnt=0;
    REP(i,N-1){
        FOR(j,i+1,N){
            ll t=0;
            REP(k,D){
                t+=(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
            }
            ll tt=sqrt(t);
            if(tt==sqrt(t))cnt++;
        }
    }
    cout<<cnt;
    
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ac = []
for i in range(m):
    a, b = map(int, input().split())
    tmpc = map(int, input().split())
    c = sum(1 << (ci - 1) for ci in tmpc)
    ac.append((a, c))

# 解説AC
dp = [[0] + [pow(10, 9)] * (pow(2, n) - 1)]
for i, (ai, ci) in enumerate(ac, 1):
    dp.append(dp[-1][:])
    for j in range(pow(2, n)):
        tmp = min(dp[i - 1][j | ci], dp[i - 1][j] + ai)
        dp[i][j | ci] = min(tmp, dp[i][j | ci])
print(-1 if dp[-1][-1] == pow(10, 9) else dp[-1][-1])

Measured memory_bytes: 105104
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stdio.h>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if((a==b and a!=c)or(b==c and b!=a)or(c==a and c!=b)){
    cout << "Yes";
  }else{
    cout << "No";
  }
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



// 隣接リストで使う辺を表す型
struct Edge {
	int to, cost;  // 辺の接続先頂点, 辺の重み
	Edge(int to, int cost) : to(to), cost(cost) {}  // コンストラクタ
};

typedef vector<vector<Edge> > AdjList;  // 隣接リストの型
AdjList graph;  // グラフの辺を格納した構造体
				// graph[v][i]は頂点vから出るi番目の辺Edge


vector<int> dist; // 最短距離

// 戻り値がtrueなら負の閉路を含む
bool bellman_ford(int n, int s) { // nは頂点数、sは開始頂点
	dist = vector<int>(n, INF);
	dist[s] = 0; // 開始点の距離は0
	for (int i = 0; i < n; i++) {
		for (int v = 0; v < n; v++) {
			for (int k = 0; k < graph[v].size(); k++) {
				Edge e = graph[v][k];
				if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
					dist[e.to] = dist[v] + e.cost;
					if (i == n - 1) return true; // n回目にも更新があるなら負の閉路が存在
				}
			}
		}
	}
	return false;
}

int main() {
	int n, m, p;
	cin >> n >> m >> p;

	graph = AdjList(n);

	for (int i = 0; i < m; i++) {
		int from, to, cost;
		cin >> from >> to >> cost;
		from--;
		to--;
		cost -= p;
		cost = -cost;
		graph[from].push_back(Edge(to, cost));
	}
	



	bellman_ford(n, 0);

	ll ans = -dist[n - 1];


	for (int i = 0; i < 2*n; i++) {
		for (int v = 0; v < n; v++) {
			for (int k = 0; k < graph[v].size(); k++) {
				Edge e = graph[v][k];
				if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
					dist[e.to] = dist[v] + e.cost;
				}
			}
		}
	}

	if (-dist[n - 1] != ans) {
		cout << -1 << endl;
	}
	else {
		cout << max(0LL, ans) << endl;
	}

	
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#define MAX_N 10

int num[MAX_N];
int dfs(int i,int MaxB,int MaxC);


int main()
{
    int i;
    int n;
    scanf("%d",&n);
    while(n--)
    {
        for(i=0;i<MAX_N;i++)
            scanf("%d",&num[i]);
        if(dfs(0,0,0))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

int dfs(int i,int MaxB,int MaxC)
{
    if(i==MAX_N)
        return 1;
    if(num[i]>MaxB && dfs(i+1,num[i],MaxC))
    {
        return 1;
    }
    if(num[i]>MaxC && dfs(i+1,MaxB,num[i]))
    {
        return 1;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int INF=1e18;

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    int ans=1;
    while(n--)
    {
        int a;
        cin>>a;
        if(a==0)
        {
            ans=0;
            break;
        }
        if(INF/ans/a==0)
            ans=INF+1;
        else
            ans*=a;
    }
    if(ans>INF)
        ans=-1;
    cout<<ans;
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll N,K;
	cin >> N>>K;
	ll arr[N+1] {0};
	while(K--)
	{
		ll d;
		cin >>d;
		while(d--)
		{
			ll temp;
			cin >>temp;
			arr[temp] = 1;
		}
	}
	ll sum = 0;
	for(int i = 1; i<=N;i++)
	{	
		sum += arr[i];
	}
	cout << N-sum <<endl;

}


Measured memory_bytes: 3648
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'

void solve(){
  int n;
  cin >> n;
  map<int,int>m;
  forn(i,n){
    int a;
    cin >> a;
    m[a]++;
    m[a-1]++;
    m[a+1]++;
  }
  int ans = 0;
  for(auto p: m){
    setmax(ans, p.ss);
  }
  cout << ans;
}

int main() {
  ios::sync_with_stdio(false);
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

k (k-1) (k-1)

2 6 3
4 6 5
6 6 7
7 7 7

*/

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

int r,g,b,n,ans,x;

int main(){
    cin>>r>>g>>b>>n;
    x=__gcd(g,b);
    for(int t=n; t>=0; t-=r){
        if(t%x) continue;
        for(int s=t; s>=0; s-=g){
            if(s%b) continue;
            ++ans;
        }
    }
    cout<<ans;
    return 0;
}


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

int main() {
  int n, ans = 100000000, ab=0, aw=0;
  string s;
  cin >> n >> s;
  vector<int> b(n), w(n);
  for(int i = 0; i < n; i++) {
    if(s[i] == '#'){
      ab++;    
    }
    b.at(i) = ab;
  }
  cout << endl;
  for(int i = n-1; i >= 0; i--) {
    if(s[i] == '.'){
      aw++;
    }
    w.at(i) = aw;
  }
  for(int i = 1; i < n; i++) {
    if(s[i] == '#' && s[i-1] == '.') {
      ans = min(ans, b.at(i-1) + w.at(i));
    }
  }
  ans = min(ans, b.at(n-1));
  ans = min(ans, w.at(0));
  cout << ans;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using dijkstra = priority_queue<T, vector<T>, greater<T>>;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fbo find_by_order  // k th index
#define ook order_of_key   // strictly smaller than k
#define PI acos(-1.0)
#define inf 0x3f3f3f3f
#define max_ull 18446744073709551615
#define max_ll 9223372036854775807
#define lead_zero(x) __builtin_clzll(x)
#define trail_zero(x) __builtin_ctzll(x)
#define total_1s(x) __builtin_popcountll(x)
#define first_1(x) __builtin_ffsll(x)
#define log2_(x) __builtin_clz(1) - __builtin_clz(x)
#define isLeap(x) ((x % 400 == 0) || (x % 100 ? x % 4 == 0 : false))
#define QUERY           \
    int test;           \
    scanf("%d", &test); \
    for (int _T = 1; _T <= test; _T++)
#define FAST ios_base::sync_with_stdio(0), cin.tie(0)
#define all(v) v.begin(), v.end()
#define reunique(v) v.resize(std::unique(all(v)) - v.begin())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define ff first
#define ss second
#define MERGE(v1, v2, v) merge(all(v1), all(v2), back_inserter(v))
#define MP make_pair
#define EB emplace_back
#define read freopen("input.txt", "r", stdin)
#define write freopen("output.txt", "w", stdout)
#define in_range(v, r, l) upper_bound(all(v), r) - lower_bound(all(v), l)
#define LCM(a, b) (a / __gcd(a, b)) * b;

ll rdn(int y, int m, int d) {
    /* Rata Die day one is 0001-01-01 */
    if (m < 3)
        y--, m += 12;
    return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
/* Direction arrays */
/*int dx[] = {1,-1,0,0}, dy[] = {0,0,1,-1};                             */  // 4Direction
/*int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1};         */  // 8Direction
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};     */  // KnightDirection
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};                */  // HexagonalDirection
/* int day[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; */
int main() {
    FAST;
    ll k;
    cin>>k;
    ll sum = 0;
    
    for(ll i=1;i<=k;i++){
        for(ll j=1;j<=k;j++){
            for(ll l=1;l<=k;l++){
                ll gcd = __gcd(__gcd(i,j),l);
                sum = sum+gcd;
            }
        }
    }
    cout<<sum<<"\n";
}


Measured memory_bytes: 3624
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

profit = []
for v, c in zip(V, C):
  profit.append(v - c)

#print(profit)
profit.sort(reverse=True)

ans = 0
for p in profit:
  if p > 0:
    ans += p
  else:
    break

print(ans)

Measured memory_bytes: 3064
N = gets.chomp.to_i
str = gets.split
a = Array.new(N) 
for i in 0...N do
    a[i] = str[i].to_i
end
b = 0
c = 0
d = 0
answer = 1
for i in 0...N do
    if a[i] == b
        if a[i] == d
            answer *= 3
            answer %= 1000000007
        elsif a[i] == c
            answer *= 2
            answer %= 1000000007
        end
        b += 1
    elsif a[i] == c
        if a[i] == d
            answer *= 2
            answer %= 1000000007
        end
        c += 1
    elsif a[i] == d
        d += 1
    else 
        puts 0
        exit
    end
end
puts answer

Measured memory_bytes: 8076
#include <iostream>
#include <vector>
#include <chrono>
#include <random>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int last = 0;
	int n;
	std::cin >> n;
	while(n--) {
		int x;
		std::cin >> x;
		if(x < last) {
			std::cout << "No\n";
			return 0;
		}
		last = std::max(last, x - 1);
	}
	std::cout << "Yes\n";
}

Measured memory_bytes: 256
n,m,k = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

a = [0]
b = [0]

for i in range(n):
    a.append(A[i] + a[-1])
for i in range(m):
    b.append(B[i] + b[-1])

best = 0
ans = 0

for i in range(n+1):
    if a[i] > k:
        break
    for j in range(best,m+1):
       min = a[i] + b[j]
       if min > k:
           book = i + j - 1
           ans = max(book,ans)
           best = j - 1
           break

       if j == m:
           book = i + j
           ans = max(book, ans)
           best = j - 1
           break


print(ans)

Measured memory_bytes: 48428
#include<bits/stdc++.h>
using namespace std;
int a[1000005];
int b[10005];
int main()
{
	int n,p;
	cin>>n>>p;
	int k=0;
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n+1;i++)
	{
		b[i]=b[i-1]+a[i-1];
	}
	for(int i=1;i<=n+1;i++)
	{
		if(b[i]<=p)sum++;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  string o,e;
  cin >> o >> e;
  string ans;
  rep(i,0,e.size()){
    ans += o[i];
    ans += e[i];
  }
  if(o.size()-e.size()==1) ans += o[o.size()-1];
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <numeric>
#include <bitset>
#include <math.h>
#include <iomanip>
#include <sstream>

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PI 3.14159265359 //πの値
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define C(x) cout << x << endl //テスト出力

//関数
//nCkの計算の関数(呼び出しは[cbn])
ll cbn(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
// a^n mod を計算する
ll powmod(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}
//２つの最大公約数
int gcb(int a, int b){
    if(a < b){
        int x = a;
        a = b;
        b = x;
    }
    int amari = a % b;
    if(amari == 0) return b;

    return gcb(b, amari);
}
//３つの最大公約数
int gcb_3(int a, int b, int c){
    return gcb(gcb(a, b), c);
}

/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;
vector<vector<要素の型>> 変数名(要素数1, vector<要素の型>(要素数2, 初期値))*/

/*-----------------------------ここから-----------------------------*/

int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string str; cin>>str;
string str_2 = "1",str_3 = "0";
FOR(i,1,str.size()-1) {
  if(str_2[i-1]=='1') {
    str_2+="0";
    str_3+="1";
  }
  else {
    str_2+="1";
    str_3+="0";
  }
}
ll cnt_2 = 0, cnt_3 = 0;
REP(i,str.size()){
  if(str[i]!=str_2[i]) cnt_2++;
  else if(str[i]!=str_3[i]) cnt_3++;
}
cout<<min(cnt_2,cnt_3);
}

Measured memory_bytes: 3924
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#include <set>
#include <stack>
#include <queue>
#include <numeric>
#include <deque>
#include <cstring>
#include <iterator>
#include <map>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <complex>
#include <bitset>
#include <chrono>
#include <random>
#include <assert.h>
#include <array>

using namespace std;

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mn(x) *min_element((x).begin(),(x).end())
#define mx(x) *max_element((x).begin(),(x).end())
//#define sum(x) accumulate((x).begin(),(x).end(),0ll)
#define eb emplace_back
#define el '\n'
typedef  long long  ll;
typedef  unsigned long long  ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

const ld pi=acos(-1);
const ll inf=(ll)1e9+1;
const int mod=1000000007;
//const int mod=998244353;

int n,m,k;
const int N=1e3+10;





int main()
{   ios_base::sync_with_stdio(false);cin.tie(NULL);
    int q,t,u,v,h;
    ll x,a,b,c,d,y,z;
    string ss, tt;
    cin >> ss >> tt;
    n=(int)tt.length();
    auto f = [&](int st){
        ll u=0;
        for(int i=0; i<n; i++){
            u+=(ss[st+i]!=tt[i]);
        }
        return u;
    };
    m=(int)ss.length();
    a=1e9;
    for(int i=0; i<m-n+1; i++){
        a=min(a,f(i));
    }
    cout << a << el;
    return 0;
}







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

int main() {
  int n,m;
  cin>>n>>m;
  pair<int,int> comb[100009];
  for(int i=0;i<m;i++){
    cin>>comb[i].second>>comb[i].first;
  }
  sort(comb,comb+m);
  int cur=0,ans=0;
  for(int i=0;i<m;i++){
    if(comb[i].second<=cur) continue;
    cur=comb[i].first-1;
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int N=1e5+100,INF=1e14;

int a[N];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin>>n;
    int s=0;
    for(int i=0;i<=n;i++)
        cin>>a[i],s+=a[i];
    int ans=0;
    for(int i=0,cur=1;i<=n;i++,cur=min(cur*2,INF))
    {
//        cout<<i<<" -> "<<cur<<" "<<s<<"\n";
        ans+=min(cur,s);
        cur-=a[i];
        s-=a[i];
        if(cur<0)
            cout<<-1,exit(0);
    }
    cout<<ans;
}


Measured memory_bytes: 4432
//sieu nhan
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inp "test.inp"
#define out "test.out"
#define oo 110
#define ii 100100
#define inf 1e15
#define mod 1000000007
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define y1 hungdzno1
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
int f[oo][ii],n,k,res=100000;
main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //freopen(inp,"r",stdin);
  //freopen(out,"w",stdout);
  cin>>n>>k;
  vector<int> w(n),v(n);
  for(int i=0;i<n;++i) cin>>w[i]>>v[i];
  for(int i=0;i<=n;++i) for(int j=0;j<ii;++j) f[i][j]=inf;
  f[0][0]=0;
  for(int i=1;i<=n;++i){
    for(int j=0;j<=100010;++j){
      if(j-v[i-1]>=0) f[i][j]=min(f[i-1][j-v[i-1]]+w[i-1],f[i][j]);
      f[i][j]=min(f[i-1][j],f[i][j]);
    }
  }
  while(f[n][res]>k) --res;
  cout<<res;
}


Measured memory_bytes: 80128
#include <cstdio>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
	int n,nl,nh;
	char c[5],bl[5],bh[5];

	while(scanf("%s",c), (c[0] | c[1] | c[2] | c[3]) != '0'){
		if(c[0] == c[1] && c[0] == c[2] && c[0] == c[3]){
			printf("NA\n");
			continue;
		}
		int tm = 0;
		while(!(c[0] == '6' && c[1] == '1' && c[2] == '7' && c[3] == '4')){
			strcpy(bl,c);
			strcpy(bh,c);
			sort(bl,bl+4);
			sort(bh,bh+4, greater<char>());
			nl = nh = 0;
			for(int i = 0; i < 4; i++){
				nl += (bl[i] - '0') * pow(10,3-i);
				nh += (bh[i] - '0') * pow(10,3-i);
			}
			n = nh - nl;
			for(int i = 0; i < 4; i++){
				c[3-i] = '0' + (n % 10);
				n /= 10;
			}
			tm++;
		}
		printf("%d\n",tm);
	}

	return 0;
}
		

Measured memory_bytes: 3056
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <complex>
using namespace std;

int main()
{
    while (1){
        int n, x;
        cin >> n >> x;
        if (n == 0 && x == 0){
            return 0;
        }

        int c = 0;
        for (int i = 1; i <= n; i++){
            for (int j = i + 1; j <= n; j++){
                for (int k = j + 1; k <= n; k++){
                    if (i + j + k == x){
                        c++;
                    }
                }
            }
        }
        cout << c << endl;
    }
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
typedef long double ld;
using ll=long long;
using namespace std;
const auto mod=1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int x,y,z; cin >> x >> y >> z;
  cout << z << " " <<  x << " " << y << endl; 
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        String input = new Scanner(System.in).nextLine();
        String[] inputs = input.split("\\s+");
        int a = Integer.parseInt(inputs[0]);
        int b = Integer.parseInt(inputs[1]);
        int c = Integer.parseInt(inputs[2]);
        if (a < b & b < c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26128
#include<iostream>
#include<cmath>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int findy(int k){
  return (1+sqrt(1+8*k))/2;
}
int findx(int k,int y){
  return k-y*(y-1)/2;
}

int main(){
  int n,k; cin >>n >>k;
  int cnt=(n-1)*(n-2)/2-k;
  if(cnt<0){
    print("-1");
    return 0;
  } 
  print(n+cnt-1);
  rep(i,n-1){
    print(i+1,n);
  }
  int i=0;
  while(cnt--){
    int y=findy(cnt),x=findx(cnt,y);
    print(x+1,y+1);
  }
}


Measured memory_bytes: 256
N, M = map(int, input().split())
E = [[] for _ in range(N+1)]
E_mat = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
    a, b = map(int, input().split())
    E[a].append(b)
    E[b].append(a)
    E_mat[a][b] = 1
    E_mat[b][a] = 1
E_inv = [[] for _ in range(N+1)]
for v, e_mat in enumerate(E_mat[1:], 1):
    for u, e in enumerate(e_mat[1:], 1):
        if e==0 and v!=u:
            E_inv[v].append(u)
colors = [0] * (N+1)
def dfs(v, c):
    colors[v] = c
    cnts[c] += 1
    for u in E_inv[v]:
        if colors[u] == c:
            print(-1)
            exit()
        if colors[u] != 0:
            continue
        dfs(u, -c)
K = []
for v in range(1, N+1):
    cnts = [0, 0, 0]
    if colors[v] == 0:
        dfs(v, 1)
    K.append(cnts[1:])

dp = 1
for a, b in K:
    dp = dp<<a | dp<<b

dp = bin(dp)[:1:-1]
ans = 0
mi = float("inf")
for i, c in enumerate(dp):
    if c=="1":
        if mi > abs(N/2-i):
            mi = abs(N/2-i)
            ans = i

print(ans*(ans-1)//2 + (N-ans)*(N-ans-1)//2)


Measured memory_bytes: 22364
#include <iostream>
using namespace std;
int main(){
	int a, b;
	cin >> a >> b;
	if(a==1) a=14;
	if(b==1) b=14;

	if(a>b) cout << "Alice" << endl;
	if(a<b) cout << "Bob" << endl;
	if(a==b) cout << "Draw" << endl;

	return 0;
}

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

int main()
{
  long long int n;
  cin >> n;
  vector<long long int> v;
  for(long long int i=0;i<n;i++)
  {
    long long int k;
    cin >> k;
    v.push_back(k);
  }
  sort(v.begin(),v.end());
  double ans=(v[0]+v[1])/2.0;
  for(long long int i=2;i<n;i++)
  {
    ans=(ans+v[i])/2.0;
  }
  printf("%0.5f",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
signed main(){
	int a,b;
	cin>>a>>b;
	if(a<10&&b<=9)cout<<a*b<<endl;
	else puts("-1");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	char ch;
	int cnt[30] = { 0 };

	while (scanf("%c", &ch) != EOF) {
		if ('a' <= ch && ch <= 'z') {
			cnt[ch - 'a']++;
		}
		else if('A' <= ch && ch <= 'Z') {
			cnt[ch - 'A']++;
		}
	}

	for (int i = 0; i < 26;i++) {
		printf("%c : %d\n", i + 'a', cnt[i]);
	}
	return 0;
}




Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s;
  cin>>t;

  if(t.length()<=s.length()){
    cout<<"No";
    return 0;
  }
 string temp = t.substr(0,s.length());
  if(s==temp){
    cout<<"Yes";
  }
  else{
  cout<<"No";
  }
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
template <typename Functor>
struct fix_type
{
    Functor functor;
    template <typename... Args>
    decltype(auto) operator()(Args&&... args) const& { return functor(functor, std::forward<Args>(args)...); }
};
template <typename Functor>
fix_type<typename std::decay<Functor>::type> fix(Functor&& functor) { return {std::forward<Functor>(functor)}; }

struct Graph
{
    Graph(const int n) : edge(n) {}
    void addEdge(const int i, const int j) { edge[i].push_back(j), edge[j].push_back(i); }
    vector<vector<int>> edge;
};

int main()
{
    int N;
    cin >> N;
    Graph g(N);
    vector<int> d(N);
    for (int i = 0; i < N - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        g.addEdge(x, y);
        d[x]++, d[y]++;
    }
    string c;
    cin >> c;
    int w = 0;
    for (const char ch : c) { w += ch == 'W' ? 1 : 0; }
    if (w <= 1) {
        cout << w << endl;
        return 0;
    }
    int root = 0;
    for (; c[root] == 'B'; root++) {}
    auto rec1 = fix([&](auto&& self, const int s, const int prev) -> bool {
        for (const int to : g.edge[s]) {
            if (to == prev) { continue; }
            if (self(self, to, s)) { d[s]--, d[to]--; }
        }
        return d[s] == 1 and c[s] == 'B';
    });
    rec1(root, -1);
    int ans = 0;
    vector<int> score(N);
    for (int i = 0; i < N; i++) {
        if (d[i] == 0) { continue; }
        ans += d[i] % 2 == (c[i] == 'W') ? d[i] : d[i] + 1;
        score[i] = d[i] % 2 == (c[i] == 'W') ? 0 : 2;
    }

    vector<int> sum(N, 0);
    auto rec2 = fix([&](auto&& self, const int s, const int prev) -> void {
        if (d[s] == 0) { return; }
        sum[s] = (prev == -1 ? 0 : sum[prev]) + score[s];
        for (const int to : g.edge[s]) {
            if (to == prev) { continue; }
            self(self, to, s);
        }
    });
    rec2(root, -1);
    root = max_element(sum.begin(), sum.end()) - sum.begin();
    fill(sum.begin(), sum.end(), 0);
    rec2(root, -1);
    const int minus = *max_element(sum.begin(), sum.end());
    cout << ans - minus << endl;

    return 0;
}


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

int main(void){
	ll n,m;
	cin>>n>>m;
	ll a[n];
	vector<pair<ll,ll>>ans;
	for(int i=0;i<n;i++){
		cin>>a[i];
		ans.push_back(make_pair(a[i],1LL));
	}
	ll b[m],c[m];
	for(ll i=0;i<m;i++){
		cin>>b[i]>>c[i];
		ans.push_back(make_pair(c[i],b[i]));
	}
	sort(ans.begin(),ans.end(),greater<pair<ll,ll>>());
	ll res =0;ll num=0;
	for(ll i=0;i<m+n+10;i++){
		res += ans[i].first * ans[i].second;
		num += ans[i].second;
		//n -= ans[i].second;
		/*if(n<=0){
			if(n<0){
				res+=ans[i].first*n;
			}
			break;
		}*/
		if(num==n){
			break;
		}else if(num>n){
			res -= ans[i].first*(num-n);
			break;
		}
	}
	cout<<res<<endl;
}


Measured memory_bytes: 7664
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#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(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;

const long long TIME_LIMIT=10000;

ll scorecalc(vector<vector<ll>> a, vector<ll> los, ll d, vector<ll> an)
{
    ll ans = 0;
    
    vector<ll> last(los.size(), 0);
    for (int i = 0; i < an.size(); i++)
    {
        ll loss = 0;
        for (int j = 0; j < 26; j++)
        {
            if (j == an[i] - 1)
                continue;

            loss += los[j] * (i+1LL - last[j]);
        }
        ans += a[i][an[i] - 1] - loss;
        last[an[i] - 1] = i + 1LL;
    }

    return ans;
}

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

    ll d;
    cin >> d;
    vector<ll> c(26);
    rep(i, 26)
    {
        cin >> c[i];
    }
    vector<vector<ll>> s(d, vector<ll>(26));
    rep(i, d)
    {
        rep(j, 26)
            cin >> s[i][j];
    }

    vector<ll> ans(d);

    vector<ll> last(26, 0);

    for (ll i = 0; i < d; i++)
    {
        ll lost = 0;
        for (int j = 0;j < 26; j++)
        {
            lost += c[j] * (i + 1 - last[j]);
        }
        ll man = s[i][0]-lost+c[0]*(i+1-last[0]);
        ll manu = 1;
        for (int j = 0; j < 26; j++)
        {
            if (man <= s[i][j]-lost+c[j]*(i+1-last[j]))
            {
                man = s[i][j] - lost + c[j] * (i + 1 - last[j]);
                manu = j + 1LL;
                last[j] = i + 1;
            }
        }
        ans[i] = manu;
    }
    ll score = scorecalc(s, c, d, ans);
    ll times = 0;
    while (times < 10000)
    {
        vector<ll> tmpD(10);
        rep(j, 10)
        {
            tmpD[j] = (ll)rand() % d;
        }
        vector<ll> tmpN(10);
        rep(j, 10)
        {
            tmpN[j] = ans[tmpD[j]];
            ans[tmpD[j]] = (ll)rand() % 26 + 1;
        }

        if (score >= scorecalc(s, c, d, ans))
        {
            rep(j, 10)
                ans[tmpD[j]] = tmpN[j];
        }
        else
            score = scorecalc(s, c, d, ans);

        times++;
    }

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

	return 0;

}

Measured memory_bytes: 3848
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <string>
# include <iostream>
using namespace std;
int main()
{
	string a;
	cin>>a;
	string a1=a;
	reverse(a.begin(),a.end());
	for(int i=0;i<a.size();i++)
	{
		if(a[i]=='q') a[i]='p';
		else if(a[i]=='p') a[i]='q';
		else if(a[i]=='b') a[i]='d';
		else if(a[i]=='d') a[i]='b';
	}
	if(a==a1) printf("Yes\n");
	else printf("No\n");
	return 0;
}
//xiulv

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<cassert>
using namespace std;
int inf = 1000000000;


int main(void) {
  int a;
  cin >> a;
  string n;
  for(int i=0; i<a; i++){
    cin >> n;
    if( a == 0 ) break;
    sort(n.begin(), n.end());
    int x = 0;
    int y = 0;
    int c = 1;
    for(int i=0; i<8; i++){
      x += c * (n[i]-'0');
      y += c * (n[7-i]-'0');
      c *= 10;
    }
    cout << x-y << endl;

  }


  return 0;
}


// EOF

Measured memory_bytes: 3200
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <queue>
#include <cctype>
#include <stack>
#include <bitset>
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <iomanip>
//#include <bits/stdc++.h>


#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define IFOR(i,a,b) for(int i=(a);i>=(b);--i)

using namespace std;

typedef long long lolo;
typedef pair<int, int> pii;
typedef unsigned long long ulolo;

const int maxn = 100000 + 5;
const int maxm = 300005;
const int INF = 0x3f3f3f3f;
const lolo inf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const int MOD = (int)1e9+9;

template<class T>
inline void read(T &x) {
    x = 0; T flag = 1;char c;
    do { c = (char) getchar(); if (c == '-') break; } while (c < '0' || c > '9');
    if (c == '-') c = '0', flag = -1;
    do { x = x * 10 + c - '0';c = (char) getchar();} while (c >= '0' && c <= '9');
    x *= flag;
}
template<class T>
inline void out(T x) {
    if (x > 9) out(x / 10);
    x = x % 10;
    putchar('0' + x);
}

int main(){
//    freopen("../in.txt","r",stdin);
    int n;
    read(n);
    out(n/3);
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>

using namespace std;

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

int main()
{
	int N, M, K;
	scanf("%d%d%d", &N, &M, &K);
	for(int i = 0; i <= N; i++){
		for(int j = 0; j <= M; j++){
			if( i*j + (N-i)*(M-j) == K ) return !printf("Yes\n");
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);
int main() {
  int n;
  cin >> n;
  vector<vector<ll>> a(n, vector<ll>(n));
  ll res = 0;
  rep(i,n) rep(j,n) cin >> a[i][j], res += a[i][j];
  res /= 2;
  auto d = a;
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
  }
  vector<vector<bool>> ok(n, vector<bool>(n, false));
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {

        if (d[i][j] != a[i][j]) {
          cout << -1 << endl;
          return 0;
        }
        if (i == j || j == k || k == i) continue;
        if (d[i][j] == d[i][k] + d[k][j] && !ok[i][j]) {
          ok[i][j] = true;
          res -= d[i][j];
        }

      }
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,k;
	cin >> n >> k;
	cout << (n - 2) / (k - 1) + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int cnt = 0;
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    a--;
    if(i != a) cnt++;
  }
  if(cnt <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h> 
    using namespace std;
     
     
     int main() {
     int N, K;
       string S;
       cin >> N >> S >> K;
       
     for (int i = 0; i < N; i++) {
         if(S.at(i) != S.at(K - 1)) {
           S.at(i) = '*';
         }
       }
       cout << S << endl;
     }
       
      

Measured memory_bytes: 256
#include "bits/stdc++.h"
#pragma optimize("unroll-loops");
#pragma optimize("Ofast");
//#include "pch.h"    
using namespace std;
unordered_map<int, bool> here;
 
using ll = long long;
const int nax = 1e5 + 10;
vector<int> edges[nax];

int main() {
    
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll& x : a) {
        cin >> x;
    }
    
    ll answer = 0;
    
    unordered_map<ll, ll> here1, here2;
    for(int i = 0; i < n; ++i) {
        if(here1.count(i - a[i])) {
            here1[i - a[i]]++;
        }else{
            here1[i - a[i]] = 1;
        }
        
        if(here2.count(i + a[i])) {
            here2[i + a[i]]++;
        }else{
            here2[i + a[i]] = 1;
        }
    }
    
    for(int i = 0; i < n; ++i) {
        ll pos = i - a[i];
        if(here2.count(pos)) {
            
            answer += (here1[pos] * here2[pos]);
            here1[pos] = here2[pos] = 0;
            if(a[i] == 0) {
                --answer;
            }
        }
    }
    
    cout << answer << "\n";
}


Measured memory_bytes: 22556
n,a,b = map(int,input().split())
mod = 10 ** 9 + 7

def comb(n, k):
    res = 1
    for i in range(n - k + 1, n + 1):
        res = res * i % mod
    for i in range(1, k + 1):
        res = res * pow(i, mod - 2, mod) % mod
    return res

sum = pow(2, n,mod) - 1
print((sum - comb(n,a) - comb(n,b)) % mod)


Measured memory_bytes: 38768
#include <iostream>
using namespace std;
int main()
{
    int H,N,twice=0;
    cin>>H>>N;
    int arr[N];
    for(int i=0;i<N;i++){
        cin>>arr[i];
    }
    while(H!=0){
        for(int i=0;i<N;i++){
                H-=arr[i];
            }
            twice++;

        if(H<0){
            break;
        }

    }
    if(twice>1){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
    return 0;
}


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

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

    vector<int> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    int min = 1e9;
    int ans = 1e9;
    for (int i = 0; i < n-k+1; i++) {
        int l = abs(x[i]);
        int r = abs(x[i+k-1]);
        if (l > r) min = r;
        else min = l;
        min += (x[i+k-1] - x[i]);

        if (ans > min) ans = min;
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
S = input()




def check_step(S):
   for i in range(len(S)):
      if (i+1)%2==1:
         if S[i]=="L" :
            print("No")
            return 
      else:
         if S[i]=="R" :
            print("No")
            return 
   print("Yes")
check_step(S)  

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
"""
Created on Fri May 17 00:23:37 2019

@author: avina
"""

s1 = input().strip()
s2 = input().strip()
F = True
d = {}
s = {}
for i in range(len(s1)):
  if s2[i] not in s:
     s[s2[i]] = s1[i]
  elif s[s2[i]] != s1[i]:
      F = False
      break
for i in range(len(s1)):
  if s1[i] not in d:
     d[s1[i]] = s2[i]
  elif d[s1[i]] != s2[i]:
      F = False
      break

if F:
   print('Yes')
else:
   print('No')

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
int cnt[59][50];

int main(){
  int n;
  string ans="";
  cin>>n;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    for(int j=0;j<s.size();j++){
      cnt[i][s[j]-'a']++;
    }
  }
  for(int i=0;i<27;i++){
    int t=INF;
    for(int j=0;j<n;j++){
      t=min(t,cnt[j][i]);
    }
    for(int j=0;j<t;j++){
      ans+=(char)('a'+i);
    }
  }

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

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


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var nextString func() string

func init() {
	nextString = newReadString(os.Stdin)
}

func main() {
	s := nextString()

	cnt := len(s)
	cnt -= calc(s, 'A')

	s = reversed(s)
	cnt -= calc(s, 'Z')
	fmt.Println(cnt)
}

func reversed(s string) string {
	r := make([]rune, len(s))
	j := 0
	for i := len(s) - 1; i >= 0; i-- {
		r[j] = rune(s[i])
		j++
	}
	return string(r)
}

func calc(s string, c rune) (cnt int) {
	for i := 0; rune(s[i]) != c && cnt < len(s); i++ {
		cnt++
	}
	return cnt
}

func nextInt() (result int) {
	result, _ = strconv.Atoi(nextString())
	return
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
		}
		return r.Text()
	}
}


Measured memory_bytes: 2304
#include<iostream>
#include<string>

using namespace std;

int main(void){

    string str;

    cin >> str;

    for(int i = 0;str[i] != '\0';i++){
        if(str[i] == '1') cout << '9';
        else if(str[i] == '9') cout << '1';
        else cout << str[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256