akhauriyash/Code-Regression huggingface dataset:
N = int(input())
S = list(input())
ans = N

RE = S.count("E")
RW = N - RE
LE = 0
LW = 0

def f(x):
  global RE, RW
  if x == "E":
    RE -= 1
  else:
    RW -= 1

def g(x):
  global LE, LW
  if x == "E":
    LE += 1
  else:
    LW += 1

for i in S:
  f(i)
  ans = min(ans, LW+RE)
  g(i)

print(ans)

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

int main()
{
    int sum=0;
    int x,y;
    cin>>x>>y;
    if(x==3) sum+=100000;
    if(y==3) sum+=100000;
    if(x==2) sum+=200000;
    if(y==2) sum+=200000;
    if(x==1) sum+=300000;
    if(y==1) sum+=300000;
    if(x==1&&y==1) sum+=400000;
    cout<<sum;
	return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "3", "1 2 3" ].parse.expand.solve == 6 );
	assert( [ "10", "3 1 4 1 5 9 2 6 5 3" ].parse.expand.solve == 237 );
	assert( [ "10", "3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820" ].parse.expand.solve == 103715602 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	// ビットごとに立っている数を集計
	auto bs = new long[ 60 ];
	foreach( a; as )
	{
		foreach( i, ref b; bs )
		{
			if( a & ( 1L << i ) ) b++;
		}
	}
	
	// 合計を計算
	auto ans = 0L;
	auto c = as.length.signed;
	foreach( a; as[ 0 .. $ - 1 ] )
	{
		// 合計の範囲を縮める
		c--;
		foreach( i, ref b; bs )
		{
			if( a & ( 1L << i ) ) b--;
		}
		
		// まとめてXORした結果を合計に加算
		foreach( i, b; bs )
		{
			auto m = 1L << i;
			if( a & m ) ans = ans.addMod( m.mulMod( c - b ) );
			else        ans = ans.addMod( m.mulMod( b ) );
		}
	}
	return ans;
}

// 足し算
auto addMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return ( x + y ) % MOD;
}

// 引き算
auto subMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return ( x + MOD - y ) % MOD;
}

// 掛け算
auto mulMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return ( ( x % MOD ) * ( y % MOD ) ) % MOD;
}


Measured memory_bytes: 25780
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<stack>
#include<map>
#include<queue>
#include<unordered_map>
#include<cmath>
#include<utility>
 
#include<ctime>
#include<random>
#include<climits>
using namespace std;
typedef long long ll;
ll inf = LLONG_MAX;
int D;
int v=27;
vector<int> c(v,0);
vector<vector<int>> s;
vector<int> last(v,0);
vector<int> t(D+1);

void init(){
    cin >> D;
    s.resize(D+1);
    t.resize(D+1);
    for(int i=0;i<D+1;i++){
        s[i].resize(v);
    }

    for(int i=1;i<27;i++){
        cin >> c.at(i);
    }
    for(int i=1;i<D+1;i++){
        for(int j=1;j<27;j++){
            cin >> s.at(i).at(j);
        }
    }
    /*
    for(int i=1;i<D+1;i++){
        cin >> t.at(i);
    }
    */

}

void init_last(){
  for(int i=0;i<v;i++){
    last.at(i) = 0;
  }
}

ll calc(){
    init_last();
    ll ans = 0;
    for(int i=1;i<D+1;i++){
        ans += s.at(i).at(t.at(i));
        last.at(t.at(i)) = i;
        for(int j=1;j<v;j++){
            ans -= c.at(j) * (i - last.at(j));
        }
    }
    return ans;
}

int main(){
  	int time = std::clock();
    init();
    std::random_device rd;
 
    std::mt19937 mt(rd());

    //vector<int> t(D+1);
  
  	for(int i=1;i<D+1;i++){
      t.at(i) = mt() % 26 + 1;
    }
  
  	ll max_score = calc();
  
	while(static_cast<int>((double)(std::clock() - time) / CLOCKS_PER_SEC * 1000.0) < 1900){
      int d = mt() % D + 1;
      int q = mt() % 26 + 1;
      int old = t.at(d);
      t.at(d) = q;
      ll tmp = calc();
      if(max_score < tmp){
        max_score = tmp;
      }else{
        t.at(d) = old;
      }
    }

    for(int i=1;i<D+1;i++){
        cout << t.at(i) << endl;
    }
  	//cout << calc() << endl;
  
  	return(0);
}


Measured memory_bytes: 3724
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

int main() {
	int D, E;
	while (cin >> D >> E, D) {
		double ans = INF;
		FOR(x, 0, D) {
			int y = D - x;
			ans = min(ans, abs(E - sqrt(x*x + y*y)));
		}
		cout << ans << endl;
	}
}

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

/* using */
using namespace std;

/* main constructor */
struct Fast
{
    Fast()
    {
        std::cin.tie(0);
        ios::sync_with_stdio(0);
        //cout << fixed << setprecision(12);
    }
} fast;

/* template */
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;
}

/* define */
#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) REP(i, 1, n + 1)
#define rrep(i, n) RREP(i, n, 0)
#define each(i, n) for (auto &i : n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define eunique(x) \
    sort(all(x));  \
    (x).erase(unique(all(x)), (x).end())
#define int long long
#define mp make_pair

/* function */
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

/* const */
const int inf = 1e9 + 7;

/* main */
signed main(void)
{
    // int n, m;
    // cin >> n >> m;
    // vector<int> a(n);
    // map<int, int> map;
    // rep(i, n)
    // {
    //     int aa, b;
    //     cin >> aa >> b;
    //     a[i] = aa;
    //     map.insert(make_pair(aa, b));
    // }
    // sort(all(a));
    // int num = m;
    // int sum = 0;
    // rep(i, n)
    // {
    //     if ((num - map.at(a[i])) > 0)
    //     {
    //         num -= map.at(a[i]);
    //         sum += a[i] * map.at(a[i]);
    //     }
    //     else if ((num - map.at(a[i])) == 0)
    //     {
    //         sum += a[i] * map.at(a[i]);
    //         break;
    //     }
    //     else
    //     {
    //         sum += a[i] * num;
    //         break;
    //     }
    // }
    // cout << sum << endl;
    // return 0;
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> pairs(n);
    rep(i, n)
    {
        int a, b;
        cin >> pairs[i].first >> pairs[i].second;
    }
    sort(pairs.begin(), pairs.end());
    int num = m;
    int sum = 0;
    rep(i, n)
    {
        if (num - pairs[i].second > 0)
        {
            num -= pairs[i].second;
            sum += pairs[i].first * pairs[i].second;
        }
        else if (num - pairs[i].second == 0)
        {
            sum += pairs[i].first * pairs[i].second;
            break;
        }
        else
        {
            sum += pairs[i].first * num;
            break;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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



    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int N=2005;

int a[N];

void solve(){
	int n,z,w;
	cin>>n>>z>>w;
	rep(i,0,n){
		cin>>a[i];
	}
	
	// X picks last
	int ans = abs(w - a[n-1]);
	
	// X picks something else
	rep(i,0,n-1){
		int tmp = INF;
		// Y picks last
		tmp = abs(a[i] - a[n-1]);
		
		// Y picks something else
		rep(j,i+1,n-1){
			amin(tmp,abs(a[j] - a[n-1]));
		}
		
		amax(ans,tmp);
		
	}
	
	cout<<ans;
	
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SIEVE
		sieve();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 3668
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int mas[101];
	int n, m, x, rsum = 0 , lsum = 0;
	cin >> n >> m >> x;
	for (int i = 0; i < m; i++) {
		cin >> mas[i];
		if (x<mas[i])rsum++;
		if (x>mas[i])lsum++;
	}
	cout << min(rsum, lsum);
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int N,M;
    cin>>N>>M;
    vector<int> d(N+1);
    REP(i,M){
        int a,b;
        cin>>a>>b;
        d[a]++;
        d[b]++;
    }
    int f=0;
    for(auto &it:d)f|=(it&1);
    if(f)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const long double PI =(acos(-1));

int main(){
    int h,w;
    while(1){
        cin >> h >> w;
        if(h==0 && w==0) break;

        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                if(i==0 || i==(h-1)){
                    cout << "#";
                }else if(j==0 || j==(w-1)){
                    cout << '#';
                }else if(0<j && j<(w-1)){
                    cout << '.';
                }
            }
            cout << endl;
        }cout << endl;
    }
    return 0;
}


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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define REP(i,n) for(int i=0; i < (n); ++i)
#define SIZE(c) (int) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
#define FWD(i,a,b) for (int i=(a); i<(b); ++i)
#define BCK(i,a,b) for (int i=(a); i>(b); --i)
#define PI 3.14159265358979311600
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

typedef vector < int > VI;
typedef vector<ll> VL;

typedef long double K;

const int inf = 1000 * 1000 * 1000 + 7;
const int N = 2005;

int n;
string a, b;
int lf[N], rt[N];
vector<int> g[N];
multiset<int> s;
int result = inf;

void solve() {
	REP(shift, n + 1) {
		REP(i, n + 1) g[i].clear();
		s.clear();
		int l, r;
		int here = shift;
		REP(i, n) {
			int pos = (i + shift) % n;
			if (!i) l = r = pos;
			if (b[pos] == '1') l = pos;
			if (r == (pos - 1 + n) % n) r = (r+1) % n;
			while (b[r] != '1') r = (r+1) % n;
			while (b[l] != '1') l = (l-1+n) % n;
			if (a[i] != b[pos]) ++here;
			int sl = (pos - l) + (pos < l ? n : 0);
			int sr = (r - pos) + (r < pos ? n : 0);
			lf[i] = sl; rt[i] = sr;
			if (sl <= shift || !sr || a[i] == b[pos]) continue;
			g[sl - shift].push_back(sr);
			s.insert(sr);
		}
		int best = inf;
		REP(sh, n + 1) {
			for (auto& item : g[sh]) s.erase(s.find(item));
			int val = s.empty() ? 0 : (*s.rbegin());
			best = min(best, here + 2*(sh + val));
		}
		result = min(result, best);
	}
}

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

	cin >> a >> b;
	n = SIZE(a);
	int check = 0;
	REP(i, n) if (b[i] == '1') check |= 1;
	REP(i, n) if (a[i] == '1') check |= 2;
	if (check == 2) {
		cout << -1 << '\n';
		return 0;
	}
	if (!check) {
		cout << 0 << '\n';
		return 0;
	}

	REP(i, 2) {
		solve();
		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());
	}

	cout << result << '\n';

	return 0;
}

Measured memory_bytes: 512
def get_min_root_num(a):
    max_a = 0
    min_a = 1000
    for buf_a in a:
        if buf_a > max_a:
            max_a = buf_a

        if buf_a < min_a:
            min_a = buf_a

    return max_a-min_a

if __name__ == '__main__':
    N = input()
    a_list = [int(i) for i in input().split()]

    print(get_min_root_num(a_list))


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

int main() {
  int n;
  int i;
  int a;
  int b;
  int sum;
  
  cin >> n;
  i = -1;
  sum = 0;
  while (++i < n)
  {
    cin >> a >> b;
    sum += b - a + 1;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }
template<class T>
ostream &operator<<(ostream &os,const vector<T> &v){
	for(int i = 0;i < v.size();i++) os << (i ? "," : "[") << v[i];
	os << "]";
	return os;
}

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }

const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int k,a,b;
	cin >> k >> a >> b;
	if(b / k == (a - 1) / k) cout << "NG" << endl;
	else cout << "OK" << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>

using namespace std;

int main() {
  int n,x;
  cin >> n >> x;
  int a[2*n-1];

  if(n == 2){
    if(x == 2){
      cout << "Yes" << endl;
      cout << 1 << endl;
      cout << 2 << endl;
      cout << 3 << endl;
    }else{
      cout << "No" << endl;
    }
    return 0;
  }

  if(x > 2*n-2 || x < 2){
    cout << "No" << endl;

  }else{
    cout << "Yes" << endl;
    for(int i = 0; i < 2*n-1; i++){
      a[i] = 0;
    }
    int blk = 0;

    if(x > n){
      a[n-1] = 2*n-1;
      a[n] = x;
      blk = 1;

      for(int i = 0; i < 2*n-1; i++){
        if(a[i] == 0){
          a[i] = blk;
          blk++;
          if(blk == x)
            blk++;
        }
      }

    }else if(x < n){
      a[n-1] = 1;
      a[n] = x;
      if(x == 2){
        blk = 3;
      }else{
        blk = 2;
      }
      for(int i = 0; i < 2*n-1; i++){
        if(a[i] == 0){
          a[i] = blk;
          blk++;
          if(blk == x)
            blk++;
        }
      }

    }else if(x == n){
      for(int i = 0; i < 2*n-1; i++){
        a[i] = i+1;
      }
    }
    for(int i = 0; i < 2*n-1; i++){
      cout << a[i] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 2304
#coding:utf-8
import math

def isPrime(n):
    if n == 2:
        return True
    elif n % 2 == 0:
        return False
    else:
        for i in range(3,math.ceil(math.sqrt(n))+1,2):
            if n % i == 0:
                return False
        return True

n = int(input())
c = 0
for i in range(n):
    if isPrime(int(input())):
        c += 1

print(c)

Measured memory_bytes: 6816
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        ArrayList<String> ans = new ArrayList<>();
        while(sc.hasNext()){
            long a = sc.nextLong(),b = sc.nextLong();
            ans.add(String.format("%d %d",getGCD(a,b),getLCM(a,b)));
        }
        for(int i = 0,size = ans.size();i < size;i++){
            System.out.println(ans.get(i));
        }
    }
    static long getGCD(long a,long b){
        while(a != b){
            if(a > b) a -= b;
            else b -= a;
        }
        return a;
    }
    static long getLCM(long a,long b){
        return a * b / getGCD(a,b);
    }
}

Measured memory_bytes: 26276
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>

using namespace std;
typedef long long ll;

struct Tower{
	ll H;
	vector<int> bridges;
};

int main()
{
	Tower towers[100001];
	int N,M;
	cin >> N >> M;
	
	for(int i = 1; i <= N; i++){
		cin >> towers[i].H;
	}
	
	for(int i = 0; i < M; i++){
		int A,B;
		cin >> A >> B;
		towers[A].bridges.push_back(B);
		towers[B].bridges.push_back(A);
	}
	
	int count = 0;
	for(int i = 1; i <= N; i++){
		bool isGood = true;
		for(int j = 0; j < towers[i].bridges.size(); j++){
			if(towers[i].H <= towers[towers[i].bridges[j]].H){
				isGood = false;
				break;
			}
		}
		if(isGood){
			count++;
		}
	}
	
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 9544
import sys
import math
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
s = SI()
t = SI()
count = 0
for i in range(len(s)):
	if s[i] !=t[i]:
		count+=1
print(count)

Measured memory_bytes: 73684
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main(){
    int n; cin >> n;
    cout << n/3 << endl;
}

Measured memory_bytes: 256
a = int(input())
d = e = 0
for i in range(a):
    b, c = map(int, input().split())
    if d <= b and e <= c:
        d = b
        e = c
    else:
        f = max((b + d - 1) // b, (c + e - 1) // c)
        d = b * f
        e = c * f
print(d + e)


Measured memory_bytes: 3060
use proconio::{*, marker::Chars};

fn main() {
    input!{
        h: usize,
        w: usize,
        k: usize,
        c: [Chars; h],
    }

    let mut ans = 0;

    for h_bits in 0..(1<<h) {
        for w_bits in 0..(1<<w) {
            let mut cnt = 0;
            for i in 0..h {
                for j in 0..w {
                    let mut is_block = c[i][j] == '#';
                    if ((1<<i) & h_bits) > 0 || ((1<<j) & w_bits) > 0 {
                        is_block = false;
                    }
                    cnt += if is_block { 1 } else { 0 };
                }
            }
            if cnt == k {
                ans += 1;
            }
        }
    }

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


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int a,b;
  cin >> a >> b;
  switch(a*b){
    case 2:
      cout << "3" << endl;
      break;
    case 3:
      cout << "2" << endl;
      break;
    case 6:
      cout << "1" << endl;
      break;
  }
  return 0;
}




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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

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

const int INF = 1e18;

int N, A, B, C;
vec<int> l;

int rec(int idx, int a, int b, int c) {
  if (idx >= N) {
    if (a == 0 or b == 0 or c == 0) return INF;
    return abs(a - A) + abs(b - B) + abs(c - C);
  }

  int ret = INF;

  // A
  chmin(ret, rec(idx+1, a+l[idx], b, c) + (a > 0 ? 10 : 0));
  // B
  chmin(ret, rec(idx+1, a, b+l[idx], c) + (b > 0 ? 10 : 0));
  // C
  chmin(ret, rec(idx+1, a, b, c+l[idx]) + (c > 0 ? 10 : 0));
  // No
  chmin(ret, rec(idx+1, a, b, c));

  return ret;
}

signed main() {
  cin >> N >> A >> B >> C;
  l.resize(N);
  rep (i, N) {
    cin >> l[i];
  }

  cout << rec(0, 0, 0, 0) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int a,b,c;
	cin>>a>>b>>c;
	cout<<(a+b+c)-max(a,max(b,c))<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <bitset>
#include <math.h>

typedef long long ll;
typedef unsigned long long ull;

#define vi std::vector<int>
#define vl std::vector<ll>
#define floop(n) for(int i = 0; i < n; ++i)
#define print(x) std::cout << x << std::endl;

const ll INF = 1e18;

int main()
{
    int A, B;
    std::cin >> A >> B;

    print(A*B);   
    return 0;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

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

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

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

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

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

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

int main() {
  init();

  ll N;
  cin >> N;
  map<ll, ll, greater<>> A;
  REP(i, 0, N) {
    ll a;
    cin >> a;
    if (A.find(a) != A.end()) {
      A[a]++;
    } else {
      A.emplace(a, 1);
    }
  }

  ll n = 0;
  ll m = 0;
  for (const auto& a : A) {
    if (a.second < 2) {
      continue;
    }

    if (n == 0) {
      if (a.second >= 4) {
        n = a.first;
        m = a.first;
      } else {
        n = a.first;
      }
    } else if (m == 0) {
      m = a.first;
    } else {
      break;
    }
  }
  cout << n * m << endl;

  return 0;
}


Measured memory_bytes: 6528
N, M = map(int, input().split())

lr = []
for _ in range(M):
    lr.append(tuple(map(int, input().split())))

ll, rr = lr[0]
if len(lr) == 1:
    print(rr - ll + 1)
    exit(0)
for l, r in lr[1:]:
    if rr < l:
        print(0)
        exit(0)
    if ll <= l <= rr:
        ll = l

    if r < ll:
        print(0)
        exit(0)
    if ll <= r <= rr:
        rr = r

print(rr - ll + 1)


Measured memory_bytes: 17380
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute;
using FieldOffsetAttribute = System.Runtime.InteropServices.FieldOffsetAttribute;


static class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var accum = new int[n + 1];
        var accumTail = new int[n + 1];
        for (int i = 0; i < a.Length; i++)
        {
            accum[i + 1] = GCD(accum[i], a[i]);
        }
        int current = 0;
        int max = 0;
        for (int i = a.Length - 1; i >= 0; i--)
        {
            max = Max(max, GCD(accum[i], current));
            current = GCD(current, a[i]);
        }
        Console.WriteLine(max);
    }

    static int GCD(int a, int b)
    {
        while (true)
        {
            if (a > b)
            {
                if (b == 0) return a;
                a %= b;
            }
            else
            {
                if (a == 0) return b;
                b %= a;
            }
        }
    }
}


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

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

  deque<int> d;
  string cmd;
  while (cin >> cmd)
  {
    if (cmd == "deleteFirst")
    {
      d.pop_front();
    }
    else if (cmd == "deleteLast")
    {
      d.pop_back();
    }
    else
    {
      int x;
      cin >> x;

      if (cmd == "insert")
      {
        d.push_front(x);
      }
      else if (cmd == "delete")
      {
        auto res = find(d.begin(), d.end(), x);
        if (res != d.end())
        {
          d.erase(res);
        }
      }
    }
  }

  for (int i = 0; i < d.size(); i++)
    cout << (i ? " " : "") << d[i];
  cout << "\n";
}


Measured memory_bytes: 6984
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>

typedef struct node {
  unsigned int key;
  struct node *prev;
  struct node *next;
} Node;

typedef struct meta {
  Node *first;
  Node *last;
} Meta;

static void
insert(Meta *m, unsigned int k) {
  Node *n;

  n = (struct node *) malloc(sizeof(struct node));
  if (n == NULL) return;

  n->key = k;
  n->prev = NULL;
  if (m->first != NULL) {
    n->next = m->first;
    m->first->prev = n;
  } else {
    m->last = n;
  }
  m->first = n;
}

static void
delete(Meta *m, unsigned int k) {
  Node *n;

  if (m->first == NULL) return;

  for (n = m->first; n != NULL; n = n->next) {
    if (n->key == k) {
      if (n->prev) {
        n->prev->next = n->next;
      } else {
        m->first = n->next;
      }
      if (n->next) {
        n->next->prev = n->prev;
      } else {
        m->last = n->prev;
      }
      free(n);
      break;
    }
  }
}

static void
delete_first(Meta *m) {
  Node *n;

  if (m->first == NULL) return;

  n = m->first;
  m->first = n->next;
  if (m->first) {
    m->first->prev = NULL;
  } else {
    m->last = NULL;
  }
  free(n);
}

static void
delete_last(Meta *m) {
  Node *n;

  if (m->last == NULL) return;

  n = m->last;
  m->last = n->prev;
  if (m->last) {
    m->last->next = NULL;
  } else {
    m->first = NULL;
  }
  free(n);
}

static void
free_list(Meta *m) {
  Node *n;
  Node *tmp;

  n = m->first;
  while (n) {
    tmp = n->next;
    free(n);
    n = tmp;
  }
}

int
main(int argc, char **argv) {
  char cmd[16];
  unsigned int key;
  int ret, n;
  Node *nd;

  Meta m = {NULL, NULL};

  ret = fscanf(stdin, "%d", &n);
  if (errno != 0) perror("fscanf");
  if (ret < 1) exit(1);

  while(1) {
    ret = fscanf(stdin, "%s", cmd);
    if (errno != 0) perror("fscanf");
    if (ret == EOF) break;

    if (strcmp(cmd, "deleteFirst") == 0) {
      delete_first(&m);
      continue;
    }

    if (strcmp(cmd, "deleteLast") == 0) {
      delete_last(&m);
      continue;
    }

    ret = fscanf(stdin, "%u", &key);
    if (errno != 0) perror("fscanf");
    if (ret == EOF) break;

    if (strcmp(cmd, "delete") == 0) {
      delete(&m, key);
      continue;
    }

    insert(&m, key);
  }

  for (nd = m.first; nd; nd = nd->next) {
    if (nd != m.first) printf(" ");
    printf("%u", nd->key);
  }
  printf("\n");

  free_list(&m);
  exit(0);
}


Measured memory_bytes: 32952
#include <iostream>
using namespace std;
int ans[1000001];

int main(void){
  int n,m,k;
  cin>>n>>m>>k;
  
   for(int i=0;i<=n;i++){
       for(int j=0;j<=m;j++){
           ans[i*m+j*n-i*j*2]=1;
       }
   }
   if(ans[k])cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
    
}


Measured memory_bytes: 4096
#include<stdio.h>
int main(){
  int a,b,c,d;
  int num=0;
  scanf("%d %d %d %d",&a ,&b ,&c ,&d);
  while(a>0 && c>0){
    if(num%2==0){
      c-=b;
    }
    else{
      a-=d;
    }
    num++;
  }
  if(a<=0){
    printf("No");
  }
  else{
   	printf("Yes");
  }
  return 0;
}

Measured memory_bytes: 1732
n = int(input())
 
l = []
for i in range(n):
	l.append(sorted(str(input())))
 
d = sorted(l)
c = 0
ans = 0
for i in range(n-1):
	if d[i] == d[i+1]:
		c += 1
		ans += c
	else:
		c = 0
print(ans)

Measured memory_bytes: 25420
#include <iostream>

template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }
    bool operator<(const ModInt& b) const { return val < b.val; }
    bool operator<=(const ModInt& b) const { return val <= b.val; }
    bool operator>(const ModInt& b) const { return val > b.val; }
    bool operator>=(const ModInt& b) const { return val >= b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept {
        lint v;
        is >> v;
        x = v;
        return is;
    }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1000000007;
using mint = ModInt<MOD>;

void solve() {
    int n;
    std::cin >> n;

    mint sum = 0, sum2 = 0;
    while (n--) {
        mint x;
        std::cin >> x;
        sum += x;
        sum2 += x * x;
    }

    std::cout << (sum * sum - sum2) / 2 << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3664
// 以下のソースを勉強する.
// zscoder氏.
// https://atcoder.jp/contests/dp/submissions/3942519
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

const LL is_query = -(1LL << 62);
struct Line{
    LL m, b;
    mutable function<const Line*()> succ;
    bool operator<(const Line& rhs) const {
        if (rhs.b != is_query) return m < rhs.m;
        const Line* s = succ();
        if (!s) return 0;
        LL x = rhs.m;
        return 1.0L * b - s->b < 1.0L *(s->m - m) * x;
    }
};

// will maintain upper hull for maximum
struct ConvexHullDynamic : public multiset<Line>{
    bool bad(iterator y){
        auto z = next(y);
        if(y == begin()){
            if(z == end()) return 0;
            return y->m == z->m && y->b <= z->b;
        }
        auto x = prev(y);
        if(z == end()) return y->m == x->m && y->b <= x->b;
        return (x->b - y->b) * 1.0L * (z->m - y->m) >= (y->b - z->b) * 1.0L * (y->m - x->m);
    }
    void insert_line(LL m, LL b){
        auto y = insert({m, b});
        y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
        if(bad(y)) { erase(y); return; }
        while(next(y) != end() && bad(next(y))) erase(next(y));
        while(y != begin() && bad(prev(y)))     erase(prev(y));
    }
    LL eval(LL x){
        auto l = *lower_bound((Line) { x, is_query });
        return l.m * x + l.b;
    }
};

LL a[222222];
LL dp[222222];

int main(){
    
    // 1. 入力情報取得.
    int N;
    LL C;
    scanf("%d %lld", &N, &C);
    for(int i = 0; i < N; i++) scanf("%lld", &a[i]);
    
    // 2. dp更新.
    dp[0] = 0;
    ConvexHullDynamic ch;
    ch.insert_line(2LL * a[0], -a[0] * a[0]);
    for(int i = 1; i < N; i++){
        dp[i] = -ch.eval(a[i]) + a[i] * a[i] + C;
        ch.insert_line(2LL * a[i], -(dp[i] + a[i] * a[i]));
    }
    
    // 3. 出力.
    printf("%lld\n", dp[N - 1]);
    return 0;
    
}

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

using namespace std;

int main() {
    ios :: sync_with_stdio(0);
    cin.tie(nullptr);
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    int x = tx - sx, y = ty - sy;

    for(int i = 0; i < x; ++i) {
        cout << 'R';
    }
    for(int i = 0; i < y; ++i) {
        cout << 'U';
    }

    for(int i = 0; i < x; ++i) {
        cout << 'L';
    }
    for(int i = 0; i < y; ++i) {
        cout << 'D';
    }

    cout << 'D';
    for(int i = 0; i <= x; ++i) {
        cout << 'R';
    }
    for(int i = 0; i <= y; ++i) {
        cout << 'U';
    }
    cout << 'L';
    cout << 'U';
    for(int i = 0; i <= x; ++i) {
        cout << 'L';
    }
    for(int i = 0; i <= y; ++i) {
        cout << 'D';
    }
    cout << 'R';
    return 0;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;

/*
struct point
{
long long dist; long long name;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};
*/

ll const MAX = 1e5 + 4;
ll h[MAX];
ll dp[MAX];
int main() {
	ll n;
	cin >> n;
	REP(i, 1, n) {
		cin >> h[i];
	}
	h[0] = h[1];
	dp[1] = 0; dp[0] = 0;
	REP(i, 2, n) {
		dp[i] = min(dp[i-1]+ abs(h[i] - h[i - 1]), dp[i-2]+abs(h[i] - h[i - 2]));
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=55,M=50;
int n,a[N],b[N],f[N][N],c[N],tot,v[N];
LL g[N][N];
inline bool check()
{
	for(int i=1;i<=n;i++)if(a[i]!=b[i])return false;
	return true;
}
inline int work(int x)
{
	memset(v,0,sizeof(v));
	v[a[x]]=1;
	for(int i=a[x];i>=b[x];i--)if(v[i])
		for(int j=1;j<=tot;j++)v[i%c[j]]=1;
	int tmp=a[x];
	for(int i=0;i<=M;i++)if(v[i]&&f[i][b[x]]<f[tmp][b[x]])tmp=i;
	return tmp;
}
inline int get(int x)
{
	memset(v,0,sizeof(v));
	v[a[x]]=1;
	for(int i=a[x];i>=b[x];i--)if(v[i])
		for(int j=1;j<=tot;j++)v[i%c[j]]=1;
	int tmp=a[x];
	for(int i=0;i<=M;i++)if(v[i]&&f[i][b[x]]<f[tmp][b[x]])tmp=i;
	return f[tmp][b[x]];
}
int main()
{
	//freopen("a.in","r",stdin);
	//freopen("a2.out","w",stdout);
	memset(f,60,sizeof(f));
	memset(g,60,sizeof(g));
	for(int i=0;i<=M;i++)f[i][i]=0,g[i][i]=0;
	for(int i=0;i<=M;i++)
		for(int j=0;j<i;j++)
			for(int k=1;k<=i;k++)f[i][j]=min(f[i][j],max(f[i%k][j],k)),g[i][j]=min(g[i][j],g[i%k][j]+(1ll<<k));
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)scanf("%d",&b[i]);
	for(int i=1;i<=n;i++)if(a[i]!=b[i]&&b[i]*2>=a[i])return puts("-1"),0;
	long long ans=0;
	while(!check())
	{
		int mx=0;
		for(int i=1;i<=n;i++)mx=max(mx,get(i));//mx=max(mx,f[a[i]][b[i]]);
		ans+=1ll<<mx;c[++tot]=mx;
		for(int i=1;i<=n;i++)if(work(i)==b[i])a[i]=b[i];
		//for(int i=1;i<=n;i++)a[i]=work(i);
		//for(int i=1;i<=n;i++)printf("%d ",a[i]);puts("");
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------

int main(void){
    int k, x;
    cin >> k >> x;

    for(int i = x - k + 1; i < x + k; i++){
        cout << i << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <time.h>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}


int main(){
    map<char,int> mp;
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++){
        mp[s[i]]++;
    }
    bool flg = false;
    if (mp['N'] > 0 && mp['S'] > 0 && mp['E'] == 0 && mp['W'] == 0) flg = true;
    else if (mp['N'] == 0 && mp['S'] == 0 && mp['E'] > 0 && mp['W'] > 0) flg = true;
    else if (mp['N'] > 0 && mp['S'] > 0 && mp['E'] > 0 && mp['W'] > 0) flg = true;
    if (flg) cout << "Yes" << endl;
    else cout << "No" << endl;
}




Measured memory_bytes: 256
from collections import deque
n=int(input())
ans=0
start=["0"]
start=deque(start)
while start:
  s=start.popleft()
  if int(s)<=n and "3" in s and "5" in s and "7" in s:ans+=1
  elif int(s)>n:continue
  for i in ["3","5","7"]:
    start.append(s+i)
print(ans)


Measured memory_bytes: 7540
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <set>
#include <string>

using namespace std;

int main() {
  int n, k;

  cin >> n >> k;

  deque<int> cnts(n, 0);

  for (int i = 0; i < k; i++) {
    int num;

    cin >> num;

    for (int j = 0; j < num; j++) {
      int ind;

      cin >> ind;

      cnts[ind - 1]++;
    }
  }

  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (cnts[i] == 0) {
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 3204
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;
int main() {
  //
  ll n, k;
  cin >> n >> k;
  vl a(n);
  rep(i, n) cin >> a[i];
  if (n == 1) {
    if (a[0] >= k) {
      cout << 0 << endl;
    } else {
      cout << 1 << endl;
    }
    return 0;
  }

  vector<bitset<5001>> dp1(n), dp2(n);
  vvl dp3(n, vl(5001, 0));
  dp1[0][0] = 0;
  if (a[0] < k) {
    dp1[0][a[0]] = 1;
  }
  REP(i, 1, n) {
    if (a[i] < k) {
      dp1[i][a[i]] = 1;
    }
    rep(v, k) {
      dp1[i][v] = max(dp1[i][v], dp1[i - 1][v]);
      if (v - a[i] >= 0) {
        dp1[i][v] = max(dp1[i][v], dp1[i - 1][v - a[i]]);
      }
    }
  }
  dp2[n - 1][0] = 0;
  dp3[n - 1][0] = 0;
  if (a[n - 1] < k) {
    dp2[n - 1][a[n - 1]] = 1;
    REP(v, 1, k) { dp3[n - 1][v] = dp3[n - 1][v - 1] + dp2[n - 1][v]; }
  }
  for (int i = n - 2; i >= 0; i--) {
    if (a[i] < k) {
      dp2[i][a[i]] = 1;
    }
    rep(v, k) {
      dp2[i][v] = max(dp2[i][v], dp2[i + 1][v]);
      if (v - a[i] >= 0) {
        dp2[i][v] = max(dp2[i][v], dp2[i + 1][v - a[i]]);
      }
    }
    dp3[i][0] = dp2[i][0];
    REP(v, 1, k) { dp3[i][v] = dp3[i][v - 1] + dp2[i][v]; }
  }
  // rep(i, n) {
  //   rep(v, k) { cerr << dp1[i][v] << " "; }
  //   cerr << endl;
  // }
  // cerr << endl;
  // rep(i, n) {
  //   rep(v, k) { cerr << dp2[i][v] << " "; }
  //   cerr << endl;
  // }
  // cerr << endl;
  // rep(i, n) {
  //   rep(v, k) { cerr << dp3[i][v] << " "; }
  //   cerr << endl;
  // }

  ll ans = 0;
  ll tmp = dp3[1][k - 1];
  if (k - a[0] - 1 >= 0) {
    tmp -= dp3[1][k - a[0] - 1];
  }
  if (a[0] < k && tmp == 0) ans++;
  // cerr << ans << endl;
  if (a[n - 1] <= k - 1) {
    ll cnt = 0;
    // cerr << dp1[n - 2][k - a[n - 1]] << endl;
    REP(v, max(0LL, k - a[n - 1]), k) {
      if (dp1[n - 2][v]) {
        cnt++;
        break;
      }
    }
    if (a[n - 1] < k && cnt == 0) {
      ans++;
    }
  }
  // cerr << ans << endl;
  REP(i, 1, n - 1) {
    if (a[i] >= k) continue;
    ll cnt = 0;
    rep(v, k) {
      if (dp1[i - 1][v] || v == 0) {
        ll tmp = dp3[i + 1][k - 1 - v];
        if (k - v - a[i] - 1 >= 0) {
          tmp -= dp3[i + 1][k - a[i] - v - 1];
        } else if (v > 0 && k - a[i] >= v) {
          cnt++;
          continue;
        }
        if (tmp > 0) {
          cnt++;
        }
      }
    }
    if (cnt == 0) {
      // cerr << dp1[i - 1][799] << endl;
      // cerr << "+" << i << "," << a[i] << endl;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 204032