akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  cin >> n;
  string s[n];
  rep(i,n) R s[i];
  int c[26];
  fill(c,c+26,MAX);
  rep(i,n) {
    int d[26];
    mem(d);
    rep(j,s[i].size()) d[s[i][j]-'a']++;
    rep(j,26) c[j]=min(c[j],d[j]);
  }
  string t="";
  rep(i,26) {
    rep(j,c[i]) t+=(char)(i+'a');
  }
  pr(t);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

int main() {
    string s;
    long long k;
    cin >> s >> k;
    int size = s.size();
    int cnt = 0;
    char c = '1';
    for(int i = 0; i < size; i++)
    {
        if (s.at(i) == '1') {
            cnt++;
            if (k <= cnt) break;
        }
        else {
            c = s.at(i);
            break;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a); i<(b); ++i)
inline ll in() { ll x; cin >> x; return x; }

#define int ll
void solve() {
  int n = in(), k = in();
  int r = in(), s = in(), p = in();
  string t; cin >> t;
  vector<bool> done(n+1, false);

  ll ans = 0;
  FOR (i,0,n) {
    if (i>=k)
      if (t[i-k]==t[i] && done[i-k]) continue;

    if (t[i]=='r') ans+=p;
    if (t[i]=='s') ans+=r;
    if (t[i]=='p') ans+=s;

    done[i] = true;
  }

  cout << ans << endl;
}

#undef int
int main() {
  solve();
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl

string S;





int main()
{

	cin >> S;
	REP(i,S.length()-1){
		if(S[i]=='A' && S[i+1] == 'C'){
			cout << "Yes";
			return 0;
		}

	}

	cout << "No";

}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int a, b, c, d, e, f;
	scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
	if(a + 5*b + 10*c + 50*d + 100*e + 500*f >= 1000) printf("1\n");
	else printf("0\n");
	
	return 0;
}

Measured memory_bytes: 584
N, M = (int(x) for x in input().split())
AB = []

for i in range(N):
    a, b = (int(x) for x in input().split())
    AB.append((a,b))

AB = sorted(AB, key=lambda x:x[0], reverse=False)
sum_money = 0

for i in AB:
    if M <= i[1]:
        sum_money += M * i[0]
        break
    else:
        sum_money += i[1] * i[0]
        M -= i[1]
        
print(sum_money)


Measured memory_bytes: 18904
/**
 * author  : UshanGhosh
 * created : 2020-09-19 17:35:23
**/ 

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

#define    ll      long long
#define    pii     pair<int,int>
#define    vii     vector<int>
#define    vcc     vector<char>
#define    pll     pair<long long, long long>
#define    mem     memset
#define    sof     sizeof
#define    co1     __builtin_popcountll
#define    PB      push_back
#define    UB      upper_bound
#define    LB      lower_bound
#define    MP      make_pair
#define    TS      to_string
#define    F       first
#define    S       second
#define    pi      acos(-1)
#define    mod     (int)1e9+7
#define    inf     (long long)1e18
#define    endl    '\n'

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long a,b,c,d,e,f,i,j,k,m,n,o,x,y;
    string s;
    cin>>n>>s;
    if(n%2) cout<<"No\n";
    else{
        ll err = 0;
        for(i=0;i<n/2;i++){
            if(s[i]!=s[i+n/2]) err++;
        }
        if(!err) cout<<"Yes\n";
        else cout<<"No\n";
    }
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S; cin >>S;
  long long K; cin >>K;
  long long sum=0;
  string saisho;
  bool hantei=false;
  long long snagasa=S.size();
  long long nagasa=min(snagasa,K);
  for(long long i=0;i<nagasa;i++){
    if(S[i]=='1'){
      sum++;
    }else{
      if(hantei==false){
        saisho=S[i];
        hantei=true;
      }
    }
  }
  if(sum==K){
    cout<<'1'<<endl;
  }else{
    cout<<saisho<<endl;
  }
  return 0;
}

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

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

  int a,b;
  cin >> a >> b;

  if (a+b<10) {
    cout << a+b << endl;
  }

  else if (a+b>=10) {
    cout << "error" << endl;
  }
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0, i##_len=(n); i<i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

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

          int ans=0;
          FOR(i,1,n){
                    int cnt=0;
                    for(char c='a';c<='z';c++){
                              bool left=false,right=false;

                              FOR(j,0,i){
                                        if(s[j]==c)         left=true;
                              }
                              FOR(j,i,n){
                                        if(s[j]==c)         right=true;
                              }
                              if(left and right)  cnt++;
                    }
                    if(ans<cnt)         ans=cnt;
          }

          cout << ans << endl;

          return 0;
}


Measured memory_bytes: 256
# coding: utf-8
import numpy as np
from functools import lru_cache
import time

def main(): 
    if True:
        N,K = list(map(int,input().split()))
        S = np.asarray(list(map(int,list(str(input())))))
    else:
        N,K = [10**5,1]
        T = np.asarray(range(N))
        S = np.zeros(N)
        S[T%2==0] = 1

    SN = np.zeros(10**5+2)
    first = S[0]
    tmpnum = first
    k = 0
    if first == 0:
        k += 1
    k += 1

    count = 0
    for n in range(N)[1:]:
        if S[n] == tmpnum:
            count += 1
        else:
            count += 1
            SN[k] = count
            k += 1
            tmpnum = S[n]
    else:
        count += 1
        SN[k] = count
        if tmpnum == 0:
            SN[k+1] = count

    max = 0
    flag = 0
    for n in range(SN.size)[2*K+1::2]:
        if SN[n] == 0: break
        if max < SN[n] - SN[n-2*K-1]:
            max = SN[n] - SN[n-2*K-1]
        flag = 1
    
    if flag == 0:
        print(int(np.max(SN)))
    else:
        print(int(max))

if __name__ =='__main__':
    main()

Measured memory_bytes: 20328
N = int(input())
A = list(map(int, input().split()))
ans = [0 for _ in range(N)]
half = int(N / 2) + 1
s = 0
hako = []
# if N % 2 == 0:
#     half = int(N / 2)

for i in reversed(range(N)):
    if i+1 >= half:
        if A[i] == 1:
            ans[i] = 1
            s += 1
            hako.append(i+1)
    else:
        cur = (i+1)*2
        tmp = 0
        while cur <= N:
            if ans[cur-1] == 1:
                tmp += 1
            cur += i+1
        if tmp % 2 != A[i]:
            ans[i] = 1
            s += 1
            hako.append(i+1)

print(s)
if len(hako) > 0:
    print(*hako)

        

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

int main(int argc, char const *argv[])
{
    int H,W;
    while(1) {
        cin >> H >> W;
        if(H==0 && W ==0) break;
        for (int i = 0; i < H; ++i)
        {
            for (int i = 0; i < W; ++i)
            {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
// Aizu 1078: SAT-EN-3
// 2017.9.17 bal4u@uu

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

char exp[510], *p;
char tbl['z'];

int literal(int *v)
{
	*v = 1; if (*p == '~') *v = -1, p++;
	return *p++;
}

int clause()
{
	int x, v, f = 1;

	memset(tbl, 0, sizeof(tbl));
	x = literal(&v), tbl[x] = v;
	while (1) {
		if (*p != '&') break;
		p++;
		x = literal(&v);
		if (tbl[x] + v == 0) f = 0;
		tbl[x] = v;
	}
	return f;
}

int expression()
{
	p++; if (clause()) return 1; p++;
	while (1) {
		if (*p != '|') break;
		p++; p++; if (clause()) return 1; p++;
	}
	return 0;
}

int main()
{
	while (1) {
		fgets(p = exp, 505, stdin); if (*p == '#') break;
		puts(expression() ? "yes" : "no");
	}
	return 0;
}

Measured memory_bytes: 1808
/*
I am not somebody you can put inside a box
And I am not somebody who will let you take my spot
It's written on my face I'm somebody who never stop
I do it because I gotta I don't do it for you props
Nah, you can keep those
I'm aiming way higher than planes in Heathrow
And I'm sorry to say but my game can't be sold
And look to be honest either you got it or don't
But if you got a dream and a vision
Put it in your mind that you gotta go out and get it
People try to stop you it's so hard in the beginning
But you said that you a winner so keep going ain't no quiting
I'm giving you the words that out me in this posotion
Some people hear and some people listen
Wanna be the best then you gotta learn the difference
*/
#include <bits/stdc++.h>                                           
 
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
//#define int long long	
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define ll long long
#define vi vector < int >
#define pii pair < int, int > 
#define sz(s) (int)s.size()
#define all(x) x.begin(), x.end()                                                                    
#define pb push_back   
#define ppb pop_back
#define mp make_pair
#define s second
#define f first                                               
	
   
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;   
   
const int N = 1e3 + 13, inf = 1e9, mod = 1e9 + 7, block = 444;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
const ll INF = 1e18;
//fucking constants
 

int n, m, ax, ay, bx, by, d[N][N];
char c[N][N];
set < pair < int, pii > > q;

bool in (int x, int y) {
	return x > 0 && y > 0 && x <= n && y <= m;
}

main () {
	scanf("%d%d%d%d%d%d", &n, &m, &ax, &ay, &bx, &by);
	for (int i = 1; i <= n; ++i) {
		scanf("\n");
		for (int j = 1; j <= m; ++j)
			scanf("%c", &c[i][j]);
	}

	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			d[i][j] = inf;

	d[ax][ay] = 0;
	q.insert(mp(0, mp(ax, ay)));
	while (sz(q)) {
		int x = q.begin()->s.f, y = q.begin()->s.s;
		q.erase(q.begin());
		for (int i = 0; i < 4; ++i) {
			int tox = x + dx[i], toy = y + dy[i];
			if (in(tox, toy) && c[tox][toy] == '.' && d[tox][toy] > d[x][y]) {
				q.erase(mp(d[tox][toy], mp(tox, toy)));
				d[tox][toy] = d[x][y];
				q.insert(mp(d[tox][toy], mp(tox, toy)));
			}
		}

		for (int tox = x - 2; tox <= x + 2; ++tox)
			for (int toy = y - 2; toy <= y + 2; ++toy) {
				if (in(tox, toy) && c[tox][toy] == '.' && d[tox][toy] > d[x][y] + 1) {
					q.erase(mp(d[tox][toy], mp(tox, toy)));
					d[tox][toy] = d[x][y] + 1;
					q.insert(mp(d[tox][toy], mp(tox, toy)));
				}				
			}
	}

	if (d[bx][by] == inf)
		d[bx][by] = -1;

	cout << d[bx][by] << endl;
	
}

Measured memory_bytes: 8844
#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std;

int main(){
    int N, M, a;
    cin >> N >> M;
    unordered_set<int> As;
    for(int i = 0; i < M; ++i){
        cin >> a;
        As.insert(a);
    }

    vector<int> table(N+2);
    table[N] = 1;
    const int mod = 1000000007;
    for(int i = N-1; i >= 0; --i){
        if(As.find(i) == As.end()){
            table[i] = (table[i+1] + table[i+2]) % mod;
        }else{
            table[i] = 0;
        }
    }    
    cout << table[0] << endl;
    return 0;
}

Measured memory_bytes: 4772
#include <cstdio>
using ll = long long;

const ll mod = 1000000007;
int N, M;
ll xd, yd, p, c;

int main() {
    scanf("%d %d %lld", &N, &M, &p);
    for (ll i = 1; i < N; i++) {
        scanf("%lld", &c);
        xd = (xd+(((c-p)*i)%mod)*(N-i))%mod;
        p = c;
    }
    scanf("%lld", &p);
    for (ll i = 1; i < M; i++) {
        scanf("%lld", &c);
        yd = (yd+(((c-p)*i)%mod)*(M-i))%mod;
        p = c;
    }
    printf("%lld\n", (xd*yd)%mod);
}

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

////////////////////////////Solution Referred/////////////////////
int main()
{
    ll n;
    cin>>n;
    ll a[n][3];
    for(ll j=0;j<n;j++)
    {
        cin>>a[j][0]>>a[j][1]>>a[j][2];
    }

    ll dp[n+1][3];
    for(ll j=0;j<3;j++)
    {
        dp[1][j]=a[0][j];
    }

    for(ll j=2;j<=n;j++)
    {
        for(ll k=0;k<3;k++)
        {
            ll s=(k+1)%3;
            ll g=(k+2)%3;
            dp[j][k]=max(dp[j-1][s],dp[j-1][g])+a[j-1][k];
        }
    }
    ll maxi=max(max(dp[n][0],dp[n][1]),dp[n][2]);
    //cout<<dp[n][0]<<" "<<dp[n][1]<<" "<<dp[n][2]<<endl;
    cout<<maxi<<endl;
    return 0;
}


Measured memory_bytes: 4992
use whiteread::parse_line;

fn dist(start: (i32, i32), goal: (i32, i32)) -> f64 {
    (((start.0 - goal.0).pow(2) + (start.1 - goal.1).pow(2)) as f64).sqrt()
}

fn main() {
    let n: usize = parse_line().unwrap();
    let mut x: Vec<i32> = Vec::new();
    let mut y: Vec<i32> = Vec::new();
    let mut ans: f64 = 0.0;

    for _ in 0..n {
        let (xi, yi): (i32, i32) = parse_line().unwrap();
        x.push(xi);
        y.push(yi);
    }
    for i in 0..n {
        for k in 0..i {
            ans += dist((x[i], y[i]), (x[k], y[k]));
        }
    }
    println!("{}", ans / (n as f64 / 2.0));
}


Measured memory_bytes: 2192
N=int(input())
s=input()
R=[0]
G=[0]
B=[0]
ans=0
#RGBの累積和を作る
for i in range(N):
  if s[i]=="R":
    R[i]+=1
  elif s[i]=="G":
    G[i]+=1
  else:
    B[i]+=1
  R.append(R[i])
  G.append(G[i])
  B.append(B[i])
del R[-1]
del G[-1]
del B[-1]
#作った
 
#全探索する
for i in range(N-2):
  a=s[i]
  for j in range(i+1,N-1):
    if a==s[j]:
      continue
    b=s[j]
    k=2*j-i
    if "R" not in a+b:
      ans+=R[-1]-R[j]
      if k>=N:
        continue
      if s[k]=="R":
        ans-=1
    
    if "G" not in a+b:
      ans+=G[-1]-G[j]
      if k>=N:
        continue
      if s[k]=="G":
        ans-=1

    if "B" not in a+b:
      ans+=B[-1]-B[j]
      if k>=N:
        continue
      if s[k]=="B":
        ans-=1
print(ans)

Measured memory_bytes: 74268
package main

import "fmt"

func abs(x float64) float64 {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var n, t, a int
	fmt.Scan(&n, &t, &a)

	var x float64
	min := 100000000.0
	index := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&x)
		if v := abs(float64(t) - x*0.006 - float64(a)); v < min {
			min = v
			index = i + 1
		}
	}
	fmt.Println(index)
}


Measured memory_bytes: 512
nm = input().split(" ");
n = int(nm[0]);
m = int(nm[1]);
k = [0]*m;
s = [[0]*n for i in range(m)];

for i in range(m) :
	st = input().split(" ");
	k[i] = int(st[0]);
	for j in range(k[i]) :
		s[i][j] = int(st[j+1]);
p = input().split(" ");
for i in range(m) :
	p[i] = int(p[i]);

ans = 0;
for i in range(2**n) :
	ok = 1;
	for j in range(m) :
		count_s = 0;
		for l in range(k[j]) :
			if ((i >> (n-s[j][l])) & 1) :
				count_s += 1;
		if count_s % 2 != p[j] :
			ok = 0;
	if bool(ok) :
		ans += 1;

print(ans);
	

Measured memory_bytes: 3064
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define NMAX 200001

int a[NMAX], up[NMAX], bt[NMAX];
int imos[NMAX];

void reset(int n) {
    for(int i = 0; i < n; i++) imos[i] = 0;
}

int get_int() {
    int res = 0;
    char c = getchar();
    while(c != EOF && c != ' ' && c != '\n') {
        res *= 10;
        res += c - '0';
        c = getchar();
    }
    return res;
}

void put_int(int n) {
    char c[30];
    int sz = 0;
    c[sz++] = (n % 10) + '0';
    n /= 10;
    while(n > 0) {
        c[sz++] = (n % 10) + '0';
        n /= 10;
    }
    for(int i = sz-1; i >= 0; i--) {
        putchar(c[i]);
    }
    putchar('\n');
}

int max(int a, int b) { 
    if(a > b) return a;
    else return b;
}

int min(int a, int b) { 
    if(a < b) return a;
    else return b;
}

int main(){

    int n, k;
    n = get_int();
    k = get_int();
    for(int i = 0; i < n; i++) a[i] = get_int();

    for(int itr = 0; itr < k; itr++) {
        reset(n+1);
        for(int i = 0; i < n; i++) {
            bt[i] = max(0, i - a[i]);
            up[i] = min(n, i + a[i] + 1);
        }
        for(int i = 0; i < n; i++){
            imos[bt[i]]++;
            imos[up[i]]--;
        }
        int acc = 0;
        for(int i = 0; i < n; i++){
            acc += imos[i];
            a[i] = acc;
        }
        int sum = 0;
        for(int i = 0; i < n; i++) sum += a[i];
        if(sum == n * n) break;
    }

    for(int i = 0; i < n; i++) put_int(a[i]);
    return 0;
}


Measured memory_bytes: 4824
using System;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            var d = new int[6];
            for(var i = int.Parse(Console.ReadLine()); i > 0; --i) {
                var h = (int)double.Parse(Console.ReadLine());
                ++d[(h -= 165) < 0 ? 0 : System.Math.Min((h / 5) + 1, 5)];
            }
            for(int i = 0; i < 6; ++i){
                Console.WriteLine("{0}:{1}", i + 1, new String('*', d[i]));
            }
        }
    }
}

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

int main() {
  string S;
  cin >> S;
  int n = S.size();
  if (S.at(n-1)=='s') cout << S+"es" << endl;
  else cout << S+"s" << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	static llint dp[5001]={};
	static llint ep[5001]={};
	int i,j,n,m;cin>>n>>m;
	dp[m]=1;
	for(i=1;i<=n;i++){
		for(j=0;j<=m;j++){ep[j]=dp[j]*(j+1);}
			for(j=m;j>0;j--){dp[j-1]+=dp[j]*2;dp[j-1]%=mod;ep[j-1]+=dp[j]*(j-1);}
		for(j=0;j<=m;j++){dp[j]=ep[j]%mod;}
	}
	llint ans=0;
	for(j=0;j<=m;j++){ans+=dp[j];}
	cout<<ans%mod<<endl;
	return 0;
}


Measured memory_bytes: 3236
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
    long long int n,w;
    cin>>n>>w;
    long long int a[n][2],i,j,s=0;
    for(i=0;i<n;i++)
    {
         cin>>a[i][0]>>a[i][1];
    }
    long long int dp[w+1][2];
    for(i=0;i<=w;i++)
    {
        dp[i][0]=0;
    }
    dp[0][0]=1;
    dp[0][1]=0;
    long long int g=0;
    long long int k,x;
    for (k = 1; k <= n; k++)
    {
    for(x=w;x>=0;x--)
        {
            if(dp[x][0])
            {
                long long int d= x+a[k-1][0];
                if(d<=w)
                {
                    s=dp[x][1]+a[k-1][1];
                    if(dp[d][0]==1)
                    {
                        if(dp[d][1]<s)
                            dp[d][1]=s;
                    }
                    else
                    {
                    dp[d][0]=1;
                    dp[d][1]=s;
                    }
                    if(dp[d][1]>g)
                        g=dp[d][1];
                }
             }
        }
    }
    cout<<g<<"\n";
    return 0;
}




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

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int N, Y; cin >> N >> Y;

    int x=-1, y=-1, z=-1;

    REP(i, N+1)
    {
        REP(j, N-i+1) {
            if (10000*i + 5000*j + 1000*(N-i-j) == Y) 
            {
                x = i;
                y = j;
                z = N-i-j;
                break;
            }
        }
    }
    
    cout << x << " " << y << " " << z << endl;  
   return 0;
}



Measured memory_bytes: 256
n = int(input())
t,a = map(int, input().split())
data = list(map(int, input().split()))

ideal_temp = a - 10**5
for i in range(n):
  now_temp = t - (data[i]* 0.006)
  if abs(a - now_temp) < abs(a - ideal_temp):
    res = i + 1
    ideal_temp = now_temp
print(res)
  

Measured memory_bytes: 3060
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  string S;
  cin >> S;
  const char* s = S.c_str();
  vll A(S.size());
  REP(i, 0, S.size()) {
    if (s[i] == 'B') {
      A[i] = 0;
    } else {
      A[i] = 1;
    }
  }

  ll idx0 = 0;
  ll count = 0;
  REP(i, 0, S.size()) {
    if (A[i] == 1) {
      count += i - idx0;
      idx0++;
    }
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 2196
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int cl(int a, int b) {
	return (a - (a%b)) / b;//b=0だと積む
}
int up(int a, int b) {
	return cl(a + b - 1, b);//b=0だと積む
}
int ord(int a, int p) {
	if (a%p == 0) {
		return ord(a / p, p) + 1;
	}
	else {
		return 0;
	}
}
int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	int su = 0;
	for (int i = 0; i < n; i++) {
		su = su + a[i];
	}
	int be = abs((a[0] * n) - su);
	for (int i = 0; i < n; i++) {
		int di =abs((a[i] * n) - su);
		if (di < be) {
			ans = i;
			be = di;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int j=0;

  for (int i=0; i<N; i++) {
    string op;
    cin >> op;
    
	if (op == "Y") {
      cout << "Four" << endl;
      break;
    }
    
    else {
      j++;
      
      if (j == N) {
        cout << "Three" << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define M 1000000007
#define ll long long
#define db double
#define pb push_back
#define F first
#define S second
#define vl vector<ll>
#define vvl vector<vl>
#define pii pair<int,int>
#define mkp make_pair

int main()
{
	ll n,k;
	cin >> n >> k;
	ll a[n],dp[n];
	for(ll i=0;i<n;i++) cin >> a[i];
	
	dp[0]=0;
	for(ll i=1;i<n;i++)
	{
		dp[i]=INT_MAX;
		for(ll j=1;j<=k;j++)
		{
			if(i-j>=0) dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
		}
	}
	cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
from collections import defaultdict

def main():
    num, k = map(int, input().split())
    data = [input() for i in range(num)]
    initial_dic = defaultdict(int)
    for i in range(num):
        initial_dic[data[i][0]] += 1

    aaa = list(initial_dic.values())
    aaa.sort(reverse=True)
    ans = 0
    if len(aaa) < k:
        pass
    else:
        while 1:
            if aaa[k - 1] == 0:
                break
            for i in range(k):
                aaa[i] -= 1
            ans += 1
            aaa.sort(reverse=True)

    print(ans)




if __name__ == '__main__':
    main()

Measured memory_bytes: 44376
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef priority_queue<int> Pr; typedef vector<int> V; typedef vector<P> Vp; typedef map<int,int> MP;
const int mod = 1000000007; const Int INF = 1145141919810893931;
#define END {cout<<ans<<'\n'; return 0;}
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) {}
	ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while(b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if(u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}

	bool operator==(ModInt that) const { return x == that.x; }
	bool operator!=(ModInt that) const { return x != that.x; }
	ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
	ModInt<MOD> r = 1;
	while(k) {
		if(k & 1) r *= a;
		a *= a;
		k >>= 1;
	}
	return r;
}
typedef ModInt<mod> mint;

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

    Int n; cin>>n; Int a[n],b[n],al[n],bl[n],c[n]; mint ans=1;
	for (int i = 0; i < n; i++){
		cin>>a[i];
		if(!i)al[i]=a[i];
		else if(a[i-1]<a[i])al[i]=a[i];
		else al[i]=-1;
	}
	for (int i = 0; i < n; i++)cin>>b[i];
	for (int i = n-1; i >= 0; i--){
		if(i==n-1)bl[i]=b[i];
		else if(b[i]>b[i+1])bl[i]=b[i];
		else bl[i]=-1;
	}
	for (int i = 0; i < n; i++){
		if(al[i]<0&&bl[i]<0)ans*=min(a[i],b[i]);
		else{
			if(al[i]>0&&bl[i]>0&&al[i]!=bl[i]){cout<<0<<'\n'; return 0;}
			else if(al[i]<0&&a[i]<b[i]){cout<<0<<'\n'; return 0;}
			else if(bl[i]<0&&b[i]<a[i]){cout<<0<<'\n'; return 0;}
		}
	}
	cout<<ans.get()<<'\n';
}

Measured memory_bytes: 3328
rhombic = Array.new(100).map{Array.new(100, 0)}

n = 0
m = 0
while s = gets
  list = s.chomp.split(",").map{|v| v.to_i}
  list.inject(n > list.size ? m % n + 1 : 0) do |index, v|
    rhombic[m][index] = v
    index + 1
  end
  n = [n, list.size].max
  m += 1
end

dp = Array.new(100).map{Array.new(100, 0)}
dp[0][0] = rhombic[0][0]

for i in 1..2*(n-1)
  dp[i][0] = rhombic[i][0] + dp[i-1][0]
end

for i in 1..2*(n-1)
  for j in 1..n-1
    dp[i][j] = [dp[i-1][j-1], dp[i-1][j]].max + rhombic[i][j]
  end
end

res = 0
for i in 0..n-1
  res = [res, dp[2*(n-1)][i]].max
end

puts res

Measured memory_bytes: 6200
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
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(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int K;
    cin>>K;
    vector<int> cost(K,INF);
    cost[1]=1;
    deque<int> q;
    q.push_front(1);
    while(!q.empty()) {
        int x=q.front(); q.pop_front();
        int y=(x+1)%K;
        if(chmin(cost[y],cost[x]+1)) q.push_back(y);
        int z=x*10%K;
        if(chmin(cost[z],cost[x])) q.push_front(z);
    }
    cout<<cost[0]<<endl;
    return 0;
}



Measured memory_bytes: 1408
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

D = int(input())
Cs = list(mapint())
Ss = [list(mapint()) for _ in range(D)]
Ts = [int(input()) for _ in range(D)]
last = [0]*26

sati = 0
for i in range(D):
    t = Ts[i]-1
    sati += Ss[i][t]
    last[t] = i+1
    for j, l in enumerate(last):
        c = Cs[j]
        sati -= (i+1-l)*c
    print(sati)

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

int n;
long long _count[2] = {0,0};
long long sum, _sum = 0;
bool _plus = false;

int main(){
    cin >> n;
    vector<int> a(n,0), b(n,0);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    
    for(int j = 0; j < 2; j++){
        if(j == 1){
            _plus = true;
        }
        for(int i = 0; i < n; i++){
            _sum = sum;
            sum = sum + a[i];
            //cout << sum << endl;
            if(_plus){
                if(sum >= 0){
                    _count[j] = _count[j] + abs(a[i] - ( - _sum - 1));
                    sum = _sum + ( - _sum - 1);
                }
                _plus = false;
            }else{
                if(sum <= 0){
                    _count[j] = _count[j] + abs(a[i] - ( - _sum + 1));
                    sum = _sum + ( - _sum + 1);
                }
                _plus = true;
            }
        //cout << sum << endl;
        }
        sum = _sum = 0;
    }
    if(_count[0] < _count[1]){
        cout << _count[0] << endl;
    }else{
        cout << _count[1] << endl;
    }
}

Measured memory_bytes: 1024
#include <stdio.h>

#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long llong;

void DLine(std::istream& in, std::ostream& out) {
  int n, x, y;
  in >> n >> x >> y;
  vector<int> dist(n, 0);

  // Node number = i + 1
  --x;
  --y;
  for (int i = 0; i < n; ++i) {
    set<int> next;
    set<int> visited;
    int d = 0;
    next.insert(i);
    while (visited.size() < n) {
      set<int> new_next;
      for (auto j: next) {
        if (visited.find(j) == visited.end()) {
          visited.insert(j);
          ++dist[d];
          if (j >= 1)
            new_next.insert(j - 1);
          if (j < n - 1)
            new_next.insert(j + 1);
          if (j == x)
            new_next.insert(y);
          if (j == y)
            new_next.insert(x);
        }
      }
      ++d;
      next = new_next;
    }
  }

  // answer
  for (int i = 1; i < n; ++i) {
    out << dist[i] / 2 << endl;
  }
}

int main(int argc, char** argv) { DLine(cin, cout); return 0; }


Measured memory_bytes: 888
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
 
struct Edge{
    int a,b,d;
    bool operator<(const Edge a)const{
        return d<a.d;
    }
};
 
int par[100],rank_[100];
 
void init(int n){
    for(int i=0;i<n;i++) par[i] = i, rank_[i] = 1;
}
 
int find(int x){
    if(par[x]==x) return x;
    return par[x] = find(par[x]);
}
 
bool unite(int _a,int _b){
    int a = find(_a), b = find(_b);
    if(a==b) return false;
    if(rank_[a]>rank_[b]) par[b] = a;
    else{
        par[a] = b;
        if(rank_[a]==rank_[b]) rank_[b]++;
    }
    return true;
}
 
int main(){
    int N,M;
    while(cin >> N , N){
        init( N );
        cin >> M;
        Edge e[10000];
        for(int i = 0;i < M; i++) scanf("%d,%d,%d",&e[i].a,&e[i].b,&e[i].d);
        sort(e,e+M);
        int ans = 0;
        for(int i = 0; i < M; i++){
            if(unite(e[i].a, e[i].b)){
                ans += e[i].d/100-1;
            }
        }
        printf("%d\n" ,ans);
    }
}

Measured memory_bytes: 1312
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
using namespace std;
#define ll long long
#include <cstdint>

int main() {
	string s, hoge;
	cin >> s;
	hoge = s;
	reverse(hoge.begin(), hoge.end());
	if (s == hoge)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main(){
    int L; cin >> L; int A[L];
    stack<int> s; 
    bool fg = true; int ans(0);
    map<int,int> mp;

    for(int i=0;i<L;i++){
        int x; cin >> x;
        if(x<0){
            if(s.empty()){
                ans = i;
                fg = false;
                break;
            }
            else if((-1)*x != s.top()){
                ans = i;
                fg = false;
                break;
            }
            else{
                s.pop();
                mp[(-1)*x] = 0;
            }
        }else{
            if(mp[x] == 1){
                ans = i;
                fg = false;
                break;
            }
            else{
                mp[x]++;
                s.push(x);
            }
        }
    }

    if(fg){
        cout << "OK" << endl;
    }
    else{
        cout << ans+1 << endl;
    }

    return 0;

}


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

using namespace std;

long long x[100000], v[100000], cw1[100000], cw2[100000], ccw1[100000], ccw2[100000];

int main() {
	int n;
	long long c, tot, mx = 0;

	scanf("%d %lld", &n, &c);

	for (int i = 0;i < n;++i)
		scanf("%lld %lld", &x[i], &v[i]);

	tot = v[0];
	cw1[0] = max((long long)0, v[0] - x[0]);
	cw2[0] = max((long long)0, v[0] - x[0] * 2);

	mx = cw1[0];

	for (int i = 1;i < n;++i) {
		tot += v[i];
		cw1[i] = max(cw1[i - 1], tot - x[i]);
		cw2[i] = max(cw2[i - 1], tot - x[i] * 2);

		mx = max(mx, cw1[i]);
	}

	tot = v[n - 1];
	ccw1[n - 1] = max((long long)0, v[n - 1] - (c - x[n - 1]));
	ccw2[n - 1] = max((long long)0, v[n - 1] - (c - x[n - 1]) * 2);

	mx = max(mx, ccw1[n - 1]);
	if (n > 1) {
		mx = max(mx, ccw1[n - 1] + cw2[n - 2]);
		mx = max(mx, ccw2[n - 1] + cw1[n - 2]);
	}

	for (int i = n - 2;i >= 0;--i) {
		tot += v[i];
		ccw1[i] = max(ccw1[i + 1], tot - (c - x[i]));
		ccw2[i] = max(ccw2[i + 1], tot - (c - x[i]) * 2);

		mx = max(mx, ccw1[i]);

		if (i > 0) {
			mx = max(mx, ccw1[i] + cw2[i - 1]);
			mx = max(mx, ccw2[i] + cw1[i - 1]);
		}
	}

	printf("%lld", mx);

	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n, k;
    cin >> n >> k;
    bool s[n] = {};
    rep(i, k) {
        int d;
        cin >> d;
        rep(j, d) {
            int a;
            cin >> a;
            a--;
            s[a] = true;
        }
    }
    int ans = 0;
    rep(i, n) {
        if (!s[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int x,y;
  cin >> x >> y;
  for(int i = 0; i < x + 1; i++) {
    if(2*i + 4*(x-i) == y){
      cout << "Yes" << endl;
      break;
    }
    else if(i == x){
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 3636
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map> 
using namespace std;
int n,A[110000],B[110000],len,in[210000],ou[210000],w[210000],father[210000];
map<int,int>M;
int findfather(int k1){
	if (father[k1]==k1) return k1; return father[k1]=findfather(father[k1]);
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&A[i]);
	for (int i=1;i<=n;i++) scanf("%d",&B[i]);
	int tot=0;
	for (int i=1;i<=n;i++)
		if (A[i]!=B[i]){
			if (M[A[i]]==0) M[A[i]]=++len,w[len]=A[i];
			if (M[B[i]]==0) M[B[i]]=++len,w[len]=B[i];
			tot++; ou[M[A[i]]]++; in[M[B[i]]]++;
		}
	int where=0;
	for (int i=1;i<=len;i++)
		if (in[i]>ou[i]){
			if (where||in[i]>ou[i]+1){
				printf("-1\n"); return 0;
			}
			where=i;
		}
	int pre=0;
	for (int i=1;i<=n;i++) pre^=A[i];
	if (where&&pre!=w[where]){
		printf("-1\n"); return 0;
	}
	if (where==0&&M[pre]) where=M[pre];
	for (int i=1;i<=len;i++) father[i]=i;
	int num=len;
	for (int i=1;i<=n;i++)
		if (A[i]!=B[i]){
			int k1=M[A[i]],k2=M[B[i]];
			if (findfather(k1)!=findfather(k2)){
				num--; father[findfather(k1)]=findfather(k2);
			}
		}
	int ans=tot+num-(where>0);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; ll k;
	cin>>s>>k;//0がdig-k個
	ll n=s.size();
	vector<vvl> dp(n+1, vvl(k+2,vl(2,0)));
	dp[0][0][0]=1;
	rep(i,n){
		ll p=s[i]-'0';
		rep(j,k+1){
			// puta(p);
			if(p==0){
				// puta(i,j);
				// puta(dp[i+1][j][0], dp[i][j][0]);
				dp[i+1][j][0] += dp[i][j][0];
			}else{
				dp[i+1][j+1][0] += dp[i][j][0];
				if(p>=2)dp[i+1][j+1][1] += dp[i][j][0]*(p-1);
				dp[i+1][j][1] += dp[i][j][0];
			}
			dp[i+1][j+1][1] += dp[i][j][1]*9;
			dp[i+1][j][1] += dp[i][j][1];
		}
	}
	// puta(dp[1][0]);// / -
	// puta(dp[1][1]);// 1 /
	// puta(dp[2][0]);// / --
	// puta(dp[2][1]);// 10 -1~9
	// puta(dp[3][0]);
	// puta(dp[3][1]);
	
	puta(dp[n][k][0]+dp[n][k][1]);
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

bool Q;
struct Line {
    mutable ll m, c, p;
    bool operator<(const Line& o) const {
        return Q ? p < o.p : m < o.m;
    }
};
struct LineContainer : multiset<Line> {
    // (for doubles, use inf = 1/.0, div(a,b) = a/b)
    const ll inf = LLONG_MAX;
    ll div(ll a, ll b) { // floored division
        return a / b - ((a ^ b) < 0 && a % b); }
    bool isect(iterator x, iterator y) {
        if (y == end()) { x->p = inf; return false; }
        if (x->m == y->m) x->p = x->c > y->c ? inf : -inf;
        else x->p = div(y->c - x->c, x->m - y->m);
        return x->p >= y->p;
    }
    void add(ll m, ll c) {
        auto z = insert({m, c, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p)
            isect(x, erase(y));
    }
    ll query(ll x) {
        if(empty()) return 0;
        Q = 1; auto l = *lower_bound({0,0,x}); Q = 0;
        return l.m * x + l.c;
    }
};

 
signed main() {
    IOS;
    #ifdef LOCAL
        freopen("input.txt","r", stdin);
        freopen("output.txt","w",stdout);
    #endif
    ll n, c, h;
    cin >> n >> c;
    LineContainer lc;
    cin >> h;
    lc.add(2*h, -h*h - c);
    for(int i = 2; i <= n; i++){
        cin >> h;
        ll cur = h*h - lc.query(h);
        lc.add(2*h, -h*h - c - cur);
        if(i == n)
            return cout << cur, 0;
    }
    return 0;
}

Measured memory_bytes: 12800
#include <stdio.h>
#include<string.h>
int main(void){
char input[6];
char str1[]="Sunny";
char str2[]="Cloudy";
char str3[]="Rainy";


  scanf("%s",input);
  
  if(strcmp(input,str1)==0){
      printf("Cloudy");
  }else if(strcmp(input,str2)==0){
      printf("Rainy");
  }else if(strcmp(input,str3)==0){
      printf("Sunny");
  }
  
  return 0;
}


Measured memory_bytes: 128