akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
using namespace std; 
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define forp(i,a,b) for (int i = a; i <b; i++)
#define forn(i,a,b) for (int i = a; i >b; i--)
#define mod 1000000007
#define multiple_testcases_t int t;cin>>t;while(t--){solve();}
#define single_testcase_t solve();
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;


ll fact(ll n)
{
  if(n==0 || n==1)
  return 1;
  else
  return (n*fact(n-1)%mod)%mod;
}

int prime(ll n)
{
  for(int i=2;i<=sqrt(n);i++)
  {
    if(n%i==0)
    {
      return 0;
    }
  }
  return 1;
}

ll gcd(ll a,ll b)
{
  if(a==0)
  return b;
  else
  return gcd(b%a,a);
}

ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}

int check_palin(string s)
{
  string str=s;
  reverse(str.begin(),str.end());
  if(str==s)
  return 1;
  else 
  return 0;
}

vector<ll> divisors(ll n)
{
  vector<ll> v;
  for(int i=2;i<=sqrt(n);i++)
  {
    if(n%i==0)
    {
      if(i==n/i)
      v.PB(i);
      else
      v.PB(i),v.PB(n/i);
    }
  }
return v;
}

ll bin_expo(int x,int n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_expo(x*x,n/2);
    else                             //n is odd
        return x*bin_expo(x*x,(n-1)/2);
}

ll modular_expo(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return modular_expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*modular_expo((x*x)%M,(n-1)/2,M))%M;
}

// <----- Actual solve() function to print output -----> //
void solve()
{
  ll n,ans=0,z=0;
  cin>>n;
  ll a[n];
  map<ll,ll> mp;
  forp(i,0,n)
  {
    cin>>a[i];
    mp[a[i]]++;
    ans+=a[i];
  }
ll x,y;
  cin>>z;
  while(z--)
  {
      cin>>x>>y;
      ans-=mp[x]*x;
      
      mp[y]+=mp[x];
      ans+=mp[x]*y;

      mp[x]=0;
      cout<<ans<<"\n";
  }
  //cout<<"\n";      //if t>1 uncomment this
}

// MAIN function --------------------------------------------------------------------------//
int main()
{
    fast_io
    single_testcase_t   //Uncomment this if only single testcase & single answer to print
   // multiple_testcases_t  //Uncomment this if t>1(t is given in question)(multiple testcases)      
return 0;
}
            
            
            
            


Measured memory_bytes: 10252
/*input
149696127901
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}


void solve(){
	int n;cin >> n;
	int x = (n+10)/11;
	if( (11*x)-5 >= n)cout << (2*x)-1;
    else cout << 2*x;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;//cin >> t;
  WL(t)solve();
  return 0;
}

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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int a,b,c;

    cin>>a>>b>>c;

    cout<<max(c-(a-b),0)<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
using namespace std;

int main(){
    int n,m,X,Y;
    cin >> n >> m >> X >> Y;
    int x[n],y[m];
    for(int i=0;i<n;i++) cin >> x[i];
    for(int i=0;i<m;i++) cin >> y[i];

    for(int z=X+1;z<Y;z++){
        bool nowar=true;
        for(int i=0;i<n;i++){
            if(z <= x[i]) nowar=false;
        }
        for(int i=0;i<m;i++){
            if(y[i] < z) nowar=false;
        }
        if(nowar){
            cout << "No War" << endl;
            return 0;
        }
    }
    cout << "War" << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int h[100009];
int main(){
	int n;
	long long int a,b;
	cin>>n>>a>>b;
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	long long int sa=a-b;
	long long int mi=0,ma=1000000000,mid;
	while(ma-mi>1){
		mid=(mi+ma)/2;
		long long int cnt=0;
		for(int i=0;i<n;i++){
			if(h[i]>b*mid){
				cnt+=(h[i]-b*mid-1)/sa +1;
			}
		}
		if(cnt>mid){
			mi=mid;
		}
		else{
			ma=mid;
		}
	}
	cout<<ma<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;


typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

ll n, m, u, v, s, d[100000], color[100000], res_sum;
vector<P> e[100000];

bool dfs(ll num, ll col, ll x) {
    if (color[num] == col) {
        if (d[num] != x) {
            res_sum = 1;
            return true;
        }
        return false;
    }
    if (color[num] == -col) {
        if (color[num] == 1) res_sum = x - d[num];
        else res_sum = d[num] - x;
        return true;
    }
    color[num] = col;
    d[num] = x;
    for (P p : e[num]) {
        if (dfs(p.first, -col, p.second - x)) return true;
    }
    return false;
}

bool check(ll num, ll x) {
    if (x <= 0) return false;
    if (d[num] != 0) {
        return d[num] == x;
    }
    d[num] = x;
    for (P p : e[num]) {
        if (!check(p.first, p.second - x)) return false;
    }
    return true;
}

int main() {
    cin >> n >> m;
    for (ll i = 0; i < m; i++) {
        cin >> u >> v >> s;
        u--;
        v--;
        e[u].push_back(P(v, s));
        e[v].push_back(P(u, s));
    }
    if (dfs(0, 1, 0)) {
        for (ll i = 0; i < n; i++) d[i] = 0;
        if (res_sum % 2 == 0 && check(0, res_sum / 2)) printf("1\n");
        else printf("0\n");
    } else {
        ll lb = 1, ub = 1000000000LL;
        for (ll i = 0; i < n; i++) {
            if (color[i] == 1) {
                lb = max(lb, 1 - d[i]);
            } else {
                ub = min(ub, d[i] - 1);
            }
        }
        printf("%lld\n", max(0LL, ub - lb + 1));
    }
}

Measured memory_bytes: 14080
s=input()
ans=0
seq_up=0
seq_down=0
d='>'
u='<'
if s[0]==u:
  seq_up+=1
else:
  seq_down+=1
for i in range(1,len(s)):
  if s[i]==u:
    if s[i]!=s[i-1]:
      ans+=max(seq_up*(seq_up-1)//2,0)
      #print(ans)
      ans+=max(seq_down*(seq_down-1)//2,0)
      #print(ans)
      ans+=max(seq_up,seq_down)
      #print(ans)
      seq_up=1
      seq_down=0
      #print('+',seq_up)
    else:
      seq_up+=1
      #print('+',seq_up)
  else:
    seq_down+=1
    #print('-',seq_down)
m=max(seq_up,seq_down)+1
ans+=m*(m-1)//2
print(ans)

Measured memory_bytes: 4120
from itertools import permutations
import sys

sys.setrecursionlimit(10 ** 6)
from bisect import *
from collections import *
from heapq import *

def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def SI(): return sys.stdin.readline()[:-1]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
int1 = lambda x: int(x) - 1
def MI1(): return map(int1, sys.stdin.readline().split())
def LI1(): return list(map(int1, sys.stdin.readline().split()))
p2D = lambda x: print(*x, sep="\n")
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
    n,t=MI()
    ab=LLI(n)
    ab.sort()
    dp=[-1]*(t+1)
    dp[0]=0
    for a,b in ab:
        for i in range(t-1,-1,-1):
            pre=dp[i]
            if pre==-1:continue
            ni=min(t,i+a)
            dp[ni]=max(dp[ni],pre+b)
    print(max(dp))

main()


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

typedef struct _point {
  short x;
  short y;
} T;


int main()
{
  char s[10000],last_cmd;
  
  int x,y,l,dir,n_t,cmd_cnt;
  
  int i,j,h[4000],v[4000],n_h,n_v;
  
  scanf("%s",s);
  scanf("%d %d",&x,&y);
  l = strlen(s);
  
  n_h = n_v = 0;
  
  dir = 0;  /* 1 = x, 2 = y */
  
  for(i=0;i<l;i++){
    if(s[i] == 'T'){
      dir = (dir == 2) ? 1 : 2;
    } else if( s[i] == 'F' ){
      j = 0;
      while(s[i+j]=='F'){
        j++;
      }
      if( dir == 2 ){
        v[n_v++] = j;
      } else {
        h[n_h++] = ( dir==0 ? -j : j );
      }
      i += (j-1);
    } else {
      
    }
  }
  
  char loc1[16002],loc2[16002];
  
  memset(loc1,0,sizeof(loc1));
  loc1[8001+0] = 1;
  for(i=0;i<n_h;i++){
    memset(loc2,0,sizeof(loc2));
    for(j=0;j<16002;j++){
      if(loc1[j]){
        if( h[i]<0 ){
          loc2[j-h[i]] = 1;
        } else {
          loc2[j-h[i]] = 1;
          loc2[j+h[i]] = 1;
        }
      }
    }
    memcpy(loc1,loc2,sizeof(loc1));
  }
  
  if(loc1[8001+x]!=1){
    printf("No\n");
    return EXIT_SUCCESS;
  }
  
  memset(loc1,0,sizeof(loc1));
  loc1[8001+0] = 1;
  for(i=0;i<n_v;i++){
    memset(loc2,0,sizeof(loc2));
    for(j=0;j<16002;j++){
      if(loc1[j]){
        loc2[j-v[i]] = 1;
        loc2[j+v[i]] = 1;
      }
    }
    memcpy(loc1,loc2,sizeof(loc1));
  }
  
  if(loc1[8001+y]!=1){
    printf("No\n");
    return EXIT_SUCCESS;
  }
  printf("Yes\n");
  
  
  
  return EXIT_SUCCESS;
  
}




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

function<LL(LL, LL)> gcdlambda = [](LL n, LL m) {
  return m ? gcdlambda(m, n % m) : n;
};
int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  cout << accumulate(A.begin(), A.end(), A[0], gcdlambda) << endl;
  return 0;
}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))
min = 1
check = True
count = 0
for i in range(N):
  if A[i] != min:
    A[i] = 0
    count += 1
  elif A[i] == min:
    min += 1
if A == [0] * N:
  print(-1)
else:
  print(count)

Measured memory_bytes: 32316
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()

void vprn(vector<int> &v){ for(int i=0;i<v.size();i++) cout<<v[i]<<(i<v.size()-1?",\t":"\n"); }

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

	vi A(N+1);
	rp(i,1,N+1){
		cin>>A[i];
	}

	// vprn(A);//

	int a = 1;
	rp(t,1,N+1){
		a = A[a];
		if(a==2){
			ote(t);
			return 0;
		}
	}
	ote(-1);
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
int main(void){
    int N;cin >> N;
    int d[N];
    map<int, int> mp;

    for (int i=0;i<N;i++){
        cin >> d[i];
        mp[d[i]]++;
    }

    cout << mp.size() << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};

ll F[110][5][2];

int main(){

  int n;
  cin >> n;
  REP(i,n)REP(j,5)REP(k,2)cin >> F[i][j][k];
  vector<vector<ll>> p(100,vector<ll>(11,0));
  REP(i,n)REP(j,11)cin >> p[i][j];
  ll res = (-1ll)*(1ll << 40);
  for(int bit = 0;bit < (1 << 5);bit++){
    vector<bool> b(5,0);
    REP(i,5)if(bit >> i & 1)b[i] = true;
    vector<int> many(n,0);
    REP(i,n)REP(j,5)if(b[j] && F[i][j][0])many[i]++;
    for(int bits = 0;bits < (1 << 5);bits++){
      if(bit == 0 && bits == 0)continue;
      vector<bool> a(5,0);
      REP(i,5)if(bits >> i & 1)a[i] = true;
      vector<int> many(n,0);
      REP(i,n)REP(j,5)if(b[j] && F[i][j][0])many[i]++;
      REP(i,n)REP(j,5)if(a[j] && F[i][j][1])many[i]++;
      ll sum = 0;
      REP(i,n)sum += p[i][many[i]];
      res = max(res,sum);
    }
  }

  cout << res << endl;





  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <ctime>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <cstring>
#define MAXN 210
using namespace std;

bool flag;
int arr[MAXN];

void dfs(int x1, int y1, int x2, int y2, int cnt){
    if(x2 < x1 || y2 < y1)
        return;
    if(cnt == 10) {
        flag = true;
        return;
    }
    dfs(x2, y1, arr[cnt], y2, cnt + 1);
    dfs(x1, y2, x2, arr[cnt], cnt + 1);
}

int main(){
    int T;
    cin >> T;
    while(T--){
        for(int i = 0; i < 10; ++i)
            cin >> arr[i];
        flag = false;
        dfs(0, 0, 0, 0, 0);
        if(flag)
            cout << "YES\n";
        else
            cout << "NO\n";
    }
    return 0;
}

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

vector<vector< pair<int, int> >> edge;
int N;

int deg[int(1e5) + 3];
int color[int(1e5) + 3];
int ans[int(1e5) + 3];

int maxAns = 0;

void dfs(int x) {
    int CL = 0;
    for(const pair<int, int> &P : edge[x]) {
        if(color[P.first]) continue;
        //
        do {
            CL++;
        } while(CL == color[x]);
        //
        color[P.first] = CL;
        ans[P.second] = CL;
        maxAns = max(maxAns, CL);
        dfs(P.first);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    //
    cin >> N;
    edge.resize( N+1, vector<pair<int, int>> () );
    for(int a, b, i = 1; i < N; i++) {
        cin >> a >> b;
        edge[a].push_back( {b, i} );
        edge[b].push_back( {a, i} );
        deg[a]++;
        deg[b]++;
    }
    for(int i = 1; i <= N; i++)
        if(deg[i] == 1) {
            color[i] = -1;
            dfs(i);
            break;
        }
    //
    printf("%d\n", maxAns);
    for(int i = 1; i < N; i++) printf("%d\n", ans[i]);
}


Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
#define  ll  long long
const int N=2e5+3;
ll a[N],b[N],c[N];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll i,j,n,m,l,r,s=0;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>b[i];
        a[b[i]]++;
    }
    for(i=1; i<=n; i++)
    {
        l=a[i];
        l=(l*(l-1))/2;
        r=a[i]-1;
        r=(r*(r-1))/2;
        s+=l;
        c[i]=r-l;
    }
    for(i=0; i<n; i++)
    {
        cout<<(s+c[b[i]])<<"\n";
    }
    return 0;
}

Measured memory_bytes: 6784
n,c,k = map(int,input().split())
list = [int(input()) for _ in range(n)]
sorted_list = sorted(list)
bus = 1
customer = 1
max_hour = sorted_list[0]+k
for i in sorted_list[1:]:
  if i > max_hour or customer >= c:
    bus+=1
    customer=1
    max_hour = i+k
  else:
    customer += 1
print(bus)

Measured memory_bytes: 8656
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define dout(n) cout<<# n<<" = "<<n<<endl;
#define v1out(v) FOR(i,0,v.size()){cout<<v[i]; if(i!=(ll)v.size()-1)cout<<" ";else cout<<endl; }
#define v2out(v) FOR(i,0,v.size())v1out(v[i]);

ll MOD = 998244353;
int main(){
    int n, k;
    cin >> n >> k;
    vector<vector<int>>dp(n+1,vector<int>(k+1,0));
    FOR(i,0,n+1)dp[i][0]=1;
    FOR(i,0,n){
        int in;
        cin>>in;
        FOR(j,0,k+1){
            (dp[i+1][j] += dp[i][j]) %= MOD;
            if(j+in<=k) ((dp[i+1][j+in]) += dp[i][j]) %= MOD;
        }
    }
    ll ans = 0;
    FOR(i,0,n+1)(ans += dp[i][k]) %= MOD;
    cout<<ans<<endl;

}

Measured memory_bytes: 35584
import java.util.*;
//オイラーのφ関数
public class Main{
    public static boolean prime(long n){
    	if(n < 2){
	    return false;
	}
	else if(n == 2){
		return true;
	}
	else{
		if(n % 2 == 0){
			return false;
		}
		else{
			for(int i = 3 ; i <= Math.sqrt(n) ; i++){
				if(n % i == 0){
					return false;
				}
			}
			return true;
		}
	}
    }
    public static void bunnkai(long n, HashMap<Long,Long> hm){
	while(n % 2 == 0){
		if(!hm.containsKey(2L))
			hm.put(2L,1L);
		else
			hm.put(2L,hm.get(2L)+1L);
		n /= 2;
	}
	long res = n;
	for(long i = 3 ; i < Math.sqrt(n) ; i+= 2){
		if(res == 1)
			return;
		else if(prime(i) && res % i == 0){
			while(res % i == 0){
				if(!hm.containsKey(i))
					hm.put(i,1L);
				else
					hm.put(i,hm.get(i)+1L);
				res /= i;
			}
		}
	}
	if(prime(res))
		hm.put(res,1L);
	return;
    }
    public static void main(String[] args){
	HashMap<Long,Long> hm = new HashMap<Long,Long>();
	Scanner sc = new Scanner(System.in);
	long n = sc.nextLong();
	bunnkai(n,hm);
	long ans = n;
	for(long key : hm.keySet()){
		ans *= (key-1);
		ans /= key;
	}
	System.out.println(ans);
    }
}


Measured memory_bytes: 26516
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    std::string s;
    std::cin >> s;


    std::cout << (
            ((bool)std::count(ALL(s), 'N')==(bool)std::count(ALL(s), 'S'))
          &&((bool)std::count(ALL(s), 'E')==(bool)std::count(ALL(s), 'W'))
          ? "Yes" : "No") << '\n';
}


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

int main() {
  int N, T; cin >> N >> T;
  vector<int> imos(T + 2, 0);
  while (N--) {
    int l, r; cin >> l >> r;
    ++imos[l];
    --imos[r];
  }
  for (int i = 0; i < T + 1; ++i) imos[i + 1] += imos[i];

  int ans = 0;
  for (auto&& x : imos) ans = max(ans, x);

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



Measured memory_bytes: 3124
// C - Snack
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll gcd(ll a, ll b){return b? gcd(b, a%b): a;}

int main(){
	int A,B; cin>>A>>B;
	cout<< A / gcd(A,B) * B <<endl;
}

Measured memory_bytes: 256
using System;
class Program
{
  static void Main (string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int N = int.Parse(input[0]);
    int M = int.Parse(input[1]);
    int[] votes = new int[M];
    for (int i = 0; i < M; i++) {
      votes[i] = 0;
    }
    
    for (int i = 0; i < N; i++) {
      string[] input2 = Console.ReadLine().Split(' ');
      int K = int.Parse(input2[0]);
      for (int j = 1; j <= K; j++) {
        votes[(int.Parse(input2[j]) - 1)]++;
      }
    }
    
    int count = 0;
    for (int i = 0; i < M; i++) {
      if (votes[i] == N) {
        count++;
      }
    }
    Console.WriteLine(count);
  }
}

Measured memory_bytes: 11092
#include <iostream>

int main() {
    char a, b;
    std::cin >> a >> b;

    if(a == 'H') {
        std::cout << b << std::endl;
    } else {
        if(b == 'H') {
            std::cout << 'D' << std::endl;
        } else {
            std::cout << 'H' << std::endl;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 555;
int h, w, d;
char c[MAX][MAX];
const string cc = "RYGB";

int main(void) {
    cin >> h >> w >> d;
    REP(i, h) {
        REP(j, w) {
            const int nh = i + j + MAX;
            const int nw = i - j + MAX;
            cout << cc[(nh / d) % 2 * 2 + (nw / d) % 2];
        }
        cout << endl;
    }
}


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


using namespace std;

int main(){
int a,b,c,d;
cin >> a>> b>>c>>d;
 int p = 3;
while(true){
   if(p == 3){ 
    c-=b;
    if(c <= 0){
        cout << "Yes" <<endl;
        return 0;
    }
    p = 2;
}
else{
    a-= d;
    if(a <= 0){
        cout << "No" <<endl;
        return 0;
    }
    p = 3;
}
}


}


Measured memory_bytes: 3632
function setUp(input) {
  input = input.split("\n");
  N = Number(input[0]);
  Hlist = input[1].split(" ").map(function (d, i) {
    return Number(d);
  });
  main();
}
function main() {
  var count = 0;
  var current = 0;
  Hlist.forEach(function (d, i) {
    if (current <= d) {
      count++;
      current = d;
    }
  });
  console.log(count);
}

setUp(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX+1];

void maxHeapify(int i) {
    int l, r, largest;
    l = 2 * i;
    r = 2 * i + 1;
    
    if (l <= H && A[l] > A[i]) largest = l;
    else largest = i;
    if (r <= H && A[r] > A[largest] ) largest = r;
    
    if ( largest != i) {
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int main() {
    cin >> H;
    
    for (int i = 1; i <= H; i++) cin >> A[i];
    for (int i = H / 2; i >= 1; i--) maxHeapify(i);
    for (int i = 1; i <= H; i++) {
        cout << " " << A[i];
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 5056
#include<bits/stdc++.h>
#define FLASH cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define pb push_back
#define int long long
#define fr(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define FILEIO freopen("/home/aman/Desktop/Kachda/input.txt", "r", stdin); freopen("/home/aman/Desktop/Kachda/output.txt", "w", stdout);
#define maxn 200000

using namespace std;

signed main()
{

 	FLASH

 	int n;
 	cin>>n;
 	int p[n + 1];

 	fr(i, 1, n + 1) cin>>p[i];

 	int ans = 0;
 	fr(i, 2, n){
 		if(min(p[i], min(p[i - 1], p[i + 1])) != p[i] and max(p[i], max(p[i - 1], p[i + 1])) != p[i])ans++;
 	}	

 	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=200005;
int a[N],n;
int main() {
  scanf("%d",&n);
  for (int i=1;i<=n;++i) scanf("%d",&a[i]);
  sort(a+1,a+1+n);
  bool flag=0;
  for (int i=2;i<=n;++i) {
    if(a[i]==a[i-1]) flag=1;
  }
  if(flag) printf("NO\n");
  else printf("YES\n");
  return 0;
}

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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
template<typename T> bool chmin(T &a, const T &b) {if (a > b) { a = b; return true; }return false;}
template<typename T> bool chmax(T &a, const T &b) {if (a < b) { a = b; return true; }return false;}

using ll = int_fast64_t;
using PII = pair<int, int>;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

struct UnionFind {
  vector<int> data;
  UnionFind(int n) : data(n, -1) {}
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[x] > data[y]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main() {
  int n, k, l; cin >> n >> k >> l;
  UnionFind UF1(n);
  UnionFind UF2(n);
  REP(i,k) {
    int p, q; cin >> p >> q;
    p--; q--;
    UF1.merge(p, q);
  }
  REP(i,l) {
    int r, s; cin >> r >> s;
    r--; s--;
    UF2.merge(r, s);
  }
  map<PII, int> mp;
  REP(i,n) mp[make_pair(UF1.root(i), UF2.root(i))]++;
  REP(i,n) {
    cout << mp[make_pair(UF1.root(i), UF2.root(i))] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
 
// #define int long long
 
/* short */
#define pb push_back
#define print(x) cout << x << '\n'
 
/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, n) for (int i = (n); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = INT_MAX;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}


signed main()
{
  ios::sync_with_stdio(false);
  string s;
  const string tbl = "yuiophjklnm";

  for (;cin >> s, s[0] != '#';){
    int cnt = 0;
    bool r = true;
    if (tbl.find(s[0]) == -1) r = false;
    REPS(i, 1, s.size()){
      if (r && tbl.find(s[i]) == -1){
        cnt++;
        r = false;
      } else if (!r && tbl.find(s[i]) != -1){
        cnt++;
        r = true;
      }
    }
    print(cnt);
  }

  return (0);
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int sum[2010][2010][4];

int main(){
    int h,w; cin>>h>>w;
    string s[h]; rep(i,h) cin>>s[i];
    for(int y=0;y<h;y++){
        for(int x=0;x<w;x++){
            sum[y][x][0]=sum[y][x][1]=1;
            if(x>=1){
                sum[y][x][0]+=sum[y][x-1][0];
            }
            if(y>=1){
                sum[y][x][1]+=sum[y-1][x][1];
            }
            if(s[y][x]=='#') sum[y][x][0]=sum[y][x][1]=0;
        }
    }
    for(int y=h-1;y>=0;y--){
        for(int x=w-1;x>=0;x--){
            sum[y][x][2]=sum[y][x][3]=1;
            if(x+1<w){
                sum[y][x][2]+=sum[y][x+1][2];
            }
            if(y+1<h){
                sum[y][x][3]+=sum[y+1][x][3];
            }
            if(s[y][x]=='#') sum[y][x][2]=sum[y][x][3]=0;
        }
    }
    int ans=0;
    for(int y=0;y<h;y++){
        for(int x=0;x<w;x++){
            if(s[y][x]=='#') continue;
            int sums=0;
            rep(k,4) sums+=sum[y][x][k];
            ans=max(ans,sums-3);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 67200
from bisect import bisect_right
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

def ruisekiwa(List):
    for i in range(1, len(List)):
        List[i] += List[i - 1]
    return List

arui = ruisekiwa(a)
brui = ruisekiwa(b)
arui.insert(0, 0)
brui.insert(0, 0)
ans = 0

for i in range(n + 1):
    if arui[i] > k:
        break
    j = bisect_right(brui, k - arui[i])
    ans = max(ans, i + j - 1)
print(ans)

Measured memory_bytes: 40416
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	resolve()
}

func resolve() {
	w, h, x, y := scanInt(sc), scanInt(sc), scanInt(sc), scanInt(sc)
	max := float64(w*h) / 2.0
	isCenter := 0
	if x<<1 == w && y<<1 == h {
		isCenter = 1
	}
	fmt.Printf("%.10f %d\n", max, isCenter)
	return
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
const ll mod = 1e9+7;
#define INFL 0x3f3f3f3f3f3f3f3fLL
 
//-------------------------<MATH>-------------------------------------------------------//
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;
ll c = (a * b)%mod;
//cout << a << " " << b << endl;
return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(5e5 + 5)] , inv_fac[(int)(5e5 + 5)];
void precomp_factorial(int M){fac[0] = 1;for(int i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(int i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int lo[(int)(1e3 + 6)];
void sieve(int M){for(int i = 2 ; i < M ; i++){ if(lo[i]) continue; for(int j = i ; j < M ; j += i)lo[j] = i;}}
int max_expo_prime_n_fac(ll N , int prime){int ress = 0;while(N){ress += (N/prime);N /= prime;}return ress;}
//-------------------------</MATH>-------------------------------------------------------//
 
//-------------------------<STRING>-------------------------------------------------------//
string get_prefix(string x , int MAX){return x.substr(0 , min((int)x.size() , MAX));}
string get_suffix(string x,int MAX){int dn=1;for(int i=x.size()-1;i>=0;i--){if(dn==MAX)return x.substr(i);dn++;}return x;}
string convert_to_binary(int x,int len) {string ans=""; while(x){if(x&1){ans='1'+ans;}
    else{ans ='0'+ans;}x/=2;}int k = ans.size();while(k < len){ans = '0' + ans;k++;}return ans;}
//-------------------------</STRING>-------------------------------------------------------//
 
ull llrand() {ull r = 0;for(int i = 0; i < 5; ++i){r = (r << 15)|(rand() & 0x7FFF);}return r & 0xFFFFFFFFFFFFFFFFULL;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
 
 
ll dp[210][210][210];
 
int main(){
    int n;
    cin >> n;
    vector <ll> vec(n);
    for(int i = 0; i < n; i++){
        cin >> vec[i];
    }
    sort(vec.begin(), vec.end());
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(vec[i] == vec[j]) continue;
            for(int k = j+1; k < n; k++){
               if(vec[i] == vec[k] || vec[k] == vec[j]) continue;
               if(vec[i]+vec[j] > vec[k]) ans++;
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 3636
/*
for(int i=1;i<=n;i++){
	for(int j=1;j<=n;j++){
		if(!a[i][x]) continue;
		for(int s=1;s<(1<<n);s++){
			if(!(s&(1<<(i-1)))) continue;
			f[i][s] += f[i-1][s|(1<<(i-1))];
		}
	}
}
*/

#include <cstdio>
#include <iostream>

using namespace std;

const int MAXN = 21;
const int MOD  = 1e9+7;

int n, a[MAXN][MAXN], f[MAXN+1][1<<MAXN];

inline int count(int x)
{
	int res = 0;
	for(int j=0;j<n;j++)
		if(x & (1<<j)) ++res;
	return res;
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			scanf("%d",&a[i][j]);
	const int MAXS = 1<<n;
	f[0][0] = 1;
	for(int s=1;s<MAXS;s++){
		int i = count(s);
		for(int j=0;j<n;j++){
			if((s & (1<<j)) && a[i-1][j]){
				f[i][s] = (f[i][s] + f[i-1][s&(~(1<<j))]) % MOD;
			}
		}
	}
	printf("%d\n",f[n][MAXS-1]);
	return 0; 
}

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

#define ll long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

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


Measured memory_bytes: 3980
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<double> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  double dp[N][N+1]; //i番目までにj個表が出る確率
  for(int i=0; i<N; i++){
    for(int j=0; j<N+1; j++){
      dp[i][j] = 0;
    }
  }
  
  for(int i=0; i<N; i++){
    if(i == 0){
      dp[i][0] = 1 - vec.at(i);
      dp[i][1] = vec.at(i);
    }
    else{
      for(int j=0; j<N; j++){
        dp[i][j] += dp[i-1][j] * (1 - vec.at(i));
        dp[i][j+1] += dp[i-1][j] * vec.at(i);
      }
    }
  }
  
  /*for(int i=0; i<N; i++){
    for(int j=0; j<N+1; j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }*/
  
  double ans = 0;
  for(int j=(N+1)/2; j<N+1; j++){
    ans += dp[N-1][j];
  }
  cout << setprecision(20) << ans << endl;
  
} 

Measured memory_bytes: 70528
(n,k),p,c=[[*map(int,t.split())]for t in open(0)]
a=-9e9
for i in range(n):
 s=f=0;x,j,*l=i,k
 while~f:x=p[x]-1;s+=c[x];l+=s,;f-=x==i
 for t in l[:k]:j-=1;a=max(a,t+j//len(l)*s*(s>0))
print(a)

Measured memory_bytes: 114368
#include<bits/stdc++.h>
using namespace std;
long long n;
int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n;
	if(n%2==1)cout<<0<<endl;
	else
	{
		long long ans=0;
		n/=2;
		while(n)
		{
			ans+=n/5;
			n/=5;
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

int main(void)
{
	int n, k;
	int i, j;
	int sum = 1;
	int min;
	
	
	scanf("%d%d", &n, &k);
	
	printf("%d\n", n - k + 1);
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD (ll)(1e9+7)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

ll c[2010][2010];

ll comb(int a, int b){
    if(a<b||b<0) return 0;
    if(c[a][b] != 0) return c[a][b];

    if(a == b || b == 0) return c[a][b] = 1;

    return c[a][b] = (comb(a-1, b-1) + comb(a-1, b)) % MOD;
}

int main(void)
{
    int n,k;
    cin >> n >> k;
    REP(i, k){
        pr((comb(n-k+1,i+1)*comb(k-1, i))%MOD);
    }
}

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

typedef long long ll;
typedef pair<ll,ll> pll;


map<pll,ll> M;
vector<pll> W;

ll count(ll a){
  pll &w=W[a];
  ll mx=0;
  ll C=0;
  for(int i=-1;i<1;i++){
    for(int t=-1;t<1;t++){
      C=0;
      for(int x=0;x<=1;x++){
	for(int y=0;y<=1;y++){
	  C+=M[{w.first+i+x,w.second+t+y}];
	}
      }
      mx=max(mx,C);
    }
  }
  return mx;
}


int main(){
  ll n;
  cin>>n;
  for(int i=0;i<n;i++){
    ll x,y,w;
    cin>>x>>y>>w;
    W.push_back({x,y});
    M[{x,y}]+=w;
  }
  ll ans=0;
  for(int i=0;i<n;i++){ans=max(ans,count(i));}
  cout<<ans<<" / 1"<<endl;


  return 0;
}



Measured memory_bytes: 60608
#include <bits/stdc++.h>
using namespace std;
const int MAXN=2510;
int n,m,p,x,y,z,eg,hd[MAXN],ver[2*MAXN],nx[2*MAXN],edge[2*MAXN],dis[MAXN],vis[MAXN],tim[MAXN];
int eg2,hd2[MAXN],ver2[2*MAXN],nx2[2*MAXN],vis2[MAXN];
void add_edge (int x,int y,int z) {
	ver[++eg]=y;
	edge[eg]=z,nx[eg]=hd[x];
	hd[x]=eg;
	return;
}
void add_edge2 (int x,int y) {
	ver2[++eg2]=y;
	nx2[eg2]=hd2[x];
	hd2[x]=eg2;
	return;
}
void dfs (int x) {
	vis2[x]=1;
	for (int i=hd2[x];i;i=nx2[i]) {
		if (!vis2[ver2[i]]) {
			dfs(ver2[i]);
		}
	}
}
bool spfa () {
	queue <int> q;
	q.push(1);
	dis[1]=0,vis[1]=1;
	while (!q.empty()) {
		int a=q.front();
		q.pop();
		vis[a]=0;
		if (vis2[a]&&++tim[a]>n-1) {return 0;}
		for (int i=hd[a];i;i=nx[i]) {
			if (!vis2[ver[i]]) {continue;}
			if (dis[ver[i]]>dis[a]+edge[i]) {
				dis[ver[i]]=dis[a]+edge[i];
				if (!vis[ver[i]]) {q.push(ver[i]);vis[ver[i]]=1;}
			}
		}
	}
	return 1;
}
int main () {
	memset(dis,0x3f,sizeof(dis));
	scanf("%d%d%d",&n,&m,&p);
	for (int i=1;i<=m;i++) {
		scanf("%d%d%d",&x,&y,&z);
		add_edge(x,y,p-z);
		add_edge2(y,x);
	}
	dfs(n);
	if (spfa()) {
		printf("%d\n",max(0,-dis[n]));
	} else {
		printf("-1\n");
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  	int X, Y, A, B, C;
  	cin >> X >> Y >> A >> B >> C;
	vector<int> p(A), q(B), r(C);
  	for (int i=0; i<A; i++) cin >> p[i];
  	for (int i=0; i<B; i++) cin >> q[i];
  	for (int i=0; i<C; i++) cin >> r[i];
  	sort(p.rbegin(),p.rend());
  	sort(q.rbegin(),q.rend());
  	vector<int> temp;
  	for (int i=0; i<X; i++) temp.push_back(p[i]);
    for (int i=0; i<Y; i++) temp.push_back(q[i]);
  	for (int i=0; i<C; i++) temp.push_back(r[i]);
  	sort(temp.rbegin(),temp.rend());
  	long long  ans = 0;
  	for (int i=0; i<X+Y; i++) ans += temp[i];
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3572
#include <iostream>

using namespace std;

int main() {
	int n, t;
	cin >> n >> t;
	
	int result = 1001;
	for (int i = 0; i < n; ++i) {
		int c, k;
		
		cin >> c >> k;
		
		if (k <= t && result > c) {
				result = c;
		}
	}
	
	if (result == 1001) {
		cout << "TLE" << endl;
	} else {
		cout << result << endl;
	}
}

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

using namespace std ;
#define int long long int

const int maxn = 1e5 + 5;
const int inf = 1e10 ;
vector<int> dp(maxn, inf);
vector<int> h(maxn);
int n, K;

int solve(int ind){
    if(ind >= n -1 ){
        if(ind == n - 1 ) return 0;
        else return inf;
    }
    int &ans = dp[ind];
    if(ans != inf ) return ans;
    ans = inf;
    for(int i = ind+1 ; i <= min(n-1,ind + K ) ; i++){
        int adder = solve(i);
        ans = min(ans, abs(h[i]-h[ind]) + adder);
    }
    return ans;
}


int32_t main(){
    //#ifndef ONLINE_JUDGE
      //freopen("input.txt", "r", stdin);
      //freopen("output.txt", "w", stdout);
    //#endif
    cin >> n >> K;
    for(int i =0; i < n ; i++ ) cin >> h[i];
    cout<<solve(0)<<endl;
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N; cin >> N;
    vector<int> A(3);
    for(int i = 0; i < 3; ++i) cin >> A[i];
    vector<pair<int, int>> query;
    for(int i = 0; i < N; ++i) {
        string S; cin >> S;
        query.emplace_back(S[0] - 'A', S[1] - 'A');
    }
    vector<int> ans, tmp;
    auto dfs = [&](auto &&dfs, int i) {
        if(!ans.empty() or A[0] < 0 or A[1] < 0 or A[2] < 0) return;
        if(i == N) { ans = tmp; return; }
        auto[x, y] = query[i];
        for(int _ = 0; _ < 2; ++_) {
            A[x]++, A[y]--, tmp.push_back(x);
            dfs(dfs, i + 1);
            A[x]--, A[y]++, tmp.pop_back();
            swap(x, y);
        }
    };
    dfs(dfs, 0);
    if(ans.empty()) {
        cout << "No" << '\n';
    } else {
        cout << "Yes" << '\n';
        for(auto &i : ans) cout << "ABC"[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 11188
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){
    int a,b,c;
    cin >> a >> b >> c;

    P((a*b) >>1);
	return  0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)

struct UnionFind {
    int data[40000];
    UnionFind() {
        memset(data, -1, sizeof(data));
    }
    void unite(int x, int y) {
        x = root(x); y = root(y);
        if(x != y){
            data[x] += data[y];
            data[y] = x;
        }
    }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]);}
    bool same(int a, int b) { return root(a) == root(b);}
};

int can_unite[2][100000];
int slime[40000][2];
int main() {
    int N, W, H;
    scanf("%d%d%d", &N, &W, &H);
    int x_, y_;
    bool edge = false;
    rep(i, N){
        scanf("%d%d", &x_, &y_); --x_; --y_;
        slime[i][0] = x_; slime[i][1] = y_;
        if(x_ == 0 || x_ == W - 1 || y_ == 0 || y_ == H - 1)
          edge = true;
    }
    
    memset(can_unite, -1, sizeof(can_unite));
    UnionFind uf;
    int ans = 0;
    rep(i, N) rep(j, 2) {
        int& a = can_unite[j][slime[i][j]];
        if(a == -1) a = i;
        else if(!uf.same(a, i)) {
            uf.unite(a, i);
            ans++;
        }
    }
    
    bitset<40000> roots(0);
    rep(i, N) roots[uf.root(i)] = 1;
    int temp = roots.count();
    if(temp == 1) cout << ans << endl;
    else {
        ans += temp * 2 - 1;
        if(edge) --ans;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2472