akhauriyash/Code-Regression huggingface dataset:
from math import ceil,floor,log
#from decimal import Decimal,ROUND_CEILING,ROUND_FLOOR,getcontext
from heapq import *
import sys
input=sys.stdin.readline
T=int(input())
cases=[list(map(int,input().split())) for _ in range(T)]
#getcontext().prec=20
num=0
cnt=0
def main():
    for i in cases:
        l2=[0]*3
        N,l2[0],l2[1],l2[2],D=i
        d = {}
        num=0
        cnt=0
        for j in range(60):         #2の累乗
            for k in range(38):     #3の累乗
                for l in range(26): #5の累乗
                    div=pow(2,j)*pow(3,k)*pow(5,l)
                    x=N//div
                    #x=Decimal(N)/Decimal(div)
                    if N%div!=0:
                        c=x+1
                    else:
                        c=x
                    f=x
                    if d.get(c)==None:
                        d[c]=float("inf")
                    if d.get(f)==None:
                        d[f]=float("inf")
        d[N]=0
        #print(d)
        q=[]
        q.append((0,N))
        heapify(q)
        #print(d)
        while True:
            dist,u=heappop(q)
            if d[u]<dist: continue
            if u==0:
                print(dist)
                break
            for j in range(3):
                num=1+pow(2,j)
                cnt=l2[j]
                x =u//num
                if u%num!=0:
                    v1 = x+1
                else:
                    v1 = x
                v2 = x
                # v1=ceil(u/2)
                # v2=floor(u/2)
                alt1 = d[u] + min(cnt+((num-(u%num))%num)*D,(u-v1)*D)
                alt2 = d[u] + min(cnt+(u%num)*D,(u-v2)*D)
                if d[v1] > alt1:
                    d[v1] = alt1
                    heappush(q, (alt1, v1))
                if d[v2] > alt2:
                    d[v2] = alt2
                    heappush(q, (alt2, v2))
            #print(d)
            #input()
        #print(d[0])
        #print(len(d))
if __name__ == '__main__':
    main()

Measured memory_bytes: 83836
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;

const int MAX_N = 200010;

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

	int n, m, q;
	cin >> n >> m >> q;

	int a[MAX_N];
	for(int i = 0; i < m; ++i){
		cin >> a[i];
	}

	list<int> l;
	for(int i = 0; i < n; ++i){
		l.push_back(i);
	}

	list<int>::iterator it = l.begin();

	int v[MAX_N];
	fill(v, v + n, 1);
	for(int i = 0; i < m; ++i){
		if(a[i] % 2 == 0){
			for(int j = 0; j < a[i]; ++j){
				it++;
				if(it == l.end()){
					it = l.begin();
				}
			}
		}
		else {
			for(int j = 0; j < a[i]; ++j){
				if(it == l.begin()){
					it = l.end();
				}
				it--;
			}
		}

		v[*it] = 0;
		it = l.erase(it);
		if(it == l.end()){
			it = l.begin();
		}
	}

	for(int i = 0; i < q; ++i){
		int b;
		cin >> b;
		cout << v[b] << endl;
	}

	return 0;
}

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



int main(){
    ll n;cin>>n;
    if(n%2==0||n%5==0){
        cout<<-1<<endl;
        return 0;
    }
    ll sev=7;
    rep(i,1,1000000){
        if(sev%n==0){
            cout<<i<<endl;
            return 0;
        }
        else{
            sev=sev*10+7;
            sev%=n;
        }
    }
}

    









Measured memory_bytes: 3632
#define _USE_MATH_DEFINES 
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <math.h>
#include <unordered_set>
#include <iomanip>
#include <cmath>
#include <set>
#include <locale>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
ll Lgcd(ll a, ll b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
ll Llcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
using Graph = vector<vector<int>>;
//cout << fixed << setprecision(6);
//cout << setfill('0') << right << setw(2);

ll memo[100100];

ll dfs(int n) {
	if (memo[n] != -1) return memo[n];
	return memo[n] = dfs(n - 1) % MOD + dfs(n - 2) % MOD;
}

int main() {
	int n, m, a;
	cin >> n >> m;
	rep(i, 100100) memo[i] = -1;
	memo[0] = 1; memo[1] = 1;
	rep(i, m) {
		cin >> a;
		memo[a] = 0;
	}
	cout << dfs(n) % MOD<< endl;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;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 llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
int n,k,x,y;
cin>>n>>k>>x>>y;
if(n<=k) cout<<n*x<<endl;
else cout<<k*x+(n-k)*y<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const ll inf =1e9;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    int n; cin >> n;
    vector<str> s(n);
    vector<int> t(n);
    int ans = 0;
    for(int i=0; i<n; i++){
        cin >> s[i] >> t[i];
        ans += t[i];
    }
    str x; cin >> x;
    for(int i=0; i<n; i++){
        if(x != s[i]){
            ans -= t[i];
        }else{
            ans -= t[i];
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int n,k,i,cnt=0;
  scanf("%d %d",&n,&k);
  int num[n];
  for(i=0;i<n;i++){
    scanf("%d",&num[i]);
    if(num[i]>=k){
      cnt++;
    }
  }
  printf("%d",cnt);
  return 0;
}
  

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;


int main(){
  int N;
  cin >> N;
  long long A[N],B[N];
  for(int i=0;i<N;i++){
  B[i]=0;
}
for(int i=0;i<N;i++){
  cin >> A[i];
  B[A[i]-1]++;
}
long long times=0;
  for(int k=0;k<N;k++){
    times+=(B[k]*(B[k]-1))/2;}
  for(int j=0;j<N;j++){
    cout << times-B[A[j]-1]+1 << endl;
  }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N + 1);
  a[0] = 0;
  rep(i, 0, N) cin >> a[i + 1];

  int current = a[1], cnt = 1;
  rep(i, 2, N + 1) {
    if (current == 2) {
      cout << cnt << endl;
      return 0;
    }
    current = a[current];
    cnt++;
  }

  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int H,W;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
int d[55][55];
const int dsup=1<<20;
typedef pair<int,int> P;
vector<string> maze(55);

void bfs(){
    FOR(i,0,H)FOR(j,0,W)d[i][j]=dsup;
    queue<P> que;
    d[0][0]=0;
    que.push(P(0,0));
    while(!que.empty()){
        int x=que.front().first;
        int y=que.front().second;
        que.pop();
        FOR(i,0,4){
            int nx=x+dx[i];
            int ny=y+dy[i];
            if(0<=nx&&nx<H&&0<=ny&&ny<W&&d[nx][ny]==dsup&&maze[nx][ny]!='#'){
                d[nx][ny]=d[x][y]+1;
                que.push(P(nx,ny));
            }
        }
    }
    return;
}

int main(){
    cin>>H>>W;
    FOR(i,0,H)cin>>maze[i];
    bfs();
    int bl=0;
    FOR(i,0,H){
        FOR(j,0,W){
            if (maze[i][j]=='#')bl++;
        }
    }
    if(d[H-1][W-1]==dsup)cout<<-1<<endl;
    else cout << H*W-bl-d[H-1][W-1]-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

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

using namespace std;

int main() {
	long long x;
	cin >> x;

	long long n = 0;
	n = x / 11;
	n *= 2;

	x %= 11;
	
	if (0 < x && x <= 6) {
		n += 1;
	}
	else if (7 <= x) {
		n += 2;
	}

	cout << n << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define NUM 100000

int main(){
  int h,n,a[NUM],sum = 0;
  
  scanf("%d",&h);
  scanf("%d",&n);

  for(int i = 0;i < n;i++){
    scanf("%d",&a[i]);
    sum += a[i];
  }

  if(sum >= h){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int,int>;
using ll = long long;


int main() {
    int n;
    cin >> n;
    set<string> st;
    string s;
    rep(i,n){
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
}

Measured memory_bytes: 19108
/* In the name of Allah */

#include <bits/stdc++.h>
using namespace std;

// const int INF = 20000000;

#define ll long long
#define _SetBit(A, k) (A[(k / 32)] |= (1 << (k % 32)))
#define _ClearBit(A, k) (A[(k / 32)] &= ~(1 << (k % 32)))
#define _CheckBit(A, k) (A[(k / 32)] & (1 << (k % 32)))
#define SetBit(x, k) (x |= (1 << k))
#define ClearBit(x, k) (x &= ~(1 << k))
#define CheckBit(x, k) (x & (1 << k))

int main()
{
  int k, n;
  cin >> k >> n;
  int prev;
  cin >> prev;
  int tmp = prev;
  int mx = 0;
  for (int i = 1; i < n; i++)
  {
    int x;
    cin >> x;
    mx = max(x - prev, mx);
    prev = x;
  }
  mx = max(mx, tmp + k - prev);

  cout << (k - mx) << "\n";

  return 0;
}

Measured memory_bytes: 256
n,k = gets.chomp.split(' ').map{|l| l.to_i}
ans = 0
ab = Array.new
cnt = 0
n.times do |i| 
  ab << gets.split(' ').map{|x| x.to_i}
end

ab.sort.each do |a,b|
  cnt += b
  if cnt >= k
    ans = a
    break
  end
end

p ans

Measured memory_bytes: 11152
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    if (abs(x-a) < abs(x-b))cout << "A" << endl;
    else cout << "B" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i,j;
	int n;

	while(1){
		scanf("%d",&n);
		
		if(n==0) break;
		
		
		int a[12][12]={0};
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%d",&a[i][j]);
				a[n][n]+=a[i][j];
				a[i][n]+=a[i][j];
			}
		}
	
		for(j=0;j<n;j++){
			for(i=0;i<n;i++){
				a[n][j]+=a[i][j];
			}
		}
	
		for(i=0;i<=n;i++){
			for(j=0;j<=n;j++){
				printf("%5d",a[i][j]);
			}
			printf("\n");
		}
	}
	
	return 0;
}

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

#define all(x)        (x).begin(),(x).end()
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int,int>
#define vi            vector<int>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
const int N = 2e5 + 1;
const int lg = 20;
const ll mod = 0xfffff;


void solve() {
  int k; cin >> k;
  int n; cin >> n;
  vi a(n);
  rep(i, 0, n)
    cin >> a[i];
  int ans = k;
  rep(i, 0, n) {
    int j = (i + 1) % n;
    int x = a[i];
    int y = a[j];
    int del = y - x;
    if (i == n - 1) {
      del = k - x + y;
    }
    ans = min(ans, k - del); 
  }
  cout << ans << "\n";
}

int main() {
  // freopen("input.in", "r", stdin);
  // freopen("input.out", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// cout<<setprecision(15);
	// int t; cin>>t; while(t--)
	solve();
	return 0;
}



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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

int n;
vector<int> a(100010), b(100010);
vector<int> ans(100010);           // 何番目の辺を何色で塗ったか
vector<pair<int, int>> g[100010];  // 行き先、何番目の辺か
int color = 0;                     // 何色使ったか

void dfs(int now, int pc) {  // pc…親への辺の色
  int c = 1;
  for (auto p : g[now]) {
    if (ans[p.second] == 0) {  // 塗られていないなら
      if (c == pc) c++;
      ans[p.second] = c;  // 色を塗る
      color = max(color, c);
      dfs(p.first, c);
      c++;
    }
  }
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  cout << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  cout << "}";
  return os;
}

// ====================================================================

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

  dfs(0, -1);
  cout << color << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 8448
def li():
    return list(map(int, input().split()))


def mi():
    return map(int, input().split())


def ii():
    return int(input())


N = ii()
a = li()

a.sort(reverse=True)

alice = 0
bob = 0

for i in range(len(a)):
    if i % 2 == 0:
        alice += a[i]
    else:
        bob += a[i]

print(alice - bob)


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


int main(){
	int K,S;
	cin >> K >> S;
	int answer=0;
	for(int i=0;i<=K;i++){
		for(int j=0;j<=K;j++){
			if(S-(j+i)>=0 && K>=S-(j+i)){
				answer++;
			}
		}
	}
	cout << answer << endl;
	return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;

int main(){
	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;
	int d=(H2-H1)*60+(M2-M1);
	cout << d-K << endl;

	return 0;
}

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

#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define endl '\n'
// #define int long long

typedef pair<int,int> pii;
const int N = 1e2+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n, k;
vector<pii> edges;

int32_t main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> n >> k;
	int mx = (n-1)*(n-2)/2;
	if (k > mx) return 0*puts("-1");
	for(int v = 2; v <= n; v++) edges.push_back({1, v});
	int sub = mx - k;
	for(int i=2; i<=n && sub; i++){
		for(int j=i+1; j<=n && sub; j++){
			edges.push_back({i, j});
			sub--;
		}
	}
	cout << edges.size() << endl;
	for(auto &e:edges) cout << e.st << ' ' << e.nd << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
ll dp[100005];
int main()
{
	ll n,i,j,k;
	cin>>n>>k;
	ll h[n+1];
	for(i=1;i<=n;i++)
		cin>>h[i];
	dp[2] = abs(h[2] - h[1]);
	dp[1] = 0;
	for(i=3;i<=n;i++)
		for(j=1;j<=k && j<i;j++)
		{
			if(j == 1)
				dp[i] = dp[i-1]+abs(h[i]-h[i-1]);
			else
				dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
			// cout<<i<<" "<<dp[i]<<endl;
		}
	cout<<dp[n]<<endl;
	return 0;
}

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

struct pos{
	int x;
	int y;
	int dis;
};

int main(){
	int w, h;
	while(cin >> w >> h){
		if(w == 0 || h == 0) break;
		int map[65][65];
		for(int i = 0; i < 65; i++){
			for(int j = 0; j < 65; j++){
				map[j][i] = 1;
			}
		}

		for(int i = 1; i <= h; i++){
			for(int j = 1; j <= w; j++){
				map[i*2-1][j*2-1] = 0;
			}
		}

		int l = 1;
		for(int i = 1; i <= h*2-1; i++){
			if(i % 2 == 1){	
				for(int j = 1; j <= w-1; j++){
					int input;
					cin >> input;
					map[l*2-1][j*2] = input;
				}
			}else{
				for(int j = 1; j <= w; j++){
					int input;
					cin >> input;
					map[l*2][j*2-1] = input;
				}
				l++;
			}
		}

		queue<pos> q;
		map[1][1] = 1;
		pos p;
		p.x = 1;
		p.y = 1;
		p.dis = 1;
		q.push(p);
		int x1[] = {-1, 0, 1, 0}, y1[] = {0, -1, 0, 1};
		while(!q.empty()){
			p = q.front();
			q.pop();
			for(int i = 0; i < 4; i++){
				pos p1 = p;
				p1.x += x1[i]; p1.y += y1[i];
				if(!map[p1.x][p1.y]){
					//p1.x += x1[i]; p1.y += y1[i];
					p1.dis++;
					map[p1.x][p1.y] = p1.dis;
					q.push(p1);
				}
 			}
		}

		int ans = (map[h*2-1][w*2-1] + 1) /2;

		cout << ans << endl;

	}
}

Measured memory_bytes: 1232
#include<iostream>
using namespace std;
 
int main(){
  int x,y,z;

  cin >> x >> y >> z;

  if(x<y && y<z && x<z){
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;		 
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define INFI 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define mem0(x) memset(x,0,sizeof(x))
#define prln(x) cout<<#x<<"="<<x<<endl;
#define R freopen("A.in","r",stdin);
///////////////////////////
int n;
const int maxn=110;
int g[maxn][maxn];
int link[maxn],a[maxn],b[maxn],c[maxn],d[maxn];
bool used[maxn];
bool dfs(int u) //从左边开始找增广路径
{
    int v;
    for(v=0; v<n; v++) //这个顶点编号从0开始，若要从1开始需要修改
        if(g[u][v]&&!used[v])
        {
            used[v]=true;
            if(link[v]==-1||dfs(link[v]))
            {
                //找增广路，反向
                link[v]=u;
                return true;
            }
        }
    return false;
}

int hungary()
{
    int res=0;
    int u;
    memset(link,-1,sizeof(link));
    for(u=0; u<n; u++)
    {
        memset(used,0,sizeof(used));
        if(dfs(u)) res++;
    }
    return res;
}
int main()
{
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>a[i]>>b[i];
    }
    for(int i=0; i<n; i++)
    {
        cin>>c[i]>>d[i];
    }
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            if(a[i]<c[j]&&b[i]<d[j])g[i][j]=1;
        }
    }

cout<<hungary();





    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <bits/stdc++.h>
using namespace std;

class AABCSwap {
 public:
  void solve(std::istream &in, std::ostream &out) {
      int a, b, c;
      in >> a >> b >> c;
      swap(a, b);
      swap(a, c);
      out << a << ' ' << b << ' ' << c << '\n';

  }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    AABCSwap solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll func(int a,int b)
{
    ll res=1;
    while(b>0)
    {
        if(b%2!=0)
        {
            res*=a;
        }
        b/=2;
        a*=a;
    }
    return res;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    ll ans=k*func(k-1,n-1);
    cout<<ans;
  	return 0;
}







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


int main() {
    int N; cin >> N;
    vector<int> V(N-1);
    for(int i=0;i<N-1;i++){
        cin >> V.at(i);
    }
    vector<int> ans(N+1);

    for(int i=0;i<N-1;i++){
        ans.at(V.at(i))++;
    }
    
    for(int i=1;i<=N;i++){
        cout << ans.at(i) << endl;
    }

}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VL x(n), y(n), h(n);
  vector<tuple<ll, ll, ll>> c;
  rep(i, n) {
    cin >> x[i] >> y[i] >> h[i];
    if(h[i] >= 1) c.emplace_back(x[i], y[i], h[i]);
  }
  tuple<ll, ll, ll> ans;
  rep(i, 101) rep(j, 101) {
    ll hh = get<2>(c[0]) + abs(get<0>(c[0]) - i) + abs(get<1>(c[0]) - j);
    bool flag = true;
    rep(k, c.size()) {
      if(hh != get<2>(c[k]) + abs(get<0>(c[k]) - i) + abs(get<1>(c[k]) - j)) {
        flag = false;
      }
    }
    if(flag) {
      ans = make_tuple(i, j, hh);
      break;
    }
  }

  if(c.size() > 1) cout << get<0>(ans) << " " << get<1>(ans) << " " << get<2>(ans) << endl;
  else cout << get<0>(c[0]) << " " << get<1>(c[0]) << " " << get<2>(c[0]) << endl;
  return 0;
}


Measured memory_bytes: 256
//初めてのBIT(本当
//テストケース28でWAする。(最適解より大きい値が出る)
#include<iostream>
#include<vector>
#include<stdlib.h>
#define int long long
using namespace std;

struct Bug{
	int a, b;
}bug[300001];
int n;
int a,b;
vector<int> uofB[100002];

signed compare(const void *s1, const void *s2){
	return ((Bug*)s1)->a - ((Bug*)s2)->a;
}

class BIT{
public:
	int bit[600000];	//bit[i] = …
	BIT(){
		for (int i = 0; i <= 500000; i++ ) bit[i] = 0;
	}
	void add(int a, int w){
		for (int x = a; x <= 500000; x += x & -x) bit[x] += w;
	}
	int sum(int a){
		int ret = 0;
		for (int x = a; x > 0; x -= x & -x) ret += bit[x];
		return ret;
	}
	void insert(int a, int w){
		int res = sum(a) - sum(a-1);
		w = w - res;
		add(a, w);
	}
	int solvesum(int l, int r){
		return sum(r) - sum(l-1);
	}
};
BIT segfoo, segins;

signed main(){
	int i;
	cin >> n;
	for( i = 1; i <= n; i++ ){
		cin >> a >> b;
		bug[i].a = a;
		bug[i].b = b;
	}
	qsort( bug+1, n, sizeof(bug[1]), compare );
	//cout << endl;
	//int debug = 0;
	for( i = 1; i <= n; i++ ){
		//debug += bug[i].a;
		//cout << bug[i].a << " " << bug[i].b << " " << debug << endl;
		uofB[bug[i].b + 1].push_back(i);
		segins.insert(i, 1);
		segfoo.insert(i, bug[i].a);
	}
	
	int minB;
	int ans = 0;
	for( minB = 0; minB < 100002; minB++ ){
		for( i = 0; i < uofB[minB].size(); i++ ){
			segfoo.insert(uofB[minB][i], 0);	//微生物uofB[Minb][i]を無効化
			segins.insert(uofB[minB][i], 0);
		}
		/*cout << endl;
		cout << "Union = { ";
		for( i = 1; i <= n; i++ ){
			if( segins.solvesum(i,i) ){
				cout << i << " ";
			}
		}
		cout << "}" << endl;*/
		
		int st = 1, ed = n+1, medi;
		int sumFoo, k;
		while( st <= ed ){
			medi = st + ed;
			medi /= 2;
			sumFoo = segfoo.solvesum(1, medi);
			k = segins.solvesum(1, medi);
			//cout << "sumFoo = " << sumFoo << " minB = " << minB << " k = " << k << " medi = " << medi << endl;
			if( sumFoo > k * minB ) {
				ed = medi - 1;
			}
			else{
				ans = max(ans, k);
				if( segfoo.solvesum(1, medi+1) > segins.solvesum(1, medi+1) * minB )
					break;
				else
					st = medi + 1;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 22476
#include<bits/stdc++.h>
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
int n,m,q;
vector<int>a,b,c,d;
int ans;
void dfs(vector<int> A){
    if(A.size()==n+1){
        int sc=0;
        rep(i,q){
            if(A[b[i]]-A[a[i]]==c[i]) sc += d[i];
        }
        ans = max(ans,sc);
        return;
    }
    A.push_back(A.back());
    while(A.back()<=m){
        dfs(A);
        A.back()++;
    }
}
int main(){
 cin>>n>>m>>q;
 a=b=c=d=vector<int>(q);
 rep(i,q){
     cin>>a[i]>>b[i]>>c[i]>>d[i];
 }

dfs(vector<int>(1,1));
cout << ans << endl;

return 0;
}

Measured memory_bytes: 3624
from collections import defaultdict
from collections import deque
from sys import stdin
 
def sp(G,R,V):
    d = {}
    INF = float('inf')
    for i in range(V):
        d[i] = INF
    d[R] = 0
    for i in range(1, V+1):
        for ((u, v), c) in G.items():
            if d[v] > d[u] + c:
                d[v] = d[u] + c
                if i == V:
                    return 0
    return d
 
 
V, E, R = [int(x) for x in stdin.readline().split()]
G = {}
for case in range(E):
    s, t, w = [int(x) for x in stdin.readline().split()]
    G[(s, t)] = w
d = sp(G, R, V)
if d == 0:
    print('NEGATIVE CYCLE')
else:
    for k in range(V):
        if d[k] == float('inf'):
            print("INF")
        else:
            print(d[k])

Measured memory_bytes: 8624
import copy
s = input()
t = input()
for i in range(len(s)-len(t)+1):
  s1 = copy.deepcopy(s[len(s)-len(t)-i:len(s)-i])
  for j in range(len(t)):
    if t[j]==s1[j]:
      continue
    elif s1[j]=="?":
      s2 = list(s1)
      s2[j]=t[j]
      s1 = "".join(s2)
    else:
      break
  else:
    s3 = s[:len(s)-len(t)-i].replace("?","a")+s1+s[len(s)-i:].replace("?","a")
    print(s3)
    exit()
print("UNRESTORABLE")

Measured memory_bytes: 3444
n,a,b = map(int,input().split())
h = [int(input()) for i in range(n)]
def judige(n):
    global h,a,b
    check = 0
    for i in range(len(h)):
        num = h[i]
        num -= b*n
        if num > 0:
            check += num//(abs(b-a)) if num % abs(b-a) == 0 else num//abs(b-a) + 1
    if check <= n:return True
    return False
inf = max(h)//b + 1
zero = 0
while True:
    num = (inf+zero)//2
    if inf-zero==1 or inf-zero==0:break
    if judige(num):inf = num
    else:zero = num
if judige(zero-2) and zero > 2:print(zero-2)
elif judige(zero-1) and zero > 1:print(zero-1)
elif judige(zero):print(zero)
else:print(inf)

Measured memory_bytes: 7088
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>

#define ll long long int

using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int month,date;
  int n[12]={31,29,31,30,31,30,31,31,30,31,30,31};
  int i;

  while(1){
    cin>>month>>date;
    if(month==0)break;
    int day=0;
    for(i=0;i<month-1;i++)
      day+=n[i];
    day+=date;

    switch(day%7){
    case 0:cout<<"Wednesday"<<endl;break;
    case 1:cout<<"Thursday"<<endl;break;
    case 2:cout<<"Friday"<<endl;break;
    case 3:cout<<"Saturday"<<endl;break;
    case 4:cout<<"Sunday"<<endl;break;
    case 5:cout<<"Monday"<<endl;break;
    case 6:cout<<"Tuesday"<<endl;break;
    }
  }
}

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

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    for (int i=0; i<n; i++){
        cin >> vec.at(i);
    }
    sort(vec.begin(),vec.end());
    cout << (vec.at(n/2)-vec.at(n/2-1));
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;

int main(){
    int n,k;
    cin >> n >> k;
    vector<ll> h(n+1),dp(n+1,INF);
    rep(i,n) cin >> h.at(i+1);
    dp.at(1)=0;
    for (int i=1;i<n;i++){
        for (int j=1;j<k+1;j++){
        if (i+j>n) break;
        dp.at(i+j)=min(dp.at(i+j),dp.at(i)+abs(h.at(i)-h.at(i+j)));
        }
    }
    cout << dp.at(n) << endl;
}


Measured memory_bytes: 1792
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    S = input()
    X, Y = map(int, input().split())
    Dxy = [[] for _ in range(2)]
    cnt = 0
    direc = 0
    for x in S:
        if x == 'F':
            cnt += 1
        else:
            Dxy[direc].append(cnt)
            cnt=0
            direc = 1-direc
    Dxy[direc].append(cnt)

    Dx = Dxy[0][1:]
    Dy = Dxy[1]
    dpx=[set([Dxy[0][0]]),set([])]
    dpy=[set([0]),set([])]
    i=1
    for dx in Dx:
        dpx[i]=set([])
        for x in dpx[1-i]:
            dpx[i].add(x+dx)
            dpx[i].add(x-dx)
        i = 1-i
    j=1
    for dy in Dy:
        dpy[j]=set([])
        for y in dpy[1-j]:
            dpy[j].add(y+dy)
            dpy[j].add(y-dy)
        j = 1-j

    if X in dpx[1-i] and Y in dpy[1-j]:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 4040
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    A, B, C = map(int, input().split())
    if A == B == C:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		double[] M = new double[N];
		for(int i=0;i<N;i++){
			M[i] = (double)(1 + P[i]) * (P[i]) / 2.0;
			M[i] /= (double) P[i];
		}
		//Console.WriteLine(String.Join(" ",M));
		
		double[] sum = new double[N + 1];
		for(int i=0;i<N;i++) sum[i + 1] = sum[i] + M[i];
		
		double max = 0;
		for(int i=0;i+K-1<N;i++){
			double s = sum[i+K] - sum[i];
			max = Math.Max(max, s);
		}
		Console.WriteLine(max);
		
		
	}
	int N,K;
	int[] P;
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1];
		P = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 29276
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N; string S; cin >> N >> S;

  vector<int> bnum(N, 0), wnum(N, 0);
  bnum[0] = (S[0] == '#');
  wnum[N-1] = (S[N-1] == '.');

  for (int i = 1; i < N; ++i) {
    bnum[i] = bnum[i-1];
    if (S[i] == '#') bnum[i]++;
  }

  for (int i = N-2; i >= 0; --i) {
    wnum[i] = wnum[i+1];
    if (S[i] == '.') wnum[i]++;
  }

  int ans = 1<<30;
  for (int i = 1; i < N; ++i) {
    ans = min(ans, bnum[i-1]+wnum[i]);
  }
  ans = min(ans, bnum[N-1]);
  ans = min(ans, wnum[0]);

  cout << ans << endl;
}

Measured memory_bytes: 2180
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

s = input().strip()

if s[0] != 'A':
    print('WA')
    sys.exit(0)

if s.count('C') != 1:
    print('WA')
    sys.exit(0)

if not (2 <= s.find('C') <= len(s) - 2):
    print('WA')
    sys.exit(0)

if not s.replace('A', '').replace('C', '').islower():
    print('WA')
    sys.exit(0)

print('AC')


Measured memory_bytes: 61768
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())
const double pi = 3.14159265358979323846;

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

    ll i,j,n;
    cin>>n;
    vector<ll> a(n);
    for(i=0;i<n;i++) cin>>a[i];
    ll tx = 0;
    for(i=0;i<n;i+=2)
    {
      tx^=(a[i]^a[i+1]);  
    }
    for(i=0;i<n;i++)
    {
        cout<<(tx^a[i])<<" ";
    }
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define lli long long int
#define llu unsigned long long int
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
#define sz(x) (lli)(x.size())
const lli MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
// cout << fixed << setprecision(0) << pi <<endl;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// for multiset
// typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

void solve() {
    lli n, a;
    cin >> n;
    lli gcd = 0;
    vector<lli> v(1e6 + 5, 0);
    lli mx = -1;

    for (lli i = 0; i < n; i++) {
        cin >> a;
        v[a] = 1;
        mx = max(mx, a);
        gcd = __gcd(gcd, a);
    }

    if (gcd != 1) {
        cout << "not coprime" << endl;
        return;
    }

    lli flag = 0;
    for (lli i = 2; i <= mx; i++) {
        lli cnt = 0;
        for (lli j = i; j <= mx; j += i) {
            if (v[j] == 1) {
                cnt++;
            }
        }
        if (cnt >= 2) {
            flag = 1;
            break;
        }
    }

    if (flag == 1) {
        cout << "setwise coprime" << endl;
    } else {
        cout << "pairwise coprime" << endl;
    }
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // lli t; cin >> t; while(t--)
    solve();
    rt;
}

Measured memory_bytes: 11108
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <complex>
#include <algorithm>

using namespace std;
using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using i32 = int_fast32_t;
using u32 = uint_fast32_t;

#define int i64

template<class T>
inline bool chmin(T &a, T b) { if(a > b) {a = b; return true;} return false; }
template <class T>
inline bool chmax(T &a, T b) { if(a < b) {a = b; return true;} return false; }
const int INF = 1LL << 60;

signed main() {
	int h, n;
	cin >> h >> n;
	vector<int> a(n), b(n);
	int maxa = -INF;
	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		if(a[i] > maxa) maxa = a[i];
	}

	vector<int> dp(h + maxa + 1, INF);
	dp[0] = 0;

	for(int i = 0; i <= h; i++) {
		for(int j = 0; j < n; j++) {
			chmin(dp.at(i + a.at(j)), dp.at(i) + b.at(j));
		}
	}

	int res = INF;
	for(int i = h; i <= h + maxa; i++) {
		if(dp[i] < res) res = dp[i];
	}

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


Measured memory_bytes: 384
/* 
 * Project: AtCoder Beginners Contest 177 A - Don't be late
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/08/29
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstdint>
using namespace std;

uint32_t d;
uint32_t t;
uint32_t s;

void solve() {

    if (t * s >= d)
        printf("Yes\n");
    else
        printf("No\n");
}

int main() {

    scanf("%d", &d);
    scanf("%d", &t);
    scanf("%d", &s);

    solve();

}

Measured memory_bytes: 3164
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;

  set<char> ss;
  REP(i, 4) {
    ss.insert(s[i]);
  }

  if(ss.size() == 2) {
    char a;
    int b = 0;
    a = s[0];
    REP(i, 4) {
      if(s[i] == a) b++;
    }
    if(b == 2) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> a(200001);
vector<string> s(200001);
map<int, int> sum;
int n, ans;

int main(void)
{
    string str1;
    cin >> str1;
    string str2;
    cin >> str2;
    int temp=0;
    for(int i=0;i<str1.size();i++){
        if(str1[i]!=str2[i]){
            temp=1;
            break;
        }
    }
    if(temp==1){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 10132
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (A + B >= C) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <functional>
using namespace std;

using ll = long long;

int main(void){
    
    ll n;
    cin >> n;
    
    std::function<ll(ll)> func = [&func](int a){ return (a == 1) ? 1 :(a * func(a-1))%(7+(ll)pow(10,9)); };
    
    cout << func(n) << endl;
    
    
}


Measured memory_bytes: 3328
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	
	LL a, b, c;
	cin >> a >> b >> c;

	if (c - a - b > 0 && 4 * a * b < (__int128) (c - a - b) * (c - a - b)) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#include <math.h>
#include <stdlib.h>
int main (){
int n,m,a[52],b[52],c[52],d[52],i,j,e,f,g;
scanf("%d %d",&n, &m);
for(i=1;i<=n;i++){
scanf("%d %d",&a[i],&b[i]);
}
for(i=1;i<=m;i++){
scanf("%d %d",&c[i],&d[i]);
}
for(i=1;i<=n;i++){
e=500000000;
for(j=m;j>=1;j--){
f=abs(a[i]-c[j])+abs(b[i]-d[j]);
if (f<=e) {
e=f;
g=j;
}
}
printf("%d\n",g);
}
return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
 
int main(int argc, const char * argv[]) {
  int a, b, c;
  cin >> a >> b >> c;
 
  if (a < b && b < c){ 
    cout << "Yes" << endl;
  }  
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 1156
// AOJ 2104: Country Road
// 2017.9.30 bal4u@uu
// 2017.11.7 retry

#include <stdio.h>
#include <string.h>

int f[1000001];

// for data input
char buf[800000], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int t, n, k, i, ans;
	int x0, x1, x, min, max;

	fgets(p=buf, 10, stdin), t = getint();
	while (t--) {
		fgets(p=buf, 20, stdin), n = getint(), p++, k = getint();
		fgets(p=buf, sizeof(buf), stdin);
		if (k >= n) { puts("0"); continue; }
		
		memset(f, 0, sizeof(f));
		min = 1000000, max = 0;
		for (x0 = getint(), i = 1; i < n; i++, x0 = x1) {
			p++, x1 = getint();
			x = x1 - x0, f[x]++;
			if (x < min) min = x;
			if (x > max) max = x;
		}

		for (ans = 0, i = n-k, x = min; i > 0; x++) {
			if (f[x] > 0) {
				if (i < f[x]) f[x] = i;
				ans += x*f[x], i -= f[x];
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 6228
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n; cin >> n;
	map<int64_t, int64_t> mp;
	int64_t sum = 0;
	rep(i,n) {
		int a; cin >> a;
		mp[a]++;
		sum += a;
	}
	int q; cin >> q;
	while(q--) {
		int64_t b, c; cin >> b >> c;
		sum -= mp[b] * b;
		sum += mp[b] * c;
		mp[c] += mp[b];
		mp[b] = 0;
		cout << sum << '\n';
	}
	return 0;
}

Measured memory_bytes: 9540
#include <algorithm>
#include <iostream>
#include <random>
#include <vector>
using namespace std;
typedef long long ll;

ll solve(string s, ll k) {
  // string s;
  // ll k;
  int n = s.length();
  ll ans;
  if (n == 1) {
    ans = k / 2;

  } else {
    int count1 = 0;
    for (int i = 0; i < n - 1; i++) {
      if (s[i] == s[i + 1]) {
        count1++;
        i++;
      }
    }

    string ss = s + s;
    int count2 = 0;
    for (int i = 0; i < n * 2 - 1; i++) {
      if (ss[i] == ss[i + 1]) {
        count2++;
        i++;
      }
    }

    string sss = ss + s;
    int count3 = 0;
    for (int i = 0; i < n * 3 - 1; i++) {
      if (sss[i] == sss[i + 1]) {
        count3++;
        i++;
      }
    }
    int diff1 = count2-count1;
    int diff2 = count3-count2;

    if (count2 != count3) {
      ans = count1 + (k/2)*diff1 + (k/2+k%2-1)*diff2;

    } else {
      ans = count1 + diff1 * (k - 1);
    }
  }
  return ans;
  // cout << ans << endl;
}

int main() {
  string s;
  ll k;
  cin >> s;
  cin >> k;
  cout << solve(s, k) << endl;

  return 0;
}


Measured memory_bytes: 256
s=input()
n=len(s)
mod=2019
sum=0
p=1
d={}
d[0]=1
for i in range(n-1,-1,-1):
    sum=(sum+int(s[i])*p)%mod
    if sum in d:
        d[sum]+=1
    else:
        d[sum]=1
    p=(p*10)%mod
ans=0
for v in d.values():
    ans+=(v*(v-1))//2
print(ans)

Measured memory_bytes: 9240
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

int n, S[24];
int x[24],y[24],r[24],c[24];
char dp[1<<24];
bool take[24];


inline int sqr(int x){ return x*x; }

int solve(int nowS){
    int i,j,k;
    int res = 0;
    static const bool underFirst[] = {true, true, false};
    static const bool underSecond[] = {true, false, true};


    if( dp[nowS] != -1 ) return dp[nowS];

    // 1. (円盤iの下に他の円盤がある,円盤jの下に他の円盤がある) の組み合わせ
    // 2.1 円盤iの下に他の円盤がある,円盤jの下にはなにもない
    // 2.2 円盤iの下にはなにもない,円盤jの下に他の円盤がある
    
    bool get = false;
    for(k=0; k<3; k++){
        for(i=0; i<n; i++){
            if( (S[i] == (nowS & S[i])) && !(nowS & (1<<i)) && (take[i] == underFirst[k]) ) {
                for(j=i+1; j<n; j++){
                    if( (S[j] == (nowS & S[j])) && c[i] == c[j] && !(nowS & (1<<j)) && (take[j] == underSecond[k]) ){
                        res = max(res, solve(nowS | (1<<i) | (1<<j)) + 2);
                        get = true;
                    }
                }
            }
        }
    }

    // 3. 円盤iの下にはなにもない,円盤jの下にもなにもない(取れるだけ取る)
    int sum = 0;
    if( !get ){
        bool used[24];
        memset(used, false, sizeof(used));
        for(i=0; i<n; i++){
            if( !used[i] && (S[i] == (nowS & S[i])) && !(nowS & (1<<i)) && (take[i] == false) ) {
                for(j=i+1; j<n; j++){
                    if( !used[j] && (S[j] == (nowS & S[j])) && c[i] == c[j] && !(nowS & (1<<j)) && (take[j] == false) ){
                        sum += 2;
                        used[i] = used[j] = true;
                        break;
                    }
                }
            }
        }
    }

    return dp[nowS] = res + sum;
}


int main(){
    int i,j;

    while( cin >> n, n ){
        // init
        memset(S, 0, sizeof(S));
        memset(take, false, sizeof(take));
        memset(dp, -1, sizeof(dp));

        // input
        for(i=0; i<n; i++) cin >> x[i] >> y[i] >> r[i] >> c[i];

        // フィルターを作る
        for(i=0; i<n; i++){
            for(j=0; j<i; j++){
                if( sqr(x[i] - x[j]) + sqr(y[i] - y[j]) < sqr(r[i] + r[j]) ){
                    S[i] |= 1<<j;

                    // 円盤jの下にある円盤があるかどうか
                    take[j] = true;
                }
            }
        }
        cout << solve(0) << endl;
    }
    return 0;
}

Measured memory_bytes: 16000
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int a,b;
int main()
{
	scanf("%d%d",&a,&b);
	for(int i=0;i<=1000;i++)
	{
		if((a-1)*i+1>=b)
		{
			printf("%d\n",i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 128
# Ai ≡ 0 (mod k) A1 = 7, A2 = 77, A3 = 777

k = int(input())
if k == 7 or k == 1:
    print(1)
    exit()
# よくわからんからAiをmodKにして試してみる
seven = 7
for i in range(1, 10**6 + 10):
    seven = seven * 10 + 7
    seven %= k
    if seven == 0:
        print(i + 1)
        exit()
print(-1)

Measured memory_bytes: 9112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <forward_list>

using namespace std;

typedef long long ll;
typedef vector<long long> vi;
typedef pair<long long, long long> ii;
typedef vector<pair<long long, long long>> vii;
typedef stringstream ss;
ll mil() { return numeric_limits<long long>::min(); }
ll mal() { return numeric_limits<long long>::max(); }

#define R3(i, a, b) for (long long i = (a); i < (b); ++i)
#define R2(i, b) for (long long i = 0; i < (b); ++i)
#define R1(b) for (long long i = 0; i < (b); ++i)
#define RR(i, a, b) for (long long i = a; i > b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

// build: ctrl + f9

// run: shift + f10
// sanitize: shift + f11
// debug: shift + f9

void A() {
    string S;
    string T;
    cin >> S >> T;

    if(T.substr(0, S.size()) == S) {
        cout << "Yes" << endl;
        return;
    }

    cout << "No" << endl;
}

void B() {
}

void C() {
}

void D() {
}

void E() {
}

int main()
{
    A();
}

Measured memory_bytes: 3628