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


using namespace std;

typedef long long ll;



bool isprime[10000000+100];
void sieve()
{
    memset(isprime,true,sizeof(isprime));
    isprime[0]=isprime[1]=false;
    for(ll i=2; i*i<=10000000; i++)
    {
        if(isprime[i])
        {
            for(ll j=i*i; j<=10000000; j+=i)
            {
                isprime[j]=false;
            }
        }
    }
}

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

   string s;
   cin>>s;
   int freq[26]={};
   for(int i=0;i<s.size();i++)
   {
       freq[s[i]-'a']++;
   }
   bool ans = true;
   for(int i=0;i<26;i++)
   {
       if(freq[i]%2!=0)
       {
           ans=false;
           break;
       }
   }
   if(ans)
   {
       cout<<"Yes\n";
   }
   else
   {
       cout<<"No\n";
   }

}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include<math.h>
using namespace std;

typedef long long int ll;
ll  a[51];
ll  p[51];


ll f(ll N,ll X){
    if (N!=0){
        if (X <= 0){
            return 0;
        }
        else if (X == 1){
            return 0;
        }
        else if (X > 1 && X <=a[N-1]+1){
            return f(N-1,X-1);
        }
        else if(X == a[N-1]+2){
            return p[N-1]+1;
        }
        else if(X >= a[N-1]+3 && X <= 2*a[N-1]+2){
            return p[N-1]+ f(N-1,X-a[N-1]-2)+1;
        }
        else {
            return 2*p[N-1]+1;
        }
    }
    else{
        if (X == 0){
            return 0;
        }
        else {
            return 1;
        }
    }
}


int main() {
    ll  N,X; cin >> N >> X;
    a[0] = 1;
    for (ll i=1;i<= 50;i++){
        a[i] = 2*a[i-1]+3;
    }
    p[0] = 1;
    for (ll i=1; i<=50;i++){
        p[i] = 2*p[i-1]+1;
        
    }
    cout << f(N,X) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
  	ll n,a,b;cin>>n>>a>>b;
  	cout << min(b,a*n) << endl;
}


Measured memory_bytes: 256
import java.io.*;
class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		
			String str=br.readLine();
			int n=Integer.parseInt(str);
			int x;
			
			for(int i=3;i<=n;i++){
				if(i%3==0){
					sb.append(" ").append(i);
				}
				else{
					x=i;
					while(x!=0){
						if(x%10==3){
							sb.append(" ").append(i);
							break;
						}
						x/=10;
					}
				}
			}
		System.out.println(sb);
	}
}

Measured memory_bytes: 25640
use std::io::{BufRead, BufWriter, Write};

fn main() {
    let stdin = std::io::stdin();
    let stdout = std::io::stdout();
    solve(&mut stdin.lock(), &mut BufWriter::new(stdout.lock()));
}

fn solve<R: BufRead, W: Write>(stdin: &mut R, stdout: &mut BufWriter<W>) {
    let (n, q): (usize, usize) = stdin.gets().split(' ').values();
    let mut map = stdin.gets().into_bytes();
    for i in 0..n {
        map[i] = map[i] - b'A';
    }
    let mut sp = Vec::new();
    for line in stdin.lines().take(q).map(|x| x.unwrap().into_bytes()) {
        let (t, d) = (line[0] - b'A',
                      if line[2] == b'R' { 1 } else { -1 });
        sp.push((t, d));
    }
    let (mut left, mut right) = (0, n);
    while left < right {
        let mid = (left + right) / 2;
        let t = alive(n, &map, &sp, mid);
        if t == -1 {
            left = mid + 1;
        } else {
            right = mid;
        }
    }
    let leftmost = left;
    let (mut left, mut right) = (0, n);
    while left < right {
        let mid = (left + right) / 2;
        let t = alive(n, &map, &sp, mid);
        if t == 1 {
            right = mid;
        } else {
            left = mid + 1;
        }
    }
    let rightmost = right;
    writeln!(stdout, "{}", rightmost - leftmost).unwrap();
}

fn alive(n: usize, map: &[u8], sp: &[(u8, isize)], mut p: usize) -> isize {
    for &(t, d) in sp {
        if map[p] == t {
            let next = p.wrapping_add(d as usize);
            if next >= n {
                return d;
            }
            p = next;
        }
    }
    0
}

trait Gets { fn gets(&mut self) -> String; }
impl<T: std::io::BufRead> Gets for T {
    fn gets(&mut self) -> String { self.lines().next().unwrap().unwrap() } }

trait Values<T> { fn values(&mut self) -> T; }
impl<'a, I, T1, T2> Values<(T1, T2)> for I
    where I: Iterator<Item=&'a str>,
          T1: std::str::FromStr, T1::Err: std::fmt::Debug,
          T2: std::str::FromStr, T2::Err: std::fmt::Debug {
    fn values(&mut self) -> (T1, T2) {
        (self.next().unwrap().parse().unwrap(),
         self.next().unwrap().parse().unwrap())
    }
}


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

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}


int xs[100010];
int ys[100010];
int ts[100010];
int N;

int main(){

    string s1,s2;
    cin >> s1 >> s2;
    int s = atoi((s1+s2).c_str());
    bool ok = false;
    for(int i = 0; i < 10000; i++){
        if(i * i == s){
            ok = true;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}


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

int main(){
      int n,k;
      cin>>n>>k;
      vector<bool>K(5000000,false);
      vector<int>arr(n);
      for(int i=0;i<n;i++)cin>>arr[i];
      for(int i=0;i<=k;i++){
            if(K[i]==false){
                  for(int j=0;j<n;j++)K[i+arr[j]]=true;
            }
      }
      if(K[k])cout<<"First";
      else cout<<"Second";
	  return 0;
}

Measured memory_bytes: 896
{
  const main = (input: string) => {
    const r = reader(input)

    // @ts-ignore
    const _n = r.n()
    const a = r.ns()
    const len = a.reduce((i, j) => i + j, 0)

    let left = 0
    let right = len
    let min = right - left
    a.forEach(v => {
      left += v
      right -= v
      min = Math.min(Math.floor(Math.abs(right - left)), min)
    })
    console.log(min)
  }

  // const values = obj => Object.keys(obj).map(e => obj[e]);

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const line = s
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    return { lines, line, s, n, ss, ns }
  }

  main(require('fs').readFileSync('/dev/stdin', 'utf8'))
}


Measured memory_bytes: 36932
fun main(args: Array<String>) {
    edpc()
}

fun edpc() {
    val n = readLine()!!.toInt()
    val vacations = (1..n)
        .map { readLine()!!.split(" ").map { it.toLong() } }

    val dp = Array(n + 1) { LongArray(3) { 0 } }
    dp[0][0] = vacations[0][0]
    dp[0][1] = vacations[0][1]
    dp[0][2] = vacations[0][2]

    for (i in 1 until n) {
        val vacation = vacations[i]
        for (j in 0..2) {
            val beforeMax = (0..2).filter { it != j }.map { dp[i - 1][it] }.max()!!
            dp[i][j] = Math.max(dp[i][j], beforeMax + vacation[j])
        }
    }

    val answer = dp[n - 1].max()!!

    println(answer)
}


Measured memory_bytes: 98292
using System;

class ABC149
{
    static void Main()
    {
        string input = Console.ReadLine();
        string[] inputA = input.Split(' ');
        long A = long.Parse(inputA[0]);
        long B = long.Parse(inputA[1]);
        long K = long.Parse(inputA[2]);

        if (A == 0 && B == 0)
        {
            Console.WriteLine(A + " " + B);
            return;
        }
        if (A - K >= 0)
        {
            long AmK = A - K;
            Console.WriteLine(AmK + " " + B);
        }
        else
        {
            long AB = A + B;
            long ABmK = AB - K;
            if (ABmK < 0)
            {
                ABmK = 0;
            }
            else
            {

            }
            Console.Write("0 ");

            Console.WriteLine(ABmK);

        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pii;
typedef pair<pii,ll> piii;
typedef pair<ll,pii> ipii;
#define MOD 1000000007
#define mod(a) ((a)%MOD)
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define dbg(x) cerr<<#x<<" = "<<x<<"\n"
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<"\n"
#define dbg3(x,y,z) cerr<<#x<<" = "<<x<<" , "<<#y<<" = "<<y<<" , "<<#z<<" = "<<z<<"\n"
#define INF (1LL<<60)
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;*/
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(v) v.begin(),v.end()
#define endl '\n'
ll gcd(ll a,ll b){if(a==0) return b; return gcd(b%a,a);}
ll powm(ll base,ll exp,ll mod=MOD) {base%=mod;ll ans=1;while(exp){if(exp&1LL) ans=(ans*base)%mod;exp>>=1LL,base=(base*base)%mod;}return ans;}
 

ll dp[10004][101];
int main(){
      sync;
      string k;
      ll d;
      cin>>k>>d;
   
      dp[0][0]=1;
      for(int i=1;i<=k.size();i++){
          for(int j=0;j<d;j++){
              for(int x=0;x<=9;x++)
                   dp[i][j]=mod(dp[i][j]+dp[i-1][(10*d+j-x)%d]);
          }
      }

        ll ans=0;
        ll res=0;
        for(int i=0;i<k.size();i++){
             for(int j=0;j<k[i]-'0';j++){
                    ans = mod(ans+dp[k.size()-1-i][(2*d-res-j)%d]);                 
             }
                 res = (2*d+res+k[i]-'0')%d;
        }

               ans=mod(MOD+ans-1+(res%d==0));
               cout<<ans<<endl;
}

Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>

using namespace std;
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; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;


vector<ll> nfv(9);

ll rec(const ll x, const bool tight)
{
	if (x <= 0) return 0;
	if (x == 1) return 1;

	if (tight)
	{
		return rec(x - 1, false);
	}
	else
	{
		return rec(x - 1, true) + rec(x - 1, false);
	}
}

ll nff(const ll x)
{
	if (x <= 1) return 1;
	return rec(x, false);
}

ll nf(const ll x)
{
	if (x <= 1) return 1;
	return nfv[x];
}

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

	ll H, W, K;
	cin >> H >> W >> K;

	vector<vector<ll>> dp(H+1, vector<ll>(W, 0));

	
	for (ll i = 0; i < 9; ++i)
	{
		nfv[i] = nff(i);
	}

	dp[0][0] = 1;

	for (ll i = 0; i < H; ++i)
	{
		for (ll j = 0; j < W; ++j)
		{
			if (j >= 1) dp[i + 1][j] += dp[i][j - 1] * nf(j - 1) * nf(W - j - 1);
			dp[i + 1][j] %= MOD;
			dp[i + 1][j] += dp[i][j] * nf(j) * nf(W - j - 1);
			dp[i + 1][j] %= MOD;
			if (j <= W-2) dp[i + 1][j] += dp[i][j + 1] * nf(j) * nf(W - j - 2);
			dp[i + 1][j] %= MOD;
		}
	}

	cout << dp[H][K - 1] << endl;

	//system("pause");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>

using namespace std;
map<string,int> mp;
char c;
char s[15];
long long ans=0;
int main()
{
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%s",s);
		sort(s,s+10);
		ans+=(long long)(mp[s]);
		mp[s]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    long long N;
    cin >> N;
    const auto &res = prime_factorize(N);
    //cout << N << ":";
    long long ans = 0;
    if ( N == 1 ) ans = 0;
    else{
        for (auto p : res) {
            for ( long long countNum = 1; countNum <= p.second; countNum++ ){
                if ( ( countNum + 1 ) * countNum / 2 <= p.second ) ans++;
                else break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
      	String s[] = sc.next().split("");
        int ans = n * 2;
        int count = 0;
        int e = 0,w = 0,back = 0;
      
        for(int i = 0;i < n;i++){
            if(s[i].equals("E")){
              e++;
            }else{
              w++;
            }
        }
        for(int i = 0;i < n;i++){
          count = 0;
            if(s[i].equals("E")){
              e--;
              count = e + back;
            }else{
              count = e + back;
              back++;
            }
          if(count < ans){
            ans = count;
          }
        }
      
        System.out.println(ans); 
    }
}

Measured memory_bytes: 67212
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int a[5],b,c,sum=0;
  string s;
  cin>>b>>c;
  if(b<c) cout<<0<<'\n';
  else cout<<10<<'\n';
  return 0;
}


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

public class Main {
    
    static int n;
    static int ans;
    static int[][] axy;

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        n = Integer.parseInt(sc.next());
        
        ans = 0;
        axy = new int[n+1][n+1];
        
        for(int i = 1; i <= n; i++){
            Arrays.fill(axy[i], -1);
            int a = Integer.parseInt(sc.next());
            for(int j = 0; j < a; j++){
                int x = Integer.parseInt(sc.next());
                int y = Integer.parseInt(sc.next());
                axy[i][x] = y;
            }
        }
        
        makeCombination(n);
        System.out.println(ans);
    }
    
    static void makeCombination(int n){
        
        int[] s = new int[n];
        for(int i = 0; i < s.length; i++){
            s[i] = 0;
        }
        rec(s, 0);
    }
    
    static void rec(int[] s, int i){
        
        if(i == s.length){
            int[] y = new int[n+1];
            Arrays.fill(y, -1);
            for(int j = 1; j <= s.length; j++){
                y[j] = s[j-1];
            }
            for(int j = 1; j <= s.length; j++){
                if(s[j-1] == 1){
                    for(int k = 1; k <= n; k++){
                        if(axy[j][k] == 0 && y[k] == 1){
                            return;
                        }else if(axy[j][k] == 1 && y[k] == 0){
                            return;
                        }else if(axy[j][k] != -1){
                            y[k] = axy[j][k];
                        }
                    }
                }
            }
            
            int count = 0;
            for(int j = 0; j < s.length; j++){
                if(s[j] == 1) count++;
            }
            if(count > ans) ans = count;
            return;
        }
        
        rec(s, i+1);
        s[i] = 1;
        rec(s, i+1);
        s[i] = 0;
    }
}

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

int main(){
    int n, count=0;
    cin >> n;
    vector<int> vec(n);

    for(int i = 0; i < n; i++){
        cin >> vec.at(i);
    }

    sort(vec.begin(), vec.end());

    for(int i = 0; i < n; i++) {

        if(i != n-1) {

            if (max(vec.at(i), vec.at(i + 1)) == vec.at(i)) {
                continue;
            } else {

                count++;
            }
        }
    }

    cout << count+1 << endl;
}

Measured memory_bytes: 256
def func(s):
  n = len(s)
  for i in range(n // 2):
    if s[i] != s[n - i - 1]:
      return False
  for i in range(n // 2, n // 2 + n // 4):
    if s[i] != s[n - i - 1]:
      return False  
  n = n // 2
  for i in range(n // 2):
    if s[i] != s[n - i - 1]:
      return False
    
  return True
    
  
print("Yes" if func(input()) else "No")



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

int main(){
  int n,l;
  cin>>n>>l;
  vector<string>s(n);
  rep(i,n)cin>>s[i];
  sort(s.begin(),s.end());
  rep(i,n)
    cout<<s[i];
  return 0;
}

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

#define rep(i,a,b)                for(ll i=a;i<b;i++)
#define re(i,b)                for(ll i=0;i<b;i++)
#define repr(i,n)                for(ll i=n-1;i>=0;i--)
#define ll long long
#define ld long double
#define pll std::pair<ll, ll> 
#define ppll std::pair<pll, ll>
#define vll std::vector<ll> 
#define vpll std::vector<pll> 
#define vppll std::vector<ppll> 
#define mll std::unordered_map<ll, ll> 
#define mpll std::unordered_map<pll, ll>
#define mppll std::unordered_map<ppll, ll>
#define sll std::set<ll>
#define ff first
#define ss second
#define msll std::multiset<ll>
#define all(c) c.begin(), c.end()
#define allr(c) c.rbegin(), c.rend()
#define srt(x) sort(all(x))
#define rsrt(x) sort(allr(x))
#define eb emplace_back
#define pb push_back
#define s(yy) ll yy;cin>>yy
#define len length()
#define sz size()
const ll mod = 1e9 + 7;
const ll INF = 0x7FFFFFFFFFFFFFFF>>1;

/*#################################################### 
#                                                    #
#                     @author                        #
#                  Parth Lathiya                     #
#      https://www.cse.iitb.ac.in/~parthiitb/        #
#                                                    #
####################################################*/


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifdef PARTH_LATHIYA_HOME

        freopen("C_in.txt","r",stdin);
    
        ll ttt,bkkk;
        cin>>ttt;
        bkkk=ttt;
        while(ttt--) {
            cout<<"Testcase - "<<bkkk-ttt<<"\n";
    #endif

//--------------------------------------------------------------------------------------

    s(n);
    s(d);
    s(x);
    ll a[n];
    re(i,n)
        cin>>a[i];
    re(i,n)
        x+=((d-1)/a[i])+1;
    cout<<x;


//--------------------------------------------------------------------------------------
    
    #ifdef PARTH_LATHIYA_HOME
        cout<<"\n"; }
    #endif

    return 0;
}

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

int main(){

 int N, K;
 cin >> N >> K;
  
 int sum = 0;
 
 for(int i = 0; i < N; i++){
  int xi;
  cin >> xi;
   
  if(xi < K - xi){
   sum += 2 * xi;
  }
  
  else{
   sum += 2 * (K - xi);
  }
 }
 cout << sum << endl;
}

Measured memory_bytes: 3504
#include "bits/stdc++.h"
using namespace std;

const int MAXN = 1e5 + 5;

int n, a[MAXN];
map<int, int> num;
vector<int> vals;

int main(){
	scanf("%d", &n);
	bool doZero = false;
	for(int i = 0; i< n; ++i){
		scanf("%d", &a[i]);
		num[a[i]]++;
		if(a[i] == 0)
			doZero = true;
	}
	if(n%3 == 0){
		if(num.size() > 3){
			printf("No\n");
		}else if(num.size() == 3){
			// All should equal
			vector<int> vals, nums;
			for(auto i : num){
				vals.push_back(i.first);
				nums.push_back(i.second);
				assert(i.second > 0);
			}
			assert(nums.size() == 3);
			if(nums[0] == nums[1] && nums[1] == nums[2] && (vals[0]^vals[1]) == vals[2]){
				printf("Yes\n");
			}else{
				printf("No\n");
			}
		}else if(num.size() == 2){
			vector<int> vals, nums;
			for(auto i : num){
				vals.push_back(i.first);
				nums.push_back(i.second);
			}

			bool valid = true;
			assert(nums.size() == 2);
			if(vals[0] == 0){
				if(2*nums[0] != nums[1])
					valid = false;
			}else if(vals[1] == 0){
				if(2*nums[1] != nums[0])
					valid = false;
			}else{
				valid = false;
			}
			if(valid)
				printf("Yes\n");
			else
				printf("No\n");
		}else{
			if(doZero){
				printf("Yes\n");
			}else{
				printf("No\n");
			}
		}
	}else{
		if(num.size() == 1 && doZero){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}
}

Measured memory_bytes: 4224
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();
        if(a+b ==15) {
            System.out.println("+");
        }else if(a*b==15) {
            System.out.println("*");
        }else {
            System.out.println("x");
        }

    }

}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
//using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX
 
 
 
 
void solve()
{
  int n;
  cin >> n;
  int ans[n+1] = {0};
  rep(i,1,100)
    rep(j,1,100)
        rep(k,1,100)
        {
            int curr = ((i+j)*(i+j) + (i+k)*(i+k) + (j+k)*(j+k))/2;
            if(curr <= n)
                ans[curr]++;
        }

    rep(i,1,n)
        cout << ans[i] << endl;
}
 
 
signed main()
{
    
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    cin>>K>>Q;
    vec d(K);
    rep(i,K) cin>>d[i];
    rep(query, Q){
        cin>>N>>A>>M;
        vec md(K);
        ll num_zero = 0, skip = 0, sum_p = 0, sum_r = A % M;
        rep(i,K){
            md[i] = d[i] % M;
            num_zero += ll(md[i] == 0) * (((N - 1) / K) + (((N - 1) % K) > i));
            sum_p += (md[i] * (((N - 1) / K) + (((N - 1) % K) > i))) / M;
            sum_r += (md[i] * (((N - 1) / K) + (((N - 1) % K) > i))) % M;
        }
        skip = sum_p + (sum_r / M);
        cout<<N - 1 - skip - num_zero<<endl;
    }
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
String s=sc.nextLine();
char c[]=s.toCharArray();
for(int i=0;i<3;i++){
	if(c[i]=='1'){
		c[i]='9';
	}else{
		c[i]='1';
	}
}
for(int i=0;i<=2;i++){
	System.out.print(c[i]);
}
System.out.println();
	}
}

Measured memory_bytes: 21716
def main():
    N  = int(input())
    cnt = 0
    for i in range(1,N+1,2):
        if len(make_divisors(i))==8:
            cnt+=1
    print (cnt)

    

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


if __name__ == '__main__':
    main()

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

int main(){
   long long sum=0,n;
   scanf("%lld",&n);
   for(long long i=1;i<=n;i++){
    if(i%3&&i%5){
        sum+=i;
    }
   }
   printf("%lld",sum);
   return 0;
}


Measured memory_bytes: 3820
import math
import fractions
import collections
import itertools
#gcd(A)=XなるAがいくつあるかを、1<=X<=Kで探査できれば問題ない
#gcdを決めうつ
#gcd(A)=aXなる条件はAの各要素がXの倍数であることであるためその個数はceil(K//X)^Nとなる
#そのうちgcd(A)=Xとなるものは#C(gcd(A)=aX)-#C(gcd(A)=2X)-...-#C(gcd(A)=nX)である
#よって上から順にgcd(A)=Xなるものを探すことができそう
N,K=map(int,input().split())
gcdnum=[0]*(K+1)
num=0
ans=0
p=10**9+7
for i in range(K,0,-1):
    num=pow(K//i,N,p)
    #print(K//i,i)
    for j in range(2,(K//i)+1):
        num=(num-gcdnum[j*i])%p
    gcdnum[i]=num
#print(gcdnum)
for i in range(K+1):
    ans=(ans+(gcdnum[i]*i)%p)%p
print(ans)

Measured memory_bytes: 73980
#include <iostream>


using namespace std;

int main() {

	int h, w, n;

	scanf("%d %d %d", &h, &w, &n);

	int grid[h][w];
	int color[n + 1] = {0};

	for (int i = 1; i <= n; ++i) {
		scanf("%d", &color[i]);
	}

	int c = 0;

	for (int i = 0; i < h; ++i) {
		if(i % 2) {
			for (int j = w - 1; j >= 0; --j) {
				while(color[c] == 0) {
					c++;
				}
				grid[i][j] = c;
				color[c]--;
			}
		} else {
			for (int j = 0; j < w; ++j) {
				while(color[c] == 0) {
					c++;
				}
				grid[i][j] = c;
				color[c]--;
			}
		}
	}

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			printf("%d ", grid[i][j]);
		}
		printf("\n");
	}


	return 0;
}

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

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

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
  string s, t;
  cin >> s >> t;
  int count = 0;
  rep(i, s.size()) if (s[i] != t[i]) count++;
  cout << count << endl;
}


Measured memory_bytes: 3856
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim D As Integer = NextInt()
        Dim N As Integer = NextInt()

        Dim ans As Integer = (N + B2I(N = 100)) * CInt(100 ^ D)
        WriteLine(ans)
    End Sub

    Function B2I(ok As Boolean) As Integer
        If ok Then Return 1
        Return 0
    End Function

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


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

int main(){
  const int Nbit= 200000;
  int Ntown; int64_t Nteleport;
  cin >> Ntown >> Nteleport;

  vector<int> data(Ntown);
  int buf;
  for(int i=0; i<Ntown; i++){
    cin >> buf;
    buf--; // 1-indexed -> 0-indexed
    data.at(i)= buf;
  }

  bitset<Nbit> bs;
  unordered_map<int, int64_t> teleport;
  vector<int> path;
  int64_t cnt= 0; int town_tmp= 0;
  while(!bs.test(town_tmp)){
    bs.set(town_tmp);
    path.emplace_back(town_tmp);
    teleport[town_tmp]= cnt;

    town_tmp= data.at(town_tmp);
    cnt++;
  }
  int64_t Toffset= teleport.at(town_tmp);
  int64_t Tcycle = cnt- teleport.at(town_tmp);

  int ans= (Nteleport < Toffset) ? path.at(Nteleport)
                                 : path.at(Toffset+ (Nteleport- Toffset) % Tcycle);
  ans++; // 0-indexed -> 1-indexed

  cout << ans << endl;
}

Measured memory_bytes: 12768
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n-1];
        int sum = 0;
        for(int i=0;i<n;i++){
            a[i] = Integer.parseInt(sc.next())-1;
        }
        for(int i=0;i<n;i++){
            b[i] = Integer.parseInt(sc.next());
        }
        for(int i=0;i<n-1;i++){
            c[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        int prev = -2;
        for(int i=0;i<n;i++){
            sum+=b[a[i]];
            if(a[i] - prev == 1){
                sum+=c[prev];
            }
            prev = a[i];
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 23124
def main():
    n = int(input())
    a = list(map(int,input().split()))
    init = 1000
    pinit = a[0]
    pprev = a[0]
    for i in range(1,len(a)):
        if(pprev > a[i]):
            c = init//pinit
            init -= c * pinit
            init += c*pprev
            pinit = a[i]
        pprev = a[i]
    if(pinit < a[n-1]):
        c = init//pinit
        init += c*(a[n-1] - pinit)
    print(init)
    return

if __name__=="__main__":
    main()


Measured memory_bytes: 9196
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> listA = new ArrayList<>();
		ArrayList<Integer> listB = new ArrayList<>();
		ArrayList<Integer> listC = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			listA.add(Integer.parseInt(sc.next()));
		}
		for(int i = 0; i < N; i++) {
			listB.add(Integer.parseInt(sc.next()));
		}
		for(int i = 0; i < N - 1; i++) {
			listC.add(Integer.parseInt(sc.next()));
		}
		sc.close();

		int satisfaction = 0;
		for(int i = 0; i < listA.size(); i++) {
			int tmp = listA.get(i) - 1;
			satisfaction += listB.get(tmp);
			if(i > 0) {
				if(listA.get(i) == listA.get(i - 1) + 1) {
					satisfaction += listC.get(listA.get(i - 1) - 1);
				}else {
					continue;
				}
			}
		}
		System.out.println(satisfaction);

	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define x             first
#define y             second
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define PI            3.14159265358979
#define N             200005

int solve(){
    int n,k; cin>>n>>k;
    int a[n+1];
    a[0]=0;
    for (int i = 1; i <= n; ++i)
    {
        cin>>a[i];
    }
    int dp[n+1]={};
    dp[1]=0; dp[2]=abs(a[2]-a[1]);
    for (int i = 3; i <= n; ++i)
    {
        dp[i]=1e18;
        for(int j=max(1ll,i-k); j<=i-1; j++){
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
        }
        // dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
        // cout<<i<<" "<<dp[i]<<"\n";
    }
    cout<<dp[n];
    return 0;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

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

main(){
  int n;
  int m[40000],y[40000];
  int t[40000];
  int c,w;
  int cheak;
  while(cin >> n,n){
    c=0;
    w=0;
    cheak=0;
    for(int i=0;i<n;i++){
      cin >> m[i];
    }
    for(int i=0;i<n;i++){
      cin >> y[i];
    }

    sort(m,m+n,greater<int>());
    sort(y,y+n,greater<int>());
    
    for(int i=0;i<n && cheak==0;i++){
      if(m[i]>y[i-w])w++;
      if(w>(i+1)/2)cheak=i+1;
    }
    if(cheak>0 && cheak<n)cout << cheak << endl;
    else cout << "NA" << endl;
  }
}

Measured memory_bytes: 1492
#![allow(unused)]
use std::io::{self, Read};

fn get_stdin() -> String {
    let mut buf = String::new();
    let mut stdin = io::stdin();
    stdin.read_to_string(&mut buf);
    return buf
}

fn to_num(ss: &str) -> i32 {
    ss.trim().parse().unwrap()
}

fn main() {
    let input = get_stdin();
    let n = to_num(&input);
    let mut buf = String::new();
    let mut cnt = 1;
    while cnt <= n {
        if (cnt % 3 == 0) | contain3(cnt) {
            buf.push(' ');
            buf.push_str(&cnt.to_string());
        }
        cnt += 1;
    }
    println!("{}", buf);
}

fn contain3(num: i32) -> bool {
    num.to_string().contains("3")
}



Measured memory_bytes: 5048
#include<iostream>
#include<algorithm>
using namespace std;
int n, t, x[100005], l, r;
int main() {
	cin >> n >> t;
	for (int i = 0; i < n; i++) {
		cin >> l >> r; x[l]++; x[r]--;
	}
	for (int i = 1; i <= t; i++)x[i] += x[i - 1];
	int maxn = 0;
	for (int i = 0; i < t; i++) {
		maxn = max(maxn, x[i]);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 3464
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

typedef long long int64;

int main()
{
	int time = 1;

	while(true) {
	
		int w, n;
		int value[1000], weight[1000];
		
		scanf("%d", &w);
		if(w == 0)
			break;
		scanf("%d", &n);
		for(int i = 0; i < n; ++i)
			scanf("%d,%d", value + i, weight + i);
			
		static int dp[1001][1001] = {0};
		
		for(int a = 1; a <= n; ++a) {
		
			int tw = weight[a - 1];
			int tv = value[a - 1];
			
			for(int b = 0; b <= w; ++b)
				dp[a][b] = dp[a - 1][b];
			
			for(int b = tw; b <= w; ++b)
				dp[a][b] = max(dp[a - 1][b - tw] + tv, dp[a][b]);
		}
		
		int ansv = dp[n][w];
		int answ = w;
		
		while(answ > 0) {
		
			if(dp[n][answ] == dp[n][answ - 1])
				answ -= 1;
			else
				break;
		}
		
		printf("Case %d:\n%d\n%d\n", time++, ansv, answ);
	}
	
	return 0;
}

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

using namespace std;

using ll = long long;

ll CD[1000 * 1000];

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

    int n;
    ll v;
    cin >> n >> v;

    ll A[n], B[n], C[n], D[n];
    for (auto &e: { A, B, C, D }) {
        for (int i = 0; i < n; ++i) {
            cin >> e[i];
        }
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            CD[i * n + j] = C[i] + D[j];
        }
    }
    sort(CD, CD + n * n);

    ll res = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            ll cd = v - (A[i] + B[j]);
            res += upper_bound(CD, CD + n * n, cd)
                    - lower_bound(CD, CD + n * n, cd);
        }
    }

    cout << res << '\n';

    return 0;
}



Measured memory_bytes: 11060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
 
using namespace std;
 
typedef unsigned long long ull;
typedef unsigned int uint;
typedef unsigned char uchar;
#define umap unordered_map
const static ull INVALID_DIGIT = ~(ull)0;

int main()
{
    unsigned int N;
    cin >> N;
    std::vector<ull> H(N);
    for (auto i=0u; i<N; i++) {
        cin >> H[i];
    }
    for (auto i=1u; i<N; i++) {
        if (H[i-1] > H[i] && abs(long(H[i-1] - H[i])) >= 2.) {
            cout << "No" << endl;
            return 0;
        }
        if (H[i-1] != H[i]) {
            H[i]--;
        }

        if (H[i-1] > H[i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff

int A,B;
int D[15][15],F[305][305];

void init(){
	scanf("%d%d",&A,&B);
	for(int i=1;i<=A;i++){
		for(int j=1;j<=B;j++){
			scanf("%d",&D[i][j]);
		}
	}
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			for(int x=1;x<=A;x++){
				for(int y=1;y<=B;y++){
					F[i][j]=max(F[i][j],D[x][y]-i*x-j*y);
				}
			}
		}
	}
	for(int x=1;x<=A;x++){
		for(int y=1;y<=B;y++){
			int f=INF;
			for(int i=0;i<=100;i++){
				for(int j=0;j<=100;j++){
					f=min(f,F[i][j]+i*x+j*y);
				}
			}
			if(f!=D[x][y]){
				printf("Impossible");
				return;
			}
		}
	}
	printf("Possible\n202 10401\n");
	for(int i=1;i<=100;i++){
		printf("%d %d X\n",i,i+1);
	}
	for(int i=102;i<202;i++){
		printf("%d %d Y\n",i,i+1);
	}
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			printf("%d %d %d\n",i+1,202-j,F[i][j]);
		}
	}
	printf("1 202\n");
}

int main(void){
	init();
	return 0;
}

Measured memory_bytes: 512
def q(a,h):
 d[a]=str(h)
 for b in t[a]:q(b,h+1)
t,p,d={},{},{}
for _ in[0]*int(input()):
 e=input().split()
 t[e[0]]=e[2:]
 for i in e[2:]:p[i]=e[0]
r=(set(t)-set(p)).pop()
p[r]='-1'
q(r,0)
for i in sorted(map(int,t)):i=str(i);print(f"node {i}: parent = {p[i]}, depth = {d[i]}, {'root'if'-1'==p[i]else'internal node'if t[i]else'leaf'}, [{', '.join(t[i])}]")


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

using i64 = int64_t;

int main(){
    int n;
    cin >> n;
    i64 ans = 0, mini = LLONG_MAX, cnt = 0;
    for(int i=0;i<n;++i){
        i64 a;
        cin >> a;
        ans += abs(a);
        mini = min(mini, abs(a));
        if(a < 0)cnt++;
    }

    if(cnt%2)ans -= mini*2;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
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();
	 int C = sc.nextInt();
	 
	 System.out.println(A==B&&B==C ? "Yes":"No");
	 
	
}

		
	}



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

int main()
{
    int N, W;
    cin >> N >> W;
    vector<int> values(N+1);
    vector<int> weights(N+1);
    for (int i=1; i<=N; i++) cin >> values[i] >> weights[i];
    vector<vector<int>> table(N+1, vector<int>(W+1, 0));
    for (int i=1; i<=N; i++)
    {
        for (int w=1; w<=W; w++)
        {
            if (weights[i]>w) table[i][w]=table[i-1][w];
            else
            {
                table[i][w] = max(table[i-1][w], table[i-1][w-weights[i]]+values[i]);
            }
        }
    }
    cout << table[N][W] << endl;

}


Measured memory_bytes: 6840
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

fn main() {
    let _ = read::<usize>();
    let aa = readv::<usize>();
    let bb = readv::<usize>();
    let x = aa.iter().fold(0, |acc, &a| acc ^ a);
    let (mut aa, bb): (Vec<_>, Vec<_>) = aa.iter().zip(bb.iter()).filter(|&(&a, &b)| a != b).unzip();
    let n = aa.len();
    aa.push(x);
    let mut nums = HashMap::with_capacity(n + 1);
    for &a in &aa {
        *nums.entry(a).or_insert(0) += 1;
    }
    // let mut nums: HashMap<_, i32> = aa.iter()
    //     .fold(HashMap::with_capacity(n + 1), |mut acc, &a| { *acc.entry(a).or_insert(0) += 1; acc });
    for &b in &bb {
        *nums.entry(b).or_insert(0) -= 1;
        if nums[&b] < 0 {
            println!("{}", -1);
            return;
        }
    }

    let mut dests = bb.iter().enumerate()
        .fold(HashMap::new(), |mut acc, (a, b)| { (acc.entry(b).or_insert(Vec::new())).push(a); acc });
    let mut q: VecDeque<_> = std::iter::once(n).collect();
    let mut rems: HashSet<_> = (0..n + 1).collect();
    let mut ans = n;
    #[cfg(local)] println!("{}: {:?}", "(aa, bb)", (&aa, &bb));
    while !rems.is_empty() {
        while let Some(s_idx) = q.pop_front() {
            if !rems.remove(&s_idx) { continue; }
            let s_num = aa[s_idx];
            if let Some(destv) = dests.remove(&s_num) {
                for dest in destv {
                    q.push_back(dest);
                }
            }
        }
        if let Some(&rem) = rems.iter().next() {
            q.push_back(rem);
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

constexpr int nax = 15, max_m = nax * (nax - 1) / 2, mod = 1e9 + 7;

int n, m;
int graph[nax + 1], dp[1 << nax], pow2[max_m + 1], pop[1 << nax];

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

    cin >> n >> m;

    for (int i = 0; i < (1 << n); ++i)
        pop[i] = __builtin_popcount(i);

    pow2[0] = 1;
    for (int i = 1; i <= m; ++i)
    {
        pow2[i] = pow2[i - 1] * 2;
        if (pow2[i] >= mod)
            pow2[i] -= mod;
    }

    for (int i = 0; i < m; ++i)
    {
        int p, q; cin >> p >> q;
        --p, --q;
        graph[p] |= (1 << q);
    }

    dp[0] = 1;
    for (int mask = 1; mask < (1 << n); ++mask)
        if ((mask & 1) == ((mask >> 1) & 1))
            for (int sub = mask; ; sub = (sub - 1) & mask)
                if ((sub & 1) == ((sub >> 1) & 1))
                {
                    int comp = mask xor sub;
                    int summand = 1;
                    for (int v = 0; v < n; ++v)
                        if (mask & (1 << v))
                        {
                            if (sub & (1 << v))
                                summand = ((ll)summand * (pow2[pop[graph[v] & comp]] - 1)) % mod;
                            else
                                summand = ((ll)summand * (pow2[pop[graph[v] & sub]] - 0)) % mod;
                        }
                    int to_add = ((ll)summand * dp[sub]) % mod;
                    dp[mask] = (dp[mask] + to_add) % mod;

                    if (sub == 0)
                        break;
                }

    int result = pow2[m] - dp[(1 << n) - 1];
    if (result < 0) result += mod;
    cout << result << '\n';
}


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


def solve(inp):
    N = int(inp.readline().strip())
    A = map(int, inp.readline().strip().split(' '))

    A = sorted(A)
    prev = A[0]
    for a in A[1:]:
        if prev == a:
            return "NO"
        prev = a

    return "YES"


def main():
    import sys
    result = solve(sys.stdin)
    if result is not None and result != '':
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26808
n = int(raw_input())
primes = [True] * ((10 ** 5) + 1)
for t in range(2,len(primes)):
	if primes[t]:
		k = 2
		while(k*t < len(primes)):
			primes[k*t] = False
			k +=1
dp = [0] * ((10 ** 5) + 1)
count = 0

for i in range(2,len(primes)):
	if primes[i] and primes[(i+1)/2] and i % 2:
		count +=1
	dp[i] = count
for _ in range(n):
	u,v = map(int, raw_input().split())
	print dp[v] - dp[u-1]

Measured memory_bytes: 82068
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

char s[1005][1005];
int main(void){
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if((i+j)%2==0){
				s[i][j] = '#';
			}else{
				s[i][j] = '.';
			}
		}
	}
	int ans = 0;
	for(int i=0;i<N;i++){
		if(s[i][0] =='.'){
			ans ++;
			s[i][0] = 'x';
		}
		if(s[N-1][i] =='.'){
			ans++;
			s[N-1][i] = 'x';
		}
	}
	for(int i=0;i<N;i++)
		if(i%3==0){
			for(int j=0;j<N;j++){
				if(s[i][j] =='.'){
					ans++;
					s[i][j] = 'x';
				}
			}
		}
	
	cout << ans << endl;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++){
		if(s[i][j] =='x')cout << i << " " << j << endl;
	}
}

Measured memory_bytes: 2432
N = int(input())
H = []
for _ in range(N):
    a, b, c = map(int, input().split())
    H.append([a, b, c])

dp = [[float('inf')] * 3 for _ in range(N+1)]
dp[0] = [0, 0, 0]
for i in range(1, N+1):
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + H[i-1][0] 
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + H[i-1][1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + H[i-1][2]
print(max(dp[N]))



Measured memory_bytes: 42544
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf=0x3f3f3f3f;
#define pii pair<int,int>
char maze[1005][1005];
int vis[1005][1005];
int c1,c2,d1,d2;
queue<pii> q[2];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0}; 
int main()
{
    int h,w;
    cin>>h>>w>>c1>>c2>>d1>>d2;
    for(int i=0;i<=h+1;i++){
    	for(int j=0;j<=w+1;j++){
    		maze[i][j]='#';
		}
	}
     for(int i=1;i<=h;i++)
        scanf("%s",maze[i]+1);
    bool flag=true;
    vis[c1][c2]=1;
    int x=0,ans=0;
    q[x].push(pii(c1,c2));
    while(1){
    	while(!q[x].empty()){
    		pii now=q[x].front();
    		q[1-x].push(now);
    		q[x].pop();
    		for(int i=0;i<4;i++){
    		  int tx=now.first+dx[i];
    		  int ty=now.second+dy[i];
    		  if(!vis[tx][ty]&&maze[tx][ty]=='.'){
    		  	q[x].push(pii(tx,ty));
    		  	q[1-x].push(pii(tx,ty));
    		  	vis[tx][ty]=1;
			  }
			}
		}
	   if(vis[d1][d2]) break;
	   x=1-x;ans++;
	   		while(q[x].size()){
    		pii now=q[x].front();
    		q[x].pop();
    		for(int i=-2;i<=2;i++){
    			for(int j=-2;j<=2;j++){
    		  int tx=now.first+i;
    		  int ty=now.second+j;
    		  if(tx<0||tx>h)continue;
    		  if(ty<0||ty>w)continue;
    		  if(!vis[tx][ty]&&maze[tx][ty]=='.'){
    		  	q[1-x].push(pii(tx,ty));
    		  	vis[tx][ty]=1;
			  }
			}
		}
	}
  if(vis[d1][d2]) break;
	   x=1-x;
	if(q[x].empty()) {
		flag=false;break;
	}

  }
  	if(!flag){
  cout<<"-1"; 
  }
  else printf("%d\n",ans);

return 0;
}



Measured memory_bytes: 8660