akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int z(int a){
  if(a<1)a*=-1;
  return a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
ll c[100000];
int main(void){
  ll n;
  char s[101];
  scanf("%s %lld",s,&n);
  if(n==1){
    PRC(s[0]);
  }else{
    int i=0;
    while(s[i]=='1')i++;
    if(i<n){
      PRC(s[i]);
    }else{
      PRC('1');
    }
  }
  return 0;
}


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

//Common
using namespace std;using f64 = double;using i64=long long;using u64=unsigned long long;
template<typename T> using Arr=vector<T>;template<typename T> using Func=function<T>;template<typename T> using Str=basic_string<T>;
#define hfor(v, s, e) for(int v=(s);(s)<=v&&v<(e);++v)//half-opened range
#define hfori(v, s, e) for(int v=(e)-1;(s)<=v&&v<(e);--v)//inversion
#define hforo(v, s, e) int v=(s);for(;(s)<=v&&v<(e);++v)//out declaration
#define hforoi(v, s, e) int v=(e)-1; for(;(s)<=v&&v<(e);--v)
#define cfor(v, s, e) hfor(v,(s),(e)+1)//closed range
#define cfori(v, s, e) hfori(v,(s),(e)+1)
#define cforo(v, s, e) hforo(v,(s),(e)+1)
#define cforoi(v, s, e) hforoi(v,(s),(e)+1)
#define rep(v,x) hfor(v,0,(x))
#define repi(v,x) hfori(v,0,(x))
#define repo(v,x) hforo(v,0,(x))
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pushb push_back
#define pushf push_front
#define popb pop_back
#define popf pop_front
#define empl emplace
#define emplb emplace_back
#define emplf emplace_front
#define fi first
#define se second
#define cxp constexpr
#define PQ std::priority_queue

//Math
template<typename T> cxp T inf() { return numeric_limits<T>::max() / 2; }
template<typename T> inline T sq(T x){return x*x;}
int rd(int lb, int ub){static mt19937 rng(time(0)^i64(new int)); return uniform_int_distribution<int>(lb, ub-1)(rng);}
int rd(int ub=inf<int>()){return rd(0,ub);}
const f64 pi=acosl(-1), eps=1e-10;

//IO
template<typename T>ostream& operator<<(ostream& s, const Arr<T>& a) {for(auto i:a) cout<<i<<' '; return s;}
int getint(){int x;cin>>x;return x;}
char getchr(){char x;cin>>x;return x;}
#ifndef DEBUG
	//#pragma GCC optimize ("Ofast") //somtimes it become more slower
	auto __PRE_RUN__=(ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),(cout<<fixed<<setprecision(11)), 0);
#endif

//Functional
namespace fun{
	template<typename U> auto map(const auto& a, auto f){Arr<U> r; for(const auto& x:a)r.pushb(f(x)); return r;}
	template<typename T> auto reduce(const auto& a, T acc){ return accumulate(all(a),acc); }
	template<typename T> auto reduce(const auto& a, T acc, auto f){ return accumulate(all(a),acc,f); }
	template<typename T> T rev(const T& a){return {a.rbegin(),a.rend()};}
	Arr<int> range(int n){ Arr<int> ret(n); rep(i,n)ret[i]=i; return ret; }
	struct defer{ defer(auto f):f(f){} ~defer(){f();} function<void()> f; };
	#define defer(x) auto _##__COUNTER__ = fun::defer([&](){x;});
	#define lam(expr, ...) [&](__VA_ARGS__){return expr;}
}

//Misc
auto split(auto s, auto p){
	Arr<decltype(s)> ret;
	auto it1=s.begin();
	for(auto it2=it1; (it2 = find(it1,s.end(),p)) != s.end(); it1=it2+1)
		ret.pushb({it1, it2});
	ret.pushb({it1,s.end()});
	return ret;
}
int pow2ceil(int x){assert(x);return 1<<(32-__builtin_clz(x-1));}

#define endl '\n'//not interactive?
#define int i64//MLE?
using pint = pair<int,int>;
using tint = tuple<int,int,int>;

signed main(){
	int n; cin>>n; n%=10;
	if(n==3) cout<<'b';
	else if(n==0 or n==1 or n==6 or n==8) cout<<'p';
	else cout<<'h';
	cout<<"on"<<endl;
	return 0;
}



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

int main()
{
  int n;
  cin>>n;
  int a[n+1];
  for(int i=1;i<=n;i++)
  {
    cin>>a[i];
    
  }
  int ans=0;
  for(int i=1;i<=n;i+=2)
  {
    if(a[i]%2==1)
    ans++;
  }
  cout<<ans;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
#define fst() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define f(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define endl '\n'
#define maxn ((int)1e7)
typedef long long ll;
typedef long double ld;
const int m=132000;

int main()
{ 
  fst();
  int a,b;
  cin>>a>>b;
  if(b>=a) cout<<a<<endl;
  else cout<<a-1<<endl;
  return 0;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
conditions = [list(map(int,input().split())) for i in range(M)]
if M == 0 and N == 1:
    print(0)
    exit(0)

if M == 0 and N == 2:
    print(10)
    exit(0)

if M == 0 and N == 3:
    print(100)
    exit(0)

for i in range(0 if N == 1 else 10**(N-1) ,10 ** N):
    isOk = False
    #print(i)
    for j,c in enumerate(conditions):
        s = str(i)
        #print(s)
        #print(c[0])
        #print(c[1])
        if c[0] > len(s):
            break
        if str(c[1]) != s[c[0]-1]:
            break
        if j == M - 1:
            isOk = True

    if isOk:
        print(i)
        exit(0)

print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int a[n],dp[n];

    for(int i=0;i<n;i++)    cin>>a[i],dp[i]=INT_MAX;
    dp[0] = 0;

    for(int i=1;i<n;i++)
        for(int j=1;j<=k;j++)
            if(i-j>=0)
                dp[i] = min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
            else
                break;
    cout<<dp[n-1]<<'\n';
}


Measured memory_bytes: 1024
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]
#define GI(name) int (name);scanf("%d",&(name))
#define GI2(name1,name2) int (name1),(name2);scanf("%d %d",&(name1),&(name2))
#define GI3(name1,name2,name3) int (name1),(name2),(name3);scanf("%d %d %d",&(name1),&(name2),&(name3))
#define GVI(name,size) vector<int> (name)(size);FOR(i,(size))scanf("%d",&(name)[i])
#define MOD 1000000007

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=n;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug_print(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug_print(Head head,Tail... tail){
    cerr<<to_string(head)<<" ";
    debug_print(tail...);
}

template<class... T>
void debug(T... args){
    cerr<<"["<<__LINE__<<"]: ";
    debug_print(args...);
}

void print(){
    cout<<endl;
}

template<class Head,class... Tail>
void print(Head head,Tail... tail){
    cout<<to_string(head);
    print(tail...);
}

int main(){
    string O=get_str(),E=get_str();
    string S;
    FOR(i,(int)O.size()+(int)E.size()){
        if(i%2==0){
            S+=O[i/2];
        }else{
            S+=E[i/2];
        }
    }
    print(S);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back

int mod,n;
vector<vector<int>> G;
vector<ll> res,ans;
void dfs1(int u,int fa){
    res[u]=1;
    for(auto to:G[u]){
        if(to==fa) continue;
        dfs1(to,u);
        (res[u]*=ll(res[to]+1))%=mod;
    }
}
void dfs2(int root,int fa,ll now){
    ans[root]=((now+1)*res[root])%mod;
    vector<pair<ll,int>> pre,suf;
    for(auto to:G[root]){
        if(to==fa) continue;
        pre.pb({res[to]+1,to});
        suf.pb({res[to]+1,to});
    }
    for(int i=1;i<sz(pre);i++) (pre[i].F*=ll(pre[i-1].F))%=mod;
    for(int i=sz(suf)-2;i>=0;i--) (suf[i].F*=ll(suf[i+1].F))%=mod;
    for(int i=0;i<sz(pre);i++){
        ll l=(i==0?1:pre[i-1].F),r=(i==sz(pre)-1?1:suf[i+1].F);
        dfs2(pre[i].S,root,l*r%mod*(now+1)%mod);
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>mod;
    G.resize(n+1);
    res.resize(n+1);
    ans.resize(n+1);
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dfs1(1,0);
    dfs2(1,0,0);
    for(int i=1;i<=n;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}



Measured memory_bytes: 26032
l = input().split()
N = int(l[0])
W = int(l[1])

v = []
w = []
for i in range(N):
    l = input().split()
    v.append(int(l[0]))
    w.append(int(l[1]))


c = [[0 for _ in range(W + 1)] for _ in range(N + 1)]

for j in range(1, N + 1):
    for k in range(1, W + 1):
        if w[j-1] <= k:
            if v[j-1] + c[j-1][k-w[j-1]] > c[j - 1][k]:
                c[j][k] = v[j-1] + c[j-1][k-w[j-1]]
            else:
                c[j][k] = c[j-1][k]
        else:
            c[j][k] = c[j-1][k]
print(c[N][W])

Measured memory_bytes: 27952
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <numeric>
#include <iomanip>
#include <climits>
#include <cstring>
#include <cmath>

using namespace std;

#define int long long
#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 rrep(i, n) for (int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for (int i=(int)(n);i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=(int)(r)-1;i>=l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;
using vpii=vector<pii>;
using ll=long long;

constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}
template<typename T>bool chmin(T&a,T b){return a>b?(a=b,1):0;}
template<typename T>bool chmax(int&a,int b){return a<b?(a=b,1):0;}
int read(){int a;scanf("%lld",&a);return a;}

const double pi = acos(-1);
constexpr int inf = 3*TEN(18) + 10;

bool exist[1000100];
bool skip[1000100];
bool is_ok[1000100];


signed main()
{
	int N; cin >> N;
	vi A(N);
	rep(i, N) {
		cin >> A[i];
		if (exist[A[i]]) {
			skip[A[i]] = true;
		} else 
			exist[A[i]] = true;
	}
	sort(all(A));
	set<int> S;
	rep(i, N) S.insert(A[i]);

	int ans = 0;

	for (int i : S) {
		for (int j = i + i; j <= 1000000; j += i) {
			if (exist[j]) {
				skip[j] = true;
			}
		}

		if (skip[i]) continue;

		ans++;
	}

	cout << ans << endl;
}




Measured memory_bytes: 14720
#include<iostream>
#include<string.h>
#include<math.h>
#include<vector>
#include<algorithm>

using namespace std;
int main(void)
{
	vector<int> n(3);
	int i;
	for (i = 0; i < 3; i++)
	{
		cin >>n[i];
	}
	sort(n.begin(), n.end());
	int sum = n[0] + n[1] + n[2]*10;
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define forn(i,n) for(int i=0; i<(int)n; i++)
ll power(ll x,ll n);
bool isprime(ll n);


void test_case()
{
    ll n,m,a,b;
    cin>>n>>m;
    ll height[n+1];
    for(ll i=1;i<=n;i++)
        cin>>height[i];
    vector<ll> adj[n+1];
    while(m--) {
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    ll cnt=0;
    for(ll i=1;i<=n;i++) {
            bool f=1;
        for(ll x:adj[i]) {
            if(height[x]>=height[i]) {
                f=0;
                break;
            }
        }
        if(f)
            cnt++;
    }
    cout<<cnt;


}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}
ll power(ll x,ll n)
{
    ll ans=1;
    while(n>0) {
        if(n&1)
            ans*=x;
        n>>=1;
        x*=x;
    }
    return ans;
}

bool isprime(ll n)
{
    if(n==2 || n==3)
        return true;
    if(n<=1 || n%2==0 || (n%6!=1 && n%6!=5))
        return false;
    for(ll i=3;i*i<=n;i+=2) {
        if(n%i==0)
            return false;
    }
    return true;
}


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


int a[50], b[50], c[50], d[50], e[50];
int n, m, q;
int ret = 0;

void dfs(int pos, int val){
    if(pos == n){
        int tmp = 0;
        for(int i = 0; i < q; i++){
            tmp += d[i] * (e[b[i]]-e[a[i]] == c[i]);
        }
        ret = max(ret, tmp);
        return;
    }    
    for(int i = val; i <= m; i++){
        e[pos] = i;
        dfs(pos+1, i);
    }
}

int main(){
    cin >> n >> m >> q;
    for(int i = 0; i < q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--, b[i]--;
    }
    dfs(0, 1);
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3636
NT = list(map(int, input().split(' ')))
N = NT[0]
T = NT[1]
res = []
for _ in range(N):
    nt = list(map(int, input().split(' ')))
    n = nt[0]
    t = nt[1]
    if t <= T:
        res.append(n)
if not res:
    res = 'TLE'
else:
    res = min(res)
print(res)

Measured memory_bytes: 3064
S = input()

def isKaibun(X):
  flag = True
  for i in range(len(X) // 2):
    if X[i]  != X[-1 - i]:
      flag = False
      break
  return flag

flag = False
if isKaibun(S):
  if isKaibun(S[0 : len(S) // 2]):
    if isKaibun(S[(len(S) + 1) // 2 : len(S)]):
      flag = True

if flag == True:
  print("Yes")
else:
  print("No")

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

int main() {
  int n;
  cin >> n;
  int a = n/10;
  int b = n/1000;

  if ((a*10)%111 == 0 || (n - b * 1000)%111 == 0) {
    cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INFS (1LL<<28)
#define INF (1LL<<60)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
#define double long double
#define all(n) n.begin(),n.end()
typedef complex<double> P;

vector<pair<double,pair<double,double>>> ans;

double rot(double x,double y){
	double angle=acos(x/(sqrt(x*x+y*y)));
	angle=angle*180.0/acos(-1);
	if(y<0)angle=360.0-angle;
	return angle;
}

signed main(){
	cout << fixed << setprecision(15);
	int n;
	cin>>n;

	lp(i,n){
		int x,y;
		cin>>x>>y;
		ans.push_back({arg(P(x,y)),{x,y}});
	}
	sort(ans.begin(),ans.end());
	lp(i,n){
		ans.push_back(ans[i]);
	}
	double r=0;
	lp(i,n){
		double sum[2]={0,0};
		for(int j=i;j<n+i;j++){
			sum[0]+=ans[j].second.first;
			sum[1]+=ans[j].second.second;
			r=max<double>(r,sqrt(sum[0]*sum[0]+sum[1]*sum[1]));
		}
	}
	cout<<r<<endl;
	return 0;
}


Measured memory_bytes: 256
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    #n=int(input())
    n,k,s= map(int, sys.stdin.readline().split(' '))
    print(min(k,s),max(0,k+s-n))
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

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

#define IOS std::cin.tie(0);std::ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>;

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())
#define END cout<<"\n"

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 55;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    CIN(N,K);
    vi h(N);VCIN(h);
    
    vi dp(N+10,INF);
    dp[0]=0;
    Rep(i,0,N){
        RepS(j,1,K){
            if(j+i<N)dp[i+j]=min(dp[j+i],dp[i]+abs(h[j+i]-h[i]));
        }
    }
    COUT(dp[N-1]);


    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

int par(int i, vector<int> &group)
{
  if(i== group[i]) return i;
  else
  {
    return group[i] = par(group[i], group);

  }
}

bool same(int i, int j, vector<int> &group)
{
  if(par(i, group) == par(j, group) )
  {
    return true;
  }
  else
  {
    return false;
  }
}

void unite(int i, int j, vector<int> &group, vector<int> &depth)
{
  int a = par(i, group);
  int b = par(j, group);
    if( a != b)
    {
      if(depth[i]==depth[j])
      {
        depth[i] ++;
        group[b] = a;
      }
      else if(depth[i] > depth[j] )
      {
        group[b] = a;
      }
      else
      {
        group[a] = b;
      }

    }
}


int main(void){

  int N, M;
  cin >> N >> M;
  vector<int> Par(N);
  vector<int> depth(N, 0);
  for(int i=0; i<N; i++)
  {
    Par[i] = i;
  }
  int a,b;
  int c = 0;
  for(int i=0; i<M; i++)
  {
      cin >>a >> b;

      if(!same(a-1, b-1, Par) )
      {
        unite(a-1, b-1, Par, depth);
        c ++;
      }
  }
  //cout << N-1-c << endl;

  int count = 0;
  vector<int> counts(N, 0);
  for(int i=0; i<N; i++)
  {
    int p = par(i, Par);
    if( counts[p]==0 )
    {
      counts[p] ++;
      count ++;

    }
  }
  cout << count-1 << endl;

  return 0;
}


Measured memory_bytes: 4516
#include <iostream>
#include <string>
#include <vector>
using namespace std;

vector<int> RLE(string s);

int main() {
  string s;
  cin >> s;
  vector<int> vec = RLE(s);
  vector<int> ans(s.length(), 0);
  int position = -1;
  for (int i = 0; i < vec.size(); i += 2) {
    int sum = vec[i] + vec[i + 1];
    position += vec[i];
    if (sum % 2 == 0) {
      ans[position] = sum / 2;
      ans[position + 1] = sum / 2;
    } else {
      if (vec[i] % 2 == 0) {
        ans[position] = sum / 2;
        ans[position + 1] = sum / 2 + 1;
      } else {
        ans[position] = sum / 2 + 1;
        ans[position + 1] = sum / 2;
      }
    }
    position += vec[i + 1];
  }
  for (int i = 0; i < ans.size(); i++) {
    if (i == ans.size() - 1){
      cout << ans[i] << endl;
      return 0;
    }
    cout << ans[i] << " ";
  }
}

vector<int> RLE(string s) {
  vector<int> ans;
  s.push_back('S');
  int counter = 0;
  while (true) {
    int count = 1;
    while (true) {
      if (s[counter] != s[counter + 1]) {
        ans.push_back(count);
        break;
      }
      counter++;
      count++;
    }
    if (counter == s.length() - 2)
      break;
    counter++;
  }
  return ans;
}


Measured memory_bytes: 1592
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_B&lang=ja

import sys
sys.setrecursionlimit(10**7)



def rec(l,r):
    if r-l < 1:
        return 0
    if r-l == 1:
        return M[l][0] * M[r][0] * M[r][1]
    if memo[l][r] != -1:
        return memo[l][r]
    memo[l][r] = min(rec(l, j-1) + rec(j, r) + M[l][0] * M[j-1][1] * M[r][1] for j in range(l+1,r+1))
    return memo[l][r]



N = int(input())
M = []
memo = [[-1]*N for _ in range(N)]

for i in range(N):
    M.append(list(map(int, input().split())))

print(rec(0,N-1))


Measured memory_bytes: 6004
package main

import "fmt"

func main() {
	var s string
	var k int
	fmt.Scan(&s, &k)
	onecnt := 0
	var last byte
	for i := 0; i < len(s); i++ {
		if s[i] != '1' {
			last = s[i]
			break
		} else {
			onecnt++
		}
	}

    if onecnt == 0 || onecnt < k {
		fmt.Println(string(last))
	} else {
		fmt.Println("1")
	}
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		long a = Long.parseLong(str[0]);
		long b = Long.parseLong(str[1]);
		long n = Long.parseLong(str[2]);

		long x = Math.min(b - 1, n);

		System.out.println((a * x) / b - a * (x / b));
	}
}

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

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

    vector<int64_t> x(n), y(n), z(n);
    for (int i = 0; i < n; i++){
        cin >> x.at(i) >> y.at(i) >> z.at(i);
    }

    int64_t max = -1;
    vector<int64_t> data(n);
    for (int tmp = 0; tmp < (1 << 3); tmp++){
        bitset<3> bit(tmp);

        for (int i = 0; i < n; i++){
            data.at(i) = 0;
            if(bit.test(0)){
                data.at(i) += x.at(i);
            }
            else{
                data.at(i) -= x.at(i);
            }

            if(bit.test(1)){
                data.at(i) += y.at(i);
            }
            else{
                data.at(i) -= y.at(i);
            }

            if(bit.test(2)){
                data.at(i) += z.at(i);
            }
            else{
                data.at(i) -= z.at(i);
            }
        }

        sort(data.begin(), data.end());
        int64_t sum = 0;
        for (int i = 0; i < m; i++){
            sum += data.at(n - i - 1);
            //sum += data.at(i);
        }

        if (sum > max){
            max = sum;
        }
    }

    cout << max << endl;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int i,n;cin>>n;
	string str;cin>>str;
	
	llint ans=1;
	array<int,26>c={};
	for(i=0;i<n;i++){c[str[i]-'a']++;}
	for(i=0;i<26;i++){
		ans*=(c[i]+1);
		ans%=mod;
	}
	ans+=mod;ans-=1;ans%=mod;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    long long n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    long long m = min(min(min(min(a, b), c), d), e);
    long long ans = (n + m - 1) / m + 4;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
ll x, y;

ll f(ll x) {
    if(x <= 0) return 0LL;
    if(x % 4 == 1) return 1LL;
    else if(x % 4 == 2) return x + 1LL;
    else if(x % 4 == 3) return 0LL;
    else return x;
}

int main() {
    cin>>x>>y;
    ll f1 = f(y);
    ll f2 = f(x-1);
    ll result = f1 ^ f2;
    cout<<result<<"\n";
    return 0;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int n, m;
int adj[200][200];
bool useE[200][200];
bool used[200];
int pre[200];
int d[200];

void dijkstra(int s){
	fill(d, d + n, INF);
	fill(used, used + n, false);
	for(int i=0; i<n; i++){
		pre[i] = -1;
	}
	d[s] = 0;

	while(true){
		int v = -1;
		for(int u=0; u < n; u++){
			if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
		}

		if(v == -1) break;
		used[v] = true;

		for(int u = 0; u < n; u++){
			if(d[u] > d[v] + adj[v][u]){
				d[u] = d[v] + adj[v][u];
				pre[u] = v;
			}
		}
	}
}

vector<int> get_path(int t, int s){
	vector<int> path;
	for(; t != -1; t = pre[t]){
		path.push_back(t);
	}
	reverse(path.begin(), path.end());

	for(int i=0; i < path.size()-1; i++){
		useE[path[i]][path[i+1]] = useE[path[i+1]][path[i]] = true;
	}
	return path;
}

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	cin >> n >> m;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			adj[i][j] = adj[j][i] = INF;
		}
	}

	for(int i=0; i<m; i++){
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		adj[a][b] = adj[b][a] = c;
	}


	for(int i=1; i<n; i++){
		dijkstra(i);
		for(int j=0; j<n; j++){
			if(i == j) continue;
			get_path(j, i);
		}
	}

	ll ans = 0;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(adj[i][j] != INF && useE[i][j] == false) ans++;
		}
	}
	/*
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(adj[i][j] != INF){
				printf("%d ", adj[i][j]);
			}else{
				printf("# ");
			}
		}
		puts("");
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			printf("%d ", useE[i][j]);
		}
		puts("");
	}
	*/

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


Measured memory_bytes: 384
fun main(args: Array<String>) {
	val (N, M, X, Y) = readLine()!!.split(" ").map { it.toInt() }
	val x = readLine()!!.split(" ").map { it.toInt() }
	val y = readLine()!!.split(" ").map { it.toInt() }
	var flg = false

	for (z in X + 1 .. Y) {
		if (z in x.max()!! + 1 .. y.min()!!) {
			flg = true
		}
	}

	if (flg) {
		println("No War")
	} else {
		println("War")
	}
}


Measured memory_bytes: 37904
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
const ll INF=1000000007LL;
typedef pair<int,int> P;
bool c[100001]={};
int main() {
	int k;
	cin>>k;
	int s=1;
	deque<P> que;
	que.push_front(P(0,1%k));
	int ans;
	while(!que.empty()){
		P p=que.front();que.pop_front();
		int d=p.first,n=p.second;
		if(c[n])continue;
		c[n]=true;
		if(n==0){
			ans=d+1;
			break;
		}
		que.push_front(P(d,(n*10)%k));
		que.push_back(P(d+1,(n+1)%k));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1152
//*Author : Franklin*
#include<bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const int N = 2e5;
#define deb(x) cout << #x << "=" << x << "\n"
#define debug(a) for(auto &x:a) cout << x << " "
#define debugg(p) for(auto &x:p) cout << "(" << x.first << "," << x.second << ")" << "\n"

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    vector<int> dp(n,INF);
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j <= i+k; j++) {
            if(j < n) {
                dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
    }
    cout << dp[n-1] << "\n";
    return 0;

}


Measured memory_bytes: 3976
#include<iostream>
#include<string>
using namespace std;
int main(void){
int sum=700;
char s[3];
cin>>s[0]>>s[1]>>s[2];
if(s[0]=='o')
sum+=100;
if(s[1]=='o')
sum+=100;
if(s[2]=='o')
sum+=100;
cout<<sum<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  if(N % 2 == 0){
    cout << 1.0 / 2.0 << endl;
  } else {
    cout << ((double)((N / 2) + 1))/((double) N);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char tile[20][21];
bool vis[20][20];
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int W,H;
int dfs(int x,int y) {
    int sum=1;
    vis[y][x]=1;
    for(int i=0;i<4;i++) {
        int nx=x+dx[i],ny=y+dy[i];
        if(0>nx||nx>=W||0>ny||ny>=H||tile[ny][nx]=='#'||vis[ny][nx]) continue;
        sum+=dfs(nx,ny);
    }
    return sum;
}
int main() {
    while(scanf("%d %d",&W,&H),W) {
        for(int i=0;i<H;i++) scanf("%s",tile[i]);
        int sx,sy;
        for(int i=0;i<H;i++) {
            for(int j=0;j<W;j++) if(tile[i][j]=='@') {sx=j;sy=i;tile[i][j]='.';}
        }
        memset(vis,0,sizeof(vis));
        printf("%d\n",dfs(sx,sy));
    }
}

Measured memory_bytes: 3100
#include<iostream>
using namespace std;
int main(){
	
  int n,k;
  cin >> n >> k;
  int arr[n];
  for(int i=0;i<n;i++) cin >> arr[i];
  bool dp[k+1];
  for(bool &i : dp) i=0;
  for(int i=0;i<=k;i++){
  	for(int j:arr){
    	if(i>=j && !dp[i-j]){
        	dp[i]=true;
          	break;
        }
    }
  }
  
  if(dp[k] == true) cout << "First";
  else cout << "Second";
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_N 1010
#define MAX_V 3010
#define INF 1e9
typedef pair<int,int> pii;
 
struct edge{
    int to,cap,cost,rev;
};
 
int V,h[MAX_V],dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];
vector<edge> G[MAX_V];
 
void add_edge(int from,int to,int cap,int cost){
    G[from].push_back((edge){to,cap,cost,G[to].size()});
    G[to].push_back((edge){from,0,-cost,G[from].size()-1});
}
 
int min_cost_flow(int s,int t,int f){
    int res = 0;
    fill(h,h+V,0);
    while(f > 0){
	priority_queue<pii,vector<pii>,greater<pii> > Q;
	fill(dist,dist+V,INF);
	dist[s] = 0;
	Q.push(pii(0,s));
	while(!Q.empty()){
	    pii p = Q.top(); Q.pop();
	    int v = p.second;
	    if(dist[v] < p.first) continue;
	    for(int i = 0 ; i < (int)G[v].size() ; i++){
		edge &e = G[v][i];
		if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]){
		    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
		    prevv[e.to] = v; preve[e.to] = i;
		    Q.push(pii(dist[e.to],e.to));
		}
	    }
	}
	if(dist[t] == INF) return -1;
	for(int v = 0 ; v < V ; v++){
	    h[v] += dist[v];
	}
	int d = f;
	for(int v = t ; v != s ; v = prevv[v]){
	    d = min(d,G[prevv[v]][preve[v]].cap);
	}
	f -= d;
	res += d * h[t];
	for(int v = t ; v != s ; v = prevv[v]){
	    edge &e = G[prevv[v]][preve[v]];
	    e.cap -= d;
	    G[v][e.rev].cap += d;
	}
    }
    return res;
}
 
void init(){
    for(int i = 0 ; i < MAX_V ; i++){
	G[i].clear();
    }
}
 
int main(){
    set<int> st;
    int N,A[MAX_N],B[MAX_N];
    cin >> N; init();
    for(int i = 0 ; i < N ; i++){
	cin >> A[i] >> B[i];
	st.insert(A[i]); st.insert(B[i]);
    }
    int size = st.size();
    int s = N+size,t = s+1;
    V = N + size + 2;
    set<int>::iterator it;
    vector<int> vec;
    for(it = st.begin() ; it != st.end() ; ++it){
	vec.push_back(*it);
    }
    add_edge(s,t,size,0);
    for(int i = 0 ; i < N ; i++){
	int j = lower_bound(vec.begin(),vec.end(),A[i])-vec.begin();
	add_edge(j,size+i,1,-B[i]);
	j = lower_bound(vec.begin(),vec.end(),B[i])-vec.begin();
	add_edge(j,size+i,1,-A[i]);
    }
    for(int i = 0 ; i < size ; i++){
	add_edge(s,i,1,0);
    }
    for(int i = 0 ; i < N ; i++){
	add_edge(size+i,t,1,0);
    }
    cout << -min_cost_flow(s,t,size) << endl;
    return 0;
}

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




int main()
{
  int N,M;
  cin >> N >> M;
  vector<int> A;
  int64_t ans = 0LL;
  int a,now;
  for (int i = 0; i < N; i++)
  {
    cin >> a;
    A.push_back(a);
  }
  if (N == 1)
  {
    int aa = A.at(0);
    for (int i = 0; i < M; i++)
    {
      aa = aa / 2;
    }
    cout << aa << endl;
    return 0;
  }
  sort(A.begin(), A.end());

  for (int i = 0; i < M; i++)
  {
    now = A.at(N - 1) / 2;
    A.pop_back();
    A.insert(lower_bound(A.begin(),A.end(), now), now);
  }

  for (int i : A)
  {
    ans += i;
  }

  cout << ans << endl;
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = 1e9+7; typedef vector<ll> VL;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

const VI prm={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,
              59,61,67,71,73,79,83,89,97};
map<ll, int> fct(int n){
	map<ll,int> mp;
	for(int i=2; i<=n; i++) if(binary_search(all(prm), i)){
		for(int w=n;w>0;w/=i) mp[i] += w/i;
	}
	return mp;
}

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

	array<int, 99> dp, np;
	dp.fill(0); dp[1] = 1;
	for(auto& z: fct(n)){
		np.fill(0);
		rep(j, 76)  rep(k, z.second+1){
			if((k+1)*j <=75) np[(k+1)*j] += dp[j];
		}
		swap(dp, np);
	}
	cout << dp[75] <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  if (u == s){
    cout << a - 1 << ' ' << b << '\n';
  }
  else
  {
    cout << a << ' ' << b - 1 << '\n';
  }
  return 0;   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}

   

int main(){
 lint N,x=1;
 cin>>N;
 while(1){
     if(x*(x+1)/2==N){
         repp(i,1,x+1){
             cout<<i<<endl;
         }
         return 0;
     }else if(x*(x+1)/2>N){
         repp(i,1,x+1){
            if(i==(x*(x+1)/2-N))continue;
            cout<<i<<endl;
         }
         return 0;
     }
     x++;
 }
}

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

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

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

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

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

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

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

// ---- ----

int n, a[3000];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; }
	
	int sum = 0;
	inc(i, n) { sum += a[i] - 1; }
	
	cout << sum << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<functional>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

typedef unsigned long long UInt64;
typedef long long Int64;

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

using namespace std;


int P=4;
int Q=15;
int R=50;
int C=400;

bool check(int p,int q,int r,int c)
{
	return (P>=p && Q>=q && R>=r && C>=c);
}

int main()
{
	int n;
	while(cin>>n)
	{
		vector<int> p,q,r,i;
		bool f=true;
		if(!n) return 0;
		rep(j,n)
		{
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			i.pb(a);
			p.pb(b);
			q.pb(c);
			r.pb(d);
		}
		cin>>P>>Q>>R>>C;
		rep(j,n)
		{
			if(check(p[j],q[j],r[j],p[j]*4+q[j]*9+r[j]*4))
			{
				f=false;
				cout<<i[j]<<endl;
			}
		}
		if(f) cout<<"NA"<<endl;
	}
		return 0;
}

Measured memory_bytes: 1240
MOD = 10**9 + 7

N, X = map(int, input().split())
Ss = list(map(int, input().split()))

Ss.sort(reverse=True)
minS = Ss[-1]

D = {X: 1}
for i, S in enumerate(Ss[:-1]):
    D2 = {}
    for x, num in D.items():
        D2[x] = (D2.get(x, 0) + num*(N-1-i)) % MOD
        D2[x%S] = (D2.get(x%S, 0) + num) % MOD
    D = D2

ans = 0
for x, num in D.items():
    ans += (x%minS) * num % MOD
    ans %= MOD

print(ans)


Measured memory_bytes: 5140
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main(){ 
  long long a,b,n,ans;
  cin>>a>>b>>n;
  ans=min(n,b-1);
  cout<<(a*ans)/b-a*(ans/b);
  }


Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<climits>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<queue>
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
#include<utility>
#include<iomanip>
//#include<ext/pb/ds/assoc_container.hpp>

#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef long long int lld;
typedef long double real;

lld mod = 1e9+7;

template<typename T>
void input_vector(vector<T>& v, lld n, lld start=0) {
	for(lld i=start; i<n; ++i) 
		cin>>v[i];
}

template<typename T>
void display_vector(vector<T> v, lld start=0, string sep=" ") {
	for(lld i=start; i<v.size(); ++i)
		cout<<v[i]<<sep;
	cout<<"\n";
}

void fillPrimes(vector<lld>& sieve, vector<lld>& primes) {
	lld i, j;
	
	for(i=2*2; i<sieve.size(); i+=2) 
		sieve[i]=0;
	
	j=3;
	while(j<sieve.size()) {
		for(i=j*j; i<sieve.size(); i+=(2*j)) {
			sieve[i]=0;
		}
		
		// get next prime
		for(i=j+1; i<sieve.size(); ++i)
			if(sieve[i]) {
				j=i;
				break;
			}
		if(i==sieve.size())
			break;
	}
	
	for(i=2; i<sieve.size(); ++i) {
		if(sieve[i])
			primes.push_back(i);
	}
}

vector<pair<lld, lld>> factorize(lld n, vector<lld> primes) {
	vector<pair<lld, lld>> factors;
	lld tmp=n;
	for(lld i=0; primes[i]*primes[i]<=n; ++i) {
		if(tmp%primes[i]==0){
			pair<lld, lld> pr = {primes[i], 0};
			while(tmp%primes[i]==0) {
				pr.second++;
				tmp /= primes[i];
			}
			factors.push_back(pr);
		}
	}
	if(tmp>1)
		factors.push_back({tmp, 1});
	return factors;
}

void solve() {
	
}

int main() {
	lld t=1;
	//cin>>t;
	
	for (lld cs=1; cs<=t; ++cs) {
		lld a;
		string b;
		int temp=0;
		cin>>a;
		cin>>b;
		for(lld i=0; i<b.length(); ++i)
			if(b[i]!='.')
				temp = temp*10 + (lld)(b[i]-'0');
		cout<<(a*temp)/100<<"\n";;
		//solve();
	}
	
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()


template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int turn = 0;
  while(true)
  {
    if(turn%2 == 0)
    {
      C -=B;
      if(C <= 0)
      {
        cout<<"Yes"<<endl;
        return;
      }
    }
    else
    {
      A -=D;
      if(A <= 0)
      {
        cout<<"No"<<endl;
        return;
      }
    }
    turn++;
    
  }
   
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);

std::cout << std::fixed;
std::cout << std::setprecision(9);
solve();

return 0;
}


Measured memory_bytes: 3660
N = int(input())
S = []
for i in range(N):
  s = list(input())
  s.sort()
  S.append(s)
S.sort()
ans = 0
snt = 1
for i in range(N-1):
  if S[i]==S[i+1]:
    snt += 1
  else :
    ans += (snt*(snt-1))//2 if snt>1 else 0
    snt = 1
ans += (snt*(snt-1))//2 if snt>1 else 0
print(ans)

Measured memory_bytes: 97880
#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>;
const int INF = 1 << 29;
 
int main() {
	string s; 
	cin >> s;
	vector<int> cnt(26, 0);

	int l = s.size();
	rep(i, l) {
		cnt[s[i]-'a']++;
	}
	rep(i,26) {
		if (cnt[i]%2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
#include<chrono>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll dp[3001][3001];
signed main(){
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
  ll n,t,mid=0,tmp,ans=0;
  cin >> n >> t;
  set<ll> st;
  ll a[n],b[n];
  vector<pair<P,ll>> v;
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
    v.push_back({P(b[i],a[i]),i});
  }
  ll idx=0;
  sort(v.begin(),v.end(),greater<pair<P,ll>>());
  while(idx<n){
    end = chrono::system_clock::now();
    double time=  static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0);
    if(time>=1800) break;
    fill(dp[0],dp[3001],0);
    a[v[idx].second]=0;
    b[v[idx].second]=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<t;j++){
        dp[i+1][j] = dp[i][j];
        if(j>=a[i]&&dp[i+1][j]<=dp[i][j-a[i]]+b[i]){
          dp[i+1][j] = dp[i][j-a[i]]+b[i];
        }
      }
    }
    ans = max(ans,dp[n][t-1]+v[idx].first.first);
    a[v[idx].second]=v[idx].first.second;
    b[v[idx].second]=v[idx].first.first;
    idx++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 70784