akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
	using namespace std;
	int counter[3011];
	int main(){
		#define int long long
		ios_base::sync_with_stdio(false);
		cin.tie(0);	
		int a;
		long long march[5]={0,0,0,0,0};
		cin>>a;
		string in;
		while(a--){
			cin>>in;
			if (in[0]=='M'){
				march[0]++;
			}
			else if (in[0]=='A'){
				march[1]++;
			}
			else if (in[0]=='R'){
				march[2]++;
			}
			else if (in[0]=='C'){
				march[3]++;
			}
			else if (in[0]=='H'){
				march[4]++;
			}
		}
		long long count=0;
		for(int i=0;i<=2;i++){
			for(int ii=i+1;ii<=3;ii++){
				for(int iii=ii+1;iii<=4;iii++){
					count+=(march[i]*march[ii]*march[iii]);
				}
			}
		}
		cout<<count<<endl;
		
		return 0;
	}

Measured memory_bytes: 256
//xsharawi is back
//SPEEEEEEEEEED IS KEEEEEEEEEEY
//REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAD
#include <bits/stdc++.h>
using namespace std;
typedef string s;
typedef long long ll;
typedef long double ld;
#if !defined(ONLINE_JUDGE)
#include "C:\debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define ins insert
#define vl vector<ll>
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
int main(){
    speed;
    ll n, k, ans = 0;
    cin >> n >> k;
    ll a[n];
    for( ll i = 0; i < n; i++ )cin >> a[i];
    sort( a, a + n );
    for( ll i = 0; i < k; i++ )ans += a[i];
    cout << ans << endl;


































return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
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 long long INF = 1LL << 60;

int main() {
    string w;
    cin >> w;
    int a[1000] = {};
    for(int i = 0; i < w.size(); i++) {
        a[w[i]] += 1;
    }
    bool flag = true;
    for(int i = 0; i< 1000; i++) {
        if(a[i] % 2 != 0) {
            flag = false;
            break;
        }
    }
    if(flag == true) {
        cout << "Yes";
    }else {
        cout << "No";
    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool>    vecbool;
typedef vector<int>     vecint;
typedef vector<ll>      vecll;
typedef vector<string>  vecstr;
typedef vector<vecint>  vec2int;
typedef vector<vecbool> vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int main()
{
  int n; cin >> n;
  vecint a(n,0);REP(i,n) cin >> a[i];
  int i = 0;
  int ans = 0;
  while(i < n){
    // cout << i << endl;
    ans ++;
    while(i < n - 1&& a[i] == a[i + 1]){
      i ++;
    }
    if(i == n - 1) break;
    bool inc = true;
    if(a[i] > a[i + 1]){
      inc = false;
    }
    // cout << i << endl;
    if(inc){
      while(i < n - 1 && a[i] <= a[i + 1]){
	i ++;
      }
      // ans ++;
    }else{
      while(i < n - 1&& a[i] >= a[i + 1]){
	i ++;
      }
      // ans ++;
    }
    i++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k,x,y;
    cin >> n >> k >> x >> y;
    if(n > k)
    cout << k * x + (n - k) * y << endl;
    else
    {
        cout << n * x << endl;
    }
    
}

Measured memory_bytes: 256
# ABC061B - Counting Roads
def main():
    N, M = tuple(map(int, input().split()))
    E = tuple(tuple(map(int, input().split())) for _ in range(M))
    G = [[] for _ in range(N + 1)]
    for v, u in E:
        G[v] += [u]
        G[u] += [v]
    print(*(len(g) for g in G[1:]), sep="\n")


if __name__ == "__main__":
    main()

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

string s, t;
int dp[3002][3002];
int lcs(int i, int j) {
    if(i==s.size() || j == t.size())
        return 0;
    if(dp[i][j] != -1)
        return dp[i][j];
        
    if(s[i] == t[j])
        return dp[i][j] = 1+ lcs(i+1, j+1);
    
    int la = lcs(i+1, j);
    int ra = lcs(i, j+1);
    if(la>ra) {
        return dp[i][j] = la;
    }
    else {
        return dp[i][j] = ra;
    }
}

void print(int i, int j) {
    if(i>=s.size() || j>=t.size())
        return;
    int ni = i, nj = j;
    if(s[i] == t[j]) {
        cout<<s[i];
        ni++;
        nj++;
        print(ni, nj);
        return;
    }
    if(dp[i][j+1]< dp[i+1][j])
        ni++;
    else
        nj++;
    print(ni, nj);
}
int main() {
	cin>>s>>t;
	int i, j;
	for(i=0;i<s.size();i++)
	    for(j=0;j<t.size();j++)
	        dp[i][j] = -1;
	lcs(0, 0);
	print(0, 0);
	return 0;
}

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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
// #define LLONG_MAX 9223372036854775806
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
// #define MOD 998244353
// #define MOD LLONG_MAX
const double PI=3.14159265358979323846;

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




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



void printv(vint &v){
  for(auto e:v) cout<<e<<" ";
  cout<<endl;
}


// 繰り返し二乗法
ll power(ll a, ll b){
  if(a==1)return a;
  // if(a==0)re
  ll res=1;
  while(b>0){
    if(b&1) res=res*a%MOD;
    a=a*a%MOD;
    b>>=1;
  }
  return res;
}

const int MAX=2100000;
 
ll fact[MAX], fact_inv[MAX];
 
void init_fact(ll n){
  fact[0]=1;
  // 階乗の計算
  rep(i, n) fact[i+1]=fact[i]*(i+1)%MOD;
  fact_inv[n]=power(fact[n], MOD-2);
  // 逆元の計算
  for(ll i=n-1;i>=0;i--) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
}
 
ll comb(ll n, ll r){
  return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
 
ll perm(ll n, ll r){
  return (fact[n]*fact_inv[n-r])%MOD;
}






int main() {
  cout<<fixed<<setprecision(10);

 vint v(3);
 rep(i,3) cin>>v[i];

 sort(ALL(v));

 cout<<v[0]+v[1]+10*v[2]<<endl;


}






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

int main(){
  while(1){
    int n,s;
    int a[10000];
    int cnt=0,t=0;
    cin>>n;
    if(n==0){
      break;
    }
    for(int i=0;i<n;i++){
      cin>>a[i];
      t=t+a[i];
    }
    s=t/n;
    for(int i=0;i<n;i++){
      if(s>=a[i]){
        cnt++;
      }
    }
    cout<<cnt<<endl;
  }
}



Measured memory_bytes: 3132
def main():
    n = int(input())
    arr = list(map(int,input().split()))
    zero = 0
    pos = []
    neg = []
    for i in arr:
        if i > 0:
            pos.append(i)
        elif i < 0:
            neg.append(abs(i))
        else:
            zero += 1

    total = 0
    ans = []
    if pos and neg:
        total = sum(pos)+sum(neg)
        curr = -neg[0]
        for i in range(len(pos)-1):
            ans.append((curr,pos[i]))
            curr = curr-pos[i]

        ans.append((pos[-1],curr))         
        curr = pos[-1]-curr

        for i in range(1,len(neg)):
            ans.append((curr,-neg[i]))
            curr = curr+neg[i]

        for i in range(zero):
            ans.append((curr,0))
    else:
        arr.sort()
        if neg:
            arr.reverse()
        curr = arr[0]
        for i in range(1,n-1):
            ans.append((curr,arr[i]))
            curr = curr-arr[i]

        if pos:
            ans.append((arr[-1],curr))
            total = arr[-1]-curr
        else:
            ans.append((curr,arr[-1]))
            total = curr-arr[-1]

    print(total)
    for i in ans:
        print(i[0],i[1])
        


main()


Measured memory_bytes: 26808
#include <stdio.h>
int main(){

  int a,b,c,d,e;

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

  if(a > 0) printf("%d\n",(b-a)*e);
  else printf("%d\n",b*e+d-a*c);

  return 0;

}

Measured memory_bytes: 596
import sys
import collections
input = sys.stdin.readline

def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    num_freq = collections.Counter(a_list)

    vals = []
    for X in set(a_list):
        v = 0
        if X in num_freq:
            v += num_freq[X]
        if X - 1 in num_freq:
            v += num_freq[X-1]
        if X + 1 in num_freq:
            v += num_freq[X+1]
        vals.append(v)
    print(max(vals))

if __name__ == '__main__':
    main()


Measured memory_bytes: 61788
// https://atcoder.jp/contests/abc087/tasks/abc087_b
#include <iostream>

using namespace std;

int main() {
    int A, B, C, X;
    cin >> skipws;
    cin >> A >> B >> C >> X;
    int count = 0;
    for(int a = 0; a <= A; ++a) {
        for (int b=0; b <= B; ++b) {
            for (int c=0; c <= C; ++c) {
                if (a*500 + b*100 + c*50 == X) {
                    ++count;
                }
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "array"
#include "string"
#include "algorithm"
#include "functional"
#include "list"
#include <math.h>


using namespace std;
#define rep(p,q) for(int i = p;i < q;i++)



//C
int main(void) {
	int n, m;
	cin >> n >> m;
	vector<int> goal = vector<int>();
	rep(0, m) {
		int x = 0;
		cin >> x;
		goal.push_back(x);
	}
	sort(goal.begin(), goal.end());
	vector<int> diff = vector<int>();
	long long int sum = 0;
	rep(0, m-1) {
		int d = goal[i + 1] - goal[i];
		diff.push_back(d);
		sum += d;
	}
	sort(diff.begin(), diff.end());
	if (n >= m) cout << 0 << endl;
	else {
		rep(0, n - 1) {
			if(m - 2 - i >= 0)
				sum -= diff[m - 2 - i];
			else break;
		}
		cout << sum << endl;
	}
}


Measured memory_bytes: 1400
<?php

fscanf(STDIN, "%d", $n);
$A = [];
for ($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d", $a);
    $A[] = $a;
}

$tmp = $A;
sort($tmp);
$max1 = $tmp[$n - 1];
$max2 = $tmp[$n - 2];

for ($i = 0; $i < $n; ++$i) {
    echo $A[$i] === $max1 ? $max2 : $max1, PHP_EOL;
}


Measured memory_bytes: 22388
#include <bits/stdc++.h>
using namespace std;
string s1; 
int w1,w2;
int main(){
	cin>>s1;
	int len=s1.size();
	for(int i=0;i<len;i++){
		if(s1[i]=='C')
			w1=i;
	}
	for(int i=0;i<len;i++){
		if(s1[i]=='F')
			w2=i;
	}
	if(s1[0]=='C'&&w2!=0){
		printf("Yes");
		return 0;
	}
	if(w1!=0&&w2!=0&&w2>w1){
		printf("Yes");
		return 0;
	}
	printf("No");

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef unsigned  long long int ll;
#define INFI LLONG_MAX
#define  forl for(int i=0;i<n;i++)
#define pb push_back	
int  main()
{
ll a;
ll b;
ll c;
cin>>a>>b>>c;
if(c<=(a+b))
cout<<"No";
else if(4*(a*b)<((c-(a+b))*(c-(a+b))))
cout<<"Yes";
else
puts("No");

}


Measured memory_bytes: 256
#include<stdio.h>
    int main()
{
    int b[100]={0}, c[100]={0}, a[100][100]={0}, m, n, i, j;
    scanf("%d %d", &n, &m);
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            scanf("%d", &a[i][j]);
        }
    }
     
    for(i = 0; i < m; i++){
        scanf("%d", &b[i]);
    }
     
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            c[i] += a[i][j] * b[j];
        }
    }   
     
    for(i = 0; i < n; i++){
        printf("%d\n", c[i]);
    }
    return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <vector>
#include <stdio.h>
#include <cmath>
using namespace std;

class Dic{
public:	
	int x;
	int y;
	int t;
	Dic(){
		x = 0;
		y = 0;
		t = 0;
	}
};

int main(){
	/*input*/
	int n;	cin >> n;
	vector<Dic>dic(n + 1);
	for(int i = 1; i <= n; i++){
		cin >> dic[i].t >> dic[i].x >> dic[i].y;
	}
	/*calculation*/
	bool flag = true;	//true:Yes false:No
	int road = 0;		//道順
	int deltat = 0;
	for(int i = 0; i < n && flag; i++){
		road = abs(dic[i + 1].x - dic[i].x) + abs(dic[i + 1].y - dic[i].y);
		deltat = dic[i + 1].t - dic[i].t;
		if(deltat < road){
			flag = false;
		}else if(deltat == road){
			flag = true;
		}else if(deltat > road){
			if((deltat - road)%2 == 0){
				flag = true;
			}else{
				flag = false;
			}
		}
		//printf("i:%d road:%d deltat:%d flag:%d\n", i, road, deltat, flag?1:0);
	}
	/*output*/
	if(flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


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

int main() {
    int N; cin >> N;
    vector<int> P(N), Q(N);
    for(int i=0; i<N; ++i) cin >> P[i];
    for(int i=0; i<N; ++i) cin >> Q[i];

    int a,b;
    int k=0;
    vector<int> perm(N);
    iota(perm.begin(), perm.end(), 1);
    do{
        if(P == perm) a = k;
        if(Q == perm) b = k;
        ++k;
    }while(next_permutation(perm.begin(), perm.end()));
    cout << abs(a - b) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 10, mod = 1e9 + 7;
int a[N];

int main() {
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) a[abs(n - i - (i - 1))]++;
	for(int i = 1, x; i <= n; ++i) {
		scanf("%d", &x);
		a[x]--;
		if(a[x] < 0) return printf("0\n"), 0;
	}
	ll pos = 1;
	for(int i = 1; i <= n / 2; ++i) pos = pos * 2 % mod;
	printf("%lld\n", pos);
	return 0;
}

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

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

   int N,K; cin>>N>>K;
   int ans=0;
   while(N>0){
      ans++;
      N/=K;
   }
   cout<<ans<<endl;
   return 0;
}


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

int main() {
  string s;
  cin >> s;
  
  int l = s.size();
  vector<int> n(l);
  for(int i = 0; i < l; ++i) n.at(i) = s.at(i) - '0';
  vector<vector<int>> dp(l+1, vector<int> (2, 0));
  dp.at(0).at(1) = 1;
  for(int i = 0; i < l; ++i){
    dp.at(i+1).at(0) = min(dp.at(i).at(0) + n.at(i), dp.at(i).at(1) + 10 -n.at(i));
    dp.at(i+1).at(1) = min(dp.at(i).at(0) + n.at(i) + 1, dp.at(i).at(1) + 9 - n.at(i));
  }
  
  cout << dp.at(l).at(0) << endl;
}

Measured memory_bytes: 59780
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    vector<int>b(n);
    rep(i, 0, n){
        cin >> a[i] >> b[i];
    }
    ll ans = 0;
    for(int i = n-1; i >= 0; i--){
        ll tmp = (a[i]+ans) % b[i];
        if(tmp == 0) ans+=tmp;
        else ans+= b[i]-tmp;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4016
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline
sys.setrecursionlimit(10**5)

k,n = map(int, read().split())

if k%2==0:
    print(*([k//2]+[k]*(n-1)))
    exit()

if k==1:
    print(*[1]*((n+1)//2))
    exit()

ans = [(k+1)//2]*n
d = 0
def f(k,i,d):
    # d <= 1+k+...+k^i?
    v = 1
    for j in range(i):
        v *= k
        v += 1
        if v > d: return True
    return False

def g(k,i):
    # 1+k+...+k^i
    v = 1
    for j in range(i):
        v *= k
        v += 1
    return v
    
for i in range(1,n):
    if f(k,n-i-1,d):
        d += 1
        continue
    """
    以下　300000 >= d >= 1+k+...+k^(n-i-1)
    i 番目の項から真ん中にならない    
    v 番目を目指す
    """
    v = (g(k,n-i)+d+1)//2 - d - 1
    
    for j in range(i,n):
        #print(v)
        if v==0:
            ans[j] = 0
            continue

        p = g(k,n-j-1)
        q = (v-1)//p 
        #print(v,j,p,q)
        
        ans[j] = q+1
        v -= 1+q*p        



    
    break


while ans[-1]==0:
    ans.pop()
print(*ans)









Measured memory_bytes: 13752
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF (1e9 + 5)
#define MOD (int)(1e9 + 7)
#define n_l '\n'
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: "; cerr << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < (int)s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cerr << to_string(H) << " | "; dbgm(T...); }
#define dbgm(...) cerr << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cerr << endl
#define run(a, b) cerr << fixed << setprecision(6) << (double) (b - a) / (double) (CLOCKS_PER_SEC) << " s" << endl;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string a, b;
	cin >> a >> b;
	vector<vector<int>> dp(a.size()+1, vector<int>(b.size()+1, 0));
	for(int i = 1; i <= (int)a.size(); i++) {
		for(int j = 1; j <= (int)b.size(); j++) {
			if(a[i-1] == b[j-1]) {
				dp[i][j] = dp[i-1][j-1] + 1;
			}
			else {
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	string ans = "";
	int i = a.size(), j = b.size();
	while(i != 0 and j != 0) {
		if(a[i-1] == b[j-1]) {
			ans += a[i-1];
			i--;
			j--;
		}
		else if(dp[i-1][j] > dp[i][j-1]) {
			i--;
		}
		else {
			j--;
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 35584
def main():
    N = int(input())

    string_data = [input() for _ in range(N * 2)]

    for _ in range(N):
        s = string_data.pop(0)
        t = string_data.pop(0)

        dp = [0] * (len(t) + 1)

        for i, sc in enumerate(s):
            tmp = dp[:]
            for j, tc in enumerate(t):
                if sc == tc:
                    dp[j + 1] = tmp[j] + 1
                elif dp[j + 1] < dp[j]:
                    dp[j + 1] = dp[j]

        print(dp[-1])


if __name__ == '__main__':
    main()



Measured memory_bytes: 5636
#include <stdio.h>

int main(void)
{
    int i, j;
    int dp[101][101][2] = {0};
    
    for (i = 1; i <= 100; i++){
        dp[i][1][0] = dp[1][i][0] = dp[i][1][1] = dp[1][i][1] = 1;
    }
    
    for (i = 2; i <= 100; i++){
        for (j = 2; j <= 100; j++){
            dp[i][j][0] = (dp[i][j - 1][0] + dp[i - 2][j][1]) % 100000;
            dp[i][j][1] = (dp[i - 1][j][1] + dp[i][j - 2][0]) % 100000;
        }
    }
    
    
    while (1){
        scanf("%d%d", &i, &j);
        
        if (i + j == 0){
            break;
        }
        
        printf("%d\n", (dp[j][i - 1][0] + dp[j - 1][i][1]) % 100000);
    }
    
    return (0);
}

Measured memory_bytes: 0
from collections import Counter


def c2(r):
    return r * (r - 1) // 2


def main():
    s = input().strip()
    c = Counter(s)
    ans = c2(len(s)) + 1
    for x in c.values():
        if x < 2:
            continue
        ans -= c2(x)
    print(ans)


if __name__ == '__main__':
    main()

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

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

int N;
ll T;
ll W[101],V[101];
ll from[101][303];
ll to[101][303];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>T;
	
	FOR(i,N) {
		cin>>W[i]>>V[i];
		FOR(x,100) FOR(y,300) {
			to[x+1][y+W[i]-W[0]]=max(to[x+1][y+W[i]-W[0]],from[x][y]+V[i]);
		}
		memmove(from,to,sizeof(from));
	}
	
	ll ret=0;
	FOR(x,101) FOR(y,301) if(W[0]*x+y<=T) ret=max(ret,from[x][y]);
	
	cout<<ret<<endl;
}


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


Measured memory_bytes: 768
s=input()
t=input()
def ga(i,t):
    turn=0
    for k in range(len(t)):
        if s[-(i+k)]!=t[-(k+1)] and s[-(i+k)]!='?':
            break
    else:
        turn+=1
    return turn
li=list(s)
li2=list(t)
for i in range(1,len(s)-len(t)+2):
    if ga(i,t)==1:
        for k in range(len(t)):
            li[-(i+k)]=li2[-(k+1)]
        n=''.join(li)
        break
else:
    print('UNRESTORABLE')
    exit()
print(n.replace('?','a'))
            

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    long long before, after;
    long long stepHeightSum = 0;
    cin >> before;
    for(int i = 1; i < N; ++i) {
        cin >> after;
        if(before > after) {
            stepHeightSum += before - after;
        } else {
            before = after;
        }
    }
    cout << stepHeightSum << endl;
    return 0;
}

Measured memory_bytes: 3632
/**
 * @author: Mackenzie
**/
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n;
    cin>>n;
    while(true){
        string cur=to_string(n);
        if(cur[0]==cur[1]&&cur[1]==cur[2]){
            cout<<cur<<endl;
            return 0;
        }
        n++;
    }

    return 0;
}

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


int main(int argc, char *argv[]) {
  // C-style stdio functions should not be used.
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  int cc = 0;
  int minZ = 10;
  for (int i = 0; i < 5; i++) {
    int x; cin >> x;
    int y = 10 * ((x+9) / 10);
    cc += y;
    int z = x % 10;
    if (z < minZ && 0 < z) {
      minZ = z;
    }
  }
  if (minZ == 10) {
    cout << cc << endl;
    return 0;
  }
  cout << cc - 10 + minZ << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    long h, w;
    cin >> h >> w;
    char s[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char c;
            cin >> c;
            s[i][j] = c;
        }
    }
    bool z = true;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            long bl = 0;
            if(i > 0 && s[i-1][j] == '#') bl++;
            if(i < h-1 && s[i+1][j] == '#') bl++;
            if(j > 0 && s[i][j-1] == '#') bl++;
            if(j < w-1&& s[i][j+1] == '#') bl++;
            if(s[i][j] == '#' && bl == 0){
                z = false;
                break;
            }
        }
    }
    if(z) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    rep(i,N) A[i]--;
    int ans=0;
    int now=0;
    while(now!=1){
        int push=A[now];
        now=push;
        ans++;
        if(ans>=2*N){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
char s[101010];

int main(){
    scanf("%s",s);
    int n = strlen(s);
    int cc = 0;
    rep(i,0,n) cc -= s[i] == 'p';
    cc += n / 2;
    printf("%d\n",cc);
    return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double r;
    cin >> r;
    cout << r * r * 3;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
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>;
ll expo(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return ans;
}
ll n,s[200005],m[200005],ans[200005];
vl adj[200005];
void dfs(ll i,ll par)
{
	s[i]=1;
	for(auto j:adj[i])
	{
		if(j!=par)
		{
			dfs(j,i);
			s[i]+=s[j];
		}
	}
	m[i]=s[i];
	for(auto j:adj[i])
	{
		if(j!=par)
			m[i]=(m[i]*m[j])%M;
	}
}
void dfs1(ll i,ll par,ll p)
{
	ans[i]=(((m[i]*p)%M*expo(s[i],M-2,M))%M*n)%M;
	for(auto j:adj[i])
	{
		if(j!=par)
			dfs1(j,i,((((p*m[i])%M*expo(s[i],M-2,M))%M*(n-s[j]))%M*expo(m[j],M-2,M))%M);
	}
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    rep(i,0,n-1)
    {
    	ll u,v;
    	cin>>u>>v;
    	adj[u].pb(v);
    	adj[v].pb(u);
    }
    dfs(1,0);
    dfs1(1,0,1);
    ll p=1;
    rep(i,1,n+1)
    	p=(p*i)%M;
    rep(i,1,n+1)
    	cout<<(p*expo(ans[i],M-2,M))%M<<"\n";
}


Measured memory_bytes: 19440
#include <stdio.h>

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

Measured memory_bytes: 600
import java.util.Arrays;
import java.util.Scanner;

//Greedy, Greedy.
public class Main{

	int n, INF = 1<<29, M = 50000;
	int[] c;

	int f(int x){
		int res = 0, k = n-1;
		while(x>0&&k>=0){
			res += x/c[k];
			x%=c[k--];
		}
		return x==0?res:INF;
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		for(int T=1;;T++){
			n = sc.nextInt();
			if(n==0)break;
			c = new int[n];
			int s = 0;
			for(int i=0;i<n;i++){
				c[i]=sc.nextInt(); s+=c[i];
			}
			int[] dp = new int[s+1];
			Arrays.fill(dp, INF);
			dp[0] = 0;
			boolean f1 = true, f2 = true;
			for(int x=1;x<=s&&f1;x++){
				for(int i=0;i<n;i++){
					if(x-c[i]>=0)dp[x] = Math.min(dp[x], dp[x-c[i]]+1);
				}
				if(dp[x]==INF)f1 = false;
				if(dp[x]<f(x))f2 = false;
			}
			System.out.println("Case #"+T+": "+(!f1?"Cannot pay some amount":!f2?"Cannot use greedy algorithm":"OK"));
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		BigDecimal a = sc.nextBigDecimal(); // Immutable class.
		BigDecimal b = sc.nextBigDecimal();
		BigDecimal ans = a.multiply(b);
		
		System.out.println(ans.toBigInteger());
	}
}


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

int prime[1000010];
bool is_prime[1000010];
int n;
int main()
{
	while(cin>>n)
	{
		int p = 0;
		for(int i = 0;i <= n;i++)
		{
			is_prime[i] = true;    //先默认全不是素数 
		}
		is_prime[0] = is_prime[1] = false;
		for(int i = 2;i <= n;i++)
		{
			if(is_prime[i])
			{
				prime[p++] = i;
				for(int j = 2 * i;j <= n;j = j + i)
				{
					is_prime[j] = false;
				}
			}
		}
		cout<<p<<endl;
	}
} 


Measured memory_bytes: 4272
#include<iostream>
using namespace std;
int main(){
	int n,cut,m,a,b,i,j;
	int c[600][600]={0};
	while(1){
		for(i=0;i<600;i++){
			for(j=0;j<600;j++){
				c[i][j]=0;
			}
		}
		cin>>n;
		if(n==0){
			break;
		}
		cin>>m;
		for(i=1;i<=m;i++){
			cin>>a>>b;
			if(a==1||b==1){
				c[a][b]=1;
				c[b][a]=1;
			}
			else{
				c[a][b]=2;
				c[b][a]=2;
			}	
		}
		cut=0;
		for(i=2;i<=n;i++){
			if(c[1][i]==1){
				cut++;
				for(j=2;j<=n;j++){
					if(c[i][j]==2&&c[1][j]==0){
						cut++;
						for(m=1;m<=n;m++){
							c[m][j]=0;
							c[j][m]=0;
						}
					}
				}
			}
		}
		cout<<cut<<endl;
	}
	return 0;
}

Measured memory_bytes: 4476
s = int(input())
if s % 10**9 == 0:
    print(0, 0, 10**9, 0, 0, s//10**9)
else:
    r = s % (10**9)
    print(0, 0, 10**9, 1, 10**9 - r, s//10**9 + 1)

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

ll gcd(ll n, ll m) {
    if(n < m) swap(n, m);
    if(n % m == 0) return m;
    return gcd(m, n % m);
}

ll lcm(ll n, ll m) {
    return n * (m / gcd(n, m));
}

int main() {
    int N; cin >> N;
    vector<ll> T(N);
    ll ans = 1;
    for(int i = 0; i < N; i++) {
        cin >> T[i];
        ans = lcm(ans, T[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3660
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

  vector<int> vg[51];

void search(vector<int> &edge, int i){
  if (edge[i] == 1) return;
  edge[i] = 1;
  for (int j = 0; j < vg[i].size(); j++){
    search(edge, vg[i][j]);
  }
}

int main(){
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > v;
  for (int i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }

  int count = 0;
  for (int i = 0; i < v.size(); i++){
    for (int j = 0; j <= n; j++){
      vg[j].clear();
    }
    for (int j = 0; j < v.size(); j++){
      if (i == j) continue;
      vg[v[j].first].push_back(v[j].second);
      vg[v[j].second].push_back(v[j].first);
    }
    vector<int> edge(n+1, 0);
    search(edge, 1);
    for (int j = 1; j <= n; j++) {
      if (edge[j] != 1) {
        count++;
        break;
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
s_array = [input() for x in range(n)]
a_count = 0
b_count = 0
ab_count = 0
for s in s_array:
    if s[-1] == "A" and s[0] != "B":
        a_count += 1
    elif s[0] == "B" and s[-1] != "A":
        b_count += 1
    elif s[0] == "B" and s[-1] == "A":
        ab_count += 1
    else:
        pass

res = sum([x.count("AB") for x in s_array])

if n == 1:
    print(res)
elif ab_count == 0:
    print(res + min(a_count, b_count))
elif a_count == 0 and b_count == 0:
    print(res - 1 + ab_count)
else:
    print(res + min(a_count, b_count) + ab_count)


Measured memory_bytes: 9876
N = int(input())
S = input()

cnt_W = [0]*N #西を向いている人の累積和を求める
if S[0] == 'W':
    cnt_W[0] = 1

for i in range(1, N):
    if S[i]=="W":
        cnt_W[i] += cnt_W[i-1] + 1
    else:
        cnt_W[i] = cnt_W[i-1]

most_E = cnt_W[-1] #全体で西を向いている人数
#print(most_E)
ans = float('inf')
for i in range(N):
    tmp = 0
    if i == 0:
        if S[i] == "W":
            tmp = (N-most_E)
        else:
            tmp = (N-most_E)-1
        #print(tmp)
    elif i == N-1:
        if S[i] == "W":
            tmp = most_E-1
        else:
            tmp = most_E
        #print(tmp)
    else:
        tmp = cnt_W[i-1] + (N-most_E) - (i+1-cnt_W[i])
        #print(tmp)

    ans = min(ans, tmp)
print(ans)


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

int main(int argc, char *argv[])
{
    int n;
    cin >> n;

    vector<int> A(n);
    int s = 0;
    for(int& x : A) { cin >> x; s += x; }

    bitset<2000*2000 + 1> c;

    for(int i = 0; i < n; ++i)
    {
        c |= (c << A[i]);
        c[A[i]] = true;
    }

    for(int i = (s+1)/2; i < c.size(); ++i)
    {
        if(c[i])
        {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 1792
w,h,x,y=map(int,input().split())
z=0
if x==h//2 and y==w//2 :
    z=1
elif y==h//2 and x==w//2:
    z=1
if w%2==1 or h%2==1:
    z=0
print(w*h/2,z)

Measured memory_bytes: 3060
N, K = map(int, input().split())
A = [int(a) for a in input().split()]
m = min(A)
ans = 0
i = 0
while i < N:
    if A[i] == m:
        i += 1
    else:
        ans += 1
        if min(A[i:i+K]) == m:
            i += K
        else:
            i += K - 1
print(ans)

Measured memory_bytes: 52860
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

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

int main()
{
    string s, t;
    cin >> s >> t;
    int index = -1;
    bool exist = false;
    for (int i = 0; i + t.size() - 1 < s.size(); i++)
    {
        bool tmp = true;
        for (int j = 0; j < t.size(); j++)
        {
            if (!(s[i + j] == t[j] || s[i + j] == '?'))
            {
                tmp = false;
                break;
            }
        }
        if (tmp)
        {
            index = i;
        }
    }

    if (index >= 0)
    {
        for (int i = index; i < index + t.size(); i++)
        {
            s[i] = t[i - index];
        }
        rep(i, s.size())
        {
            if (s[i] == '?')
                s[i] = 'a';
        }
    }
    else
    {
        s = "UNRESTORABLE";
    }
    cout << s << endl;
    return 0;
}

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

struct Edge {
    int to, id;
    Edge(int _to, int _id) : to(_to), id(_id) {}
};

int main() {
    int N; cin >> N;
    vector<vector<Edge>> G(N);
    for(int i = 0; i < N - 1; ++i) {
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].emplace_back(b, i);
        G[b].emplace_back(a, i);
    }

    vector<vector<int64_t>> path(N, vector<int64_t>(N));
    for(int i = 0; i < N; ++i) {
        auto dfs = [&](auto &&dfs, int cur, int pre, int64_t S) -> void {
            for(auto &e : G[cur]) {
                if(e.to == pre) continue;
                path[i][e.to] |= S;
                path[i][e.to] |= (1LL << e.id);
                dfs(dfs, e.to, cur, path[i][e.to]);
            }
        };
        dfs(dfs, i, i, 0);
    }

    int M; cin >> M;
    vector<int64_t> mask(M);
    for(int i = 0; i < M; ++i) {
        int u, v; cin >> u >> v;
        u--, v--;
        mask[i] = path[u][v];
    }

    int64_t ans = 0;
    for(int bit = 0; bit < (1 << M); ++bit) {
        int64_t S = 0;
        for(int i = 0; i < M; ++i) {
            if(bit & (1 << i)) S |= mask[i];
        }
        int c = __builtin_popcount(bit);
        int p = __builtin_popcountll(S);

        int64_t res = 1LL << (N - 1 - p);
        if(c % 2 == 0) ans += res;
        else ans -= res;
    }
    cout << ans << '\n';
    return 0;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

//! 3^n%MOD
ll P[100005];

int main()
{
    string L;
    cin >> L;
    ll N = L.length();

    ll ans = 1;
    REP(i, N)
    {
        ans = (ans * 3LL) % MOD;
    }
    P[0] = 1;
    REP(i, N)
    {
        P[i + 1] = (P[i] * 3LL) % MOD;
    }

    ll t = 1;
    REP(i, N)
    {
        if (L[i] == '1')
        {
            t = (t * 2LL) % MOD;
            continue;
        }

        ans = (ans + MOD - (t * 2LL * P[N - 1 - i]) % MOD) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1280
def numinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    n = int(input())
    a = numinput()
    print('%d %d %d' % (min(a), max(a), sum(a)))

if __name__ == "__main__":
    main()


Measured memory_bytes: 6336
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    int n,k;
    cin>>n>>k>>s;
    int a[500000]={};
    a[0]=1;
    int j;
    for(int i=1,j=0;i<n;i++){
        if(s.at(i-1)!=s.at(i)) j++;
        a[j]++;
    }
    int m=0;
    
    for(int i=0;i<n;i++){
        if(a[i]>0) m++;
    }
    int sum=0;
    int ans=0;
    if(s.at(0)=='1'){
        for(int i=0;i<=2*k;i++){
            sum+=a[i];
        }
        ans=sum;
        for(int i=0;i+2*k<=m+2;i+=2){
            sum+=a[i+2*k+1]+a[i+2*k+2]-a[i]-a[i+1];
            ans=max(ans,sum);
        }
    }
    else{
        for(int i=0;i<=2*k-1;i++){
            sum+=a[i];
        }
        ans=sum;
        sum+=-a[0]+a[2*k]+a[2*k+1];
        ans=max(sum,ans);
        for(int i=1;i+2*k<=m+2;i+=2){
            sum+=a[i+2*k+1]+a[i+2*k+2]-a[i]-a[i+1];
            ans=max(ans,sum);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 2432
#include <stdio.h>  
#include <string.h>  
#include <queue>  
#define MAX_W 1000  
#define MAX_H 1000  
#define MAX_N 9  
  
using namespace std;  
  
char m[MAX_H][MAX_W + 1];  
int w, h, n;  
int gx[MAX_N + 1], gy[MAX_N + 1];  
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};  
  
int bfs(int sx, int sy, int gx, int gy)  
{  
    int d[MAX_H][MAX_W];  
    memset(d, -1, sizeof(d));  
    queue<int> que;  
    que.push(sx * w + sy);  
    d[sx][sy] = 0;  
          
    while(que.size())  
    {  
        int x = que.front()/w, y = que.front()%w;  
        que.pop();  
        if(x == gx && y == gy)  
            break;  
  
        for(int di = 0; di < 4; ++di){  
            int nx = x + dx[di], ny = y + dy[di];  
            if(nx >= 0 && nx < h && ny >= 0 && ny < w && 'X' != m[nx][ny] && -1 == d[nx][ny]){  
                d[nx][ny] = d[x][y] + 1;  
                que.push(nx * w + ny);  
            }  
        }  
    }  
    return d[gx][gy];  
}  
  
void solve()  
{  
    int ans = 0;  
    for(int i = 0; i < n; i ++)  
        ans += bfs(gx[i], gy[i], gx[i + 1], gy[i + 1]);  
    printf("%d\n", ans);  
}  
  
int main()  
{  
    scanf("%d%d%d", &h, &w, &n);  
    for(int i = 0; i < h; i ++)  
        scanf("%s", m[i]);  
          
    for(int i = 0; i < h; i ++)  
        for(int j = 0; j < w; j ++){  
            if('1' <= m[i][j] && '9' >= m[i][j])  
                gx[m[i][j] - '0'] = i, gy[m[i][j] - '0'] = j;  
            else if('S' == m[i][j])  
                gx[0] = i, gy[0] = j;  
        }  
  
    if(w || h)  
        solve();  
    return 0;  
}  


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

int main() {
    int n;
    int a[1000]={};
    int v;
    int i;
    int j;
    int k;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<n;i++){
        if(i>0){cout<<" ";}
        cout<<a[i];
    }
        cout<<endl;
    for(i=1;i<n;i++){
        v=a[i];
        j=i-1;
        while(j>=0&&a[j]>v){
            a[j+1]=a[j];
            j--;
            a[j+1]=v;
        }
        for(k=0;k<n;k++){
        if(k>0){cout<<" ";}
        cout<<a[k];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#line 2 "cpplib/util/template.hpp"
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
#include<bits/stdc++.h>
using namespace std;
struct __INIT__{__INIT__(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}__INIT__;
typedef long long lint;
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define endl ('\n')
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
template<typename T>inline void numout(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i<INF/2?i:"INF";f=1;}cout<<endl;}
template<typename T>inline void numout2(T t){for(auto i:t)numout(i);}
template<typename T>inline void output(T t){bool f=0;for(auto i:t){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}
template<typename T>inline void output2(T t){for(auto i:t)output(i);}
template<typename T>inline void _output(T t){bool f=0;for(lint i=0;i<t.size();i++){cout<<f?"":" "<<t[i];f=1;}cout<<endl;}
template<typename T>inline void _output2(T t){for(lint i=0;i<t.size();i++)output(t[i]);}
#define rep(i,...) for(auto i:range(__VA_ARGS__)) 
#define rrep(i,...) for(auto i:reversed(range(__VA_ARGS__)))
#define repi(i,a,b) for(lint i=lint(a);i<(lint)(b);++i)
#define rrepi(i,a,b) for(lint i=lint(b)-1;i>=lint(a);--i)
#define irep(i) for(lint i=0;;++i)
inline vector<long long> range(long long n){vector<long long>v(n);iota(v.begin(),v.end(),0LL);return v;}
inline vector<long long> range(long long a,long long b){vector<long long>v(b-a);iota(v.begin(),v.end(),a);return v;}
inline vector<long long> range(long long a,long long b,long long c){if((b-a+c-1)/c<=0)return vector<long long>();vector<long long>v((b-a+c-1)/c);for(int i=0;i<(int)v.size();++i)v[i]=i?v[i-1]+c:a;return v;}
template<typename T>inline T reversed(T v){reverse(v.begin(),v.end());return v;}
#define all(n) begin(n),end(n)
#define dist(a,b,c,d) sqrt(pow(a-c,2)+pow(b-d,2))
template<typename T,typename E>bool chmin(T& s,const E& t){bool res=s>t;s=min<T>(s,t);return res;}
template<typename T,typename E>bool chmax(T& s,const E& t){bool res=s<t;s=max<T>(s,t);return res;}
const vector<lint> dx={1,0,-1,0,1,1,-1,-1};
const vector<lint> dy={0,1,0,-1,1,-1,1,-1};
#define SUM(v) accumulate(all(v),0LL)
template<typename T,typename ...Args>auto make_vector(T x,int arg,Args ...args){if constexpr(sizeof...(args)==0)return vector<T>(arg,x);else return vector(arg,make_vector<T>(x,args...));}
#line 2 "code.cpp"

int main(){
    lint n;
    cin>>n;
    cout<<1-n<<endl;
}


Measured memory_bytes: 3644
def gcd(x, y):
    while y != 0:
        x, y = y, x%y
    return x

def lcm(a, b):
    return a*b//gcd(a, b)

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

ac = int((A-1)//C)
ad = int((A-1)//D)
bc = int(B//C)
bd = int(B//D)

c = bc - ac
d = bd - ad

baisu = lcm(C,D)
a_baisu = int((A-1)//baisu)
b_baisu = int(B//baisu)
print(B-A+1-c-d+(b_baisu-a_baisu))

Measured memory_bytes: 38384
import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	n,k,q=map(int,input().split())
	A=[q-k]*n
	for i in range(q):
		A[int(input())-1]-=1

	for i in A:
		print("Yes" if i<0 else "No")




if __name__ == "__main__":
	main()


Measured memory_bytes: 6496