akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

const lint MOD7 = (lint)1e9 + 7;

lint f(VEC(lint)& X)
{
    lint o = X[0];
    for (lint& x : X)
        x -= o;

    lint sum = 0, ret = 0;
    FOR(i, 0, SZ(X)) {
        ret += i * X[i] - sum;
        ret %= MOD7;
        sum += X[i];
    }

    return ret;
};

void solveSingleCase(int caseNo)
{
    int N, M;
    cin >> N >> M;
    VEC(lint) X(N), Y(M);
    READVEC(X);
    READVEC(Y);

    lint ret = f(X);
    ret *= f(Y);
    cout << ret % MOD7 << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

constexpr ll INF = 1LL << 62;
constexpr ll MAX = 1e5;

bool is_prime(ll n) {
    if (n <= 1) {
        return false;
    }
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}

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

    vector<ll> primes(MAX + 1, 0);
    for (ll i = 0; i <= MAX; i++) {
        primes[i] = (is_prime(i) && is_prime((i + 1) / 2)) ? 1 : 0;
    }

    for (ll i = 0; i < MAX; i++) {
        primes[i + 1] += primes[i];
    }

    ll Q;
    cin >> Q;
    for (ll q = 0; q < Q; q++) {
        ll l, r;
        cin >> l >> r;
        cout << primes[r] - primes[l - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

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

template<class T>
struct point{
	T x,y;
	point operator+(const point &a)const{ return (point){x+a.x,y+a.y}; }
	point operator-(const point &a)const{ return (point){x-a.x,y-a.y}; }
};

template<class T>
point<T> operator*(T c,const point<T> &a){ return (point<T>){c*a.x,c*a.y}; }

template<class T>
struct line{ point<T> a,b; };

template<class T>
struct circle{
	point<T> c;
	T r;
};

template<class T>
T dot(const point<T> &a,const point<T> &b){ return a.x*b.x+a.y*b.y; }

template<class T>
double abs(const point<T> &a){ return sqrt(a.x*a.x+a.y*a.y); }

template<class T>
T abs2(const point<T> &a){ return a.x*a.x+a.y*a.y; }

template<class T>
point<double> proj(const point<T> &p,const line<T> &L){
	return L.a+dot(p-L.a,L.b-L.a)/abs2(L.b-L.a)*(L.b-L.a);
}

point<double> rot(const point<double> &a,double theta){
	return (point<double>){a.x*cos(theta)-a.y*sin(theta),a.x*sin(theta)+a.y*cos(theta)};
}

int intersect(const circle<double> &C,const line<double> &L){
	point<double> m=proj(C.c,L);
	double d=abs(C.c-m);
	if(C.r+EPS<d) return 0;
	if(C.r-EPS<d) return 1;
	return 2;
}

int tangent(const circle<double> &C1,const circle<double> &C2,vector< line<double> > &res){
	double d=abs(C1.c-C2.c);
	if(d<EPS) return 0;

	int c=0;
	// 内接線
	if(C1.r+C2.r<d-EPS){
		double t=acos((C1.r+C2.r)/d);
		res.push_back((line<double>){C1.c+rot(C1.r/d*(C2.c-C1.c), t),C2.c+rot(C2.r/d*(C1.c-C2.c), t)});
		res.push_back((line<double>){C1.c+rot(C1.r/d*(C2.c-C1.c),-t),C2.c+rot(C2.r/d*(C1.c-C2.c),-t)});
		c+=2;
	}
	else if(C1.r+C2.r<d+EPS){
		point<double> p=C1.c+C1.r/d*(C2.c-C1.c);
		res.push_back((line<double>){p,p+rot(C2.c-C1.c,PI/2)});
		c++;
	}

	// 外接線
	if(abs(C1.r-C2.r)<d-EPS){
		double t1=acos((C1.r-C2.r)/d),t2=PI-t1;
		res.push_back((line<double>){C1.c+rot(C1.r/d*(C2.c-C1.c), t1),C2.c+rot(C2.r/d*(C1.c-C2.c),-t2)});
		res.push_back((line<double>){C1.c+rot(C1.r/d*(C2.c-C1.c),-t1),C2.c+rot(C2.r/d*(C1.c-C2.c), t2)});
		c+=2;
	}
	else if(abs(C1.r-C2.r)<d+EPS){
		point<double> p=C1.c+C1.r/d*(C2.c-C1.c);
		res.push_back((line<double>){p,p+rot(C2.c-C1.c,PI/2)});
		c++;
	}

	return c;
}

int main(){
	for(int n;scanf("%d",&n),n;){
		circle<double> J[50],M[50];
		rep(i,n){
			int x,y,m; scanf("%d%d%lf%d",&x,&y,&J[i].r,&m);
			M[i].c=J[i].c=(point<double>){x,y};
			M[i].r=J[i].r+m;
		}

		vector< line<double> > L;
		rep(j,n) rep(i,j) {
			tangent(J[i],J[j],L);
			tangent(J[i],M[j],L);
			tangent(M[i],J[j],L);
			tangent(M[i],M[j],L);
		}

		int ans=1;
		rep(i,L.size()){
			int cnt=0;
			rep(j,n) if(intersect(J[j],L[i])<=1 && intersect(M[j],L[i])>=1) cnt++;
			ans=max(ans,cnt);
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int ll
#define pii pair <int,int>
#define pipii pair <int,pair <int,int>>
#define mp make_pair
#define sz(var) (int)var.size()
const int maxinput=2000005;
const int mod=1e9+7;
signed main() 
{
    FAST
    int n;cin>>n;
    string s;cin>>s;

    int dp[n+5][n+5];
    memset(dp,0,sizeof(dp));

    for(int j=1;j<=n;j++)
        dp[1][j]=1;   //prefix sum
    dp[1][0]=0;
    
    dp[1][1]=1;

    /*
        dp[i][j] is the number of permutations of 1,2...,i such that last element is j
        Now how will we construct it from i-1, 
        Let's say current symbol is <
        consider i=4
        Suppose we want to put j=3 at 4th position, then at 3rd position we want number smaller than 3
        so we will consider all permutations of 3 elements whose last digit is 1 or 2. Now when we put 3 at 4th position we
        will assign new values to first i-1 elements accordingly
        Consider permutation 3,1,2 this tells relative order of first 3 elements-
        When we put 3 at 4th position relative order of first i-1 should remain same and there should 
        be no repetation. So 3,1,2,(3) is actually 4,1,2,3.
        Similarly say sign is < and we put 4 at last position and permutation of i-1 elements is 
        5,4,1,3,2,(4) is actually 6,5,1,3,2,4.
        Similarly reason for > sign.
        If still unclear view errichto solution on Youtube.
    */
    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            if(s[i-2]=='<')
            {
                /*
                    for(int k=1;k<=j-1;k++)
                        dp[i][j]+=dp[i-1][k];
                */
                dp[i][j]=dp[i-1][j-1]-dp[i-1][0];
                dp[i][j]%=mod;
            }
            else
            {
                /*
                    for(int k=j;k<=i-1;k++)
                        dp[i][j]+=dp[i-1][k];
                */
                dp[i][j]=dp[i-1][i-1]-dp[i-1][j-1];
                dp[i][j]%=mod;
                
            }
        }
        for(int j=1;j<=n;j++)
        {
            dp[i][j]+=dp[i][j-1]; //prefix sum
            dp[i][j]%=mod;
        }
    }

    /*for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
            cout<<dp[i][j]<<" ";
        cout<<endl;
    }*/

    int ans=0;
    ans=dp[n][n]; //prefix sum already there
    ans%=mod;
    ans=(ans+mod)%mod;
    cout<<ans<<endl;
}


Measured memory_bytes: 70784
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<cstdlib>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#include<string>
#include<deque>
#define lmid l,mid,rt<<1
#define rmid mid+1,r,rt<<1|1
using namespace std;
using namespace std;
int n, ans;
char s[100100];
int main() {
     scanf("%s", s);
     ans = n = strlen(s);
     for (int i = 1; i < n; i++)
          if (s[i] != s[i - 1])
               ans = min(ans, max(i, n - i));
     printf("%d\n", ans);
     return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int h,w;
    cin >> h >> w;
    VS a(h);
    REP(i,0,h) cin >> a[i];
    char emp = '.';
    VVI dp(h,VI(w));
    dp[0][0] = 1;
    REP(i,1,w) if (a[0][i] == emp) dp[0][i] = dp[0][i-1];
    REP(i,1,h) if (a[i][0] == emp) dp[i][0] = dp[i-1][0];
    REP(i,1,h) REP(j,1,w) {
        if (a[i][j] != emp) continue;
        dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
    }
    cout << dp[h-1][w-1] << endl;
}

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

Measured memory_bytes: 5248
const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    a,b,c=sort(intLine())
    println(a+b+10c)
end
main()

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


int main() {
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    long long ans = 1LL * a * c;
    ans = max(ans, 1LL * a * d);
    ans = max(ans, 1LL * b * c);
    ans = max(ans, 1LL * b * d);
    cout<<ans<<endl;

    return 0;
}


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

int main()
{
    int a,b,c,d;
    cin >> a>> b >> c>> d;
    
    while(a && c)
    {
        c=c-b;
        if(c<=0)
        {
            break;
        }
        a=a-d;
    }
    
    if(a>0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    
    
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

ll n;
ll a[111][111];

int main(){
	cin>>n;
  rep(i,2)rep(j,n)cin>>a[i][j];
  ll res=0;
  rep(s,n){
    ll sum=0;
    rep(j,s+1)sum+=a[0][j];
    repl(j,s,n)sum+=a[1][j];
    maxch(res,sum);
  }
  cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

		while (sc.hasNext()) {
			int a = sc.nextInt();
			int b = sc.nextInt();

			int sum = a + b;

			String checkSumLength = String.valueOf(sum);

			System.out.println(checkSumLength.length());
		}
	}

}

Measured memory_bytes: 26848
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int num[13] = { 0,1,3,1,2,1,2,1,1,2,1,2,1 };
	int x, y;
	cin >> x >> y;
	if (num[x] == num[y]) cout << "Yes";
	else cout << "No";
	return 0;

}

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

int n, m;
int a[105];
int main()
{
	cin >> n >> m;
	double sum = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		if (a[i] >= sum / m / 4)
			cnt++;
	}
	if (cnt >= m)
		cout << "Yes";
	else
		cout << "No";
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var l = Console.ReadLine().Split(' ')
        .Select(x => int.Parse(x)).ToArray();
        var L = l[0]; var r = l[1]; var d = l[2];
        var ans = 0;
        var nu = L;
        while (r >= nu) {
            if (nu % d == 0) ans++;
            nu++;
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 28236
// CHECKLIST
// 1) SAMPLES
// 2) MAXN, EPS, ... VALUE
// 3) CORNER CASES
// 4) MINTEST !!!!!
// 5) MAXTEST (IN CASE IF IT'S NOT OBVIOUS)
// 6) SUBMIT
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
 
  
  
using namespace std;
  
  
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
/** Interface */
  
inline int readChar();
template <class T = int> inline T readInt(); 
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x ); 
inline void writeWord( const char *s );
  
/** Read */
  
static const int buf_size = 4096;
  
inline int getChar() {
    static char buf[buf_size];
    static int len = 0, pos = 0;
    if (pos == len) {
        pos = 0, len = fread(buf, 1, buf_size, stdin);
    }
    if (pos == len) {
        return -1;
    }
    return buf[pos++];
}
  
inline int readChar() {
    int c = getChar();
    while (c <= 32) {
        c = getChar();
    }
    return c;
}
  
template <class T>
inline T readInt() {
    int s = 1, c = readChar();
    T x = 0;
    if (c == '-')
        s = -1, c = getChar();
    while ('0' <= c && c <= '9')
        x = x * 10 + c - '0', c = getChar();
    return s == 1 ? x : -x;
}
  
/** Write */
  
static int write_pos = 0;
static char write_buf[buf_size];
  
inline void writeChar( int x ) {
    if (write_pos == buf_size)
        fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
    write_buf[write_pos++] = x;
}
  
template <class T> 
inline void writeInt( T x, char end ) {
    if (x < 0)
        writeChar('-'), x = -x;
  
    char s[24];
    int n = 0;
    while (x || !n)
        s[n++] = '0' + x % 10, x /= 10;
    while (n--)
        writeChar(s[n]);
    if (end)
        writeChar(end);
}
  
inline void writeWord( const char *s ) {     while (*s)
writeChar(*s++); }
  
struct Flusher {
    ~Flusher() {
        if (write_pos)
            fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
    }
} flusher;


#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
const int MAXN = 100001;


int n, m;
int add[MAXN];


int main() {
    n = readInt(), m = readInt();
    int cnt = 0;
    for (int i = 0; i < m; i++) {
        int a = readInt(), b = readInt();
        a--, b--;
        if (a > b) {
            swap(a, b);
        }
        add[a]++;
        add[b]--;
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += add[i];
        if (sum & 1) {
           writeWord("NO\n"); 
           return 0;
        }
    }
    writeWord("YES\n"); 
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
int main() {
	char b[102],*s,*e;
	int n=0;
	while(fgets(b,102,stdin)){
		s=b;
		e=strchr(b,'\n')-1;
		while(s<e && *s==*e)
			s++, e--;
		n+=(s>=e);
	}
	printf("%d\n",n);
	return 0;
}

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


auto solve(std::string O, std::string E){
    stringstream ss;
    for(int i = 0; i < E.size(); ++i) {
        ss << O[i] << E[i];
    }
    if(E.size() < O.size()) {
        ss << O[O.size()-1];
    }
    return ss.str();
}

int main(){
    std::string O;
    std::cin >> O;
    std::string E;
    std::cin >> E;
    auto result = solve(O, E);
    cout << result << endl;
    return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n;
    cin>>n;
    vector<double> v(n);
    for (int i = 0; i < n; i++)
    {
        cin>>v[i];
    }
    sort(all(v));
    double ans = v[0];
    for (int i = 1; i < n; i++)
    {
        ans=(ans+v[i])/2.0;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n;
    cin>>n;
    ll a[n];
    rep(0,i,n)a[i]=0;
    rep(0,i,n-1){
        ll b;
        cin>>b;
        --b;
        ++a[b];
    }
    rep(0,i,n)cout<<a[i]<<endl;
}


Measured memory_bytes: 5196
#include <stdio.h>
 
int main()
{
  int i, sum;
  char x[1001];
 
  while (1) {
    scanf("%s", x);
    if (x[0] == '0' && x[1] == '\0') break;
    for (i = 0, sum = 0; x[i] != '\0'; i++) sum += x[i] - '0';
    printf("%d\n", sum);
  }
 
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>

using namespace std;

int main()
{
	int N, M, *A;

	cin >> N >> M;
	A = new int[N];
	for (int i = 0; i < N; i++)
		cin >> A[i];

	int total = 0;
	for (int i = 0; i < N; i++)
		total += A[i];

	int count = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] < ((double)total * (1.0 / (4.0 * (double)M))))
			continue;
		else
			count++;
	}

	if (count >= M)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	delete A;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);

    while(1){
        c=c-b;
        if(c<=0){
            printf("Yes\n");
            break;
        }
        a=a-d;
        if(a<=0){
            printf("No\n");
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1660
import sys

sys.setrecursionlimit(10**6)

stdin = sys.stdin
na = lambda: map(int, stdin.readline().split())

g = []
counter = []
ans = []

def dfs(cur, par, val):
  global counter, ans, g
  val += counter[cur]
  ans[cur] = val
  for e in g[cur]:
    if e == par:
      continue
    dfs(e, cur, val)

def main():
  global g, ans, counter
  N, Q = na()
  
  g = [[] for _ in range(N)]
  for _ in range(N - 1):
    a, b = na()
    g[a-1] += [b-1]
    g[b-1] += [a-1]

  counter = [0] * N
  for _ in range(Q):
    p, x = na()
    counter[p-1] += x

  ans = [0] * N
  dfs(0, -1, 0)
  print(*ans)

if __name__ == "__main__":
  main()


Measured memory_bytes: 236936
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
a = -1
b = -1
for i, tup in enumerate(itertools.permutations(range(1, N+1))):
    if P == tup:
        a = i
    if Q == tup:
        b = i
print(abs(a-b))


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

int main() {
  int N, M;
  cin >> N >> M;
  int a[56], b[51];
  int counter[51] = {0};
  for (int i = 1; i <= M; i++) {
    cin >> a[i] >> b[i];
    counter[a[i]]++;
    counter[b[i]]++;
  }
  for (int i = 1; i <= N; i++) cout << counter[i] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define hell 1000000007
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long int
#define pi 3.1415926536
using namespace std;
void solve()
{ll t,n,k,c=0;
 string s,x;
 cin>>s;
 t=(int(s[0]-'0')*10)+(int(s[1]-'0'));
 n=(int(s[2]-'0')*10)+(int(s[3]-'0'));
 if((t>=1&&t<=12)&&(n>=1&&n<=12)) cout<<"AMBIGUOUS";
 else if((t>=1&&t<=12)&&(!(n>=1&&n<=12))) cout<<"MMYY";
 else if((!(t>=1&&t<=12))&&(n>=1&&n<=12)) cout<<"YYMM";
 else cout<<"NA";
 return ;
}
int main()
{
fast
ll t=1;
while(t--)
{solve();
 //cout<<ma<<endl;
}
return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
//aoj 0558 广度优先搜索
#define M_VALUE 10000000
using namespace std;
//定义四个方向
int H, W, N;

int dir[4][2] = {
        {0,  1},
        {0,  -1},
        {1,  0},
        {-1, 0}
};

//用于存储迷宫
char map[1024][1024];

//用于存储距离
int d[1024][1024];

int factory[16][2];

typedef pair<int, int> P;

//采用广度优先遍历，寻找从(sx,sy)到(ex,ey)的最短路径
int bfs(int sx, int sy, int ex, int ey) {
    queue<P> que;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            d[i][j] = M_VALUE;
        }
    }
    que.push(P(sx, sy));
    d[sx][sy] = 0;
    while (que.size()) {
        P p = que.front();
        que.pop();

        if (p.first == ex && p.second == ey) {
            break;
        }

        for (int i = 0; i < 4; i++) {
            int nx = p.first + dir[i][0];
            int ny = p.second + dir[i][1];


            if (nx >= 0 && ny >= 0 && nx < H && ny < W && d[nx][ny] == M_VALUE && map[nx][ny] != 'X') {
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }

        }


    }
    return d[ex][ey];

}

int main() {
    cin >> H >> W >> N;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> map[i][j];
            if (map[i][j] == 'S') {
                factory[0][0] = i;
                factory[0][1] = j;
            }
            if (isdigit(map[i][j])) {
                int index = map[i][j] - '0';
                factory[index][0] = i;
                factory[index][1] = j;
            }
        }
    }
    int res = 0;

    for (int i = 0; i < N; i++) {
        res += bfs(factory[i][0], factory[i][1], factory[i + 1][0], factory[i + 1][1]);
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 8136
import numpy as np
import itertools

N,M,Q=map(int,input().split())
a=[];b=[];c=[];d=[]

for q in range(Q):
  array=list(map(int,input().split()))
  a.append(array[0])
  b.append(array[1])
  c.append(array[2])
  d.append(array[3])

all = list(itertools.combinations_with_replacement(range(1,M+1), N))

MAX=[]

for al in all:
  sum=0
  for q in range(Q):
    if al[b[q]-1]-al[a[q]-1]== c[q]:
      sum += d[q]
  MAX.append(sum)
  
print(max(MAX))

Measured memory_bytes: 43120
fun main(args: Array<String>) {
    abc076c()
}

private val unrestorable = "UNRESTORABLE"

fun abc076c() {
    val (sd, t) = (1..2).map { readLine()!! }

    if (sd.length < t.length) return println(unrestorable)
    if (sd.length == t.length) {
        return if (sd.withIndex().all { iv -> iv.value == '?' || iv.value == t[iv.index] }) {
            println(t)
        } else {
            println(unrestorable)
        }
    }

    val diff = sd.length - t.length

    val probablyStrings = mutableListOf<String>()
    for (i in diff downTo 0) {
        val sub = sd.substring(i until i + t.length)
        if (sub.withIndex().all { iv -> iv.value == '?' || iv.value == t[iv.index] }) {
            probablyStrings += sd.substring(0 until i).replace('?', 'a') +
                    t + sd.substring(i + t.length, sd.length).replace('?', 'a')
        }
    }

    val answer = if (probablyStrings.isEmpty()) unrestorable else probablyStrings.min()!!

    println(answer)
}


Measured memory_bytes: 31992
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    vi p;
    bool is_prime[100000];
    rep(i,100000)is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    Rep(i,2,100000){
        if(is_prime[i]){
            p.pb(i);
            for(int j=2*i;j<=100000;j+=i)is_prime[j]=false;
        }
    }
    int m,a,b;
    while(cin>>m>>a>>b,m){
        int ansa=0,ansb=0;
        rep(i,10000){
            if(!is_prime[i])continue;
            for(int j=i;j<10000&&i*j<=m;j++){
                if(!is_prime[j])continue;
                if(a*j>b*i)continue;
                if(ansa*ansb<i*j)ansa=i,ansb=j;
            }
        }
        cout<<ansa<<sp<<ansb<<endl;
    }
}


Measured memory_bytes: 3400
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	map<ll, ll> mp;
	int num;
	ll count = 0;
	ll N;
	cin>>N;
	for(int i=0; i<N;i++)
	{
		cin>>num;
		count += mp[i-num];
		mp[i+num]++;
	}
	cout<<count<<"\n";
	return 0;
}

Measured memory_bytes: 26224
#include<iostream>
#include<map>
using namespace std;
 
map <char,string> t;
void make_table(){
  t[' '] ="101";
  t['\'']="000000";
  t[','] ="000011";
  t['-'] ="10010001";
  t['.'] ="010001";
  t['?'] ="000001";
  t['A'] ="100101";
  t['B'] ="10011010";
   
  t['C'] ="0101";
  t['D'] ="0001";
  t['E'] ="110";
  t['F'] ="01001";
  t['G'] ="10011011";
  t['H'] ="010000";
  t['I'] ="0111";
  t['J'] ="10011000";
 
  t['K'] ="0110";
  t['L'] ="00100";
  t['M'] ="10011001";
  t['N'] ="10011110";
  t['O'] ="00101";
  t['P'] ="111";
  t['Q'] ="10011111";
  t['R'] ="1000";
 
  t['S'] ="00110";
  t['T'] ="00111";
  t['U'] ="10011100";
  t['V'] ="10011101";
  t['W'] ="000010";
  t['X'] ="10010010";
  t['Y'] ="10010011";
  t['Z'] ="10010000";
}
char ch_table[]={' ','.',',','-','\'','?'};
 
char s2ch(string str){
  int num=0;
  for(int i=0;i<5;i++){
    num*=2;
    num+=str[i]-'0';
  }
  if(num<=25)return 'A'+num;
  return ch_table[num-26];
}
 
int main(){
  string str,A;
  make_table();
  while(getline(cin,str)){
    A="";
    for(int i=0;i<(int)str.size();i++){
      A+=t[str[i]];
    }
     
    while(A.size()%5!=0)A+="0";
     
    for(int i=0;i<(int)A.size();i+=5){
      //cout<<A.substr(i,5)<<" ";
      cout<<s2ch(A.substr(i,5));
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1192
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 1 << 60


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X, M):
    ans = 0
    x = X
    x %= M
    s = [x]
    u = set()
    while True:
        x *= x
        x %= M
        s.append(x)
        if x in u:
            break
        u.add(x)

    i = s.index(s[-1])
    if i + 1 >= N:
        return sum(s[:N]) % M

    N -= i
    ans += sum(s[:i])

    s = s[i:]
    s.pop()
    ss = sum(s)
    ans += (N // len(s)) * ss
    ans += sum(s[:N%len(s)])
    return ans


def main():
    N, X, M = read_int_n()
    print(slv(N, X, M))

if __name__ == '__main__':
    main()


Measured memory_bytes: 88708
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i=0;i<n;i++) cin >> d[i];
    sort(d.begin(), d.end());
    
    int ans = d[d.size()/2] - d[d.size()/2-1];
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 640
#ifdef DEBUG_IS_VALID
#define DEB 1 
#define _LIBCPP_DEBUG 0
#else
#define DEB 0
#define NDEBUG
#endif

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define fi first
#define se second
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<Pl>;
using vvp = vector<vp>;

const int INF = 1<<29;
const long long LINF=1LL<<59;

const string YES = "Yes";
const string NO = "No";
void yn(bool ok){
  cout << (ok ? YES : NO) << endl;
}

void solve(long long N, std::vector<long long> a){
  map<ll,ll> mp;
  rep(i,N) mp[a[i]]++;
  bool ans = (mp.size()<=3);
  vl t, c;
  for(auto& p:mp) t.pb(p.fi), c.pb(p.se);
  if(t.size()==3){
    ans &= ((t[0]^t[1]^t[2])==0) & (c[0]==c[1] && c[1]==c[2]);
  }
  if(t.size()==1){
    ans &= (t[0]==0);
  }
  if(t.size()==2){
    if(t[0]>t[1]) swap(t[0],t[1]), swap(c[0],c[1]);
    ans &= (t[0]==0 && N%3==0 && c[0]==N/3);
  }
  yn(ans);
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> a(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&a[i]);
  }
  solve(N, std::move(a));
  return 0;
}


Measured memory_bytes: 7332
import java.util.*;
import java.math.BigDecimal;
import java.math.MathContext;

public class Main {
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int x[]=new int[n];
    int y[]=new int[n];
    for(int i=0;i<n;i++){
      x[i]=sc.nextInt();
      y[i]=sc.nextInt();
    }
    BigDecimal ans=BigDecimal.valueOf(0);
    for(int i=0;i<n;i++){
      for(int k=0;k<n;k++){
        long a=(x[i]-x[k])*(x[i]-x[k])+(y[i]-y[k])*(y[i]-y[k]);
        BigDecimal aa=BigDecimal.valueOf(a);
        aa=sqrt(aa,10);
        ans=ans.add(aa);
      }
    }
    BigDecimal nn=BigDecimal.valueOf(n);
    ans=ans.divide(nn,8,BigDecimal.ROUND_HALF_UP);
    System.out.println(ans);
  }

  public static BigDecimal sqrt(BigDecimal a, int scale){
    BigDecimal x = new BigDecimal(Math.sqrt(a.doubleValue()), MathContext.DECIMAL64);
    if(scale < 17) return x;
    BigDecimal b2 = new BigDecimal(2);
    for(int tempScale = 16; tempScale < scale; tempScale *= 2){
      x = x.subtract(x.multiply(x).subtract(a).divide(x.multiply(b2), scale, BigDecimal.ROUND_HALF_EVEN));
    }
    return x;
  }
}

Measured memory_bytes: 27300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	vector<ll> a;
	for (int i = 1; i <= 9; ++ i) a.push_back(i);
	vector<int> p {0, 9};
	for (int l = 2; l <= 10; ++ l) {
		for (int i = p[l-2]; i < p[l-1]; ++ i) {
			for (int k = a[i]%10-1; k <= a[i]%10+1; ++ k) if (0 <= k && k <= 9) {
				a.push_back(a[i]*10+k);
			}
		}
		p.push_back((int)a.size());
	}

	int K;
	cin >> K;
	cout << a[K-1] << endl;
}


Measured memory_bytes: 2420
#include<stdio.h>
#define max(a,b) ((a)>(b) ? (a):(b))
#define min(a,b) ((a)>(b) ? (b):(a))

int main(){
  int i;
  int ct=0;
  int co=0;
  int tmp;
  int n;
  int a,b,c,d;
  scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
  char s[220000];
  scanf("%s",s);

  for(i=a-1;i<max(c,d)-1;i++){
    if(s[i]=='#'&&s[i+1]=='#'){
      ct++;
    }
  }
  if(ct>0){
    printf("No");
    return 0;
  }else{

    if(c<d){
      printf("Yes");
      return 0;
    }else{
      for(i=b-2;i<d-1&&i+2<c;i++){
        if((s[i]!='#')&&(s[i+1]!='#')&&(s[i+2]!='#')){
          co++;
          tmp=i;
        }
      }
      if(co>0){
        if(co==1&&s[tmp-1]=='#'&&tmp==d-1){
          printf("No");
        }else{
          printf("Yes");
        }
        return 0;
      }else{
        printf("No");
        return 0;
      }


    }


}
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A,B,X;cin>>A>>B>>X;
  cout<<(A<=X&&X<=A+B? "YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

struct card {
	char suit;
	int value;
};

void swap(struct card *, struct card *);
void printc(int, struct card *);

int main(void)
{
	int i, j, minj, n, flag;
	struct card Cb[36], Cs[36];
	
	scanf("%d",&n);
	for (i=0; i<n; i++) {
		scanf(" %c%d", &Cb[i].suit, &Cb[i].value);
		Cs[i] = Cb[i];
	}
	
	for (i=0; i<n; i++) {
		for (j=n-1; j>i; j--) {
			if ( Cb[j].value < Cb[j-1].value ) swap( &Cb[j] , &Cb[j-1] );
		}
	}
	
	for (i=0; i<n; i++) {
		minj = i;
		for (j=i; j<n; j++) {
			if( Cs[j].value < Cs[minj].value ) minj = j;
		}
		if(i != minj) swap( &Cs[i], &Cs[minj]);
	}
	flag = 1;
	for (i=0; i<n; i++) {
		if( Cb[i].suit != Cs[i].suit ) {
			flag = 0;
			break;
		}
	}
	
	printc(n, Cb);
	printf("Stable\n");
	printc(n, Cs);
	if(flag) printf("Stable\n");
	else printf("Not stable\n");
	
	return 0;
}

void swap(struct card *card1, struct card *card2)
{
	struct card temp;
	temp = *card1;
	*card1 = *card2;
	*card2 = temp;
}

void printc(int n, struct card *C)
{
	int i;
	for (i=0; i<n-1; i++) {
		printf("%c%d ", C[i].suit, C[i].value);
	}
	printf("%c%d\n", C[n-1].suit, C[n-1].value);
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 200100;
const long long MOD = 998244353;
long long n, ans, p2[2 * N], c[2 * N];
string x;

char op(char c, long long nr) {
	if(nr % 2 == 0) return c;
	if(c == '1') return '0';
	return '1';
}

long long cnt(long long pos) {
	long long ret = 0;
	for(long long i = 0; i < n; i++)  {
		// dbg(i);
		if(i < pos) {
			if(x[i] == '1') 
				ret += p2[pos - i - 1];
			ret %= MOD;
		} else  {
			// dbg(x[i], op(x[i - pos], i/pos));
			if(op(x[i % pos], i / pos) < x[i]) {
				// ret++;
				break;
			} else if(op(x[i % pos], i / pos) > x[i]) {ret--; break;}
		}
	}
	ret++;
	assert(ret >= 0);
	return ret % MOD;
}

int main() {
	ios_base::sync_with_stdio(false);


	cin >> n >> x;

	p2[0] = 1;
	for(long long i = 1; i < N; i++)
		p2[i] = 2LL * p2[i - 1] % MOD;
	// reverse(x.begin(), x.end());

	long long p2 = 1;
	for(long long i = x.size() - 1; i >= 0; i--) {
		if(x[i] == '1')
			ans += p2;
		ans %= MOD;
		p2 = 2LL * p2 % MOD;
	}
	// dbg(p2);
	ans = 2LL * ans * n % MOD;
	ans += 2LL * n;
	ans %= MOD;

	// dbg(ans);
	for(long long i = 1; i < n; i++) {
		// dbg(i);
		if(n % i == 0 && (n / i) % 2 == 1) {
			// dbg(i);
			c[i] = cnt(i);
			for(int j = 1; j < i; j++) {
				if(i % j == 0)
					c[i] -= c[j];
				c[i] %= MOD;
			}
			// dbg(c[i]);
			// dbg(c[i]);


			ans -= 2 * n * c[i];
			ans %= MOD;
			ans += 2 * i * c[i];
			ans %= MOD;
		}
	}
	cout << (ans % MOD + MOD) % MOD<< '\n';
}


	

Measured memory_bytes: 4756
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int> (n-1, 0));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n-1; ++j) {
            scanf("%d", &v[i][j]);
            v[i][j]--;
        }
    }
    auto f = [&n](int i, int j){ return i*n+j; };
    int m = n*(n-1)/2;
    vector<vector<int>> G(n*n);
    vector<int> deg(n*n);
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n-2; ++j) {
            int l = min(i, v[i][j]), r = max(i, v[i][j]);
            int ll = min(i, v[i][j+1]), rr = max(i, v[i][j+1]);
            G[f(l, r)].emplace_back(f(ll, rr));
            deg[f(ll, rr)]++;
        }
    }
    vector<int> dp(n*n, 1);
    queue<int> Q;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            if(!deg[f(i, j)]){
                ans++;
                Q.emplace(f(i, j));
            }
        }
    }

    while(!Q.empty()){
        int i = Q.front(); Q.pop();

        for (auto &&j : G[i]) {
            dp[j] = max(dp[j], dp[i]+1);
            deg[j]--;
            if(deg[j] == 0) {
                Q.emplace(j);
                ans++;
            }
        }
    }
    if(ans != n*(n-1)/2){
        puts("-1");
    }else {
        cout << *max_element(dp.begin(),dp.end()) << "\n";
    }
    return 0;
}

Measured memory_bytes: 51072
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String name = sc.next();
		int ans = 0;
		for(int i=0;i<N;i++) {
			String oldName = sc.next();
			boolean ok2 = false;
			for(int j=0;j<=oldName.length()-name.length();j++) {
				for(int k=1;k*(name.length()-1)+1+j<=oldName.length();k++) {
					boolean ok = true;
					for(int l=0;l<name.length();l++) {
						//System.out.println(j+","+k+","+l);
						if(name.charAt(l)!=oldName.charAt(j+k*l)) {
							ok=false;
						}
					}
					if (ok) {
						ok2=true;
						break;
					}
				}
				if(ok2) {
					break;
				}
			}
			if(ok2) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

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

#define Bye return 0
#define ll long long

using namespace std;

void solve(){
    int k; cin>>k;
    int sum = 0;
    for (int i=1; i<=k; i++){
        for (int j=1; j<=k; j++){
            for (int x=1; x<=k; x++){
                int g = __gcd(i, j);
                sum += __gcd(g, x);
            }
        }
    }
    cout<<sum<<endl;
}

int main(){
    solve();
    Bye;
}

Measured memory_bytes: 3608
n = int(input())
a = list(map(int, input().split()))
four = 0
two = 0
for i in range(n):
    if a[i] % 4 == 0:
        four += 1
    elif a[i] % 2 == 0:
        two += 1

if 2 * four + 1 >= n:
    print("Yes")
elif 2 * four + two >= n:
    print("Yes")
else:
    print("No")


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

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

	int op = 0;
	for(int i=0; i<s1.length(); i++)
		if(s1[i] != s2[i])
			op++;

	cout<<op<<endl;
	return 0;
}

Measured memory_bytes: 3916
x= int(input())

if 400<=x<=599:
    print(int(8))
elif 600<=x<=799:
    print(int(7))
elif 800<=x<=999:
    print(int(6))
elif 1000<=x<=1199:
    print(int(5))
elif 1200<=x<=1399:
    print(int(4))
elif 1400<=x<=1599:
    print(int(3))
elif 1600<=x<=1799:
    print(int(2))
elif 1800<=x<=1999:
    print(int(1))
else:
    print(int(1))

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

public class Main {
	final int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if ((a | b) == 0)
				break;
			int min = INF;
			for (int i = 1; i * i <= a; i++) {
				if (a % i != 0)
					continue;
				for (int j = 1; j * j <= b; j++) {
					if (b % j != 0)
						continue;
					int[] ns = { i, a / i, j, b / j };
					Arrays.sort(ns);
					min = Math.min(min, (ns[1] - ns[0]) * (ns[1] - ns[0])
							+ (ns[2] - ns[1]) * (ns[2] - ns[1])
							+ (ns[3] - ns[2]) * (ns[3] - ns[2]));
				}
			}
			System.out.println(min);
		}
	}

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

Measured memory_bytes: 12000
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
char arr[1005][1005];
int H, W;
int mod=1e9+7;
void solve()
{
	int dp[1005][1005];
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(int i=1;i<H;i++)
	{
		if(arr[i][0]=='#') dp[i][0]=0;
		else
			dp[i][0]=dp[i-1][0];
	}
	for(int i=1;i<W;i++)
	{
		if(arr[0][i]=='#') dp[0][i]=0;
		else
			dp[0][i]=dp[0][i-1];
	}
	for(int i=1;i<H;i++)
	{
		for(int j=1;j<W;j++)
		{
			if(arr[i][j]=='#') dp[i][j]=0;
			else
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
		}
	}
	cout<<dp[H-1][W-1]%mod;
	return ;


}

int main()
{
	
	cin>>H>>W;
	//arr.clear();
	for(int i=0;i<H;i++)
	{
		for(int j=0;j<W;j++)
		{
			cin>>arr[i][j];
		}
	}

	solve();
	return 0;
}

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

int main() {
  int N, L;
  cin >> N >> L;
  vector<int> taste(N);
  rep(i, N) taste[i] = L + i;

  int ans;
  int sum = 0;
  rep(i, N) sum += taste[i];
  int min_diff = 100 + 200 + 1;
  rep(i, N) {
    if (abs(taste[i]) < min_diff) {
      ans = sum - taste[i];
      min_diff = abs(taste[i]);
    }
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;

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

    int N;
    cin >> N;

    vector<int> a(200000);
    vector<int> b(200000);

    for(int i = 0; i < N; i++) {
        int v;
        cin >> v;
        if(i % 2) {
            b[v]++;
        } else {
            a[v]++;
        }
    }

    int am = max_element(a.begin(), a.end()) - a.begin();
    int bm = max_element(b.begin(), b.end()) - b.begin();

    if(am == bm) {
        int as = a[am];
        int bs = b[bm];

        b[bm] = 0;
        bm = max_element(b.begin(), b.end()) - b.begin();

        int m = as + b[bm];

        a[am] = 0;
        am = max_element(a.begin(), a.end()) - a.begin();

        m = max(m, bs + a[am]);

        cout << N - m << endl;
        return 0;
    }

    cout << N - a[am] - b[bm] << endl;
}

Measured memory_bytes: 1792
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashSet;
// use std::collections::VecDeque;

fn main() {
    input! {
        N: usize,
        XYs: [(i64, i64); N],
    }

    // let set: HashSet<(i64, i64)> = XYs.into_iter().collect();

    // if set.len() == 1 {
    //     println!("0");
    //     return ;
    // }

    // 45度回転
    let mut rotXs: Vec<i64> = vec![0; N];
    let mut rotYs: Vec<i64> = vec![0; N];

    for (i, &(x, y)) in XYs.iter().enumerate() {
        let rotX = x + y;
        let rotY = x - y;

        rotXs[i] = rotX;
        rotYs[i] = rotY;
    }

    rotXs.sort();
    rotYs.sort();

    let max_x = (rotXs[N - 1] - rotXs[0]).abs();
    let max_y = (rotYs[N - 1] - rotYs[0]).abs();
    let ans = max(max_x, max_y);

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


Measured memory_bytes: 12960