akhauriyash/Code-Regression huggingface dataset:
n = gets.to_i

edges = []
g = Array.new(n){ [] }
(n-1).times do |i|
  e = gets.split.map(&:to_i).map{|k|k-=1}
  e[1], e[0] = e[0], e[1] if e[0] > e[1] # 辺は頂点 i < j の形で入れる。
  g[e[0]] << e[1] # 隣接リストに
  g[e[1]] << e[0] # 反対向きにも隣接リストに.無向グラフなので
  edges << e # 辺リストにいれる。辺が識別されてて、最後に辺リストから辺を回して色をとりだす。
end

colors = Hash.new() # Esge => color # 辺についてO(1)で使った色を見れる。O(1)はホントに?
colors_used = Array.new(n){Hash.new} # 頂点と色についてO(1)で使ったか確かめられる。
# used = Array.new(n){false} # 頂点について探索済みかどうかO(1)でわかる。
que = [0] # 頂点0から見ていくので0が入っている # 探索待ちの未探索の頂点リスト

k = 0 # 答えとなる色の数
while !que.empty? do
  v = que.shift # queにある頂点を取り出す. 破壊的メソッドなので先頭は削除される。
  cur = 1 # 使ってない色がわからないので、とりあず色1から見ていく。
  g[v].each do |w| # vの隣接頂点wを見ていく。
    k = g[v].size if k < g[v].size  # 隣接する頂点数より色数が小さければ色数を更新
    v<w ? (i,j = v,w) : (i,j = w,v) # i < jの並びで頂点を捉える。
    next if colors[[i,j]] != nil # nilでなければi-jの辺に色がついてて頂点jは探索済みで,次に。
    cur += 1 while colors_used[v][cur] == true # v周りの頂点で色をつかっていれば次の色に更新していく。塗る前に使ってない色にする。
    colors_used[v][cur] = true # vに色を使ったので記録する。
    colors_used[w][cur] = true # wに色を使ったので記録する。
    colors[[i,j]] = cur # 辺に使った色をいれる。
    que.push(w) #探索待ちの未探索頂点リストに頂点wを入れる。
  end
  # used[v] = true # 頂点vを探索済みにする。
end

puts k
edges.each{ |e| puts colors[e] }

Measured memory_bytes: 60540
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<numeric>

using namespace std;

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

	vector<int> a(n);

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	vector<double> num(n);

	for (int i = 0; i < n; i++)
	{
		num[i] = 1.0 / a[i];
	}

	double sum = accumulate(num.begin(), num.end(), 0.0);

	cout << 1.0 / sum << endl;

}

Measured memory_bytes: 256
H,W,h,w=map(int,input().split())
if W%w!=0:
    print("Yes")
    s=[0 for i in range(W+1)]
    s[W%w]=1+W//w
    for i in range(w,W+1):
        s[i]=s[i-w]-1
    a=[s[i]-s[i-1] for i in range(1,W+1)]
    ans=[[str(a[i]) for i in range(W)] for j in range(H)]
    for line in ans:
        print(" ".join(line))
elif H%h!=0:
    print("Yes")
    s=[0 for i in range(H+1)]
    s[H%h]=1+H//h
    for i in range(h,H+1):
        s[i]=s[i-h]-1
    a=[s[i]-s[i-1] for i in range(1,H+1)]
    ans=[[str(a[i]) for j in range(W)] for i in range(H)]
    for line in ans:
        print(" ".join(line))
else:
    print("No")

Measured memory_bytes: 20084
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18

 
using namespace std;
 
int max(int a, int b)
{
    if(a>b) return a;
    else return b;
}
 
int min(int a,int b)
{
    if(a<b) return a;
    else return b;
}
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a;
}


Measured memory_bytes: 3636
/**
 * author: said_v15
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <__msvc_all_public_headers.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
 
typedef long long  ll;

#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define fore(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define th third
#define ld long double
#define kek cout<<"\n"; 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end()) 
#define halt {cout<<"NO"; return 0;}


const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int MAXN = 1000100;
const int INF = 1e8;
const ll LL_INF=1e18;
const double pi=3.1415926535;
using namespace std;
int divide(int a, int b)
{
          return (a+b-1)/b;
}

int main()
{
    #if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";
 int questions=1;
// cin>>questions;
 while(questions--)
 {
  int n;
  cin>>n;
  vector<pair<ll,ll>> v(n);
  forn cin>>v[i].f>>v[i].sc;
  ll ans=-1e18;
  ll mx1=-1e18, mx2=-1e18, mx3=-1e18, mx4=-1e18;
  forn 
  {
            mx1=max(mx1,v[i].f+v[i].sc);
            mx2=max(mx2, -v[i].f+v[i].sc);
            mx3=max(mx3,-v[i].sc+v[i].f);
            mx4=max(mx4, -v[i].f-v[i].sc);
  }
  forn 
  {
            ll x=v[i].f;
            ll y=v[i].sc;
            ll dist=x+y+mx4;
            ans=max(ans, dist);
            dist=x-y+mx2;
            ans=max(ans, dist);
            dist=-x-y+mx1;
            ans=max(ans, dist);
            dist=y-x+mx3;
            ans=max(ans, dist);
  }
    cout<<ans;
       
 }
 
 
 // !!! LOOK AT NUMBER OF QUESTIONS IN A PROBLEM !!! (cin>>questions)
 

  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
}

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

using namespace std;

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    int A[N+1], B[N];
    rep(i,N+1)cin>>A[i];
    rep(i,N)cin>>B[i];
    ll ans;
    rep(i,N){
        int left = min(A[i],B[i]);
        ans += left;
        A[i] -= left;
        B[i] -= left;

        int right = min(A[i+1],B[i]);
        ans += right;
        A[i+1] -= right;
        B[i] -= right;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int M=1e7+10,N=5e3+10,mod=1e9+7;
ll fac[M],fm[M];
ll power(ll n,ll k){
    if (k==0) return 1;
    if (k%2==1){
        ll x=power(n,k/2);
        return x*x%mod*n%mod;
    }
    ll x=power(n,k/2);
    return x*x%mod;
}
ll ent(ll k,ll n){
    if (k<0 || k>n || n<0) return 0;
    if (k==0 || k==n) return 1;
    return (fac[n]*fm[k])%mod*fm[n-k]%mod;
}
ll sol(ll x,ll y){
    ll ans=fac[x+y-1]*x%mod;
    return ans;
}
ll solve(ll a,ll b,ll c){
    ll p1=a+b+1;
    ll ans=sol(a,b)%mod;
    for (int i=1;i<=c;i++){
        ans*=p1;
        ans%=mod;
        p1++;
    }
    p1=-1;
    for (int i=1;i<=a;i++){
        ans+=p1*ent(i,a)*sol(a-i,b)%mod*fac[a-i+b+c]%mod*fm[a-i+b]%mod;
        ans+=mod;
        ans%=mod;
        p1*=-1;
    }
    return ans;
}
int32_t main(){
    fac[0]=1;
    fm[1]=1;
    for (int i=1;i<M;i++) fac[i]=fac[i-1]*i%mod;
    for (int i=0;i<M;i++) fm[i]=power(fac[i],mod-2);
    ll n,a;
    cin >> n >> a;
    ll ans=0;
    for (int i=1;i<=a;i++){
        ll z=ans;
        if (i!=a){
            ans+=solve(i,n-a,a-i-1);
        }
        else
            ans+=solve(i,n-a,a-i);
        ans%=mod;
     //    cout << ans-z << " " << cheker(i+1) << endl;

    }
    cout << ans << endl;

}


Measured memory_bytes: 159904
#include "bits/stdc++.h"
using namespace std;
int main(){
  string S;
  cin >> S;
  for (int i=0; i<3; i++){
    if (S.at(i) == '1'){
      cout << '9';
    }
    else{
      cout << '1';
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int m = 0;
	int f = 0;
	int r = 0;
	while (1)
	{
		cin >> m >> f >> r;
		int a = 0;
		a = m + f;
		if (m == -1 && f == -1 && r == -1)break;

		if (m == -1){ cout << "F" << "\n"; }
		else if (f == -1){ cout << "F" << "\n"; }
		else if (80 <= a){ cout << "A" << "\n"; }
		else if (65 <= a&&a < 80){ cout << "B" << "\n"; }
		else if (50 <= a&&a < 65){ cout << "C" << "\n"; }
		else if (30 <= a&&a < 50 && 50 <= r){ cout << "C" << "\n"; }
		else if (30 <= a&&a < 50){ cout << "D" << "\n"; }
		else if (a < 30){ cout << "F" << "\n"; }
	}

	return 0;
}

Measured memory_bytes: 2964
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	int[2] x;
	while (x = readln.split.map!(to!int).array, x[0]) {
		auto n = x[0];
		auto m = x[1] - 1;
		int i;
		auto keys = n.iota.array;
		while (keys.length > 1) {
			i += m;
			if (i >= keys.length) i %= keys.length;
			keys = keys.remove(i);
		}
		(keys[0]+1).writeln;
	}
}

Measured memory_bytes: 1076
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    LL H; cin >> H;
    LL ans = 0, base = 1;
    while(H){
        ans += base;
        base *= 2;
        H /= 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/nikkei2019-2-qual/tasks/nikkei2019_2_qual_c

class UnionFind:
    def __init__(self, size):
        self.data = [-1] * size
    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]
    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)
    def same(self, x, y):
        return (self.find(x) == self.find(y))
    def size(self, x):
        return -self.data[self.find(x)]

N, *AB = map(int, open(0).read().split())
A, B = AB[:N], AB[N:]

AI = sorted((a, i) for i, (b, a) in enumerate(sorted(zip(B, A))))

A.sort()
B.sort()

if any(a > b for a, b in zip(A, B)):
    print("No")
    quit()

uf = UnionFind(N)
for j, (a, i) in enumerate(AI):
    uf.union(i, j)

if uf.size(0) != N or any(a <= b for a, b in zip(A[1:], B)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 30860
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
using P = pair<int, int>;
const ll inf =1e9;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

vector<int> warshall_floyd(vector<vector<int>> c){
    for(int k=0; k<c.size(); k++){
        for(int i=0; i<c.size(); i++){
            for(int j=0; j<c.size(); j++){
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    vector<int> to_one(c.size());
    for(int i=0; i<c.size(); i++){
        to_one[i] = c[i][1];
    }
    return to_one;
}

// ワ―シャルフロイド法
int main(){
    int h, w; cin >> h >> w;
    vector<vector<int>> c(10);
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            int tmp; cin >> tmp;
            c[i].emplace_back(tmp);
        }
    }
    vector<vector<int>> a(h);
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            int tmp; cin >> tmp;
            a[i].emplace_back(tmp);
        }
    }
    int ans = 0;
    vector<int> to_one = warshall_floyd(c);
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(a[i][j] != -1){
                ans += to_one[a[i][j]];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
from sys import stdin

N, K = stdin.readline().rstrip().split()
N = int(N)
K = int(K)

keta = 1
#num = 0
K_ = K
while 1:
	if N < K:
		break
		
	else:
#		num += 1
		keta += 1
#		print(num)
		K *= K_
#		print('keta ... ' + str(keta))
#		print('K    ... ' + str(K))
	
print(keta)

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

int main()
{
    string str;
    cin>>str;
    
   int cnt=0;

    for(int i=0;i<str.length();i++)
    {
        if(str[i]=='+')
            cnt++;
        else
            cnt--;
    }

    cout<<cnt<<endl;

    return 0;
}




Measured memory_bytes: 256
def main():
    s = input()
    al = list("abcdefghijklmnopqrstuvwxyz")
    d = set(s)
    n = len(s)
    if list(s) == al[::-1]:
        print(-1)
        return 0
    if n == 26:
        for i in (range(n-1))[::-1]:
            if s[i] < s[i+1]:
                for j in range(i+1,n)[::-1]:
                    if s[i] < s[j]:
                        print(s[:i]+s[j])
                        return 0
    else:
        for i in al:
            if i not in d:
                print(''.join(s)+i)
                return 0

if __name__ == '__main__':
    main()


Measured memory_bytes: 39984
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    string s;
    int n;
    cin >> n >> s;
    int rw = 0, re = 0, e = 0, w = 0;
    REP(i, n) {
    	if(s[i] == 'W') ++rw;
    	else ++re;
    }
    int ans = INF;
    REP(i, n) {
    	if(s[i] == 'W') {
    		--rw;
    		ans = min(ans, w+re);
    		++w;
    	} else {
    		--re;
    		ans = min(ans, w+re);
    		++e;
    	}
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 720
import math
n, p = map(int, input().split())
a = list(map(int, input().split()))
def combi(x, y):
    if y == 0:
        return 1
    if x == 0:
        return 0
    return math.factorial(x) / (math.factorial(x - y) * math.factorial(y))
odd_count = 0
even_count = 0
for i in range(n):
    if a[i] % 2 == 0:
        even_count += 1
    else:
        odd_count += 1
ans = 0
if p % 2 == 0:
    ans += pow(2,even_count)
    tmp = 0
    for i in range(0,odd_count+1,2):
        tmp += combi(odd_count,i)
    ans *= tmp
else:
    ans += pow(2,even_count)
    tmp = 0
    for i in range(1,odd_count+1,2):
        tmp += combi(odd_count,i)
    ans *= tmp
print(int(ans))


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

ll solve(ll n){
    ll ret=0;

    if(n <= 0) return 0;

    //数列{0,1...B-1,B}のXORの累計和は
    //Bi,1,Bi+1,0 ... の繰り返しになる
    int m = n % 4;
    switch(m){
        case 0:
            ret = n;
            break;
        case 1:
            ret = 1;
            break;
        case 2:
            ret = n+1;
            break;
        case 3:
            ret = 0;
            break;
    }

    return ret;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    ll a,b;
    cin>>a>>b;

    //数列{0,1...B-1,B}のXORの和は
    //Bi,1,Bi+1,0 ... の繰り返しになる
    //ll ans = (xorsumA ^ xorsumB) ^ a;
    ll ans;
    ans = solve(a-1) ^ solve(b);
    
    cout << ans << endl;
    return 0;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int x, y, a, b, c; cin >> x >> y >> a >> b >> c;

  vector<P> v;
  rep(i, a) {
    int z; cin >> z;
    v.push_back(make_pair(z, 0));
  }
  rep(i, b) {
    int z; cin >> z;
    v.push_back(make_pair(z, 1));
  }
  rep(i, c) {
    int z; cin >> z;
    v.push_back(make_pair(z, 2));
  }
  sort(v.begin(), v.end(), greater<P>());
 
  int a_cnt = 0, b_cnt = 0;

  ll ans = 0;
  int j = 0;
  for(int i = 0; j < x+y; ++i) {
     if(v[i].second == 0) {
      if(a_cnt < x) {
	ans += v[i].first;
	++a_cnt;
	++j;
      }
    } else if(v[i].second == 1) {
      if(b_cnt < y) {
	ans += v[i].first;
	++b_cnt;
	++j;
      }
    } else {
      ans += v[i].first;
      ++j;
    }
  }
  cout << ans << endl;
}


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

int main()
{int n, k, i, j, op=INT_MAX;
 cin>>n>>k;
 int h[n+1]={0};

 for(i=1 ; i<=n ; i++)
   cin>>h[i];

 int dp[n+1]={0};
 dp[2]=abs(h[2]-h[1]);
 for(i=3 ; i<=n ; i++)
 {
   dp[i]=abs(h[i]-h[i-1])+dp[i-1];
   for(j=2 ; j<=k && j<i ; j++)
   {
     int op=abs(h[i]-h[i-j])+dp[i-j];
     dp[i]=min(dp[i], op);
   }
 }
 cout<<dp[n];

 return 0;
}

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

int i,j,k,m;
main()
{
    int c=0;
    int k,s;cin>>k>>s;
    for(i=0;i<=k;i++)
    {
        for(j=0;j<=k;j++)
        {
            int f=i+j;
            if((s-f)>=0&&(s-f)<=k) c++;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3644
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main(){
	while(1){
		int n, m;
		
		scanf(" %d %d", &n, &m);
		if(n==0) break;
		
		vector< pair<long, pair<int, int> > > d(m);
		
		for(int i=0; i<m; ++i){
			//pairをつかいたい
			scanf(" %ld %d %d", &d[i].first, &d[i].second.first, &d[i].second.second);
		}
		//pairのソート
		sort(d.begin(), d.end());
		
		bool infected[20001];
		for(int i=0; i<=n; ++i) infected[i]=false;
		infected[1]=true;
		
		for(int i=0; i<m; ++i){
			if(infected[ d[i].second.first ])
				infected[ d[i].second.second ]=true;			
		}
		
		int ans=0;
		for(int i=1; i<=n; ++i){
			if(infected[i]) ans++;
		}
		 
		printf("%d\n", ans); 
	}
}

Measured memory_bytes: 1520
n, m, x = map(int, input().split())
lst = list(map(int, input().split()))

g1, g2 = 0, 0
for i in range(x):
  if i in lst:
    g1 += 1
    
for i in range(x+1, n):
  if i in lst:
    g2 += 1
    
print(min(g1, g2))
  

Measured memory_bytes: 61944
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793


int main(){
    int r; cin >> r;
    cout << (double)r*PI*2 << endl;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define RANGE(i,n) for(int i=0;i<n;i++)
typedef long long ll;
struct P{
    ll var1;
    ll var2;
};
bool operator< ( const P &one, const P &two){
    return one.var1 < two.var1;
};
bool operator> ( const P &one, const P &two){
    return one.var1 > two.var1;
};

using namespace std;

signed main() {
    int H,W;
    cin >> H >> W;
    vector<vector<int>> map(H, vector<int>(W,1));
    vector<vector<int>> l2r(H, vector<int>(W,0));
    vector<vector<int>> r2l(H, vector<int>(W,0));
    vector<vector<int>> t2b(H, vector<int>(W,0));
    vector<vector<int>> b2t(H, vector<int>(W,0));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            char mark;
            cin >> mark;
            if(mark == '#') map[i][j] = 0;
        }
    }

    for(int i=0; i<H; i++){
        int increment = 0;
        for(int j=0; j<W; j++){
            l2r[i][j] = increment++;
            if(map[i][j] == 0) increment = 0;
        }
    }
    for(int i=0; i<H; i++){
        int increment = 0;
        for(int j=W-1; j>=0; j--){
            r2l[i][j] = increment++;
            if(map[i][j] == 0) increment = 0;
        }
    }
    for(int j=0; j<W; j++){
        int increment = 0;
        for(int i=0; i<H; i++){
            t2b[i][j] = increment++;
            if(map[i][j] == 0) increment = 0;
        }
    }
    for(int j=0; j<W; j++){
        int increment = 0;
        for(int i=H-1; i>=0; i--){
            b2t[i][j] = increment++;
            if(map[i][j] == 0) increment = 0;
        }
    }

    int result = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            result = max(result, map[i][j] * (l2r[i][j] + r2l[i][j] + t2b[i][j] + b2t[i][j]) + map[i][j]);
        }
    }
    cout << result << endl;
}


Measured memory_bytes: 80768
import sys
# def input():
#     return sys.stdin.readline()[:-1]

# n = int(input())
# A = [input() for i in range(n)]

class Node():
    __slots__ = ['key', 'left', 'right','parent']
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None
        self.parent = None


def insert(key):
    global root
    x = root # x is current node
    y = None  #  parent of x 
    while x:
        y = x # set parent
        if key < x.key:
            x = x.left # move to left child
        else:
            x = x.right #move to right child
    
    if root is None:
        root = Node(key)
    elif key < y.key: # set z as left child of y
        y.left = Node(key)
        y.left.parent = y
    else: 
        y.right = Node(key) # set z as right child of y
        y.right.parent = y
        
def find(key):
    global root
    x = root
    while x:
        if key==x.key:
            print('yes')
            return
        elif key < x.key:
            x = x.left
        else:
            x = x.right
    print('no')
    
    
def minimum(x):
    while x.left:
        x = x.left
    return x
    
    
def successor(x):
    if x.right:
        return minimum(x.right)
    y = x.parent
    while (y) and (x==y.right):
        x = y
        y = y.parent
    return y
    
    
    
def delete(key):
    global root
    
    # find z
    z = None
    x = root
    while x:
        if key==x.key:
            z = x
            break
        elif key < x.key:
            x = x.left
        else:
            x = x.right
    if z is None:
        return
    
    # determin y
    if (z.left==None) or (z.right==None):
        y = z
    else:
        y = successor(z)
        
    if y.left:
        x = y.left
    else:
        x = y.right
        
    if x:
        x.parent = y.parent
    
    if y.parent is None:
        root = x
    elif y==y.parent.left:
        y.parent.left = x
    else:
        y.parent.right = x
        
    if y!=z:
        z.key = y.key
    

def inorder(inorder_list, node):
    if node.left is not None:
        inorder(inorder_list, node.left)
    inorder_list.append(str(node.key))
    if node.right is not None:
        inorder(inorder_list, node.right)
    return inorder_list
        
def preorder(preorder_list, node):
    preorder_list.append(str(node.key))
    if node.left is not None:
        preorder(preorder_list, node.left)
    if node.right is not None:
        preorder(preorder_list, node.right)
    return preorder_list
        
root = None

input()
for o in sys.stdin:
    if o[0]=='i':
        insert(int(o[7:]))
    elif o[0]=='f':
        find(int(o[5:]))
    elif o[0]=='d':
        delete(int(o[7:]))
    else:
        x = root
        inorder_list = inorder([], x)
        print(' '+' '.join(inorder_list))
        preorder_list = preorder([], x)
        print(' '+' '.join(preorder_list))


Measured memory_bytes: 110840
N = int(input())
c = input()

cR = c.count('R')
cW = c.count('W')


if all([i == 'R' for i in c[:cR]]):
    print(0)
    exit()

if all([i == 'W' for i in c[cR:cR+cW]]):
    print(0)
    exit()

ans = c[:cR].count('W')

print(ans)


Measured memory_bytes: 11160
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef unsigned long long LL;

LL sum_digit(string x){
	LL ans = 0;
	
	while(x.size()){
		ans = ans + (x[x.size() - 1] - '0');
		x.pop_back();
	}
	return ans;
}

int main(){
	string n;
	cin >> n;
	
	LL ans = sum_digit(n);
	
	if (ans % 9 == 0)  cout << "Yes" << endl;
	else       cout << "No" << endl;
	
	return 0;
	} 

Measured memory_bytes: 3908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(void){
	int n,d; cin>>n>>d;
	if(n%(d*2+1)==0){
		cout<<n/(d*2+1)<<endl;
	}else{
		cout<<n/(d*2+1)+1<<endl;
	}
	
}


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

int main() {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int ans = 1<<30;
	for (int i = 0; i <= max(2*x,2*y) ; i+=2)
	{
		int la = max(0, x - i / 2);
		int lb = max(0, y - i / 2);
		ans = min(ans, la * a + lb * b + i * c);
	}
	cout << ans << endl;

}

Measured memory_bytes: 3624
class TriangleChecker
  def initialize
    @triangles = []
  end

  # add Triangle Data
  def add(triangle)
    @triangles << triangle
  end

  # check added Triangle
  def check

    @triangles.each {|triangle|

      # sort Triangle Data
      triangle.Line.sort!

      puts ((triangle.Line[0] ** 2) + (triangle.Line[1] ** 2) == (triangle.Line[2] ** 2)) ? "YES" : "NO"
    }
  end
end

# Rectangle Data Class
class Triangle
  attr_accessor :Line
end


inputs = gets.chomp.split(nil)
dataCount = inputs[0].to_i
checker = TriangleChecker.new

dataCount.times {|i|
  inputs = gets.chomp.split(nil)
  line = inputs.map(&:to_i)

  triangle = Triangle.new
  triangle.Line = line

  checker.add(triangle)
}

checker.check

Measured memory_bytes: 6120
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>

using namespace std;
int h,l;
int dp[101][101];
char g[101][101];
int ans;
int dx[5]={0,1,0,-1};
int dy[5]={1,0,-1,0};
void dfs(int x,int y,char c)
{
      g[x][y]=0;
    for(int i=0;i<4;i++)
    {
        int nx=x+dx[i];
        int ny=y+dy[i];

//      if(nx<0|nx>h||ny<0||ny>l||g[nx][ny]!=c)
//      {
//
//          continue;
//      }
//      else
//      {
//          g[nx][ny]=0;
//          dfs(nx,ny,c);
//      }
    if(nx>=0&&nx<h&&ny>=0&&ny<l&&g[nx][ny]==c)
           dfs(nx,ny,c);

    }
}
int main()
{
    while(scanf("%d%d",&h,&l))
    {
        ans=0;
        memset(dp,0,sizeof(dp));
        if(h==0&&l==0)  break;
        for(int i=0;i<h;i++)
           // for(int j=0;j<l;j++)
               scanf("%s",g[i]);
        for(int i=0;i<h;i++)
        for(int j=0;j<l;j++)
        {
            if(g[i][j]!=0)
            {
                ans++;
                dfs(i,j,g[i][j]);
            }
        }
        cout<<ans<<endl;
    }

}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
using namespace         std;
#define                 int long long
#define                 double long double
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<'\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 2014159
#define  vi vector<int>
#define  v  vector
#define die exit(0)
#define alln(arr) arr+1 , arr+1+n
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update> oset; 

inline int mul(int a,int b){return (a*1ll*b)%MOD;}
inline int add(int a,int b){a+=b;if(a>=MOD)a-=MOD;return a;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,MOD-2);}


int fac[N];
int invfac[N];
void pre()
{
    fac[0] = 1;
	invfac[0] = inv(1);
	forn(i,1,N-10)
	{
		fac[i] = fac[i-1]*i;
		fac[i]%=MOD;
		invfac[i] = inv(fac[i]);

	}
}
int ncr(int n,int r)
{
    if(r>n)return 0;
    return mul(fac[n],mul(invfac[r],invfac[n-r]));
}



int n,m,k,arr[N];



void solve()
{
	int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans = 0;
    forn(i,a,c)
    {
    	int x = ncr(i+d+1,i+1)-ncr(i+b,i+1);
    	x+=MOD;
    	x%=MOD;
    	ans=add(ans,x);
    }
    cout<<ans;

}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    pre();
    forn(i,1,t)
    {
        solve();
        nl;
    }



    return 0;

}

//       clang++ c.cpp ; ./a.out < a.txt ;  

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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i < (n); i++)
#define CIN(A) int A; cin >> A;
#define CIN2(A, B) int A, B; cin >> A >> B;
#define CIN3(A, B, C) int A, B, C; cin >> A >> B >> C;
#define CINVEC(A, N) vector<int> A; REP(i, N) { int a; cin >> a; A.emplace_back(a); }
#define ANS(ans) cout << (ans) << endl
#define rsort(p, q) sort(p, q, greater<int>());

#define DEBUGV(V) REP(i, V.size()) cout << V.at(i) << " "; cout << endl 

int
main()
{
  CIN2(H, W);
  vector<vector <int>> yoko(H, vector<int>(W));
  vector<vector <int>> tate(W, vector<int>(H));
  REP(i, H) {
    string s; cin >> s;
    REP(j, W) {
      int num = 0;
      if (s.at(j) == '.') num = 1;
      yoko.at(i).at(j) = num;
      tate.at(j).at(i) = num;
    }
  }

  REP(i, H) {
    int num = 0;
    REP(j, W) {
      if (yoko.at(i).at(j) == 1) ++num;

      if ((0 < j && yoko.at(i).at(j) == 0) || j == W - 1) {
	int end = j - 1;
	if (yoko.at(i).at(j) == 1) end++;
	for (int k = end - num + 1; k <= end; k++) {
	  yoko.at(i).at(k) = num;
	}
	num = 0;
      }
    }
  }

  REP(i, W) {
    int num = 0;
    REP(j, H) {
      if (tate.at(i).at(j) == 1) ++num;

      if ((0 < j && tate.at(i).at(j) == 0) || j == H - 1) {
	int end = j - 1;
	if (tate.at(i).at(j) == 1) end++;
	for (int k = end - num + 1; k <= end; k++) {
	  tate.at(i).at(k) = num;
	}
	num = 0;
      }
    }
  }

  int max = 0;
  REP(i, H) {
    REP(j, W) {
      yoko.at(i).at(j) += tate.at(j).at(i);
      if (max < yoko.at(i).at(j)) max = yoko.at(i).at(j);
    }
  }

  ANS(max - 1);

  return 0;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N;
string s;
const int MN = 6010;
int a[MN],b[MN];
int id[MN];
string dp[MN];
int main(){
	cin>>N>>s;
	int A=0,B=0;
	rep(i,N*2){
		if(s[i]=='a'){
			a[A] = i;
			id[i] = A;
			A++;
		}else{
			b[B] = i;
			id[i] = B;
			B++;
		}
	}
	string ans;
	for(int i=N-1;i>=0;i--){
		vector<bool> sel(N,false);
		sel[i] = 1;
		int nxt = N;
		if(a[i]<b[i]){
			for(int x=i+1;x<N;x++){
				if(a[x]<b[i]){
					sel[x]=0;
					continue;
				}
				nxt = x;
				break;
			}
		}else{
			for(int x=i+1;x<N;x++){
				if(b[x]<a[x-1]){
					sel[x]=1;
					continue;
				}
				nxt = x;
				break;
			}
		}
		string now;
		rep(j,2*N) if(sel[id[j]]) now += s[j];
		dp[i] = max(dp[i+1],now+dp[nxt]);
	}
	cout<<dp[0]<<endl;
}


Measured memory_bytes: 14592
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int K = scanner.nextInt();
    int S = scanner.nextInt();
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < K; i++) sb.append(S).append(' ');
    int T = S == 1_000_000_000 ? 1 : 1_000_000_000;
    for (int i = K; i < N; i++) sb.append(T).append(' ');
    sb.setLength(sb.length() - 1);
    System.out.println(sb.toString());
  }
}


Measured memory_bytes: 31620
#include<bits/stdc++.h>
#define mo 100000007
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
int n,m,len,i,x,y,a[1500005],flag[1500005],ch[1500005][3],top,ans[1500005];
char s[200005];
void buildtree(int v,int w,int ww){
	if(w==m){
		a[v]=ww;
		return;
	}
	top++;
	ch[v][0]=top;
	top++;
	ch[v][1]=top;
	top++;
	ch[v][2]=top;
	buildtree(ch[v][0],w*3,ww);
	buildtree(ch[v][1],w*3,ww+w);
	buildtree(ch[v][2],w*3,ww+w*2);
}
void ytree(int v,int w,int ww){
	if(w==m){
		ans[a[v]]=ww;
		return;
	}
	if(flag[v]==1){
		swap(ch[v][1],ch[v][2]);
		flag[ch[v][0]]^=1;
		flag[ch[v][1]]^=1;
		flag[ch[v][2]]^=1;
	}
	ytree(ch[v][0],w*3,ww);
	ytree(ch[v][1],w*3,ww+w);
	ytree(ch[v][2],w*3,ww+w*2);
}
int main(){
	//freopen("domino.in","r",stdin);
	//freopen("domino.out","w",stdout);
	n=read();
	scanf("%s",s+1);
	len=strlen(s+1);
	m=1;
	for(i=1;i<=n;i++)
		m*=3;
	buildtree(0,1,0);
	for(i=1;i<=len;i++){
		if(s[i]=='S')
			flag[0]^=1;
		else{
			x=0;
			while(ch[x][0]!=0){
				if(flag[x]==1){
					swap(ch[x][1],ch[x][2]);
					flag[ch[x][0]]^=1;
					flag[ch[x][1]]^=1;
					flag[ch[x][2]]^=1;
					flag[x]=0;
				}
				y=ch[x][2];
				ch[x][2]=ch[x][1];
				ch[x][1]=ch[x][0];
				ch[x][0]=y;
				x=y;
			}
		}
	}
	ytree(0,1,0);
	for(i=0;i<m;i++)
		pus(ans[i],1);
	cout<<endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> f(n,vector<int>(10));
    vector<vector<int>> p(n, vector<int>(11));
    for(int i=0; i<n; i++){
        for(int j=0; j<10; j++){
            cin >> f.at(i).at(j);
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<11; j++){
            cin >> p.at(i).at(j);
        }
    }
    int ans = -pow(10,9);
    for(int i=1; i<(1<<10); i++){
        vector<int> open(10,0);
        for(int j=0; j<10; j++){
            if(i & (1<<j)) open.at(j)=1;
        }
        int gain=0;
        for(int j=0; j<n; j++){
            //お店j
            int dub=0;
            for(int k=0; k<10; k++){
                //お店jとの被り時間数を考える
                dub += f.at(j).at(k)*open.at(k);
            }
            gain += p.at(j).at(dub);
        }
        ans = max(ans, gain);
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  vector<int> S(N);
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &S[i]);
    ans += S[i];
  }
  bool ok = true;
  if (ans % 10 == 0) {
    ok = false;
    sort(S.begin(), S.end());
    for (int i = 0; i < N; ++i) {
      if (S[i] % 10 != 0) {
        ans -= S[i];
        ok = true;
        break;
      }
    }
  }
  printf("%d\n", ok ? ans : 0);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<long> A(55), P(55);
long f(long n, long x);



int main()
{
    long n, x;
    cin >> n >> x;
    A[0] = 1; P[0] = 1;
    
    for(int i=0; i<n-1; i++)
    {
        A[i+1] = A[i]*2 + 3;
        P[i+1] = P[i]*2 + 1;
    }

    cout << f(n, x);
}

long f(long n, long x)
{
    if(n == 0)
    {
        if(x <= 0) return 0;
        else return 1;
    }
    else if(x <= 1+A[n-1])
    {
        return f(n-1, x-1);
    }
    else
    {
        return P[n-1] + 1 + f(n-1, x-2-A[n-1]);
    }
}


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

vector<int> num = {0,2,5,5,4,5,6,3,7,6};
vector<char> nchar = {'0','1','2','3','4','5','6','7','8','9'};

bool check(string s,string t){
    int n1 = s.size(), n2 = t.size();
    if(n1 > n2) return false;
    if(n1 < n2) return true;
    if(s > t) return false;
    return true;
}

int main(){
    int n,m; cin >> n >> m;
    vector<string> dp;
    vector<int> match(m);
    rep(i,m) cin >> match[i];
    dp.push_back("");
    for(int i = 1;i <= n;++i){
        string s = "";
        rep(j,m) {
            if(num[match[j]] <= i) {
                if(dp[i-num[match[j]]] == "" && i != num[match[j]]) continue;
                if(check(s,dp[i-num[match[j]]]+nchar[match[j]])) s = dp[i-num[match[j]]]+nchar[match[j]];
            }
        }
        dp.push_back(s);
    }
    cout << dp[n] << endl;
}

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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define dump(x) cerr << #x " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define endl '\n'

#ifdef _DEBUG27_
    //#define STRESS 1
#endif

typedef long long llong;

const int INF = 2e9 + 999;
const llong LINF = 2e18 + 999;

void inv(bool e);
template<typename T> T sign(T a);
template<typename T> void die(T &a);
template<typename T> void umax(T &a, T b);
template<typename T> void umin(T &a, T b);

bool brute, alter;
int cnt_tests = 1;

// Atcoder 2018

// Code below

set<int> st;
int n;

void inp() {
    cin >> n;
    int x;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        st.insert(x);
    }
}

void solve() {
    cout << sz(st);
}

void stress() {

}

void naive() {

}

void run();
int main() {
    #ifdef _DEBUG27_
        if (1)
            freopen("input.txt", "r", stdin);
    #else
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        if (0) {
            freopen("palindrome.in", "r", stdin);
            freopen("palindrome.out", "w", stdout);
        }
    #endif
    srand(time(0));
    #ifdef STRESS
        brute = true;
    #else
        brute = false;
    #endif

    for (int i = 0; (i < cnt_tests); i++) {
        run();
    }

    #ifdef _DEBUG27_
        cout << endl << "Time: " << clock() / 1000.0 << " ms";
    #endif
    return 0;
}

void run() {
    if (!brute) {
        inp();
    }
    else {
        stress();
    }
    solve();
    cout << endl;
}

template<typename T>
void die(T &a) {
    cout << a;
    exit(0);
}

template<typename T>
T sign(T a) {
    if (a == 0)
        return 0;
    if (a < 0)
        return -1;
    return 1;
}

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

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

void inv(bool e) {
    if (!e) {
        vector<int> a;
        a[-1] += 1;
    }
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
a = [0] * N
dp = [[0] * 5 for _ in range(N + 1)]
for i in range(N): a[i] = int(input())
for i in range(N + 1):
  for j in range(5): dp[i][j] = 10 ** 15

dp[0][0] = 0
for i in range(N):
  for j in range(5):
    for k in range(j, 5):
      w = a[i]
      if k % 2:
        if a[i] > 0: w = a[i] % 2
        else: w = 2
      elif k == 2: w = int(a[i] % 2 == 0)
      dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + w)
print(min(dp[-1]))

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

#define lld long long
#define pp pair<int,int>
#define pb push_back
#define MOD 10007
#define left lleft
#define right rright
#define INF 2000000000
#define LINF 1000000000000000000LL
#define next nnext

using namespace std;

int N;
lld a[100002];

int main(){
	scanf("%d",&N);
	for(int i=1; i<=N; i++) scanf("%lld",&a[i]);
	lld sum1,sum2,sum;
	sum = sum1 = sum2 = 0;
	for(int i=1; i<=N; i++){
		sum += a[i];
		if(i%2 == 1){
			if(sum <= 0){
				sum1 += (1-sum);
				sum = 1;
			}
		}else{
			if(sum >= 0){
				sum1 += (sum+1);
				sum = -1;
			}
		}
	}
	sum = 0;
	for(int i=1; i<=N; i++){
		sum += a[i];
		if(i%2 == 1){
			if(sum >= 0){
				sum2+= (sum+1); 
				sum = -1;
			}
		}else{
			if(sum <= 0){
				sum2 += (1-sum);
				sum = 1;
			}
		}
	}
	printf("%lld\n",min(sum1,sum2));

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
	int a[100][100] = {}, b[100][100] = {};
	long c[100][100] = {};

	int n, m, l;
	int i, j, k;

	cin >> n >> m >> l;

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}

	for (i = 0; i < m; i++)
	{
		for (j = 0; j < l; j++)
		{
			cin >> b[i][j];
		}
	}

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < l; j++)
		{
			for (k = 0; k < m; k++)
			{
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}

	for (i = 0; i < n; i++)
	{
		for (j = 0; j < l; j++)
		{
			cout << c[i][j];
			if (j != l - 1)
				cout << " ";
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1324
N=int(input())
memo=[[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N+1):
  memo[i//(10**(len(str(i))-1))][i%10]+=1
ans=0
for i in range(10):
  for j in range(10):
    ans+=memo[i][j]*memo[j][i]
print(ans)

Measured memory_bytes: 40428
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define deb2a(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define mod 998244353
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
// int mI(int a, int m)  {return power(a, m - 2, m);}
vector<vector<int>> dir = {{0, 1}, {0, -1}, {1, 0}, {-1, 0},{1,1},{1,-1},{-1,1},{-1,-1}};
void solve(){
    int n;
    cin >> n;
    vec v(n);
    map<int, int> m;
    int s = 0;
    fo(i,n){
        cin >> v[i];
        s += v[i];
        m[v[i]]++;
    }
    int q;
    cin >> q;
    fo(i,q){
        int a,b;
        cin >> a >> b;
        s -= (a * m[a]);
        m[b] += m[a];
        s += (b * m[a]);
        m[a] = 0;
        cout << s << "\n";
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 10092
#include <bits/stdc++.h>
#define int long long int 
#define N 100001
using namespace std;
int DP[N][2];
bool vis[N];
vector<int> adj[N];
const int mod = 1e9 +7;
void dfs(int x)
{
    int w=1,b=1;
    vis[x]=1;
    for(auto i:adj[x])
    {
        if(!vis[i])
        {
            dfs(i);
            w = w*((DP[i][0] + DP[i][1])%mod)%mod;
            b = b*(( DP[i][1])%mod)%mod;
        }
        
    }
    DP[x][0] = (DP[x][0]*b)%mod;
    DP[x][1] = (DP[x][1]*w)%mod;
}

signed main() {
    int n,x,y;
    cin>>n;
    for(int i=1;i<=n-1;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    for(int i=1;i<=n;i++)
    {
        DP[i][0]=1;
        DP[i][1] =1;
        vis[0]=0;
    }
    dfs(1);
    cout<<(DP[1][0] + DP[1][1])%mod;
    return 0;
}

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,D;cin>>N>>D;
  cout<<(N-1)/(2*D+1)+1<<endl;
  return 0;
}


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

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

const int mod = 1000*1000*1000+7;

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

	int result = 1;

	int n, m;

	cin >> n >> m;

	REP(j, 2) {

		long long sum = 0;
		long long now = 0;

		REP(i, n) {
			long long x;
			cin >> x;

			now = (now + i * x % mod - sum % mod + mod) % mod;
			sum += x;
		}

		result = 1LL * result * now % mod;
		swap(n, m);
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string S; cin >> S;

    if (stoi(S.substr(5,2)) <= 4) OUT("Heisei")
    else OUT("TBD")

    return 0;
}

Measured memory_bytes: 256