akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
char S[200010];
int f[200010],sf[200010];
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi(),m=gi(),all=0;
	scanf("%s",S+1);
	int L=1145141;
	for(int l=1,r;l<=m;l=r+1){
		r=l;if(S[l]!=S[1])continue;
		while(r<m&&S[r+1]==S[r])++r;
		if(l==1&&r==m)all=1;
		if(((r-l+1&1)||l==1)&&r<m)cnk(L,r-l+2);
	}
	if(all){
		static int f[200010][2];
		int ans=0;
		for(int fir=0;fir<2;++fir){
			memset(f,0,sizeof f);
			f[1][fir]=1;
			for(int i=1;i<=n;++i){
				inc(f[i+1][0],f[i][1]);
				inc(f[i+1][1],f[i][0]);
				inc(f[i+1][1],f[i][1]);
			}
			if(fir)inc(ans,f[n][0]);
			inc(ans,f[n][1]);
		}
		printf("%d\n",ans);
		return 0;
	}
	if(L&1)++L;
	f[1]=sf[1]=1;
	for(int i=2;i<=n;++i)f[i]=(sf[i-2]-(i-L-2<0?0:sf[i-L-2])+mod)%mod,sf[i]=(f[i]+sf[i-2])%mod;
	int ans=0;
	for(int i=n-1;n-i<L&&i>=0;i-=2)
		inc(ans,1ll*(n-i+1)*f[i]%mod);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;

int main(){

  int n;
  cin >> n;
  vector<long long> a(3*n);
  rep(i,3*n) cin >> a[i];

  vector<long long> S(2*n,0);
  priority_queue<long long, vector<long long>, greater<long long> > p1;

  S[0] = a[0];
  rep(i,n){
    p1.push(a[i]);
    if(i == 0) continue;
    else S[i] = S[i-1] + a[i];
  }

  for(int i=n; i<2*n; ++i){
    S[i] = S[i-1];
    S[i] += a[i];
    p1.push(a[i]);
    S[i] -= p1.top();
    p1.pop();
  }

  vector<long long> T(2*n,0);
  priority_queue<long long> p2;

  T[0] = a[3*n-1];
  rep(i,n){
    p2.push(a[3*n-1 - i]);
    if(i == 0) continue;
    else T[i] = T[i-1] + a[3*n-1 - i];
  }

  for(int i=n; i<2*n; ++i){
    T[i] = T[i-1];
    T[i] += a[3*n-1 - i];
    p2.push(a[3*n-1 - i]);
    T[i] -= p2.top();
    p2.pop();
  }

  long long res = -(1LL << 60);
  for(int i=n; i<=2*n; ++i){
    res = max(res, S[i-1] - T[3*n-1 - i]);
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 8052
package main

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

//FOR I/O : STARTS
var Reader *bufio.Reader = bufio.NewReader(os.Stdin)
var Writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func Printf (f string, a ...interface{}) { fmt.Fprintf(Writer, f, a...) }
func Scanf (f string, a ...interface{}) { fmt.Fscanf(Reader, f, a...) }
func Println (a ...interface{}) { fmt.Fprintln(Writer, a...)}
func Scanln (a ...interface{}) { fmt.Fscanln(Reader, a...)}
//I/O ENDS HERE



func main() {
    defer Writer.Flush()

    var a, b, k int
    Scanf("%d\n%d %d\n", &k, &a, &b)

    // Println(k, a, b)

    for i := 1; i*k <= 1000; i += 1 {
        if a <= i*k && i*k <= b {
            Println("OK")
            return
        }
    }
    Println("NG")
}


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    bool flag = false;
    if(a == b && a != c) flag = true;
    else if(a == c && a != b) flag = true;
    else if(b == c && a != c) flag = true;

    cout << (flag ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

int go_x[300000] = {};
int go_y[300000] = {};

void solve() {
	int n, w, h;
	cin >> n >> w >> h;
	REP(i, n) {
		int a, b, c;
		cin >> a >> b >> c;
		go_x[max(a - c, 0LL)]++;
		go_x[a + c]--;
		
		go_y[max(b - c, 0LL)]++;
		go_y[b + c]--;
	}
	{
		int ok = 1;
		REP(i, w) {
			go_x[i + 1] += go_x[i];
			if (go_x[i] == 0) {
				ok = 0;
			}
		}
		if (ok == 1) {
			cout << "Yes" << endl;
			return;
		}
	}
	{
		int ok = 1;
		REP(i, h) {
			go_y[i + 1] += go_y[i];
			if (go_y[i] == 0) {
				ok = 0;
			}
		}
		if (ok == 1) {
			cout << "Yes" << endl;
			return;
		}
	}

	cout << "No" << endl;
	return;
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 6256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s,t;
	cin>>s>>t;
	ll n=s.length();
	ll m=t.length();
	ll dp[n+2][m+2];
	memset(dp,0,sizeof(dp));
	for(ll i=1;i<=n;i++)
	{
		if (s[i-1]==t[0])
			dp[i][0]=0;
		dp[i][0]=max(dp[i][0],dp[i-1][0]);
	}
	for(ll i=1;i<=m;i++)
	{
		if (s[0]==t[i-1])
			dp[0][i]=0;
		dp[0][i]=max(dp[0][i],dp[0][i-1]);
	}
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=m;j++)
		{
			if (s[i-1]==t[j-1])
			{
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else
			{
				dp[i][j]=max(dp[i][j],dp[i-1][j]);
				dp[i][j]=max(dp[i][j],dp[i][j-1]);
			}
			
		}
		
	}
	/*
	for(ll i=0;i<=n;i++)
	{
		for(ll j=0;j<=m;j++)
		{
			cout<<dp[i][j]<<" "; 
		}
		cout<<endl;
	}*/
	ll i=n,j=m;
	string ans="";
	while(i>=1 and j>=1)
	{
		if (s[i-1]==t[j-1])
		{
			ans+=s[i-1];
			i--;j--;
		}
		else
		{
			if (dp[i-1][j]>=dp[i][j-1])
			{
				i--;
			}
			else
			{
				j--;
			}
		}
		//cout<<i<<" "<<j<<endl;
	}
	
	reverse(ans.begin(),ans.end());
	cout<<ans;
}

Measured memory_bytes: 70656
#include <algorithm>
#include <iostream>
#include <iterator>
#include <limits>
#include <sstream>
#include <vector>

using namespace std;
int main() {
  cin.ignore(numeric_limits<streamsize>::max(), '\n');
  string s;
  getline(cin, s);
  istringstream is{s};
  istream_iterator<int> ii{is}, eol;
  vector<int> v{ii, eol};
  cin.ignore(numeric_limits<streamsize>::max(), '\n');

  int b, m, e;
  while (cin >> b >> m >> e) {
    rotate(v.begin() + b, v.begin() + m, v.begin() + e);
  }
  cout << v[0];
  for (auto it = ++v.begin(); it != v.end(); ++it)
    cout << " " << *it;
  cout << endl;
}


Measured memory_bytes: 3188
n = int(input())
a = list(map(int, input().split()))


def count_2(x):
    if x % 2 != 0:
        return 0
    else:
        return count_2(x // 2) + 1


ans = 0
for i in range(n):
    ans += count_2(a[i])

print(ans)


Measured memory_bytes: 10052
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int n,m,x,sum,ans=1e9,a[15][15],c[15],b[15];
int main(){
	n=read(),m=read(),x=read();
	for(int i=0;i<n;i++){
		c[i]=read();
		for(int j=0;j<m;j++)
			a[i][j]=read();
	}
	for(int i=0;i<(1<<n);i++){
		memset(b,0,sizeof(b)),sum=0;
		for(int j=0;j<n;j++)
			if(i&(1<<j))
				for(int k=0;k<m;k++)
					b[k]+=a[j][k];
		bool y=true;
		for(int j=0;j<m;j++)
			if(b[j]<x){
				y=false;
				break;
			}
		if(y){
			for(int j=0;j<n;j++)
				if(i&(1<<j))sum+=c[j];
			ans=min(ans,sum);
		}
	}
	if(ans==1e9)ans=-1;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3636
using System;

class Sample
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var b = int.Parse(line[1]);
        var c = int.Parse(line[2]);
        if (a < b && b < c) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}


Measured memory_bytes: 15980
n, p = [int(i) for i in input().split()]
s = input()




digit_rm = [0 for _ in range(n)]
for i in range(n):
	digit_rm[i] = (int(s[n-1-i]) * pow(10, i, p) ) % p

remain = [0 for _ in range(n)]
for i in range(n):
	if i == 0:
		remain[i] = digit_rm[i]
	else:
		remain[i] = (remain[i-1] + digit_rm[i]) % p

pcnt = [0 for _ in range(p)]

for i in remain:
	pcnt[i] += 1

if 10 % p == 0:
	ans = 0
	for i in range(n):
		if int(s[n-1-i]) % p == 0:
			ans += n - i
	print(ans)
else:
	ans = pcnt[0]
	for num in pcnt:
		if num != 0:
			ans += num * (num - 1) // 2

	print(ans)







Measured memory_bytes: 18420
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//根なら-size,子なら親の頂点を示す
vector<int> par(200000,-1);

//xの根を求める
int find(int x){
    if(par[x]<0)return x;
    else{
        par[x]=find(par[x]);
        return par[x];
    }
}

//xとyの属する集合の合体
bool merge(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return false;
    else{ //sizeの大きい方をxとする
        if(par[x]>par[y])swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }
}

//xとyが同じ集合に属するかの判定
bool same(int x,int y){
    if(find(x)==find(y))return true;
    else return false;
}

//xが属する集合の個数
int size(int x){
    return -par[find(x)];
}


//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int n,m,x,y;cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>x>>y;x--;y--;
        merge(x,y);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(par[i]<ans)ans=par[i];
    }
    cout<<-ans<<endl;
}


Measured memory_bytes: 3900
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		
		int a,b;
		
		while(true) {
			char[] serve = scan.next().toCharArray();
			
			if(serve[0] == '0') break;
			
			a = 0;
			b = 0;
			
			for(int i = 1; i < serve.length; i++) {
				if(serve[i] == 'A') {
					a++;
					
				} else {
					b++;
					
				}
			}
			if(a > b) {
				a++;
				
			} else {
				b++;
				
			}
			System.out.println(a + " " + b);
		}
		
		scan.close();
	}
}

Measured memory_bytes: 25828
n = gets.chomp.to_i
s = ""
while n > 0
	mod = n % 26
	a = mod == 0 ? "z".ord : "a".ord + mod - 1
	s += a.chr
	#puts "mod:#{mod} n:#{n}"
	n -= 1
	n /= 26
end
puts s.reverse



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

using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int64_t n, m;
  cin >> n >> m;

  if (m < n) swap(n, m);
  if (n == 2 || m == 2) {
    cout << 0;
  } else if (n == 1) {
    if (m == 1) {
      cout << 1;
    } else {
      cout << (m - 2);
    }
  } else {
    cout << ((n - 2) * (m - 2));
  }
  cout << "\n";
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1);





int main() 
{
  ll N; cin>>N;
  vector<vector<vector<ll>>> vec(N,vector<vector<ll>>(0));
  rep(i,N)
  {
    ll A; cin>>A;
    rep(j,A)
    {
      ll x,y; cin>>x>>y; x--;
      vec.at(i).push_back({y,x});
    }
  }
  ll ans=0;
  rep(i,1<<N)
  {
    bitset<15> i2(i);
    ll ans2=0;
    rep(j,N)
    {
      if(i2.test(j))
      {
        ans2++;
        for(auto p:vec.at(j))
        {
          ll x=p.at(1),y=p.at(0);
          if(y==1&&!i2.test(x)) {goto OUT;}
          if(y==0&&i2.test(x)) {goto OUT;}
        }
      }
    }
    ans=max(ans,ans2);
    OUT:;
    //cout<<i<<" "<<ans<<endl;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin>>s;

    if(s[0]==s[1]&&s[1]==s[2]){
        cout<<s<<endl;
    }
    else if(s[0]>s[1]||(s[0]==s[1]&&s[1]>s[2])){
        int x=s[0]-'0';
        cout<<x*100+x*10+x<<endl;
    }
    else if(s[0]<s[1]||(s[0]==s[1]&&s[1]<s[2])){
        int x=(s[0]-'0')+1;
        cout<<x*100+x*10+x<<endl;
    }
}

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

int main(){
	
	int A,B,C,temp;

	cin >> A >> B >> C; 

	temp = A - B;
	C = C - temp;
	
	if(C > 0) cout << C <<endl;
	else cout << 0 <<endl;
	

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define all(x) x.begin(), x.end()
using namespace std;
using vi = vector<int>;

int main() {
    vi a(3);
    for (int i = 0; i < a.size(); i++)
        cin >> a[i];
    sort(all(a));
    for (int i = 0; i < a.size(); i++) {
        cout << a[i];
        if (i < 2) cout << ' ';
        else cout << endl;
    }
}



Measured memory_bytes: 3148
#include <stdio.h>
#include <stdlib.h>
 
void maxHeap(int *, int, int);

int main(void){
  int i, num;
 int H[500000];
  scanf("%d", &num);
 
  for(i = 1;i <= num;i++) scanf("%d", &H[i]);
 
  for(i = num/2;i > 0;i--) maxHeap(H, i, num);
 
 
  for(i = 1;i <= num;i++) printf(" %d", H[i]);
 
  printf("\n");
  return 0;
}
void maxHeap(int *H, int i, int num){
  int l, r, large, c;
 
  if( i*2+1 < num + 1)
    { 
    r = i*2+1;
    }
  else r = i;
  if( i*2 < num + 1) 
    {
      l = i*2;
    }
  else l = i;
 
  if(l <= num && H[l] > H[i])
    {
      large = l;
    }
      else large = i;
    
  if(r <= num && H[r] > H[large])
    {
    large = r;
    }
  if(large != i)
    {
    c = H[i];
    H[i] = H[large];
    H[large] = c;
    maxHeap(H, large, num);
    }
}

Measured memory_bytes: 2552
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 2500000
ll MOD=1e9+7;



main(){
    int n=in();
    vector<int> a;
    int M1=0,M2=0;
    rep(i,n){
        int x=in();
        M2=max(M2,x);
        if(M2>M1)swap(M2,M1);
        a.pb(x);
    }
    rep(i,n){
        if(a[i]==M1)cout<<M2<<endl;
        else cout<<M1<<endl;
    }
}



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

int main() {
  string a;
  cin >> a;
  for(unsigned int i=0;i<a.size();i++){
    if(a.at(i)=='?'){
      a.at(i)='D';
    }
  }
  cout << a << endl;  
}

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

using namespace std;

int main()
{
  int n;
  cin >> n;
  while(n--){
    set<string> district;
    string train;
    cin >> train;
    for(int i = 0; i < train.size(); i++){
      string f = train.substr(0, i);
      string b = train.substr(i, train.size() - i);
      reverse(f.begin(), f.end());
      district.insert(f + b);
      district.insert(b + f);
      reverse(b.begin(), b.end());
      district.insert(f + b);
      district.insert(b + f);
      reverse(f.begin(), f.end());
      district.insert(f + b);
      district.insert(b + f);
      reverse(b.begin(), b.end());
      district.insert(f + b);
      district.insert(b + f);    
    }
    cout << district.size() << endl;
  }
  return 0;
}

Measured memory_bytes: 1292
import bisect
n = int(input())
l = sorted(list(map(int,input().split())))

ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        ans += bisect.bisect_left(l,l[i] + l[j]) - (j + 1)


print(ans)


Measured memory_bytes: 74516
// 計算の処理
function solve(n) {
  // jsのif分は(が必要)
  // pythonの逆順でindexof はinと同じ
  if ([3].indexOf(n % 10) >= 0) {
    return 'bon';
  }
  if ([0, 1, 6, 8].indexOf(n % 10) >= 0) {
    return 'pon';
  }
  return 'hon';
}
//  インプットの処理
function main(input) {
  // 入力値を整数値に治す
  let n = parseInt(input);
  // ここでようやく出力
  console.log(solve(n));
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

struct Pair{ 
	int yens;
	int no_drinks;;
	bool operator< (const Pair& other){
		return yens < other.yens;
	}
};

using namespace std;

int main(){
	int N, M;
	long long res = 0;
	vector<Pair> Stores;
	cin >> N >> M;
	for (int i = 0; i < N; ++i){
		int no_drinks;
		int yens;
		cin >> yens >> no_drinks;
		Stores.push_back({yens, no_drinks});
	}
	sort(Stores.begin(), Stores.end());
	int current_store = 0;
	while (M > 0 && current_store < N){
		if (M - Stores[current_store].no_drinks >= 0)
			res += 1LL * Stores[current_store].yens * Stores[current_store].no_drinks;
		else 
			res += 1LL * Stores[current_store].yens * M;
		M -= Stores[current_store].no_drinks;
		++current_store;
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
#define F 114514*1000
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,k,f,t,a,b;
int q[1000],x[1000],head,tail;
int g[100][100],r[100];
void BFS(int p,int y){
	rep(i,n)if(y+g[p][i]<r[i])q[tail]=i,x[tail]=y+g[p][i],r[i]=x[tail],tail++;
	return;
}
int main(){
	while(true){
	cin>>n>>k;
	if(!n&&!k)break;
	rep(i,n)rep(j,n)g[i][j]=F;
	rep(u,k){
		cin>>t>>a>>b;
		a--,b--;
		if(t){
			cin>>t;
			g[a][b]=min(t,g[a][b]),g[b][a]=g[a][b];
		}
		else{
			rep(i,n)r[i]=F;
			head=0,tail=1,q[0]=a,x[0]=0;
			while(true){
				if(head==tail)break;
				BFS(q[head],x[head]);
				head++;
			}
			if(r[b]==F)r[b]=-1;
			cout<<r[b]<<endl;
		}
	}
	}
	return 0;
}

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

void InvArray(int n, int fArray[]){
    for (int i = n; i > 0; i--)
    {
        cout << fArray[i];
        if (i>1) cout << " ";
    }
    cout << endl;
}

int main(){
    int a;
    int array[100]= {0};
    cin >> a;
    for (int i = 1; i <= a; i++)
    {
        cin >> array[i];
    }
    InvArray(a, array);
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000009
using namespace std;
int main(){
	int n;
	cin>>n;
	int cnt=0;
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		if(x!=i)cnt++;
	}
	if(cnt<=2)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 < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    ll n = s.size();
    vector<set<int>> st(26);
    rep(i,26) st[i].insert(100005);
    rep(i,n){
        st[(s[i]-'a')].insert(i);
    }
    ll ans = 0, cur = -1;
    rep(j,t.size()){
        auto idx = st[(t[j]-'a')].lower_bound(cur+1);
        if(*idx == 100005){
            auto idx2 = st[(t[j]-'a')].lower_bound(0);
            if(*idx2 == 100005){
                cout << -1 << endl;
                return 0;
            }
            ans += (n - cur) + *idx2;
            cur = *idx2;
        }
        else{
            ans += *idx - cur;
            cur = *idx;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8504
N,M=map(int,input().split())
table=[]
for i in range(M):
    p,y=map(int,input().split())
    table.append((p,y,i))
table.sort()
L=[[0]*2 for i in range(M)]
s=0
t=0
for p,y,i in table:
    if s!=p:
        s=p
        t=1
    else:
        t+=1
    L[i][0]=s
    L[i][1]=t
for i in range(M):
    print('%06d'%L[i][0]+'%06d'%L[i][1])

Measured memory_bytes: 76632
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define sqrt(d) pow((long double) (d), 0.50)

const ll INF = 2e9;
const ll large_P = 1e9 + 7;


int main(){
  int N, M;
  cin >> N >> M;
  
  vector<int> p(M);
  vector<string> S(M);
  rep(i, M) cin >> p.at(i) >> S.at(i);
  rep(i, M) p.at(i)--;
  
  int res = 0;
  vector<int> AC(N, 0), WA(N, 0);   
  
  rep(i, M){
    if(S.at(i) == "WA"){
      if(AC.at(p.at(i)) == 0) WA.at(p.at(i))++;
    }else{
      AC.at(p.at(i))++;
    }
  }
  
  int AC_number = 0;
  int WA_number = 0;
  
  rep(i, N){
    if(AC.at(i) > 0) AC_number++;
    if(AC.at(i) > 0) WA_number += WA.at(i);
  }
  
  
  
  
  cout << AC_number << " " << WA_number << endl;
}

Measured memory_bytes: 6912
#include <stdio.h>

int
main(void)
{
	char line[80];
	int a[4], b[4];

	while (true) {
		if (fgets(line, sizeof line, stdin) == NULL) {
			return 0;
		}
		if (sscanf(line, "%d %d %d %d", &(a[0]), &(a[1]), &(a[2]), &(a[3])) != 4) {
			return 0;
		}

		if (fgets(line, sizeof line, stdin) == NULL) {
			return 0;
		}
		if (sscanf(line, "%d %d %d %d", &(b[0]), &(b[1]), &(b[2]), &(b[3])) != 4) {
			return 0;
		}
		
		int h = 0;
		int w = 0;
		
		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 4; j++) {
				if (a[i] == b[j]) {
					if (i == j) {
						h++;
					} else {
						w++;
					}
				}
			}
		}
		printf("%d %d\n", h, w);
	}

	return 0;
}

Measured memory_bytes: 1036
#include "bits/stdc++.h"
using namespace std;
int main(){
    int N,K,i;
    cin >> N >> K;
    vector<int> x(N);
    for(i=0;i<N;i++) cin >> x.at(i);
    int ans = 300000000;
    int tmp;
    for(i=0;i<N-K+1;i++){
        tmp = abs(x.at(i))-x.at(i)+x.at(i+K-1);
        if(tmp < ans) ans = tmp;
        tmp = abs(x.at(i+K-1))+x.at(i+K-1)-x.at(i);
        if(tmp < ans) ans = tmp;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

/*****************MACRO*****/

#define ll long long
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

/*******CONSTANT***********/
#define INF (1<<30) //infinity value
#define EPS 1e-9
#define MOD 10000007
#define SIZ 1005
#define PI (acos(-1))

const int N=5e5+10;



char s[N];
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cout.tie(0);

    scanf("%s",s+1);
    ///cout<<"s="<<s<<"\n";
    //cout<<"n="<<n<<"\n";
    int n = strlen(s+1);
    ///cout<<"n="<<n<<"\n";
//    int L[n];
//    int R[n];
    vector<int> L(n+1);
    vector<int> R(n+1);

    for(int i=1, left=0; i<=n; i++){
        if(s[i]=='<') left++;
        else left= 0;
        L[i]= left;

    }
//    cout<<"Left:";
//    for(int i=1, left=0; i<=n; i++)
//        cout<<L[i]<<" ";
    for(int i=n-1, right = 0 ; i>=0; i--){
        if(s[i+1]=='>') right++;
        else right=0;
        R[i]= right;
    }
//    cout<<"\nRight:";
//    for(int i=0; i<=n-1; i++)
//        cout<<R[i]<<" ";
    ll ans= 0;
    for(int i=0; i<=n; i++)
    {
        ans+= max(L[i], R[i]);
    }
    cout<<ans<<"\n";


    return 0;
}



///>><<<>












/**********************************************************************************
Input:
<>>><<><<<<<>>><
Output:

n=16; so 17 ta number ; focus on indexing of left right

Left 1 to N idx:  1 0 0 0 1 2 0 1 2 3 4 5 0 0 0 1
Right 0 to  N-1:0 3 2 1 0 0 1 0 0 0 0 0 3 2 1 0
28


##
>><<><<<<<>>>

n=13
Left 1 to N idx:   0 0 1 2 0 1 2 3 4 5 0 0 0
Right 0 to N-1 : 2 1 0 0 1 0 0 0 0 0 3 2 1
24




*************************************************************************************/



Measured memory_bytes: 4608
a,b,c,d,e,f = map(int,input().split())
mizu = []
satou = []
tmp_ans = []
ans = -1
ans_i = 0
ans_j = 0
for i in range(31):
    for j in range(31):
        tmp = a * 100 * i + b * 100 * j
        if tmp <= f:
            mizu.append(tmp)
mizu = list(set(mizu))
for i in range(101):
    for j in range(101):
        tmp = c * i + d * j
        if tmp <= f:
            satou.append(tmp)
satou = list(set(satou))
for i in mizu:
    for j in satou:
        if i + j <= f:
            if i + j != 0 and i != 0 and i // 100 * e >= j:
                if ans < j /(i + j):
                    ans = j / (i + j)
                    ans_i = i
                    ans_j = j
print(ans_i + ans_j,ans_j)

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

const int MOD = 1e+9 + 7;


int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    for( int i = 0; i < H; ++i ) cin >> a[i];


    // dp[i][j]: (i, j) に到達できる道の数 
    long long dp[1001][1001] = {};
    bool block = false;
    for( int j = 0; j < W; ++j ){
        if( a[0][j] == '#' ) block = true;
        if( !block ) dp[0][j] = 1; 
        else         dp[0][j] = 0;
    }
    block = false;
    for( int i = 0; i < H; ++i ){
        if( a[i][0] == '#' ) block = true;
        if( !block ) dp[i][0] = 1;
        else         dp[i][0] = 0;
    }
    for( int i = 1; i < H; ++i ){
        for( int j = 1; j < W; ++j ){
            if( a[i][j] == '#' ) dp[i][j] = 0;
            else                 dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
        }
    }
    cout << dp[H-1][W-1] << endl;

    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
typedef long double ld;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
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; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int main(){
  string s;
  cin >> s;
  if(s=="zyxwvutsrqponmlkjihgfedcba"){
    cout << -1 << endl;
    return 0;
  }
  if(s.size()!=26){
    map<char,int> ma;
    rep(i,0,s.size()){
      ma[s[i]]++;
    }
    for(char c='a' ; c<='z' ; c++){
      if(ma[c]==0){
        s += c;
        break;
      }
    }
    cout << s << endl;
  }else{
    string t = s;
    next_permutation(all(t));
    string ans="";
    for(int i=0 ; i<t.size() ; i++){
      ans += t[i];
      if(s[i]<t[i]) break;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int ans;
char b;
int main()
{
	scanf("%c",&b);
	while ((b=='+') || (b=='-'))
	{
		if (b=='-') ans--;
		    else ans++;
		scanf("%c",&b);
	}
	printf("%d",ans);
	return 0;
}


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

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;

signed main(){
    llin(n);
    llin(q);
    vll a(n);
    vll aa(n);
    vll d(n);
    vll u(n);
    vpl4 x(q);
    cin >>a[0];
    aa[0]=a[0];
    FOR(i,1,n-1){
        cin >>a[i];
        aa[i]+=aa[i-1]+a[i];
    }
    FOR(i,0,q-1){
        cin >>x[i].fi;
        x[i].se=i;
    }
    ll e=0;
    FOR(i,0,n-1){
        e=n-((n-i)/2+((n-i)%2));
        d[i]=(a[i]+a[e])/2;
    }
    vll c(n,0);
    if(n%2==0){
    FOR(i,1,n-1){
        c[i]=((i%2==0)?c[i-1]:c[i-1]+a[i]);
    }
    }else{
        c[0]=a[0];
        FOR(i,1,n-1){
            c[i]=((i%2==0)?c[i-1]+a[i]:c[i-1]);
        }
    }
    SORT(x);
    ll j=2-(n%2);
    vll z(q,0);
    FOR(i,0,q-1){
        if(x[i].fi>d[1-(n%2)]){
        while(j<n-1 && x[i].fi>d[j+1]){
            j+=2;
        }
        if(j<n-1){
            z[x[i].se]=c[j-1]+(aa[n-1]-aa[n-(n-j)/2-1]);
        }else{
            z[x[i].se]=c[n-1];
        }
        }else{
            z[x[i].se]=aa[n-1]-aa[n/2-1];
        }
    }
    FOR(i,0,q-1){
        sal(z[i]);
    }
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A<C && C<B) {
    cout << "Yes" << endl;
  }
  else {
    if (B<C && C<A) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 3592
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
#include<numeric>
using namespace std;
typedef long long int lli;
#define rep(i,n) for(lli i = 0;i<((lli)(n));i++)
#define reg(i,a,b) for(lli i = ((lli)(a));i<=((lli)(b));i++)
#define irep(i,n) for(lli i = ((lli)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(lli i = ((lli)(b));i>=((lli)(a));i--)
typedef pair<lli, lli> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprllif(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	int n; cin >> n;
	vector<lli> a(n);
	rep(i, n) cin >> a[i];
	
	lli s = accumulate(a.begin(), a.end(), 0ll), ans = LINF, t = a[0];
	reg(i, 1, n-1){
		ans = min(ans, abs(s - t*2));
		t += a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int N;
	vector<double> X;
	vector<string> U;
	double x;
	double answer;
	string u;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> x >> u;
		X.push_back(x);
		U.push_back(u);
	}
	for (int t = 0; t < N; t++) {
		if (U[t] == "JPY") {
			answer += X[t];
		}
		else {
			answer += X[t] * 380000.0;
		}
	}

	cout << fixed<<answer;
	return 0;
}

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

//ライブラリ始まり

//定数

//円周率
const double PI = 3.1415926535897932384;

//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15

//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";

//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//関数

//ctoi
int ctoi(char c){
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  } 
  if (c == '2') {
    return 2;
  } 
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  } 
  if (c == '5') {
    return 5;
  } 
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  } 
  if (c == '8') {
    return 8;
  } 
  if (c == '9') {
    return 9;
  }
  return -1;  
}

//素数判定
bool PN(int x) {
  if (x <= 1) {
    return false;
  }
  if (x == 2) {
    return true;
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

//ライブラリ終わり

int main() {
  int N, M;
  cin >> N >> M;
  vector<ll> A(N + 1, 0);
  for (int i = 0; i < M; i++) {
    int B;
    cin >> B;
    A.at(B) = -1;
  }
  A.at(0) = 1;
  if (A.at(1) != -1) {
    A.at(1) = 1;
  }
  else {
    A.at(1) = 0;
  }
  for (int i = 2; i <= N; i++) {
    if (A.at(i) == -1) {
      A.at(i) = 0;
    }
    else {
      A.at(i) = A.at(i - 1) + A.at(i - 2);
      A.at(i) %= MOD;
    }
  }
  cout << A.at(N) << endl;
}

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

int main() {
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    vector<vector<int>> res(H, vector<int>(W, 0));

    for(int i=0; i<H-B; i++) for(int j=W-A; j<W; j++) res[i][j] = 1;
    for(int i=H-B; i<H; i++) for(int j=0; j<W-A; j++) res[i][j] = 1;

    rep(i, H) {
        rep(j, W) {
            cout << res[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  bool rev;
  string s;
  cin >> s;
  int q;
  cin >> q;
  while(q--){
      int a;
      cin >> a;
      if(a==1)rev = 1-rev;
      else if(a==2){
          int b;
          cin >> b;
          char t;
          cin >> t;
          if(rev){
              if(b==1)
               s.push_back(t);
               else
               s.insert(s.begin(),t);
          }
         else{
             if(b==1)s.insert(s.begin(),t);
             else s.push_back(t);
         }
           
      }
  }
  if(rev)reverse(s.begin(),s.end());
  cout << s;
    
}

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

long long x;

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

    cin>>x;
    x*=2;
    long long t=sqrt(x);
    if(t*t+t>=x)
        cout<<t<<endl;
    else
        cout<<t+1<<endl;

    return 0;
}


Measured memory_bytes: 3700
#include<stdio.h>
int main()
{
	int x;
	int a[35]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	scanf("%d",&x);
	printf("%d",a[x-1]);
}

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

using namespace std;

#define fo(i,CApiTaL_N) for(int i=0; i<CApiTaL_N; i++)
#define Fo(i,k,CApiTaL_N) for(int i=k; i<CApiTaL_N; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it=a.begin(); it!=a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

int t=1;
const int mxN=1e5, mxH=1e4;
int n,k;
vi h(mxN+1), dp(mxN+1, INT_MAX);

void test_case(){
    cin>>n>>k;
    fo(i,n)cin>>h[i+1];
    dp[1]=0,dp[2]=abs(h[2]-h[1]);
    Fo(i,3,n+1){
        Fo(j,1,k+1){
            if(i-j<1)continue;
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout<<dp[n]<<endl;
}

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

    // cin>>t;
    while(t--){
        test_case();
    }
    
    return 0;
}

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

int main(){
  int a,b,c,d,e,k[14],max,max2,str,straight;
  char s;
  while(cin>>a>>s>>b>>s>>c>>s>>d>>s>>e){
    for(int i=1;i<=13;i++)k[i]=0;
    k[a]++;
    k[b]++;
    k[c]++;
    k[d]++;
    k[e]++;
    max=0;
    max2=0;
    str=0;
    straight=0;
    for(int i=1;i<=13;i++){
      if(max<=k[i]){//??°???
	max2=max;
	max=k[i];
      }else if(max2<=k[i])max2=k[i];

      if(k[i]==1){
	str++;
	if(str==5)straight=1;
      }else str=0;
      
    }
    
    if(max==4&&max2==1)cout<<"four card"<<endl;
    else if(max==3&&max2==2)cout<<"full house"<<endl;
    else if(straight==1)cout<<"straight"<<endl;
    else if(k[10]==1&&k[11]==1&&k[12]==1&&k[13]==1&&k[1]==1)cout<<"straight"<<endl;
    else if(max==3&&max2==1)cout<<"three card"<<endl;
    else if(max==2&&max2==2)cout<<"two pair"<<endl;
    else if(max==2&&max2==1)cout<<"one pair"<<endl;
    else cout<<"null"<<endl;
    
							

  }
  return 0;
}

Measured memory_bytes: 2984
#include<stdio.h>
#include<stdlib.h>

int main()
{
 char a;
 char b;
 scanf("%c %c",&a, &b);
 if((a=='H')&(b=='H')) printf("H\n");
 if((a=='H')&(b=='D')) printf("D\n");
 if((a=='D')&(b=='H')) printf("D\n");
 if((a=='D')&(b=='D')) printf("H\n");
 return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int N,M;
char m[55][55];
int main(){
    scanf("%d%d",&N,&M);
    for(int i=0;i<N;i++){
        scanf("%s",m[i+1]+1);
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=M;j++){
        int cnt=0;
            if(m[i][j]=='#')putchar('#');
            else {
                if(m[i+1][j]=='#')cnt++;
                if(m[i-1][j]=='#')cnt++;
                if(m[i][j+1]=='#')cnt++;
                if(m[i][j-1]=='#')cnt++;
                if(m[i+1][j+1]=='#')cnt++;
                if(m[i+1][j-1]=='#')cnt++;
                if(m[i-1][j+1]=='#')cnt++;
                if(m[i-1][j-1]=='#')cnt++;
                printf("%d",cnt);
            }
        }
            putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 256
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    a = [0] * n
    for i, hi in enumerate(h[1:], 1):
        s = max(0, i - k)
        a[i] = min([aj + abs(hi - hj) for hj, aj in zip(h[s:i], a[s:i])])
    print(a[-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 13980
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

ll		calc(string ex)
{
	ll ret = 0;
	int l = 0;
	for (int i = 0; i < (int)ex.size(); i++)
	{
		while (i < (int)ex.size() && ex[i] != '+')
			i++;
		ret += stoll(ex.substr(l, i-l));
		l = i+1;
	}
	return ret;
}

int		main(void)
{
	string S;
	cin >> S;
	int size = (int)S.size();
	size--;

	ll sum = 0;
	for (int i = 0; i < (1 << size); i++)
	{
		bitset<9> bs(i);
		string ex;
		for (int j = 0; j < size+1; j++)
		{
			ex += S[j];
			if (bs[j])
				ex += '+';
		}
		sum += calc(ex);
	}
	cout << sum << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef int64_t intl;


intl modpow(intl a, intl n, intl p){
  intl res = 1;
  while (n > 0){
    if (n&1){res = (res * a) % p;}
	a = (a * a) % p;
    n >>= 1;
  }
  return res;
}

intl modinv(intl a, intl p){
  if (a==0){
    cout << "/0 at modinv"<<endl;
    exit(0);
  }
  if (a < 0){
    cout << "/- at modinv" <<endl;
    exit(0);
  }
  if (a==1){return 1;}
  if (a > p){return modinv(a%p, p);}

  return p - ( modinv(p%a,p) * (p/a) ) % p;
}

intl modcomb(intl n, intl k, intl p){
  if (k > n || k < 0 || n < 0){
    cout << "error at modcomb"<<endl;
    exit(0);
  }
  if (2*k > n){ k = n-k;}
  if (k ==0){return 1;}
  intl c=1;
  for (intl i = 0; i < k; i++){
    c =( c * ( (n-i) % p ) % p ) * modinv(i+1,p) % p;
  }
  return c;
}

int main(){
  intl n,a,b;
  intl mod = 1000000007;
  cin >> n >> a >> b;
  if (n==2){
    cout << 0;
    return 0;
  }
  
  intl ans;
  ans = modpow(2, n, mod);
  ans -= modcomb(n, a, mod);
  ans -= modcomb(n, b, mod);
  ans -= 1;
  while (ans < 0){
    ans += mod;
  }
  cout << ans;
}

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

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

int main() {
  int n;
  long long ans=0;
  long long tmp;

  cin >> n;

  for(int i=1;i<=n;i++) {
    for(int j=1;j<=n;j++) {
      tmp=gcd(i,j);
      for(int k=1;k<=n;k++) {
        ans+=gcd(tmp,k);
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<cmath>
using namespace std;
double pi=3.1415926;
struct Point{
	double x;
	double y;
};

void draw(Point p1,Point p2,int n){
	if(n==0)return;
	Point s,u,t;
	s.x=(2*p1.x+p2.x)/3;
	s.y=(2*p1.y+p2.y)/3;
	draw(p1,s,n-1);
	printf("%.8f %.8f\n",s.x,s.y);
	t.x=(p1.x+2*p2.x)/3;
	t.y=(p1.y+2*p2.y)/3;
	u.x=(t.x-s.x)*cos(pi/3)-(t.y-s.y)*sin(pi/3)+s.x;
	u.y=(t.x-s.x)*sin(pi/3)+(t.y-s.y)*cos(pi/3)+s.y;
	
	draw(s,u,n-1);
	printf("%.8f %.8f\n",u.x,u.y);
	
	draw(u,t,n-1);
	printf("%.8f %.8f\n",t.x,t.y);
	
	draw(t,p2,n-1);
}

int main(){
	int n;
	cin>>n;;
	Point a,b;
	a.x=a.y=0.0f;
	b.x=100.0f;
	b.y=0.0f;
	printf("%.8f %.8f\n",a.x,b.y);
	draw(a,b,n);
	printf("%.8f %.8f\n",b.x,b.y);
	return 0;
}


Measured memory_bytes: 3248
#include<iostream>
#include<algorithm>

int main(){
    int N;
    std::cin >> N;
    
    int ans = N;
    for (int i=0;i<=N;i++) {
        int cnt = 0;
        int A = i;

        while (A>0) {
            cnt += A%6;
            A /= 6;
        }
        A = N-i;
        while (A>0) {
            cnt += A%9;
            A /= 9;
        }
        ans = std::min(ans,cnt);
    }

    std::cout << ans << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
#define int long long
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

struct edge{
    int to,cost;
};
struct Unionfind{
    vector<int> data;
    Unionfind(int size):data(size, -1) {}
    bool unite(int x, int y){
        x=root(x);
        y=root(y);
        if(x!=y){
            if(data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x!=y;
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    int root(int x){
        return (data[x] < 0) ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    vector<pair<P,int>> v;
    vector<pair<P,int>> w;
    rep(i,n){
        int x,y; cin >> x >> y;
        v.pb({{x,y},i});
        w.pb({{y,x},i});
    }
    sort(ALL(v));
    sort(ALL(w));
    vector<pair<int,P>> G;
    rep(i,n-1){
        G.pb({v[i+1].fi.fi-v[i].fi.fi,{v[i+1].se,v[i].se}});
        G.pb({w[i+1].fi.fi-w[i].fi.fi,{w[i+1].se,w[i].se}});
    }
    sort(ALL(G));
    Unionfind uni(n);
    ll ans=0;
    for(auto u:G){
        if(!uni.same(u.se.fi,u.se.se)){
            uni.unite(u.se.fi,u.se.se);
            ans+=u.fi;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 13860
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 8192
#define MOD 1'000'000'007LL
class UF{
public:
	int p[N], d[N] = {};
	UF() {
		iota(p, p+N, 0);
	}
	
	int group(int a){
		if(a == p[a]) return a;
		else return p[a] = group(p[a]);
	}

	void merge(int a, int b) {
		a = group(a);
		b = group(b);
		if(a == b) return;
		if(d[a] < d[b]) swap(a, b);
		p[b] = a;
		LAR(d[a], d[b]+1);
	}
} uf;
bool t[N] = {};
bool u[N] = {};
ll a[N];
ll s[N][N] = {};
ll np[N] = {1};

int main(){
	ll n; scanf("%lld", &n);
	FOR(i, 1, n+1){
		int p; scanf("%d", &p);
		if(p == -1) t[i] = true;
		else uf.merge(i, p);
	}
	ll kk = 0, b = 0;
	FOR(i, 1, n+1){
		if(u[i]) continue;
		int y = 0;
		bool z = true;
		FOR(j, 1, n+1) if(uf.group(i) == uf.group(j)) {
			y++;
			if(t[j]) z = false;
			u[j] = true;
		}
		DEBUG("%d => (%d, %c)\n", i, y, z ? 'o' : 'x');
		if(z) b++;
		else a[++kk] = y;
	}
	DEBUG("kk = %lld, b = %lld\n", kk, b);
	FOR(i, 1, kk+1) s[1][i] = s[1][i-1] + a[i] % MOD;
	FOR(k, 2, kk+1){
		FOR(i, k, kk+1){
			s[k][i] = (s[k][i-1] + s[k-1][i-1] * a[i]) % MOD;
			DEBUG("%lld ", s[k][i]);
		}
		DEBUG("\n");
	}
	FOR(i, 1, N) np[i] = (np[i-1] * (n-1)) % MOD;

	ll ans = np[kk] * (n-b) % MOD;
	DEBUG("ans = %lld\n", ans);
	FOR(i, 1, kk+1){
		ans = (ans + MOD - (a[i] - 1) * np[kk-1] % MOD) % MOD;
		DEBUG(" - %lld * %lld\n", a[i]-1, np[kk-1]);
	}
	ll fct = 1;
	FOR(m, 2, kk+1){
		fct = fct * (m-1) % MOD;
		ans = (ans + MOD - fct * s[m][kk] % MOD * np[kk-m] % MOD) % MOD;
		DEBUG(" - %lld * %lld * %lld\n", fct, s[m][kk], np[kk-m]);
	}
	printf("%lld\n", ans);
}






Measured memory_bytes: 115840
<?php
// Your code here!
fscanf(STDIN, "%d", $n);
$list = explode(" ", trim(fgets(STDIN)));

asort($list);

$res = '';
foreach($list as $key => $val){
    $res .= ((int)$key + 1).' ';
}
echo trim($res).PHP_EOL;

Measured memory_bytes: 16884
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long int N;
  cin >>N;
  vector<int>A(N);
  vector<int>B(N);
  vector<int>C(N);
  
  for(int i =0;i<N;i++){
  cin >>A[i];
  }
  for(int i =0;i<N;i++){
  cin >>B[i];
  }
  for(int i =0;i<N;i++){
  cin >>C[i];
  }
  
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());
  
  long int p,q,nextB,ans=0;
  for(int i=0;i<N;i++){
    
   p= lower_bound(A.begin(),A.end(),B[i])-A.begin();
   q=C.end()-upper_bound(C.begin(),C.end(),B[i]);
  
   ans+=p*q; 
  }
  cout<<ans;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
ll a[400];
ll dp[400][400];

ll d[401];
void solve(){
	rep(i, N){
		d[i + 1] = d[i] + a[i];
	}
	rep(i, N){
		rep(j, N){
			if(i != j)
				dp[i][j] = LINF;
		}
	}
	reps(w, N - 1){
		for(int i = 0; i + w < N; i++){
			for(int j = i; j < i + w; j++){
				chmin(dp[i][i + w], dp[i][j] + dp[j + 1][i + w] + d[i + w + 1] - d[i]);
			}
		}
	}
	//da2(dp, N, N);
	cout << dp[0][N - 1] << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	rep(i, N) {
		cin >> a[i];
	}
		solve();
	return 0;
}


Measured memory_bytes: 1664