akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

mp_score = {"r": P, "s": R, "p": S}

lines = [""] * K
for ix in range(len(T)):
    lines[ix%K] += T[ix]

ans = 0
for l in lines:
    before = ""
    for c in l:
        if before == c:
            before = ""

        else:
            ans += mp_score[c]
            before = c

print(ans)
        

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll h, w;
  cin >> h >> w;
  vs s(h);
  rep(i, h) {
    cin >> s[i];
  }

  vvll ans(h, vll(w));

  rep(y, h) {
    rep(x, w) {
      if (s[y][x] == '#') {
        continue;
      }

      ll cnt = 0;
      FOR(u, -1, 2) {
        FOR(v, -1, 2) {
          if (y + v >= 0 && y + v < h) {
            if (x + u >= 0 && x + u < w) {
              if (s[y + v][x + u] == '#') {
                cnt++;
              }
            }
          }
        }
      }
      s[y][x] = '0' + cnt;
    }
  }

  rep(y, h) {
    cout << s[y] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n = sc.read();
    let mut v: Vec<u64> = sc.vec(n);
    v.sort();
    let mut ans = ((v[0] + v[1]) as f64) / 2.0;
    for i in 2..n {
        ans = (ans + v[i] as f64) / 2.0;
    }
    println!("{}", ans);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;

const int N = 1e5 + 10, INF = 0x3f3f3f3f , MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

struct E{
    ll x,y;

}a[N];

void init() {

}

bool cmp1(E e1,E e2) {
    return e1.y > e2.y;
}

bool cmp2(E e1,E e2) {
    return e1.x > e2.x;
}

int main(){
//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
    ios_base::sync_with_stdio(0);
    init();
    int n,s;cin>>n>>s;
    for(int i = 0;i < n;i++) {
        cin>>a[i].x>>a[i].y;
    }
    sort(a,a+n,cmp2);

    ll max_x = a[0].x;
    sort(a,a+n,cmp1);
    int len_t = -1;
    for(int i = 0;i < n;i++) {
        if(a[i].y < max_x) {
            len_t = i;
            break;
        }
    }
    if(len_t == -1) {
        ll sum = 0;
        int res = 0;
        for(int i = 0;i < n;i++) {
            sum += a[i].y;
            res++;
            if(sum >= s) {
                cout<<res<<endl;
                return 0;
            }
        }
        s -= sum;
        res += ceil(s*1.0/max_x);
        cout<<res<<endl;
    } else {
        ll sum = 0;
        int res = 0;
        for(int i = 0;i < len_t;i++) {
            sum += a[i].y;
            res++;
            if(sum >= s) {
                cout<<res<<endl;
                return 0;
            }
        }
        s -= sum;
        res += ceil(s*1.0/max_x);
        cout<<res<<endl;

    }
    return 0;
}


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

int main() {
	int N, L;
	string S[100];
	cin >> N >> L;
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	sort(S, S + N);
	for (int i = 0; i < N; i++) {
		cout << S[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int N,p[44];
vi G[44];
vector<string> con[44];
map<string,int> M;

int f(int cur,int* flag2){
	int flag[44],res=p[cur];
	rep(i,N)flag[i]=flag2[i];
	flag[cur]=1;
	rep(i,G[cur].sz){
		flag[G[cur][i]]=-1;
	}
	rep2(i,cur+1,N)if(flag[i]==0){
		rep(j,G[i].sz){
			if(flag[G[i][j]]!=-1)goto skip;
		}
		flag[i]=1;
		res+=p[i];
		skip:;
	}
	int res2=0;
	rep2(i,cur+1,N)if(flag[i]==0){
		res2=max(res2,f(i,flag));
		flag[i]=-1;
	}
	return res+res2;
}

int main(){
	while(cin>>N && N){
		rep(i,N)G[i].clear(),con[i].clear();
		rep(i,N){
			string s;
			int m;
			cin>>s>>p[i]>>m;
			M[s]=i;
			rep(j,m){
				cin>>s;
				con[i].pb(s);
			}
		}
		rep(i,N){
			rep(j,con[i].sz){
				G[i].pb(M[con[i][j]]);
			}
		}
		int flag[44]={};
		cout<<f(0,flag)<<endl;
	}
}

Measured memory_bytes: 1172
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long LL;
const LL INF = 0x3f3f3f3f3f3f3f3f;

vector <LL> G[200005];
LL n,m,mxd = 0,cnt = 0,c1 = 0,c2 = 0,flg = 0;
LL deg[200005] = {0};
LL vis[200005] = {0};

void dfs(LL u,LL f){
	vis[u] = 1;
	for(LL i = 0;i < G[u].size();i ++){
		LL v = G[u][i];
		if(v == c1 && f != c1) flg = 1;
		if(v == c2 || vis[v]) continue;
		dfs(v,u);
	}
}

int main(){
	ios::sync_with_stdio(false);
	LL u,v;
	cin >> n >> m;
	for(LL i = 1;i <= m;i ++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
		deg[u] ++; deg[v] ++;
	}
	for(LL i = 1;i <= n;i ++){
		if(deg[i] & 1){
			cout << "No" << endl;
			return 0;
		} 
		if(deg[i] == 4){
			cnt ++;
			if(!c1) c1 = i;
			else c2 = i;
		}
		mxd = max(mxd,deg[i]);
	}
	if(mxd >= 6){ cout << "Yes" << endl; return 0; }
	if(mxd <= 2){ cout << "No" << endl; return 0; }
	if(cnt >= 3){ cout << "Yes" << endl; return 0; }
	if(cnt <= 1){ cout << "No" << endl; return 0; }
	
	//cout << c1 << ' ' << c2 << endl;
	dfs(c1,0);
	cout << (flg ? "Yes" : "No") << endl;
	return 0;
}

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

int main()
{
	int n,b[105];
	scanf("%d",&n);
	for(int i = 1;i <= n-1;i++) scanf("%d",&b[i]);
	
	int ans = b[1] + b[n-1];
	for(int i = 2;i <= n-1;i++){
		ans += min(b[i],b[i-1]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  double a, b, num;
  cin >> a >> b;

  if (b<10) {
    num=a*10+b;
  } else if (b<100) {
    num=a*100+b;
  } else {
    num=a*1000+b;
  }

  if (ceil(sqrt(num))==floor(sqrt(num))) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int n, m;
vector<vector<int>> edges, iedges;
vector<double> E;

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) {
        freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
        //freopen("d:\\code\\cpp\\contests\\stdout", "w", stdout);
    }

    cin >> n >> m;
    edges.resize(n); iedges.resize(n); E.resize(n);
    vector<int> sz(n);
    FOR(i, m){
        int u, v;
        cin >> u >> v;
        u--; v--;
        edges[u].push_back(v);
        sz[u]++;
        iedges[v].push_back(u);
    }

    double sol = -1;
    vector<double> es(n);
    FOR(h, n-1) {
        if (edges[h].size() == 1 && sol > -1) continue;
        FOR(u, n) sz[u] = edges[u].size();
        E.clear(); E.resize(n);

        queue<int> Q;
        Q.push(n - 1);
        while (!Q.empty()) {
            int u = Q.front();
            Q.pop();

            int cnt = 0;
            double sum = 0;
            double mm = 0;
            for (int v : edges[u]) {
                es[cnt++] = E[v];
                mm = max(mm, E[v]);
                sum += E[v];
            }
            if (cnt > 1 && u == h) {
                sum -= mm;
                cnt--;
            }
            if (cnt) {
                sum /= cnt;
                E[u] = 1 + sum;
            } else
                E[u] = 0;

            for (int v : iedges[u]) {
                sz[v]--;
                if (sz[v] == 0)
                    Q.push(v);
            }
        }
        if (sol == -1 || E[0] < sol)
            sol = E[0];
    }
    cout << sol << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 2560
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

// AtCoder Functions
var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	S := nextString()
	T := nextString()

	ret := 0
	Sary := strings.Split(S, "")
	Tary := strings.Split(T, "")
	for i := 0; i < 3; i++ {
		if Sary[i] == Tary[i] {
			ret++
		}
	}

	fmt.Println(ret)
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100000;

ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b,a%b);
}

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

int x[N];

int main() {
	int n,a;cin>>n>>a;
	rep(i,n) {cin>>x[i];x[i]-=a;x[i]=abs(x[i]);}
	ll ans=gcd(x[0],x[1]);
	rep(i,n) ans=gcd(ans,x[i]);
	cout<<ans<<endl;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

int main()
{
    int N; cin >> N;
    set<ll> A;
    for(int i=0; i<N; i++){
        ll Ai; cin >> Ai;
        A.insert(Ai);
    }
    int BN; cin >> BN;
    ll B[BN];
    for(int i=0; i<BN; i++){
        ll Bi; cin >> Bi;
        B[i] = Bi;
    }
    int count = 0;
    for(int i=0; i<BN; i++){
        if(A.count(B[i])) count += 1;
    }
    cout << count << endl;
}


Measured memory_bytes: 3144
/// hi_im_manh :D
#include <bits/stdc++.h>
#define reset(a,n) memset(a,0,(n+1)*sizeof(int))
#define endl "\n"
#define llmin LLONG_MIN
#define llmax LLONG_MAX
#define intmax INT_MAX
#define intmin INT_MIN
#define ll long long
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

#define duckman "TASK"

#define input freopen(duckman".inp", "r", stdin);
#define output freopen(duckman".out", "w", stdout);

#define nmax 22000
using namespace std;


int main()
{
    fast;
//    input;
//    output;
    string s;
    int q;
    cin >> s >> q;
    bool r = 0;
    string add[2];
    while (q--) {
        int t;
        cin >> t;
        if (t == 1) {
            r = !r;
        }
        else {
            int f;
            char c;
            cin >> f >> c;
            --f;
            if (f^r) {
                add[1] += c;
            }
            else {
                add[0] = c + add[0];
            }
        }
    }
    string res = add[0] + s + add[1];
    if (r) {
        reverse(res.begin(), res.end());
    }
    cout << res;
}
/*


*/


Measured memory_bytes: 1416
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
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; }
// const ll INF = 1LL <<60;
const int INF = 10000;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int n,t;
  cin>>n>>t;
  int a[n];
  int mimi[n];
  for(int i = 0; i < n; i++){
    cin>>a[i];
  }
  mimi[0]=0;
  int tmpmin = a[0];
  for(int i = 1; i < n; i++){
    tmpmin = min(tmpmin,a[i]);
    mimi[i]=a[i]-tmpmin;
    // cout<<a[i]<<" "<<tmpmin<<" "<<mimi[i]<<endl;
  }
  sort(mimi,mimi+n);

  int cnt=0;
  for(int i = 0; i < n; i++){
    // cout<<mimi[i]<<" ";
    if(mimi[n-1]==mimi[i]){
      cnt++;
    }
  }
  // cout<<endl;
  cout<<cnt<<endl;
  return 0;
}


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

using namespace std;

int main(void)
{
    constexpr int N = 26;
    int D;
    cin >> D;

    int c[N];
    for(auto& c_ : c)
    {
        cin >> c_;
    }

    int s[D][N];
    for(auto& s_ : s)
    {
        for (auto &s__ : s_)
        {
            cin >> s__;
        }
    }

    int t[D];
    for(auto& t_ : t)
    {
        cin >> t_;
    }

    {
        int M;
        cin >> M;

        for (int i = 0; i < M; ++i)
        {
            int d, q;
            cin >> d >> q;
            t[d - 1] = q;

            {
                int score = 0;
                int last[N]{};
                for (int i = 0; i < D; ++i)
                {
                    int select = t[i] - 1;
                    score += s[i][select];
                    last[select] = i + 1;
                    for (int j = 0; j < N; ++j)
                    {
                        score -= c[j] * (i + 1 - last[j]);
                    }
                }
                cout << score << endl;
            }
        }
    }


    return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		String res;
		if(a > 0) {
			res = "Positive";
		}else if(a <= 0 && b >= 0) {
			res = "Zero";

		}else {
			int cnt = -a - (-b)+1;
			if(cnt%2==0) {
				res = "Positive";
			}else {
				res = "Negative";
			}
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(100001)

def dfs(node,w):
  weight = w
  for l in tree[node]:
    if color[l[0]] > -1:
      continue
    color[l[0]] = int (not ((l[1]%2==0) ^ color[node]))
    
    dfs(l[0],l[1])
    


N = int(input())
tree = {}
color = [-1]*(N+1)

for i in range(1,N+1):
  tree[i] = []
for i in range(N-1):
  u,v,w = map(int,input().split())
  tree[u].append([v,w])
  tree[v].append([u,w])
  
color[1] = 0
dfs(1,0)
print('\n'.join(map(str,color[1:])))

Measured memory_bytes: 93568
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll INF = 10000000000000000;

int main()
{
    ll n;
    cin >> n;
    ll a[5]; 
    ll les = INF;
    for(int i = 0; i < 5; i++){
        cin >> a[i];
        les = min(les, a[i]);
    }
    cout << (n - 1) / les + 5 << endl;
}

Measured memory_bytes: 256
H,W,K=map(int,input().split())
l=[]
for i in range(H):
    S=input()
    l.append(S)
l_2d="".join(l)
x=l_2d.count("#")
for i in range(W):
    S=""
    for j in range(H):
        S+=l[j][i]
    l.append(S)
ans=0
for i in range(2**(H+W)):
    bag=[]
    h=[]
    w=[]
    for j in range(H+W):
        if ((i>>j)&1):
            bag.append(l[j])
            if j<H:
                h.append(j)
            else:
                w.append(j-H)
    bag_2d="".join(bag)
    y=bag_2d.count("#")
    for k in h:
        for m in w:
            if l[k][m]=="#":
                y-=1
    if x-y==K:
        ans+=1
print(ans)


        




    









        

    









    

        




    















    



    





    






        






    
















        


























            
    


    


    
    














    


    














Measured memory_bytes: 9084
import sys
import numpy as np
import numba

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


@numba.njit("(i8, i2[:], i4[:,:])", cache=True)
def optimize(D, C, S):
    NUM_ITERS = 30_000_000

    def calc_score(sol):
        last = -np.ones((26, D + 1))
        score = 0
        for d in range(D):
            ct = sol[d]
            score += S[d, ct]
            for i in range(26):
                last[i, d + 1] = last[i, d]
            last[ct, d + 1] = d
            for i in range(26):
                score -= C[i] * (d - last[i, d + 1])
        return score, last

    sol = np.zeros(D, dtype=np.int16)
    last_tmp = -np.ones(26, dtype=np.int16)
    for d in range(D):
        score = 0
        mi = -1
        for x in range(D):
            for i in range(26):
                s = S[x, i] - C[i] * (x - last_tmp[i])
                if score < s:
                    score = s
                    mi = i
        sol[d] = mi
        last_tmp[mi] = d

    sol_bak = sol.copy()
    max_score, last = calc_score(sol)
    last_bak = last.copy()

    def update(d, before, after):
        score = max_score
        score -= S[d, before]
        score += S[d, after]
        lb = last[before, d]
        la = last[after, d]
        da = db = 0
        for x in range(d, D):
            if x > d and sol[x] == before:
                break
            last[before, x + 1] = lb
            db += 1
        score -= C[before] * (d - lb) * db
        for x in range(d, D):
            if x > d and sol[x] == after:
                break
            last[after, x + 1] = d
            da += 1
        score += C[after] * (d - la) * da
        sol[d] = after
        return score

    tried = numba.typed.Dict.empty(
        key_type=numba.types.int32, value_type=numba.types.boolean
    )
    for i in range(NUM_ITERS):
        new_d = np.random.randint(0, D)
        c_before = sol[new_d]
        c_after = np.random.randint(0, 26)
        if c_before == c_after:
            continue
        candidate = new_d * 26 + c_after
        if candidate in tried:
            continue
        tried[candidate] = True
        new_score = update(new_d, c_before, c_after)
        if max_score < new_score:
            max_score = new_score
            sol_bak[:] = sol
            last_bak[c_before, :] = last[c_before, :]
            last_bak[c_after, :] = last[c_after, :]
            tried.clear()
        else:
            sol[:] = sol_bak
            last[c_before, :] = last_bak[c_before, :]
            last[c_after, :] = last_bak[c_after, :]
    return sol


def main():
    D = ini()
    C = np.array(inl(), dtype="int16")
    assert len(C) == 26
    S = np.zeros((D, 26), dtype="int32")
    for i in range(D):
        S[i, :] = inl()

    sol = optimize(D, C, S)
    print(*(sol + 1), sep="\n")


main()


Measured memory_bytes: 109200
#include<stdio.h>

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}
 


int main(){
  int H, i;
  int A[200000];
  scanf("%d", &H);

  for ( i = 1; i <= H; i++ ){ 
    scanf("%d",&A[i]);
  }

  for ( i = 1; i <= H; i++ ){ 
    printf("node %d: key = %d, ",i ,A[i]);

    if(parent(i) >=1){
    printf("parent key = %d, ",A[parent(i)]);
    }

    if(left(i) <= H){
    printf("left key = %d, ",A[left(i)]);
    }
    if(right(i) <= H){
    printf("right key = %d, ",A[right(i)]);
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
int a[3];
int b[3]={5,5,7};
int main(void)
{
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if(!memcmp(a,b,sizeof(a)))
    {
        puts("YES");
    }
    else
    {
        puts("NO");
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){
    int A,B,C;  cin>>A>>B>>C;
    int five=0,seven=0;
    if(A==5){
        ++five;
    }
    else if(A==7){
        ++seven;
    }
    if(B==5){
        ++five;
    }
    else if(B==7){
        ++seven;
    }
    if(C==5){
        ++five;
    }
    else if(C==7){
        ++seven;
    }
    if(five==2&&seven==1){
        cout<<"YES"<<endl;
        return 0;
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
// LNU_Algotesters
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <fstream>
#include <complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = 2*INF * (LL) INF;

const int MAX = 200 * 1000 + 47;
const int MOD = INF;


VI G[MAX];
char A[MAX];
int S[MAX];
int D[MAX];
LL ans = 0;

void dfs(int v, int p = -1)
{
    S[v] = (A[v] == '1');
    D[v] = 0;
    FOR(i, 0, SZ(G[v]))
    {
        int to = G[v][i];
        if (to == p)continue;
        dfs(to, v);
        S[v] += S[to];
        D[v] = max(D[v], D[to] + 1);
    }
}

void DFS(int v, int p = -1, int x = 0)
{
    int mn = INF;
    int mx = max(x, 0), mx2 = 0;
    
    if (A[v] == '1')mn = 0;
    if (S[0] != S[v])mn = min(x, mn);
    
    FOR(i, 0, SZ(G[v]))
    {
        int to = G[v][i];
        if (to == p)continue;
        
        if (D[to] + 1 > mx)
            mx2 = mx, mx = D[to] + 1;
        else mx2 = max(mx2, D[to] + 1);
        
        if (S[to] != 0)mn = min(mn, D[to] + 1);
    
    }
    
    ans += max(0, min(mx-1, mx2+1) - mn + 1);
    
    FOR(i, 0, SZ(G[v]))
    {
        int to = G[v][i];
        if(to == p)continue;
        if (D[to] + 1 == mx)
            DFS(to, v, mx2 + 1);
        else
            DFS(to, v, mx + 1);
    }
}


int main()
{
    int n;
    scanf("%d", &n);
    FOR(i, 0, n-1)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        --x, --y;
        G[x].PB(y);
        G[y].PB(x);
    }
    scanf("%s", A);
    dfs(0);
    DFS(0);
    ++ans;
    printf("%lld\n", ans);
}

Measured memory_bytes: 24832
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for (int i = a; i <= b; i++) {
        string s = to_string(i);
        if (s[0] == s[4] && s[1] == s[3]) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b, c := intScanner(), intScanner(), intScanner()
	if a <= c && c <= b {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int N, M; cin >> N >> M;
  vector<int> S(N), T(M);
  for (auto& s : S) {
    cin >> s;
  }
  for (auto& t : T) {
    cin >> t;
  }

  vector<vector<int>> dp(N, vector<int>(M));
  vector<vector<int>> sum(N, vector<int>(M));

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      auto i0 = i - 1;
      auto j0 = j - 1;
      if (S[i] == T[j]) {
        dp[i][j] += (i0 >= 0 && j0 >= 0) ? sum[i0][j0] : 0;
        dp[i][j] += 1;
        dp[i][j] %= MOD;
      }
      if (i0 >= 0) { sum[i][j] += sum[i0][j]; sum[i][j] %= MOD; }
      if (j0 >= 0) { sum[i][j] += sum[i][j0]; sum[i][j] %= MOD; }
      if (i0 >= 0 && j0 >= 0) { sum[i][j] -= sum[i0][j0]; sum[i][j] = (sum[i][j] + MOD) % MOD; }
      sum[i][j] += dp[i][j];
      sum[i][j] %= MOD;
    }
  }
  int ans = sum[N-1][M-1] + 1;
  ans %= MOD;
  cout << ans << CRLF;

  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 33280
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <random>
#include <time.h>
#include <bitset>
#include <stack>

using namespace std;

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

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

    int ans = 0;
    for (int i = 1; i <= a; ++i) {
        if (i < a) {
            for (int j = 1; j <= 20; ++j) ans += (i == j);
        }
        else {
            for (int j = 1; j <= b; ++j) ans += (i == j);
        }
    }
    
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
//--- pA ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	PrintWriter out;
	public Solution() {
		reader = new Reader();
		out = new PrintWriter(System.out);
		while (reader.hasNext()) {
			run_case();
		}
		out.flush();
	}

	private void run_case() {
		int k = reader.ni();
		int a = reader.ni();
		int b = reader.ni();
		boolean ok = false;
		for (int i=a; i<=b; i++) {
			if (i % k == 0) {
				ok = true;
				break;
			}
		}
		if (ok) {
			out.println("OK");
		} else {
			out.println("NG");
		}
		return;
	}
}


class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public long nl() {return Long.parseLong(this.next());}
	public String ns() {return this.next();}
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());

    ll ans = 0;
    rep(i, n) {
        ll bsize = b[i];
        ll numc = c.end() - upper_bound(c.begin(), c.end(), bsize);
        ll numa = lower_bound(a.begin(), a.end(), bsize) - a.begin();
        ans += numc * numa;
    }
    cout << ans  << endl;
    return 0;

}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define make_unique(x) \
    sort(all((x)));    \
    (x).resize(unique(all((x))) - (x).begin())
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
    cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " = " << arg1 << " | ";
    __f(comma + 1, args...);
}

ll max(ll a, ll b) { return (a > b ? a : b); }
ll min(ll a, ll b) { return (a < b ? a : b); }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
void yes_or_no(ll x)
{
    if (x)
        cout << "YES\n";
    else
        cout << "NO\n";
}
void solve_test()
{
    ll ans = 0;
    string s;
    cin >> s;
    cout << s;
    if (s[s.size() - 1] == 's')
        cout << "es";
    else
        cout << "s";
    //cout << ans << "\n";
}
int main()
{
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    // cin >> t; while (t--)
    solve_test();
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main(void)
{
  int x, y;
  int sum[] = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};

  scanf("%d %d", &x, &y);

  if(sum[x-1] == sum[y-1])
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}


Measured memory_bytes: 128
def solve():
    mod = 10**9+7
    n, k = map(int, input().split())
    m = min(n-1,k)
    ans = 1
    dp0 = [1]*(m+1)
    dp1 = [1]*(m+1)
    for i in range(1,m+1):
        dp0[i] = dp0[i-1]*(n-i+1)*pow(i,mod-2,mod)%mod
        dp1[i] = dp1[i-1]*(n-i)*pow(i,mod-2,mod)%mod
        ans += dp0[i]*dp1[i]%mod
        ans %= mod
    return ans
print(solve())

Measured memory_bytes: 76724
#include <stdio.h>

int main()
{
  int n, ab, retval, m;
  retval = 0;
  scanf("%d", &n);
  for (int i = 1; i < n; i++)
  {
    m = 0;
    ab = n - i;
    for (int j = 1; j <= ab; j++)
    {
      //printf("%d %d %d\n", j, ab, i);

      if (j * j > ab)
      {
        retval += m * 2;
        //printf("%d\n", retval);
        break;
      }
      else if (j * j == ab)
      {
        retval += m * 2 + 1;
        //printf("%d\n", retval);
        break;
      }
      if (ab % j == 0)
      {
        m++;
      }
      //printf("%d\n", m);
    }
  }
  printf("%d\n", retval);
  return 0;
}

Measured memory_bytes: 1736
#include<iostream>
#include<algorithm>
#include<string>
#include<set>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int N;
  cin >> N;
  int d[N];
  REP(i, N) cin >> d[i];

  set<int> values;
  REP(i, N) values.insert(d[i]);

  cout << values.size() << endl;


  return 0;
}


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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

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


int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n , k , q , x;
    cin >> n >> k >> q;
    vi freq(n);
    loop(i,q){
        cin >> x;
        freq[x-1]++;
    }

    loop(i,n){
        int score = k - q + freq[i];
        if(score > 0)cout << "Yes" << endl;
        else cout << "No" << endl;
    }



    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;

const int mxn=2e5+1;

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

  int t=1;
//  cin>>t;
  int tt=1;
  while(t--){
    int n,i;
    cin>>n;
    int arr[n];
    int ans[n];
    fr(i,0,n)
    cin>>arr[i];
    ll temp=0;
    int cur=1;
    fr(i,0,n)
    {
      temp+=cur*arr[i];
      cur*=-1;
    }
    ans[0]=temp;
    fr(i,0,n-1)
    {
      ans[i+1]=2*(arr[i]-ans[i]/2);
      
   // cout<<"Case #"<<tt<<": ";
   // tt++;
    }
    fr(i,0,n)
    cout<<ans[i]<<" ";
    }
  return 0;
}



Measured memory_bytes: 2176
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

int main(void)
{
	int n;
	while(scanf("%d", &n)==1)
	{
		vi a(n);
		for(auto&m:a) scanf("%d", &m);

		bool ans=true;
		for(auto&m:a)
		{
			if(m%2==0)
			{
				if(m%3!=0 && m%5!=0) ans=false;
			}
		}
		printf("%s\n", ans?"APPROVED":"DENIED");
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }

int main() {
    int n; cin >> n;
    long long inc, dec; cin >> inc >> dec;
    if (inc + dec - 1 > n || inc * dec < n) return !(cout << -1 << endl);
    vector<int> a(n);
    iota(a.begin(), a.end(), 1);
    #define rev(s, t) reverse(begin(a) + s, begin(a) + t);
    if (dec > 1) {
        if (inc * dec == n) {
            for (int i = 0; i < n; i += dec) rev(i, i + dec);
        } else {
            int q = (n - inc) / (dec - 1);
            int r = (n - inc) % (dec - 1);
            for (int i = 0; i < dec * q; i += dec) rev(i, i + dec);
            rev(dec * q, dec * q + r + 1);
        }
    }
    cout << a << endl;
    return 0;
}


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

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

  int tmp = n % 10;
  if (tmp == 3)
    cout << "bon" << endl;
  else if (tmp == 0 || tmp == 1 || tmp == 6 || tmp == 8)
    cout << "pon" << endl;
  else
    cout << "hon" << endl;
  
}

Measured memory_bytes: 3632
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vit vector<lint>::iterator
#define all(x) (x).begin(),(x).end()
#define rep(x) for(int i = 0;i < (x);i++)
#define repj(x) for(int j = 0;j < (x);j++)
#define REP(i,x) for(int (i) = 0;(i) < (x);(i)++)
#define rrep(x) for(int i = (x);i >= 0;i--)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define mod 1000000007
#define graph_set(n) struct edge{int to,int cost;} vector<edge> G((n))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define range(x,y) ((x) >= 0 && (x) < h && (y) >= 0 && (y) < w)
#define pyes cout << "Yes" << endl
#define pno cout << "No" << endl
#define fin return 0
typedef vector<long long> vi;
typedef vector<pair<long long, long long>> vp;
typedef vector<vector<long long>> vvi;
typedef pair<long long, long long> pi;
typedef long long lint;
typedef long long ll;
lint qp(int a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
lint qp(int a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
lint gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
long long INF = 1e19;

//////////////////////////////////////////////////////////////////////
int num = 32;

int main() {
	int n; cin >> n;
	vi a(n); rep(n)cin >> a[i];
	
	for (int i = 0; i < 32; i++) {
		int c1=0, c2=0;
		for (int j = 0; j < n; j++) {
			if (((a[j]>>i)&1) == 0) c1++;
			else c2++;
		}
		if (!(c2 == 0 || c1 * 2 == c2)) { pno; fin; }
	}
	pyes; fin;
}


Measured memory_bytes: 3988
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

//bfs
queue<pair<int, int>>q;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int d[2005][2005];
vector<string>maze(2005);
int h, w;

void bfs(int x, int y) {
	d[x][y] = 0;
	pair<int, int>p;
	while (!q.empty()) {
		p = q.front();
		q.pop();
		for (int i = 0; i < 4; ++i) {
			int nx = p.first + dx[i]; int ny = p.second + dy[i];
			if (0 <= nx && nx < h && 0 <= ny && ny < w && maze[nx][ny] != '#' && d[nx][ny] == 1000000) {
				q.push(make_pair(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;

			}
		}
	}
}

int main() {
	cin >> h >> w;
	int white=0;
	repp(i, 0, h)cin >> maze[i];
	repp(i, 0, h)repp(j, 0, w)d[i][j] = 1000000;
	repp(i, 0, h)repp(j, 0, w)if (maze[i][j] != '#')++white;
	q.push(make_pair(0,0));
	bfs(0,0);
	if (d[h - 1][w - 1] != 1000000)cout << white - d[h - 1][w - 1] - 1 << endl;
	else cout << "-1" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;

  string result = "Three";
  int i = 0;
  while(i < N){
    char S;
    cin >> S;
    if (S == 'Y'){
      result = "Four";
      break;
    }
    i++;
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

S = input()
T = input()

SL = len(S)
TL = len(T)
X = SL - TL + 1
min = SL
for i in range(X):
    dif = 0
    for j in range(TL):
        if S[i+j] != T[j]:
            dif += 1
    if dif < min:
        min = dif
    # print(dif)
print(min)


Measured memory_bytes: 72680
import java.util.Scanner;

public class Main {

	static int cnt;
	public static void main(String[] args) {
		Scanner cin  = new Scanner(System.in);
		while(true){
			cnt=0;
			int x =cin.nextInt();
			int y =cin.nextInt();
			if(x+y==0){
				break;
			}
			if(x<y){
				int tmp = x;
				x = y;
				y = tmp;
			}
			System.out.println(yu(x,y)+" "+cnt);
		}
	}
	static int yu(int x,int y){
		
		if(y==0){
			return x;
		}
		else{
			cnt++;
			return yu(y , x%y);
		}
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
#define MAX 10000

int search(int [],int,int);

int main() {
  
  int n,s[MAX],q,t[MAX],c=0;
  int i;
  
  // input
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&s[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++) scanf("%d",&t[i]);
  
  // Search
  for(i=0;i<q;i++){
    c += search(s,t[i],n);
  }
  printf("%d\n",c);
  
  
  return 0;
}

int search(int *s,int t,int n) {
  
  int i;
  
  for(i=0; i<n; i++){ 
    if( *(s+i) == t) return 1;
  }
  return 0;
}

Measured memory_bytes: 644
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdio>
#include <climits>
#include <set>
#include <map>
using namespace std;

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

typedef long long ll;



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

    cout << 6 - a - b << endl;
    
    return 0;
}

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

using namespace std;

int main(){

    string s;
    cin>>s;

    if(s[0]==s[1]){
        cout<<1<<" "<<2<<endl;return 0;
    }
    REP(i,s.size()-2){
        if(s[i]==s[i+1]||s[i]==s[i+2]){
            cout<<i+1<<" "<<i+3<<endl;
            return 0;
        }
    }
    cout<<-1<<" "<<-1<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    lint N=1;
    for(lint i=0;i<n;i++)N<<=1;
    std::vector<lint>a;
    lint g=N-1;
    {
        std::string s;std::cin>>s;
        a.resize(2*g+1);
        a.at(g)=-1;
        for(lint i=1;i<=g;i++){
            a.at(g+i)=s.at(i-1)=='1';
            a.at(g-i)=!a.at(g+i);
        }
    }
    std::vector<std::vector<lint>>dp(n+1,std::vector<lint>(2*N,-1));
    for(lint i=0;i<N;i++){
        lint x;std::cin>>x;
        dp.at(0).at(i)=dp.at(0).at(N+i)=x;
    }
    for(lint i=0;i<n;i++){
        lint I=1ll<<i;
        for(lint j=0;j<=2*N-2*I;j++){
            lint x=dp.at(i).at(j);
            lint y=dp.at(i).at(j+I);
            dp.at(i+1).at(j)=a.at(g+y-x)?y:x;
        }
    }
    for(lint i=0;i<N;i++){
        std::cout<<dp.at(n).at(i)<<'\n';
    }
}



Measured memory_bytes: 89072