akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int N;
vector<int> w_list;

int main() {
  cin >> N;
  w_list.resize(N);
  int sum  = 0;
  int half = 0;
  for(int i=0;i<N;i++) {
    cin >> w_list[i];
    sum += w_list[i];
  }
  half = sum / 2;

  int tmp_w_m1 = 0;
  int tmp_w = 0;
  int t   = 0;
  for(auto s: w_list) {
    t++;
    tmp_w += s;
    if (half <= tmp_w) {
      break;
    }
    tmp_w_m1 = tmp_w;
  }
#if 0
  cout << "tmp_w_m1=" << tmp_w_m1 << "\n";
  cout << "tmp_w=" << tmp_w << "\n";
  cout << "half=" << half << "\n";
  cout << "t=" << t << "\n";
#endif
  int ans1 = abs(sum-tmp_w-tmp_w);
  int ans2 = abs(sum-tmp_w_m1-tmp_w_m1);
  cout << min(ans1,ans2) << "\n";

#if 0
  cout << N << "\n";
  for(auto s: w_list) cout << s << " "; 
  cout << "\n";
#endif
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	
	//0210 start
	//0308 sample matched
	//0308 WA
	//0319 AC
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int d = sc.nextInt();
			if((n|d) == 0) break;
			ArrayList<ArrayList<Integer>> list = new ArrayList<ArrayList<Integer>>();
			int [] sum = new int[n];
			for(int i = 0 ; i< n; i++){
				int m = sc.nextInt();
				list.add(new ArrayList<Integer>());
				for(int j = 0; j < m; j++){
					int temp = sc.nextInt();
					sum[i] += temp;
					list.get(i).add(temp);
				}
			}
			
			while(true){
				int max = sum[0];
				int min = sum[0];
				int maxind = 0;
				for(int i = 1; i < n; i++){
					min = Math.min(min, sum[i]);
					if(max < sum[i]){
						max = sum[i];
						maxind = i;
					}
					else if(max == sum[i]) maxind = -1;
				}
				int secondmax = get2max(sum, max);
				
				boolean isremove = false;
				for(int i = 0; i < n; i++){
					int len = list.get(i).size();
					if(len== 0) continue;
					int now = sum[i] - list.get(i).get(len - 1);
					int diff;
					if(i == maxind){
						diff = Math.max(now, secondmax) - Math.min(min, now);
					}
					else{
						diff = Math.max(now, max) - Math.min(min, now);
					}
					if(diff > d) continue;
					sum[i] = now;
					list.get(i).remove(len - 1);
					isremove = true;
					break;
				}
				if(! isremove) break;
			}
			
			boolean ansflg = true;
			for(int i = 0; i < n; i++){
				if(list.get(i).size() != 0) ansflg = false;
			}
			System.out.println(ansflg ? "Yes" : "No");
		}
	}

	private int get2max(int[] sum, int max) {
		int res = 0;
		boolean flg = false;
		for(int i = 0; i < sum.length; i++){
			if(max == sum[i]){
				if(! flg){
					flg = true;
				}
				else{
					res = sum[i];
					return res;
				}
			}
			else{
				res = Math.max(res, sum[i]);
			}
		}
		return res;
	}

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

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ln "\n"
#define pb push_back
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define vll vector<ll>
#define vpll vector<pll>
#define vvll vector<vector<ll>>
#define sll stack<ll>
#define qll queue<ll>
#define mp make_pair
#define f first
#define s second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define Test ll t;cin>>t; while(t--)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define init(x,n,v) for(ll i=0;i<=n;i++) x[i]=v;
#define all(x) x.begin(),x.end()
ll MOD = 1e9+7 , MAX = 1e18;
int main() 
{
	fast_io;
	ll n,i,k,j;
	cin>>n>>k;
	vll dp(n,MAX),a(n);
	dp[0]=0;
	for(i=0;i<n;i++)
	{
	    cin>>a[i];
	    for(j=i-1;j>=max(i-k,0ll);j--) dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1792
import sys
input=sys.stdin.readline
from collections import deque
n,m=map(int,input().split())
Edges=[[] for _ in range(3*n)]
for _ in range(m):
    u,v=map(lambda x: int(x)-1,input().split())
    Edges[u].append(v+n)
    Edges[u+n].append(v+2*n)
    Edges[u+2*n].append(v)
s,t=map(lambda x: int(x)-1,input().split())
q=deque()
q.append(s)
Dist=[-1]*(3*n)
Dist[s]=0
while q:
    fr=q.popleft()
    for to in Edges[fr]:
        if Dist[to]==-1:
            Dist[to]=Dist[fr]+1
            q.append(to)
print(Dist[t]//3)

Measured memory_bytes: 79012
#include <stdio.h>

int main(void){
    int N, K;
    char S[10];

    scanf("%d%s%d", &N, S, &K);

    for(int i = 0; i < N; i++){
        if(S[i] != S[K - 1]) S[i] = '*';
    }

    printf("%s", S);

}


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

int N,H,W;

int main(){
    cin>>N>>H>>W;
    int ans=0;
    for(int i=0; i<N; i++){
        int a,b;
        cin>>a>>b;
        if(a>=H&&b>=W)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int n,k;
int main(){
	scanf("%d%d",&n,&k);
	int ans=INF;
	for(int i=0;i<(1<<n);i++){
		int cur=1;
		for(int j=0;j<n;j++){
			if(i>>j&1)
				cur*=2;
			else
				cur+=k;
		}
		umin(ans,cur);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 0x7fffffff
#define LL long long
#define pb push_back
#define make_pair
#define maxn 100100
#define Pii pair<int,int>
using namespace std;
int n,seg[maxn],a,b,c;
bool flag=false;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d",&seg[i]);
		if(seg[i]%2==1) a++;
		else if(seg[i]%4==0) c++;
		else if(seg[i]%2==0) b++;
	}
	/*if(n==1){
		if(seg[1]%4==0) flag=true;
		else flag=false;
	}
	else if(n==2){
		if((seg[1]*seg[2])%4==0) flag=true;
		else flag=false;
	}
	else if(a>2){
		if() 
		flag=false;
	 
	} 
	else{
		if(c<a){
			if(a==2&&n==3&&c==1) flag=true;
			else flag=false;-
		}
		else flag=true;
	} */
	if(b==0){
		if(c+1>=a) flag=true;
		else flag=false;
	}
	else{
		if(c>=a) flag=true;
		else flag=false;
	}
	if(flag) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
	// your code goes here
	int a,n;
	int approve=1;
	
	scanf("%d",&n);
	
	while(n--){
		scanf("%d",&a);
		if(a%2==0){
			if(a%3!=0&&a%5!=0)
				approve=0;
				
		}
	}
	
	if(approve==0)
		printf("DENIED");
	else
		printf("APPROVED");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void display(int n, int m) {
    int i, j;
    for(i = 0; i < n; i++) {
        for(j = 0; j < m; j++) {
            printf("#");
        }
        printf("\n");
    }
    
}
int main() {
    int i, j, k;
    int num[300][300] = {0};
    
    i = 0;
    while(1) {
        j = 0;
        scanf("%d %d", &num[i][j], &num[i][j+1]);
        if(num[i][j] == 0 && num[i][j] == 0) break;
        i++;
    }
    
    for(k = 0; k < i; k++) {
        j = 0;
        display(num[k][j], num[k][j+1]);
        printf("\n");
    }
    
    return 0;
}


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

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    bool can = false;
    for (int i=1; i<=B; ++i) {
        if (A*i % B == C) {
            can = true;
            break;
        }
    }

    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int S(int n){
	if(n < 10) return n;
	else return n%10 + S(n/10);
}

int main()
{
	int n;
	cin >> n;
	int ans = 1e9;
	for(int i = 1; i <= n; i++){
		int x = S(i)+S(n-i);
		if(x < ans) ans = x;
	}
	if(n%10 == 0) ans = 10;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n,w;
    cin >> n >> w;
    int weight[n];
    int value[n];
    REP(i,n) cin >> weight[i] >> value[i];

    int ans = 0;
    int mask = 1;
    REP(i,n) if( (w & weight[i]) == weight[i] ) ans += value[i];
    while(mask * 2 <= w) mask *= 2;
    while(mask > 1){
        int tmp_value = 0;
        if( (mask & w) ){
            int tmp =  w - ( w % mask) - 1;
            REP(i,n) if( (tmp & weight[i]) == weight[i] ) tmp_value += value[i];
            chmax(ans,tmp_value);
        }
        mask /= 2;
    }
    cout << ans << endl;
}

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

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

    string s[n];
    int p[n];
    int b[n];
    for(int i=0; i<n; i++){
        cin >> s[i] >> p[i];
        b[i]=i+1;
    }

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(s[i]<s[j]){
                swap(p[i], p[j]);
                swap(s[i], s[j]);
                swap(b[i], b[j]);
            }
        }
    }

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(p[i]>p[j]&&s[i]==s[j]){
                swap(p[i], p[j]);
                swap(s[i], s[j]);
                swap(b[i], b[j]);
            }
        }
    }


    for(int i=0; i<n; i++){
        cout << b[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    ll K;
    cin >> K;
    ll N = 50;
    vector<ll> a(N), b(N);

    rep(i,N) {
        if (K % N > i) b[i] = K / N + 1;
        else b[i] = K / N;
        a[i] = (N - 1) + N * b[i] - (K - b[i]);
    }

    cout << N << endl;
    rep(i,N) {
        cout << a[i];
        if (i < N - 1) cout << " ";
        else cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3568
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)

using namespace std;

typedef long long ll;

const double EPS = 1e-10;
const double PI = acos(-1.0);

int main(void) {
	int n;
	string s[100000];

	scanf("%d", &n);
	REP(i, n) {
		char cs[11];
		scanf("%s", cs);
		s[i] = string(cs);
	}

	REP(i, n) { sort(s[i].begin(), s[i].end()); }
	sort(s, s + n);

	ll result = 0;
	ll c = 0;
	REP(i, n - 1) {
		if(s[i] == s[i + 1]) {
			c++;
		} else {
			result += c * (c + 1) / 2;
			c = 0;
		}
	}
	result += c * (c + 1) / 2;

	printf("%lld\n", result);
	return 0;
}

Measured memory_bytes: 5760
//AtCoder Grand Contest 017 E - Jigsaw

#include <cstdio>
#include <iostream>
#include <cmath>

using namespace std;

int qr(){int ret = 0,f=1;char ch =getchar();while(!isdigit(ch))f=ch=='-'?-1:1,ch=getchar();while(isdigit(ch))ret=ret*10+ch-'0',ch=getchar();return ret*f;}

#define maxN 100005
#define maxH 205

int indegree[maxH<<2],outdegree[maxH<<2];
int active[maxH<<2];
void read(int x,int y){
    indegree[y]++;
    outdegree[x]++;
}
int f[maxH<<1],pd[maxH<<1];
int gf(int x){
    if(f[x] == x) return x;
    else return f[x] = gf(f[x]);
}
int main(){
    int N = qr(),H = qr();
    for(int i = 0;i<=(H<<1);i++)
        f[i] = i;
    int t1,t2,t3,t4,t5,t6;//上 t + maxN 下 t + maxN + maxH
    for(int i = 1;i<=N;i++){
        t1 = qr(),t2 = qr(),t3 = qr(),t4 = qr();
        if(!t3) t5 = t1;else t5 = -t3;
        if(!t4) t6 = -t2;else t6 = t4;
        t5 += H,t6 += H;
        active[t5] = active[t6] = 1;
        indegree[t6]++;outdegree[t5]++;
        f[gf(t5)] = gf(t6);
    }
    int mark=1;
    for(int i = 0;i<=H;i++){
        if(indegree[i]<outdegree[i])
            mark=0;
    }
    for(int i = H+1;i<=(H<<1);++i){
        if(indegree[i]>outdegree[i])
            mark=0;
    }
    for(int i = 0;i<=(H<<1);i++){
        pd[gf(i)] |= (indegree[i] != outdegree[i]);
    }
    pd[H] = 1;
    for(int i = 1;i<=(H<<1);i++){
        if(active[i] && !pd[gf(i)])
            mark=0;
    }
    if(mark)
        cout << "YES";
    else cout << "NO";
    return 0;
}

Measured memory_bytes: 256
#ABC C-Christmas Eve
n , k = list(map(int, input().split()))
p = []
for i in range(n):
        p.append(int(input()))
p.sort()
m = p[n-1] - p[0]
for i in range(n-k+1):
    t = p[i+k-1] - p[i]
    m = min(t,m)
print(m)

Measured memory_bytes: 7384
#include <bits/stdc++.h>
using namespace std;
const int M = 100001;
int n, i, cost1, cost2, h[M], ans[M];
int main ()
{
    cin >> n;
    for(i = 1; i <= n; i++) cin >> h[i];
    ans[1] = 0, ans[2] = abs(h[2]-h[1]);
    for(i = 3; i <= n; i++)
    {
        cost1 = abs(h[i-1]-h[i]);
        cost2 = abs(h[i-2]-h[i]);
        ans[i] = min(ans[i-1]+cost1, ans[i-2]+cost2);
    }
    cout << ans[n] << endl;
}


Measured memory_bytes: 4356
X=int(input())

def ok(B):
    i=1
    B=abs(B)
    while i**5<B:
        i+=1
    return i**5==B

def get(B):
    f = B/abs(B)
    i=1
    B=abs(B)
    while i**5<B:
        i+=1
    return int(i*f)



A_cand=[]
i=0
while i**5<=10**10:
    A_cand.append(i)
    i+=1

#print(A_cand)
for a in range(300):
    B_5=a**5-X
    if ok(B_5):
        r=get(B_5)
        print(a,r)
        exit()
        break


Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    REPS(k, N) {
        for (int i = k; i <= N; i += k) {
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

int main() {
	int n,m,p,x,sum;
	cin>>n;
	vector<int> t(n);

	for(int i=0;i<n;i++){
	    cin>>t.at(i);
	}
	sum=accumulate(t.begin(),t.end(),0);
	cin>>m;
	for(int j=0;j<m;j++){
	    cin>>p>>x;
	    cout<<sum+(x-t.at(p-1))<<endl;
	}
}

Measured memory_bytes: 256
n = int(input())
d = [list(map(int, input().split())) for _ in range(n)]

for i in range(n-2):
    if d[i][0] == d[i][1]:
        if d[i+1][0] == d[i+1][1]:
            if d[i+2][0] == d[i+2][1]:
                print('Yes')
                exit()
            else:
                continue
        else:
            continue
    else:
        continue

print('No')

Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x,y,z;
  cin >> x >> y >> z;
    
  int temp = x;
  x = y;
  y = temp;
  
  temp = x;
  x = z;
  z = temp;
  
  cout << x << " " << y << " " << z << endl;
  return 0;
}


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

int N;
long int Y;
int main(){
    cin >> N >> Y;
    bool flag = false;
    for (int x = 0; x <= N; x++){
        for (int y = 0; y <= N - x; y++){
            int z = N - x - y;
            if (10000 * x + 5000 * y + 1000 * z == Y){
                cout << x << " " << y << " " << z << endl;
                flag = true;
                break;
            }
        }
        if (flag){
            break;
        }
    }
    if (!flag){
        cout << -1  << " " << -1 << " " << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    int n,m;
    cin>>n>>m;
    vi place(m);
    vector<int> v(m);
    rep(i,m){
        cin>>place[i];
        int b;
        cin>>b;
        rep(j,b){
            int c;
            cin>>c;
            c--;
            v[i]|=1<<c;
        }
    }
    vll dp((1<<n)+10,LLINF);
    dp[0]=0;
    rep(i,(1<<n)-1){
        rep(j,m){
            chmin(dp[i|v[j]],dp[i]+place[j]);
        }
    }
    if(dp[(1<<n)-1]!=LLINF)fin(dp[(1<<n)-1]);
    else fin(-1);
}



Measured memory_bytes: 256
def euc(x, y):
	if y == 0: return x
	return euc(y, x%y)

A, B, C, D = map(int, input().split())
divC = B // C - (A-1) // C
divD = B // D - (A-1) // D
divCD = B // ((C*D)//euc(C, D)) - (A-1) // ((C*D)//euc(C, D))
print((B-A+1) - divC - divD + divCD)

Measured memory_bytes: 38384
//#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>

using namespace std;

#define ll long long

void solve()
{
    string S;
    cin >> S;
    ll a = stoll(S.substr(0, 2));
    ll b = stoll(S.substr(2, 2));
    string result = "NA";
    if (a >= 1 && a <= 12)
    {
        if (b >= 1 && b <= 12)
        {
            result = "AMBIGUOUS";
        }
        else
        {
            result = "MMYY";
        }
    }
    else
    {
        if (b >= 1 && b <= 12)
        {
            result = "YYMM";
        }
        else
        {
            result = "NA";
        }
    }

    cout << result << endl;

    return;
}

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


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

int main() {
  string s,ans;
  ans = "Yes";
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(i%2==1 && s.at(i)!='L'&&s.at(i)!='U'&&s.at(i)!='D'){
      ans ="No";}
    if(i%2==0 && s.at(i)!='R'&&s.at(i)!='U'&&s.at(i)!='D'){
      ans = "No";}
  }
  cout <<ans << endl;
  return 0;
}

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

int main(void){
    int H, W;
    cin >> H >> W;
    vector<vector<int>> G(10, vector<int>(10));
    int c;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> c;
            G[j][i] = c;
        }
    }
    vector<int> dist(10, 10001);
    dist[1] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> Q;
    Q.push(make_pair(0, 1));
    while (!Q.empty()) {
        for (int i = 0; i < 10; i++) {
            if (dist[i] > Q.top().first + G[Q.top().second][i]) {
                dist[i] = Q.top().first + G[Q.top().second][i];
                Q.push(make_pair(dist[i], i));
            }
        }
        Q.pop();
    }
    int sum = 0, A;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A;
            if (A == -1) continue;
            sum += dist[A];
        }
    }
    cout << sum << endl;
}


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

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
   ll x,k,d;
   cin>>x>>k>>d;
   x=abs(x);
   if((x/d)>=k)
   {
       cout<<x-(k*d)<<endl;
   }
   else if((abs((x/d)-k))%2!=0)
   {
       cout<<d-(x%d)<<endl;
   }
   else
   {
       cout<<x%d<<endl;
   }
   
	return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int a[3];
    for (auto& ai : a) cin >> ai;
    sort(a, a + 3);
    a[2] -= a[0]; a[1] -= a[0]; a[0] = 0;
    int cnt = 1;
    if (a[2] % 2 != 0 && a[1] % 2 != 0) { a[2]++; a[1]++; }
    else if (a[2] % 2 != 0 && a[1] % 2 == 0) { a[0]++; a[1]++; }
    else if (a[2] % 2 == 0 && a[1] % 2 != 0) { a[2]++; a[0]++; }
    else cnt = 0;
    // outa(a, 3);
    out(cnt + (a[2] - a[0]) / 2 + (a[2] - a[1]) / 2);
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){


int a,b,c,d;


d=0;


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


for(a;a<=b;a++){


if(c%a==0){


d=d+1;


}


}


printf("%d\n",d);


return 0;


}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 100000;
const double INF = 1e8;

int n;
double c[N],r[N];

inline double SQ(double x){ return x*x; }
double h(double x)
{
    double ret = INF;
    rep(i,n) ret = min(ret, sqrt(SQ(r[i]) - SQ(x-c[i])));
    return ret;
}

int main()
{
    cin >>n;
    rep(i,n) cin >>c[i] >>r[i];

    double L = -INF, R = INF;
    rep(i,n)
    {
        L = max(L,c[i]-r[i]);
        R = min(R,c[i]+r[i]);
    }

    rep(loop,80)
    {
        double m1 = (2*L+R)/3;
        double m2 = (L+2*R)/3;

        if(h(m1)>h(m2)) R=m2;
        else L=m1;
    }

    printf("%.10f\n", h((L+R)/2));
    return 0;
}

Measured memory_bytes: 4748
s = input()
revs = s[::-1] + "Z"
i = 0

while(True):
 if revs[i:i+5]=="maerd": i+=5
 elif revs[i:i+7]=="remaerd": i+=7
 elif revs[i:i+5]=="esare": i+=5
 elif revs[i:i+6]=="resare": i+=6
 elif revs[i]=="Z":
  print("YES")
  break
 else:
  print("NO")
  break

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}


vector<ll> enum_div(ll n){//yakusu
  vector<ll> ret;
  for(ll i=1 ; i*i<=n ; ++i){
      if(n%i == 0){
        ret.push_back(i);
        if(i*i!=n)ret.push_back(n/i);
      }
  }
  return ret;
}


int main(){

  ll N;
  cin >> N;
  vector<ll> A(N);
  FOR(i,0,N) cin >> A[i];

  SORT(A);
  if(A[0] == 1 && N>1 && A[1] == 1){
    cout << 0 << endl;
    return 0;
  }
  if(A[0]==1 && N==1){
    cout << 1 << endl;
    return 0;
  }
  if(A[0] == 1 && N>1 && A[1] > 1){
    cout << 1 << endl;
    return 0;
  }

  vector<ll> se(1000007,0);

  ll ans = 0;
  FOR(i,0,N){
    bool ok = true;
    if(i!=(N-1) && A[i]==A[i+1])ok = false;
    for(auto x:enum_div(A[i])){
      if(se[x])ok = false;
    }
    ans += ok;
    se[A[i]]=1;
  } 
  cout << ans << endl;
}



Measured memory_bytes: 12632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

int main() {
  int n, k;
  string s, t;
  cin >> n >> k >> s; k--;
  rep(i, n) {
    if (i == k) {
      if (s[i] == 'A') t[i] = 'a';
      if (s[i] == 'B') t[i] = 'b';
      if (s[i] == 'C') t[i] = 'c';
    }
    else t[i] = s[i];
  }
  rep(i, n) cout << t[i];
  return 0;
}

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

 using namespace std;

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

   vector<int> d(N);
   for (int i = 0; i < N; i++) cin >> d.at(i);

   int ans = 0;

   for (int i = 0; i < N - 1; i++) {
     for (int j = i + 1; j < N; j++) {
       ans += d.at(i) * d.at(j);
     }
   }

   cout << ans << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

ll mod_pow(ll a,ll b,ll p){ //(a^b)%p
	ll res=1;
	a%=p;

	while(b>0){
		if(b&1==1) res=((res%p)*(a%p))%p;
		a=(a%p*a%p)%p;
		b>>=1;
	}
	return res;
}

//mod_inv=mod_pow(denominator,MOD-2,MOD);
int fac[MAXSIZE+6];
int inv[MAXSIZE+6];

void pre(){
	fac[0] = 1;
	for(int i=1;i<=MAXSIZE;i++){
		fac[i] = fac[i-1] * (i);
		fac[i]%=mod;
	}
	inv[MAXSIZE] = mod_pow(fac[MAXSIZE],mod-2,mod);
	for(int i=MAXSIZE-1;i>=0;i--){
		inv[i] = (i+1) * inv[i+1];
		inv[i]%=mod;
	}
}

int nCr(int n, int r){
	if(r>n) return 0;
	int ans = fac[n];
	ans%=mod;
	ans = ans * inv[r];
	ans%=mod;
	ans = ans * inv[n-r];
	ans%=mod;
	return ans;
}


int32_t main(){
	fastio();
	int n;
	cin >> n;
	pre();
	int ans = 0;
	for(int i = 1; i <= n - 1; i++){
		int left = n - i;
		int curr = (nCr(n,i));
		int c2 = mod_pow(9,left,mod);
		int c3 = mod_pow(8,left,mod);
		c2 = (c2 - c3 + mod) % mod;
		curr = curr  * c2;
		curr %= mod;
		ans += curr;
		ans %= mod;
	}
	cout << ans;
}

Measured memory_bytes: 19272
lis=[]
while True:
	w,h=[int(x) for x in input().split()]
	if w==0 and h==0:
		break
	else:
		lis.append([w,h])

for x in lis:
	w,h=x[1],x[0]
	for i in range(h):
		for j in range(w):
			if i==0 or j==0 or i==h-1 or j==w-1:
				print("#",end="")
			else:
				print(".",end="")
		print()
	print()




Measured memory_bytes: 7008
package main

import (
	"fmt"
)

func main() {
	var x int
    fmt.Scan(&x)
	if x%11 == 0 {
		fmt.Println(x / 11 * 2)
	} else if x%11 <= 6 {
		fmt.Println(x/11*2 + 1)
	} else {
		fmt.Println(x/11*2 + 2)
	}
}


Measured memory_bytes: 512
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._
object Main extends App {

  solve()
  @tailrec def solve(): Unit = {
    val arg = readLine.trim
    if (arg == "#") return
    val state = arg.toState
    val Array(a, b, c, d) = readLine.trim.split(' ').map(_.toInt)
    state(a - 1)(b - 1) = false
    state(c - 1)(d - 1) = true
    println(state.toJfen)
    solve()
  }
  implicit class JfenExpression(val expression: String) extends AnyVal {
    def toState: Array[Array[Boolean]] = {
      val split = expression.split('/')
      val height = split.length
      val width = calWidth(split.head)
      val state = Array.fill(height){Array.fill(width){false}}
      for ((line, i) ← split.zipWithIndex) {
        var j = 0
        for (c ← line) {
          c match {
            case 'b' ⇒
              state(i)(j) = true
              j += 1
            case _ ⇒ j += c.asDigit
          }
        }
      }
      state
    }
    private[this] def calWidth(line: String): Int = {
      line.map{
        case 'b' ⇒ 1
        case c ⇒ c.asDigit
      }.sum
    }
  }
  implicit class State(val state: Array[Array[Boolean]]) extends AnyVal {
    def toJfen: String = {
      var result = Nil: List[String]
      for (line ← state) {
        var state = Nil: List[String]
        val indices = -1 +: line.indices.filter(i ⇒ line(i)) :+ line.length
        for (i ← indices.indices.tail) {
          state :::=  "b" :: (indices(i) - indices(i - 1) - 1).toString :: Nil
        }
        result ::= state.tail.reverse.filter(_ != "0").mkString
      }
      result.reverse.mkString("/")
    }
  }
}


Measured memory_bytes: 45172
/* ex 5_4
   sak_Citrus */

#include <stdio.h>

int main(void){
    char seq[11];
    char *ptr;
    int ans = 0,temp = 0;
    scanf("%s",&seq[0]);
    ptr = seq;

    while(1){
        //ATCG文字列ならtempを＋
        if(*ptr == 'A' || *ptr == 'T' || *ptr == 'C' || *ptr == 'G')temp++;
        //ATCG列が途切れたらリセット
        else temp = 0;
        //長さが現時点で最大であればansを更新
        if(temp > ans)ans = temp;
        if(*ptr++ == '\0')break;
    }

    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1704
import java.util.*;

/**
 * B
 */
public class Main {

    void run() {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[][] DP = new int[n+1][n+1];
        int[] r = new int[n+1];
        int[] c = new int[n+1];
        int[] p = new int[n+2];

        for(int i=1; i<=n; i++) {
            r[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }

        sc.close();

        for(int i=1; i<=n+1; i++) {
            if(i==1) {
                p[i] = r[i];
            } else {
                p[i] = c[i-1];
            }
        }

        for(int i=1; i<=n; i++) {
            DP[i][i] = 0;
        }

        for(int d=1; d<=n; d++) {
            for(int i=1; i<=n-d; i++) {
                int j = i+d;
                int min = DP[i][i]+DP[i+1][j]+p[i]*p[i+1]*p[j+1];
                for(int k=i; k<j; k++) {
                    if(DP[i][k]+DP[k+1][j]+p[i]*p[k+1]*p[j+1]<min) {
                        min = DP[i][k]+DP[k+1][j]+p[i]*p[k+1]*p[j+1];
                    }
                }
                DP[i][j] = min;
            }
        }

        System.out.println(DP[1][n]);

    }

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

}


Measured memory_bytes: 26436
import java.util.*;

public class Main {
	public static void main (String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Point> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
		    list.add(new Point(sc.nextInt(), sc.nextInt()));
		}
		double all = 0;
		for (int i = 0; i < n; i++) {
		    Point p = list.remove(i);
		    all += getLength(p, list);
		    list.add(i, p);
		}
		System.out.println(all / kaijo(n));
	}
	
	static double getLength(Point base, ArrayList<Point> list) {
	    if (list.size() == 0) {
	        return 0;
	    }
	    double ans = 0;
	    for (int i = 0; i < list.size(); i++) {
	        Point p = list.remove(i);
	        ans += p.getLength(base) * kaijo(list.size());
	        ans += getLength(p, list);
	        list.add(i, p);
	    }
	    return ans;
	}
	
	static int kaijo(int x) {
	    if (x <= 1) {
	        return 1;
	    } else {
	        return x * kaijo(x - 1);
	    }
	}
	
	static class Point {
	    int x;
	    int y;
	    
	    public Point(int x, int y) {
	        this.x = x;
	        this.y = y;
	    }
	    
	    public double getLength(Point another) {
	        return Math.sqrt((x - another.x) * (x - another.x) + (y - another.y) * (y - another.y));
	    }
	    
	    public String toString() {
	        return "x:" + x + " y:" + y;
	    }
	}
}


Measured memory_bytes: 25100
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const LL N = 1000000007;

LL dp[65][2][2];
LL bx[65],by[65];

LL dfs(LL pos,LL l1,LL l2){
	if(!pos) return 1;
	if(dp[pos][l1][l2] != -1) return dp[pos][l1][l2];
	LL ret = 0;
	LL t1 = l1 ? bx[pos] : 0,t2 = l2 ? by[pos] : 1;
	for(LL y = t1;y <= t2;y ++){
		for(LL x = t1;x <= y;x ++){
			ret += dfs(pos - 1,l1 && x == t1,l2 && y == t2);
			ret %= N;
		}
	}
//	cout << pos << ' '  << l1 << ' ' << l2 << ' ' << ret << endl;
	dp[pos][l1][l2] = ret;
	return ret;
}

int main(){
	memset(dp,-1,sizeof(dp));
	LL l,r,ll = 0,rr = 0,ans = 0;
	cin >> l >> r;
	while(1){ if(!l) break; bx[++ ll] = l & 1; l >>= 1; }
	while(1){ if(!r) break; by[++ rr] = r & 1; r >>= 1; }
	for(LL i = ll;i <= rr;i ++) ans = (ans + dfs(i - 1,i == ll,i == rr)) % N;
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 1e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 0;i < n;i++) ans += i;
  cout << ans << endl;
}

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

using namespace std;

int main() {
	
	int n, q;
	cin >> n;
	vector<int> s(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	cin >> q;
	vector<int> c(q, 0);
	for (int i = 0; i < q; i++) {
		cin >> c[i];
	}

	int counter = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < q; j++) {
			if (s[i] == c[j]) { c[j] = -1; counter++; }
		}
	}
	cout << counter << endl;
}


Measured memory_bytes: 3084
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef std::uint64_t u64;
typedef std::int64_t  i64;
typedef std::uint32_t u32;
typedef std::int32_t  i32;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl

#define YesNo(x) cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x) cout << ((x) ? "YES" : "NO") << endl

bool cmp(string a, string b) {
	auto n = min(a.size(), b.size());
	rep(i, n) {
		if(a[i] < b[i]) {
			return true;
		} else if(a[i] > b[i]) {
			return false;
		}
	}

	return (a.size() <= b.size());
}

int main(int argc, const char* argv[]) {
	string s, t;
	cin >> s >> t;

	if(s.size() < t.size()) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	vector<string> v;

	for(int i = 0; i <= s.size() - t.size(); ++i) {
		string tmp = s;
		rep(j, t.size()) {
			if(tmp[i+j] == '?') {
				tmp[i+j] = t[j];
			} else if(tmp[i+j] != t[j]) {
				goto L1;
			}
		}

		rep(i, tmp.size()) if(tmp[i] == '?') tmp[i] = 'a';
		v.push_back(tmp);

		L1:
		cerr << endl;
	}

	if(v.empty()) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	sort(v.begin(), v.end(), cmp);
	cout << v[0] << endl;
	return 0;
}

Measured memory_bytes: 256
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const int M=1000000007;
const int MM=998244353;
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(m<=1)return 0;
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=5e5+5;

ll vis[100];

vl arr[100];

ll low[100],in[100];

ll timer=1;

ll cnt;

void dfs(ll node,ll par){
  vis[node]=1;
in[node]=low[node]=timer++;

  for(auto child:arr[node]){
    if(child==par){
      continue;
    }
    if(!vis[child]){
      dfs(child,node);
   //   low[node]=min(low[node],low[child]);
      if(in[node]<low[child]){
        cnt++;
      //  d3("there is a bridge b/w ",node,child);
      }
      else low[node]=min(low[node],low[child]);
    }
    else {
      low[node]=min(low[node],in[child]);
    }
  }
}



int main()
{ 

IOS;

ll n,m;

cin>>n>>m;

while(m--){
  ll a,b;
  cin>>a>>b;
  arr[a].pb(b);
  arr[b].pb(a);
}


dfs(1,-1);

cout<<cnt<<endl;

//end_routine();

return 0;
 
}


Measured memory_bytes: 3600
n, m = map(int, raw_input().split())
 
a = [[0]*m for i in xrange(n)]
 
b = [0]*m
 
for i in xrange(n):
    tmp = map(int, raw_input().split())
    for j in xrange(m):
        a[i][j] = tmp[j]
for i in xrange(m):
    b[i] = input()
for i in xrange(n):
    tmp = 0
    for j in xrange(m):
        tmp += a[i][j] * b[j]
    print tmp

Measured memory_bytes: 6648
h,w=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(2*h)]
board=[[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    board[i][j]+=arr[i][j]
for i in range(h):
  for j in range(w):
    board[i][j]=abs(board[i][j]-arr[h+i][j])
dp=[[set() for _ in range(w)] for _ in range(h)]
dp[0][0].add(board[0][0])
for i in range(h):
  for j in range(w):
    if i!=0:
      for k in dp[i-1][j]:
        dp[i][j].add((k+board[i][j])%800)
        dp[i][j].add(abs(k-board[i][j])%800)
    if j!=0:
      for k in dp[i][j-1]:
        dp[i][j].add((k+board[i][j])%800)
        dp[i][j].add(abs(k-board[i][j])%800)
print(min(dp[h-1][w-1]))

Measured memory_bytes: 236936
N=int(input())
aN=list(map(int,input().split()))
dic={}
for a in aN:
  if a in dic:
    dic[a] += 1
  else:
    dic[a] = 1
ans=0
for k,v in dic.items():
  if k > v:
    ans +=v
  else:
    ans+=v-k
print(ans)

Measured memory_bytes: 18168
import java.util.*;
import java.io.*;

import static java.lang.Character.isUpperCase;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int A = in.nextInt();
        int B = in.nextInt();
        if(A==1 && B==2 || A==2 && B==1)
        {
            System.out.println(3);
        }
        else if(A==2 && B==3 || A==3 && B==2)
        {
            System.out.println(1);
        }
        else if(A==1 && B==3 || A==3 && B==1)
        {
            System.out.println(2);
        }
        else
            {
                System.out.println("ERROR");
            }







        }







    }
















Measured memory_bytes: 35784
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > Pii;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
#define pb push_back
#define rs resize 
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repll(i, a, b) for(ll i=(a); i<(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define COUT(a) cout << a << endl
#define ALL(a) (a).begin(),(a).end()
const long long int mod = 1e9 + 7;
vector<ll> Divisor(ll n){
  vector<ll> temp;
  for(ll i=1; i*i<=n; i++){
    if(n%i==0){
      temp.pb(i); 
      if(i!=n/i) temp.pb(n/i);
    }
  }
  return temp;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 
    ll N,mini=1e12+1;
    cin >> N;
    Vll div = Divisor(N);
    rep(i,0,div.size()){
        ll temp = N/div[i]+div[i]-2;
        if(mini>temp) mini = temp;
    }
    COUT(mini);
}

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

def bs(d, x):
  l, r = 0, len(d)
  while l < r:
    mid = (l + r) // 2
    if d[mid] < x:
      l = mid + 1
    else:
      r = mid
  return l


def main():
  n, q = map(int, input().split())
  stx = [tuple(map(int, input().split())) for _ in range(n)]
  stx = list(sorted(stx, key=lambda x: x[2]))
  dlist = [int(input()) for _ in range(q)]
  ans = [-1 for _ in range(q)]
  skip = [-1 for _ in range(q)]
  for s, t, x in stx:
    l = bs(dlist, s-x)
    r = bs(dlist, t-x)
    while l < r:
      if skip[l] == -1:
        ans[l] = x
        skip[l] = r
        l += 1
      else:
        l = skip[l]
  print(*ans, sep='\n')


if __name__ == '__main__':
  main()

Measured memory_bytes: 111960
#include<bits/stdc++.h>
// Author : Pham Ngoc Minh - 12 Tin - CTB
// The Way To Progress Is To Constantly Try
using namespace std;
#define f first
#define s second
#define ll long long
#define fl float
#define db double
#define ii pair<ll,ll>
#define pii pair<ii,ii>
#define ford(i,a,b) for(int i=a;i<=b;i++)
#define foru(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,a,b) for(int i=a;i<b;i++)
#define oo 10000000000001
#define ooo -1000000000001
#define bost  ios_base::sync_with_stdio(false); cin.tie(0);
long long a,b;
int main()
{
    bost
    cin>>a>>b;
    if((a+b)%2==1 && a!=b)
    {
        cout<<"IMPOSSIBLE";
        return 0;
    }
    if(a==b)
    {
        cout<<0;
        return 0;
    }
    cout<<(a+b)/2;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void){
	char a[1024],answer[]="Hoshino",*c;
	int i,n;
	scanf("%d\n",&n);
	for(i=0;i<n;i++){
		fgets(a,sizeof(a),stdin);
		while((c=strstr(a,answer)) != NULL) c[6]='a';
		printf("%s",a);
	}
	return 0;
}

Measured memory_bytes: 608
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] s = new String[h];
		for(int i=0; i<h; i++){
			s[i] = sc.next();
		}
		char[][] a = new char[h+2][w+2];
		for(int i=1; i<=h; i++){
			for(int j=1; j<=w; j++){
				a[i][j] = s[i-1].charAt(j-1);
			}
		}
		for(int i=0; i<h+2; i++){
			a[i][0] = '#';
			a[i][w+1] = '#';
		}
		for(int i=0; i<w+2; i++){
			a[0][i] = '#';
			a[h+1][i] = '#';
		}
		for(int i=0; i<h+2; i++){
			for(int j=0; j<w+2; j++){
				System.out.print(a[i][j]);
			}
		System.out.println("");
		}
	}
}

Measured memory_bytes: 25684