akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 14;
char cn[cm], * ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int mod = 1e9 + 7;
int A[1001], B[1001];

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

	fread(cn, 1, cm, stdin);

	int N = getint(), M = getint();
	rep(i, N) A[i] = getint();
	rep(i, M) B[i] = getint();
	sort(A, A + N, greater<int>());
	sort(B, B + M, greater<int>());

	int Aima = 0;
	int Bima = 0;
	ll kotae = 1;
	int nokori = 0;

	for (int i = N * M; i >= 1; i--) {
		if (A[Aima] == i && B[Bima] == i) {
			nokori += Aima++ + Bima++;
		}
		else if (A[Aima] == i) {
			kotae = kotae * Bima % mod;
			nokori += Bima - 1;
			Aima++;
		}
		else if (B[Bima] == i) {
			kotae = kotae * Aima % mod;
			nokori += Aima - 1;
			Bima++;
		}
		else {
			kotae = kotae * nokori-- % mod;
		}
	}

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

typedef pair<int, int> pii;

using namespace std;

int a[100000];

int main()
{
	fill(a, a + 100000, 0);

	int n, q;
	cin >> n >> q;

	for (int i = 0; i < q; i++)
	{
		int c, x, y;
		cin >> c >> x >> y;

		switch (c)
		{
		case 0:
			a[x] += y;
			break;
		case 1:
		{
			int sum = a[x];
			for (int j = x + 1; j <= y; j++)
			{
				sum += a[j];
			}
			cout << sum << endl;
		}
			break;
		}
	}

	return 0;
}




Measured memory_bytes: 3476
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, i, ans=0;
    cin >> n;
    for(i=1;i<=sqrt(n)+1;i++){
        if(n%i==0){
            if(ans!=0) ans=min(ans, i+(n/i)-2);
            else ans=i+(n/i)-2;
        }
    }
    cout << ans <<endl;
    return 0;
}



Measured memory_bytes: 256
input_str = input().split()
k = int(input_str[0])
s = int(input_str[1])

count = 0
for x in range(k+1):
  for y in range(k+1):
    if x+y <= s:
      z = s-(x+y)
      if z <= k:
        count += 1
print(count)

Measured memory_bytes: 9176
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,x,cnt=0,c=0;
  cin >> n;
  vector<int> prime;
  for(int i=11; i<=55555; i+=10) {
    x=i,cnt=0;
    for(int j=2; j<x; j++) {
      if(x%j==0) {
        cnt++;
      }
    }
    if(!cnt) {
      prime.push_back(i);
      c++;
    }
    if(c==55) {
      break;
    }
  }
  for(int i=0; i<n; i++) {
    cout << prime[i] << " ";
  }
  cout << endl;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> H(N);
	for (int i = 0; i < N; i++) cin >> H[i];
	vector<int> Cost(N);
	Cost[0] = 0;
	Cost[1] = abs(H[1] - H[0]);
	for (int i = 2; i < N; i++) Cost[i] = min(Cost[i - 2] + abs(H[i] - H[i - 2]), Cost[i - 1] + abs(H[i] - H[i - 1]));
	cout << Cost[N - 1] << endl;
}


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

using namespace std;

int main() {
  int N, T;
  cin >> N >> T;
  vector<int64_t> A(N), B(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  int64_t minA = A[0];
  int64_t maxB = 0;
  for (int i = 0; i < N; i++) {
    B[i] = A[i] - minA;
    minA = min(minA, A[i]);
    maxB = max(maxB, B[i]);
  }

  int maxCount = 0;
  for (int i = 0; i < N; i++) {
    maxCount += (maxB == B[i]);
  }
  printf("%d\n", maxCount);

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i,start,end) for(int i=start;i<end;i++)
#define ll long long
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(2*b>=a)
        cout<<"0"<<endl;
    else
        cout<<a-2*b<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 10000007
#define endl "\n"
#define PI 3.14159265358979323846264338327950288
 
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;




int main(){
    FAST_IO ;
    int N ; cin >> N ;
    cout << 2 * (double) PI * N  << endl ;
    return 0 ;
}
 
 
 

Measured memory_bytes: 3780
#include<cstdio>
#include<cstring>
#include<vector>
#include<cctype>
#include<algorithm>
#include<iostream>
using namespace std;

#define reg register
typedef long long ll;
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)

#define pb push_back
#define Mod1(x)  ((x>=P)&&(x-=P))
#define Mod2(x)  ((x<0)&&(x+=P))
template <class T> inline void cmin(T &a,T b){ ((a>b)&&(a=b)); }
template <class T> inline void cmax(T &a,T b){ ((a<b)&&(a=b)); }

char IO;
int rd(){
	int s=0,f=0;
	while(!isdigit(IO=getchar())) if(IO=='-') f=1;
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(isdigit(IO=getchar()));
	return f?-s:s;
}

const int N=2e5+10;

bool be;

int n,m;
int a[N];
struct Node{ int to,w; };
vector <Node> G[N];

struct Edge{
	int u,v;
	ll w;
	bool operator < (const Edge __) const {
		return w<__.w;
	}
} E[N*75];
int cnt,fa[N];
int Find(int x){ return fa[x]==x?x:fa[x]=Find(fa[x]); }

int vis[N],sz[N];
int mi=1e9,rt;
void FindRt(int n,int u,int f){
	int ma=n-sz[u];
	for(Node t:G[u]) if(t.to!=f && !vis[t.to]) {
		int v=t.to;
		FindRt(n,v,u);
		cmax(ma,sz[v]);
	}
	if(mi>ma) mi=ma,rt=u;
}

int line[N],lc;
ll dis[N],Mindis;
int id;

void dfs(int u,int f){
	line[++lc]=u; sz[u]=1;
	for(Node t:G[u]) if(!vis[t.to] && t.to!=f){
		int v=t.to,w=t.w;
		dis[v]=dis[u]+w;
		dfs(v,u);
		sz[u]+=sz[v];
	}
	dis[u]+=a[u];
	if(dis[u]<Mindis) Mindis=dis[u],id=u;
}

void Divide(int u){
	vis[u]=1,lc=0;
	Mindis=1e18,dis[u]=0,dfs(u,0);
	rep(i,1,lc) if(line[i]!=id) E[++cnt]=(Edge){line[i],id,Mindis+dis[line[i]]};
	for(Node t:G[u]) if(!vis[t.to]) {
		mi=1e9;
		FindRt(sz[t.to],t.to,u);
		Divide(rt);
	}
}

bool ed;

int main(){
	n=rd();
	rep(i,1,n) a[i]=rd();
	rep(i,2,n){
		int u=rd(),v=rd(),w=rd();
		G[u].pb((Node){v,w}),G[v].pb((Node){u,w});
	}
	Divide(1);
	sort(E+1,E+cnt+1);
	rep(i,1,n) fa[i]=i;
	ll ans=0;
	rep(i,1,cnt){
		int u=Find(E[i].u),v=Find(E[i].v);
		if(u==v) continue;
		fa[u]=v;
		ans+=E[i].w;
	}
	printf("%lld\n",ans);
}








Measured memory_bytes: 86400
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};


int main(){
    string str;
    string T;
    cin >> str;
    cin >> T;
    REP(a,str.size()){
        if(T == str.substr(a,str.size()-a) + str.substr(0,a)){
            COUT("Yes");
            return 0;
        }

    }
    COUT("No");
    return 0;
}


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

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner scan = new Scanner(System.in);
        
        String s = scan.next();
        String t = scan.next();
        int a = scan.nextInt();
        int b = scan.nextInt();
        String u = scan.next();
        
        if(s.equals(u)){
            a--;
        }else{
            b--;
        }
        
        System.out.println(a + " " + b);
        
    }
}

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

int main() {
    long long a,b,c,k;
    cin>>a>>b>>c>>k;
    
    /*
     a(n+1)=b(n)+c(n)
     b(n+1)=c(n)+a(n)
     c(n+1)=a(n)+b(n)
     
     a(n+1)-b(n+1)=-(a(n)-b(n))
     a(n)-b(n)=(a(0)-b(0))*(-1)^n
     */
    
    long long ans;
    if(k%2==0)
        ans=a-b;
    else{
        ans=b-a;
    }
    
    if(ans<=1000000000000000000 and ans>=-1000000000000000000 ){
        cout<<ans<<endl;
    }else{
        cout<<"Unfair"<<endl;
    }
    
}


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

int main(){
    int x1,y1,x2,y2,x3,y3,x4,y4;
    cin>>x1>>y1>>x2>>y2;

    x3=y1+x2-y2;
    y3=-x1+x2+y2;

    x4=y2+x3-y3;
    y4=-x2+x3+y3;

    cout<<x3<<' '<<y3<<' '<<x4<<' '<<y4<<endl;
}

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



int main()
{
  int a,b,c;cin>>a>>b>>c;
  if(a==b)printf("%d\n",c);
  else if(a==c)printf("%d\n",b);
  else printf("%d\n",a);
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
d = defaultdict(lambda: 0)
n=int(input())
a=list(map(int,input().split()))
for x in a:
    d[x]+=1

ans=0
for x in d:
    k=d[x]
    if k-x>=0: ans+=k-x
    else: ans+=k
print(ans)

Measured memory_bytes: 18664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<int,int> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    map<ll,ll> a;
    rep(i,n){
      ll x,y;
      cin>>x>>y;
      a[x]+=y;
    }
    ll cnt=0;
    for(auto itr:a){
      cnt+=itr.second;
      if(cnt>=k){
        cout<<itr.first<<endl;
        return 0;
      }
    }
}


Measured memory_bytes: 4224
#include <iostream>
#include<bits/stdc++.h>
#define int long long int
#define vi vector<int>
#define vvi vector<vector<int>>
using namespace std;
int N=1e6+1;
int n,k;
vi a(N);
int m(int l,int h)
{
    return l+(h-l)/2;
}
int bs(int l,int h)
{
    if((h-l)<=1)
    return l+1;
    int mid=m(l,h);int i,count=0;
    for(i=0;i<n;i++)
    {
        if(mid<a[i])
        {
            int cnt=(a[i]-1)/mid;
            count+=(cnt);
            
        }
    }
    if(count>k)
    return bs(mid,h);
    return bs(l,mid);
}
int32_t main() {
	// your code goes here
	int i,j;
cin>>n>>k;
for(i=0;i<n;i++)
cin>>a[i];
sort(a.begin(),a.begin()+n);
cout<<bs(0,a[n-1])<<"\n";
	return 0;
}


Measured memory_bytes: 10912
#include <bits/stdc++.h>
using namespace std; 
#define loop for(int i=0;i<n;i++)
#define pb push_back
#define int long long int
#define mod 1000000007
int32_t main()
{
	int p=100;
	int a;
	cin>>a;
	int i=0;
	while(true)
	{
		if(p>=a)
		{
			break;
		}
		i++;
		p=p+(p)/100;
	}
	cout<<i;
}

		


Measured memory_bytes: 3636
N,K = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h = sorted(h)
tmp = 0
ans = 10000000000
loop = N-K+1
for i in range(loop):
    tmp = h[K+i-1] - h[0+i]
    if(tmp < ans):
        ans = tmp
print(ans)

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int maxNum = 0;
    maxNum = max(A, max(B, C));

    int tmp1 = maxNum * 3 - (A + B + C);
    int tmp2 = (maxNum + 1) * 3 - (A + B + C);
    if (tmp1 % 2 != 0) cout << tmp2 / 2 << endl;
    else cout << tmp1 / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		char[] c = str.toCharArray();

		if(c[0] == c[1] || c[1] == c[2] || c[2] == c[3]) {
			System.out.println("Bad");
		}else {
			System.out.println("Good");
		}

	}

}



Measured memory_bytes: 21716
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

n = int(input())
a = [int(input()) for _ in range(n)]

ans = 0
idx = 0
for i in range(n):
    if (a[idx] == 2):
        break
    else:
        ans += 1
        idx = a[idx] - 1

if (ans == n):
    print(-1)
else:
    print(ans+1)


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

int main()
{
  int w,a,b;
  cin>>w>>a>>b;
    if(a>b)
        cout<<a-(b+w);
    else if(a<b&&b<=(a+w)|| a==b)
        cout<<0;
    else cout<<b-(a+w);
    return 0;

}


Measured memory_bytes: 3632
#include<stdio.h>
#include<math.h>
int main()
{
  int n,temp;
  scanf("%d",&n);
  if(n%2!=0)
    temp=n/2+1;
  else
    temp=n/2;
  printf("%.10lf",(double)temp/(double)n);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define H 101
#define W 10001
using namespace std;
int w,h;
string mp[H];

vector<int> count(char ch){
  vector<int> res(w);
  for(int i=0;i<w;i++){
    if(i) res[i]+=res[i-1];
    for(int j=0;j<h;j++)res[i]+=mp[j][i]==ch;

  }
  return res;
}


int main(){
  cin>>w>>h;
  for(int i=0;i<h;i++) cin>>mp[i];
  for(int i=0;i<h;i++) mp[i]='#'+mp[i]+'#';
  w+=2;
  vector<int> west=count('W'),east=count('E');
  
  int mn=1e9,ans=0;
  for(int i=0;i<w;i++){
    int cntW = west.back()-west[i];
    int cntE = east[i];
    int sum = cntW+cntE;
    if(sum<mn)mn=sum,ans=i;
  }
  cout<<ans<<" "<<ans+1<<endl;
  return 0;
}

Measured memory_bytes: 4540
#include <stdio.h>
#include <string.h>

int main(void) {
	char buf[1001] = {0};
	char tbuf[1001] = {0};
	char cmd[10] = {0};
	int n, i, j;
	int a, b;
	
	scanf("%s", buf);
	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		memset(tbuf, '\0', sizeof(tbuf));
		memset(tbuf, '\0', sizeof(cmd));
		scanf("%s", cmd);
//		printf("%s %d", cmd, i);
		if (strcmp(cmd, "replace") == 0) {
//			printf("replace %d\n", i);
			scanf("%d %d %s", &a, &b, tbuf);
			for (j = a; j <= b;++j) {
				buf[j] = tbuf[j -a];				
			}
		} else if (strcmp(cmd, "reverse") == 0) {
			scanf("%d %d", &a, &b);
			for (j = a; j <= b; ++j) {
				tbuf[j-a] = buf[j];
			}
			for (j = a; j <= b; ++j) {
				buf[j] = tbuf[b - j];
			}
		} else {
			scanf("%d %d", &a, &b);
			for (j = a; j <= b; ++j) {
				putchar(buf[j]);
			}
			putchar('\n');
		}
	}
	
	return 0;
}

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

int main() {
  int T;
  cin >> T;
  while(T--) {
    string s,t;
    cin >> t >> s;
    int n=s.size();
    for(int j=t.size()-1; j>=0; j--) {
      if(t[j]=='C') rotate(s.begin(),s.begin()+1,s.end());
      if(t[j]=='J') rotate(s.begin(),s.end()-1,s.end());
      if(t[j]=='E') {
        if(s.size()%2) s=s.substr(n/2+1)+s[n/2]+s.substr(0,n/2);
        else s=s.substr(n/2)+s.substr(0,n/2);
      }
      if(t[j]=='A') reverse(s.begin(),s.end());
      if(t[j]=='M') {
        for(int i=0; i<n; i++) {
          if(!isdigit(s[i])) continue;
          if(s[i]=='9') s[i]='0';
          else s[i]++;
        }
      }
      if(t[j]=='P') {
        for(int i=0; i<n; i++) {
          if(!isdigit(s[i])) continue;
          if(s[i]=='0') s[i]='9';
          else s[i]--;
        }
      }
    }
    cout << s << endl;
  }
  return 0;
}


Measured memory_bytes: 3096
import java.util.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  long l = sc.nextLong();
	  long r = sc.nextLong();
      
      
      if(r-l > 3000) {
        System.out.println(0);
      }else {
      
        long min = 2018;
        for(long i = l; i < r; i++) {
          for(long j = l+1; j <=r; j++) {
            long num = (i*j)%2019;
            if(num<min) {
              min = num;
            }
          }
        }
                  System.out.println(min);

  
      }

      
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;

 
int main() {
    set<string> s;
    int n;
    cin >> n;
    int ans=0;
    rep(i,n){
        string f;
        cin >> f;
        auto it=s.find(f);
        if (it==s.end()) {
            ans++;
            s.insert(f);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 19228
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
using ll = long long;
int main()
{
	ll n;
    cin >> n;
    ll arr[n];
    ll x = 0;
    for(ll i=0;i<n;i++) 
    {
        cin >> arr[i];
        x ^= arr[i];
    }
    for(ll i=0;i<n;i++)
    {
        ll ans = x ^ arr[i];
        cout << ans << " " ;
    }
    cout << endl;
    
	return 0;
}

Measured memory_bytes: 5128
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define MOD 1000000007
using ll = long long;

long long minf(int u)
{
    long long sol = 1ll;
    while (--u)
    {
        sol *= 10;
    }
    return sol;
}

long long maxf(int u)
{
    long long sol = 1ll;
    while (u--)
    {
        sol *= 10;
    }
    sol--;
    return sol;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(10);
    // Those who forgive themselves, and are able to accept their true nature...THEY ARE THE STRONG ONES

    int k,a, b;
    cin >> k >> a >> b;
    b = k * (b / k);
    if(a <= b) {
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <map>

#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;

char GetOperator(int bit, int digit)
{
    return (bit & 1 << digit) ? '+' : '-';
}

int main()
{
    std::string str;
    std::cin >> str;

    std::vector<int> v(4);
    v[0] = str[0] - '0';
    v[1] = str[1] - '0';
    v[2] = str[2] - '0';
    v[3] = str[3] - '0';

    int bit = 1 << 3;
    for (auto i=0; i<bit; ++i)
    {
        auto result = v[0];
        for (int op=0; op<3; ++op)
        {
            // i番目を足すか引くか
            if (1 << op & i)
            {
                result += v[op+1];
            }
            else
            {
                result -= v[op+1];
            }
        }

        if (result == 7)
        {
            std::cout << v[0] << GetOperator(i, 0)
                        << v[1] << GetOperator(i, 1)
                        << v[2] << GetOperator(i, 2)
                        << v[3] << "=7" << std::endl;

            return 0;
        }
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace Atcoder2
{
    class Program
    {

        public static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int ans = 0;
            
            for(int i = 0; i < input.Length; i++)
            {
                ans = ans + int.Parse(input[i].ToString());
            }

            if (ans % 9 == 0)
            {
                Console.WriteLine("Yes");
            } else
            {
                Console.WriteLine("No");
            }
        }

    }
}

Measured memory_bytes: 32996
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;

int a[100001];
int b[100001];
int n, x;

int f(int a, int b) {
  if(b == 0 ) {
    return a;
  }
  else {
   return f(b, a % b);
  }
}

int main() {
  cin >> n >> x;
  rep(i, n)
    cin >> a[i];
  a[n] = x;
  sort(a, a+n+1);
  if(n == 1){
    cout << a[1]-a[0] << endl;
    return 0;
  }
  rreps(i, n)
    b[i] = a[i]-a[i-1]; 
  int ans = 1 << 30;
  sort(b, b+n+1);
  for(int i = n;i> 1; i--){
    int tmp = f(b[i-1], b[i]);

    ans =min(tmp, ans);
  }
  cout << ans << endl;
}



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

template<typename T>
istream& operator >> (istream& istr, vector<T>& vec){
    for(T& x: vec) istr >> x;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& vec){
    if(!vec.empty()){
        ostr << vec.front();
        for(auto itr = ++vec.begin(); itr != vec.end(); itr++)
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    ostr << p.first << " " << p.second;
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& mat){
    if(!mat.empty()){
        ostr << mat.front();
        for(auto itr = ++mat.begin(); itr != mat.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
// vll x(n); x[i]=a;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
// vvll x(m,vi(n)); x[i][j]=a;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll>> vpll;
// vpll x(n); x[i]={a,b}; x[i].first/second;

#define PI 3.1415926535897932
#define INF 1e+12
#define EPS 1e-12
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

int main(){
    ll n, m, p, ac=0, wa=0;
    string s;
    cin >> n >> m;
    vll a(n, 0);
    vll w(n, 0);
    REP(i, m){
        cin >> p >> s;
        if(a[p-1] == 0){
            if(s == "AC"){
                a[p-1] = 1;
                ac += 1;
                wa += w[p-1];
            }
            else{
                w[p-1] += 1;
            }
        }
    }
    cout << ac << " " << wa << endl;
    return 0;
}


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

#define LL long long
#define int long long
#define PB push_back
#define N 500001
#define LG 22
#define MXQ 200001
#define M 1000000007
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define LD double
#define F first
#define S second
#define ll long long
#define inf LLONG_MAX
#define endl "\n"

int32_t main()
{
    LL i,j,lt,d,z,v,c,r,l,q,x,y,m,n,x1,y1,t1,k;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    LL a[n];
    k=0;
    x=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(x<=a[i])
            k++;
        x=max(x,a[i]);
    }
    cout<<k;
}       

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var a [3][3]int
  for i := 0; i < 3; i++ {
    for j := 0; j < 3; j++ {
      fmt.Scan(&a[i][j])
    }
  }
  var n int 
  fmt.Scan(&n)
  announced := make(map[int]bool)
  for i := 0; i < n; i++ {
    var b int 
    fmt.Scan(&b)
    announced[b] = true
  }
  var res [3][3]bool
  for i := 0; i < 3; i++ {
    for j := 0; j < 3; j++ {
      if _, ok := announced[a[i][j]]; ok {
        res[i][j] = true
      }
    }
  }

  var flag bool
  for i := 0; i < 3; i++ {
    flag = true
    for j := 0; j < 3; j++ {
      if res[i][j] {continue}
      flag = false
      break
    }
    if flag {
      fmt.Println("Yes")
      return
    } 
  }
  for j := 0; j < 3; j++ {
    flag = true
    for i := 0; i < 3; i++ {
      if res[i][j] {continue}
      flag = false
      break
    }
    if flag {
      fmt.Println("Yes")
      return
    }
  }
  flag = true
  for i := 0; i < 3; i++ {
    if res[i][i] {continue}
    flag = false
    break
  }
  if flag {
    fmt.Println("Yes")
    return
  }
  flag = true
  for i := 0; i < 3; i++ {
    if res[i][2-i] {continue}
    flag = false
    break
  }
  if flag {
    fmt.Println("Yes")
    return
  }
  fmt.Println("No")
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  scanf("%d", &n);
  int max=0;
  int second=0;
  int maxi;
  for(int i=0; i<n; i++){
    int tmp;
    cin>>tmp;
    if(tmp>max){
      second=max;
      max=tmp;
      maxi=i;
    }
    else if(tmp>second){
      second=tmp;
    }
  }
  for(int i=0;i<n;i++){
    if(i!=maxi) cout<<max<<endl;
    else cout<<second<<endl;
  }
  return 0;
}

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

int main() {
	ios :: sync_with_stdio(false);
	for(int d; cin >> d; ) {
		int ans = 0;
		for(int i = 0; i < 600; i += d)
			ans += d * i * i;
		cout << ans << '\n';	
	}
	return 0;
}

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

int main()
{
    int N;
    int count = 0;
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++)
        {
            for(int k = 0; k < N; k++)
                count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
A_college = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]

N = int(input())
moves = [[int(i)-1 for i in input().split()] for _ in range(N)]

for m in moves:
    b,f,r,v = m
    v += 1
    A_college[b][f][r] += v

for b,building in enumerate(A_college):
    if 0 != b: print('#'*20)
    for flr in building:
        print('',*flr)


Measured memory_bytes: 5624
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;


int main(){
  string S;
  cin >> S;
  int ans=0;
  for(int i=0; i<(int)S.size()-1; i++){
    if(S[i] != S[i+1]){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i
 
count = 0
(a+1).times do |i|
  (b+1).times do |j|
    (c+1).times do |k|
      count += 1 if 500*i + 100*j + 50*k == x
    end
  end
end
puts count


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

using namespace std;

const double EPS = 1e-8, PI = acos(-1);

inline bool eq(double a, double b) { return fabs(b - a) < EPS; }

struct Point
{
  double x, y;

  Point() {}

  Point(double x, double y) : x(x), y(y) {}

  Point operator+(const Point &b) const { return Point(x + b.x, y + b.y); }

  Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); }

  Point operator*(const double b) const { return Point(x * b, y * b); }

  Point operator*(const Point &b) const { return Point(x * b.x - y * b.y, x * b.y + y * b.x); }

  Point operator/(const double b) const { return Point(x / b, y / b); }

  bool operator<(const Point &b) const { return x != b.x ? x < b.x : y < b.y; }

  bool operator==(const Point &b) const { return eq(x, b.x) && eq(y, b.y); }

  double norm() { return x * x + y * y; }

  double arg() { return atan2(x, y); }

  double abs() { return sqrt(norm()); }

  Point rotate(double theta) { return Point(cos(theta) * x - sin(theta) * y, sin(theta) * x + cos(theta) * y); }

  Point rotate90() { return Point(-y, x); }

  friend ostream &operator<<(ostream &os, Point &p) { return os << "(" << p.x << "," << p.y << ")"; }

  friend istream &operator>>(istream &is, Point &a) { return is >> a.x >> a.y; }
};

double cross(const Point &a, const Point &b)
{
  return a.x * b.y - a.y * b.x;
}

double dot(const Point &a, const Point &b)
{
  return a.x * b.x + a.y * b.y;
}

struct Segment
{
  Point a, b;

  Segment() {};

  Segment(Point a, Point b) : a(a), b(b) {};

  friend ostream &operator<<(ostream &os, Segment &p) { return os << "(" << p.a.x << "," << p.a.y << ") to (" << p.b.x << "," << p.b.y << ")"; }

  friend istream &operator>>(istream &is, Segment &a) { return is >> a.a.x >> a.a.y >> a.b.x >> a.b.y; }
};

int ccw(const Point &a, Point b, Point c)
{
  b = b - a, c = c - a;
  if(cross(b, c) > EPS) return +1;
  if(cross(b, c) < -EPS) return -1;
  if(dot(b, c) < 0) return +2;
  if(b.norm() < c.norm()) return -2;
  return 0;
}

Point Projection(const Segment &l, const Point &p)
{
  double t = dot(p - l.a, l.a - l.b) / (l.a - l.b).norm();
  return l.a + (l.a - l.b) * t;
}

bool Intersect(const Segment &s, const Point &p)
{
  return ccw(s.a, s.b, p) == 0;
}

bool Intersect(const Segment &s, const Segment &t)
{
  return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}

double Distance(const Segment &s, const Point &p)
{
  Point r = Projection(s, p);
  if(Intersect(s, r)) return (r - p).abs();
  return min((s.a - p).abs(), (s.b - p).abs());
}

double Distance(const Segment &a, const Segment &b)
{
  if(Intersect(a, b)) return 0;
  return min(min(Distance(a, b.a), Distance(a, b.b)), min(Distance(b, a.a), Distance(b, a.b)));
}

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

  if(N > 5100) {
    cout << 0 << endl;
    return (0);
  }

  vector< Segment > seg(N);
  double ret = 1e9;
  for(int i = 0; i < N; i++) {
    cin >> seg[i].a >> seg[i].b;
    for(int j = 0; j < i; j++) {
      ret = min(ret, Distance(seg[i], seg[j]));
    }
  }
  cout << fixed << setprecision(10) << ret << endl;
}


Measured memory_bytes: 3248
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element


int N;
int K;
string S;

signed main()
{
	cin >> N >> K;
	cin >> S;
	S[K - 1] = S[K - 1] - ('A' - 'a');
	cout << S << endl;
}



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

int main(void)
{
  int n,m;
  cin>>n>>m;
  
  int sum=0;
  int a[n];
  for(int i=0; i<n; i++){
    cin>>a[i];
    sum+=a[i];
  }
  
  int cnt=0;
  for(int i=0; i<n; i++){
    if(a[i]>=((double)sum/(4*m))){
      cnt++;
    }
  }
  
  if(cnt>=m){
  	cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

using namespace std;


#define PI 3.14159265
#define int long long


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



main(){


	int a, b, c, d;


	cin >> a >> b >> c >> d;


	int t = c * d / gcd(c, d);


	int A = b / c - (a - 1) / c;
	int B = b / d - (a - 1) / d;
	int C = b / t - (a - 1) / t;


	cout << (b - a + 1) - (A + B - C) << endl;





	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    cout << n/3 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{

    string S,T;
    cin >> S >> T;
    int a,b;
    cin >> a >> b;
    string U;
    cin >> U;
    if(U == S) cout << a-1 csp b << endl;
    else cout << a csp b-1 << endl;
    
    
    
    

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int p = 0;
    int max = 0;
    int min = 0;
    for (int i = 0; i < n; i++) {
      char c = s.charAt(i);
      if (c == '(') {
        p++;
      } else {
        p--;
      }
      max = Math.max(p, max);
      min = Math.min(p, min);
    }
    int d = - min;
    for (int i = 0; i < d; i++) {
      System.out.print("(");
    }
    System.out.print(s);
    for (int i = 0; i < p + d; i++) {
      System.out.print(")");
    }
    System.out.println("");
  }
}

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

int main() {
  int N, M;
  cin >> N;
  cin >> M;
  vector<int> data(N, 0);
  vector<bool> dataResult(N, false);
  bool error = false;
  for (int i = 0; i < M; i++) {
    int keta;
    cin >> keta;
    int number;
    cin >> number;
    if ((dataResult[keta - 1] == true && data[keta - 1] != number) || N >= 2 && keta == 1 && number == 0) {
      error = true;
    } else {
      data[keta - 1] = number;
      dataResult[keta - 1] = true;
    }
  }
  int result = 0;
  int keta = 1;
  if (!error) {
    for (int i = N - 1; i >= 0; i--) {
      int tmp = N >= 2 && i == 0 && data[i] == 0 ? 1: data[i];
      result += tmp * keta;
      keta *= 10;
    }
  } else {
    result = -1;
  }
  cout << result << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int N,L;
string S[110];

int main()
{       
        cin >> N >> L;
        for(int i=0;i<N;++i){
                cin >> S[i];
        }       
        sort(S,S+N);
        string ans = "";
        for(int i=0;i<N;++i){
                ans += S[i];
        }       
        cout << ans << endl;
}       

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

typedef long long ll;
const int MAX_VALUES = 1000*100 + 5;
ll const MAX_WEIGHTS = 1e9*100 + 5;
ll w[105], v[105], dp[MAX_VALUES];
int N, W, ans = 0;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> W;

    fill(dp, dp + MAX_VALUES, MAX_WEIGHTS);

    for(int i = 0; i < N; i++) {
        cin >> w[i] >> v[i];
        //dp[w[i]] = v[i];
    }

    for(int i = 0; i < N; i++) {
        for(int x = MAX_VALUES - 2; x >= 0; x--) {
            if(dp[x] != MAX_WEIGHTS)
                dp[x + v[i]] = min(dp[x + v[i]], dp[x] + w[i]);
            else if(x == 0)
                dp[x + v[i]] = min(dp[x + v[i]], w[i]);
        }
    }

    for(int i = 1; i < MAX_VALUES; i++)
        if(dp[i] <= W) ans = max(ans, i);
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <memory>

struct Node{
    int key;
    std::shared_ptr<Node> prev, next;
};

class DoubleLinkedList{
 public: 
    DoubleLinkedList(){
        nil_ = std::make_shared<Node>();
        nil_->prev = nil_;
        nil_->next = nil_;
    }

    void InsertFront(const int key){
        std::shared_ptr<Node> new_node = std::make_shared<Node>();
        new_node->key = key;
        nil_->next->prev = new_node;
        new_node->next = nil_->next;
        nil_->next = new_node;
        new_node->prev = nil_;
    }

    void DeleteKey(const int key){
        std::shared_ptr<Node> p = nil_->next;
        while(p != nil_ && p->key != key){
            p = p->next;
        }
        if(p == nil_)
            return;
        Delete(p);
    }

    void DeleteFirst(){
        Delete(nil_->next);
    }

    void DeleteLast(){
        Delete(nil_->prev);
    }

    void Dump(){
        auto p = nil_->next;
        while(p != nil_){
            std::cout << p->key << ((p->next == nil_) ? "\n" : " ");
            p = p->next;
        }
    }
 protected: 
    std::shared_ptr<Node> nil_;
    void Delete(std::shared_ptr<Node> p){
        p->prev->next = p->next;
        p->next->prev = p->prev;
    }
};


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

    int n;
    std::cin >> n;
    DoubleLinkedList list;
    for(; n>0; n--){
        std::string command;
        std::cin >> command;
        if(command == "insert"){
            int a;
            std::cin >> a;
            list.InsertFront(a);
        }else if(command == "delete"){
            int a;
            std::cin >> a;
            list.DeleteKey(a);
        }else if(command == "deleteFirst"){
            list.DeleteFirst();
        }else if(command == "deleteLast"){
            list.DeleteLast();
        }
    }
    list.Dump();
}


Measured memory_bytes: 65512
#include<iostream>
#include<algorithm>
using namespace std;
int n,p[20],cnt;
int main(){
    cin>>n;
    for(int i=0;i<n;i++)cin>>p[i];
    for(int i=1;i<n-1;i++){
        int a=p[i-1]+p[i]+p[i+1];
        a-=min({p[i-1],p[i],p[i+1]});
        a-=max({p[i-1],p[i],p[i+1]});
        if(a==p[i])cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; ++i)
const long long INF = 1LL << 60;
using namespace std;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  vector<int> H(100100);
  rep(i, n) cin >> H[i];

  int dp[100100];
  dp[0] = 0;
  for(int i = 1; i < n; ++i) {
      dp[i] = dp[i-1] + abs(H[i]-H[i-1]);
      if(i >= 2) dp[i] = min(dp[i], dp[i-2] + abs(H[i-2]-H[i]));
  }
  cout << dp[n-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a < b && b < c) {
		cout << a << " " << b << " " << c << endl;
	}
	else if (a <= c && c <= b)
	{
		cout << a << " " << c << " " << b << endl;
	}
	else if (b <= a && a <= c) {
		cout << b << " " << a << " " << c << endl;
	}
	else if (b <= c && c <= a) {
		cout << b << " " << c << " " << a << endl;
	}
	else if (c <= a && a <= b) {
		cout << c << " " << a << " " << b << endl;
	}
	else if (c <= b && b <=a) {
		cout << c << " " << b << " " << a << endl;
	}
}


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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }

    int cnt = 0;
    while(true){
        bool flag = true;
        for(int i = 0; i < n; i++){
            if(h[i] != 0){
                flag = false;
                break;
            }
        }
        if(flag){
            break;
        }

        int tmp; 
        for(int i = 0; i < n; i++){
            if(h[i] != 0){
                tmp = i;
                break;
            }
        }

        for(int i = tmp; i < n; i++){
            if(h[i] == 0){
                break;
            }
            h[i]--;
        }
        cnt++;
        /*
        for(int i = 0; i < n; i++){
            cout << h[i] << " ";
        }
        cout << endl;
        */
    }

    cout << cnt << endl;

    return 0;
}

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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int h,a;

int32_t main()
{
    IOS
    cin>>h>>a;
    cout<<(h+a-1)/a<<endl;
}



Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
i = 1
while i < N:
	A[i] += A[i - 1]
	i += 1
a = {}
for i in A:
	if i in a:
		a[i] += 1
	else:
		a[i] = 1
ans = A.count(0)
for i in a.values():
	ans += (i - 1) * i // 2
print(ans)

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    if (m <= n) {
        cout << 0 << endl;
        return 0;
    }
    vector<int> x(m);
    for (int i = 0; i < m; i++) cin >> x[i];
    sort(x.begin(), x.end());

    vector<ll> d(m-1);
    for (int i = 1; i < m; i++) d[i-1] = x[i]-x[i-1];
    sort(d.begin(), d.end());
    ll ans = 0;
    for (int i = 0; i < m-1-(n-1); i++) ans += d[i];
    cout << ans << endl;
    return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n,cnt=0,ans=0,a[10000000],b,c,cmp=1,cmpp=1,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

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

       cin >> n;
       rep(i,n)cin>>a[i];
       rep(i,n){
           cmp*=3;
       }
       rep(i,n){
           if(a[i]%2==0){
               cmpp*=2;
           }
           else{
               cmpp*=1;
           }
       }
       Cout(cmp-cmpp);
return 0;
}


Measured memory_bytes: 256
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const prices = input[0].map(Number);

  prices.sort((a, b) => a - b);

  return prices[0] + prices[1];
};

console.log(main(read()));


Measured memory_bytes: 29592
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] montains = new int[N + 1];
		int westMost = 0;
		int ans = 0;
		for (int i = 1; i <= N; i++) {
			montains[i] = scanner.nextInt();
			if(montains[i] >= westMost) {
				westMost = montains[i];
				ans++;
			}
		}
		System.out.println(ans);
		scanner.close();
	}
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        string str[4];
        int num[4]={-1,-1,0,0};
        for(int i=0,sum;i<n;i++){
            string st;
            cin>>st;
            sum=0;
            for(int j=0,minute,second;j<4;j++){
                cin>>minute>>second;
                sum+=60*minute+second;
            }
            for(int j=0;j<2;j++){
                if(sum<num[j]||num[j]==-1){
                    swap(num[j],sum);
                    swap(str[j],st);
                }
            }
            for(int j=3;j>1;j--){
                if(sum>num[j]){
                    swap(num[j],sum);
                    swap(str[j],st);
                }
            }
        }
        for(int i=0;i<3;i++)cout<<str[i]<<endl;
    }
}

Measured memory_bytes: 1200
#include <stdio.h>
int main(void){
  	int count[4][3][10] = {};

	int N, i, j, k;


	scanf("%d", &N);

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

		int b, f, r, v;

		scanf("%d %d %d %d", &b, &f, &r, &v);

		count[b - 1][f - 1][r - 1] += v;

	}

	for (i = 0; i < 4; i++) {

		if (i > 0) printf("####################\n");

		for (j = 0; j < 3; j++) {

			for (k = 0; k < 10; k++) {

				printf(" %d", count[i][j][k]);

			}

			printf("\n");

		}

	}

	return 0;

}// Your code here!


Measured memory_bytes: 2140