akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

std::ostream& operator<<(std::ostream& stream, const mint& m){
    stream << m.v;
    return stream;
}


const ll MAXSIZE = 2 * 100000;

void solve(long long N, std::vector<long long> C){
    array<array<mint, MAXSIZE>, 2> dp;
    array<mint, MAXSIZE> cs;

    REP(i, dp.size()){
        fill(dp.at(i).begin(), dp.at(i).end(), 0);
    }
    fill(cs.begin(), cs.end(), 0);
    REP(i, C.size()){ C.at(i)--; }

    REP(i, N){
        if(i == 0){
            dp.at(0).at(C.at(i)) = 1;
            dp.at(1).at(C.at(i)) = 0;

            cs.at(C.at(i)) += dp.at(0).at(C.at(i));
        }else{
            const mint new_zero = dp.at(0).at(C.at(i - 1)) +
                dp.at(1).at(C.at(i - 1));
            mint new_one;
            if(C.at(i) == C.at(i - 1)){
                new_one = 0;
            }else{
                new_one = cs.at(C.at(i));
                cs.at(C.at(i)) += new_zero;
            }
            dp.at(0).at(C.at(i)) = new_zero;
            dp.at(1).at(C.at(i)) = new_one;
        }
    }
    cout << dp.at(0).at(C.back()) + dp.at(1).at(C.back()) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> C(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(C));
    return 0;
}


Measured memory_bytes: 6528
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


immutable string YES = "Yes";
immutable string NO = "No";


auto solve(long N, long[] L) {
    auto ls = L.sort!"a > b";
    return ls.front < ls.drop(1).sum ? YES : NO;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long[] L = new long[](cast(size_t) (N));
    foreach (i; 0 .. cast(size_t) (N)) {
        L[i] = input.front.to!long;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, L);
    else
        solve(N, L).writeln;
}


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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
ll const MOD = 998244353;
//ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n, s;
    cin >> n >> s;

    vector<int> v(n);
    for(auto& i : v) cin >> i;

    vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(s+1, vector<ll>(3)));

    dp[0][0][0] = 1;

    REP(i, n){
        dp[i+1] = dp[i];
        REP(j, s+1){
            if(j + v[i] <= s){
                dp[i+1][j + v[i]][1] += dp[i][j][0]*(i + 1) + dp[i][j][1];
                dp[i+1][j + v[i]][1] %= MOD;
            }
        }
        REP(j, s+1){
            dp[i+1][j][2] += dp[i+1][j][1];
            dp[i+1][j][2] %= MOD;
        }
    }

    cout << dp[n][s][2] << endl;

    return 0;
}


Measured memory_bytes: 493056
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>

int64_t test(uint64_t n, uint64_t s);
int main(void) {
    char *p;
    char str[16];
    uint64_t n,s;

    p = fgets(str, 16, stdin);
    n = strtoul(p,0,0);
    p = fgets(str, 16, stdin);
    s = strtoul(p,0,0);

    printf("%ld\n", test(n,s));
//    printf("%ld\n", test(87654UL,30UL));
//    printf("%ld\n", test(87654UL,138UL));
//    printf("%ld\n", test(87654UL,45678UL));
//    printf("%ld\n", test(31415926535UL,1UL));
//    printf("%ld\n", test(1UL,31415926535UL));
//    printf("%ld\n", test(100000000000,1));
    
    return 0;
}

int64_t test(uint64_t n, uint64_t s) {
    uint64_t i;
    uint64_t tmp;
    uint64_t sum;
    uint64_t sqrtN;
    uint64_t p;
    uint64_t b;
    int64_t ret = -1;

    if(n == s) {
        return n+1;
    } else if(n < s){
        return -1;
    }

    sqrtN = (uint64_t)sqrt((double)n) + 1;

    for(i=2UL;i<=sqrtN;i++){
        tmp = n;
        sum = 0;
        while(tmp > 0) {
            sum += (tmp % i);
            tmp /= i;
//            if(i == 316228)
//            printf("sum:%lu tmp:%lu, i:%lu\n", sum, tmp, i);
        }
        if(sum == s){
//            printf("zentansaku:%lu tmp:%lu s:%lu\n", i, tmp, s);
            ret = i;
            break;
        }
    }
    if(ret == -1){
    for(p=sqrtN;p>=1;p--){
        if(((n-s) % p) == 0) {
            b = ((n-s)/p) + 1;
            if (((n % b) + (n/b)) == s){
//                printf("p:%lu b:%lu c2:%lu c1:%lu\n",p, b, (n/b), (n%b));
                ret = b;
                break;
            }
        }
   
    }
    }
    
    return ret;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;

template<typename T>
struct BIT{
  int n;
  vector<T> bit;
  //1-indexed
  BIT():n(-1){}
  BIT(int n_,T d):n(n_),bit(n_+1,d){}

  T sum(int i){
    T s=bit[0];
    for(int x=i;x>0;x-=(x&-x))
      s+=bit[x];
    return s;
  }
  void add(int i,T a){
    if(i==0) return;
    for(int x=i;x<=n;x+=(x&-x))
      bit[x]+=a;
  }

  int lower_bound(int w){
    if(w<=0) return 0;
    int x=0,r=1;
    while(r<n) r<<=1;
    for(int k=r;k>0;k>>=1){
      if(x+k<=n&&bit[x+k]<w){
        w-=bit[x+k];
        x+=k;
      }
    }
    return x+1;
  }

  T sum0(int i){
    return sum(i+1);
  }
  void add0(int i,T a){
    add(i+1,a);
  }

  T query(int l,int r){
    return sum(r-1)-sum(l-1);
  }

  T query0(int l,int r){
    return sum(r)-sum(l);
  }
};

signed main(){
  int N,K;
  cin>>N>>K;
  const int INF=1e9+7;
  std::vector<int> a(N);
  for(int i=0;i<N;i++)cin>>a[i];
  for(int i=0;i<N;i++)a[i]-=K;
  std::vector<int> v(N+1);
  v[0]=0;
  for(int i=1;i<=N;i++)v[i]=v[i-1]+a[i-1];
  map<int,int> m;
  for(int i=0;i<=N;i++)m[v[i]]=0;
  int k=1;
  for(auto &p:m)p.second=k++;
  int ans=0;
  BIT<int> bit(3e5,0);
  for(int i=0;i<=N;i++){
    ans+=bit.sum(m[v[i]]);
    //cout<<ans<<endl;
    bit.add(m[v[i]],1);
  }
  //for(int i=0;i<=N;i++)cout<<m[v[i]]<<" "<<bit.sum(m[v[i]])<<endl;
  cout<<ans<<endl;
}


Measured memory_bytes: 18176
#include<iostream>
#include<climits>
#include<numeric>
#include<algorithm>
#include <sstream>
#include<cstring>
#include<cmath>
#include<iterator>
#include<utility>
#include<array>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<list>
#include<forward_list>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define pa(a) cout<<a<<endl;
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;

int main()
{
#ifdef RAHUL
    freopen("input.txt","r",stdin);
#endif
ll t;
cin>>t;
ll a=t%100;
ll b=t/100;
//5
//19
if(1<=a and a<=12){
    if(1<=b and b<=12){
        cout<<"AMBIGUOUS"<<endl;
    }
    else{
        cout<<"YYMM"<<endl;
    }
}
else{
    if(1<=b and b<=12){
        cout<<"MMYY"<<endl;
    }
    else{
        cout<<"NA"<<endl;
    }
}
return 0;   

}




Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
        	int n = scan.nextInt();
        	int s = scan.nextInt();
        	if(n == 0 && s == 0){
        		break;
        	}
        	int[] r = new int[n];
        	for(int i = 0;i < n;i++){
        		r[i] = scan.nextInt();
        	}
        	int count = 0;
        	for(int i = 0;i < n-1;i++){
        		for(int j = i + 1;j < n;j++){
        			if(r[i]+r[j] > s){
        				count++;
        			}
        		}
        	}
        	System.out.println(count);
        }
	}
}

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

int n, m;
int a[100], b[100];

void solve() {
	int asum = 0, bsum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		asum += a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
		bsum += b[i];
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (asum - a[i] + b[j] == bsum - b[j] + a[i]) {
				cout << a[i] << " " << b[j] << endl;
				return;
			}
		}
	}
	cout << -1 << endl;
}

int main() {
	while (cin >> n >> m , n) {
		solve();
	}
}

Measured memory_bytes: 1160
Option Strict On
Module Module1

    Sub Main()
        Dim z() As String = Split(Console.ReadLine())
        Dim N As Integer = Convert.ToInt32(z(0))
        Dim Q As Integer = Convert.ToInt32(z(1))
        Dim S As String = Console.ReadLine()
        Dim l(Q - 1) As Integer
        Dim r(Q - 1) As Integer
        For i As Integer = 0 To Q - 1
            z = Split(Console.ReadLine())
            l(i) = Convert.ToInt32(z(0))
            r(i) = Convert.ToInt32(z(1))
        Next
        '        For Each t In l
        'Console.WriteLine(t)
        'Next
        'For Each t In r
        'Console.WriteLine(t)
        'Next
        Dim Ahurag As Integer = 0
        Dim counter As Integer = 0
        Dim at(N - 1) As Integer
        For i As Integer = 0 To N - 1
            If Mid(S, i + 1, 1) = "A" Then
                Ahurag = 1
            ElseIf Ahurag = 1 AndAlso Mid(S, i + 1, 1) = "C" Then
                Ahurag = 0
                counter += 1

            Else
                Ahurag = 0
            End If
            at(i) += counter
        Next
        Dim answer As Integer = 0
        For i As Integer = 0 To Q - 1
            answer = at(r(i) - 1) - at(l(i) - 1)
            Console.WriteLine(answer)
        Next
        Console.ReadLine()
    End Sub

End Module

Measured memory_bytes: 30520
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int l, r, d;
    cin >> l >> r >> d;
    int n1 = l/d, n2 = r/d;
    if (l%d == 0) cout << n2-n1+1;
    else cout << n2-n1;
    return 0;
}




Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#define N 200000
using namespace std;

int a[N+1];

int main(void)
{
  vector<int> b;
  int n;
  cin >> n;
  for ( int i=0; i<n; i++ ) {
    cin >> a[i];
  }
  for ( int i=0; i<n; i++ ) {
    if ( i % 2 == 0 ) {
      b.push_back(a[i]);
    } else {
      b.insert(b.begin(), a[i]);
    }
  }
  if ( n % 2 == 0 ) {
    for ( int i=0; i<n; i++ ) {
      cout << b[i] << " ";
    }
  } else {
    for ( int i=n-1; i>=0; i-- ) {
      cout << b[i] << " ";
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3828
#include<stdio.h>

int main(void){
	int R, G;
/*現在のレーティング*/
	do{
		scanf("%d", &R);
	}while(R < 0 || R > 4500);
/*目標レーティング*/
	do{
		scanf("%d", &G);
	}while(G < 0 || G > 4500);
/*必要パフォーマンス*/
	printf("%d\n", G * 2 - R);

	return 0;
}


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

using namespace std;

int main() {
	int N, K;

	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
	}

	int ans = ceil((double)(N - 1) / (K - 1));
	cout << ans << endl;

	return 0;
}

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

int n, m, a[233], tot = 0;

int main() {
    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
        cin >> a[i], tot += a[i];
    sort(a + 1, a + n + 1, greater<int>());
    bool fl = 1;
    double ma = (double)tot / (m << 2);
    for(int i = 1; i <= m; ++i) {
        if(a[i] < ma) {
            fl = 0;
            break;
        }
    }
    if(fl) cout << "Yes";
    else cout << "No";
    return 0;
}

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

using namespace std;

int main()
{
	int t;
	t=1;
	
	while(t--)
	{
	
	long long a,b,c,d,e,f;
	
	
	cin>>a>>b>>c>>d;
	
	
	e=max(a*c,a*d);
	f=max(b*c,b*d);
	
	cout<<max(e,f)<<endl;
	
	
	
	}



}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/


int main(void) {
  ll i, j, k;
  
  ll N;
  cin >> N;
  ll a[MAX];
  ll cnt[MAX]={};
  
  for(i=0; i<N; i++) cin >> a[i];
  sort(a, a+N);
  reverse(a, a+N);
  
  ll f=0;
  if(a[0]>a[1]) {pt("Impossible"); return 0;}
  if(a[N-1]!=(a[0]+1)/2) {pt("Impossible"); return 0;}
  
  
  for(i=0; i<N; i++) cnt[a[i]]++;
  
  for(i=a[N-1]+1; i<=a[0]; i++)
    if(cnt[i]<=1) {pt("Impossible"); return 0;}
  
  if(cnt[a[N-1]]>2) {pt("Impossible"); return 0;}
  
  if(a[0]&1 && cnt[a[N-1]]==1) {pt("Impossible"); return 0;}
  if(!(a[0]&1) && cnt[a[N-1]]==2) {pt("Impossible"); return 0;}
  
  pt("Possible");
}





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

void Main()
{
	while(1){
		int n, x;
		cin >> n >> x;
		if(n == 0){
			break;
		}
		int ans = 0;
		for(int i = 1; i <= n; i++){
			for(int j = 1; j <= n; j++){
				for(int k = 1; k <= n; k++){
					if(i == j || j == k || k == i){
						continue;
					}else{
						if(i + j + k == x){
							ans++;
						}
					}
				}
			}	
		}
		cout << ans/6 << endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 3132
n = gets.to_i
as = gets.split.map(&:to_i)
ans = 0
loop do
  dms = as.map{|a| a.divmod(2)}
  as = dms.map{|dm| dm[0]}
  ms = dms.map{|dm| dm[1]}
  if ms.count(0) != n
    break
  end
  ans += 1
end
puts ans

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll M=1e2+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,d;
	cin>>n>>d;
	vector< vector<ll > > vec(n+1,vector<ll> (d+1,0));
	
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=d;j++){
			cin>>vec[i][j];
		}
	}
	
	ll ans=0;
	for(ll i=1;i<=n;i++){
		for(ll j=i+1;j<=n;j++){
			ll sum=0;
			for(ll k=1;k<=d;k++){
				ll c=vec[i][k]-vec[j][k];
				sum+=(c*c);
			}
			ll o=sqrt(sum);
			if(o*o==sum){
				ans++;
//				cout<<i<<" "<<j<<endl;
//				cout<<sqrt(sum)<<" "<<sum<<endl;
			}
		}
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 256
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N, X;
int l[100];

void solve()
{
    int ans = 0;
    int p = 0;
    REP(i, N+1){
        if(p <= X) ans++;
        if(i < N) p += l[i];
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> X;
    REP(i, N) cin >> l[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <atcoder/all>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll INF = 1e18;
// VL ps, cnt;

ll calc(ll k1, ll k2){
    VL m({k1, k2});
    VL r({0, k2 - 1});
    PL p = atcoder::crt(r, m);
    if (p.first == 0) return INF;
    return p.first;
}

int main(void){
    ll n;
    cin >> n;
    if (n == 1){
        cout << 1 << endl;
        return 0;
    }
    n *= 2;
    ll ans = n;
    for (ll x = 2; x * x <= n; x++){
        if (n % x != 0) continue;
        ll y = n / x;
        ll k1 = calc(x, y);
        ll k2 = calc(y, x);
        chmin(ans, k1);
        chmin(ans, k2);
    }
    cout << ans << endl;

    return 0;
}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

// G13E_5.cpp

LL n, m, x[100002];
const LL MOD = 1000000007;

void mat_prod(LL a[3][3], LL b[3][3], LL c[3][3]) { // a = b * c;
	LL d[3][3];
	inc(i, 3) {
	inc(j, 3) {
		d[i][j] = 0;
	}
	}
	
	inc(i, 3) {
	inc(j, 3) {
	inc(k, 3) {
		(d[i][j] += b[i][k] * c[k][j]) %= MOD;
	}
	}
	}
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = d[i][j];
	}
	}
	
	return;
}

void mat_exp(LL a[3][3], LL b[3][3], LL c) { // a = b ^ c;
	LL t[60][3][3];
	if(true) {
		inc(i, 3) {
		inc(j, 3) {
			t[0][i][j] = b[i][j];
		}
		}
		inc(i, 60 - 1) {
			mat_prod(t[i + 1], t[i], t[i]);
		}
	}
	
	inc(i, 3) {
	inc(j, 3) {
		a[i][j] = 0;
	}
	}
	inc(i, 3) { a[i][i] = 1; }
	inc(i, 60) {
		if((c >> i) & 1) {
			mat_prod(a, a, t[i]);
		}
	}
	
	return;
}

int main() {
	cin >> n >> m;
	inc1(i, m) { cin >> x[i]; }
	x[0] = 0;
	x[m + 1] = n + 1;
	
	LL a[3][3] = { { 2, 1, 1 }, { 2, 1, 0 }, { 1, 1, 1 } };
	LL b[3][3] = { { 1, 0, 0 }, { 2, 1, 0 }, { 1, 1, 1 } };
	LL c[3][3] = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
	LL d[3][3];
	
	inc(i, m + 1) {
		if(i != 0) { mat_prod(c, b, c); }
		mat_exp(d, a, x[i + 1] - x[i] - 1);
		mat_prod(c, d, c);
	}
	
	cout << c[2][0] << endl;
	
	return 0;
}


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


int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	long n;cin>>n;
	string s;cin>>s;
	long f=0,r=-1,w=-1,c=0;
	for(long i=0;i<n;i++){
		if(s[i]=='R')r=i;
		if(s[i]=='W' && f==0){w=i;f++;}
		if(s[i]=='R')c++;
	}
	if(r==-1 || w==-1)cout<<"0\n";
	else{
		long x=0,y=0;
		for(long i=0;i<n;i++){
			if(s[i]=='R')x++;
			if(s[i]=='W')y++;
		}
		long z=0;
		int f1=0;
		for(long i=0;i<c;i++){
			if(s[i]=='W'){z++;f1=1;}
		}
		cout<<min(x,min(y,z))<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3716
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ans = 0

for i in range(n):
  ans += b[a[i]-1]
  if i != n-1 and a[i+1] == a[i] + 1:
    ans += c[a[i]-1]

print(ans)

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

int main (){
int n,ki=0,gu=0;
cin>>n;
for (int i=1;i<=n;i++){
        if (i%2==1)ki++;
        else gu++;
}
ki*=gu;
cout<<ki<<endl;

return 0;
}



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

int N;
int mem[110];
int dp[110][110];

int main()
{
    scanf("%d",&N);

    for(int i = 1; i <= N; i++)
    {
        int tmp = i;
        for(int j = 2; j <= N; j++)
        {
            if(tmp % j == 0)
            {
                while(tmp % j == 0)
                {
                    tmp /= j;
                    mem[j]++;
                }
            }
        }
    }

    dp[0][1] = 1;
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j <= 75; j++)
        {
            for(int k = 0; k <= mem[i]; k++)
            {
                if(j * (k + 1) <= 75)dp[i + 1][j * (k + 1)] += dp[i][j];
            }
        }
    }

    printf("%d\n",dp[N][75]);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
using namespace std;

//ABC140 B
int main() {
	int N;
	int A[100];
	int B[100];
	int C[100];
	int ans = 0;

	cin >> N;
	for (int i=0; i<N; i++) {
		cin >> A[i];
	}
	for (int i=0; i<N; i++) {
		cin >> B[i];
		ans += B[i];
	}
	for (int i=0; i<N-1; i++) {
		cin >> C[i];
	}

	for (int i=0; i<N-1; i++) {
		if (A[i] + 1 == A[i+1]) {
			ans += C[A[i]-1];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
from bisect import bisect_left


def p_d():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()
    ans = N * (N - 1) * (N - 2) // 6

    for i in range(N - 2):
        for j in range(i + 1, N - 1):
            b = bisect_left(L, L[i] + L[j])
            if b != N:
                ans -= N - b

    print(ans)
    
p_d()

Measured memory_bytes: 42588
N = int(input())
STR = input().split()
#print(N, STR)
G = STR.count("G") >= 1
W = STR.count("W") >= 1
Y = STR.count("Y") >= 1
P = STR.count("P") >= 1
counter = G+W+Y+P
#print(G+W+Y+P)
if counter == 4:
    print("Four")
else:
    print("Three")

Measured memory_bytes: 3060
import sys
INPUT = sys.stdin.readline
#入力関数
def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()

N,D = MULT_INT_MAP()
x = D*2+1
y = N/x


def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

if is_integer_num(y):
    print(int(y))
else:
    y = int(y)
    print(y+1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/


int main(void) {
  ll i, j, k;
  string s;
  cin >> s;
  
  string t="";
  for(i=0; i<s.size(); i++)
    if(s[i]!='A') t+=s[i];
  
  ll f=1;
  if(t!="KIHBR") f=0;
  
  for(i=0; i<s.size(); i++) {
    string s2=s.substr(i, 2);
    
    if(s2=="KA") f=0;
    if(s2=="IA") f=0;
    if(s2=="AA") f=0;
  }
  
  if(f) pt("YES");
  else pt("NO");
  
}



Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//スペルミスに注意
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//関係性は隣接行列で記録
//過半数：N/2.0で判定
//ある量からある量を引く系の問題：端から定義してやる
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll S, W; cin >> S >> W;

	if (W >= S) cout << "unsafe" << endl;
	else cout << "safe" << endl;
}
	

Measured memory_bytes: 11056
#include<iostream>
using namespace std;
int main(){
    int n,a,b,ma=1,sum=0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a >> b;
        if(b > sum || b == sum && a < ma){
            ma = a;
            sum = b;
        }
    }
    cout << ma << " " << sum << endl;
    return(0);
}


Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
//#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
//#include <stack>
//#include <limits>
#include <sstream>
//#include <functional>
using namespace std;

#define len(array)  (sizeof (array) / sizeof *(array))
#define rep(i, s, e) for(int i = s;i < e;i++)
#define rrep(i, e, s) for(int i = e;s <= i;i--)
#define vrange(v) v.begin(), v.end()
#define vrrange(v) v.rbegin(), v.rend()
#define vsort(v) sort(vrange(v))
#define vrsort(v) sort(vrrange(v))
#define arange(a) a, a + len(a)
#define asort(a) sort(arange(a))
#define arsort(a, t) sort(arange(a), greater<t>())
#define afill(a, v) fill(arange(a), v)
#define afill2(a, v, t) fill((t *)a, (t *)(a + len(a)), v)
#define fmax(a, b) (a < b? b : a)
#define fmin(a, b) (a > b? b : a)
#define fabs(a) (a < 0? -a : a)
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-10;
const int dx[] = {1, -1, 0, 0, 1, -1, -1, 1};
const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};
//const int weight[] = {0,1,10,100,1000,10000,100000,1000000,10000000};
//priority_queue< int, vector<int>, greater<int> > q;

void doIt(){
	int w, h, sx, sy;
	string f[21];
	bool visited[21][21];
	queue<P> q;
	while(true){
		cin >> w >> h;
		if(w + h == 0) break;
		rep(i, 0, h){
			cin >> f[i];
		}
		afill2(visited, false, bool);
		rep(i, 0, h){
			rep(j, 0, w){
				if(f[i][j] == '@'){
					sx = j;
					sy = i;
					break;
				}
			}
		}
		q.push(P(sy, sx));
		while(!q.empty()){
			P e = q.front();
			int yy = e.first, xx = e.second;
			// cout << xx << ", " << yy << endl;
			q.pop();
			if(0 <= yy && yy < h && 0 <= xx && xx < w && visited[yy][xx] == false){
				visited[yy][xx] = true;
				// cout << xx << ", " << yy << endl;
				if(f[yy][xx] == '@' || f[yy][xx] == '.' ){
					rep(i, 0, 4){
						q.push(P(yy + dy[i], xx + dx[i]));
					}
				}
			}
		}
		int ans = 0;
		rep(i, 0, h){
			rep(j, 0, w){
				if(visited[i][j] && f[i][j] == '.'){
					ans++;
				}
			}
		}
		cout << ans + 1 << endl;

	}	

}

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

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

using namespace std;

int a, b, c, a1, b1, c1, ans;

int main () {

cin >> a >> b >> c;

if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {cout << 0; return 0;}
else if (a == b && b == c) {cout << -1; return 0;}

while(a % 2 != 1 && b % 2 != 1 && c % 2 != 1) {
    a1 = a / 2;
    b1 = b / 2;
    c1 = c / 2;
    a = b1 + c1;
    b = a1 + c1;
    c = a1 + b1;

    ans++;
}

cout << ans;

return 0;

}


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

int main(){
	ll n,maks,ans=0;
	cin >> n >> maks;
	for(ll i=0;i<n;i++){
		ll a,b;
		cin >> a >> b;
		double x=(double)sqrt(a*a+b*b);
		if(x<=maks) ans++;
	}
	cout << ans << '\n';
}

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

#define endl '\n'

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

    long long n,m; cin >> n >> m;
    long long ac, a[n], num=0, x; cin >> a[0];
    a[0]/=2;
    x = a[0];
    while(x % 2 == 0){
        x /= 2;
        num++;
    }
    bool ok = true;
    for (int i=1; i<n; i++){
        cin >> a[i];
        a[i] /= 2ll;
        x = a[i];
        int temp=0;
        while(x % 2 == 0){
            temp++;
            x/=2;
        }
        if (temp != num) ok =false;
    }
    if (!ok){
        cout << "0\n";
        return 0;
    }
    ac = a[0];
    for (int i=1; i<n; i++){
        ac = ac*a[i]/__gcd(ac, a[i]);
        if (ac > 2*m){
            ok = false;
            break;
        }
    }
    if (!ok) cout << "0\n";
    else cout << m/ac - m/(ac*2) << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int existe[100001];
int main()
{

int n;
cin>>n;
int ans;
cin>>ans;
int arr[n];
arr[0]=ans;
for(int index=1;index<n;index++)
{
    cin>>arr[index];
    ans^=arr[index];
}
for(int index = 0;index<n;index++)
{
    cout<<(ans^arr[index])<<" ";
}
cout<<endl;
    return 0;
}


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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> x(n);
    for(int i=0;i<n;i++) cin>>x[i];
    int res=1e9;
    for(int i=0;i+k-1<n;i++){
        if(x[i]<0 && 0<x[i+k-1]) res=min(res,min(-x[i],x[i+k-1])*2+max(-x[i],x[i+k-1]));
        else res=min(res,max(abs(x[i]),abs(x[i+k-1])));
    }
    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 640
#
from collections import deque


def main():
    k = int(input())
    lun = deque(["1", "2", "3", "4", "5", "6", "7", "8", "9"])
    keta = 0
    while len(lun) <= k:
        keta += 1
        for i in range(1, 10):
            generate_lunlun(lun, "", i, keta)
    print(lun[k - 1])


def generate_lunlun(array, s, c, keta):
    if keta == 0:
        array.append(s + str(c))
        return
    if c > 0:
        generate_lunlun(array, s + str(c), c - 1, keta - 1)
    generate_lunlun(array, s + str(c), c, keta - 1)
    if c < 9:
        generate_lunlun(array, s + str(c), c + 1, keta - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 17524
#define rep(i, n) for(ll i = 0; i < n; i++)
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int nmax = 8;
bool graph[nmax][nmax];

int dfs(int x, int n, bool visited[nmax]) {
	bool all_visited = true;
	rep(i,n) if (!visited[i]) all_visited = false;

	if (all_visited) return 1;
	
	int ret = 0;
	rep(i,n) {
		if (!graph[x][i]) continue;
		if (visited[i]) continue;

		visited[i] = true;
		ret += dfs(i,n,visited);
		visited[i] = false;
	}
	return ret;
}

int main() {
	int n,m;
	cin >> n >> m;
	rep(i,n) rep(j,n) graph[i][j] = false;
	rep(i,m) {
		int a,b;
		cin >> a >> b;
		a--;b--;
		graph[a][b] = graph[b][a] = true;
	}

	bool visited[nmax];
	rep(i,n) visited[i] = false;

	visited[0] = true;
	cout << dfs(0,n,visited) << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = defaultdict(int)
    for a in A: d[a] += 1
    kind = [0] * 2
    for key in d: kind[d[key] % 2] += 1
    if kind[0] % 2 == 0:
        print(sum(kind))
    else:
        print(sum(kind) - 1)





if __name__ == "__main__":
    main()


Measured memory_bytes: 98908
N=int(input())
A=sorted(list(map(int, input().split())))
m=A[0]
M=A[-1]
S=[]
for a in A[1:-1]:
    if a>0:
        S.append(str(m)+' '+str(a))
        m-=a
    else:
        S.append(str(M)+' '+str(a))
        M-=a
S.append(str(M)+' '+str(m))
print(M-m)
[print(s) for s in S]

Measured memory_bytes: 18084
n = int(input())
ans = 100000
for i in range(1,n):
    count = 0
    a = str(i)
    b = str(n-i)
    for j in a:
        count += int(j)
    for k in b:
        count += int(k)
    ans = min(ans,count)
print(ans)

Measured memory_bytes: 3316
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int e = 0, w = 0, s = 0, n = 0;
	string str;
	cin >> str;
	int len = str.length();
	for (int i = 0; i < len; i++)
		if (str[i] == 'S') s = 1;
		else if (str[i] == 'E') e = 1;
		else if (str[i] == 'W') w = 1;
		else n = 1;
	if ((s != n) || (e != w)) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG
// header {{{
#include <bits/stdc++.h>
using namespace std;
#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y
#define ASSERT(expr...) assert((expr))
using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using f80 = __float80;
// }}}
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

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

signed main() {
    string s;
    cin>>s;

    vector<string> l={"Sunny","Cloudy","Rainy"};

    REP(i,3){
        if(l.at(i) == s){
            cout<<l.at((i+1)%3)<<endl;
            return 0;
        }
    }

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

Measured memory_bytes: 256
n, m, x = map(int, input().split())
A = list(map(int, input().split()))
res1, res2 = 0, 0
for i in range(len(A)):
    if A[i] > x:
        res1 += 1
    else:
        res2 += 1

if res1 < res2:
    print(res1)
else:
    print(res2)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n, x; cin >> n >> x;
    vector<int> l(n + 1);
    l[0] = 0;
    rep(i, n) cin >> l[i + 1];

    int tmp = 0, cnt = 0;
    rep(i, n + 1)
    {
        tmp += l[i];
        if (tmp <= x) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;


int main(){
   long long N;
   cin>>N;
   long long h,n,w;
   for(long long h=1;h<=3500;h++){
      for(long long n=1;n<=3500;n++){
         if(4*h*n-N*n-N*h==0)continue;
         if(N*h*n%(4*h*n-N*n-N*h)==0){
            w=N*h*n/(4*h*n-N*n-N*h);
            if(w<=0)continue;
            cout<<h<<" "<<n<<" "<<w<<endl;
            return 0;
         }
      }
   }
}

   


Measured memory_bytes: 760
from math import sqrt

while True:
    a, b, c = map(int, raw_input().split())
    if a == 0 and b == 0 and c == 0:
        break

    d1, d2, d3 = sqrt(a**2 + b**2), sqrt(b**2 + c**2), sqrt(c**2 + a**2)

    for i in range(int(raw_input())):
        r = int(raw_input())
        if d1 < r * 2 or d2 < r * 2 or d3 < r * 2:
            print "OK"
        else:
            print "NA"

Measured memory_bytes: 4372
import math
MOD = 10**9+7
n, m = map(int, input().split())

if n == m:
    print( (2 * (math.factorial(n)%MOD)**2) % MOD)
elif abs(n-m) == 1:
    print((max(n, m)*(math.factorial(min(n, m))%MOD)**2) % MOD)
else:
    print(0)


Measured memory_bytes: 4028
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= int(b); i++)
#define per(i, a, b) for (int i = (a); i >= int(b); i--)
#define fir first
#define sec second
#define tct template<class type>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int maxn = 2e5, mod = 1e9 + 7;
int M, n, m, a[maxn + 5];

inline void red(int &x) { x += x >> 31 & mod; }
tct inline void cmax(type &x, type y) { x < y ? x = y : 0; }
tct inline void cmin(type &x, type y) { x > y ? x = y : 0; }

bool check(int x) {
	rep(i, 1, n - x) if (a[m - i + 1] + a[2 * x + i] < M) return false;
	return true;
}

int main() {
	scanf("%d %d", &n, &M), m = n * 2;
	rep(i, 1, m) scanf("%d", &a[i]);
	sort(a + 1, a + m + 1);
	int l = 0, r = n;
	while (l < r) {
		int mid = (l + r) >> 1;
		if (check(mid)) r = mid;
		else l = mid + 1;
	}
	int res = 0;
	rep(i, 1, l) res = max(res, a[i] + a[2 * l - i + 1]);
	rep(i, 1, n - l) res = max(res, a[m - i + 1] + a[2 * l + i] - M);
	printf("%d\n", res); 
	return 0;
}

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

int main()
{   
	string s[] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

	int n = sizeof(s)/sizeof(s[0]);

	string a;
	cin>>a;

	for(int i=0;i<n;i++)
	{
		if(a==s[i])
		{	
			cout<<7-i;
			return 0;
		}
	}
return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::f64::consts::PI;

fn main() {
	let mut line = String::new();
	stdin()
		.read_line(&mut line)
		.ok()
		.expect("error");
	let line: Vec<f64> = line
		.split_whitespace()
		.map(|s| s.parse().expect("error"))
		.collect();
	//println!("{:?}",line );
	let a = line[0];
	let b = line[1];
	let h = line[2];
	let m = line[3];
	//println!("{:?}{:?}",A,B );
	let deg = calc_degree(h.into() ,m.into() );
	//println!("{:?}",deg );
	let ans = (a.powi(2) + b.powi(2) - 2.0*a*b*deg.cos()).sqrt();
	println!("{:?}",ans );

}

fn calc_degree(h: f64,m: f64) -> f64 {
	let ans = (2.0 * PI * m / 60.0) - ((2.0 * PI * h / 12.0) + (2.0 * PI / 12.0)* m / 60.0 );
	ans
}

Measured memory_bytes: 2992
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
struct edge
{
    int to; string word;
    edge(int to, string word) { this->to = to, this->word = word; }
};
vector<edge> G[1010];
void dfs(int depth, int num)
{
    if(G[depth].size() == 0) return;
    for(int u = 0; u < G[depth].size(); u++)
    {
        for(int i = 0; i < num; i++) cout << ".";
        cout << G[depth][u].word << endl;
        if(G[depth][u].to != depth) dfs(G[depth][u].to, num + 1);
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    for(int i = 0; i < n; i++)
    {
        int k; cin >> k;
        string word; cin >> word;
        G[k].push_back(edge(i + 1, word));
    }
    dfs(0, 0);
    return 0;
}




Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6;
long double a[N];


int32_t main()
{
   int n; cin>>n;
   int count = 0;
    for(int i=0;i<=n;i++)
    {
        if((int)floor(log10(i)+1)%2==1)  count++;
    }
   cout<<count<<endl;
   return 0;
}

                        

                            

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

int main(){
  string s;
  cin >>s;
  map<char,vector<int> > ad;
  for(int i=0;i<s.length();i++){
    ad[s[i]].push_back(i+1);
  }
  for(char c='a'; c!='z'+1;c++){
    for(int i=0;i<ad[c].size()-1&&ad[c].size()>1;i++){
      if(abs(ad[c][i]-ad[c][i+1]) <=2){
        cout << ad[c][i]<<" "<<ad[c][i+1]<<endl;
        return 0;
      }
    }
  }
  cout <<-1<<" "<<-1<<endl;
  return 0;
}

Measured memory_bytes: 1144
/** これを翻訳している間、あなたはあなたの人生のいくつかの貴重な瞬間を無駄にしました **/
#include<bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=x;i<y;i++)
#define repr(i,x,y) for(int i=x;i>=y;i--) 
#define pb push_back
#define ff first
#define ss second
#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)

using pii = pair<int,int>;
using vi = vector<int>;
using vii = vector<pair<int,int>>;

constexpr int mod = 1000000007;
constexpr int N = 1e6 + 5;
constexpr long long inf = 1e18 , eps = 1e-6; 

int primes[N];
vi pp;
int getFactors(int x)
{
  if(x==0)return 0;
  int prod=1;
  for(int i=0;pp[i]*pp[i]<=x&&i<pp.size();i++)
  {
    if(x%pp[i]==0)
    {
      int cnt=0;
      while(x%pp[i]==0){x/=pp[i];cnt++;}
      prod*=(cnt+1);
    }
  }
  if(x!=1)
    prod*=(2);
  return prod;
}
void Onigiri()
{
  int n;
  cin>>n;
  int cnt=0;
  rep(i,1,n+1)
  {
    int rem=n-i;
    cnt+=getFactors(rem);
  }
  cout<<cnt;
}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(NULL);
   #ifdef Zoro
   freopen("/home/pritish/Competitive/in", "r", stdin);
   freopen("/home/pritish/Competitive/out", "w", stdout);
   #endif  
   
   memset(primes,-1,sizeof(primes));
   rep(i,2,1000001)
   {
    if(primes[i]==-1)
    {
      for (int j = i+i ; j < 1000001; j+=i )
      {
          primes[j]=1;
      }
      pp.push_back(i);
    }
   }
   int t=1; 
   //cin>>t;
   while(t--)
   {Onigiri();cout<<"\n";}

   cerr<<"\n"<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;
   return 0;
}

Measured memory_bytes: 7840