akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;bool f=0;register char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return f?-x:x;
}
void wi(int x)
{
	if(x<0)	putchar('-'),x=-x;
	if(x>9)	wi(x/10);
	putchar(x%10+'0');
}
const int N=105,M=N*N;
ll inf=1e18;
int head[N],cur[N],nxt[M<<1],to[M<<1],q[N],dep[N],S,T;
ll val[M<<1];
inline void ade(int x,int y,ll z)
{
	nxt[++nxt[0]]=head[x];
	head[x]=nxt[0];
	to[nxt[0]]=y;
	val[nxt[0]]=z;
}
inline void ins(int x,int y,ll z)
{
	ade(x,y,z);ade(y,x,0);
}
inline bool bfs()
{
	int he=1,ti=0,now,tmp;
	memcpy(cur,head,sizeof(cur));
	memset(dep,-1,sizeof(dep));
	q[++ti]=S;dep[S]=1;
	while(he<=ti)
	{
		tmp=q[he++];
		for(now=head[tmp];now;now=nxt[now])
		{
			if(dep[to[now]]==-1&&val[now])
			{
				dep[to[now]]=dep[tmp]+1;
				q[++ti]=to[now];
			}
		}
	}
	return dep[T]!=-1;
}
ll dfs(int x,ll f)
{
	if(x==T)	return f;
	ll res=0;
	for(int &now=cur[x];now;now=nxt[now])
	{
		if(dep[to[now]]==dep[x]+1&&val[now])
		{
			ll tmp=dfs(to[now],min(f,val[now]));
			if(tmp)
			{
				val[now]-=tmp;
				val[now^1]+=tmp;
				res+=tmp;
				f-=tmp;
				if(f==0)	return res;
			}
		}
	}
	dep[x]=-1;
	return res;
}
ll dinic()
{
	ll res=0;
	while(bfs())	res+=dfs(S,inf);
	return res;
}
const int NN=105;
int a[NN];
int main()
{
	int n=ri(),j,i;
	ll res=0;
	nxt[0]=1;
	S=n+1,T=n+2;
	for(i=1;i<=n;i++)
	{
		a[i]=ri();
		if(a[i]>0)	ins(S,i,a[i]),res+=a[i];
		else	ins(i,T,-a[i]);
	}
	for(i=1;i<=n;i++)
		for(j=i+i;j<=n;j+=i)	ins(j,i,inf);
	cout<<res-dinic();
	return 0;
}


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

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

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll k;
    cin >> k;
    ll a, b;
    cin >> a >> b;
    string ans = "NG";
    for(ll i = a; i <= b; i++){
        if(i % k == 0){
            ans = "OK";
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 3572
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
int n;
int a[100005];
int b[100005],pre[100005];
int ll[100005],rr[100005];
int mergesort(int l,int r){
	if(l==r)return 0;
	int mid=l+r>>1;
	int ret=mergesort(l,mid);
	ret+=mergesort(mid+1,r);
	for(int i=l;i<=(l+r)/2;i++)ll[i]=pre[i];
	for(int i=(l+r)/2+1;i<=r;i++)rr[i]=pre[i];
	int pos=l,lpos=l,rpos=mid+1;
	while(lpos!=mid+1||rpos!=r+1){
		if(lpos==mid+1){pre[pos++]=rr[rpos++];continue;}
		if(rpos==r+1){pre[pos++]=ll[lpos++];continue;}
		if(ll[lpos]<=rr[rpos]){
			ret+=(r+1-rpos);
			pre[pos++]=ll[lpos++];
		}else{
			pre[pos++]=rr[rpos++];
		}
	}
	return ret;
}
bool check(int v){
	for(int i=1;i<=n;i++)b[i]=(a[i]>=v?1:-1);
	pre[0]=0;
	for(int i=1;i<=n;i++)pre[i]=pre[i-1]+b[i];
	int sum=mergesort(0,n);
//	cerr<<v<<" "<<sum<<endl;
	return sum>=1ll*n*(n+1)/4;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	if(n==1){
		cout<<a[1]<<endl;
		return 0;
	}
	int l=-1,r=2e9;
	while(r-l>1){
		int mid=l+r>>1;
		if(check(mid))l=mid;
		else r=mid;
	}
	cout<<l<<endl;
	return 0;
}

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

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

  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	char a[1000],b[1000];
	scanf("%s%s",a,b);
	for(int i=0;i<max(strlen(a),strlen(b));i++){
		if(a[i]>='a'&&a[i]<='z')cout<<a[i];
		if(b[i]>='a'&&b[i]<='z')cout<<b[i];
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    ll N, A, B;
    cin>>N>>A>>B;
    if((B-A)%2==0) cout<<(B-A)/2<<endl;
    else{
        cout<<min((A+B-1)/2, (2*N-A-B+1)/2)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	
	void doIt() {
		Scanner stdIn = new Scanner(System.in);
		String input = stdIn.nextLine();
		input += " ~";
		String[] str = input.split(" ");
		TreeSet<String> repete = new TreeSet<String>();
		
		Arrays.sort(str);
		//System.out.println(Arrays.toString(str));
		String len = "", mode = str[0];
		int count = 1, max = -1;
		for(int r = 1; r < str.length; r++) {
			if(str[r].length() > len.length()) len = str[r]; 
			if(repete.contains(str[r])) {
				count++;
			} else {
				if(count > max) {
					max = count;
					mode = str[r - 1];
					//System.out.println(count + ", " + mode);
				}
				repete.add(str[r]);
				count = 1;
			}
			//System.out.println(count);
		}
		
		System.out.println(mode + " " + len);
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().doIt();
	}

}

Measured memory_bytes: 17136
#pragma region Macros
#include <bits/stdc++.h>

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

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { 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; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i=0; i<n; i++) {
        cin >> h.at(i);
    }
    sort(h.begin(), h.end());
    ll res = 0;
    for (int i=0; i<n-k; i++) {
        res += h.at(i);
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


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

int main() {
	int N;
	int l[100000], r[100000];
	int sum = 0;
	
	cin >> N;
	
	for(int i=0; i<N; i++){
		cin >> l[i] >> r[i];
		if(l[i] != r[i]){
			r[i]++;
			sum += r[i] - l[i];
		}
		else if(l[i] == r[i]){
			sum++;
		}
	}
	
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int a,b;
	cin >> a >> b;
	for (int i=1; i <=3;i++) {
		if ((a * b * i) %2 ==1) {
			cout << "Yes" <<endl;
			return 0;
		}
	}
	cout << "No" <<endl;
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

#define F first
#define S second

int L, n;
vector<pair<ll, pi> > v;

int main(){
	
	cin >> L >> n;
	rep(i, n){
		int p, d, t;
		cin >> p >> d >> t;
		
		v.pb(mp(p, mp(d, t)));
	}
	v.pb(mp(L, mp(0, 0)));
	sort(all(v));
	
	priority_queue<pi> q;
	set<int> vis;
	
	q.push(mp(-v[0].F, 0));
	
	
	while(!q.empty()){
		
		ll cur = q.top().S;
		ll t = q.top().F; q.pop();
		
		if(vis.count(cur)) continue;
		vis.insert(cur);
		
		if(cur == n){
			
			cout << -t << endl;
			return 0;
		}
		
		q.push(mp(t - (v[cur + 1].F - v[cur].F), cur + 1));
		
		ll nt = t - v[cur].S.S;
		int pos = lower_bound(all(v), mp(v[cur].F + v[cur].S.F, pi(0, 0))) - v.begin();
		
		if(v[cur].F + v[cur].S.F > L) continue;
		
		nt -= max(0ll, v[pos].F - (v[cur].F + v[cur].S.F));
		q.push(mp(nt, pos));
	}
	
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279

#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 1; i <= n; i++)
#define REPR(i, n) for(ll i = n; i >= 1; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
const ld INF = 1e9+123;
#define VEC(type,A,N) vector<type> A(N+10)
#define VECi(type,A,N,i) vector<type> A(N+10,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N+10,vector<type>(M+10))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N+10,vector<type>(M+10,i))
#define ALL(v) v.begin()+1, v.end()-9
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ll N;
    cin>>N;
    string S;
    cin>>S;
    
    ll mi=1,m=0;
    string s="";
    REP(i,N){
        ll tm=0;
        REP(j,i){
            REP(k,N-i){
                //sl(j,k+i,S[j-1],S[k+i-1]);
                if(s.find(S[j-1])==-1&&S[j-1]==S[k+i-1]){
                    s+=S[j-1];
                    tm++;
                    break;
                }
            }
        }
        //sl(tm)
        s="";
        if(m<tm){
            m=tm;
            mi=i;
        }
    }
    cout<<m;
    //cout<<fixed<<setprecision(15)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K;
    cin >> N >> K;
    int ans = 0;
    while (N != 0) {
        N = N / K;
        ++ans;
    }
    cout << ans << endl;
}


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

typedef long long ll;

int main() {
    ll D,N;
    cin >> D >> N;
    
    if ( N != 100 ){
        if ( D == 0 ) cout << N << endl;
        else if ( D == 1 ) cout << 100 * N << endl;
        else cout << 10000 * N << endl;
    } else {
        if ( D == 0 ) cout << 101 << endl;
        else if ( D == 1 ) cout << 10100 << endl;
        else cout << 1010000 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3552
n,a,b,c,d = map(int,input().split())
s = list(input())
n = n-(a-1)
b = b-(a-1)-1
c = c-(a-1)-1
d = d-(a-1)-1
for i in range(a-1):
    s.pop(0)
a = a-(a-1)-1
for i in range(n-(max(c,d)+1)):
    s.pop(-1)
n -= n-(max(c,d)+1)

check = True
for i in range(n-1):
    if s[i] == "#" and s[i+1] == "#":
        check = False

temp = False
for i in range(b,d+1):
    if i+1 < n:
        if s[i] == "." and s[i-1] == "." and s[i+1] == ".":
            temp = True
            break
    else:
        temp = True


if check == False:
    print("No")
else:
    if temp:
        print("Yes")
    else:
        print("No")

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

int main() {

  string S;
  cin >> S;
  if(S[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }
  int count_c = 0;
  int iter_c;
  for(int i=2; i<S.size()-1; i++) {
    if(S[i] == 'C'){
      iter_c = i;
      count_c++;
    }
  }
  if(count_c != 1) {
    cout << "WA" << endl;
    return 0;
  }

  for(int i=1; i<S.size(); i++) {
    if(i != iter_c && S[i] < 'a') {
      cout << "WA" << endl;
      return 0;
    }
  }
  cout << "AC" << endl;
  return 0;
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import copy

def main():
    N,M,K = map(int,input().split())
    MOD = 10**9+7
    fac = [0 for _ in range(N*M-1)]
    fac[0],fac[1] = 1,1
    inv = copy.deepcopy(fac)
    invfac = copy.deepcopy(fac)
    
    for i in range(2,N*M-1):
        fac[i] = (fac[i-1]*i)%MOD
        inv[i] = MOD-(MOD//i)*inv[MOD%i]%MOD
        invfac[i] = (invfac[i-1]*inv[i])%MOD
        
    def coef(x,y):
        num = (((fac[x]*invfac[y])%MOD)*invfac[x-y]%MOD)
        return num

    xa = ((M**2)*N*(N-1)*(N+1)//6)%MOD
    ya = ((N**2)*M*(M-1)*(M+1)//6)%MOD
    print((xa+ya)*coef(N*M-2,K-2)%MOD)

if __name__ == "__main__":
    main()


Measured memory_bytes: 27320
from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
sary = sorted(["".join(sorted(stdin.readline().rstrip())) for _ in range(n)])

gr = groupby(sary)

res = 0

for k, g in gr:
    num = len(list(g))
    if  num >= 2:
        res += num * (num - 1) // 2

print(res)

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

int main() {
  int N;
  cin >> N;
  long long a = 0, b = 0;
  for (int i = 0; i < N; ++i) {
    long long x; cin >> x;
    a += x * x;
    b += x;
  }
  cout << (b*b - a) / 2 << endl;
}
  
  
  
  

Measured memory_bytes: 3596
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
stack<int> S1;
stack<pair<int,int> >S2;
char ch;
int sum=0;
for(int i=0;cin>> ch;i++){
if(ch=='\\')S1.push(i);
else if(ch=='/' && S1.size()>0){
int j=S1.top();
S1.pop();
sum+=i-j;
int a=i-j;
while(S2.size()>0&& S2.top().first>j){
a+=S2.top().second;
S2.pop();
}
S2.push(make_pair(j,a));
}
}
vector<int>ans;
int t=0;
while(S2.size()>0){
ans.push_back(S2.top().second);
S2.pop();
}
reverse(ans.begin(),ans.end());
cout<<sum<<endl;
cout<<ans.size();
for(int i=0;i<ans.size();i++){
cout<<" ";
t+=ans[i];
cout<< ans[i];
}
cout << endl;
return 0;
}

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

#define show_vars(args...) {\
  string vars_names = #args;\
  replace(begin(vars_names), end(vars_names), ',', ' ');\
  stringstream _ss(vars_names);\
  istream_iterator<string> it(_ss);\
  _show_vars(it, args); }

// base case
void _show_vars(istream_iterator<string>) {}

template<typename T, typename ...Types>
void _show_vars(istream_iterator<string> it, T val, Types ... args) {
  cout << *it++ << " = " << val << endl;
  _show_vars(it, args...);
}

// overload to be able to print vector
template<typename T, typename ...Types>
void _show_vars(istream_iterator<string> it, vector<T> val, Types ... args) {
  cout << *it++ << " = \n";
  for(const auto& v: val) cout << v << " ";
  cout << endl;
  _show_vars(it, args...);
}


int main(int argc, char* argv[]) {
  unsigned long long H,W;
  cin >> H >> W;
  if( (H == 1) || (W == 1) ) {
    cout << 1 << endl;
  } else cout << ((H*W)/2 + H*W%2) << endl;
  
  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
using namespace std;

void solve(){
  int h, w; cin >> h >> w;
  vector<vector<char> > v(h, vector<char>(w));
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> v[i][j];
    }
  }
  for(int i = 0; i < v.size(); i++){
    int j = 0;
    for(; j < v[i].size(); j++){
      if(v[i][j] != '.') break;
    }
    if(j == v[i].size()){
      v.erase(v.begin() + i);
      i = -1;
      /*cout << endl;
      for(int i = 0; i < v.size(); i++){
        for(int j = 0; j < v[i].size(); j++){
          cout << v[i][j];
        }
        cout << endl;
      }*/
    }
  }
  int i = 0;
  while(i < v[0].size()){
    int j = 0;
    for(; j < v.size(); j++){
      if(v[j][i] != '.') break;
    }
    if(j == v.size()){
      for(int k = 0; k < v.size(); k++){
        v[k].erase(v[k].begin() + i);
      }
    }
    else i++;
  }




  /*for(int i = 0; i < v[i].size(); i++){
    cout << "v[" << i << "].size: " << v[i].size() << endl;
    int j = 0;
    for(; j < v.size(); j++){
      if(v[j][i] != '.') break;
    }
    if(j == v.size()){
      for(int k = 0; k < v.size(); k++){
        v[k].erase(v[k].begin() + i);
      }
      i = -1;
      cout << endl;
      for(int i = 0; i < v.size(); i++){
        for(int j = 0; j < v[i].size(); j++){
          cout << v[i][j];
        }
        cout << endl;
      }
    }
    if(i + 1 >= v.size()) break;
  }*/

  for(int i = 0; i < v.size(); i++){
    for(int j = 0; j < v[i].size(); j++){
      cout << v[i][j];
    }
    cout << endl;
  }
  return;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
N,x=map(int,input().split())
A=list(map(int,input().split()))
if A[0]>x:
  ans=A[0]-x
  A[0]=x
else:
  ans=0
for i in range(1,N):
  s=A[i]+A[i-1]
  if s>x:
    ans+=(s-x)
    A[i]-=(s-x)
print(ans)


Measured memory_bytes: 14540
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
	ll q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	ll a = min(q * 2, h);
	ll b = min(a * 2, s);
	ll c = min(b * 2, d);
	if (n == 1)cout << b << endl;
	else {
		if (n % 2 == 0)cout << n / 2 * c << endl;
		else cout << (n - 1) / 2 * c + b << endl;
	}
}

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

using namespace std;

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;

int main() {
  int n, y;
  fscanf(stdin, "%d%d ", &n, &y);
  y /= 1000;
  int done = 0;
  REP(i,n+1) {
    REP(j,n-i+1) {
      if (i * 10 + j * 5 + (n - (i + j)) == y) {
        fprintf(stdout, "%d %d %d\n", i, j, n - i - j);
        done = 1;
      }
      if (done) break;
    }
    if (done) break;
  }
  if (!done) puts("-1 -1 -1");
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ll N, K;
	cin >> N >> K;

	vector <int> A(N);
	for (int ii = 0; ii < N; ++ii){
		cin >> A[ii];
		A[ii]--;
	}

	vector <int> vlist;
	vector <int> ord(N, -1);
	int idx = 0;
	ord[idx] = vlist.size();
	vlist.push_back(idx);
	int threshold = 0;
	while (true) {
		int idx = A[idx];
		if (ord[idx] != -1){
			threshold = ord[idx];
			break;
		}
		ord[idx] = vlist.size();
		vlist.push_back(idx);
	}

	ll ans = 0;
	if (K <= threshold){
		ans = vlist[K] + 1;
	} else {
		ll loop = vlist.size() - threshold;
		ll rem = (K - threshold) % loop;
		ans = vlist[threshold + rem] + 1;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5864
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007

int now,n,k;

int main(){
  int ans=0;
  cin >> n ;
  vector<int> a(n+1),b(n+1);
  REP(i,n) cin>>a[i+1];

for(int i=n;i>=1;i--){
    if (i>(n/2)){
        b[i]=a[i];
    }else{
        for(int j=i*2;j<=n;j+=i){
            b[i]+=b[j];
        }
        b[i]=(b[i]+a[i])%2;
    }
}

REP(i,n+1){
    ans+=b[i];
}


cout<<(ans)<<endl;

if (ans!=0){
    REP(i,n+1){
        if (b[i]==1){
            cout<<i<<" ";
        }
    }
    cout<<endl;
}
  return 0;
}

Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		double x1 = stdIn.nextDouble();
		double y1 = stdIn.nextDouble();
		double x2 = stdIn.nextDouble();
		double y2 = stdIn.nextDouble();
		
		System.out.println(Math.sqrt(Math.pow(x2-x1,2)+Math.pow(y2-y1,2)));
	}
}

Measured memory_bytes: 18588
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    s = input()
    k = int(input())
    #LIST = {s}
    #for i in range(k):
    #    for j in range(len(s) - i):
    #        LIST.add(s[j:j+i+1])
    #print(LIST)
    #print(sorted(list(LIST))[k-1])
    # 辞書順で5番目、長さは最長でも5
    r = []
    for i in range(1,6): # 1 ~ 5 文字のながさ 1から5文字まで
        for j in range(len(s) - i + 1): # 見る範囲 len(s) - j  ~ len(s) - j + i まで最後まで見てる!
            r.append(s[j:j+i])
    #print(r)
    print(sorted((set(r)))[k-1])


if __name__ == '__main__':
  main()


Measured memory_bytes: 5068
#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() {
  int N,M,X;
  cin >> N >> M >> X;
  int C[N],A[N][M];
  rep(i,N){
    cin >> C[i];
    rep(j,M){
      cin >> A[i][j];
    }
  }
  int ans=1200001;
  for(int i=0;i < 1<<N ;i++){
    int sum = 0;
    int Ai[M];
    rep(i,M) Ai[i] = 0;
    for(int j=0;j<N;j++){
      if((i>>j)%2==1){
        sum += C[j];
        rep(k,M){
          Ai[k] += A[j][k];
        }
      }
    }
    int flag = 1;
    rep(j,M){
      if(Ai[j] < X){
        flag = 0;
      }
    }
    if(flag){
      ans = min(ans,sum);
    }
  }
  if(ans != 1200001) cout << ans << endl;
  else cout << -1 << endl;
  return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

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

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> A(N);

    REP(i, N){
        cin >> A[i];
    }
    
    vector<ll> L(N);
    vector<ll> R(N);

    L[0] = A[0];
    for(ll i=1; i<N; i++){
        L[i] = gcd(L[i-1], A[i]);
    }

    R[N-1] = A[N-1];
    for(ll i=N-2; i>0; i--){
        R[i] = gcd(R[i+1], A[i]);
    }

    ll ans = 0;
    ans = max(R[1], L[N-2]);
    for(ll i=1; i<N-1; i++){
        ans = max(ans, gcd(L[i-1], R[i+1]));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a=0, b = 0,c,d, n, k;
string s, t;


int main()
{

	cin >> n;
	vector<string> a(n);
	rep(i, n)
		cin >> a.at(i);
	map<string, int> x;
	int cnt = 1;
	rep(i,n)
	{
		x[a.at(i)] += 1;
		if (x[a.at(i)] > cnt)cnt = x[a.at(i)];
	}
	
	auto begin = x.begin(), end = x.end();
	for (auto s = begin; s != end; s++)
	{
		if (s->second == cnt)
			cout << s->first << endl;
	}
	return 0;
}

Measured memory_bytes: 26752
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

//Nが素数だと1,素数じゃないと0になる関数
int is_prime(int N){
    int ans=1;

    for(int i=2;i*i<=N;i++){
        if(N%i==0){
            ans=0;
            break;
        }
    }
    return ans;
}

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

    int cnt=0;
    int p=2;
    while(cnt<N){
        if(is_prime(p)){
            if(p%5==1){
                printf("%d\n",p);
                cnt++;
            }
        }
        p++;
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 128
N = int(input())
AB = []
ans = 0
for i in range(N):
    a,b = map(int,input().split())
    ans += a
    AB.append(a+b)

AB.sort(reverse=True)
for i in range(N):
    if i%2 == 1:
        ans -= AB[i]

print(ans)

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

long a[111111], b[111111];
int main() {
    long n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        scanf("%ld", a + i);
    sort(a, a + n, greater<>());
    for(int i = 0; i < n; i++)
        b[i + 1] = b[i] + a[i];
    int l = 0, r = 222222;
    long c, d;
    while(l + 1 < r) {
        int k = (l + r) / 2;
        c = d = 0;
        for(int i = 0; i < n; i++) {
            int x = upper_bound(a, a + n, k - a[i], greater<>()) - a;
            c += b[x] + a[i] * x;
            d += x;
        }
        if(d < m)
            r = k;
        else
            l = k;
    }
    c = d = 0;
    for(int i = 0; i < n; i++) {
        int x = upper_bound(a, a + n, l - a[i], greater<>()) - a;
        c += b[x] + a[i] * x;
        d += x;
    }
    cout << c - (d - m) * l << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

map<ii,ll> ma;

bool cmp(pair<ii,ll> a, pair<ii,ll> b)
{
	if(a.fi.fi!=b.fi.fi) return (a.fi.fi<b.fi.fi);
	if(a.fi.se!=b.fi.se) return (a.fi.se>b.fi.se);
	return (a.se<b.se);
}


class LazySegmentTree {
private:
	int size_;
	vector<long long> v, lazy;
	void update(int a, int b, long long x, int k, int l, int r) {
		push(k, l, r);
		if (r <= a || b <= l) return;
		if (a <= l && r <= b) {
			lazy[k] += x;
			push(k, l, r);
		}
		else {
			update(a, b, x, k * 2, l, (l + r) >> 1);
			update(a, b, x, k * 2 + 1, (l + r) >> 1, r);
			v[k] = merge(v[k * 2], v[k * 2 + 1]);
		}
	}
	long long query(int a, int b, int k, int l, int r) {
		push(k, l, r);
		if (r <= a || b <= l) return 0;
		if (a <= l && r <= b) return v[k];
		long long lc = query(a, b, k * 2, l, (l + r) >> 1);
		long long rc = query(a, b, k * 2 + 1, (l + r) >> 1, r);
		return merge(lc, rc);
	}
 
public:
	LazySegmentTree() : v(vector<long long>()), lazy(vector<long long>()) {};
	LazySegmentTree(int n) {
		for (size_ = 1; size_ < n;) size_ <<= 1;
		v.resize(size_ * 4,0);
		lazy.resize(size_ * 4,0);
	}
	inline void push(int k, int l, int r) {
		if (lazy[k] != 0) {
			v[k] += lazy[k];
			if (r - l > 1) {
				lazy[k * 2] += lazy[k];
				lazy[k * 2 + 1] += lazy[k];
			}
			lazy[k] = 0;
		}
	}
	inline long long merge(long long x, long long y) {
		return min(x,y);
	}
	inline void update(int l, int r, long long x) {
		update(l, r, x, 1, 0, size_);
	}
	inline long long query(int l, int r) {
		return query(l, r, 1, 0, size_);
	}
};

vector<ii> V[222222];
ll dp[222222];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m; cin>>n>>m; ll sum=0;
	for(int i=0;i<m;i++)
	{
		int l,r; ll w; cin>>l>>r>>w;
		ma[mp(l,r)]+=w; sum+=w;
	}
	vector<pair<ii,ll> > vec;
	for(auto X:ma)
	{
		vec.pb(X);
	}
	sort(vec.begin(),vec.end(),cmp);
	for(auto X:vec)
	{
		V[X.fi.se].pb(mp(X.fi.fi,X.se));
	}
	LazySegmentTree st(n+5);
	for(int i=1;i<=n+1;i++)
	{
		dp[i] = st.query(0,i);
		//cerr<<i<<' '<<dp[i]<<'\n';
		for(ii v:V[i])
		{
			st.update(0,v.fi,v.se);
		}
		st.update(i,i+1,dp[i]);
	}
	cout<<sum-dp[n+1]<<'\n';
}


Measured memory_bytes: 48236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M;
int cnt[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    cnt[a-1]++;
    cnt[b-1]++;
  }
  bool yes = true;
  for (int i = 0; i < N; i++) {
    yes &= cnt[i] % 2 == 0;
  }
  cout << (yes ? "YES" : "NO") << endl;

  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,C1,C2,C3,C4;
    cin >> N;
    C1=0;
    C2=0;
    C3=0;
    C4=0;
    string str;
    for(int i=0;i<N;i++){
        cin >> str;
        if(str=="AC")C1++;
        if(str=="WA")C2++;
        if(str=="TLE")C3++;
        if(str=="RE")C4++;
    }
    cout << "AC x " << C1 << endl;
    cout << "WA x " << C2 << endl;
    cout << "TLE x " << C3 << endl;
    cout << "RE x " << C4 << endl;
}


Measured memory_bytes: 3624
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

ll const mod = 1000000007;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll w, h, x, y;
  cin >> w >> h >> x >> y;

  double s = (double)(w * h) / 2.0;

  cout << s << " " << (w == 2 * x && h == 2 * y) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int h,w,a,b;
 	cin >> h>>w>>a>>b;
 	for (int i = 0; i < h; i++){
 		for (int j = 0; j < w; j++)
 		if(i<b^j<a){
 			cout << 0;
 		}else{
 			cout << 1;
 		}
 		cout <<  endl;
 	}
 }

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int main() {
	int a, b;
	cin >> a >> b;
	cout << 6 - a - b << endl;

}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
int main()
{
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  rep(i, H)
  {
    cin >> a[i];
  }
  vector<bool> row(H, false);
  vector<bool> col(W, false);
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      if (a[i][j] == '#')
      {
        row[i] = true;
        col[j] = true;
      }
    }
  }

  for (int i = 0; i < H; i++)
  {
    if (row[i])
    {
      for (int j = 0; j < W; j++)
      {
        if (col[j])
        {
          cout << a[i][j];
        }
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	int N=sc.nextInt();
	String S2=sc.next();
	String S[]=S2.split("");
	long ans=0;
	if(N<=3) {
		System.out.println(0);
	}else {
		long Rnum=0;
		long Gnum=0;
		long Bnum=0;
		for(int i=0;i<N;i++) {
			if(S[i].equals("R")) {
				Rnum++;
			}else if(S[i].equals("G")) {
				Gnum++;
			}else {
				Bnum++;
			}
		}
		ans=Rnum*Gnum*Bnum;
		for(int j=1;j<N-1;j++) {
			for(int i=j-1,k=j+1;i>=0&&k<N;i--,k++) {
				if(!S[j].equals(S[i])&&!S[j].equals(S[k])&&!S[k].equals(S[i])) {
					ans--;
				}
			}
		}
		System.out.println(ans);


	}
	}
}


Measured memory_bytes: 37108
#include<bits/stdc++.h>
using namespace std;
main()
{
	int n,m,i,p,q;
	cin>>n>>m;
	int a[n];
	int b[n];
	map<int,int>mp;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		b[i]=0;
	}
	for(i=0;i<m;i++)
	{
		cin>>p>>q;
			if(a[p-1]>a[q-1])
			b[q-1]=1;
			else if(a[p-1]<a[q-1])
			{
				b[p-1]=1;
			}
			else if(a[p-1]==a[q-1])
			{
				b[p-1]=1;
				b[q-1]=1;
			}
		
		
	}
	int c=0;
	for(i=0;i<n;i++)
	{
		if(b[i]==0)
		c++;
	}
	cout<<c<<endl;
 
}

Measured memory_bytes: 4360
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const int INF = pow(2,30);
const int MOD = 1000000007;
const int N_MAX = pow(10,5);

vector<int> dp(N_MAX+10, INF); 

int dfs(int n) {
  if (n==0) return dp[0] = 0;
  if (dp[n]!=INF) return dp[n];
  int result = dfs(n-1)+1;
  for(int i=1; pow(6,i)<=n; i++) result = min(result, dfs(n-pow(6,i))+1);
  for(int i=1; pow(9,i)<=n; i++) result = min(result, dfs(n-pow(9,i))+1);
  return dp[n] = result;
}

int main() {
  int N; cin >> N;
  dfs(N);
  cout << dp[N] << endl;
  return 0;
}

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


#define lld long long 

lld max(lld x,lld y)
{
	if(x>y)
		return x;
	return y;
}		
lld min(lld x,lld y)
{

	if(x<y)
		return x;
	return y;
}

int main()
{
	double n;
	cin>>n;
	n=n/3;
	double x=n*n*n;
	
	cout<<setprecision(8)<<x<<"\n";
}

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

int main() {

    std::string str;
    int m;

    for ( ;; ) {

        std::cin >> str;

        if ( str == "-" ) break;

        std::cin >> m;

        for ( int i = 0; i < m; i++ ) {

            int h;

            std::cin >> h;

            str = str.substr(h) + str.substr(0, h);
        }

        std::cout << str << std::endl;
    }

    return 0;
}



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

#define pb push_back
#define ppp pop_back
#define fi first
#define se second
#define pii pair<int,int>

const int N = 100005;
const ll inf = 1e18;

vector<vector<int> > g[N];

bool processed[N];
ll dist[3][N];

void dijkstra(int v, int currency) {
    for (int i=0; i<N; i++) processed[i] = false;
    for (int i=0; i<N; i++) dist[currency][i] = inf;
    priority_queue<pair<ll, int> > q;
    q.push({0, v});
    dist[currency][v] = 0;
    while (!q.empty()) {
        int u = q.top().se;
        q.pop();
        if (processed[u]) continue;
        processed[u] = true;
        for (vector<int> w : g[u]) {
            if (dist[currency][u] + w[currency] < dist[currency][w[0]]) {
                dist[currency][w[0]] = dist[currency][u] + w[currency];
                q.push({-dist[currency][w[0]], w[0]});
            }
        }
    }
}

set<ll> a;
map<ll, int> cnt;
ll b[N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
   freopen("input.txt", "r", stdin);
#endif
    int n,m,s,t;
    cin >> n >> m >> s >> t;
    for (int i=1; i<=m; i++) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        g[u].pb({v, a, b});
        g[v].pb({u, a, b});
    }
    dijkstra(s, 1);
    dijkstra(t, 2);
    for (int i=1; i<=n; i++) {
        b[i] = dist[1][i] + dist[2][i];
        cnt[b[i]]++;
        a.insert(b[i]);
    }
    ll ans = 1e15;
    cout << ans - *(a.begin()) << "\n";
    for (int i=1; i<=n-1; i++) {
        cnt[b[i]]--;
        if (cnt[b[i]] == 0) a.erase(b[i]);
        cout << ans - *(a.begin()) << "\n";
    }
}

Measured memory_bytes: 30080
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn dfs(edges: &Vec<Vec<usize>>, cur: usize, par: usize, pxs: &Vec<usize>, ans: &mut Vec<usize>) {
    ans[cur] = pxs[cur];
    if par != edges.len() {
        ans[cur] += ans[par];
    }
    for &nd in edges[cur].iter() {
        if nd != par {
            dfs(edges, nd, cur, pxs, ans);
        }
    }
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      q: usize,
      abs: [(usize1, usize1); n-1],
      pxs: [(usize1, usize); q],
    }

    let mut edges = vec![vec![]; n];
    for (a, b) in abs {
        edges[a].push(b);
        edges[b].push(a);
    }

    let mut psums = vec![0; n];
    for (p, x) in pxs {
        psums[p] += x;
    }

    let mut ans = vec![0; n];
    dfs(&edges, 0, n, &psums, &mut ans);

    for i in 0..ans.len() {
        if i == ans.len() - 1 {
            puts!("{}", ans[i]);
        } else {
            puts!("{} ", ans[i]);
        }
    }
    puts!("\n")
}


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

#define int long long

using namespace std;

 

const int mod=1e9+7;

const int Max=100005;

int n,m,s;

int sum[Max];

 

inline int ksm(int a,int b)

{

	int ans=1;

	while(b)

	{

	  if(b&1) ans=(ans*a)%mod;

	  b>>=1;

	  a=(a*a)%mod;

	}

	return ans;

}

 

signed main()

{

	scanf("%d",&n);

	for(int i=1;i<=n;i++) scanf("%d",&m),sum[m]++;

	for(int i=0;i<n;i++) if(sum[i]>=3) {cout<<"0";return 0;}

	if((n&1&&sum[0]!=1)||(!(n%2)&&sum[0])) {cout<<"0";return 0;}

	cout<<ksm(2,n/2);

	return 0;

}


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

int main() {
  int K,N;
  cin >> K >> N;
  
  vector<int>A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  vector<int>B(N);
  for (int i = 0; i < N-1; i++) {
    B.at(i) = A.at(i+1) - A.at(i);
  }
  
  if (A.at(N-1) - A.at(0) > K/2){
    B.at(N-1) = K - (A.at(N-1) - A.at(0));
  }
  else {
    B.at(N-1) = A.at(N-1) - A.at(0);
  }

  sort(B.begin(), B.end());
  cout << K - B.at(N-1) << endl;
}



Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int vec_find(vector <string> vec, string n)
{
    for (size_t i = 0; i < vec.size(); i++){
        if (vec.at(i) == n)
            return 1;
    }
    return 0;
}

int main()
{
    int N; cin >> N;
    vector <string> W(N);
    vector <string> W2;
    for (int i = 0; i < N; i++){
        cin >> W.at(i);
    }

    int cnt = 0;
    for (int i = 1; i < N; i++){
        int w_size = W.at(i-1).length();
        if (W.at(i - 1).at(w_size - 1) == W.at(i)[0])
            cnt += 1;
    }

    for (int i = 0; i < N; i++ ){
        if (vec_find(W2,W.at(i)) == 0){
            W2.push_back(W.at(i));
        }else{
            cout << "No" << endl;
            return 0;
        }
    }

    if (cnt == N - 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    //N個の宮殿
    //地点の高さがHにそれぞれ入っている
    //平均気温がAに最も近くなる地点を選ぶ
    //T-Hi＊０.06で平均気温が求まる。
    

    int N, T, A;
    int min_value = 1e7;
    int ans;
    cin >> N >> T >> A;

    for(int i = 0; i < N; i++){
        int H;
        cin >> H;
        int tmp = T*1000 - H * 6;
        int tmp2 = abs(tmp-A*1000);
        if(min_value > tmp2){
            ans = i + 1;
            min_value = tmp2;
        }
    }

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


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a,0,sizeof(a))
#define minus(a) memset(a,0xff,sizeof(a))
#define chmax(a,b) a=min((a),(b))
#define chmin(a,b) a=max((a),(b))


#define MOD 1000000007LL

typedef pair<int,int>P;
#define INF (1<<29)
 
struct edge { 
	int from, to; 
	edge (int from, int to){
		this->from=from; this->to=to;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

int down[100005];
int a[100005];
int cnt[100005];
int l, r;
ll inv[100005];
ll f[100005];

void fact(ll a) {
	ll ret = 1LL;
	for (ll i = 1; i <= a; i++) {
		ret = ret*i%MOD;
		f[i] = ret;
	}
	
}

ll beki(ll a, ll p) {
	ll ret = 1LL;
	while (p > 0) {
		if (p & 1) {
			ret = ret*a%MOD;
		}
		a = a*a%MOD;
		p >>= 1;
	}
	return ret;
}

ll comb(ll a, ll b) {
	if (a < 0 || b < 0 || a < b)return 0LL;
	if (a == b || b == 0)return 1LL;
	ll ret = f[a]*inv[b]%MOD;
	ret = ret*inv[a - b] % MOD;
	return ret;

}

int main() {
	int n;
	scanf("%d ", &n);
	rep(i, n+1) {//
		scanf("%d ", &a[i]);
		cnt[a[i]]++;
		if (cnt[a[i]] == 2) {
			r = i;
		}

	}

	rep(i,n+1){
		if (a[i] == a[r]) {
			l = i;
			break;
		}
	}
	l++; r++;
	f[0] = 1;//
	fact(n + 1);//


	inv[0] = 1;//
	FOR(i, 1, n + 1) {
		inv[i] = beki(f[i], MOD - 2);
	}
	
	FOR(i,1,n+1) {
		printf("%lld\n", (comb(n + 1, i) + MOD - comb(n - r + l, i - 1)) % MOD);

	}
	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int input,odd=1,even=1;
	cin>>input;
	if (input%2==0)
	{
		even=input/2;
		odd=input-even;
	}
	else
		{
			odd=input/2 +1;
			even=input-odd;
		}
	cout<<odd*even;
	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>;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//無限大
const ll INF = 1LL << 60;


//------------------------------------------------
int main() {

    //DPテーブル初期化
    ll dp[100010];
    rep(i,100010) dp[i] = INF;
    dp[0] = 0;

    //main
    int N,K;
    cin >> N >> K;

    ll h[100010];
    rep(i,N) cin >> h[i];

    rep(i,N){
        for (int j = 1; j <= min(K,i); ++j ){
            chmin( dp[i], dp[i-j] + abs(h[i]-h[i-j]) );
        }
    }

    //answer
    cout << dp[N-1] << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  int count = 0;
  for(int j=0; j<N-2; j++){
    if(vec.at(j) == vec.at(j+1)){
      if(vec.at(j)+1 == vec.at(j+2)){
        vec.at(j+1) = vec.at(j) + 2;
      }
      else{
      vec.at(j+1) = vec.at(j) + 1;
      }
      count++;
    }
  }
  if(vec.at(N-2) == vec.at(N-1)){
    count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1e9+7;




int main(){
int N,M;
cin>>N>>M;
Graph G(N+1);
int ine[N+1];
memset(ine,0,sizeof(ine));
rep(i,M){
    int x,y;
    cin>>x>>y;
    G[x].push_back(y);
    ine[y]++;
}

stack<int> st;
rep3(i,N){
    if(ine[i]==0)st.push(i);
}
vector<int> toposort;

while(!st.empty()){
    int v= st.top();
    st.pop();
    toposort.push_back(v);
    for(auto j : G[v]){
        ine[j]--;
        if(ine[j]==0)st.push(j);
    }


}
int dp[N+1];
memset(dp,0,sizeof(dp));
rep(i,toposort.size()){


    for(auto j : G[toposort[i]]){
        dp[j]=max(dp[j],dp[toposort[i]]+1);
    }

}
int ans=0;
rep3(i,N)ans=max(ans,dp[i]);
cout<<ans<<endl;


   

return 0;
}

Measured memory_bytes: 9668