akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var K = Sarray()[0];
            var N = 50L;
            var b = K / N;
            var r = K % N;
            var ai = Enumerable.Repeat(N - 1 + b, (int)N).ToArray();
            for (var i = 0; i < r; ++i)
            {
                for (var j = 0; j < N; ++j)
                    --ai[j];
                ai[i] += N + 1;
            }
            WriteLine(N);
            WriteLine(string.Join(" ", ai));
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

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

int main(){
	int n, c, k;
	cin >> n >> c >> k;
	vector<LL> t(n);
	for(int i = 0; i < n; i++) cin >> t[i];
	sort(t.begin(), t.end());
	int ans = 0;
	int cur = 0;
	while(cur < n){
		int b = cur;
		while(b+1 < n && t[b+1] <= t[cur] + k && b+1 < cur + c) b++;
		ans++;
		cur = b + 1;
	}
	cout << ans << '\n';
}

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

int main(){
    int n;
    while(cin >> n,n){
        int zc = 0,maxi = 0,ch;
        for(int i=0;i<n;i++){
            cin >> ch;
            if(ch == 0) zc++;
            maxi = max(maxi,ch);
        }
        if(maxi <= 1) cout << "NA" << endl;
        else cout << n + 1 - zc << endl;
    }
}

Measured memory_bytes: 1164
N=int(input())
A=[]
B=[]
C=[]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
    c=a+b
    C.append(c)

C.sort(reverse=True)
ans=0
for i in range(N):
    if i%2==0:
        ans+=C[i]

bs=sum(B)
ans-=bs
print(ans)

Measured memory_bytes: 15356
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
#define NMAX 110000

struct info {
    int p;
    int y;
    int x;
};


int main(void)
{
    int n,m;
    cin >> n >> m;
    info py[NMAX];

    for(int i = 0; i < m;i++)  {
        cin >> py[i].p >> py[i].y;
    }
    vector<int> mp[NMAX];
    for(int i = 0; i < m; i++){
        mp[py[i].p].emplace_back(py[i].y);
    }
    for (int i = 0; i <= n; i++) {
        sort(mp[i].begin(), mp[i].end());
    }
    for (int i = 0; i < m; i++){
        auto itr = lower_bound(mp[py[i].p].begin(), mp[py[i].p].end(), py[i].y);
        py[i].x = (int) distance(mp[py[i].p].begin(), itr) + 1;
        cout << setw(6) << setfill('0') << py[i].p;
        cout << setw(6) << setfill('0') << py[i].x << endl;
    }

    return 0;
}


Measured memory_bytes: 8448
#include<stdio.h>
 
struct Node { int p, l, r; };
struct Node T[100000000];
int n;
 
void preParse(int u) {
    if (u==-1) return 1;
    printf(" %d",u);
    preParse(T[u].l);
    preParse(T[u].r);
}
 
void inParse(int u) {
    if (u==-1) return 1;
    inParse(T[u].l);
    printf(" %d",u);
    inParse(T[u].r);
}
 
void postParse(int u) {
    if(u==-1) return 1;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d",u);
}
 
int main(void)
{
    int i, v, l, r, root;
 
    scanf("%d", &n);
    for(i=0;i<n;i++) {
        T[i].p=-1;
    }
    for (i=0;i<n;i++){
        scanf("%d %d %d",&v,&l,&r);
        T[v].l=l;
        T[v].r=r;
        if(l!=-1) T[l].p=v;
        if(r!=-1) T[r].p=v;
    }
     
    for(i=0;i<n;i++) 
if(T[i].p==-1)
 root = i;
 
    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");
 
    return 0;
}

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

int  main()
{
	int n,k; cin >> n >> k;
	set<int> st;
	vector<int> a(n);
	map<int, int> mp;
	priority_queue<int, vector<int>, greater<int>> q;
	rep(i, n)
	{
		cin >> a[i];
		mp[a[i]]++;
		st.insert(a[i]);
	}
	if (st.size() <= k)
	{
		cout << 0; return 0;
	}

	rep1(i, n)
	{
		if(st.count(i))
			q.push(mp[i]);
	}
	int r = st.size() - k;
	int ans = 0;
	rep(i, r)
	{
		ans += q.top();
		// cout << q.top() << endl;
		q.pop();
	}
	cout << ans << endl;
	return (0);
}


Measured memory_bytes: 20988
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	string s;
	cin>>s;
	int flag=0;
	int m=s.length();
	for (int i=0;i<m;i++)
	{
		if (s[m-i-1]!=s[i])
		{printf("No");return 0;}
	}
	if (flag==0)
	printf("Yes");
	return 0;
}


Measured memory_bytes: 256
N = int(input())

A = [0]*N
B = [0]*N

for i in range(N):
    A[i], B[i] = map(int, input().split())


indexes = [i for i in range(N)]
sorted_indexes = sorted(indexes, key=lambda i: B[i])

sorted_A = [A[i] for i in sorted_indexes]
sorted_B = [B[i] for i in sorted_indexes]

total = 0
for i in range(N):
    total += sorted_A[i]
    if total <= sorted_B[i]:
        continue
    else:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 30244
#include<cstdio>
#include<vector>

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

using namespace std;

struct mobile{ double w,l,r; };

vector<mobile> dfs(const vector<int> a){
	int n=a.size();
	if(n==1) return vector<mobile>(1,(mobile){a[0],0,0});

	vector<mobile> res;
	rep(S,1<<n) if(0<S && S<(1<<n)-1) {
		vector<int> al,ar;
		double wl=0,wr=0;
		rep(i,n){
			if(S&1<<i) al.push_back(a[i]), wl+=a[i];
			else       ar.push_back(a[i]), wr+=a[i];
		}

		vector<mobile> L=dfs(al),R=dfs(ar);
		rep(i,L.size()) rep(j,R.size()) {
			double l2=min(-wr/(wl+wr)+L[i].l,wl/(wl+wr)+R[j].l);
			double r2=max(-wr/(wl+wr)+L[i].r,wl/(wl+wr)+R[j].r);
			res.push_back((mobile){wl+wr,l2,r2});
		}
	}
	return res;
}

int main(){
	int T; scanf("%d",&T);
	while(T--){
		double W;
		int n; scanf("%lf%d",&W,&n);
		vector<int> a(n);
		rep(i,n) scanf("%d",&a[i]);

		vector<mobile> res=dfs(a);

		double ans=-1;
		rep(i,res.size()) if(res[i].r-res[i].l<W) ans=max(ans,res[i].r-res[i].l);
		printf("%.9f\n",ans);
	}

	return 0;
}

Measured memory_bytes: 2544
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        double[] A = new double[5];
        
        int pos=0, min=10;
        for(int i=0; i<5; i++){
            String x = sc.next();
            A[i] = Integer.parseInt(x);
            int y = x.charAt(x.length()-1) - '0';
            if(y!=0 && y<min){
                min = y;
                pos = i;
            }
        }
        
        int sum = 0;
        for(int i=0; i<5; i++){
            if(i == pos){
                sum += A[i];
            }else{
                sum += Math.ceil(A[i]/10)*10;
            }
        }
        
        System.out.println(sum);
    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(ll, N, T);
  VEC(ll, t, N);
  ll ans = T;
  rep(i, 0, N - 1) {
    ans += min(t[i + 1] - t[i], T);
  }
  print(ans);
}


Measured memory_bytes: 1792
INF = float('inf')
n, k = map(int, input().split())
G = [[] for _ in range(n)]
_G = []
for _ in range(k):
    ss, t, d = map(int, input().split())
    G[ss].append((t,d))
    if t == 0:_G.append((ss,d))
    
dp = [[INF]*n for _ in range(1<<n)]
dp[1][0] = 0

for s in range(1,(1<<n)):
    for v in range(n):
        if dp[s][v] == INF:continue
        for t, d in G[v]:
            if not(s & (1<<t)):
                next_s = s | (1<<t)
                dp[next_s][t] = min(dp[next_s][t],dp[s][v]+d)
                    
                    
ans = INF
for pre, d in _G:
    ans = min(ans, dp[-1][pre]+d)
print(ans if ans != INF else -1)


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

#define ll long long
#define N 3010
int a[4], n;
ll f[4][N];

int main() {
	while (scanf("%d", a + 1) != EOF) {
		for (int i = 2; i <= 3; ++i) {
			scanf("%d", a + i);
		}
		scanf("%d", &n);
		memset(f, 0, sizeof f);
		f[0][0] = 1;
		for (int i = 1; i <= 3; ++i) {
			for (int j = 0; j <= n; j += a[i]) {
				for (int k = n - j; k >= 0; --k) {
					f[i][k + j] += f[i - 1][k];
				}
			}
		}
		printf("%lld\n", f[3][n]);
	}
	return 0;
}


Measured memory_bytes: 384
// God put a smile upon your face <3

#include <bits/stdc++.h>

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> n)
    {
		double side = (n / 3.0);

		cout << setprecision(10) << fixed << side * side * side << "\n";
    }


}





Measured memory_bytes: 3796
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N, M = IL()
abc = [IL() for _ in range(M)]

dp = [[MAX_INT]*N for _ in range(N)]
for a, b, c in abc:
  dp[a - 1][b - 1] = c
  dp[b - 1][a - 1] = c
for i in range(N):
  dp[i][i] = 0

for k in range(N):
  for i in range(N):
    for j in range(N):
      dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
#print(dp)

used = [False]*M
cnt = 0
for edge in range(M):
  a, b, c = abc[edge]
  for i in range(N):
    for j in range(N):
      if dp[i][a - 1] + c + dp[b - 1][j] == dp[i][j]:
        used[edge] = True
        cnt += 1
        break
    else:
      continue
    break

#print(used)
print(M - cnt)

Measured memory_bytes: 44396
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=1000000007;

int main(){
  int a,b;cin>>a>>b;
  Ans(a*b%2==1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long pow(long long p,long long q,long long r){
  if(q==0)return 1;
  else if(q%2==0)return pow(p,q/2,r)*pow(p,q/2,r)%r;
  else return pow(p,q-1,r)*p%r;
}
int main() {
  int n;
  cin>>n;
  long long a[n],b[60],ans=0,mod=1000000007;
  for(int i=0;i<60;i++)b[i]=0;
  for(int i=0;i<n;i++){
    long long l;
    cin>>l;
    for(int j=0;j<60;j++){
      if(l%2==1)b[j]++;
      l=l/2;
    }
  }
  for(int i=0;i<60;i++){
    ans=(ans+(b[i]*(n-b[i])%mod)*pow(2,i,mod))%mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std; 
int main(){
	int n;
	scanf("%d",&n);
	int ans=0;
	while(n--){
		int a,b;
		scanf("%d%d",&a,&b);
		ans=ans+b-a+1;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
<?php
while (true){
    $inLine = explode(" ", trim(fgets(STDIN)));
    if ($inLine[0] == 0 && $inLine[1] == 0){
        break;
    }
    
    $hit = 0;
    $blow = 0;
    $trueWords = str_split($inLine[0]);
    $ansWords = str_split($inLine[1]);
    
    foreach ($trueWords as $trueKey => $trueDigit) {
        foreach ($ansWords as $ansKey => $ansDigit){
            if ($trueDigit == $ansDigit){
                if ($trueKey == $ansKey){
                    $hit++;
                } else {
                    $blow++;
                }
            } 
        }
    }
    echo $hit." ".$blow.PHP_EOL;
}


Measured memory_bytes: 9256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		
		System.out.println(solve(D));

		sc.close();
	}
	
	static final int MAXL=17;
	static int N;
	static long[] v;
	
	static long solve(int D) {
		if(D%9 != 0)
			return 0;
		D /= 9;
		
		long[] B = new long[MAXL];
		B[0] = 1;
		for(int i=1; i<MAXL; i++)
			B[i] = B[i-1]*10;

		long ans =0;
		for(int i=1; i<=MAXL; i++) {
			N = (i+1)/2;
			v = new long[N];
			for(int j=0; j<N; j++)
				for(int k=j; k<i-j; k++)
					v[j] += B[k];
			ans += count(D, i, 0, new int[N]);
		}
		
		return ans;
	}
	
	static long count(long D, int l, int t, int[] x) {
		if(t==N) {
			if(D!=0)
				return 0;
			
			long ans = 1;
			for(int i=0; i<N; i++) {
				ans *= (i==0 ? 9 : 10) - Math.abs(x[i]);
			}
			if(l%2==0)
				ans *= 10;
			return ans;
		}
		long ans = 0;
		for(int m=-9; m<=9; m++) {
			if(-v[t] < D+v[t]*m && D+v[t]*m < v[t]) {
				x[t] = m;
				ans += count(D+v[t]*m, l, t+1, x);
			}
		}
		return ans;
	}
}


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

int main() {
    int n,m;cin>>n>>m;
    int a[n];
    for (int i=0;i<n;i++) {
        cin>>a[i];
        a[i]/=2;
    }
    int c=0;
    for (int t=a[0];t%2==0;t/=2)
        c++;
    int f=1;
    for (int i=1;i<n;i++) {
        int c2=0;
        for (int t=a[i];t%2==0;t/=2)
            c2++;
        f&=c==c2;
    }
    if (!f) {
        cout<<0<<endl;
        return 0;
    }
    ll lcm=1;
    for (int i=0;i<n;i++)
        lcm=lcm*a[i]/__gcd(lcm,(ll)a[i]);
    cout<<(m/lcm+1)/2<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>
int main() {
    int d, t, s;
    double sum;
    scanf("%d", &d);
    scanf("%d", &t);
    scanf("%d", &s);
    sum = (double)d / s;
    if (sum <= t) {
        printf("Yes");
    }
    else {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e14;
const int ZERO = 0;
const int MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int par[100010]; //親
int deep[100010]; //木の深さ

//ｎ要素で初期化
void init(int n) {
	for(int i = 0;i < n;i++) {
		par[i] = i;
		deep[i] = 0;
	}
}

//木の根を求める
int find(int x) {
	if(par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

//ｘとｙの属する集合を併合
void unite(int x,int y) {
	x = find(x);
	y = find(y);
	if(x == y) {
		return;
	}
	if(deep[x] < deep[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if(deep[x] == deep[y]) {
			deep[x]++;
		}
	}
}

//ｘとｙが同じ集合に属するか否か
bool same(int x,int y) {
	return find(x) == find(y);
}

signed main() {
    int N,M;
    cin >> N >> M;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
        vec.at(i)--;
    }
    init(N);
    for(int i = 0;i < M;i++) {
        int A,B;
        cin >> A >> B;
        unite(A - 1,B - 1);
    }
    vector<int> cnt[100010];
    for(int i = 0;i < N;i++) {
        cnt[find(i)].push_back(i);
    }
    int ret = 0;
    for(int i = 0;i < 100010;i++) {
        vector<bool> count(N);
        for(int j = 0;j < cnt[i].size();j++) {
            count.at(cnt[i].at(j)) = true;
        }
        for(int j = 0;j < cnt[i].size();j++) {
            if(count.at(vec.at(cnt[i].at(j))) == true) {
                ret++;
            }
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 8064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}

int main(){
    int q;
    cin >> q;
    rep(zz,q){
        ll a,b,c,d;
        cin >> a >> b >> c >> d;
        c--;d--;
        ll len = max((a+b)/(b+1),(a+b)/(a+1));
        if(len*b <= a){
            for(int i=c;i<=d;i++){
                if(i%(len+1)==len){
                    cout << "B";
                }else{
                    cout << "A";
                }
            }
            cout << "\n";
            continue;
        }
        if(len*a <= b){
            for(int i=c;i<=d;i++){
                if((a+b-1-i)%(len+1)==len){
                    cout << "A";
                }else{
                    cout << "B";
                }
            }
            cout << "\n";
            continue;
        }

        ll ok = 0;
        ll ng = inf;
        while(ng-ok>1){
            ll mid = (ok+ng)/2;
            if(mid*len>a-1){
                ng = mid;
                continue;
            }
            if(b-len-mid <= (a-1-mid*len)*len){
                ok = mid;
            }else
            {
                ng = mid;
            }
            
        }   
        ll L = ok;
        ll R = min(a-1-ok*len,(b-1-ok)/len);
        ll A = a - L*len-R;
        ll B = b - R*len-L;
        // cerr << len << endl;
        // cerr << L << " " << A << " " << B << " " << R << endl;
        for(int i=c;i<=d;i++){
            if(i<(len+1)*L){
                if(i%(len+1)==len){
                    cout << "B";
                }else{
                    cout << "A";
                }
            }else if(i<(len+1)*L+A){
                cout << "A";
            }else if(i<(len+1)*L+A+B){
                cout << "B";
            }else{
                if((i-(len+1)*L-A-B)%(len+1)==0){
                    cout << "A";
                }else{
                    cout << "B";
                }
            }
        }
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000
#define ll long long
using namespace std;
int main()
{
    int N, M, R;
    ll ans = INF;
    cin >> N >> M >> R;
    vector<int> r(R);
    rep(i, R) cin >> r[i];
    sort(r.begin(), r.end());
    vector<vector<ll>> d(N, vector<ll>(N, INF));
    rep(i, N) d[i][i] = 0;
    rep(i, M)
    {
        int a, b, c;
        cin >> a >> b >> c;
        d[a - 1][b - 1] = d[b - 1][a - 1] = c;
    }
    for (int k = 0; k < N; k++)
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    do
    {
        ll sum = 0;
        rep(i, R - 1) sum += d[r[i] - 1][r[i + 1] - 1];
        ans = min(ans, sum);
    } while (next_permutation(r.begin(), r.end()));
    cout
        << ans << "\n";
}

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

constexpr int INF = 1e9;

int main() {
    int a, b;
    vector<int> cnt(101, 0);
    while(cin >> a >> b) {
        if(a == 0 && b == 0) {
            bool ok = cnt[1] & 1 && cnt[2] & 1;
            if(ok) {
                for(int i=3; i<=100; ++i) {
                    ok &= !(cnt[i] & 1);
                }
            }
            if(ok) {
                cout << "OK" << endl;
            } else {
                cout << "NG" << endl;
            }
            fill(cnt.begin(), cnt.end(), 0);
        } else {
            cnt[a]++;
            cnt[b]++;
        }
    }
}


Measured memory_bytes: 2968
from collections import deque

H, W = map(int, input().split())
S = [input() for _ in range(H)]

move = ((1, 0), (-1, 0), (0, 1), (0, -1))
visited = [[-1] * W for _ in range(H)]

ans = 0
que = deque([])
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            visited[i][j] = 0
            for di, dj in move:
                ni, nj = i + di, j + dj
                if 0 <= ni < H and 0 <= nj < W \
                   and S[ni][nj] != '#' and visited[ni][nj] == -1:
                    que.append((ni, nj, 1))
                    visited[ni][nj] = 1
                    ans = 1

while que:
    i, j, d = que.popleft()
    for di, dj in move:
        ni, nj = i + di, j + dj
        if 0 <= ni < H and 0 <= nj < W and visited[ni][nj] == -1:
            que.append((ni, nj, d+1))
            visited[ni][nj] = d+1
            ans = d+1

print(ans)


Measured memory_bytes: 122972
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <tuple>
#include <unordered_set>
#include <unordered_map>

typedef long long ll;
using namespace std;

int main(void) {
  ll N, M; cin >> N >> M;
  vector<ll> from;
  vector<ll> to;

  for (int i = 0; i < M; i++) {
    ll f, t; cin >> f >> t;
    if (f == 1) from.push_back(t);
    if (t == N) to.push_back(f);
  }

  // for (auto v : from) { cout << v << " "; } cout << endl;
  // for (auto v : to)  { cout << v << " "; } cout << endl;

  sort(from.begin(), from.end());
  sort(to.begin(), to.end());
  vector<ll> common;
  set_intersection(from.begin(), from.end(), to.begin(), to.end(), inserter(common, common.end()));
  cout << (common.size() > 0 ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}


Measured memory_bytes: 2004
//JSD
#include<iostream>
#include<vector>
#include<map>
#include<set>
#define pii pair<int ,int >

using namespace std;
vector<int > G[100001];
vector<pii > a;
int n;
map<pii ,int > M;
bool visited[100001];
void dfs(int s,int parentColor){
	int i=1;	
	visited[s]=1;
	for(auto x: G[s]){
		if(!visited[x]){
			if(i==parentColor) i++;
			M[{min(x,s),max(x,s)}]=i;
			dfs(x,i);
			i++;
		}
	}
}
int main(){
	cin>>n;
	for(int i=0;i<n-1;i++){
		int p,q;
		cin>>p>>q;
		a.push_back({min(p,q),max(p,q)});
		G[p].push_back(q);
		G[q].push_back(p);
	}
	dfs(1,-1);
	set<int> s;
	for(auto x: a){
		s.insert(M[x]);
	}
	cout<<s.size()<<"\n";
	for(auto x: a){
		cout<<M[x]<<"\n";
	}
	
	return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> b = a;
    sort(b.begin(), b.end());
    int left = n/2 - 1;
    int right = n/2;

    rep(i, n) {
        int value = a[i];
        if(lower_bound(b.begin(), b.end(), value) - b.begin() <= left) {
            cout << b[right] << endl;
        }else{
            cout << b[left] << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
/*-----------------------------------------------------------------------------------------------*/
const int N = 1e5+10;
int n,t;
string s,ss;
int a[N];
int main()
{
    _SAD()
    int a,b;
    cin>>a>>b;
    stringstream x,y;
    x<<a;
    y<<b;
    x>>s;
    y>>ss;
    string kk,pp,o,p;
    o=s;
    p=ss;
    for(int i=0;i<b-1;i++)
    {
        s+=o;
    }
    for(int i=0;i<a-1;i++)
    {
        ss+=p;
    }
    if(a==b)
    {
        cout<<ss<<nl;
    }
    else if(a>b)
    {
        cout<<ss<<nl;
    }
    else
    {
        cout<<s<<nl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::map<int,int>S;
std::set<int>T;
int n,A,mid;
void set(int p,int x){
	S[p]=x;
	if(x==mid){
		if(T.count(p))T.erase(p);
		if(!S.count(p-1)||S[p-1]<mid)T.insert(p-1);
	}
}
int len[200010];
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=gi();
	for(int i=1;i<=n;++i)len[i]=gi();
	bool flg=0;
	for(int i=1;i<n;++i)if(len[i]>=len[i+1])flg=1;
	if(!flg)return puts("1"),0;
	int l=1,r=n;
	while(l<r){
		mid=((l+r)>>1);
		A=len[1];
		S.clear(),T.clear();
		T.insert(0);
		bool flg=0;
		for(int i=2;i<=n;++i){
			int B=len[i];
			if(B<=A){
				while(!S.empty()&&(--S.end())->first>B)S.erase(--S.end());
				while(!T.empty()&&*--T.end()>B)T.erase(--T.end());
				if(!S.count(B)||S[B]<mid)set(B,S[B]+1);
				else{//S[B]=mid
					int p=*--T.lower_bound(B);
					if(!p){l=mid+1;flg=1;break;}
					else{
						set(p,S[p]+1);
						while(!S.empty()&&(--S.end())->first>p)S.erase(--S.end());
						while(!T.empty()&&*--T.end()>p)T.erase(--T.end());
					}
				}
			}
			A=B;
		}
		if(!flg)r=mid;
	}
	printf("%d\n",l+1);
	return 0;
}


Measured memory_bytes: 1024
n=int(input())
s=input()
sum=0
r=int(s.count('R'))
g=int(s.count('G'))
b=int(s.count('B'))
for k in range(n):
    for j in range(k):
        i=2*j-k
        if i+1>0:
            if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                sum=sum+1
print(r*g*b-sum)

Measured memory_bytes: 9140
fn solve(xys: Vec<(i64, i64)>) -> f64 {
    let n = xys.len();
    let mut xys = xys;

    xys.sort_by(|&(x1, y1), &(x2, y2)| {
        let p1 = (y1 as f64).atan2(x1 as f64);
        let p2 = (y2 as f64).atan2(x2 as f64);

        p1.partial_cmp(&p2).unwrap()
    });

    let mut ans = 0.0;

    for i in 0..n {
        let mut x = 0;
        let mut y = 0;

        for j in 0..n {
            let k = (i + j) % n;
            let (ax, ay) = xys[k];
            x = x + ax;
            y = y + ay;

            let r = ((x * x + y * y) as f64).sqrt();
            if ans < r {
                ans = r;
            }

            if (i + j + 1) % n == i {
                break;
            }
        }
    }

    ans
}

#[test]
fn solve_test() {
    assert_eq!(solve(vec![(0, 10), (5, -5), (-5, -5)]), 100.0_f64.sqrt());
    assert_eq!(
        solve(vec![(1, 1), (1, 0), (0, 1), (-1, 0), (0, -1)]),
        8_f64.sqrt()
    );
    assert_eq!(solve(vec![(96000, -72000), (-72000, 54000)]), 120000_f64);
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let n = parse_line!(usize);

    let xys = (0..n).map(|_| parse_line!(i64, i64)).collect::<Vec<_>>();

    println!("{}", solve(xys));
}


Measured memory_bytes: 4604
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#include<cmath>
using namespace std;
void read(int &x){
	char ch;bool ok;
	for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
	for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
#define rg register
const int maxn=110;
#define max(a,b) ((a)>(b)?(a):(b))
short ans,f[maxn][maxn][maxn][maxn],l[maxn][maxn],r[maxn][maxn];
int n,m,x,y;char s[maxn];
void solve(){
	int le=y-1,rt=m-y,up=x-1,dw=n-x;
	for(rg int i=0;i<=le;i++)
		for(rg int j=0;j<=rt;j++)
			for(rg int k=0;k<=up;k++)
				for(rg int t=0;t<=dw;t++){
					if(y-i-1>j){
						int now1=max(x-k,t+1),now2=min(x+t,n-k);
						f[i+1][j][k][t]=max(f[i+1][j][k][t],f[i][j][k][t]+r[now2][y-i-1]-r[now1-1][y-i-1]);
					}
					else f[i+1][j][k][t]=max(f[i+1][j][k][t],f[i][j][k][t]);
					
					if(y+j+1+i<=m){
						int now1=max(x-k,t+1),now2=min(x+t,n-k);
						f[i][j+1][k][t]=max(f[i][j+1][k][t],f[i][j][k][t]+r[now2][y+j+1]-r[now1-1][y+j+1]);
					}
					else f[i][j+1][k][t]=max(f[i][j+1][k][t],f[i][j][k][t]);
					
					if(x-k-1>t){
						int now1=max(y-i,j+1),now2=min(y+j,m-i);
						f[i][j][k+1][t]=max(f[i][j][k+1][t],f[i][j][k][t]+l[x-k-1][now2]-l[x-k-1][now1-1]);
					}
					else f[i][j][k+1][t]=max(f[i][j][k+1][t],f[i][j][k][t]);
					
					if(x+t+1+k<=n){
						int now1=max(y-i,j+1),now2=min(y+j,m-i);
						f[i][j][k][t+1]=max(f[i][j][k][t+1],f[i][j][k][t]+l[x+t+1][now2]-l[x+t+1][now1-1]);
					}
					else f[i][j][k][t+1]=max(f[i][j][k][t+1],f[i][j][k][t]);
				}
	printf("%d\n",f[le][rt][up][dw]);
}
int main(){
	read(n),read(m);
	for(rg int i=1;i<=n;i++){
		scanf("%s",s+1);
	    for(rg int j=1;j<=m;j++){
			if(s[j]=='E')x=i,y=j;
			else if(s[j]=='o')l[i][j]=r[i][j]=1;
		}
	}
	for(rg int i=1;i<=n;i++)
		for(rg int j=1;j<=m;j++)
			l[i][j]+=l[i][j-1];
	for(rg int i=1;i<=m;i++)
		for(rg int j=1;j<=n;j++)
			r[j][i]+=r[j-1][i];
	solve();
}


Measured memory_bytes: 213376
import Data.Char
import Data.List
main = do
  txt<- getContents
  putStr $ unlines $ zipWith (\c x -> [c]++" : "++show x) ['a'..'z'] (foldl1 (zipWith(+)) (map (map (\c-> length $ filter (== c) txt) ) [['a'..'z'],['A'..'Z']]))

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	cout<<(h2-h1)*60+m2-m1-k<<endl;
}


Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#define int long 
using namespace std;

signed main() {
	int N;
	cin >> N;
	for(int i = 1;i < 10;i++) {
		if(N <= i * 111) {
			cout << i * 111 << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def cal(A, F, m):
    res = 0
    for a, f in zip(A, F):
        c = m // f
        res += max(0, a - c)
    return res


def main():
    N, K = read_values()
    A = read_list()
    F = read_list()
    A.sort()
    F.sort(reverse=True)

    l = 0
    r = 10 ** 12
    while l < r:
        m = (l + r) // 2
        if cal(A, F, m) > K:
            l = m + 1
        else:
            r = m
    
    print(r)


if __name__ == "__main__":
    main()

Measured memory_bytes: 116264
from collections import*
n,*a=map(int,open(0).read().split())
r=[];s=[]
for k,v in Counter(a).items():
	if v>1:
		r+=[k]
	if v>3:
		s+=[k]
if len(r)<2 and len(s)<1:
	print(0)
	exit()
r+=[0,0]
s+=[0]
r.sort()
s.sort()
print(max(r[-1]*r[-2],s[-1]**2))

Measured memory_bytes: 18528
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Feb  9 20:41:09 2019

@author: shinjisu
"""


# 2019/2/9 Yahoo
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def db(x):
    global debug
    if debug:
        print(x)


def probA():
    N, K = getIntList()
    db((N, K))
    if (N+1)//2>=K:
        print('YES')
    else:
        print('NO')


def probB():
    return 0


def probC():
    return 0


debug = False
probA()


Measured memory_bytes: 3064
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <functional>
# include <utility>
# include <queue>
# include <stack>
# define MOD 1000000007
# define INF 2000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

int main() {
	long long ans = 0, counter = 0, maxi = -1, mini = INF, pass = 0;
	//new
	ll a, b,n;
	cin>>n>> a >> b;
	
	if ((b-a)% 2 == 0) {
		ll x = (b-a) / 2;
		cout << x << endl;
	}
	else {
		ll one = (a-1)+1+(b-a-1)/2;
		ll enu = (n-b)+1+(n-(a+n-b+1))/2;
		cout << min(one,enu) << endl;
	}
}

Measured memory_bytes: 256
#!/usr/bin/env python
#pyrival orz
import os
import sys
from io import BytesIO, IOBase

"""
    for _ in range(int(input())):
    n,m=map(int,input().split())
    n=int(input())
    a = [int(x) for x in input().split()]
"""

def main():
    n=int(input())
    print((-n)%1000)

# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Measured memory_bytes: 62576
while num = gets do
  c1, c2, c3 = num.split.map(&:to_i)
  cnt = 0
  for i in 1..10 do
    unless i == c1 || i == c2 || i == c3 then
  	  if c1 + c2 + i <= 20 then
  	    cnt += 1
      end
    end
  end
  puts cnt >= 4 ? 'YES' : 'NO'
end

Measured memory_bytes: 6100
N = int(input())
dic = dict()
for j in range(N):
    i = int(input())

    if i not in dic.keys():
        dic[i] = 1
    else:
        if dic[i] == 0:
            dic[i] = 1
        else:
            dic[i] = 0



ans = sum(dic.values())

print(ans)

Measured memory_bytes: 15072
(* O(1) *)
let a, b, c = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let ps = Array.make_matrix 2 3 0
let pn = Array.make 2 0
let f x =
  let r = x mod 2 in
  ps.(r).(pn.(r)) <- x;
  pn.(r) <- pn.(r) + 1
let _ =
  List.iter f [a; b; c];
  Printf.printf "%d\n" @@
    if pn.(0) = 3 || pn.(1) = 3 then
      let m = List.fold_left max 0 [a; b; c] in
      (3 * m - (a + b + c)) / 2
    else
      let i = List.find (fun i -> pn.(i) = 2) [0; 1] in
      let j = 1 - i in
      let x, y, z = ps.(i).(0), ps.(i).(1), ps.(j).(0) in
      let m = max x y + 1 in
      abs (x - y) / 2 + 1 + if m > z then (m - z) / 2 else m - z

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

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

const ll LINF = 9187201950435737471;
const ll nLINF = -9187201950435737472;
const int INF = 2139062143;
const int nINF = -2139062144;
const ull ULINF = numeric_limits<ull>::max();
const int MAXN = 1e3 + 15;
const ll MOD = 1e9 + 7;
const double EPS = 1e-7;
const double PI = acos(-1);
const double E = 2.718281828459045;
const int BLOCK = 2000;
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd(seed);

#define all(_v) _v.begin(), _v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define sqr(_v) ((_v) * (_v))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mod(x, m) ((x) % m + (x < 0 ? m: 0))

inline void IO() {
#ifdef buyolitsez
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
}


template <typename T>
istream& operator >> (istream& in, vector<T>& a) {
    for (auto& i : a)
        in >> i;
    return in;
}

template <typename T>
ostream& operator << (ostream& out, const vector<T>& a) {
    for (auto& i : a) {
        out << i << " ";
    }
    return out;
}

template <typename T, typename D>
istream& operator >> (istream& in, pair<T, D>& a) {
    in >> a.first >> a.second;
    return in;
}

template <typename T, typename D>
ostream& operator << (ostream& out, const pair<T, D>& a) {
    out << a.first << " " << a.second;
    return out;
}

#define int int64_t

bool check(int n, int i) {
    if (n % i == 0) {
        int k = n / i;
        return check(k, i);
    }
    return n % i == 1;
}

inline void solve() {
    int n;
    cin >> n;
    int pos;
    for (pos = 1; pos * pos <= n; ++pos) {}
    int ans = 0;
    for (int i = 1; i <= pos; ++i) {
        if ((n - 1) % i == 0) {
            if ((n - 1) / i >= pos) {
                ans++;
            }
        }
        if (i * i > n || i == 1) {continue;}
        if (check(n, i)) {
            ans++;
        }

    }
    cout << ans + 1;
}

signed main() {
    IO();
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
// 簡易競プロテンプレ
#include <bits/stdc++.h>
using namespace std;

int c[4];
int main(void){
 string s; cin >> s;
 for(int i=0;i<s.size();i++){
  if (s[i]=='N') c[0]++;
  if (s[i]=='S') c[1]++;
  if (s[i]=='E') c[2]++;
  if (s[i]=='W') c[3]++;
 }
 if (((int)(c[0]>0))^((int)(c[1]>0)) || ((int)(c[2]>0))^((int)(c[3]>0)))
  cout << "No" << endl;
 else cout << "Yes" << endl;
 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,P;cin>>N>>P;
    string S;cin>>S;
    
    if(P==2){
        ll ans=0;
        for(int i=0;i<N;i++){
            if(int(S[i]-'0')%2==0) ans+=(i+1);
        }
        cout<<ans<<endl;
        return 0;
    }
    if(P==5){
        ll ans=0;
        for(int i=0;i<N;i++){
            if(int(S[i]-'0')%5==0) ans+=i+1;
        }
        cout<<ans<<endl;
        return 0;
    }
    vector<int> right(N+1),cnt(P),rui10(N+1,1);
    for(int i=1;i<=N;i++){
        rui10[i]=rui10[i-1]*10;
        rui10[i]%=P;
    }
    for(int i=N-1;i>=0;i--){
        right[i]=right[i+1]+int(S[i]-'0')*rui10[N-1-i];
        right[i]%=P;
    }
    
    ll ans=0;
    
    cnt[0]++;
    
    for(int i=N-1;i>=0;i--){
        ans+=cnt[right[i]];
        cnt[right[i]]++;
        
        //cout<<ans<<endl;
    }
    
    cout<<ans<<endl;
    
    //for(int i=N-1;i>=0;i--) cout<<right[i]<<endl;
}




Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename 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 c[3][3];
	for(int i = 0;i < 3;i++){
		for(int j = 0;j < 3;j++){
			cin >> c[i][j];
			if(i) c[i][j] -= c[0][j];
		}
	}
	if(c[1][0] == c[1][1] && c[1][1] == c[1][2] && c[2][0] == c[2][1] && c[2][1] == c[2][2]) Yes();
	else No();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> imos(n);
    auto xx = [&](int aka, int ichi) {
        imos[max(0,ichi-aka)]++;
        if (n-1 >= ichi+aka+1) imos[ichi+aka+1]--;
        return;
    };

    rep(i,k) {
        rep(j,n) {
            int ichi = j;
            int aka = a[ichi];
            xx(aka, ichi);
        }
        rep(j,n-1) imos[j+1] += imos[j];
        a = imos;
        imos = vector<int>(n);
        int min_aka = INF;
        rep(j,n) min_aka = min(min_aka, a[j]);
        if(min_aka == n) break;
    }

    rep(i,n) cout << a[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 5576
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int r[111][111];

Int mod_pow(Int x,Int y,Int mod){
  Int res = 1;
  while(y){
    if(y&1) res = res * x % mod;
    x = x * x % mod;
    y /= 2;
  }
  return res;
}

Int extgcd(Int a,Int b,Int &x,Int &y){
  Int d = a;
  if(b != 0){
    d = extgcd(b, a%b, y,x);
    y -= (a/b) * x;
  } else{
    x = 1, y = 0;
  }
  return d;
}

Int mod_inverse(Int a,Int mod){
  Int x,y;
  extgcd(a,mod,x,y);
  return (mod+x%mod)%mod;
  //return mod_pow(x, mod-2, mod);

}

pair<Int, Int> linear_congruence(const vector<Int> &A, const vector<Int> &B,const vector<Int> &M){
  Int x = 0 ,m = 1;
  for(Int i=0;i<(Int)A.size();i++){
    Int a = A[i] * m , b = B[i] - A[i] * x, d = __gcd(M[i], a);
    if(b%d!=0) return make_pair(0,-1);
    Int t = b / d * mod_inverse(a / d, M[i] / d) % (M[i] / d);
    x = x + m * t;
    m *= M[i]/d;
  }
  return make_pair(x%m,m);
}

signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n,m,d;
  cin>>n>>m>>d;
  vector<Int> a(m);
  for(Int i=0;i<m;i++) cin>>a[i];

  for(Int i=0;i<d;i++)
    for(Int j=0;j<m;j++)
      cin>>r[i][j];

  for(Int i=0;i<d;i++){
    vector<Int> A,B,M;
    for(Int j=0;j<m;j++){
      if(r[i][j]<0) continue;
      A.emplace_back(1);
      B.emplace_back(r[i][j]);
      M.emplace_back(a[j]);
    }
    auto p=linear_congruence(A,B,M);
    //cout<<i<<":"<<p.first<<" "<<p.second<<endl;
    if(p.second<0){
      n=-1;
      break;
    }
    if(p.second<0) p.first+=p.second;
    n=(n-p.first)/p.second*p.second+p.first;
  }
  
  cout<<n<<endl;
  return 0;
}




Measured memory_bytes: 3256
/*
_________________________
|   LIVE FREE OR DIE     |
|       327 2153         |
|          New           |
|_______HAMPSHIRE________|

*/
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define MAX 20
#define int long long
#define MOD 998244353

int32_t main()
{
	IOS
	int n,m;cin>>n>>m;
	if(m>=n) cout<<"unsafe";
	else cout<<"safe";
	return 0;
}

Measured memory_bytes: 3648
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    s = S()
    l = len(s)
    if l == 2:
        if s == ">>" or s == "<<":
            return 3
        if s == "><":
            return 2
        return 1

    a = [-1] * (l+1)
    q = []
    v = [False] * (l+1)
    if s[0] == "<":
        q.append(0)
        v[0] = True
    if s[l-1] == ">":
        q.append(l)
        v[l] = True
    for i in range(1,l):
        if s[i-1:i+1] == "><":
            q.append(i)
            v[i] = True

    for qi in range(l+1):
        t = q[qi]
        if t == 0:
            a[t] = a[t+1] + 1
            if not v[t+1] and (v[t+2] or s[t+1] == "<"):
                q.append(t+1)
                v[t+1] = True
        elif t == l:
            a[t] = a[t-1] + 1
            if not v[t-1] and (v[t-2] or s[t-2] == ">"):
                q.append(t-1)
                v[t-1] = True
        else:
            a[t] = max(a[t+1], a[t-1]) + 1
            if not v[t+1] and (t == l-1 or v[t+2] or s[t+1] == "<"):
                q.append(t+1)
                v[t+1] = True
            if not v[t-1] and (t == 1 or v[t-2] or s[t-2] == ">"):
                q.append(t-1)
                v[t-1] = True

    # k = []
    # for ai,c in zip(a,s+" "):
    #     k.append(ai)
    #     k.append(c)
    # print(k)
    return sum(a)


print(main())





Measured memory_bytes: 50144