akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int b;
string a;
int main() {
	cin>>a;
	int l=a.size();
	for(int i=0; i<l; i++) {
		if(a[i]=='S') {
			b=0;
			for(int i=0; i<l; i++) {
				if(a[i]=='N') {
					b=1;
					break;
				}
			}
			if(b==0) {
				cout<<"No"<<'\n';
				return 0;
			}
		}
		if(a[i]=='N') {
			b=0;
			for(int i=0; i<l; i++) {
				if(a[i]=='S') {
					b=1;
					break;
				}
			}
			if(b==0) {
				cout<<"No"<<'\n';
				return 0;
			}
		}
		if(a[i]=='E') {
			b=0;
			for(int i=0; i<l; i++) {
				if(a[i]=='W') {
					b=1;
					break;
				}
			}
			if(b==0) {
				cout<<"No"<<'\n';
				return 0;
			}
		}
		if(a[i]=='W') {
			b=0;
			for(int i=0; i<l; i++) {
				if(a[i]=='E') {
					b=1;
					break;
				}
			}
			if(b==0) {
				cout<<"No"<<'\n';
				return 0;
			}
		}
	}
	cout<<"Yes"<<'\n';
	return 0;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.Char



main = do
    [a, b, c] <- map read . words <$> getLine
    let rad = c * pi / 180
    let s = a * b * sin (rad) / 2
    let l = a + b + sqrt (a**2 + b**2 - 2 * a * b * cos rad)
    mapM_ print [s, l, s * 2 / a]

Measured memory_bytes: 4200
x = list(map(int,input().split(" ")))
n = x[0]
k = x[1]

sunlist = [0]*n
dlist = []
alist = []

for i in range(k):
    d = int(input())
    dlist.append(d)
    # print(d)
    # print(dlist)

    a =list(map(int,input().split(" ")))
    for j in range(d):
        sunlist[a[j]-1] += 1
        # print(sunlist)

sunlist_plus = [i for i in sunlist if i > 0]
sunlist_plus_len = len(sunlist_plus)
print(n-sunlist_plus_len)

Measured memory_bytes: 9208
import math

n = int(input())

def func(a, b):
    return len(str(max(a, b)))

ans = len(str(n))
for num in range(1, math.ceil(math.sqrt(n))+1):
    if n % num == 0:
        ans = min(ans, func(num, n//num))

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
ll x;
int ans=0;
void dfs(ll y){
    string s=to_string(y);
    if (y>x)
        return;
    if (s.find('3')!=-1 &&s.find('5')!=-1 &&s.find('7')!=-1)
        ans++;
    dfs(y*10+3);
    dfs(y*10+5);
    dfs(y*10+7);
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>x;
    dfs(0);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding utf-8 -*-
N = int(input())
S = input()

ans = 0
a = 0
num1, num2 = 0, 0
# dp = [[0] * N for _ in range(N)]
dp = [[0] *2 for _ in range(N + 1)]
for i in range(N):
    dp[i + 1][0] = dp[i][0] + (1 if S[i] == '.' else 0)
    dp[i + 1][1] = dp[i][1] + (1 if S[i] == '#' else 0)

ans = 1e10
for i in range(1, N + 1):
    num = dp[i - 1][1] + (dp[N][0] - dp[i - 1][0])
    ans = min(ans, num)
ans = min(ans, dp[N][1])
print(ans)



Measured memory_bytes: 38432
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define cpy(a,b) memcpy(a,b,sizeof(a))
#define prq priority_queue
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
int n,a[101010];
ll ans=0;
int x=0,y=1e9;
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	fo(i,0,n){
		cin>>a[i];
		if(a[i]<0)x++;
		y=min(y,abs(a[i]));
		ans+=abs(a[i]);
	}
	cout<<ans-x%2*2*y<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void){
    char s[4096] = {0};
    int counts[128] = {0};
    int i=0,p;
    while(scanf("%c",&s[i])!=EOF){
        if(s[i]>=65&&s[i]<=90){
            p = s[i]-65;
            counts[p]++;
        }
        else if(s[i]>=97&&s[i]<=122){
            p = s[i]-97;
            counts[p]++;
        }
        i++;
    }
    for(i=0;i<26;i++){
        printf("%c : %d\n",i+97,counts[i]);
    }
    return 0;
  }



Measured memory_bytes: 2040
A, B, K = map(int, input().split())

hako = {}
for i in range(A, A + K):
    if i <= B:
        hako[i] = 0
for j in range(B, B - K, -1):
    if j >= A:
        hako[j] = 0

for k in sorted(hako):
    print(k)


# for i in range(A, B+1):
#     hako.append(i)
# new = []
# new += hako[0:K]
# new += hako[B - K + 1::-1]


Measured memory_bytes: 3060
#include <cstdio>
#include <utility>
#include <queue>
#include <algorithm>
using namespace std;

typedef pair<int,int> pii;

struct mypq: priority_queue<pii>{
	using priority_queue<pii>::c;
};

int main(){
	typedef pair<int,int> pii;
	mypq pq;
	int n, r, l, d, t, x, u = 0;
	scanf("%d%d%d", &n, &r, &l);
	pq.c.reserve(n + r);
	vector<int> s(n + 1), c(n + 1);
	for(int i = 1; i <= n; ++i){
		pq.c.push_back(pii(0, ~i));
	}
	for(int i = 0; ; ++i){
		if(i == r){
			t = l;
		}
		else{
			scanf("%d%d%d", &d, &t, &x);
		}
		while(1){
			const pii &p = pq.c[0];
			if(s[~p.second] == p.first){
				c[~p.second] += t - u;
				break;
			}
			pq.pop();
		}
		if(i == r){
			break;
		}
		s[d] += x;
		pq.push(pii(s[d], ~d));
		u = t;
	}
	int ans = max_element(c.begin(), c.end()) - c.begin();
	printf("%d\n", ans);
}

Measured memory_bytes: 7536
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		int ans = 0;
		while (N) {
			ans += N / 5;
			N /= 5;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3004
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int len_bit = line.length() - 1;
		int con = 0;
		long ans = 0;

		for (int i = 0; i < (1 << len_bit); i++) {
			int[]index = new int[line.length() + 1];
			index[0] = 0;
			con = 1;
			for (int j = 0; j < len_bit; j++) {
				if (((i >> j) & 1) == 1) {
					index[con] = j + 1;
					con++;
				}
			}
			index[con] = line.length();
			for (int j = 0; j < con; j++) {
				ans += Long.parseLong(line.substring(index[j], index[j + 1]));
			}
		}
		System.out.println(ans);

	}




}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<math.h>
#include<string>
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
using namespace std;

int main()
{
	int n;
	int k;
	std::cin >> n;
	std::cin >> k;
	int* arr = new int[n];
	for (int i = 0; i < n; i++)
	{
		std::cin >> arr[i];
	}
	int* dp = new int[n];
	dp[0] = 0;
	dp[1] = abs(arr[1] - arr[0]);
	for (int i = 2; i < n; i++)
	{
		int s = k;
		int mix = INT_MAX;
		s = min(i, s);
		s++;
		while (s--)
		{
			int x = abs(arr[i] - arr[i - s]) + dp[i - s];
			if (mix > x)
			{
				mix = x;
			}
			dp[i] = mix;
		}
	}
	std::cout << dp[n - 1] << endl;
	return 0;
}

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

using namespace std;

const long long MOD = 998244353;

vector<int> tree;

void update(int node, int nl, int nr, int id, int val) {
	if (nl == nr) {
		tree[node] = val;
		return;	
	}
	int mid = nl + nr >> 1;
	if (id <= mid) {
		update(2 * node, nl, mid, id, val);
	} else {
		update(2 * node + 1, mid + 1, nr, id, val);
	}
	tree[node] = max(tree[2 * node], tree[2 * node + 1]);
	return;
}

int query(int node, int nl, int nr, int l, int r) {
	if (nr < l || r < nl) {
		return -1;
	}
	if (l <= nl && nr <= r) {
		return tree[node];
	}
	int mid = nl + nr >> 1;
	return max(query(2 * node, nl, mid, l, r), query(2 * node + 1, mid + 1, nr, l, r));
}

int main() {
	int n;
	cin >> n;
	tree.resize(n << 2);
	vector<pair<int, int>> a(n);
	vector<int> x(n), d(n), to(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i].first >> a[i].second;
	sort(a.begin(), a.end());
	for (int i = 0; i < n; ++i) {
		x[i] = a[i].first;
		d[i] = a[i].second;
	}	
	to[n - 1] = n;
	update(1, 0, n - 1, n - 1, to[n - 1]);
	for (int i = n - 2; ~i; --i) {
		int r = lower_bound(x.begin() + i + 1, x.end(), x[i] + d[i]) - x.begin() - 1;
		if (r < i + 1) {
			to[i] = i + 1;
		} else {
			to[i] = query(1, 0, n - 1, i + 1, r);
		}
		update(1, 0, n - 1, i, to[i]);
	}
	vector<int> dp(n + 1);
	dp[n] = 1;
	for (int i = n - 1; ~i; --i) {
		dp[i] = dp[i + 1] + dp[to[i]];
		if (MOD <= dp[i]) dp[i] -= MOD;		
	}
	cout << dp[0] << '\n';
	return 0;
}

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

int main(){
    int n,t;
    cin >> n;
    int l[n];
    for(int i=0;i<n;i++){
        cin >> t;
        l[n - i - 1] = t;
    }
    for(int i=0;i<n;i++){
        cout << l[i];
        if(i<n-1)cout << " ";
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3064
// TLEします
#include <bits/stdc++.h>
using namespace std;

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL<<(n))
#define sz(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;using vb=vector<bool>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
template <typename T> T read() {T t; cin >> t; return t;}

template<typename T> vector<vector<T> > doubling(vector<T> vec, ll depth) {
  int s = (int) vec.size();
  int vs = 1;
  while ((1LL << vs) <= depth) vs++;
  vector<vector<T> > tbl(vs, vector<T>(s));
  for (int j = 0; j < s; j++) tbl[0][j] = vec[j];
  for (int i = 1; i < vs; i++) {
    for (int j = 0; j < s; j++) {
      tbl[i][j] = tbl[i - 1][tbl[i - 1][j]];
    }
  }
  return tbl;
}

void Main() {
  int n = read<int>();
  vi X(n);
  rep(i, n) X[i] = read<int>();

  int m = read<int>();
  ll K = read<ll>();

  vector<int> A(m);
  rep(i, m) A[i] = read<int>() - 1;

  vl D(n-1);
  rep(i, n-1) D[i] = X[i+1] - X[i];

  vi P(n-1);
  rep(i, n-1) P[i] = i;

  forr(a, A) swap(P[a], P[a-1]);

  vl E(n-1);
  auto table = doubling(P, K);
  rep(i, n-1) {
    int v = i;
    rep(k, sz(table)) {
      if (K & bit(k)) {
        v = table[k][v];
      }
    }
    E[i] = D[v];
  }

  vl ans(n);
  ans[0] = X[0];
  rep(i, n-1) {
    ans[i+1] = ans[i] + E[i];
  }

  rep(i, n) cout << ans[i] << endl;
}
int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 28272
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<lli>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = INF;
  string s, t;
  cin >> n;
  vi x(n);
  rep(i, 0, n)
  {
    cin >> x[i];
  }
  repe(i, 1, 100)
  {
    ans = 0;
    rep(j, 0, n)
    {
      ans += (x[j] - i) * (x[j] - i);
    }
    count = min(count, ans);
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN=200000+5;
int k,n,a[MAXN],ans=1<<30;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin>>k>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=2;i<=n-1;i++)
		ans=min(ans,k-max(abs(a[i]-a[i-1]),abs(a[i+1]-a[i])));
	ans=min(ans,a[n]-a[1]);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <string>
#include <random>
#include <map>
#pragma warning(disable : 4996)



int main(void) {
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	printf("%d", (a*b > c *d) ? a*b : c*d);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define INF ((ll)1<<31)-1
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int gcd(int a,int b){
	if(!a)return b;
	return gcd(b%a,a);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
vector<P> vec;
int n,a,b;
signed main(){
	cin>>n;
	rep(i,n){
		cin>>a>>b;
		vec.push_back({a,1});
		vec.push_back({b+1,-1});
	}
	sort(vec.begin(),vec.end());
	int cnt=1;
	int ans=0;
	for(int i=1;i<vec.size();i++){
		if(vec[i].first!=vec[i-1].first){
			ans=max(ans,cnt);
		}
		cnt+=vec[i].second;
	}
	cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 7020
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << endl;

}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define int long long
#define ll long long
#define moder 1000000007
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
signed main(){
	string s;
	cin>>s;
	int ans=999;
	for(int i=0;i<s.size()-2;i++){
		if(ans>abs(753-stoi(s.substr(i,3))))ans=abs(753-stoi(s.substr(i,3)));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n, MOD = map(int,input().split())
    if n == 1:
        print(1)
        return

    E = [[] for _ in range(n)]
    nv_to_idx = [{} for _ in range(n)]
    for _ in range(n - 1):
        u, v = map(int,input().split())
        u -= 1; v -= 1
        nv_to_idx[u][v] = len(E[u])
        nv_to_idx[v][u] = len(E[v])
        E[u].append(v)
        E[v].append(u)

    # tree DP
    dp = [1] * n
    deg = [len(E[v]) - 1 for v in range(n)]
    deg[0] += 1
    stack = [(0, -1)]
    while stack:
        v, p = stack.pop()
        if v >= 0:
            for nv in E[v]:
                if nv == p:
                    continue
                stack.append((~nv, v))
                stack.append((nv, v))
        else:
            if deg[~v] == 0:
                dp[p] = dp[p] * (dp[~v] + 1) % MOD
            deg[p] -= 1

    # rerooting
    def rerooting(v, p):
        # p-rooted -> dp[p] を v-rooted に modify
        if p != -1:
            idx = nv_to_idx[p][v]
            p_res = 1
            if idx > 0:
                p_res *= cum_left[p][idx - 1]
            if idx < len(E[p]) - 1:
                p_res *= cum_right[p][idx + 1]
            dp[p] = p_res % MOD

        # monoid に対する cumulative sum を計算
        if cum_left[v] is None:
            left = [(dp[nv] + 1) % MOD for nv in E[v]]
            right = [(dp[nv] + 1) % MOD for nv in E[v]]
            k = len(E[v])
            for i in range(k - 1):
                left[i + 1] *= left[i]
                left[i + 1] %= MOD
            for i in range(k - 1, 0, -1):
                right[i - 1] *= right[i]
                right[i - 1] %= MOD
            cum_left[v] = left
            cum_right[v] = right
        dp[v] = cum_left[v][-1]

    ans = [None] * n
    stack = [(0, -1)]
    cum_left = [None] * n
    cum_right = [None] * n
    while stack:
        v, p = stack.pop()
        if v >= 0:
            rerooting(v, p)
            ans[v] = dp[v]
            for nv in E[v]:
                if nv == p:
                    continue
                stack.append((~nv, v))
                stack.append((nv, v))
        else:
            rerooting(p, ~v)

    print(*ans, sep = '\n')
resolve()

Measured memory_bytes: 132400
#include <math.h>
#include <cstdlib>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char* argv[]) {
  int N, M;

  cin >> N >> M;

  if(N == M){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 888
n, k = gets.split.map(&:to_i)
r, s, p = gets.split.map(&:to_i)
t = gets.chomp.split("")

peri = Array.new(k).map{Array.new(0)}
for i in 0..(n-1)
  peri[i%k].push(i)
end

ps = Hash.new(0)
ps["s"] += r
ps["p"] += s
ps["r"] += p

po = 0
for i in 0..(k-1)
  pret = "N"
  peri[i].each do |id|
    if pret != t[id]
      po += ps[t[id]]
      pret = t[id]
    else
      pret = "N"
    end
  end
end
puts po

Measured memory_bytes: 15740
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

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

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int H, W, N;
    cin >> H >> W >> N;
    int sr, sc;
    cin >> sr >> sc;
    string S, T;
    cin >> S >> T;

    vector<int> ud_s(N, 0);
    vector<int> ud_t(N, 0);
    vector<int> lr_s(N, 0);
    vector<int> lr_t(N, 0);

    for (int i = 0; i < N; i++) {
        if (S[i] == 'U') ud_s[i] = -1;
        else if (S[i] == 'D') ud_s[i] = 1;
        else if (S[i] == 'L') lr_s[i] = -1;
        else if (S[i] == 'R') lr_s[i] = 1;

        if (T[i] == 'U') ud_t[i] = -1;
        else if (T[i] == 'D') ud_t[i] = 1;
        else if (T[i] == 'L') lr_t[i] = -1;
        else if (T[i] == 'R') lr_t[i] = 1;
    }

    // 上下ゲーム, 戦略上
    int h = sr;
    for (int i = 0; i < N; i++) {
        h += min(0LL, ud_s[i]);
        if (h <= 0) {
            cout << "NO" << endl;
            return 0;
        }
        h += max(0LL, ud_t[i]);
        h = min(H, h);
    }

    // 上下ゲーム, 戦略下
    h = sr;
    for (int i = 0; i < N; i++) {
        h += max(0LL, ud_s[i]);
        if (h > H) {
            cout << "NO" << endl;
            return 0;
        }
        h += min(0LL, ud_t[i]);
        h = max(1LL, h);
    }

    // 左右ゲーム, 戦略右
    int w = sc;
    for (int i = 0; i < N; i++) {
        w += max(0LL, lr_s[i]);
        if (w > W) {
            cout << "NO" << endl;
            return 0;
        }
        w += min(0LL, lr_t[i]);
        w = max(1LL, w);
    }

    // 左右ゲーム, 戦略左
    w = sc;
    for (int i = 0; i < N; i++) {
        w += min(0LL, lr_s[i]);
        if (w <= 0) {
            cout << "NO" << endl;
            return 0;
        }
        w += max(0LL, lr_t[i]);
        w = min(W, w);
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 7048
#include<iostream>

using namespace std;


int main(){
    long long  N;
    long long sum,answer;
    cin >> N;
    long long  a[N],b[N];
    for(long long i=0;i<N;i++){
        b[i]=0;
    }
    for(long long i=0;i<N;i++){
        cin >> a[i];
        b[a[i]-1]++;
    }
    sum=0;

    for (long long i=0;i<N; i++){
        sum+=b[i]*(b[i]-1)/2;
    }

    for(long long i=0;i<N;i++){
        answer=sum;
        answer-=(b[a[i]-1]-1);
        cout << answer << endl;
    }
    return 0;
}

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

int main(){
  int N,x;
  cin >> N;
  for (int i = 0;i < N ; i++){
    int l , r;
    cin >> l >> r ;
    x+=(r-l+1);
  }
  cout << x << endl;
}

    
    

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    int ma = 0, mi = 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] > a[ma])ma = i;
        if (a[i] < a[mi])mi = i;
    }

    vector<vector<int>> ope;
    if (a[ma] * 2 + a[0] > -(a[mi] * 2 + a[n - 1])) {
        ope.push_back({ma, 0});
        for (int i = 1; i < n; i++) ope.push_back({i - 1, i});
    } else {
        ope.push_back({mi, n - 1});
        for (int i = n - 1; i > 0; i--) ope.push_back({i, i - 1});
    }

    cout << ope.size() * 2 << endl;
    for (auto x:ope) {
        cout << x[0] + 1 << " " << x[1] + 1 << endl;
        cout << x[0] + 1 << " " << x[1] + 1 << endl;
    }
    return 0;
}

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

using namespace std;
#define ll long long
const int N = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if (a <= k) k -= a, ans += a;
    else ans += k, k = 0;
    if (b <= k) k -= b;
    else k = 0;
     if (c <= k) k -= c, ans -= c;
    else ans -= k;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3652
/*Template by hemnath_d(Enlightened by chamow)*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vec vector<ll>
#define pll pair<ll,ll>
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fx first
#define sx second
#define inf 100000000000000
#define minf -100000000000000
#define maxi 100005

int main()
{
    fastread;
    int n;
    cin>>n;
    string s;
    cin>>s;
    map<char, int> col;
    col['R'] = 0;
    col['G'] = 1;
    col['B'] = 2;
    vector<int> suffix[3];
    suffix[0].resize(s.size() + 1, 0);
    suffix[1].resize(s.size() + 1, 0);
    suffix[2].resize(s.size() + 1, 0);
    for(int i = n - 1; i >= 0; i--) {;
    	for(int j = 0; j < 3; j++) {
    		suffix[j][i] = suffix[j][i+1];
    	}
    	suffix[col[s[i]]][i]++;
    }
    long long ans = 0;
    for(int i = 0; i < n; i++) {
    	for(int j = i + 1; j < n; j++) {
    		if(s[i] == s[j])
    			continue;
    		int cval;
    		cval = 0;
    		if(s[i] == 'R' || s[j] == 'R') cval++;
    		if(cval == 1 && (s[i] == 'G' || s[j] == 'G')) cval++;
    		ans += suffix[cval][j];
    		if(j + (j - i) < n) {
    			ans -= (col[s[j + j - i]] == cval);
    		}
    	}
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3672
n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
b = gets.chomp.split(" ").map(&:to_i)
c = gets.chomp.split(" ").map(&:to_i)

sakkitabetano = -2
ans = 0
n.times do |i|
  ans += b[i]
  if sakkitabetano+1 == a[i]-1
    ans += c[a[i]-2]
  end
  sakkitabetano = a[i]-1
end
puts ans

Measured memory_bytes: 3836
import itertools,sys
def S(): return sys.stdin.readline().rstrip()
S = S()
groupby_S = itertools.groupby(S)
ans = 0
rangeN = [i for i in range(len(S)+1)]
rangeN_accumulate = list(itertools.accumulate(rangeN))
group = []
temp = []
for k,g in groupby_S:
    if k=='<':
        temp.append(len(list(g)))
    else:
        temp.append(len(list(g)))
        group.append(temp)
        temp = []
group.append(temp)
for x in group:
    if len(x)==0:
        continue
    elif len(x)==1:
        ans += rangeN_accumulate[x[0]]
    else:
        a,b = max(x),min(x)-1
        ans += rangeN_accumulate[a]
        ans += rangeN_accumulate[b]
print(ans)


Measured memory_bytes: 65548
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n,m;
int x[100001],sx[100001];
int main(){
    cin>>n>>m;
    rep(i,m){
        cin>>x[i];
    }
    if(n>=m){
        cout<<0<<endl;
        return 0;
    }
    sort(x,x+m);
    rep(i,m-1) sx[i]=abs(x[i+1]-x[i]);
    sort(sx,sx+(m-1));
    ll ans=0;
    rep(i,m-n){
        ans+=sx[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
int main( void )
{
	int a = 0;
	for ( int i = 0; i < 4; i++ )
	{
		int p;
		cin >> p;
		a += p;
	}

	int b = 0;
	for ( int i = 0; i < 4; i++ )
	{
		int p;
		cin >> p;
		b += p;
	}

	cout << max( a, b ) << endl;

	return 0;
}

Measured memory_bytes: 0
import sys
for line in sys.stdin:
    n = int(line)
    flag = [True]*(n+1)
    flag[0] = flag[1] = False
    for i in range(2,int(n**0.5)+1):
        if flag[i]:
            for j in range(i**2, n+1, i):
                flag[j] = False
    print(flag.count(True))

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

template <class T, class U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}
 
template <class T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v) {
    os << "[";
	for (int i = 0; i < v.size(); ++i) {
        if (i) {
            if (i % 5 == 0) {
                os << ",\n ";
            } else {
                os << ", ";
            }
        }
		os << v[i];
	}
	os << "]";
	return os;
}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

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

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

    int N;
    cin >> N;
    string S;
    cin >> S;

    int result = 0;
    int L = 0;
    int R = N - 1;
    while (true) {
        while (L < N && S[L] == 'R') {
            ++L;
        }
        while (R >= 0 && S[R] == 'W') {
            --R;
        }
        if (L < N && R >= 0 && L < R) {
            ++result;
            ++L;
            --R;
        } else {
            break;
        }
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 3780
#include<iostream>
#include<vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> h(n);
	for(int i=0;i<n;i++)
		cin >> h[i];
	
	vector<int> dp(n,0);
	dp[1-1]=0;
	dp[2-1]=dp[1-1]+abs(h[2-1]-h[1-1]);

	for(int i=3;i<=n;i++)
	{
		dp[i-1]=min(dp[i-1-1]+abs(h[i-1]-h[i-1-1]),dp[i-2-1]+abs(h[i-1]-h[i-2-1]));
	}

	cout << dp[n-1] << endl;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  rep(i, sz(S)) {
    int alpha = (S[i] - 'A' + N) % 26;
    S[i] = 'A' + alpha;
  }
  cout << S << '\n';
  return 0;
}

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

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) 
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) 
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i)
#define deb(x) cout << #x << "= " << x << endl
#define pb push_back
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define tr(x) for(auto it = x.begin(); x != x.end(); it++)
#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

ll power(int a, ll b){
    ll ans=1;
    for0(i,b){
            ans = ((ans%MOD)*a)%MOD;
        }
  	return ans;
}

int main() {
    fast;
    int t=1;
    while(t--){
        //begin code here
        int n; cin>>n;
        if(n==2){
            cout << 2;
            continue;
        }
        else if(n==1){
            cout << 0;
            continue;
        }
        ll ans=0;
        ans+=power(10,n);
        ans-=2ll*power(9,n);
        ans=ans+MOD+MOD; ans%=MOD;
        ans+=power(8,n);
        ans%=MOD;
        cout << ans;
    }
}

Measured memory_bytes: 3632
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
const int inf=1e9;
const ll INF=1e18;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a[1005]={},ans=1,x,now;
  cin >> n;
  for(int i=2; i<=n; i++) {
    x=i,now=2;
    while(now<=i) {
      while(x%now==0) {
        a[now]++,x/=now;
      }
      now++;
    }
  }
  for(int i=2; i<=n; i++) {
    ans*=a[i]+1;
    ans%=MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.05.26 20:48:23
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    int a, p;
    scanf("%d%d", &a, &p);
    int ret = (a * 3 + p) / 2;
    printf("%d\n", ret);

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 256
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N, K = map(int, input().split())
MOD = 10**9+7
n = min(N,K)
ans = 0
for i in range(max(1,N-n),N+1):
  m = cmb(N,i,MOD)
  m *= cmb(N-1,i-1, MOD)
  ans += m
  ans %= MOD
print(ans)

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n; cin>>n;
  vi x(3);
  rep(i,n){
    int a; cin>>a;
    if(!(a%4))x[0]++;
    else if(!(a%2))x[1]++;
    else x[2]++;
  }
  if(x[1]==0&&(x[2]>x[0]+1)||(x[1]!=0)&&(x[2]>x[0])) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
// Aizu Vol-5 0595: Schedule
// 2017.8.31 bal4u@uu

#include <stdio.h>

#define J 1
#define O 2
#define I 4
#define JOI 7

int p[2][8];
char a[1003];

int main()
{
	int n, i, j, x, x2, k1, k2, ans;

	scanf("%d%s", &n, a + 1);
	for (i = 1; i <= n; i++) {
		if      (a[i] == 'J') a[i] = J;
		else if (a[i] == 'O') a[i] = O;
		else                  a[i] = I;
	}
	if (a[1] == J) p[0][J] = p[0][J|O] = p[0][J|I] = p[0][JOI] = 1;
	else           p[0][J|a[1]] = p[0][JOI] = 1;
	for (k1 = 0, k2 = 1, i = 2; i <= n; i++, k1 = k2, k2 = !k2) {
		for (j = 0; j < 8; j++) p[k2][j] = 0;
		x = a[i], x2 = a[i-1];
		if (x2 == x) {
			int t = p[k1][x|J] + p[k1][x|O] + p[k1][x|I] + p[k1][JOI];
			p[k2][x|J] += t, p[k2][x|O] += t, p[k2][x|I] += t, p[k2][JOI] += t;
		} else {
			int t, x3;
			t = p[k1][x2], p[k2][x|x2] += t, p[k2][JOI] += t;
			t = p[k1][x|x2], p[k2][x|J] += t, p[k2][x|O] += t, p[k2][x|I] += t,	p[k2][JOI] += t;
			t = p[k1][JOI], p[k2][x|J] += t, p[k2][x|O] += t, p[k2][x|I] += t, p[k2][JOI] += t;
			x3 = ((JOI & ~x) & ~x2) & JOI;
			t = p[k1][x2|x3]; p[k2][x|x2] += t, p[k2][x|x3] += t, p[k2][JOI] += t;
		}
		for (j = 0; j < 8; j++) p[k2][j] %= 10007;
	}
	for (ans = 0, j = 0; j < 8; j++) ans += p[k1][j];
	printf("%d\n", ans % 10007);
	return 0;
}

Measured memory_bytes: 596
import numpy as np
def IntLog2(N):
    k = 0
    while N%2 == 0:
        k += 1
        N /= 2
    return k

N = raw_input()
inputArray = map(int, raw_input().split())
Log2_inputArray = [IntLog2(n) for n in inputArray]
print min(Log2_inputArray)

Measured memory_bytes: 17012
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    double N,T,A,H[10000],t[10000],ans=0,m=1e8;
    cin>>N>>T>>A;
    for(int i=1;i<N+1;i++){
        cin>>H[i];
        t[i]=T-0.006*H[i];
        if(fabs(A-t[i])<m){
            ans=i;
            m=fabs(A-t[i]);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    N = N % 1000;
    if (N) cout << 1000 - N << endl;
    else cout << 0 << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
ll a, b, bita[42], bitb[42], pow2[42], A[42], B[42], ans;

int main()
{
	cin >> a >> b;
	ll c = a, d = b;
	ll s = 0, t = 0;
	while (c)
	{
		A[s] = c % 2;
		s++, c /= 2;
	}
	while (d)
	{
		B[t] = d % 2;
		t++, d /= 2;
	}
	pow2[0] = 1;
	for (int i = 1; i <= 41; i++) pow2[i] = pow2[i - 1] * 2;
	for (int i = 0; i <= 40; i++)
	{
		bita[i] += a / pow2[i + 1] * pow2[i + 1] / 2;
		if (A[i] == 1)
		{
			bita[i] += a % pow2[i] + 1;
		}
	}
	for (int i = 0; i <= 40; i++)
	{
		bitb[i] += b / pow2[i + 1] * pow2[i + 1] / 2;
		if (B[i] == 1)
		{
			bitb[i] += b % pow2[i] + 1;
		}
	}
	for (int i = 0; i <= 40; i++)
	{
		ans += pow2[i] * ((bitb[i] - bita[i] + A[i]) % 2);
	}
	cout << ans << endl;
	int www;
	cin >> www;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
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; }

int main()
{
    int N;
    cin >> N;
    int x = 0, y = 0;
    int t_prev = 0;
    rep(i, N)
    {
        int t, p, q;
        cin >> t >> p >> q;
        int n = abs(p-x);
        int m = abs(q-y);
        //if((n+m)==t)
        int d = t-t_prev;
        t_prev = t;
        // if(n==0 && m ==0)
        // {
        //     if(n%2 == 0)
        //     {
        //         x = p; y = q;
        //         continue;
        //     } 
        //     else
        //     {
        //         cout << "No" << endl;
        //         return 0;
        //     }    
           
        // }
        // else
        {
            if(d%(n+m) == 0)
            {
                x = p; y = q;
                continue;
            } 
            else
            {
                cout << "No" << endl;
                return 0;
            }    
        }
        
       
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3624
use proconio::input;
use std::collections::BTreeSet;
use std::ops::Bound::Excluded;
use std::ops::Bound::Unbounded;
use rand::Rng;

const C:usize = 26;
const N_ITER:usize = 2000000;

fn main() {

    input!{
        d:usize,
        c:[i32;C],
        s:[[i32;C];d],
    };
    let mut t:Vec<usize> = (0..d).map(|x|x%C).collect();
    let mut occs = vec![BTreeSet::<i32>::new();C];
    for occ in &mut occs {
        occ.insert(-1);
    }
    let mut ans = 0;
    for (day,&ti) in t.iter().enumerate() {
        ans += s[day][ti];
        occs[ti].insert(day as i32);
        for j in 0..26 {
            let sc = (c[j] as i32) * ((day as i32) -*occs[j].iter().last().unwrap());
            ans -= sc;
        }
    }
    for occ in &mut occs {
        occ.insert(d as i32);
    }    

    let sum_lr = |l,r,n| n*(l+r)/2;
    let mut rng = rand::thread_rng();
    
    for _ in 0..N_ITER {
        let d = rng.gen::<usize>()%d;
        let q = rng.gen::<usize>()%C;
        let pre_q = t[d];
        let pre_ans = ans;
        let mut try_change = |d:usize,q:usize|{
            let pre_q = t[d];
            ans-=s[d][pre_q];
            ans+=s[d][q];
            t[d]=q;
            let d = d as i32;
            // for pre_q
            let mut calc = |q:usize,is_ins:bool| {
                if is_ins {
                    occs[q].insert(d);
                }
                else {
                    occs[q].remove(&d);
                }
                let pre_d = *occs[q].range((Unbounded,Excluded(&d))).last().unwrap();
                let nex_d = *occs[q].range((Excluded(&d),Unbounded)).next().unwrap();
                let lbig = d - pre_d;
                let rbig = nex_d - pre_d -1;
                let lsml = 0;
                let rsml = nex_d-d-1;
                let sc = sum_lr(lbig,rbig,nex_d-d)-sum_lr(lsml,rsml,nex_d-d);
                sc
            };
            
            ans -= calc(pre_q,false)*c[pre_q];
            ans += calc(q,true)*c[q];
            ans
        };
        let now_ans = try_change(d,q);
        if now_ans<pre_ans {
            try_change(d,pre_q);
        }
    }

    for tv in t {
        println!("{}",tv+1);
    }
    
    
}




Measured memory_bytes: 2736
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll h,w;
char s[400][400];
bool used[400][400];
ll dcnt = 0;
ll dx[] = {1,0,-1,0}, dy[] = {0, 1, 0 ,-1};
ll dfs(ll x, ll y){
  if(used[x][y]) return 0;
  ll ret = 0;
  used[x][y] = true;
  if(s[x][y] == '.') ret++;
  else dcnt++;
  for(ll i=0;i<4;i++){
    if(x+dx[i] < 0 || y+dy[i] < 0 || x+dx[i] >=h || y+dy[i] >= w) continue;
    if(s[x+dx[i]][y+dy[i]] != s[x][y])
      ret += dfs(x+dx[i], y+dy[i]);
  }
  return ret;
}

int main(){
  cin >> h >> w;
  
  for(ll x=0;x<h;x++){
    for(ll y=0;y<w;y++){
      cin >> s[x][y];
      used[x][y] = false;
    }
  }
  ll ans = 0;
  for(ll x=0;x<h;x++){
    for(ll y=0;y<w;y++){
      if(s[x][y] == '#'){
        // cout << "x: " << x << " y: " << y << " start" << endl;
        dcnt = 0;
        ll tmp = dfs(x,y);
        ans += tmp*dcnt;
      }
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 8064
a,b = map(int,input().split())

if a % 2 == 0:
    if (b-a+1)%2 == 0:
        if (b-a+1)%4 == 2:
            print(1)
        else:
            print(0)
    else:
        if (b-a+1)%4 == 1:
            print(0^b)
        else:
            print(1^b)
else:
    if (b-a)%2 == 0:
        if (b-a)%4 == 2:
            print(a^1)
        else:
            print(a^0)
    else:
        if (b-a)%4 == 1:
            print(a^0^b)
        else:
            print(a^1^b)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, a, b;
vector <int> ans;

void solve(int l, int r, vector <int> c){
    if(r - l == 1) return;
    int mid = (l + r) / 2;
    int f = 0;
    for(auto &i : c){
        if(((ans[l] >> i) ^ (ans[r] >> i)) & 1){
            f = i;
            break;
        }
    }
    c.erase(find(c.begin(), c.end(), f));
    for(int i = l ; i <= r ; i++){
        if(i <= mid) ans[i] |= (((ans[l] >> f) & 1) << f);
        else ans[i] |= (((ans[r] >> f) & 1) << f);
    }
    bool b = 0;
    for(auto &i : c){
        if(b == 0){
            ans[mid] |= ((((ans[l] >> i) & 1) ^ 1) << i);
            ans[mid + 1] |= ((((ans[l] >> i) & 1) ^ 1) << i);
            b = 1;
        }
        else{
            ans[mid] |= (((ans[l] >> i) & 1) << i);
            ans[mid + 1] |= (((ans[l] >> i) & 1) << i);
        }
    }
    solve(l, mid, c);
    solve(mid + 1, r, c);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> a >> b;
    if(__builtin_popcount(a ^ b) % 2 == 0) finish("NO");
    ans.resize(1 << n);
    ans[0] = a;
    ans[(1 << n) - 1] = b;
    vector <int> all;
    for(int i = 0 ; i < n ; i++){
        all.push_back(i);
    }
    solve(0, (1 << n) - 1, all);
    cout << "YES" << endl;
    for(auto &i : ans) cout << i << " ";
    cout << endl;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
typedef long long int ll;
int main(){
  ll n;
  while( cin >> n,n ){
    ll ma[4001] = {0};
    vector<ll>ve;
    ve.clear();
    for(ll k = 0 ; k < n ; k++ ){
      ll a,b,c;
      cin >> a >> b >> c;
      if(ma[a] == 0)ve.push_back(a);
      ma[a] += b*c;
    }
    int f = 1;
    for(vector<ll>::iterator it = ve.begin() ; it != ve.end() ; it++ ){
      if(ma[(*it)] >= 1000000 ){
	cout << (*it) << endl;
	f = 0;
      }
    }
    if(f)cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

int main() {
    FAST_IO();
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));
    if(N % 3 == 0) {
        // N이 3의 배수이면 ai, ai+1, ai+2 가 다를 수 있음
        int M = N / 3, a[3] = {0};
        rep(i, 3) {
            a[i] = A[i * M];
            rep(j, M) {
                if(A[i * M + j] != a[i]) {
                    cout << "No\n";
                    return 0;
                }
            }
        }
        if((a[0] ^ a[1]) == a[2]) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    } else {
        // N이 3의 배수가 아니면 모든 ai가 같음
        rep(i, N) if(A[i] != A[(i + 1) % N]) {
            cout << "No\n";
            return 0;
        }
        cout << "Yes\n";
    }
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void){
	char number[1001];
	char *np;
	int i,sum;
	np = number;

	while(1){
		scanf("%s", number);
		if(number[0] == '0'){
			return 0;
		}

		sum = 0;

		for(i = 0; *(np+i) != '\0';i++){
			sum += *(np+i) - '0';
		}
		printf("%d\n", sum);
	}

	return 0;
}

Measured memory_bytes: 536