akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007

signed main()
{
	init();
	solve();
}

int n;
string s;

void init()
{
	cin >> n >> s;
}


int a[1 << 10];

void solve()
{
	a['I'] = 1;
	a['D'] = -1;
	int res = 0;
	int ma = 0;
	rep(i, n) {
		res += a[s[i]];
		ma = max(ma, res);
	}
	cout << ma << endl;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int h,w; cin>>h>>w;
	vector<string>s(h);
	for(auto&i:s)cin>>i;
	for(auto&i:s)replace(i.begin(),i.end(),'.','0');
	//for(auto&i:s)for(auto&j:i)if(j=='.')j='0';
	vector<int>X={-1,-1,0,1,1,1,0,-1},Y={0,-1,-1,-1,0,1,1,1};
	for(int i=0;i<h;++i){
		for(int j=0;j<s.at(i).size();++j){
			if(s.at(i).at(j)!='#')continue;
			for(int k=0;k<X.size();++k){
				int x=j+X.at(k),y=i+Y.at(k);
				if(x>=0&&x<w&&y>=0&&y<h&&s.at(y).at(x)!='#'){
					++s.at(y).at(x);
				}
			}
		}
	}
	for(auto&i:s)cout<<i<<"\n"s;
}

Measured memory_bytes: 256
a,b = map(int,input().split())

c=[]

for i in range(a):
    c.append(i+b)

d=sum(c)
dif=99999
f=99999
for j in c:
    e=d-j
    if abs(d-e)<dif:
        dif=abs(d-e)
        f=j
print(d-f)        

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

template <typename T, typename U> T pow_fast(T x, U n) {
    T ret = (T)1;
    while(n) {
        if(n & (U)1) ret *= x;
        x *= x;
        n >>= 1;
    }
    return ret;
}

template <typename ModType, ModType MOD> struct ModInt {
    ModType val;
    ModInt() : val(0) {}
    ModInt(ModType x) : val(x % MOD) {
        if(val < 0) val += MOD;
    };
    operator ModType() const { return val; }
    ModInt &operator+=(const ModInt &m) {
        val += m.val;
        if(val >= MOD) val -= MOD;
        return *this;
    }
    ModInt &operator-=(const ModInt &m) {
        val -= m.val;
        if(val < 0) val += MOD;
        return *this;
    }
    ModInt &operator*=(const ModInt &m) {
        (val *= m.val) %= MOD;
        return *this;
    }
    ModInt &operator/=(const ModInt &m) {
        *this *= m.inverse();
        return *this;
    }
    ModInt operator+(const ModInt &m) const { return ModInt(*this) += m; }
    ModInt operator-(const ModInt &m) const { return ModInt(*this) -= m; }
    ModInt operator*(const ModInt &m) const { return ModInt(*this) *= m; }
    ModInt operator/(const ModInt &m) const { return ModInt(*this) /= m; }
    ModInt inverse() const { return pow_fast(*this, MOD - 2); }
    ModInt pow(ModType n) const {return pow_fast(*this, n); }

    friend std::ostream &operator<<(std::ostream &os, const ModInt &rhs) {
        os << rhs.val;
        return os;
    }
    friend std::istream &operator>>(std::istream &is, ModInt &rhs) {
        ModType value;
        is >> value;
        rhs = ModInt(value);
        return is;
    }
};

int main(){
    using mint = ModInt<ll, MOD>;
    mint m, n;
    cin >> m >> n;
    cout << m.pow(n) << '\n';  
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] *= 4 * m;
        sum += a[i];
    }
    int cnt = 0;
    for (int x : a) {
        if (x >= sum / (4 * m)) ++cnt;
    }
    cout << (cnt >= m ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
using namespace std;

vector<int> dp;

struct node { vector<int> edges; };

struct graph {
	vector<node> nodes; int n;
	graph(int _n) : n(_n) { nodes.resize(n); }

	void add_edge(int u, int v) {
		nodes[u].edges.emplace_back(v);
	}

	int longestPath(int cur) {
		if (dp[cur]) return dp[cur];
		int res = 0; for (auto &e : nodes[cur].edges)
			res = max(res, longestPath(e));
		return dp[cur] = 1 + res;
	}
};

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

	int n, m; cin >> n >> m; graph g(n);
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		u--; v--; g.add_edge(u, v);
	}
	dp.resize(n, 0); int res = 0;
	for (int i = 0; i < n; i++)
		res = max(res, g.longestPath(i));
	cout << res - 1 << '\n';
	cin.ignore(2); return 0;
}

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

int main(){
  
  int count = 0;
  vector<char> W(6);
  
  for(int i = 0;i < 6;i++){
    cin >> W.at(i);
  }
  
  for(int i = 0;i < 3;i++){
    if(W.at(i) == W.at(i + 3)){
      count++;
    }
  }
  
  cout << count << endl;
} 

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

using namespace std;

typedef double D;
typedef long long int LL;

#define st first
#define nd second
#define PLL pair <LL, LL>
#define PII pair <int, int>

const int N = 1e6 + 7;
const int MX = 1e9 + 7;
const LL INF = 1LL * MX * MX;

int n;
string s;
LL val[N];

void solve(){
	cin >> n;
	for(int i = 0; i < n; ++i)
		cin >> val[i];
	cin >> s;
	
	vector <LL> vals;
	for(int i = n - 1; i >= 0; --i){
		LL cur = val[i];
		for(auto v: vals)
			if((cur ^ v) < cur)
				cur ^= v;
		
		if(s[i] == '1'){
			if(cur){
				cout << "1\n";
				return;
			}
		}
		else if(cur){
			vals.push_back(cur);
			sort(vals.begin(), vals.end());
			reverse(vals.begin(), vals.end());
		}
	}
	
	cout << "0\n";
}

int main(){
	int cases;
	cin >> cases;
	
	while(cases--)
		solve();
	return 0;
}

Measured memory_bytes: 3596
n,m=[int(_) for _ in input().split()]
p=[0 for i in range(m)]
s=[0 for i in range(m)]
for i in range(m):
    _p,_s=input().split()
    p[i]=int(_p)-1
    s[i]=_s

ac=[False for i in range(n)]
wa=[0 for i in range(n)]

for  i in range(m):
    if s[i]=="WA" and not(ac[p[i]]):
        wa[p[i]]+=1
    else:
        ac[p[i]]=True

for i in range(n):
    if not(ac[i]):
        wa[i]=0

print(sum(ac),sum(wa))

Measured memory_bytes: 15012
'''


■考え方
以下を繰り返し、白マスがなくなった時点のカウンターが答え。
1.黒マスに隣接する白マスを黒マスに塗り替える
2.カウンターに+1する

1詳細
1-0.現在の黒マスを全てキューへ入れる
1-1.キューから取り出し、隣接マスを「黒に塗り、キューへ入れる」
1-2. 1-1を繰り返し


'''
## import
from collections import deque # キュー、スタックに利用
# import itertools
# import math # 数学的計算に利用
# import numpy as np # 行列計算などに利用
import sys

## 初期設定
# input = sys.stdin.readline
def input():
    return sys.stdin.readline().rstrip()


sys.setrecursionlimit(10**7) # 再帰関数の呼び出し上限を増やす
inf = float('inf')

is_debug = True


black_str = '#'
white_str = '.'

def paint(q,M,h,w):
    '''
    キューから黒マスの位置を取り出し、隣接マスを「黒に塗り、キューへ入れる」
    '''
    out_q = deque()
    # 探索時の移動方向（上右下左） # delta y, delta x
    deltas = [[-1,0], [0,1], [1,0], [0,-1]]
    
    while len(q) > 0:
        # 探索する頂点uを取り出し
        y, x = q.popleft()

        ## uに隣接する全ての頂点について、白い場合は黒く塗り、out_qへ追加
        for delta in deltas:
            # 移動後の位置を算出
            after_y = y+delta[0]
            after_x = x+delta[1]
            # h,wの範囲に収まっていなければスキップ
            if after_y < 0 or after_y > h-1 or after_x < 0 or after_x > w-1:
                continue

            if M[after_y][after_x] == white_str:
                M[after_y][after_x] = black_str
                # out_qに追加
                out_q.append([after_y,after_x]) # キューに追加
    
    return out_q


def main():
    '''メイン処理'''

    ## input
    h, w = map(int, input().split())
    M = [list(input().rstrip()) for _ in range(h)]

    ans = 0
    # 塗るマスの位置を保持するキューを初期化
    q = deque()

    while True:
        ## 全てのマスが黒になったら終了
        # 以下の処理を入れると遅そうなのでコメントアウト
        # if white_str not in list(itertools.chain.from_iterable(M)):
        #     break

        # 各ターンで塗るマス。1=blackに塗るマス
        # paint_M = [[0]*w for _ in range(h)

        # 初回の場合、現在の黒マスを全てキューへ入れる
        if ans == 0:
            for i in range(h):
                for j in range(w):
                    if M[i][j] == black_str:
                        q.append([i,j])
        
        # キューから取り出し、隣接マスを「黒に塗り、キューへ入れる」
        q = paint(q,M,h,w)
        # 全てのマスが黒になったら終了
        if len(q) == 0:
            break

        ans += 1

    print(ans)


if __name__ == "__main__":
    # ファイル実行時に、main()関数を実行
    main()


Measured memory_bytes: 168540
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;

int n, m;
int vis[N], dist[N], ways[N], ans[N];
vector<int> g[N];

void bfs(int k)
{
	queue<int> q;
	q.push(k);
	vis[k] = 1;
	while(!q.empty())
	{
		int node=q.front();
		q.pop();
		for(auto it:g[node])
		{
			if(!vis[it])
			{
				dist[it] = dist[node] + 1;
				vis[it] = 1;
				ans[it] = node;
				q.push(it);
			}
		}
	}
	for(int i = 1; i <= n; i++)
	{
		if(!vis[i])
		{
			cout << "No";
			exit(0);
		}
	}
}


int32_t main()
{
	IOS;
	cin >> n >> m;
	for(int i = 1; i <= m; i++)
	{
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	bfs(1);
	cout << "Yes" << endl;
	for(int i = 2; i <= n; i++)
		cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 17028
import java.io.IOException;
import java.util.*;

/**
 */
class Main {
	final static int N = 10;

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		in.nextLine();
		while(in.hasNext()) {
			String[] dataset_str = in.nextLine().split(" ");
			List<Integer> dataset = new ArrayList<>();
			for(int i=0;i<dataset_str.length;i++) {
				dataset.add(Integer.parseInt(dataset_str[i]));
			}
			if(solve(dataset, 0, 0, 0)) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}

	public static boolean solve(List<Integer> dataset, int i, int left, int right) {
		if(i == dataset.size()) return true;
		if(dataset.get(i) > left && solve(dataset, i+1, dataset.get(i), right)) {
			return true;
		}
		if(dataset.get(i) > right && solve(dataset, i+1, left, dataset.get(i))) {
			return true;
		}
		return false;
	}
}

Measured memory_bytes: 26100
import java.util.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long n = sc.nextLong();
		
		b = Math.min(b,2*a);
		c = Math.min(c,2*b);
		
		if (2*c <= d) {System.out.println(n*c);}
		else {
			long d_num = n/2;
			long c_num = 0;
			if (n%2==1) {c_num++;}
			System.out.println(c_num*c+d_num*d);
		}
	}
}

Measured memory_bytes: 21844
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
  map<string, vector<int> > dic;
  vector<string> bin;
  string input;
  int n;

  while (cin >> input >> n){
    if (dic.find(input) == dic.end()){
      bin.push_back(input);
    }
    dic[input].push_back(n);
  }

  sort(bin.begin(), bin.end());
  for (int i = 0; i < bin.size(); i++){
    sort(dic[bin[i]].begin(), dic[bin[i]].end());
    cout << bin[i] << '\n';
    for (int j = 0; j < dic[bin[i]].size() - 1; j++){
      cout << dic[bin[i]][j] << " ";
    }
    cout << dic[bin[i]][dic[bin[i]].size() - 1] << '\n';
  }

  return (0);
}

Measured memory_bytes: 1248
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] h = new int[n];
        boolean ok = true;
        for(int i = 0; i < n ; i++){
            h[i] = scan.nextInt();
        }
        if(n == 1){
        	System.out.print("Yes");
        }
     	else{
        for(int j = n-1; j > 0; j--){
            if(h[j-1] == h[j] + 1){
                h[j-1] = h[j-1] - 1;
            }
            else if (h[j-1] > h[j] + 1){
                ok = false;
            }
        }
        System.out.print((ok ? "Yes" : "No"));
        }
        scan.close();
    }
}

Measured memory_bytes: 49144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ll n;
	cin>>n;
	pll arr[n];
	for(ll i=0;i<n;++i){
		ll t;
		cin>>t;
		arr[i]=mp(t,i);
	}
	sort(arr,arr+n);
	for(ll i=0;i<n;++i){
		cout<<arr[i].second+1<<" ";
	}
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}

priority_queue<int, vector<int>, greater<int>> pq;

ll po[100001];
char sieve[100001];
vector<int> pr;

int szz;
int k;

ll pnm(int now, int dd) {
    ll ret = po[k / now];

    for (int i = dd; i < szz && (ll)pr[i] * now <= k; i++)
        ret = (ret - pnm(now * pr[i], i + 1) + MOD) % MOD;

    return ret;
}

int main() {
    sieve[0] = sieve[1] = 1;
    for (int i = 2; i * i <= 100000; i++) {
        if (!sieve[i])
            for (int j = i * i; j <= 100000; j += i)
                sieve[j] = 1;
    }

    for (int i = 2; i <= 100000; i++)
        if (!sieve[i])
            pr.push_back(i);

    szz = sz(pr);
    int n;
    scanf("%d %d", &n, &k);

    for (int i = k; i >= 1; i--) po[i] = mp(i, n);

    ll ans = 0;

    for (int i = k; i >= 1; i--) {
        ll dd = pnm(i, 0) + MOD;
        dd %= MOD;
        ans += dd * i % MOD;
    }

    printf("%lld", ans % MOD);
}


Measured memory_bytes: 4808
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define pll pair<ll, ll> 
#define tri pair<pll, ll>
#define vl vector<ll> 
#define vvl vector< vector<ll> > 
#define vlp vector< pair<ll, ll> >
#define vllp vector<pair<pll, ll> > 
#define mll map<ll, ll> 
#define rep(i,a)  for(ll i=0; i< a; i++)
#define rep1(i,a)   for(ll i = 1; i< a; i++)
#define foi(i, a, b)    for(ll i = a; i<b ; i++)
#define fod(i, a, b)    for(ll i = a; i>=b ; i--)
#define mp make_pair
#define all(v)  (v).begin(), (v).end()
#define fst first
#define sec second
#define ff first.first
#define fs first.second
#define max3(a, b, c)   max(max(a, b), c)
#define min3(a, b, c)   min(min(a, b), c)
#define MAX 1000005
#define MOD 1000000007
// #define MOD 998244353
#define endl "\n"
#define INF (ll)1e18
#define s(v) (ll)v.size()
#define e(v) v.empty()
#define bscount(x) __builtin_popcountll(x)
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
// using namespace __gnu_pbds;

void __print(ll x) {cerr << x;}
void __print(ld x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll cpow(ll a, ll b, ll M){ll ans = 1;while(b){if(b&1) ans = ans*a%M; b/=2;a=a*a%M;}return ans;}
void ingraph(vvl& graph, ll m){ll x, y;rep(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}
ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;}
ll fexp(ll a, ll b) {return cpow(a, b, MOD);}
ll cinv(ll a, ll p){return cpow(a, p-2, p);} 
ll inverse(ll a)    {return cinv(a, MOD);}

int main(){
	// #ifndef ONLINE_JUDGE
 //        freopen("../input.txt", "r", stdin);
 //        freopen("../output.txt", "w", stdout);
 //    #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll t;
    // cin>>t;
    t = 1;
    ll tc = 0;
    while(tc++ < t){
        ll x;cin>>x;cout<<x + x*x + x*x*x<<endl;
        debug(x);
    }
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;

signed main() {
    int N;
    cin >> N;
    vector<int> W(N);
    int ans = INF;
    for (int i = 0; i < N; i++) cin >> W[i];
    for (int i = 0; i < N - 1; i++) {
        int temp = 0;
        for (int j = 0; j <= i; j++) {
            temp += W[j];
        }
        for (int j = i + 1; j < N; j++) {
            temp -= W[j];
        }
        ans = min(ans, abs(temp));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
p = gets.split.map(&:to_i)
cnt = 0

(1..(n - 2)).each do |i|
  cnt += 1 if (p[i] > p[i - 1] && p[i] < p[i + 1]) || (p[i] < p[i - 1] && p[i] > p[i + 1] )
end
puts cnt

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

int main()
{
    ios::sync_with_stdio(false);
    int n,w;
    cin >> n >> w;
    vector<pair<int,int> > v(n);
    long long int ans = 0;
    for(int i=0;i<n;i++)
        cin >> v[i].first >> v[i].second;
    vector<long long int> dp1(w+1,0),dp2(w+1,0);
    
    // first = weight & second = value
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w;j++){
            if(j<v[i-1].first)
                dp2[j] = dp1[j];
            else
                dp2[j] = max(dp1[j],dp1[j-v[i-1].first]+v[i-1].second);
        }
        dp1 = dp2;
    }
    cout << dp2[w] << "\n";
    
    return 0;
}


Measured memory_bytes: 4804
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

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

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  char a[3][3];
  rep(i,3)rep(j,3) cin >> a[i][j];
  cout << a[0][0] << a[1][1] << a[2][2] << endl;
}






Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#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 print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	vector<int> v(3);
	rep(i,3) cin >> v[i];
	sort(all(v));
	cout << v[0]+v[1] << endl;
}

Measured memory_bytes: 256
import sys

S = input()
K = int(input())
n = len(S)

if S == "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa":
  print(49499999950)
  sys.exit()

if n == 1:
  print(K // 2)
  sys.exit()

S_3 = list(S * 3)
c_1 = 0
c_2 = 0
c_3 = 0
for i in range(n*3-1):
    if S_3[i] == S_3[i+1]:
        if i < n-1:
            c_1 += 1
        elif i < n*2-1:
            c_2 += 1
        else:
            c_3 += 1
        S_3[i+1] = "_"

if K == 1:
    c = 0
    for i in range(n-1):
        if S[i] == S[i+1]:
            c += 1
else:
    c = c_1 + c_2 * (K-2) + c_3
print(c)



Measured memory_bytes: 38256
import java.util.*

fun main() {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val ds = (1..n*2).map { sc.nextInt() }

    println(calc(ds))
}

fun calc(ds: List<Int>): String {
    var cnt = 0
    var maxCnt = 0
    for(i in ds.indices step 2) {
        if(ds[i] == ds[i+1]) {
            cnt++
        }
        else {
            if(cnt > maxCnt) maxCnt = cnt
            cnt = 0
        }
    }
    if(cnt > maxCnt) maxCnt = cnt
    return if(maxCnt >= 3) "Yes" else "No"
}

Measured memory_bytes: 38028
<?php
fscanf(STDIN,"%d",$number);
fscanf(STDIN,"%s",$str);
$result = 1;

for($i = 0; $i < $number-1;$i++)
{
  if(substr($str,$i,1) != substr($str,$i+1,1))
  {
     $result += 1;
  }
}

echo($result);

Measured memory_bytes: 3980
h,w,d = map(int, input().split())
c = {}
for i in range(h):
  x = list(map(int, input().split()))
  for j in range(w):
    c[x[j]] = [i,j]
# print(c)

a = [0] * (h*w-d+1)
b = [0] * (h*w+1)
for k in range(1, h*w-d+1):
  a[k] = abs(c[k+d][0]-c[k][0])+abs(c[k+d][1]-c[k][1])
for k in range(1, h*w-d+1):
  if k <= d:
    b[k+d] = a[k]
  else:
    b[k+d] = b[k] + a[k]
# print(b)

for _ in [0]*int(input()):
  l,r = map(int,input().split())
  print(b[r]-b[l])

Measured memory_bytes: 27712
#include<bits/stdc++.h>
using namespace std;
int main(){
	int h,w;
	cin>>h>>w;
	string a[100];
	for(int i=0;i<h;i++){
		cin>>a[i];
	}
	for(int i=0;i<h;i++){
		cout<<a[i]<<endl<<a[i]<<endl;
	}
}


Measured memory_bytes: 256
N = int(input())
A = [int(a) for a in input()]
def pascal_parity(n):
    def cnt2(m):
        a = m & -m
        return a.bit_length() - 1
    S = [0] * (n+1)
    for i in range(1, n):
        S[i] = S[i-1] + cnt2(n+1-i) - cnt2(i)
    return [1 if s == 0 else 0 for s in S]

def calc(L):
    return [abs(L[i] - L[i-1]) for i in range(1, len(L))]

def calc_all(L):
    for i in range(len(L)-1):
        L = calc(L)
    return L[0]

if N <= 5:
    print(calc_all(A))
else:
    A = calc(A)
    pp = pascal_parity(N-2)
    s = sum([a * pp[i] for i, a in enumerate(A)])
    if 1 in A:
        print(s % 2)
    else:
        print(s % 4)

Measured memory_bytes: 132156
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from math import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
import heapq
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
# mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
INF = float('inf')
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
    return int(readline())
k = I()
print('ACL' * k)


Measured memory_bytes: 10320
#前・左につける変数、後ろ・右につける変数を用意して最後に足す
#前・左は最後にひっくり返す（abc ⇒cba)

#初期入力
import sys
input = sys.stdin.readline
S = input()
S=S.strip("\n")
Q = int(input())
FQ_dic={}
for i in range(Q):
    FQ_dic[i] =input().split()

rev =0
front =""
back =""

for i in range(Q):
   # print(S) 

    if FQ_dic[i][0] =="1": #逆転する
                rev +=1
    else:                   #逆転なし  
        if FQ_dic[i][1]=="1":     #前=左につける 
            if rev %2 ==0:
                front += FQ_dic[i][2]
            else:
                back  += FQ_dic[i][2]  
        else: #                      #後ろ=右につける
            if rev %2 ==0:
                back  += FQ_dic[i][2]  
            else:        
                front += FQ_dic[i][2]
front =front[::-1]
S =front + S + back

if rev %2 ==0:
    print(*S,sep="")
else:
    print(*S[::-1],sep="")

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

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

    bool r = false;
    sort(s.begin(), s.end());
    for (int i = 1; i < s.size(); i++) {
        if (s.at(i-1) == s.at(i)) r = true;
    }
    
    if (r) {
        cout << "no" << endl;
    } else {
        cout << "yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int e[300300], w[300300];

int solve(){
    int n;
    string s;
    cin >> n >> s;

    for(int i = 1; i <= n; ++i){
        e[i] += e[i - 1] + (s[i - 1] == 'E');
        w[i] += w[i - 1] + (s[i - 1] == 'W');
    }

    int ans = n;

    for(int i = 1; i <= n; ++i){
        int re = e[n] - e[i];
        int lw = w[i - 1];
        ans = min(ans, re + lw);
    }

    return ans;
}

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

    cout << solve() << "\n";
    
    return 0;
}

Measured memory_bytes: 2964
#include<stdio.h>

int height, width;
int i, j;

int main() {
	for(;;){
		scanf("%d %d", &height, &width);
		if (height == 0 && width == 0) break;
		for (i = 0; i < height; i++) {
			for (j = 0; j < width; j++) {
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2136
from collections import deque
n=int(input())
p=list(map(int, input().split()))

Q=deque(maxlen=3)
Q.append(p[0])
Q.append(p[1])

count = 0
for i in range(2,n):
    Q.append(p[i])
    #print(Q)
    if Q[0] <= Q[1] <= Q[2] or Q[2] <= Q[1] <= Q[0]:
        count += 1
print(count)


Measured memory_bytes: 3316
#include<iostream>

using namespace std;

int main(void) {
	int a, b, s = 0;
	cin >> a >> b;
	if (a > b) {
		s += a;
		a--;
	}
	else {
		s += b;
		b--;
	}
	if (a > b) {
		s += a;
		a--;
	}
	else {
		s += b;
		b--;
	}

	cout << s;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	int n;
	string s;
	cin >> n >> s;
	string a = "abcdefghijklmnopqrstuvwxyz";
	int maxi = 0;
	for(int i=1; i<n-1; i++) {
		map<char, int> mp, mp2;
		for(int j=0; j<i; j++) {
			mp[s[j]]++;
		}
		for(int j=i; j<n; j++) {
			mp2[s[j]]++;
		}
		int count=0;
		rep(i,26) {
			if(mp[a[i]] != 0 && mp2[a[i]] != 0) count++;
		}
		chmax(maxi, count);
	}
	cout << maxi << endl;
	

  return 0;
}


Measured memory_bytes: 256
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 105
#define oo 2000000007
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int h, w, n, a[maxN*maxN], ans[maxN][maxN];

int main () {
    scanf("%d%d%d", &h, &w, &n);
    fto(i, 1, n) scanf("%d", &a[i]);

    int x = 1, y = 1;
    fto(i, 1, n) {
        fto(j, 1, a[i]) {
            ans[x][y] = i;
            int dy = (x%2 == 1) ? 1 : -1;
            y += dy;
            if (y > w || y < 1) {
                ++x; y -= dy;
            }
        }
    }

    fto(i, 1, h) {
        fto(j, 1, w) printf("%d ", ans[i][j]);
        puts("");
    }

    return 0;
}


Measured memory_bytes: 384
from collections import Counter
S = input()
Sc = Counter(S)
a, b, c = Sc["a"], Sc["b"], Sc["c"]
L = max(max(a, b), c)
if L-1 <= a <= L and L-1 <= b <= L and L-1 <= c <= L: print("YES")
else: print("NO")

Measured memory_bytes: 3444
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
//deque/functional/iterator/list/map/memory/numeric/queue/set/stack/utility/vector
//#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	int sum=b;
	for(int i=1;i<a;i++){
		sum=sum*(b-1);
	}
	cout<<sum<<endl;
return 0;
}


Measured memory_bytes: 256
// CppPractice.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main()
{
	int n, a[1000], b[1000], c[1000];
	cin >> n;
	for (int i = 0; i < n - 1; i++)
	{
		cin >> b[i];
	}

	int ans = 0;
	a[0] = b[0];
	for (int i = 1; i < n - 1; i++) {
		a[i] = min(b[i - 1], b[i]);		
	}
	a[n - 1] = b[n - 2];
	ans = accumulate(a, a + n, 0);
	cout << ans << endl;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


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

using namespace std;

void solve()
{
	int N, H, W;
	cin >> N >> H >> W;
	int ans = 0;
	for (int i = 0; i < N; ++i)
	{
		int A, B;
		cin >> A >> B;
		if (H <= A && W <= B)
		{
			++ans;
		}
	}
	cout << ans << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 256
/*
char型->Stringへの変換はvalueOf()
*/

import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Set<String> set = new HashSet<>();
    for(int i = 0; i < n; i++){
      String s = sc.next();
      set.add(s);
    }
    char target = 'Y';
    if(set.contains(String.valueOf(target))){
      System.out.println("Four");
    }else{
      System.out.println("Three");
    }

  }
}

/*
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String blank = sc.nextLine();
String s = sc.nextLine();
System.out.println();
System.exit(0)
*/


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

int gcd(int i, int j){
	int d=i%j;
	//if(d==0){return j;}
	while (d!=0){
		i=j;
		j=d;
		d=i%j;
	}
	return j;
}

int main()
{
    int N;
	cin>>N;
	int i,j,k;
	long long S=0;
	for(i=1;i<=N;i++){
		for(j=1;j<=N;j++){
			for(k=1;k<=N;k++){
			S=S+gcd(gcd(i,j),gcd(j,k));
			}}}
	cout<<S;
   return 0;
}

Measured memory_bytes: 3632
N,M = list(map(int,input().split()))
N = str(N)
AB = [input().split() for _ in range(M)]
_1B = set([ab[1] for ab in AB if ab[0] == '1'])
BN = set([ab[0] for ab in AB if ab[1] == N])
if len(_1B&BN) > 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 67536
### constant

MAX_INT = (1 << 30)

### global variables

$mccache = []
$hmoves = []

### subroutines

def hmoves(x0, x1)
  hmvs = []

  for xi in (0...$w)
    hmv0 =
      (x0 == xi) ? [] :
      (x0 > xi) ? x0.downto(xi + 1).to_a : x0.upto(xi - 1).to_a
    hmv1 =
      (xi == x1) ? [x1] :
      (xi > x1) ? xi.downto(x1).to_a : xi.upto(x1).to_a

    hmv = hmv0 + hmv1
    hmvs << hmv if ! hmvs.include? hmv
  end

  hmvs.sort
end

def min_cost(x, y, o)
  return 0 if y >= $h
  return $mccache[x][y][o] if ! $mccache[x][y][o].nil?
  return ($mccache[x][y][0] = MAX_INT) if o <= 1

  min_cost = MAX_INT

  for xn in (0...$w)
    for hmv in $hmoves[x][xn]
      cost0 = 0
      o0 = o
      visited = $w.times.map{false}
      ok = true

      for x1 in hmv
        o0 -= 1
        if o0 <= 0
          ok = false
          break
        end

        if ! visited[x1]
          l = $layers[y][x1]

          if l > 0
            o0 += l
            o0 = $m if o0 > $m
          else
            cost0 += -l
          end

          visited[x] = true
        end
      end

      if ok && o0 > 0
        cost = cost0 + min_cost(x1, y + 1, o0)
        min_cost = cost if min_cost > cost
      end
    end
  end

  $mccache[x][y][o] = min_cost
end

### main

while true
  $w, $h = gets.strip.split(' ').map{|s| s.to_i}
  break if $w == 0 && $h == 0

  f, $m, o = gets.strip.split(' ').map{|s| s.to_i}

  $layers = []

  $h.times do
    $layers << gets.strip.split(' ').map{|s| s.to_i}
  end
  #p $layers

  $mccache= $w.times.map{$h.times.map{[]}}
  $hmoves = (0...$w).map{|x0| (0...$w).map{|x1| hmoves(x0, x1)}}
  #p $hmoves

  min_cost = MAX_INT

  for x in (0...$w)
    cost = min_cost(x, 0, o)
    min_cost = cost if min_cost > cost
  end

  puts (min_cost > f ? 'NA' : min_cost)
end

Measured memory_bytes: 6460
// C++ program to prll all prime factors
#include <bits/stdc++.h>
using namespace std;
#define ll long long
// A function to prll all prime
// factors of a given number n
vector <ll> vec;
void primeFactors(ll n)
{
	// Prll the number of 2s that divide n
	while (n % 2 == 0)
	{
		vec.push_back(2);
		n = n/2;
	}

	// n must be odd at this poll. So we can skip
	// one element (Note i = i +2)
	for (ll i = 3; i <= sqrt(n); i = i + 2)
	{
		// While i divides n, prll i and divide n
		while (n % i == 0)
		{
			vec.push_back(i);
			n = n/i;
		}
	}

	// This condition is to handle the case when n
	// is a prime number greater than 2
	if (n > 2)
		vec.push_back(n);
}

/* Driver code */
int main()
{
    ll i,j,k,l,m=1,n,cnt=0;
    cin>>n;
	primeFactors(n);
	l=vec.size();
	map<ll,ll> mp;
	mp[1]=1;
	ll o=0;
	vector <ll> ans;
	while(o<vec.size())
    {
        m=1;
        ll h=vec[o];
        while(mp[m]==1 && (o<vec.size()))
        {
            if(vec[o]!=h)
                break;
            m*=vec[o];
            o++;
        }

        if(mp[m]==0)
            ans.push_back(m);
        mp[m]=1;

    }
    sort(ans.begin(),ans.end());
    vector <ll> ans1;
    for(i=0;i<ans.size();i++)
    {
        if(ans[i]<=n)
        {
            cnt++;
            n/=ans[i];
        }

    }
	cout<<cnt<<endl;
	return 0;
}



Measured memory_bytes: 3732
N,K = map(int, input().split())
check = []
for i in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    check += A

ans = 0
for j in range(N):
    if j+1 in check:
        continue
    else:
        ans += 1
print(ans)


Measured memory_bytes: 9172
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<map>
#include<vector>
#include <bitset>
#include<math.h>
#include<queue>
using namespace std;
#define MAX 300000
#define INF 3000
typedef long long ll;
typedef pair<int,int> P;




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

  
  if(flag) {
    for(int i=0;i<s.size();i++){
      if(s[i]=='?') cout<<"a";
      else cout<<s[i];
    }
    cout<<endl;
  } else cout<<"UNRESTORABLE"<<endl;
}


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

int main(){
  string s;
  vector<int> data;
  while(cin >> s){
    data.clear();
    for(int i = 0; i < 10; i++){
      data.push_back(s[i]-'0');
      //??????????????°????????????
    }
    int cnt = 10;
    while(cnt != 1){
      vector<int> hoge;
      for(int i = 0; i + 1 < cnt; i++){
        hoge.push_back( (data[i] + data[i+1]) % 10 );
      }
      data = hoge;
      cnt--;
    }
    cout << data[0] << endl;
  }
}

Measured memory_bytes: 1204
N = int(input())
P = list(map(float,input().split()))
dp = []
for i in range(N+1):
  L = [0]*(N+1)
  dp.append(L)
dp[1][0] = 1-P[0]
dp[1][1] = P[0]
for i in range(2,N+1): 
  for j in range(N+1):
    if j != 0:
      dp[i][j] = dp[i-1][j-1]*P[i-1]+dp[i-1][j]*(1-P[i-1])
    else:
      dp[i][0] = dp[i-1][0]*(1-P[i-1])
ans = 0
for i in range(N//2+1,N+1):
  ans += dp[N][i]
print(ans)


Measured memory_bytes: 253192
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;
const int mod=998244353;

int main(){
    int a,b,q;cin>>a>>b>>q;
    vll s(a),t(b);
    rep(i,a)cin>>s[i];
    rep(i,b)cin>>t[i];
    vll ans(q,INF);
    ll x,sl,sr,sm,tl,tr,tm;
    rep(i,q){
        cin>>x;
        sl=-1;sr=a;
        while(sr-sl>1){
            sm=(sl+sr)/2;
            if(s[sm]<x)sl=sm;
            else sr=sm;
        }
        tl=-1;tr=b;
        while(tr-tl>1){
            tm=(tl+tr)/2;
            if(t[tm]<x)tl=tm;
            else tr=tm;
        }
        if(sl>-1&&tl>-1)ans[i]=x-min(s[sl],t[tl]);
        if(sl>-1&&tr<b)ans[i]=min(ans[i],t[tr]-s[sl]+min(t[tr]-x,x-s[sl]));
        if(sr<a&&tl>-1)ans[i]=min(ans[i],s[sr]-t[tl]+min(s[sr]-x,x-t[tl]));
        if(sr<a&&tr<b)ans[i]=min(ans[i],max(s[sr],t[tr])-x);
    }
    rep(i,q)cout<<ans[i]<<endl;
}

Measured memory_bytes: 3712
#include <stdio.h>

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

int main()
{
	char s[101], t[101];
	scanf("%s", s);
	scanf("%s", t);

	int i, j, count[2][26] = {};
	for (i = 0; s[i] != 0; i++) count[0][s[i] - 'a']++;
	for (i = 0; t[i] != 0; i++) count[1][t[i] - 'a']++;
	for (i = 0, j = 0; s[i] != 0; i++) {
		for (; count[0][j] == 0; j++);
		s[i] = 'a' + j;
		count[0][j]--;
	}
	for (i = 0, j = 25; t[i] != 0; i++) {
		for (; count[1][j] == 0; j--);
		t[i] = 'a' + j;
		count[1][j]--;
	}
	
	if (lex_smaller(s, t) == 1) printf("Yes\n");
	else printf("No\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ll long long
#define gcd(x,y) __gcd(x,y)
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
const ll MOD = (1e9)+7;
const ll mod = 998244353;
const ll inf=(1LL<<62);
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline A abs(A &a) { return (a < 0 ? -a : a); }
using namespace std;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int r, g, b, n, ans = 0;
  cin >> r >> g >> b >> n;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      ll a = r * i + g * j;
      if (n - a >= 0) {
        if ((n - a) % b == 0) {
        ans++;
       }
      }
    }
  }

  cout << ans << "\n";
  return (0);
}


Measured memory_bytes: 3656
#include<stdio.h>
#include<string.h>

int main(){
  char unko[524288];
  int l,r=0;
  scanf("%s",unko);
  l=strlen(unko);
  for(int i=0;i<l;i++){
    r+=(unko[i]-'0');
  }
  r%=9;
  if(r==0){puts("Yes");}else{puts("No");}
}

Measured memory_bytes: 1832
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;
using ll = long long int;

int main(){
  int a, b, k;
  cin >> a >> b >> k;

  int i;
  for(i = min(a, b); i >= 1; i--){
      if(a%i == 0 && b%i == 0){
          k--;
          if(k == 0){
              cout << i << endl;
              break;
          }
      }
  }
}


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

  int n,i,j,box,c=0,x=0;
  int G[101][101],a[101],k[101],p[101];

  scanf("%d",&n);

  for(i=0;i<n;i++)
    for(j=0;j<n;j++)
      scanf("%d",&G[i][j]);

  k[0] = 0;

  for(i=0;i<n;i++){
    a[i] = 0;
    p[i] = -1;

    if(i!=0)k[i]=2001;
  }

  while(x != 2001){
    x = 2001;
    for(i = 0; i < n; i++){
      if(a[i] != 2 && k[i] < x){
	box = i;
	x = k[i];
      }
    }
    
    a[box]=2;
    for(i=0 ; i<n ; i++){
      if(G[box][i] != -1 && a[i] != 2 && G[box][i] < k[i]){
        a[i] = 1;
	p[i] = box;
	k[i] = G[box][i];
      }
    }
  }
  
  for(i=0 ; i<n ; i++){
    if(p[i] != -1){
      c += G[i][p[i]];
    }
  }
  
  printf("%d\n",c);
  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define P pair<int, int>
using namespace std;

int main(void)
{
    int H, W, M;
    cin >> H >> W >> M;
    set<P> boms;
    vector<int> hLis(H+1);
    vector<int> wLis(W+1);

    for(int i = 0; i < M; i++){
        int h, w;
        cin >> h >> w;
        hLis[h]++;
        wLis[w]++;
        boms.insert({h, w});
    }
    
    int hmax = *max_element(hLis.begin(), hLis.end());
    int wmax = *max_element(wLis.begin(), wLis.end());

    vector<int> hmlis;
    vector<int> wmlis;
    for(int i = 1; i <= H; i++){
        if(hLis[i] == hmax) hmlis.push_back(i);
    }
    for(int i = 1; i <= W; i++){
        if(wLis[i] == wmax) wmlis.push_back(i);
    }

    for(int i: hmlis){
        for(int j: wmlis){
            if(boms.find({i, j}) == boms.end()){
                cout << hmax + wmax << endl;
                return 0;
            }
        }
    }
    cout << hmax + wmax - 1 << endl;
    return 0;
}

Measured memory_bytes: 23740
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 1e6 + 7;

int n;
int main()
{
    //ios::sync_with_stdio(0); cin.tie(0); //C++关同步
    int k, a, b;
    cin >> k >> a >> b;
    if(a % k == 0 || b % k == 0 || b / k > a / k)cout << "OK\n";
    else cout << "NG\n";
    return 0;
}


Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main
{
	private static void solve(FastScanner fr) {
		int n = fr.nextInt();
		int k = fr.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++)
			arr[i] = fr.nextInt();			

		int[] dp = new int[n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0] = 0;		
		for(int i = 0; i < n; i++) {
			for(int j = i-1; j >= i-k && j >= 0; j--) {
				dp[i] = Math.min(dp[i], dp[j] + Math.abs(arr[i] - arr[j]));
			}
			// sout(i + " " + dp[i]);
		}

		sout(dp[n-1]);
	}
    public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		int n = 1;
		// int n = fs.nextInt();
		while (n-- > 0)	{
			solve(fs);
        }
    }

    private static void sout()          { System.out.println();  }
    private static void sout(String s)  { System.out.println(s); }
    private static void sout(int s)     { System.out.println(s); }
    private static void sout(long s)    { System.out.println(s); }
    private static void sout(double s)  { System.out.println(s); }
    
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); }
			return st.nextToken();
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		int nextInt() {	return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}


Measured memory_bytes: 39512