akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(void) {
	int n, k; cin >> n >> k;
	priority_queue<int, vector<int>, less<int>> pq;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		pq.push(x);
	}

	int res = 0;
	while (k--) {
		res += pq.top();
		pq.pop();
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=200010;
int f[maxn],pos[maxn][30],n;
char s[maxn];
int main(){
	scanf("%s",s);
	n=strlen(s);
	for(int i=0;i<26;i++)pos[n][i]=n;
	f[n]=1;f[n+1]=0;
	for(int i=n-1;i>=0;i--){
		for(int j=0;j<26;j++)pos[i][j]=pos[i+1][j];
		pos[i][s[i]-'a']=i;
		f[i]=n+1;
		for(int j=0;j<26;j++)f[i]=min(f[i],f[pos[i][j]+1]+1);
	}
	int T=f[0],p=0;
	while(T--){//printf("p=%d f[]=%d\n",p,f[p]);
		for(int j=0;j<26;j++)if(f[pos[p][j]+1]+1==f[p]){
			putchar('a'+j);
		//	printf("%c",'a'+j);
			p=pos[p][j]+1;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 24576
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;

int main(){
  ll n;cin>>n;
  map<ll,ll>m;
  rep(i,0,n){
    ll a;cin>>a;
    m[a]++;
  }
  ll cnt=0;
  for(auto u:m){
    if(u.second>1){
      cnt+=u.second-1;
    }
  }
  cout<<(cnt%2?n-cnt-1:n-cnt)<<endl;
}



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

int main(){
  int a,b,c,d,e=0;
  cin >>a>>b>>c>>d;
  for(int i=0;i<10000;i++){
    c=c-b;
    if(c<=0){
      e++;
      break;
    }
    a=a-d;
    if(a<=0){
      e=e+2;
      break;
    }
  }
  if(e==1)cout<<"Yes";
  else cout <<"No";
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
	char s[4][100] = {"AMBIGUOUS","YYMM","MMYY","NA"};
	int a, ans = 0;
	cin >> a;
	if (a/100>12 || a/100 ==0)
		ans += 1;
	if(a%100>12 || a%100 == 0)
		ans += 2; 
	cout << s[ans];
}

Measured memory_bytes: 256
s, t = list(input().split())
s_num, t_num = map(int, input().split())
bad_string = input()

if bad_string == s:
    print(s_num - 1, t_num)
elif bad_string == t:
    print(s_num, t_num - 1)
else:
    print(s_num, t_num)


Measured memory_bytes: 2940
import sys
sys.setrecursionlimit(10 ** 6)

# 末端の頂点は白1通り、黒1通り
# それ以外の頂点は、各子どもの頂点を元に、白:子の全ての場合分けの積、黒:子が全て白の場合分けの積
# で更新していく

N = int(input())
G = [[] for i in range(N)]
MOD = 10 ** 9 + 7

for i in range(N - 1):
  x,y = map(int,input().split())
  G[x - 1].append(y - 1)
  G[y - 1].append(x - 1)
  
dp_black = [-1] * N
dp_white = [-1] * N

# 頂点vの(黒,白)の場合の数を求める
def search(v,parent):
  if dp_black[v] != -1:
    return (dp_black[v],dp_white[v])
  black = 1
  white = 1
  for child in G[v]:
    if child == parent:
      continue
    b,w = search(child, v)
    black *= w
    black %= MOD
    white *= (b + w)
    white %= MOD
  dp_black[v] = black
  dp_white[v] = white
  return (black, white)

print(sum(search(0, -1)) % MOD)


Measured memory_bytes: 947048
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>

using namespace std;

pair<string, string> p[1000000];
pair<string, string> a[1000000];

int main(){
  int n;cin>>n;
  string s;cin>>s;
  for(int i=0;i<(1<<n);i++){
    string pre;
    string af;
    for(int j=0;j<n;j++)if(((i&(1<<j))>0)){
      pre += s[j];
    }
    for(int j=n-1;j>=0;j--)if(!((i&(1<<j))>0)){
      af+=s[j];
    }
    p[i] = make_pair(pre,af);
  }

  for(int i=0;i<(1<<n);i++){
    string pre;
    string af;
    for(int j=0;j<n;j++)if(((i&(1<<j))>0)){
      pre += s[n+j];
    }
    for(int j=n-1;j>=0;j--)if(!((i&(1<<j))>0)){
      af+=s[n+j];
    }
    a[i] = make_pair(af,pre);
  }

  sort(p,p+(1<<n));
  /*for(int i=0;i<(1<<n);i++){
    cout<<p[i].first<<" "<<p[i].second<<endl;
  }*/
  sort(a,a+(1<<n));
  /*for(int i=0;i<(1<<n);i++){
    cout<<a[i].first<<" "<<a[i].second<<endl;
  }*/

  long long cnt=0;
  int ppre = 0;
  int paf = 0;
  while(1){
    if(ppre == (1<<n)) break;
    if(paf == (1<<n)) break;

    if(p[ppre] == a[paf]){
      ppre++;
      paf++;
      int cp = 1;
      int dp = 1;
      while(p[ppre-1] == p[ppre]){
        ppre++;
        cp++;
      }
      while(a[paf-1] == a[paf]){
        paf++;
        dp++;
      }
      cnt+= (long long)cp * (long long)dp;

    } else if(p[ppre] > a[paf]){
      paf++;
    } else {
      ppre++;
    }

  }

  cout<<cnt<<endl;

  return 0;
}


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

#define TARGET "slv"

using namespace std; 

using ll = long long;
using pii = pair<int, int>;

const int M1 = (int) 1e9+7;
const int B1 = (int) 19937;

const int M2 = (int) 1e9+21;
const int B2 = (int) 600011;

int tote(int a, int b, int m) {
    a += b;
    if (a >= m)
        a -= m;
    return a;
}

int subt(int a, int b, int m) {
    a -= b;
    if (a < 0)
        a += m;
    return a;
}

int mult(int a, int b, int m) {
    return (ll) a * b % m;
}

void buildHash(string& s, vector<int>& h, int b, int m) {
    int n = (int) s.size();
    h.resize(n+1, 0);
    h[0] = 0;
    for (int i = 0; i < n; i++)
        h[i+1] = tote(mult(h[i], b, m), s[i], m); 
}

void buildPws(int n, vector<int>& pws, int b, int m) {
    pws.resize(n+1);
    pws[0] = 1%m;
    for (int i = 1; i <= n; i++)
        pws[i] = mult(pws[i-1], b, m);
}

int getHash(vector<int>& h, vector<int>& pws, int l, int r, int m) {
    return subt(h[r], mult(h[l], pws[r-l], m), m);
}

bool check(vector<int>& h1, vector<int>& pws1, int m1, vector<int>& h2, vector<int>& pws2, int m2, int len, int n) {
    multiset<pii> s;
    for (int l2 = len; l2+len <= n; l2++) {
        int v1 = getHash(h1, pws1, l2, l2+len, m1);
        int v2 = getHash(h2, pws2, l2, l2+len, m2);
        s.insert(pii(v1, v2));
    }
    for (int l1 = 0; l1+len+len <= n; l1++) {
        int v1 = getHash(h1, pws1, l1, l1+len, m1);
        int v2 = getHash(h2, pws2, l1, l1+len, m2);
        if (s.find(pii(v1, v2)) != s.end()) 
            return true;
        int l2 = l1+len;
        v1 = getHash(h1, pws1, l2, l2+len, m1);
        v2 = getHash(h2, pws2, l2, l2+len, m2);
        s.erase(s.find(pii(v1, v2)));
    }
    return false;
}

int main() {
#ifdef INSPIRATION
    freopen(TARGET".in", "r", stdin);
    freopen(TARGET".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> h1, h2;
    buildHash(s, h1, B1, M1);
    buildHash(s, h2, B2, M2);
    vector<int> pws1, pws2;
    buildPws(n, pws1, B1, M1); 
    buildPws(n, pws2, B2, M2);
    int l = 0;
    int r = n/2;
    int ans = 0;
    while (l <= r) {
        int len = (l+r)/2;
        if (check(h1, pws1, M1, h2, pws2, M2, len, n)) {
            ans = len;
            l = len+1;        
        } else {
            r = len-1;
        }
    }
    cout << ans;
    return false;
} 

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;



int main() {
	int X, N;
	int p[110];
	cin >> X >> N;

	if (N == 0) {
		cout << X << endl;
		return 0;
	}

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

	sort(p, p + N);

	int hikutasu = 0;

	int flag = 0;

	while (true) {

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

			if (X - hikutasu == p[i]) {
				++flag;
			}

		}


		if (flag == 0) {
			cout << X - hikutasu << endl;
			return 0;
		}

		flag = 0;

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

			if (X + hikutasu == p[i]) {
				++flag;
			}

		}

		if (flag == 0) {
			cout << X + hikutasu << endl;
			return 0;
		}

		++hikutasu;
		flag = 0;
	}


	return 0;
}

Measured memory_bytes: 3600
N = int(input())
a = list()
for i in range(N):
    x = int(input())
    a.append(x)

c = 0
l = 1

for i in a:
    l = a[l-1]
    c += 1
    if l == 2:
        break
if l != 2:
    c = -1
print(c)
            


Measured memory_bytes: 7084
#include <cstdio>
#include <iostream>
#include <vector>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
inline char nc()
{
    // return getchar();
    static char buf[100000],*l=buf,*r=buf;
    return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
    x=0; int f=1,ch=nc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
    while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
    x*=f;
}
const int maxn=1e5+50;
int n,k;
vector<int> id;
void init()
{
    id.resize(n);
    for(int i=0;i<n;++i) id[i]=i;
}
vector<int> mul(vector<int> a,vector<int> b)
{
    vector<int> re(n);
    for(int i=0;i<n;++i) re[i]=a[b[i]];
    return re;
}
vector<int> inver(vector<int> a)
{
    vector<int> re(n);
    for(int i=0;i<n;++i) re[a[i]]=i;
    return re;
}
vector<int> power(vector<int> x,int y)
{
    vector<int> re=id;
    while(y)
    {
        if(y&1) re=mul(re,x);
        x=mul(x,x);
        y>>=1;
    }
    return re;
}
int main()
{
    read(n),read(k);
    vector<int> p(n),q(n);
    for(int i=0;i<n;++i) read(p[i]),--p[i];
    for(int i=0;i<n;++i) read(q[i]),--q[i];
    init();
    int d=(k-1)/6; k-=d*6;
    vector<int> A=id,B;
    A=mul(A,q);
    A=mul(A,inver(p));
    A=mul(A,inver(q));
    A=mul(A,p);
    A=power(A,d);
    if(k==1) B=p;
    else if(k==2) B=q;
    else if(k==3) B=mul(q,inver(p));
    else if(k==4) A=mul(A,q),B=inver(p);
    else if(k==5) A=mul(mul(A,q),inver(p)),B=inver(q);
    else A=mul(mul(A,q),inver(p)),B=mul(inver(q),p);
    vector<int> an=mul(mul(A,B),inver(A));
    for(int i=0;i<n;++i)
    {
        if(i) printf(" ");
        printf("%d",an[i]+1);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 5208
//
//  ABC060pC.cpp
//  
//
//  Created by 楊承昊 on 2017/4/29.
//
//

#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    long long int N,T;
    while(cin>>N>>T){
        long long int When[200000+5]={0};
        for(long long int i=0;i<N;i++)
            cin>>When[i];
        When[N]=9000000000;
        long long int sum=0;
        for(long long int i=1;i<=N;i++)
        {
            sum+=min(When[i]-When[i-1],T);
        }
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        boolean[] s = new boolean[13],h = new boolean[13],c = new boolean[13],d = new boolean[13];
        int n = sc.nextInt();
        for(int i = 0;i < n;++i){
            switch(sc.next()){
                case "S":
                    s[sc.nextInt() - 1] = true;
                    break;
                case "H":
                    h[sc.nextInt() - 1] = true;
                    break;
                case "C":
                    c[sc.nextInt() - 1] = true;
                    break;
                case "D":
                    d[sc.nextInt() - 1] = true;
                    break;
                default:
                    break;
            }
        }
        for(int i = 0;i < 13;++i){
            if(!s[i]) System.out.printf("S %d\n",i + 1);
        }
        for(int i = 0;i < 13;++i){
            if(!h[i]) System.out.printf("H %d\n",i + 1);
        }
        for(int i = 0;i < 13;++i){
            if(!c[i]) System.out.printf("C %d\n",i + 1);
        }
        for(int i = 0;i < 13;++i){
            if(!d[i]) System.out.printf("D %d\n",i + 1);
        }
    }

}

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

int main(){
  int n;
  double a;
  double ans = 0;
  cin >> n;
  
  for(int i = 0; i < n; i++) {
    cin >> a;
    ans = ans + (1 / a);
  }
  
  ans = 1 / ans;
  
  cout << ans << endl;
}

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

int n;
int temp2;
bool found;

unordered_set<int> temp;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n;

    while(n--) {
        cin >> temp2;
        if(temp.count(temp2))
            found = true;
        else
            temp.insert(temp2);
    }

    cout << (found?"NO":"YES") << endl;

    

    return 0;
}

Measured memory_bytes: 8520
n, m = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(n)]
CD = [list(map(int, input().split())) for i in range(m)]

for a, b in AB:
    dist = [[abs(a - c) + abs(b - d)] for c, d in CD]
    print(dist.index(min(dist)) + 1)

Measured memory_bytes: 3064
N=int(input())
A,B=map(int,input().split())
P=input().split()
P_low=[int(x) for x in P if int(x)<=A]
P_normal=[int(x) for x in P if A+1<=int(x)<=B]
P_high=[int(x) for x in P if B+1<=int(x)]


ans=P_low
if len(ans)<=len(P_normal):
    pass
else:
    ans=P_normal
if len(ans)<=len(P_high):
    pass
else:
    ans=P_high
print(len(ans))


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

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();

    for (int i = 0; i < 1000; i++) {
      if (a <= i*k && i*k <= b) {
        System.out.println("OK");
        return;
      }
    }

    System.out.println("NG");

  }

}


Measured memory_bytes: 35768
from collections import deque

s = input()
q = int(input())
S = deque(s)
head = True

for i in range(q):
    li = input().split()
    if li[0] == '1':
        head = not head
    else:
        if head:
            if li[1] == '1':
                S.appendleft(li.pop())
            else:
                S.append(li.pop())
        else:
            if li[1] == '2':
                S.appendleft(li.pop())
            else:
                S.append(li.pop())
s = ''.join(S)
if not head:
    s = s[::-1]
print(s)

Measured memory_bytes: 8820
def z(a):
  return max(a,-a)
N=int(input())
l=[list(map(int,input().split())) for _ in range(N)]
l=[[0,0,0]]+l
n=True
for i in range(N):
  a=z(l[i][1]-l[i+1][1])+z(l[i][2]-l[i+1][2])
  if not(l[i+1][0]-l[i][0]-a>=0 and (l[i+1][0]-l[i][0]-a)%2==0):
    n=False
if n:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 28068
#include<bits/stdc++.h>
#define int long long
 
using namespace std;
 
int dp[3001][3001] = {};
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    
    string a, b;
    cin >> a >> b;
    for (int i = 1; i <= a.size(); i++)
        for (int j = 1; j <= b.size(); j++)
            if (a[i - 1] == b[j - 1])
                dp[i][j] = dp[i - 1][j - 1] + 1;
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
    
    int i = a.size(), j = b.size();
    stack<char> ans;
    while (i > 0 && j > 0)
    {
        if (dp[i][j] > dp[i - 1][j] && dp[i][j] > dp[i][j - 1])
            ans.push(a[i - 1]), i--, j--;
        else if (dp[i][j] == dp[i][j - 1] && j > 1)
            j--;
        else
            i--;
    }
    while (!ans.empty())
        cout << ans.top(), ans.pop();
    cout << '\n';
    
    return 0;
}

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

int main() { /* ここに書く */
  
  long long HP , X , Ans ;
  cin >> HP ;
  X = 1 ;
  Ans = 0 ;
  
  while( HP > 0 ){
    HP = HP/2 ;
    Ans = Ans + X ;
    X = 2*X ;
  }
  cout << Ans << endl ;
}

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

int main(){
  string S;
  cin >> S;
  int M;
  cin >> M;
  char ans = '1';
  for(int i=0; i<M; i++){
    if(S.at(i) != '1'){
      ans = S.at(i);
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
A,B,C,D = map(int,input().split())
if A%D==0:
    counter_ao=A//D
else:
    counter_ao=A//D+1

if C%B==0:
    counter_ta=C//B
else:
    counter_ta=C//B+1

if counter_ao >= counter_ta :
    print("Yes")
else:
    print("No")

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

int main() {
  vector<int> v;
  int temp;
  
  while(cin>>temp) v.push_back(temp);
  
  sort(v.begin(),v.end());
  
  int mx=0, cnt[101] = {};
  for(unsigned int i = 0; i < v.size(); i++) {
    mx = max(mx, ++cnt[v[i]]);
  }
  for(int i = 0; i < 101; i++) {
    if(mx == cnt[i]) cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	double d;
	cin >> d;

	double res = 0;
	rep(i, d + 1) {
		double h = d * d - i * i;
		if(sqrt(h) < 1) {
			res = max(res, (double)(i + 1));
		}
	}

	cout << fixed;
	cout.precision(20);
	cout << max(res, d * sqrt(2)) << endl;

	return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC110(void);
void ABC111(void);
void ABC112(void);
void ABC113(void);
void ABC114(void);
void ABC115(void);
void ABC116(void);
void ABC117(void);
void ABC118(void);
void ABC119(void);

int main(void){
    ABC111();
}

void ABC111(){
    int i,n,a,b,c;
    cin>>n;
    for(i=n;i<=999;i++){
        a=i%10;
        b=(i/10)%10;
        c=i/100;
        if(a==b&&b==c)break;
    }
    cout<<c<<b<<a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000000000;
template <typename T>
struct range_edges{
	int N;
	int V;
	vector<vector<pair<T, int>>> E;
	range_edges(int n){
		N = 1;
		while (N < n){
			N *= 2;
		}
		V = N * 5 - 2;
		E = vector<vector<pair<T, int>>>(V);
		for (int i = 0; i < N - 1; i++){
			E[i].emplace_back(0, i * 2 + 1);
			E[i].emplace_back(0, i * 2 + 2);
			E[i * 2 + N * 2].emplace_back(0, i + N * 2 - 1);
			E[i * 2 + N * 2 + 1].emplace_back(0, i + N * 2 - 1);
		}
		for (int i = 0; i < N; i++){
			E[N - 1 + i].emplace_back(0, N * 4 - 2 + i);
			E[N * 4 - 2 + i].emplace_back(0, N * 3 - 2 + i);
		}
	}
	void add_edge_from(int L, int R, int v, int i, int l, int r){
		if (R <= l || r <= L){
			return;
		} else if (L <= l && r <= R){
			E[i + N * 2 - 1].emplace_back(0, v);
		} else {
			int m = (l + r) / 2;
			add_edge_from(L, R, v, i * 2 + 1, l, m);
			add_edge_from(L, R, v, i * 2 + 2, m, r);
		}
	}
	void add_edge_from(int L, int R, int v){
		add_edge_from(L, R, v, 0, 0, N);
	}
	void add_edge_to(int L, int R, int v, int i, int l, int r){
		if (R <= l || r <= L){
			return;
		} else if (L <= l && r <= R){
			E[v].emplace_back(0, i);
		} else {
			int m = (l + r) / 2;
			add_edge_to(L, R, v, i * 2 + 1, l, m);
			add_edge_to(L, R, v, i * 2 + 2, m, r);
		}
	}
	void add_edge_to(int L, int R, int v){
		add_edge_to(L, R, v, 0, 0, N);
	}
	void add_edge(int L1, int R1, int L2, int R2, T cost){
		E.emplace_back();
		E.emplace_back();
		V += 2;
		add_edge_from(L1, R1, V - 2);
		add_edge_to(L2, R2, V - 1);
		E[V - 2].emplace_back(cost, V - 1);
	}
	void debug(){
		for (int i = 0; i < V; i++){
			cout << i << ":";
			for (auto P : E[i]){
				cout << " (" << P.first << "," << P.second << ")";
			}
			cout << endl;
		}
	}
};
int main(){
  int N, M;
  cin >> N >> M;
  range_edges<long long> G(N);
  for (int i = 0; i < M; i++){
    int L, R, C;
    cin >> L >> R >> C;
    L--;
    G.add_edge(L, R, L, R, C);
  }
  int s = G.N * 4 - 2;
  vector<long long> d(G.V, INF);
  d[s] = 0;
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> Q;
  Q.push(make_pair(0, s));
  while (!Q.empty()){
    long long c = Q.top().first;
    int v = Q.top().second;
    Q.pop();
    if (d[v] >= c){
      for (auto P : G.E[v]){
        int w = P.second;
        if (d[w] > d[v] + P.first){
          d[w] = d[v] + P.first;
          Q.push(make_pair(d[w], w));
        }
      }
    }
  }
  long long ans = d[G.N * 4 - 2 + N - 1];
  if (ans == INF){
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}

Measured memory_bytes: 118284
#include<stdio.h>

int main(){
    int  N;
    int  a[3];

    scanf("%d",&N);

// N = N/100;
     if(N/100 == 7){
         printf("Yes\n");
     }
     else{
         N = N % 100;
         if(N/10==7){
             printf("Yes\n");
         }
         else{
             N = N % 10;
             if(N==7){
                printf("Yes\n");
             }
             else{
                 printf("No\n");
         }
         }
     }


    return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	char s[20];
	cin>>s;
	int b=strlen(s);
	for(int i=0;i<b;i++)
	{
		if(s[i]==',') s[i]=' ';
	}
	puts(s);
	return 0;
}

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

int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}

string calc(string &s, string formula, int sum, int i) {
  // ベースケース
  if (i == (int) s.size()) {
    if (sum == 7) {
      return formula + '=' + to_string(sum);
    } else {
      return "";
    }
  }
  // 再帰ステップ
  int num = ctoi(s[i]);

  string calculated;
  // 加算
  calculated = calc(s, formula + '+' + s[i], sum + num, i + 1);
  if (calculated == "") {
    // だめなら減算
    calculated = calc(s, formula + '-' + s[i], sum - num, i + 1);
  }

  return calculated;
}

int main() {
  string s;
  cin >> s;

  string formula;
  formula.push_back(s[0]);
  int sum = ctoi(s[0]);

  formula = calc(s, formula, sum, 1);

  cout << formula << endl;
  return 0;
}

Measured memory_bytes: 256
// =====================================================================
// macros
// =====================================================================

/// stdin macro from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537
macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

/// input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

/// test macro from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn answer_test() {
            $(
                assert_eq!(answer($input), $output);
            )*
        }
    };
}
// =====================================================================
// test cases
// =====================================================================

test!{
    /// write inputs for test cases here.
    /// e.g.) 
    /// ```
    /// "1 2 3"=>"4",
    /// r"4 5 6
    ///   7 8 9"=>"10",
    /// ```
    r"
    5 7 9
    "=>"win",
}

// =====================================================================
// functions
// =====================================================================

/// answer fn for the problem
fn answer(input: &str)->String{
    input!{
        source = input,
        a1: usize,
        a2: usize,
        a3: usize,
    }
    return if a1+a2+a3 <= 21{"win".to_string()} else{"bust".to_string()};
}

/// the entry point
fn main() {
    println!("{}",answer(&stdin!()));
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
int N; cin >> N;
int ans = 0;
int count = 0;
vector<int> H(N);
rep(i,N){
  cin >> H[i];
}
  rep(i,N-1){
      if(H[i] >= H[i+1]){
        count++;
      }
      else{
        ans = max(ans,count);
        count = 0;
      }
    }
  ans = max(ans,count);
  cout << ans << endl;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
s=ss()

cc = 0
res = s
for i in s:
    if i == "(":
        cc += 1
    elif i == ")":
        cc -= 1
        if cc < 0:
            res = "(" + res
            cc = 0

res += ")" * cc
print(res)




        

Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,K;
  cin>>N>>M;

  vector<vector<int>> data(N, vector<int>(M));
 
  for (int i = 0; i < N; i++) {
    cin>>K;
    for (int j = 0; j < K; j++) {
      cin >> data.at(i).at(j);
    }
  }
 

vector<int> check(M);
  
 for(int l = 1; l < M+1; l++){
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
 
      if (data.at(i).at(j) == l) {
        check.at(l-1)+=1;
      }
 
    }
  }
 }
  int count=0;
  
  for(int k=0;k<M;k++){
    if(check.at(k)==N){
      count++;
    }
  }

  cout<<count<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = sS.Substring(0, 1) + (sS.Length - 2).ToString() + sS.Substring(sS.Length - 1, 1);

            //出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 13268
N = int(input())
A = []
for i in range(N):
    A.append(list(map(int, input().split())))

A = sorted(A, key=lambda x: x[1])
last = A[N-1][1]
si = 0
for i in range(N):
    si += A[i][0]
    if(si > A[i][1]):
        print('No')
        exit()
print("Yes")

Measured memory_bytes: 55256
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func debug(a ...interface{}) {
	if os.Getenv("ONLINE_JUDGE") == "false" {
		fmt.Fprintln(os.Stderr, a...)
	}
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	n, p := scanInt(), scanInt()
	if n == 1 {
		fmt.Fprintln(wr, p)
		return
	}

	ans := 1
	f := func(p, i int) {
		c := 0
		for p%i == 0 {
			c++
			p /= i
		}
		if c >= n {
			ans = max(ans, i)
		}
	}

	for i := 2; i*i <= p; i++ {
		if p%i == 0 {
			f(p, i)
			f(p, p/i)
		}
	}
	fmt.Fprintln(wr, ans)
}


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

int main() {
  string s;
  cin >> s;
  int q;
  cin >> q;
  string a,b;
  b = s;
  int count_swap = 0;
  
  rep(i,q){
    int t;
    cin >> t;
    if(t == 1){
      swap(a,b);
    }else{
      int f;
      char c;
      cin >> f >> c;
      if(f == 1){
        a = a + c;
      }else{
        b = b + c;
      }      
    }
  }
  reverse(a.begin(),a.end());
  cout << a + b << endl;
  return 0;
}



Measured memory_bytes: 2028
N,L=map(int,input().split())
A=[]
B=[]
C=[]
for i in range(N):
  A.append(L+i)
a=sum(A)
for i in range(N):
  B.append(a-A[i])
for i in range(N):
  C.append(abs(a-B[i]))
c=float('inf')
ans=0
for i in range(N):
  if C[i]<c:
    ans=i
    c=C[i]
print(B[ans])

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var s = Console.ReadLine();
            var easy = true;
            for (var i = 0; i < s.Length; i++)
            {
                if (s[i] == 'U' || s[i] == 'D') continue;

                if (i % 2 == 0)
                {
                    if (s[i] != 'R') easy = false;
                }
                else
                {
                    if (s[i] != 'L') easy = false;
                }
                if (!easy) break;
            }
            Console.WriteLine(easy ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13140
n = int(input())
h = list(map(int, input().split()))
if n == 1:
  print("Yes")
  exit()
else:
  pre = False
  for i in range(n-1):
    diff = h[i+1] - h[i]
    if diff <= -2:
      print("No")
      exit()
    elif diff == -1:
      if pre == False:
        pre = True
      else:
        print("No")
        exit()
    elif diff == 0:
      continue
    else:
      pre = False
  print("Yes")


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

int main(){
    char c;
    cin >> c;
    if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
        cout << "vowel" << endl;
    else
        cout << "consonant" << endl;
}

Measured memory_bytes: 3560
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string S;
	cin >> S;
	sort(S.begin(), S.end());
	if (S == "abc") cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

const int INF = 2001001001;

void insert(vector<int> &pq, int in){
  pq.push_back(in);
  int now = pq.size() - 1;
  while(0 < now){
    int par = (now-1)/2;
    if(pq.at(par) < pq.at(now)){
      swap(pq.at(par), pq.at(now));
      now = par;
    }else break;
  }
}

int del(vector<int> &pq){
  int ret = pq.front();
  int now = 0;
  // rep(i, pq.size()){
  //   cerr << pq.at(i) << " ";
  // }
  // cerr << endl;
  pq.front() = pq.back();
  if(pq.size() == 1) return ret;
  pq.pop_back();
  while((now+1)*2-1 < pq.size()){
    int nn = pq.at(now);
    int l = (now+1)*2-1, r = (now+1)*2;
    int ll = pq.at(l), rr;
    if(pq.size() == r) rr = -INF;
    else rr = pq.at(r);
    // cerr << nn << " " << ll << " " << rr << endl;
    if(nn < rr && nn < ll){
      if(ll > rr){
        swap(pq.at(l), pq.at(now));
        now = l;
      }else{
        swap(pq.at(r), pq.at(now));
        now = r;
      }
    }else if(nn < rr){
      swap(pq.at(r), pq.at(now));
      now = r;
    }else if(nn < ll){
      swap(pq.at(l), pq.at(now));
      now = l;
    }else break;
  }
  // rep(i, pq.size()){
  //   cerr << pq.at(i) << " ";
  // }
  // cerr << endl;
  return ret;
}

int main(){
  vector<int> pq;
  while(1){
    string s;
    cin >> s;
    if(s == "end") break;
    else if(s == "insert"){
      int in;
      cin >> in;
      insert(pq, in);
    }else{
      printf("%d\n", del(pq));
    }
  }
  return 0;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    int n,k;
    cin>>n>>k;
    vector<ll> h(n);
    rep(i,n){
        cin>>h[i];
    }
    sort(h.begin(),h.end());
    ll sum=0;
    rep(i,n-k){
        sum+=h[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<array>
 
using namespace std;
 
int main() {
    int n;
    string s;
    cin >> n;
    cin >> s;
    array<long long, 3> count{};
    for (auto& e : s) {
        if(e == 'R') {
            ++count[0];
        } else if (e == 'G') {
            ++count[1];
        } else if (e == 'B') {
            ++count[2];
        }
    }
    int dup = 0;
    for (int i=0; i<n; ++i) {
        for (int j=1; i+j+j<n; ++j) {
            if(s[i] != s[i+j] && s[i+j] != s[i+j+j] && s[i+j+j] != s[i])
                ++dup;
        }
    }
    cout << count[0] * count[1] * count[2] - dup << endl;
    
}

Measured memory_bytes: 3164
#include <stdio.h>
long long int min(long long int a, long long int b){return a > b ? b : a;}
int main(void){
    int i, j, k;
    int n;
    long long int a[300][300];
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            scanf("%lld", &a[i][j]);
        }
    }
    long long int large_n = 1000000000000;
    long long int dist_min;
    long long int d, d_tmp;
    long long int ans = 0;
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            dist_min = large_n;
            d = a[i][j];
            /*この道路が必要かどうかを判定
            ある道路kを介してもっと最短で移動できるような道路であれば，-1をprint
        　　他のあらゆる道路を介しても，最短ではいけないような道路の場合，必要，ansに足す
            すべての道路を介しても，イコール以上の場合は，不必要*/

            for(k = 0; k < n; k++){
                if(i == k || k == j){
                    continue;
                }
                d_tmp = a[i][k] + a[k][j];
                if(d_tmp < d){
                    printf("-1\n");
                    return 0;
                }
                dist_min = min(dist_min, d_tmp);
            }
            if(dist_min > d){
                ans += d;
            }
        }
    }
    printf("%lld\n", ans/2);
    return 0;
}

Measured memory_bytes: 2404
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  cin >> N >> S;
  int count=0;
  for (int i=1;i<N;i++){
    if (S[i]=='E'){
      count++;
    }
  }
  int ans=count;
  for (int i=0;i<N-1;i++){
    if (S[i+1]=='E'){
      count--;
    }
    if (S[i]=='W'){
      count++;
    }
    ans=min(ans,count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 900
from itertools import combinations_with_replacement
n,m,q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]

nums = list(combinations_with_replacement(range(1,m+1), n))

ans = 0
for i in nums:
  t = 0
  for j in abcd:
    s = i[j[1]-1] - i[j[0]-1]
    if s == j[2]:
      t += j[3]
  ans = max(ans, t)
print(ans)

Measured memory_bytes: 21472
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000000000000



int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector<long long> A(N+1,0);
	
	for(int i=0;i<N;i++){
		cin>>A[i+1];
		A[i+1]+=A[i];
	}
	
	map<int,long long> mp;
	
	for(int i=0;i<=N;i++){
		mp[A[i]%M]++;
	}
	
	long long ans = 0;
	
	for(auto a:mp){
		ans += (a.second * (a.second-1))/2;
	}
	
	cout<<ans<<endl;
	
    return 0;
}


Measured memory_bytes: 4992
# -*- coding: utf-8 -*-


def main():
    n, m = map(int, input().split())
    s = list()
    c = list()

    for i in range(m):
        si, ci = map(int, input().split())
        si -= 1

        s.append(si)
        c.append(ci)

    for i in range(1000):
        digit = list(str(i))

        if len(digit) != n:
            continue

        ok = True

        for j in range(m):
            if int(digit[s[j]]) != c[j]:
                ok = False

        if ok:
            print(i)
            exit()

    print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()

using namespace std;
typedef long long ll;

template<typename T>
T gcd(T a, T b) {
	if (a % b == 0) {
		return(b);
	}
	else {
		return(gcd(b, a % b));
	}
}


template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}

int main(void) {
	char c;
	cin >> c;
	if (int(c) <= 90) {
		cout << 'A';
	}
	else {
		cout << 'a';
	}
}

/*

*/


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

using namespace std;

int n, k;
int dp[100010];

const int MOD = 1e9 + 7;

int add() {return 0;}
template<typename... Args>
int add(long long a, Args... args){
    return (a + add(args...)) % MOD;
}

int mul() {return 1;}
template<typename... Args>
int mul(long long a, Args... args){
    return (a * mul(args...)) % MOD;
}

int fp(int a, long long b){
	int ret = 1;

	while(b){
		if(b & 1) ret = mul(ret, a);

		a = mul(a, a);
		b >>= 1;
	}

	return ret;
}

int ans = 0;

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

	cin >> n >> k;

	for(int i = k; i; i--){
		dp[i] = fp(k / i, n);

		for(int j = (i << 1); j <= k; j += i)
			dp[i] = add(dp[i], -dp[j]);

		ans = add(ans, mul(dp[i], i));
	}

	if(ans < 0) ans += MOD;

	cout << ans << "\n";
	
	return 0;
}

Measured memory_bytes: 4040
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
struct node{
	string s;int c;
	inline node(R string ss,R int cc):s(ss),c(cc){}
	inline bool operator <(const node &b)const{return s<b.s;}
};set<node>s;
int x,y,z;
int main(){
	scanf("%d%d%d",&x,&y,&z);
	if(x)s.insert(node("a",x));
	if(y)s.insert(node("b",y));
	if(z)s.insert(node("c",z));
	while(2333){
		if(s.size()==1){
			node p=*s.begin();
			fp(i,1,p.c)cout<<p.s;
			puts("");
			return 0;
		}
		R node p=*s.begin(),q=*--s.end();
		s.erase(s.begin()),s.erase(--s.end());
		R int k=min(p.c,q.c);s.insert(node(p.s+q.s,k));
		if(p.c-k)s.insert(node(p.s,p.c-k));
		if(q.c-k)s.insert(node(q.s,q.c-k));
	}
	return 0;
}

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

#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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

bool dp[5010][5010]={},dpr[5010][5010]={};
signed main(){
	int n,k;
	cin>>n>>k;
	int a[5010];
	rep(i,n){
		cin>>a[i];
	}
	dp[0][0]=true;
	dpr[0][0]=true;
	rep(i,1,n+1){
		rep(j,k)dp[i][j]=dp[i-1][j];
		rep(j,k){
			if(dp[i-1][j]){
				if(j+a[i-1]<k)dp[i][j+a[i-1]]=true;
			}
		}
	}
	rep(i,1,n+1){
		rep(j,k)dpr[i][j]=dpr[i-1][j];
		rep(j,k){
			if(dpr[i-1][j]){
				if(j+a[n-i]<k)dpr[i][j+a[n-i]]=true;
			}
		}
	}
	int cnt=0;
	rep(i,n){
		int mn=INF;
		vector<int> s,t;
		rep(j,k){
			if(dp[i][j])s.push_back(j);
			if(dpr[n-i-1][j])t.push_back(j);
		}
		/*cout<<"s:";
		rep(j,s.size())cout<<s[j]<<" ";
		cout<<endl;
		cout<<"t:";
		rep(j,t.size())cout<<t[j]<<" ";
		cout<<endl;*/
		rep(j,s.size()){
			int l=lower_bound(t.begin(),t.end(),k-s[j]-a[i])-t.begin();
			if(l<t.size())chmin(mn,s[j]+a[i]+t[l]);
		}
		if(mn==INF||mn-a[i]>=k)cnt++;
	}
	cout<<cnt<<endl;
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll N;
	cin>>N;
	
	vector<ll>V;
	
	ll inp;
	
	for(ll i = 0;i<N-1;i++)
	{
		cin>>inp;
		V.push_back(inp);
	}
	
	unordered_map<ll,ll>mp;
	
	for(ll i = 0;i<V.size();i++)
	{
		mp[V[i]]++;
	}
	
	for(ll i = 1;i<=N;i++)
	{
		cout<<mp[i]<<endl;
	}
}

Measured memory_bytes: 12996
N = int(input())
h = list(map(int,input().split()))

ans = 0
s = 0
e = 0
while max(h) != 0:  
    for k in range(N):
        if h[k] != 0:
            s = k
            break
    if s == N-1:
        ans += h[N-1]
        break
    for k in range(s+1,N):
        e = k
        if h[k] == 0:
            break
        if k == N-1:
            e += 1
    t = min(h[s:e])
    for k in range(s,e):
        h[k] -= t
    ans += t
print(ans)

Measured memory_bytes: 3064
/*input
cabacc
abc
*/
 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
#include <tgmath.h>
 
using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define ar array
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define tests int r; cin >> r; while(r--)
#define MP make_pair
#define PI acos(-1)
typedef pair<long long, long long> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
 
#define M(x) ((x)%(1000000007))
 
vector<int> adj_list[100010];
bool visited[10010];

void dfs(int node){
	visited[node] = true;
	for(int n: adj_list[node]){
		if(!visited[n]){
			dfs(n);
		}
	}
}



int main() {
 	string s;
 	string t;
 	cin>>s>>t;
 	int mi = t.size();
 	rep(i,s.size()-t.size()+1){
 		int count = 0;
 		rep(j,t.size()){
 			if(s[i+j]!=t[j]){
 				count++;
 			}
 		}
 		mi = min(count,mi);
 	}
 	cout<<mi<<endl;
}



 


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

int main(){
    long long w, h, x, y;
    cin >> w >> h >> x >> y;

    double square = double(w) * double(h);

    if(x+x == w and y+y == h){
        printf("%lf 1\n",  square/2.0);
    }
    else{
        printf("%lf 0\n", square/2.0);
    }

    return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1000000000 + 7;

int main() {
    int n;
    cin >> n;
    const int m = 5;
    vector<ll> cnt(m, 0);
    string march = "MARCH";
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < m; j++) {
            if (s[0] == march[j]) cnt[j]++;
        }
    }
    ll ans = 0;
    for (int i = 0; i < m - 2; i++) {
        for (int j = i + 1; j < m - 1; j++) {
            for (int k = j + 1; k < m; k++) {
                ans += cnt[i] * cnt[j] * cnt[k];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int A, B, C, K;
	cin >> A >> B >> C >> K;

	int count = 0;
	int card;
	if (A < K) {
		count = A;
		card = K - A;
		if (B < card) {
			card = card - B;
		}
		else {
			cout << count << endl;
			return 0;
		}
		if (card > 0) {
			count = count - card;
		}
	}
	else count += K;

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define LONGLONGMAX 9223372036854775807
#define LONGLONGMIN -9223372036854775807
#define INTMAX 32767
#define INTMIN -32767
#define ROUNDUP(divisor,dividend) (divisor + (dividend - 1)) / dividend
char b;
int main(){
  cin >> b;
  if(b == 'A') cout << 'T';
  if(b == 'T') cout << 'A';
  if(b == 'C') cout << 'G';
  if(b == 'G') cout << 'C';
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int clas[30]={0},tei[28],i;
    for(i=0;i<28;i++)
    {
        scanf("%d",&tei[i]);
        clas[--tei[i]]++;
    }
    for(i=0;i<30;i++)
        if(clas[i]==0)
            printf("%d\n",i+1);
    return 0;
}

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

using namespace std;

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

    long int a,b,c,k;
    cin>>a>>b>>c>>k;

    if(k<=a+b){
        cout<<min(k,a)<<"\n";
    }
    else{
       cout<<a+((k-a-b)*-1)<<"\n";
    }


    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    int ans = 0;
    for (int i=105; i<=n; i += 2) {
        int tmp = 0;
        for (int j=1; j<=i; j += 2) {
            if (i%j == 0) ++tmp;
        }
        if (tmp == 8) ++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*input
6
7 6 8 6 1 1
*/
#include<bits/stdc++.h>
using namespace std;
const int N = 402;
const long long int inf = 1e18;
long long int dp[N][N],sum[N][N];

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

	vector<long long int> pf(n+1);
	for(int i=1;i<=n;i++) pf[i]=pf[i-1]+a[i];

	for(int i=1;i<=n;i++) for(int j=i;j<=n;j++) sum[i][j]=pf[j]-pf[i-1];
	for(int len=1;len<=n;len++)
	{
		for(int i=1;i<=n-len+1;i++)
		{
			int j = i+len-1;
			if(len==1) dp[i][j]=0;
			else
			{
				dp[i][j]=inf;
				for(int k=i;k<j;k++) dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j] + sum[i][k]+sum[k+1][j]);
			}

			// cout<<i<<" "<<j<<" "<<dp[i][j]<<"\n";
		}
	}

	cout<<dp[1][n]<<"\n";

	return 0;
}


Measured memory_bytes: 6092