akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	string s;
	while(cin>>s) {
		map<char, ll> h;
		REP(i, 4) h[s[i]]++;
		string ans = "No";
		if(h.size()==2 && h[s[0]]==2) ans = "Yes";
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,k,x,y,w;
	scanf("%d %d %d %d",&n,&k,&x,&y);
		if(n<k){
			w=n*x;
		}
		else{
			w=k*x+((n-k)*y);
		}
	printf("%d\n",w);
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[]) {
    double theta;
    double s,h,a,b,c;
    scanf("%lf %lf %lf",&a,&b,&theta);
    theta=theta*M_PI/180;
    s=a*b*sin(theta)/2;
    c=sqrt(a*a+b*b-2*a*b*cos(theta));
    h=2/a*s;
    printf("%f\n",s);
    printf("%f\n",a+b+c);
    printf("%f\n",h);


    
    
    
    return 0;
}

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

// A

using namespace std;


int main(int argc, char **argv)
{
	
	int x , y , z;
	
	cin >> x >> y >> z;
	
	swap(x ,y);
	swap(x , z);
	
	cout << x << " " << y << " " << z << "\n";
	
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a,b,c;
    int i;
    int count=0;
    scanf("%d%d%d",&a,&b,&c);
    for(i=a;i<=b;i++){
        if(c%i==0){
            count = count + 1;
        }
    }
    printf("%d\n",count);







    return 0;
}

Measured memory_bytes: 596
#include <stdio.h>

int main(void)
{
  int r;
  double cir;
  
  do {
    scanf("%d",&r);
  } while(r<1 || r>100);
  
  cir = 2*r*3.14159;
  
  printf("%f",cir);
  
  return 0;
}

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

int main(){
  int A, B;
  cin >> A >> B;
  int count = 0;
  for(int i=A;i<=B;++i){
    //5ケタであることから1,2,4,5桁目の判定を行う。回文数であれば3桁目は変わらないので。
    int n1 = i % 10;
    int n2 = i /10 % 10;
    int n4 = i /1000 % 10;
    int n5 = i /10000 % 10;
    if(n1 == n5 and n2 == n4) ++count;
  }
  cout << count << endl;
  return 0;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define ll long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18
        
        int main() {
 

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        string s;
        cin>>s;
        if(s[2]==s[3]&&s[4]==s[5])
            cout<<"Yes";
        else
            cout<<"No";

        return 0;
        }

Measured memory_bytes: 256
def turn(d,dir)
  case dir
  when "North" then d[0],d[1],d[5],d[4] = d[1],d[5],d[4],d[0]
  when "South" then d[0],d[1],d[5],d[4] = d[4],d[0],d[1],d[5]
  when "West" then d[0],d[2],d[5],d[3] = d[2],d[5],d[3],d[0]
  when "East" then d[0],d[2],d[5],d[3] = d[3],d[0],d[2],d[5]
  when "Right" then d[1],d[2],d[4],d[3] = d[2],d[4],d[3],d[1]
  when "Left" then d[1],d[2],d[4],d[3] = d[3],d[1],d[2],d[4]
  end
  d
end

while true
  n = gets.to_i
  break if n == 0
  d = Array.new(6){|i| i+1}
  ans = 1
  n.times do
    dir = gets.chomp 
    d = turn(d,dir)
    ans += d[0]
  end
  puts ans
end

Measured memory_bytes: 8816
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 >=1 && A <= 9) && (B >=1 && B <= 9)){
			System.out.println(A*B);
		} else {
			System.out.println("-1");
		}
	}

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef string str;
typedef vector<str> vst;typedef vector<ll> vll;
ll mod = 1000000007, INF = 10000000000000000;
ll gcd(ll a, ll b){if(b==0){return a;}return gcd(b, a%b);}
// for (ll i = 0; i < n; i++) {
// sort(.begin(),.end());

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

  for(i=1;i<n-1;i++){
    if((p[i+1]-p[i])*(p[i-1]-p[i])<0){
      c++;
    }
  }

  cout<<c<<endl;
}
    


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        a: [i64; n],
    }

    let sum = a.iter().sum::<i64>();

    let mut ans = 0;
    let mut dist = sum + 1;
    for i in 0..n {
        let d = (sum - a[i] * n as i64).abs();
        if d < dist {
            dist = d;
            ans = i;
        }
    }

    println!("{}", ans);
}


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

using namespace std;

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

    bool F[n];
    for(int i=0; i<n; i++) F[i] = true;

    int d, a;
    for(int i=0; i<k; i++) {
        cin >> d;
        for(int j=0; j<d; j++) {
            cin >> a;
            F[a-1] = false;
        }
    }

    int cnt = 0;
    for(int i=0; i<n; i++) if(F[i]) cnt++;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3624
n=int(input())
s=int(input())
if n==s:
  print(n+1)
  exit()
if n<s:
  print(-1)
  exit()
for b in range(2,int(n**(1/2))+1):
  m=n
  wa=0
  while m>0:
    wa+=m%b
    m=m//b
  if wa==s:
    print(b)
    exit()

for p in range(int((n-1)**(1/2)),0,-1):
  if (n-s)%p==0:
    b=(n-s)//p+1
    if p+n%b==s:
      print(b)
      exit()
print(-1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;
 
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
 
int h, w, counts=0;
vector<string> fi;

const int INF = 1000000001;
 
int main() {
    cin >> h >> w;
    fi.resize(h);
    for (int i = 0; i < h; ++i) cin >> fi.at(i);
 
    vector<vector<int> > dist(h, vector<int>(w, INF));
     
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            if (fi.at(i).at(j)=='.')
            {
                dist.at(i).at(j) = -1;
                counts++;
            }
        }
    }

    if (dist.at(0).at(0) == INF || dist.at(h-1).at(w-1) == INF)
    {
        cout << -1 << endl;
        return 0;
    }
 
    dist.at(0).at(0) = 1;
     
    queue<pint> que;
    que.push(pint(0, 0));
 
    // BFS
    while(!que.empty()) {
        auto cur = que.front();
        que.pop();
 
        for (int dir = 0; dir < 4; ++dir)
        {
            int nx = cur.first + dx[dir];
            int ny = cur.second + dy[dir];

            if (nx < 0 || h <= nx || ny < 0 || w <= ny) continue;
            if (dist.at(nx).at(ny)==INF) continue;
 
            if (dist.at(nx).at(ny)==-1)
            {
                dist.at(nx).at(ny) = dist.at(cur.first).at(cur.second) + 1;
                que.push(pint(nx, ny));
            }
        }
    }
    
    if (dist.at(h-1).at(w-1) == -1)
    {
        cout << -1 << endl;
        return 0;
    } else {
        cout << counts - dist.at(h-1).at(w-1) << endl;
    }
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto K = RD;
	string s = "ACL";

	string ans;
	foreach (i; 0..K)
		ans ~= s;
	
	writeln(ans);
	stdout.flush;
	debug readln;
}


Measured memory_bytes: 2696
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
#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 fi first
#define se second
typedef long long ll;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    cin>>N>>M;
    N *= 3;
    N += M;
    N /= 2;
    cout << N << endl;
}

Measured memory_bytes: 256
class PriorityQueue

  def initialize(capacity)
    @items = Array.new(capacity)
    @size = 0
  end

  def push(x)
    n = @size
    @items[n] = x
    @size += 1
    while n != 0
      p = (n - 1) / 2
      if @items[n] > @items[p]
        @items[p], @items[n] = @items[n], @items[p]
      end
      n = p
    end
  end

  def pop
    result = @items[0]
    @items[0] = @items[@size - 1]
    @size -= 1

    n = 0
    loop do
      left = 2 * n + 1
      break if left >= @size

      right = left + 1
      if (right < @size) && (@items[right] > @items[left])
        c = right
      else
        c = left
      end

      break unless @items[c] > @items[n]

      @items[n], @items[c] = @items[c], @items[n]
      n = c
    end
    result
  end

  def empty?
    @size == 0
  end

  def size
    @size
  end
end

n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort.reverse
 
queue = PriorityQueue.new(n)
a.each do |x|
	queue.push x
end
while m > 0
	x = queue.pop
	queue.push x / 2
	m -= 1
end

ans = 0
until queue.empty?
	ans += queue.pop
end
puts ans


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

const long b_max = 100000;

long solve(int n, std::vector<long>& integers)
{
  integers.insert(integers.begin(), b_max);
  integers.push_back(b_max);

  long result = 0;
  for (int i = 0; i < n; ++i) {
    result += std::min(integers[i], integers[i + 1]);
  }
  return result;
}

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

  std::vector<long> integers(n - 1);
  for (auto& b : integers) {
    std::cin >> b;
  }

  std::cout << solve(n, integers) << std::endl;
}


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

int main() {
	// your code goes here
	int n;
	cin>>n;
	vector<double> a(n+1);
	int i,j;
	for(i=1;i<=n;i++)
	cin>>a[i];
	a[0]=1;
	vector<vector<double>> dp(n+1,vector<double> (n+1,0));
	for(i=0;i<=n;i++)
	{
	    dp[0][i]=1;
	    dp[i][0]=1;
	}
	for(i=1;i<=n;i++)
	{
	    for(j=1;j<=n;j++)
	   { if(i==1&&j==1)
	   dp[i][j]=a[1];
	   else
	   if(i<j)
	   dp[i][j]=0;
	   else
	       dp[i][j]=dp[i-1][j]*(1-a[i])+dp[i-1][j-1]*a[i];}
	}

	cout<<fixed<<setprecision(10)<<dp[n][n/2+1]<<"\n";
	return 0;
}


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

#define int long long

template <class Monoid> struct SegmentTree{
    using Func = function<Monoid(Monoid, Monoid)>;

    int size;
    vector<Monoid> seg;
    const Func merge;
    const Monoid def;

    SegmentTree(int n, Monoid d, const Func f): merge(f), def(d){
        for(size = 1; size <= n; size <<= 1);
        seg.assign(size*2, def);
    }

    Monoid& operator[] (int i) { return seg[i+size]; };
    void build(){ for(int i = size-1;i >= 0;i--) seg[i] = merge(seg[i*2], seg[i*2+1]); } 

    void update(int i, Monoid val){
        seg[i += size] = val;
        while(i >>= 1) seg[i] = merge(seg[i*2], seg[i*2+1]);
    }

    void add(int i, Monoid val){ update(i, val+seg[i+size]); }

    Monoid get(int a, int b){
        Monoid l = def, r = def;
        for(a += size, b += size; a < b; a >>= 1, b >>= 1){
            if(a & 1) l = merge(l, seg[a++]);
            if(b & 1) r = merge(seg[--b], r);
        }
        return merge(l, r);
    }
};

signed main(){
	int n;
	cin >> n;
	vector<SegmentTree<bool>> seg(26, SegmentTree<bool>(n, false, [](bool a, bool b){
			return a || b;
	}));

	string s;
	cin >> s;
	
	for(int i = 0;i < n;i++){
		seg[s[i]-'a'].update(i, true);
	}

	int q;
	cin >> q;

	for(int i = 0;i < q;i++){
		int que;
		cin >> que;
		if(que == 1){
			int idx;
			char c;
			cin >> idx >> c;
			idx--;
			seg[s[idx]-'a'].update(idx, false);
			s[idx] = c;
			seg[s[idx]-'a'].update(idx, true);
		}else{
			int ans = 0;
			int l, r;
			cin >> l >> r;
			l--; r--;
			for(int j = 'a';j <= 'z';j++){
				if(seg[j-'a'].get(l, r+1)) ans++;
			}
			cout << ans << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 4480
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		while(true) {
			int n = sc.nextInt();
			if(n == -1) break;
			double x = 1;
			double y = 0;
			double ang = 180;
			
			for(int i = 0; i < n-1; i++) {
				ang -= 90;
				y += Math.sin(Math.toRadians(ang));
				x += Math.cos(Math.toRadians(ang));
				ang = Math.toDegrees(Math.atan2(-y, -x));
			}
			out.println(x);
			out.println(y);
		}
		out.flush();

	}
}
//------------------------------//
//-----------//
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    
    public int nextInt() {
    	return (int)nextLong();
    }
    

}

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

const int MOD = 1e9 + 7;

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    ll res = 0;
    for (int d = 0; d < 60; d++) {
        ll n0 = 0, n1 = 0;
        for (int i = 0; i < N; i++) {
            if ((A[i] >> d) & 1) n1++;
            else ++n0;
        }
        ll tmp = (1ll << d) % MOD;
        ll n = n0 * n1 % MOD;
        tmp = tmp * n % MOD;
        res = (res + tmp) % MOD;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin >> s;    
  if((s[0]==s[1])&(s[2]==s[3])&(s[0]==s[3])){
    cout << "No"<< endl;
    return 0;
  }
  if((s[0]==s[1])&(s[2]==s[3])){
    cout << "Yes"<< endl;
    return 0;
  }
  if((s[0]==s[2])&(s[1]==s[3])){
    cout << "Yes"<<endl;;
    return 0;
  }
  if((s[0]==s[3])&(s[1]==s[2])){
    cout << "Yes"<< endl;;
    return 0;
  }
  
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  DPpractice
//
//  Created by abhishek kumar on 20/04/20.
//  Copyright © 2020 abhishek kumar. All rights reserved.
//

#include <iostream>
#include<utility>
#include<math.h>
#include<vector>
#include<math.h>
using namespace std;
typedef long long int ll;
const long long int N=1000;
ll n,w,k,m,temp,arr[N+1][N+1],dp[N+1][N+1],visited[N+1][N+1];



void maxi(ll& a,ll b)
{
    a=max(a,b);
}

int main(int argc, const char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>w;
    ll weight,value;
    vector<pair<ll,ll>> store;
    for(auto i=0;i<n;i++)
    {
        cin>>weight>>value;
        store.push_back(make_pair(weight, value));
    }
    
    vector<ll> dp(w+1,0);
    dp[0]=0;
    
        for(auto j=0;j<store.size();j++)
        {
            for(auto wt=w-store[j].first;wt>=0;wt--)
            {
                maxi(dp[wt+store[j].first], dp[wt]+store[j].second);
            }
        }
    ll ans=0;
    for(auto i=0;i<w+1;i++)
        maxi(ans,dp[i]);
    cout<<ans;
  
    return 0;
        
}

Measured memory_bytes: 1024
#include<map>
#include <iostream>
#include<vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(long long)(n);++(i))
using ll = long long;
using P = pair<int, int>;
#define fs first
#define sc second
using namespace std;

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int n;
string s;
map<int, map<string, map<string, ll>>> dp;
map<int, map<string, map<string, bool>>> flag;

ll solve(int idx, string r, string b) {
    if (idx >= n*2) {
        reverse(b.begin(), b.end());
        if (r == b) return 1;
        else return 0;
    }
    if (flag[idx][r][b]) return dp[idx][r][b];
    flag[idx][r][b] = true;
    ll res = 0;
    if (idx < n) {
        res += solve(idx+1, r+s[idx], b);
        res += solve(idx+1, r, b+s[idx]);
    }
    else {
        //
        if (r.size()+1 <= n and s[idx] == b[n-r.size()-1]) res += solve(idx+1, r+s[idx], b);
        if (b.size()+1 <= n and s[idx] == r[n-b.size()-1]) res += solve(idx+1, r, b+s[idx]);
    }
    return (dp[idx][r][b] = res);
}

int main() {
    cin >> n >> s;
    cout << solve(0, "", "") << endl;
    return 0;
}


Measured memory_bytes: 407680
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>

using Int = std::int64_t;

constexpr Int MOD = 1e9 + 7;

int main() {
	Int N, X;
	std::cin >> N >> X;

	std::vector<Int> S(N);
	for (auto&& e : S)
		std::cin >> e;

	std::sort(S.begin(), S.end());

	// dp[i][x] := 最初が x のときに i 個目まで見たときの総和
	std::vector<std::vector<Int>> dp(N + 1, std::vector<Int>(X + 1));
	for (Int x = 0; x < X + 1; ++x)
		dp[0][x] = x;

	for (Int i = 1; i < N + 1; ++i) {
		for (Int x = 0; x < X + 1; ++x) {
			// 前に挿入
			dp[i][x] += dp[i - 1][x % S[i - 1]];
			dp[i][x] %= MOD;
			// 後ろに挿入
			dp[i][x] += (i - 1) * dp[i - 1][x];
			dp[i][x] %= MOD;
		}
	}

	std::cout << dp[N][X] << std::endl;
}

Measured memory_bytes: 158592
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fi first
#define se second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>
 
using std::cin;
using std::cout;
using std::endl;
 
typedef long long ll;
typedef unsigned long long ull;
 
const int N = 200000 + 5;
const int M = 1000 + 5;
const int K = 1e7 + 5;
const int MOD = 1e9 + 7;
const int inv2 = 500000004;
const int LOG = 40;
const ull BASE = 19260817;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };
const double PI = acos(-1);

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
 
template<class T>
inline T readT() {
    T res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}
#define read readT<int>

namespace Comb{
inline void exgcd(ll a, ll b, ll &g, ll &x, ll &y) {
    if (!b) g = a, x = 1, y = 0;
    else exgcd(b, a % b, g, y, x), y -= x * (a / b);
}
 
inline ll inv(ll a) {
    ll g, res, tmp;
    exgcd(a, MOD, g, res, tmp);
    return ((res % MOD) + MOD) % MOD;
}
 
ll f[N], invFact[N];
 
inline void prepare() {
    f[0] = 1;
    int n = 200000;
    for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % MOD;
    invFact[n] = inv(f[n]);
    for (int i = n - 1; i >= 1; i--) invFact[i] = invFact[i + 1] * (i + 1) % MOD;
}
 
inline ll C(int n, int m) {
    if (!m) return 1;
    if (n == m) return 1;
    if (m > n) return 0;
    if (m < 0) return 0;
    return f[n] * invFact[m] % MOD * invFact[n - m] % MOD;
}
}

int n;
String s, t;

int main() {
    cin >> n >> s >> t;
    for (int i = 0; i < n; i++) {
        putchar(s[i]);
        putchar(t[i]);
    }
    puts("");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int v[n];
    for(int i=0;i<n;i++)cin >> v[i];
    map<int,int>odd;
    map<int,int>even;

    for(int i=0;i<n;i++){
        if(i%2==0)even[v[i]]++;
        else odd[v[i]]++;
    }
    int oddMax = 0;
    int evenMax = 0;
    int oddSub = 0;
    int evenSub = 0;
    
    for(int i=1;i<=100000;i++){
        if(odd[i] >= odd[oddMax]){
            oddSub = oddMax;
            oddMax = i;
        }else if(odd[i] > odd[oddSub]){
            oddSub = i;
        }

        if(even[i] >= even[evenMax]){
            evenSub = evenMax;
            evenMax = i;
        }else if(even[i] > even[evenSub]){
            evenSub = i;
        }
    }
    if(evenMax == oddMax){
        if(odd[oddMax] - odd[oddSub] >= even[evenMax] - even[evenSub])evenMax = evenSub;
        else oddMax = oddSub;
    }
    cout << n-odd[oddMax]-even[evenMax]<<endl;


}

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define MOD 1000000007
#define MAX 200010

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

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

long long int f[MAX] = {};
long long int rf[MAX] = {};

long long int pw(long long int x, long long int y) {
  long long ret = 1LL;

  for (long long int mask = 0; mask < 50; ++mask) {
    if (y >> mask & 1)
      ret = ret * x % MOD;
    x = x * x % MOD;
  }
  return ret % MOD;
}

long long int getComb(int n, int k) {
  if (k > n)
    return 0;
  long long int ret = f[n];
  ret = ret * rf[k] % MOD;
  ret = ret * rf[n - k] % MOD;
  return ret;
}

long long int initComb(int n) {
  rf[0] = f[0] = 1;
  for (int i = 1; i < n + 1; i++) {
    f[i] = f[i - 1] * i % MOD;
    rf[i] = pw(f[i], MOD - 2);
  }
  return 1;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  ll N, M, K;
  cin >> N >> M >> K;

  initComb(MAX);

  ll ans = 0;

  FOR(d, 1, N) {
    ll e = (N - d) * M * M % MOD;
    e *= getComb(N * M - 2, K - 2);
    e %= MOD;
    e = e * d % MOD;
    ans += e;
    ans %= MOD;

    // cout << d << " " << e << endl;
  }

  FOR(d, 1, M) {
    ll e = (M - d) * N * N % MOD;
    e *= getComb(N * M - 2, K - 2);
    e %= MOD;
    e = e * d % MOD;
    ans += e;
    ans %= MOD;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>
#include<set>
#include<tuple>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n, q;
    cin >> n >> q;
    vector<ll> s(n), t(n), x(n);
    vector<tuple<ll, ll, ll>> e;
    for(int i = 0; i < n; i++){
        cin >> s[i] >> t[i] >> x[i];
        e.push_back(make_tuple(s[i] - x[i], 1, x[i]));
        e.push_back(make_tuple(t[i] - x[i], -1, x[i]));
    }
    vector<ll> d(q);
    for(int i = 0; i < q; i++){
        cin >> d[i];
    }
    sort(begin(e), end(e));
    set<ll> st;
    int p = 0;
    int ep = 0;
    vector<int> ans(q, -1);
    while(ep < e.size() && p < q){
        while(ep < e.size() && get<0>(e[ep]) <= d[p]){
            if(get<1>(e[ep]) == 1){
                st.insert(get<2>(e[ep]));
            }else{
                st.erase(get<2>(e[ep]));
            }
            ep++;
        }
        if(!st.empty()) ans[p] = *st.begin();
        p++;
    }
    for(int i = 0; i < q; i++){
        cout << ans[i] << endl;
    }
}


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

long a[222222], A[222222], d[111][111];
int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        double x;
        cin >> x;
        long b = round(x * 1e9);
        int c = 0;
        while(b % 2 == 0)
            c++, b /= 2;
        a[i] = c;
        int cc = 0;
        while(b % 5 == 0)
            cc++, b /= 5;
        A[i] = cc;
        d[c][cc]++;
    }
    for(int i = 100; i--;)
        for(int j = 100; j--;)
            d[i][j] += d[i + 1][j];
    for(int i = 100; i--;)
        for(int j = 100; j--;)
            d[i][j] += d[i][j + 1];
    long r = 0;
    for(int i = 0; i < n; i++) {
        int v = a[i];
        int u = max(18 - v, 0);
        int vv = A[i];
        int uu = max(18 - vv, 0);
        int x = d[u][uu];
        if(v >= u && vv >= uu)
            x--;
        r += x;
    }
    cout << r / 2 << endl;
    return 0;
}


Measured memory_bytes: 6920
#include <iostream>
#include <vector>
using namespace std;
int main() {
        int n,app=1;
        cin >> n;    
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
                cin >> a[i];
                if (a[i] % 2 == 0) 
                        if (!(a[i] % 3 == 0 || a[i] % 5 == 0))
                                app = 0;
        }   
        if (app)
                cout << "APPROVED" << endl;
        else
                cout << "DENIED" << endl;
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, A="Yes";
  int N;
  cin >> S;
  N = S.size();
  for (int i=0; i<(N-1)/2; i++){
    if (S.at(i) == S.at(N-1-i))
      continue;
    else
      A = "No";
  }
    for (int i=0; i<(N-1)/2; i++){
    if (S.at(i) == S.at((N-1)/2-1-i))
      continue;
    else
      A = "No";
  }
    for (int i=(N+3)/2; i<N; i++){
    if (S.at(i) == S.at(N-1-i))
      continue;
    else
      A = "No";
  }
  cout << A << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;


const int inf = 0x3f3f3f3f ;
const int maxw = 1000 ;
int g[105][105] , w[105] ;
int a[105] , v[105] , na[105] ;
int n , m ;
int mincut( int n ) {
	int i , j, pv , zj ;
	int best = inf ;
	for( i = 0 ; i < n; i ++ ) {
		v[i] = i ;
	}
	while( n > 1 ) {
		for( a[v[0]] = 1 , i = 1 ; i < n; i ++ ) {
			a[v[i]] = 0 ; na[i-1] = i ;
			w[i] = g[v[0]][v[i]] ;
		}
		for( pv = v[0] ,i = 1 ; i < n ; i ++ ) {
			for( zj = -1 , j = 1 ; j < n ; j ++ ) 
				if( !a[v[j]] && (zj<0||w[j]>w[zj]))
					zj = j ;
				a[v[zj]] = 1 ;
				if( i == n - 1 ) {
					if( best > w[zj] ) best = w[zj] ;
					for( i = 0 ; i < n;  i++ ) {
						g[v[i]][pv] = g[pv][v[i]] +=g[v[zj]][v[i]] ;
					}
					v[zj] = v[--n] ;
					break;
				}
				pv = v[zj] ;
				for( j = 1 ; j < n; j ++ ) if( !a[v[j]])
					w[j] += g[v[zj]][v[j]] ;
		}
	}
	return best ;
}

int main(){
	while( scanf( "%d%d" , &n , &m ) != EOF ) {
		if( n == 0 && m == 0 ) break;
		memset( g , 0 , sizeof(g) ) ;
		int ans = 0 ;
		int i ;
		for( i = 1 ; i <= m ;i ++ ) {
			int from , to ,val ;
			scanf( "%d%d%d" , &from , &to , &val ) ;
			if( val < 0 ) {
				ans += val ;
				continue ;
			}
			if( g[from][to] == inf ) {
				g[from][to] = val ;
			}else{
				g[from][to] += val ;
			}
			g[to][from] = g[from][to] ;
		}
		printf( "%d\n" , ans + mincut(n) )  ;
	}
	return 0 ;
}

Measured memory_bytes: 1076
#include <stdio.h>
int n;
int a[110];
int ans;
int min(int a,int b){
	return a<b?a:b;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d",&a[i]);
	}
	ans+=a[1]+a[n-1];
	for(int i=1;i<n-1;i++){
		ans+=min(a[i],a[i+1]);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
import numpy as np

s = input()
p = np.array([0]*13)
p[0] = 1

amari = [[0]*13 for _ in range(13)]
for j in range(10):
  for i in range(13):
    amari[i][(i*10+j)%13] += 1
M = np.array(amari)

for si in range(len(s)):
  a = np.array([0]*13)
  if s[si] == '?':
    a = np.dot(p,M)
  else:
    c = int(s[si])
    for i in range(13):
      a[(i*10+c)%13] += p[i]
  p = np.mod(a,1000000007)
print(p[5])

Measured memory_bytes: 14588
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();
		int Y=sc.nextInt();
		int ans1=-1;
		int ans2=-1;
		int ans3=-1;
		
		for(int i=0;i<=N;i++) {
			for(int j=0;j<=N;j++) {
				if(i+j<=N) {
					int otosidama=(10000*i)+(5000*j)+1000*(N-i-j);
					if(otosidama==Y) {
						ans1=i;
						ans2=j;
						ans3=N-i-j;
						break;
					}
				}
			}
		}

		System.out.println(ans1+" "+ans2+" "+ans3);

		sc.close();
	}
}


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

int count(long a){
  int cnt = 0;
  while(a > 0){
    a /= 10;
    cnt++;
  }
  return cnt;
}

int main(){
  long n, ans;
  long m = 0;
  cin >> n;
  for(int i = 1; i <= sqrt(n); i++){
    if(n%i == 0){
      m = n/i;
    }
  }
  cout << count(m) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
signed main()
{
    IOS
    string str; cin>>str;
    int n = str.length();
    int ans[n];
    for(int i=0;i<n;i++) ans[i] = 0;
    int lastR=0,rc=0,lc=0,r=0,l=0;
    for(int i=1;i<n;i++)
    {
        if(str[i-1] == 'L' && str[i] == 'L') lc++;
        if(str[i-1] == 'L' && str[i] == 'R')
        {
            rc++;
            //cout<<rc<<" "<<lc<<endl;
            if(rc%2){
                r += (rc/2 + 1);
                l += rc/2;
            } 
            else{
                r += rc/2;
                l += rc/2;
            }
            if(lc%2)
            {
                r += lc/2;
                l += (lc/2 + 1);
            }
            else{
                r += lc/2;
                l += lc/2;
            }
            ans[lastR] = r;
            ans[lastR+1] = l;
            rc = 0,lc=0,r=0,l=0;
        }
        if(str[i-1] == 'R' && str[i] == 'L')
        {
            lc++;
            lastR = i-1;
        }
        if(str[i-1] == 'R' && str[i] == 'R') rc++;
    }
    rc++;
            if(rc%2){
                r += (rc/2 + 1);
                l += rc/2;
            } 
            else{
                r += rc/2;
                l += rc/2;
            }
            if(lc%2)
            {
                r += lc/2;
                l += (lc/2 + 1);
            }
            else{
                r += lc/2;
                l += lc/2;
            }
            ans[lastR] = r;
            ans[lastR+1] = l;

    for(int i=0;i<n;i++)
        cout<<ans[i]<<" ";
    return 0;
}

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

int n, a;
map<int, bool> s;

signed main() {
  
  cin>>n;
  rep(i, n) {
    cin>>a;
    if(s.count(a))s.erase(a);
    else s.insert(make_pair(a, true));
  }
  
  cout<<s.size()<<endl;
  
  return 0;
}

Measured memory_bytes: 6528
#include<cstdio>
#include<complex>
using namespace std;
double X1, Y1, X2, Y2, XQ, YQ;
typedef complex<double> xy_t;
double dot_product(xy_t a, xy_t b) {
	return (conj(a)*b).real();
}
xy_t projection(xy_t p, xy_t 

b) {
	return b*dot_product(p, b) / norm(b);
}
int main() {
	while (scanf("%lf,%lf,%lf,%lf,%lf,%lf",
		&X1, &Y1, &X2, &Y2, &XQ, &YQ) == 6) {
		xy_t P1(X1, Y1), P2(X2, Y2), Q(XQ, YQ);
		xy_t R = P1*2.0 - Q + projection(Q - P1, P2 - P1)*2.0;
		printf("%.6f %.6f\n", real(R), imag(R));
	}
	return 0;
}

Measured memory_bytes: 2788
H,W = [int(i) for i in input().split()]

maze = [['.']*(W+2)]
for i in range(H):
    maze.append(list('.'+input()+'.'))
maze.append(['.']*(W+2))

ans = [[0]*W for _ in range(H)]
for i in range(1,H+1):
    for j in range(1,W+1):
        if maze[i][j] == '#':
            ans[i-1][j-1] = '#'
        else:
            for p,q in [[1,0],[-1,0],[0,1],[0,-1],[1,1],[-1,-1],[1,-1],[-1,1]]:
                if maze[i+p][j+q] == '#':
                    ans[i-1][j-1] += 1

for i in range(H):
    for j in range(W):
        print(ans[i][j],end='')
    print()


Measured memory_bytes: 9184
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    int sum=0;
    for (int i=0; i<m; i++){
        int a;
        cin>>a;
        sum+=a;
    }
    int ans=n-sum;
    if (ans>=0){
        cout<<ans<<endl;
    }
    else{
        cout<<"-1"<<endl;
    }
}

Measured memory_bytes: 3596
#include <iostream>
#include <math.h>
using namespace std;

int GetDigit(int n)
{
  int num = 0;
  while (true)
  {
    if (n == 0)
    {
      break;
    }
    n = n / 10;
    num++;
  }
  return num;
}

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

  int a = sqrt(N);

  for (int A = a;; A--)
  {
    if (N % A == 0)
    {
      int B = N / A;
      ans = GetDigit(B);
      break;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
int n,ans;
int a[5][5],b[6];
int c[5][5];


int check(){
  int res=0;
  for(int i=0;i<5;i++)
    for(int j=0;j<5;j++)
      c[i][j]=a[i][j];
  for(int cnt=1;;cnt++){
    bool flg[5][5]={};
    for(int i=0;i<5;i++){
      for(int j=0;j<5;j++){
        if(c[i][j]==0)continue;
        if(i+2<5&&c[i][j]==c[i+1][j]&&c[i][j]==c[i+2][j])
          flg[i][j]=flg[i+1][j]=flg[i+2][j]=true;
        if(j+2<5&&c[i][j]==c[i][j+1]&&c[i][j]==c[i][j+2])
          flg[i][j]=flg[i][j+1]=flg[i][j+2]=true;
      }
    }
    bool f=true;
    for(int i=0;i<5;i++){
      for(int j=0;j<5;j++){
        if(!flg[i][j])continue;
        res+=(b[c[i][j]]*cnt);
        c[i][j]=0;
        f=false;
      }
    }
    if(f)break;
    for(int j=0;j<5;j++){
      int k=4;
      for(int i=4;i>=0;i--)if(c[i][j])c[k--][j]=c[i][j];
      for(int i=k;i>=0;i--)c[i][j]=0;
    }
  }
  return res;
}

void dfs(int y,int x,int d,int prev){
  ans=max(ans,check());
  if(d==n)return;
  for(int i=0;i<4;i++){
    if((i+2)%4==prev)continue;
    int ny=y+dy[i];
    int nx=x+dx[i];
    if(ny<0||nx<0)continue;
    if(ny>4||nx>4)continue;
    swap(a[ny][nx],a[y][x]);
    dfs(ny,nx,d+1,i);
    swap(a[ny][nx],a[y][x]);
  }
}

int main(){
  while(1){
    cin>>n;
    if(n==-1)break;
    for(int i=0;i<5;i++)
      for(int j=0;j<5;j++)
        cin>>a[i][j];
    for(int i=1;i<=5;i++)cin>>b[i];
    ans=0;
    for(int i=0;i<5;i++)
      for(int j=0;j<5;j++)
        dfs(i,j,0,-1);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N = int(input())
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

count = 0

for i in range(1,N+1,2):
    ans = make_divisors(i)
    if len(ans) == 8:
        count += 1
        
print(count)

Measured memory_bytes: 9416
#include<iostream>
#include<vector>
#include<string>

using namespace std;

struct Union_Find {
	vector<int> rank, par;
	int independent_tree;
	int N;

	Union_Find(int n) {
		N = n;
		for (int i = 0; i < N; i++)rank.push_back(1), par.push_back(i);
		independent_tree = N;
	}

	int getroot(int X) {
		if (par[X] == X)return X;
		return par[X] = getroot(par[X]);
	}

	bool issame(int A, int B) {
		return getroot(A) == getroot(B);
	}

	void unite(int A, int B) {
		A = getroot(A), B = getroot(B);
		if (A == B)return;
		if (rank[A] > rank[B]) {
			par[B] = A;
		}
		else if (rank[A] == rank[B]) {
			par[B] = A;
			rank[A]++;
		}
		else {
			par[A] = B;
		}
	}

};

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

	bool narabi[100000];//true == Sheep  false == Wolf
	for (int bit = 0; bit < 4; bit++) {
		if (bit % 2 == 0)narabi[1] = true;
		else narabi[1] = false;

		if (bit & 2)narabi[0] = false;
		else narabi[0] = true;

		for (int i = 1; i < N - 1; i++) {
			if (s[i] == 'o') {
				if (narabi[i])narabi[i + 1] = narabi[i - 1];
				else narabi[i + 1] = !narabi[i - 1];
			}
			else {
				if (narabi[i])narabi[i + 1] = !narabi[i - 1];
				else narabi[i + 1] = narabi[i - 1];
			}
		}
		bool f = false;
		if ((s[N - 1] == 'o' && (narabi[N - 1] ^ (narabi[N - 2] != narabi[0]))) ^ 
			(s[N - 1] == 'x' && (narabi[N - 1] ^ (narabi[N - 2] == narabi[0])))) {
			if (s[0] == 'o' && (narabi[0] ^ (narabi[N - 1] != narabi[1])))f = true;
			if (s[0] == 'x' && (narabi[0] ^ (narabi[N - 1] == narabi[1])))f = true;
		}
		
		if (f) {
			for (int i = 0; i < N; i++) {
				if (narabi[i])cout << "S";
				else cout << "W";
			}
			cout << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
//#include <unordered_map>
//#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")

using namespace std;

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

//typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <db, db> pdd;

int main() {
	ll N, X;
	scanf("%lld %lld", &N, &X);

	ll ans = N;
	N = N - X;
	while (1) {
		if (N < X) swap(N, X);

		if (N%X == 0) {
			ans += 2 * N - X;
			break;
		}
		else {
			ans += 2 * (N / X) * X;
			N %= X;
		}
	}
	return !printf("%lld\n", ans);
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    int ans = 1;
    for(int i = 1; i * i <= m; i++){
        if(m % i == 0){
            int j = m / i;
            if(j <= m / n){
                cout << j << endl;
                return 0;
            }
            if(i <= m / n){
                ans = i;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
    } 

    if(0 < a[0]) {  // a[0]が0でないときはダメ
        cout << -1 << endl;
        return 0;
    }
    
    rep(i, n-1) {  // a[i+1]がa[i]より2以上大きいときはダメ
        if(a[i] + 1 < a[i+1]) {
            cout << -1 << endl;
            return 0;
        }
    }

    ll ans = 0;
    rep(i, n-1) {
        if(a[i] + 1 == a[i+1]) {
            ans++;
        }
        else {
            ans += a[i+1];
        }
    }

    cout << ans << endl;
    return 0;
}

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

int main() {
    int N, t, x, y, a, b, c;
    scanf("%d", &N);
    a = b = c = 0;
    bool flg = true;
    for (int i = 0; i < N; i++) {
        scanf("%d %d %d", &t, &x, &y);
        int time = t - a;
        int dist = abs(b - x) + abs(c - y);
        if ((time - dist) < 0 || (time - dist) % 2 != 0) flg = false;
    }
    if (flg) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
N = int(input())
y= [-1 for i in range(N)]
t = []
for i in range(N):
  X, Y = map(int, input().split())
  X, Y = X -1, Y -1
  y[X] = Y
  t.append(X)
  
c = [1 for i in range(N)]
sumy = 0
comp = 0
for i in range(N-1):
  sumy += y[i]+1
  comp += N - i
  if sumy != comp:
    c[i + 1] = c[i] + 1
buf = c[-1]
for i in range(1,N+1):
  buf2 = buf
  if c[-i]==1 and i < N:
    buf2 = c[-i-1]  
  c[-i] = buf
  buf = buf2
for i in t:
  print(c[i])
  


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

int main() {
  int N;
  cin >> N;
    
  rep (i, N) {
    char S;
    cin >> S;
      if (S == 'Y') {
      cout << "Four" << endl;
      break;
      }
      if (i == N-1 && S != 'Y') {
      cout << "Three" << endl;
      }
  }
}


Measured memory_bytes: 256