akhauriyash/Code-Regression huggingface dataset:
//实在抱歉...我嗑了一个费用流的板子...因为来不及了.... 
//话说跟我之前讲的那道题怎么这么像:) 
#include<cstdio>
#include<cstring>
#include<queue>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAXN 5000
#define MAXM 70000
#define INF 0x3f3f3f3f
#define pINF 1000000000000000000
#define FR first
#define SE second
#define LL long long
int read()  
{  
    int x=0,f=1;char s=getchar();  
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}  
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}  
    return x*f;  
}
struct E
{
    int to,cap;LL cost;int next;
}e[2*MAXM+5];int head[MAXN+5] ,ecnt;
LL dis[MAXN+5];
int Q[MAXN*6+5],vis[MAXN+5];
int n,m,S,T,cnt,D;
int ax[MAXN+5],ay[MAXN+5],bx[MAXN+5],by[MAXN+5];
int ac[MAXN+5],bc[MAXN+5];
void Clear()
{
    ecnt = 0;
    memset(head,-1,sizeof head);
}
void add(int fr,int to,int cap,LL cost)
{
    e[ecnt]=(E){to,cap,cost,head[fr]};
    head[fr]=ecnt++;
    e[ecnt]=(E){fr,0,-cost,head[to]};
    head[to]=ecnt++;
}
void Dij(int s,int t)
{
    for(int i=S;i<=T;i++)dis[i]=pINF;
    priority_queue<pair<LL, int> > Q;
    dis[t]=0;
	Q.push(make_pair(0,t));
    while(!Q.empty())
    {
        int cur=Q.top().SE;LL d=-Q.top().FR;
		Q.pop();
		if(d!=dis[cur])continue;
        for (int i=head[cur];i!=-1;i=e[i].next)
        {
            int nxt=e[i].to;
            if (e[i^1].cap&&dis[nxt]>dis[cur]-e[i].cost)
            {
                dis[nxt]=dis[cur]-e[i].cost;
				Q.push(make_pair(-dis[nxt],nxt));
            }
        }
    }
}
bool modf(int s,int t)
{
    //vis为访问到的点集,delta为修改值
    LL delta=pINF;
    for(int i=S;i<=T;i++)
    if(vis[i])
        for(int j=head[i];j!=-1;j=e[j].next)
		{
			int v=e[j].to;
            if(e[j].cap&&!vis[v])delta=min(delta,dis[v]+e[j].cost-dis[i]);
		}
    if(delta==pINF)return 0;//所有点都访问到 退出
    for(int i=S;i<=T;i++)
    if(vis[i])dis[i]+=delta;
    return 1;
}
int aug(int p,int t,int Flow,LL &mincost)
{
    if(p==t){mincost+=Flow*dis[S];return Flow;}
    vis[p]=1;
    int Fl=Flow,tp;
    for(int i=head[p];i!=-1;i=e[i].next)
    {
		int v=e[i].to;
        if(e[i].cap&&!vis[v]&&dis[p]==dis[v]+e[i].cost)
        {
            tp=aug(v,t,min(Fl,e[i].cap),mincost);
            e[i].cap-=tp,e[i^1].cap+=tp;
            Fl-=tp;
            if(!Fl)return Flow;
        }
    }
    return Flow-Fl;
}
void MCMF(int s,int t,int &maxflow,LL &mincost)
{
    maxflow=mincost=0;
    int p=0;
	Dij(s,t);
    do{
        do{
            memset(vis,0,sizeof(vis));
            maxflow+=p;
        }while(p=aug(s,t,2e9,mincost));
    }while(modf(s,t));
}
int main(){
    Clear();
    n=read();
    S=0,T=2*n+5;
    for(int i=1;i<=n;i++){
    	ax[i]=read(),ay[i]=read(),ac[i]=read();
    	add(S,i,ac[i],0);
    	add(i,2*n+1,INF,ax[i]+ay[i]);
    	add(i,2*n+2,INF,ax[i]-ay[i]);
    	add(i,2*n+3,INF,-ax[i]+ay[i]);
    	add(i,2*n+4,INF,-ax[i]-ay[i]);
	}
    for(int i=1;i<=n;i++){
  	  	bx[i]=read(),by[i]=read(),bc[i]=read();
  	  	add(n+i,T,bc[i],0);
    	add(2*n+1,n+i,INF,-bx[i]-by[i]);
    	add(2*n+2,n+i,INF,-bx[i]+by[i]);
    	add(2*n+3,n+i,INF,bx[i]-by[i]);
    	add(2*n+4,n+i,INF,bx[i]+by[i]);
  	}
    int ans1;LL ans2;
   	MCMF(S,T,ans1,ans2);
    printf("%lld",-ans2);
}

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

using ll = long long;

struct Heap {
  Heap *l, *r;
  long double val;
  int pos;
  Heap(long double val, int pos) : val(val), pos(pos) {
    l = r = nullptr;
  }
};
Heap  *root;
Heap *meld(Heap *a, Heap *b) {
  if(a == nullptr) return b;
  if(b == nullptr) return a;

  if(a->val > b->val) swap(a, b);
  a->r = meld(a->r, b);
  swap(a->l, a->r);

  return a;
}
void push(Heap x){
  
  Heap *p = new Heap(x);
  root = meld(root, p);
}
Heap top()
{
  return (*root);
}
void pop()
{
  Heap *p = root;
  root = meld(root->r, root->l);
  delete p;
}



long double calc(long double x1, long double y1, long double x2, long double y2){
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    
    long double xs,ys,xt,yt; cin >>xs>>ys>>xt>>yt;
    int N;
    cin >> N;
    
    vector<long double> x,y,r;
    x.push_back(xs);
    y.push_back(ys);
    r.push_back(0);
    for(int i = 0; i<N; i++){
        int a, b, c; cin>>a>>b>>c;
        x.push_back(a);
        y.push_back(b);
        r.push_back(c);
    }
    x.push_back(xt);
    y.push_back(yt);
    r.push_back(0);
    
    
    push(Heap(0, 0));
 
    vector<long double> dist(N+3, (1LL<<61));
 
    dist[0] = 0;
    while(root){
        Heap xx = top();
        pop();
        long double c = xx.val, pos = xx.pos;
        if(dist[pos] < c) continue;
 
        for(int i=0; i<x.size(); i++){
            if(i == pos) continue;
            
            long double d = calc(x[pos], y[pos], x[i], y[i]);
            if(r[pos] + r[i] >= d){
                if(dist[i] > dist[pos]){
                    dist[i] = dist[pos];
                    push(Heap(dist[pos], i));
                }
            }else{
                long double g = d - r[pos]-r[i];
                if(dist[i] > dist[pos] + g){
                    dist[i] = dist[pos] + g;
                    push(Heap(dist[i], i));
                }
            }
        }
    }
    cout << dist[x.size()-1] << endl;
    return 0;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N,n;
  cin >> N;
  n = 0;
  for(int i = 0; i < 3; i++){
    if(N%10 == 7){
      n = 1;
    }
    N = N/10;
  }
  if(n==1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3636
def getsum(S, delimiter, idx):
    if idx == len(S):
        retval = 0
        prev = 0
        for d in delimiter:
            retval += int(S[prev:d])
            prev = d
        retval += int(S[prev:])
        return retval
    return getsum(S, delimiter, idx+1) + getsum(S, delimiter + [idx], idx+1)


def main():
    S = input()

    print(getsum(S, [], 1))


if __name__ == "__main__":
    main()


Measured memory_bytes: 39792
/* 
 * File:   main.c
 * Author: s1252006
 *
 * Created on June 15, 2018, 11:19 AM
 */

#include <stdio.h>
#include <stdlib.h>

void insertionSort(int array[], int length) {
    int key, i;
    for (int j = 1; j < length; j++) {
        key = array[j];
        i = j-1;
        while (i >= 0 && array[i] > key) {
            array[i+1] = array[i];
            i = i-1;
        }
        array[i+1] = key;
        
        
        printf("\n");
        for (int ixArray = 0; ixArray < length; ixArray++) {
            if (ixArray != 0) printf(" ");
            printf("%d", array[ixArray]);
        }
        
    }
}


int main(int argc, char** argv) {
    int length;
    scanf("%d", &length);
    
    const int nxArray = length;
    int array[nxArray];
    for (int ixArray = 0; ixArray < nxArray; ixArray++)
        scanf("%d", &array[ixArray]);

    for (int ixArray = 0; ixArray < nxArray; ixArray++) {
        if (ixArray != 0) printf(" ");
        printf("%d", array[ixArray]);
    }
    
    insertionSort(array, nxArray);
    printf("\n");
    
//    for (int ixArray = 0; ixArray < nxArray; ixArray++) {
//        printf("%d ", array[ixArray]);
//    }
    
    

    return (EXIT_SUCCESS);
}




Measured memory_bytes: 2140
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
vector<int> graph[100010];
int d[2][100010];
void dfs(int x, int cost, int num){
    d[num][x] = cost;
    for(auto i:graph[x]){
        if(d[num][i] != INF)continue;
        dfs(i, cost + 1, num);
    }
}
main(){
    int N;
    cin >> N;
    rep(i,0,N-1){
        int a,b;
        cin >> a >> b;
        a--,b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    rep(i,0,N)d[0][i] = d[1][i] = INF;
    dfs(0, 0, 0);
    dfs(N-1, 0, 1);
    int cnt = 0;
    rep(i,0,N)cnt += d[0][i] <= d[1][i] ? 1 : -1;
    if(cnt > 0)cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

void dfs(vector<vector<ll>> &graph, vector<ll> &counter, vector<bool> &visited, ll parentCounter, ll current) {
  // cout << current << endl;
  visited[current] = true;
  counter[current] += parentCounter;

  for (auto v : graph[current]) {
    if (v == false) continue;
    if (visited[v] == true) continue;

    dfs(graph, counter, visited, counter[current], v);
  }
}

int main() {
  ll N, Q;
  cin >> N >> Q;
  vector<vector<ll>> graph(N);

  for (ll i = 0; i < N - 1; i++) {
    ll a, b;
    cin >> a >> b;
    graph[a-1].push_back(b-1);
    graph[b-1].push_back(a-1);
  }

  vector<ll> counter(N, 0);
  for (ll i = 0; i < Q; i++) {
    ll p, x;
    cin >> p >> x;
    counter[p-1] += x;
  }

  vector<bool> visited(N, false);
  dfs(graph, counter, visited, 0, 0);

  for (auto p : counter) {
    cout << p << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 30592
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int c[10][10];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < 10; ++i)
        for (int j = 0; j < 10; ++j)
            cin >> c[i][j];

    for (int k = 0; k < 10; ++k)
        for (int i = 0; i < 10; ++i)
            for (int j = 0; j < 10; ++j)
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);

    int sol = 0;
    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            int x;
            cin >> x;
            if (x != -1)
                sol += c[x][1];
        }
    }
    cout << sol;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i =(b)-1;i>=(a);--i)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
typedef vector<int> vi;
const int mod = 1e9 + 7;
const int maxn = 2e6 + 10;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin >> n >> m;
	if(n&1){
		int l = n/2,r = n/2 + 1;
		rep(i,0,m){
			cout << l << ' ' << r << '\n';
			--l,++r;
		}
	}
	else{
		
		int c = m - m/2,d = m/2;
		int l = m/2+1,r = m/2 + 2;
		rep(i,0,c){
			cout << l <<' '<< r << '\n';
			--l,++r;
		}
		l = m+1+m/2,r = m+m/2+3;
		rep(i,0,d){
			cout << l <<' '<< r << '\n';
			--l,++r;
		}
	}
	return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
typedef long long ll; 
#define pb push_back
#define mp make_pair
#define mod 998244353
#define vi vector <ll>
using namespace std ; 
ll power(ll x,ll y,ll m)
{            //power(x,y)=x^y  %m;
	ll res=1%m;
	while(y)
	{
	    if(y&1)
	    res=(res*x)%m;
	    x=(x*x)%m;
	    y=(y>>1)%m;
	}
	return res;
}
ll mod_inverse(ll x,ll m)
{
	return power(x,m-2,m);
}
int main ()
{
    ios_base :: sync_with_stdio ( false );
    cin.tie( NULL );
    cout.tie( NULL );
ll t = 1 ;
//cin>>t;
while ( t--)  
{
 ll n;
 cin>>n;
 if(n%1000==0)
 {
     cout<<0<<"\n";
     continue;
 }
 cout<<1000-n%1000<<"\n";
 
  
 
}
 

 return 0;
}

Measured memory_bytes: 3648
let string_of_list s =
  let rec exp i l =
    if i < 0 then l else exp (i - 1) (s.[i] :: l) in
  exp (String.length s - 1) []
let string_of_char c = String.make 1 c
let () =
  Scanf.scanf "%s\n"
    (fun s ->
       let lst = string_of_list s in
       let arr = Array.of_list lst in
       let headChar = arr.(0) in
       let sublst = Array.to_list (Array.sub arr 2 ((Array.length arr) - 3)) in
       let exist1C =((List.length sublst) - (List.length (List.filter (fun s -> s <> 'C') sublst))) = 1 in
       if headChar = 'A' && exist1C then
         let o = List.map (string_of_char)
             (List.filter (fun s -> s <> 'A' && s <> 'C') lst) in
         let original = List.fold_left (^) "" o in
         let want = String.lowercase original in
         if original = want && (List.length o = (List.length lst - 2)) then "AC"
         else "WA"
       else "WA"
    ) |> print_string


Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, M, D; cin >> N >> M >> D;
    ll cnt = 0;
    if(D == 0) cnt = N;
    else cnt = 2*(N-D);
    double unit = (double)cnt/(double)(N*N);
    cout << fixed << setprecision(20) << (unit*(M-1)) << endstr;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 10000000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

class edge{
public:
	int u,v,t,c;
	edge(){}
	edge(int uu,int vv,int tt,int cc){
		u=uu;
		v=vv;
		t=tt;
		c=cc;
	}
	bool operator<(const edge &e)const{
		return t<e.t;
	}
};

class data{
public:
	int v,t,c;
	data(){}
	data(int vv,int tt,int cc){
		v=vv;
		t=tt;
		c=cc;
	}
	bool operator<(const data &d)const{
		return d.t<t;
	}
};
int n,m,s,g;
int dp[100001];
int prev[100001];
vector<edge> G;

int main(void){
	scanf("%d%d%d%d",&n,&m,&s,&g);
	s--;
	g--;
	for(int i=0;i<m;i++){
		int u,v,t,c;
		scanf("%d%d%d%d",&u,&v,&t,&c);
		u--;
		v--;
		G.push_back(edge(u,v,t,c));
	}
	sort(G.begin(),G.end());
	priority_queue<data> que;
	for(int i=0;i<n;i++){
		dp[i]=INF;
	}
	dp[s]=0;
	int res=INF;
	for(int i=0;i<m;i++){
		edge e=G[i];
		while(1){
			if(!que.size())break;
			data q=que.top();
			if(q.t<=e.t){
				if(dp[q.v]+e.t-prev[q.v]>q.c){
					dp[q.v]=q.c;
					prev[q.v]=q.t;
				}
				que.pop();
			}else break;
		}
		if(e.u==g)res=min(dp[e.u],res);
		if(dp[e.u]!=INF){
			dp[e.u]=dp[e.u]+e.t-prev[e.u];
			prev[e.u]=e.t;
			que.push(data(e.v,e.t+e.c,dp[e.u]));
		}
	}
	while(que.size()){
		data q=que.top();
		que.pop();
		if(dp[q.v]>q.c){
			dp[q.v]=q.c;
		}
	}
	printf("%d\n",min(res,dp[g]));
	return 0;
}

Measured memory_bytes: 8512
N,M = map(int,input().split())
lis = [None]*N
ans = 0
for i in range(N):
  lis[i] = list(map(int,input().split()))
lis = sorted(lis,key = lambda x:x[0])
for j in range(N):
  if lis[j][1] >= M:
    ans += M*lis[j][0]
    break
  else:
    ans += lis[j][1]*lis[j][0]
    M -= lis[j][1]
print(ans)

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

int main(){
	int n;
	cin>>n;
	vector<long long> a(n);
	for(long long i=0;i<n;i++)cin>>a[i];
	long long ans=1e10;
	for(long long i=-100;i<=100;i++){
		long long cnt=0;
		for(long long j=0;j<n;j++){
			cnt+=abs(a[j]-i)*abs(a[j]-i);
		}
		ans=min(cnt,ans);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter
from collections import deque
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,w=mp()
dp=[0]*(w+1)
for i in range(n):
    x,y=mp()
    for k in range(w,x-1,-1):
        dp[k]=max(dp[k],dp[k-x]+y)
print(dp[-1])

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

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

	int n = X / 100;
	int r = X - n * 100;
	int ans = 0;
	for( int i = 0; i <= n; i++ ) {
		for( int j = 0; j <= n; j++ ) {
			if( i + j > n ) break;
			for( int k = 0; k <= n; k++ ) {
				if( i + j + k > n ) break;
				for( int l = 0; l <= n; l++ ) {
					if( i + j + k + l > n ) break;
					for( int m = 0; m <= n; m++ ) {
						if( i + j + k + l + m > n ) break;
						if( i + j * 2 + k * 3 + l * 4 + m * 5 == r ) {
							ans = 1;
							break;
						}
					if( ans ) break;
					}
				if( ans ) break;
				}
			if( ans ) break;
			}
		}
		if( ans ) break;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int LUT[ 'Z' + 1 ] = { };

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int cards[ 4 ][ 14 ] = { };
  int n;
  int i, j;

  LUT[ 'S' ] = 0;
  LUT[ 'H' ] = 1;
  LUT[ 'C' ] = 2;
  LUT[ 'D' ] = 3;

  scanf ( "%d", &n );
  while ( n-- )
  {
    char mark;
    int  rank;

    scanf ( " %c %d", &mark, &rank );
    cards[ LUT[ mark ] ][ rank ] = 1;
  }

  for ( i = 0; i < 4; ++i )
  for ( j = 1; j <= 13; ++j )
  {
    const char MK[ ] = { 'S', 'H', 'C', 'D' };

    if ( cards[ i ][ j ] ) continue ;
    printf ( "%c %d\n", MK[ i ], j );
  }

  return ( 0 );
}

Measured memory_bytes: 0
using System;

namespace Application
{
	class Solution
	{
		static void Main(string[] args)
		{
			var inputWords = Console.ReadLine().Split(' ');
			var trainFare = int.Parse(inputWords[0]);
			var busFare = int.Parse(inputWords[1]);

			var result = trainFare + busFare / 2;

			Console.WriteLine(result);
		}
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mk make_pair

template <class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;

// struct path
// {
//     pair<ll, ll> f;
//     pair<ll, ll> t;
// };

// struct cmp
// {
//     bool operator() ( path a, path b ) const
//     { return std::make_pair(a.f,a.t) > std::make_pair(b.f,b.t) ; }
// };

void solve()
{
    ll n, k;
    cin >> n >> k;
    ll k1 = k;
    vector<ll> x(n + 5);
    for (int i = 1; i <= n; i++)
    {
        cin >> x[i];
    }

    unordered_map<ll, ll> h, h1;
    unordered_set<ll>s;
    ll cur = 1;
    ll cnt = 0;
    vector<ll> cycle;
    ll last=0;
    while (h[x[cur]] < 2)
    {
        h[x[cur]]++;
        cur = x[cur];
        if (h[cur] == 2)
        {
            cnt++;
            cycle.push_back(cur);
            if(s.count(cur))
            {
                s.erase(cur);
            }
        }
        else
        {
            h1[cur] = ++last;
            s.insert(cur);
        }
    }

    ll lol=s.size();
    vector<ll>ans(lol+5);
    

    for(auto it:s)
    {
        ans[h1[it]] = it;
    }
    
    if(k<=lol)
    {
        cout<<ans[k]<<endl;
    }
    else
    {
        cout << cycle[(((((k % cnt)-lol-1)%cnt)+cnt)%cnt)] << endl;
    }   
    
    
}

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

    // ll t;
    // cin >> t;

    // while (t--)
    // {
    //     solve();
    // }
    solve();
    return 0;
}

Measured memory_bytes: 31244
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1


N = int(input())
A = list(map(int, input().split()))
ans = [0] * N

even_A = sum([A[i] for i in range(len(A)) if i % 2 == 0])
odd_A = sum([A[i] for i in range(len(A)) if i % 2 == 1])

# print(even_A)
# print(odd_A)

ans[0] = even_A - odd_A

for i in range(N - 1):
    ans[i + 1] = 2 * A[i] - ans[i]

print(*ans)



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

int main() {
  int64_t N;
  cin >> N;
  
  int64_t a, b, c = N + 1, k = 1;
  for (int64_t i = 1; i < N/k; i++) {
    if (N % i != 0) {k = i; continue;}
    int64_t a1 = i, b1 = N/i, c1 = a1 + b1;
    if (c1 <= c) {
      a = a1; b = b1; c = c1;
    }
  }
  cout << c - 2 << endl;
}


Measured memory_bytes: 256
H, W = map( int, input().split())
A = [ list( input()) for _ in range(H)]
Flag = True
yoko = [0]*H
tate = [0]*W
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            yoko[i] = 1
            break
for j in range(W):
    for i in range(H):
        if A[i][j] == '#':
            tate[j] = 1
ANS = []
for i in range(H):
    if yoko[i] == 0:
        continue
    ans = ''
    for j in range(W):
        if tate[j] == 1:
            ans += A[i][j]
    ANS.append(ans)
for ans in ANS:
    print(ans)

Measured memory_bytes: 3188
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int i,j,k,l,n,a[101],cnt=0,cn=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			for(k=j+1;k<n;k++){
				if(!((a[i]==a[j]&&a[j]==a[k])||(a[i]==a[j]||a[j]==a[k]))){
					if(a[i]+a[j]>a[k]){
						cnt++;
					}
				
				}
			}
		}
	}
	printf("%d\n",cnt-cn);
	return 0;
}
		
	

Measured memory_bytes: 1736
import java.util.Scanner;

//20180508
//10

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

		int num = scanner.nextInt();
		int[] value = new int[num];

		for(int i = 0;i < num;i++) {
			value[i] = scanner.nextInt();
		}
		for(int j = num-1;j >= 0;j--) {
			System.out.print(value[j]);
			if(j != 0) {
				System.out.print(" ");
			}
		}
		System.out.println();

    	scanner.close();
    }
}


Measured memory_bytes: 26264
// Problem : D - Integer Cards
// Contest : AtCoder - AtCoder Beginner Contest 127
// URL : https://atcoder.jp/contests/abc127/tasks/abc127_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	// && has higher precedence than ||
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int N,M;
	cin>>N>>M;
	map<int,int> m;
	F0R(x,N)
	{
		int a;
		cin>>a;
		m[a]++;
	}
	// vpi v;
	F0R(x,M)
	{
		int a,b;
		cin>>a>>b;
		m[b]+=a;
	}
	ll ans=0,c=0;
	for(auto i=m.rbegin();i!=m.rend();i++)
	{
		if(c+(*i).s<=N)
		{
			ans+=(*i).s*(ll)(*i).f;
			c+=(*i).s;
		}
		else
		{
			ans+=(*i).f*(ll)(N-c);
			break;
		}
	}
	cout<<ans<<nl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 12948
package main

import "fmt"

func main() {
	var N, A, B int
	fmt.Scan(&N, &A, &B)

	ans := 0
	for i := 1; i <= N; i++ {
		c := 0
		n := i
		for n > 0 {
			c += n % 10
			n /= 10
		}
		if A <= c && c <= B {
			ans += i
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
/*
Looking from a window above
It's like a story of love
Can you hear me?
Came back only yesterday
I'm moving further away
Want you near me
All I needed was the love you gave
All I needed for another day
And all I ever knew
Only you
Sometimes when I think of her name
When it's only a game
And I need you
Listen to the words that you say
It's getting harder to stay
When I see you
All I needed was the love you gave
All I needed for another day
And all I ever knew
Only you, only you
Uh uh uh only you, only you
Only you, only you, only you
This is going to take a long time
And I wonder what's mine
Can't take no more
Wonder if you'll understand
It's just the touch of your hand
Behind a closed door
And all I needed was the love you gave
All I needed for another day
And all I ever knew
Only you, only you, only you
All I needed was the love you gave
All I needed for another day
And all I ever knew
Only you, only you, only you
Only you
*/

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ld long double
#define endl '\n'
#define rep(x,s,e) for(int x=s;x<=(e);x++)
#define repn for(int x=0;x<n;x++)
#define rep1n for(int x=1;x<=n;x++)
#define rep1m for(int y=1;y<=m;y++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define precise(x) cout << fixed << setprecision(x)
#define bits(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) ((int)(x.size()))
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define see(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define see(x...)
#endif

const int inf = 3e18;
const int N = 5e5 + 100;




int32_t main(){ 
   FAST;
   int k,x;
   cin >> k >> x;
   cout << (500*k >= x ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
rsp = list(map(int, input().split()))
t = input()
ans = 0
d = {'r': 2, 's':0, 'p': 1}
for c in t:
  ans += rsp[d[c]]
for i in range(k):
  prev = t[i]
  seq = 1
  for j in range(i+k, n, k):
    if t[j] == prev:
      seq += 1
    else:
      ans -= rsp[d[prev]] * (seq // 2)
      prev = t[j]
      seq = 1
  ans -= rsp[d[prev]] * (seq // 2)
print(ans)

Measured memory_bytes: 3316
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
constexpr ll MOD = 1000000007;
 
#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " (" << x.first << " : " << x.second << ")" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "["; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "(" << obj.first << ", " << obj.second << ")"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print_sim_py(void) {cout << endl;}
template <class Head> void print_sim_py(Head&& head) {cout << head;print_sim_py();}
template <class Head, class... Tail> void print_sim_py(Head&& head, Tail&&... tail) {cout << head << " ";print_sim_py(forward<Tail>(tail)...);}
 
#define print(...) print_sim_py(__VA_ARGS__);
#else
#define print(...);
#endif

template<class T, class U>
void dfs(ll x, vector<vector<T>>& g, vector<U>& seen, function<void(void)> func=nullptr){
    for(ll i=0; i<g[x].size(); i++){
        if(g[x][i] && !seen[i]){
            seen[i] = !seen[i];
            if(func) func();
            dfs(i,g,seen,func);
        }else{
            continue;
        }
    }
}

template<class T, class U>
void dfs(ll x, vector<list<T>>& g, vector<U>& seen, function<void(void)> func=nullptr){
    for(auto& i : g[x]){
        if(!seen[i]){
            seen[i] = !seen[i];
            if(func) func();
            dfs(i,g,seen,func);
        }else{
            continue;
        }
    }
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll n,m;
    ll ans=0;

    cin >> n >> m;
    
    //vector<vector<char>> f(n,vector<char>(n,0));
    vector<list<ll>> f(n);
    vector<ll> seen(n,0);

    for(ll i=0;i<m;i++){
        ll x,y;
        cin >>x>>y;
        f[x-1].push_back(y-1);
        f[y-1].push_back(x-1);
    }

    for(ll i=0; i<n; i++){
        if(!seen[i]){
            ll cnt=0;
            dfs(i,f,seen,[&](){cnt++;});
            //print(i,seen, cnt)
            ans = max(ans,cnt);
        }
    }
    ans = max(ans,1ll);

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



Measured memory_bytes: 43720
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	double n, x, ave = 0,z=INF;
	vector<int> a;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		ave += x;
		a.push_back(x);
	}
	ave = ave / n;

	for (int i = 0; i < n; i++) {
		if (abs(a[i] - ave) < z) {
			z = abs(a[i] - ave);
			x = i;
		}
	}

	cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<math.h>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#include<stack>
#include<string>
#include<vector>

using namespace std;
int main(void) {
	int N = 0, L = 0;
	char str[105][105] = { "\0" };

	scanf("%d%d", &N, &L);
	for (int i = 0; i < N; i++)
		scanf("%s", str[i]);

	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			bool frag = false;
			for (int k = 0; k < L; k++) {
				if (str[i][k] < str[j][k])
					break;
				if (str[i][k] > str[j][k]) {
					frag = true;
					break;
				}
			}
			if (frag) {
				char s[105] = "\0";
				strcpy(s, str[i]);
				strcpy(str[i], str[j]);
				strcpy(str[j], s);
			}
		}
	}

	for (int i = 0; i < N; i++) {
		printf("%s", str[i]);
	}
	printf("\n");

	return 0;
}

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

using namespace std ;

const int MAXN = 13 , MAXM = 1e3 + 10 ;

long long dp[(1 << MAXN)][MAXM] ;
int n , m ;
long long arr[MAXM] ;
int arrmask[MAXM] ;

long long solve(int mask , int idx)
{
	if(mask == (1ll << n) - 1)
		return 0 ;
	if(idx == m)
		return 1e9 ;
	long long &ret = dp[mask][idx] ;
	if(ret != -1)
		return ret ;
	ret = solve(mask , idx+1) ;
	ret = min(ret , solve(mask | arrmask[idx] , idx+1) + arr[idx]) ;
	return ret ;
}

int main()
{
	memset(dp , -1 , sizeof(dp)) ;
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m ;
	for(int i = 0 ; i < m ; ++i)
	{
		cin>>arr[i] ;
		int sz ;
		cin>>sz; 
		int mask = 0 ;	
		while(sz--)
		{
			int x ;
			cin>>x ;
			mask |= (1ll << (x-1)) ;
		}
		arrmask[i] = mask ;
	}
	int ans = solve(0 , 0) ;
	if(ans >= (1e9))
		return cout<<-1<<"\n" , 0 ;
	return cout<<ans<<"\n" , 0 ;
}

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

int n, m, z[100005], par[100005], tb, tc;
long long x[100005], y[100005], sum[100005], dp[100005], ta;
vector< int > v[100005], vv[100005];

int find(int a) {
	return par[a] == a ? a : par[a] = find(par[a]);
}

void dfs(int a) {
	sum[a] = x[a];
	if (vv[a].empty())
		dp[a] = sum[a] + y[a];
	else {
		for (int i: vv[a]) {
			dfs(i);
			sum[a] += sum[i];
		}
		dp[a] = LLONG_MAX;
		for (int i: vv[a])	
			dp[a] = min(dp[a], max(dp[i], y[a]) + sum[a] - sum[i]);
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		scanf("%lld%lld", &ta, x + i);
		y[i] = max(ta - x[i], 0LL);
		z[i] = i;
	}
	sort(z + 1, z + n + 1, [](const int &a, const int &b) {return y[a] < y[b];});
	while (m--) {
		scanf("%d%d", &tb, &tc);
		v[tb].push_back(tc);
		v[tc].push_back(tb);
	}
	for (int i = 1; i <= n; i++) {
		tb = z[i];
		par[tb] = tb;
		for (int j: v[tb])
			if (par[j] && find(j) != tb) {
				vv[tb].push_back(par[j]);
				par[par[j]] = tb;
			}
	}
	dfs(z[n]);
	printf("%lld\n", dp[z[n]]);
	return 0;
}


Measured memory_bytes: 18812
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;

int main(void)
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	int n=read<int>();
	int m=read<int>();

	if(n<=m) puts("unsafe");
	else puts("safe");

	return 0;

}

Measured memory_bytes: 3632
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let b: String = read();
    if b == "A" {
        println!("T");
    } else if b == "T" {
        println!("A");
    } else if b == "G" {
        println!("C");
    } else {
        println!("G");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl s(n);
    rep(i, n) {
        cin >> s[i];
    }

    vl t(m);
    rep(i, m) {
        cin >> t[i];
    }

    vvl dp(n, vl(m));  // dp[i][j] : s[i]までとt[j]まででs[i]とt[j]を含む空でない整数列として等しい部分列の組の個数
    vvl rui(n+1, vl(m+1));  // rui[i][j] : dp[x][y]を 0 <= x < i, 0 <= y < j で足し合わせたもの
    rep(i, n) {
        rep(j, m) {
            if(s[i] == t[j]) {
                dp[i][j] = rui[i][j] + 1;
                dp[i][j] %= mod;
            }
            rui[i+1][j+1] = rui[i+1][j] + rui[i][j+1] + mod - rui[i][j] + dp[i][j];
            rui[i+1][j+1] %= mod;
        }
    }

    ll ans = (rui[n][m] + 1)%mod;
    out(ans);
    re0;
}

Measured memory_bytes: 62976
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
LRC = [tuple(map(int,input().split())) for i in range(M)]
LRC.sort()

INF = float('inf')
class SegTreeMin:
    def __init__(self,arr):
        n = 1
        while n < len(arr):
            n *= 2
        self.n = n
        nodes = [INF]*(2*n-1)
        nodes[n-1:n-1+len(arr)] = arr
        for i in range(n-2,-1,-1):
            nodes[i] = min(nodes[2*i+1],nodes[2*i+2])
        self.nodes = nodes

    # thanks
    # https://smijake3.hatenablog.com/entry/2018/11/03/100133
    def update(self,i,val):
        i += self.n-1
        self.nodes[i] = val
        while i >= 0:
            i = (i - 1) // 2
            self.nodes[i] = min(self.nodes[2*i+1], self.nodes[2*i+2])

    def query(self,l,r):
        L = l + self.n; R = r + self.n
        s = INF
        while L < R:
            if R & 1:
                R -= 1
                s = min(s, self.nodes[R-1])
            if L & 1:
                s = min(s, self.nodes[L-1])
                L += 1
            L >>= 1; R >>= 1
        return s

segt = SegTreeMin([0] + [INF]*N)
for l,r,c in LRC:
    mn = segt.query(l-1,r-1)
    org = segt.query(r-1,r)
    if org > mn+c:
        segt.update(r-1, mn+c)

ans = segt.query(N-1,N)
print(-1 if ans==INF else ans)

Measured memory_bytes: 129116
import java.util.Scanner;

public class Main {

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

		int r = scan.nextInt();
		int g = scan.nextInt();
		int b = scan.nextInt();

		int rgb = r * 100 + g * 10 + b;

		if (rgb % 4 == 0) {
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	}
}

Measured memory_bytes: 22868
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        double T = (double)sc.nextInt();
        double A = (double)sc.nextInt();
        double min = 100000000;
        int ans = 0;
        for(int i = 0;i < N;i++){
            double d = Math.abs(A-T+(double)sc.nextInt()*0.006);
            if(d < min){
                min = d;
                ans = i+1;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22484
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long
#define rg register
#define inf 0x3f3f3f3f
inline int read()
{
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x*f;
}
int n,z,w,a[2050];
int main(){

    n=read();
    z=read(),w=read();
    for(int i=1;i<=n;i++)
        a[i]=read();
    if(n==1)
    {
        cout<<abs(a[1]-w)<<endl;
        return 0;
    }
    cout<<max(abs(a[n]-a[n-1]),abs(a[n]-w))<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(ll i=vv;i<n;i++)
#define FORR(i,n,vv) for(ll i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v))-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)



int main(){

	#ifndef ONLINE_JUDGE
    // for getting input from input.txt	
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
	 #endif

    FAST
	//PRECISE

ll n;
cin>>n;
string s;
cin>>s;
ll ans=0;
FOR(i,0,n-2){
	if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
		ans++;
}
cout<<ans;

return 0;
 }


Measured memory_bytes: 3568
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
int rec(string s){
	if(s=="Male")return 1;
	else return 0;
}
int main(){
	int n;
	cin>>n;
	int lb=0,rb=n;
	string s0;
	cout<<0<<endl;
	cin>>s0;
	int st=rec(s0);
	REP(i,20){
		int mid=(lb+rb)/2;
		cout<<mid<<endl;
		string s;
		cin>>s;
		int now=rec(s);
		if(st^now==mid%2){
			lb=mid;
		}else{
			rb=mid;
		}
	}
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,k,ans=0;
	cin>>n >>k;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		ans+=2*min(x,abs(k-x));
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

def comb(x):
    return int(x * (x-1)/2)

N = I()
A = LI()

c = collections.Counter(A)

tmp = 0
for i in c.values():
    tmp += comb(i)

for a in A:
    print(tmp - comb(c[a]) + comb(c[a]-1))

Measured memory_bytes: 88404
//It is made by ljh2000
//有志者，事竟成，破釜沉舟，百二秦关终属楚；苦心人，天不负，卧薪尝胆，三千越甲可吞吴。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long LL;
const int MAXN = 100011;
int n,L,T,X[MAXN];

inline int getint(){
    int w=0,q=0; char c=getchar(); while((c<'0'||c>'9') && c!='-') c=getchar();
    if(c=='-') q=1,c=getchar(); while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar(); return q?-w:w;
}

inline void work(){
	n=getint(); L=getint(); T=getint();
	int pos=0,x,w;
	for(int i=0;i<n;i++) {
		x=getint();	w=getint(); 
		if(w==1) {
			X[i]=x+T; X[i]%=L;
			pos+=(x+T)/L;
		}
		else {
			X[i]=x-T; X[i]%=L;
			pos+=(x-T)/L;
			if(X[i]<0) {
				X[i]+=L;
				pos--;
			}
		}
	}
	sort(X,X+n);
	pos%=n; pos+=n; pos%=n;//!!!
	for(int i=pos;i<n;i++) printf("%d\n",X[i]);
	for(int i=0;i<pos;i++) printf("%d\n",X[i]);
}

int main()
{
    work();
    return 0;
}
//有志者，事竟成，破釜沉舟，百二秦关终属楚；苦心人，天不负，卧薪尝胆，三千越甲可吞吴。


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

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()

using namespace std;

typedef vector<int> vi;

int main(){
  int t;
  cin >> t;
  rep(_,t){
    int n,k; cin >> n>>k;
    vi x(n);
    rep(i,n) cin >> x[i];
    sort(all(x));
    vi d(n-1);
    int s=0;
    rep(i,n-1){
      d[i]=x[i+1]-x[i];
      s+=d[i];
    }
    sort(rall(d));

    int end=min(k-1,n-1);

    rep(i,end){
      s-=d[i];
    }
    s=max(0,s);
    cout << s << endl;
  }
}

Measured memory_bytes: 1856
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 == 0 or a[i] % 5 == 0:
            continue
        else:
            print("DENIED")
            quit()
else:
    print("APPROVED") 


Measured memory_bytes: 3064
import java.io.*;
import java.util.*;

public class Main {
	private static final int READ_COUNT = 1;
	private static List<String> strList = new ArrayList<>();
	
	public static void main(String[] args) {
		read();
		
		int n = Integer.parseInt(strList.get(0));
		
		System.out.println((n % 2 == 0) ? n : n * 2);
	}
	
	private static void read() {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			for (int i = 0; i < READ_COUNT; i++) {
				strList.add(br.readLine());
			}
		} catch (IOException e) {
		}
	}
}


Measured memory_bytes: 21460