akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main() {

    int A;
    scanf("%d", &A);

    int B;
    scanf("%d", &B);

    int max = 0;

    if (A > B) {
        max += A;
        A--;
    } else {
        max += B;
        B--;
    }

    if (A > B) {
        max += A;
        A--;
    } else {
        max += B;
        B--;
    }

    printf("%d\n", max);

    return 0;
}


Measured memory_bytes: 128
num500 = gets.chomp.to_i
num100 = gets.chomp.to_i
num50 = gets.chomp.to_i
x = gets.chomp.to_i

def coins(x,num500,num100,num50)
  if num500 == 0 or x < 500 then
    if num100 == 0 or x < 100 then
      if x % 50 != 0 or x / 50 > num50 then
        return 0
      else
        return 1
      end
    else
      return coins(x-100,0,num100-1,num50) + coins(x,0,0,num50)
    end
  else
     return coins(x-500,num500-1,num100,num50) + coins(x,0,num100,num50)
  end
end

puts coins(x,num500,num100,num50)


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

int main(){
    int n,a[100];
    std::cin >> n;
    int l,r,total= 0;
    rep(i,n){
        std::cin >> a[i];
        total += a[i];
    }
    rep(i,n){
        total -= a[i] * 2;
        if(total <= 0){
            std::cout << min(abs(total),abs(total + a[i]*2)) << endl;
            break;
        }
    }
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1

int main() {
  int H,A;
  cin >> H >> A;
  int ans=0;
  while(H>0)
  {
    H-=A;
    ans++;
  }
cout << ans << endl;
}


Measured memory_bytes: 256
l,r = map(int,input().split())
if r-l >= 2019:
    print(0)
else:
    r1 = r % 2019
    l1 = l % 2019
    if l1 > r1:
        print(0)
    else:
        ans = 2019
        for i in range(l1, r1):
            for j in range(i + 1, r1 + 1):
                ans = min(ans, (i*j) % 2019)
        print(ans)

Measured memory_bytes: 65384
#include <stdio.h>
#include <string.h>
#include <unordered_set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

#define F(x, y, d) while (f[x+dx[d]][y+dy[d]] != '#') x+=dx[d], y+=dy[d]
inline int h(int x, int y, int d) { return (x<<8) | (y<<2) | d; }
inline int h(int x1, int y1, int d1, int x2, int y2, int d2) {
    return (h(x1, y1, d1) << 16) | h(x2, y2, d2);
}

int H, W;
char f[16][64], h1[16][64][4];
int sx, sy, sd, tx, ty, td;
std::unordered_set<int> h2;

bool reach(int x, int y, int d) {
    F(x, y, d);
    if (x == tx && y == ty) return true;
    if (h1[x][y][d]) return false;
    h1[x][y][d] = 1;
    if (reach(x, y, (d+1)%4)) return true;
    if (reach(x, y, (d+3)%4)) return true;
    return false;
}

bool acc(int cx, int cy, int cd, int x, int y, int d) {
    if (f[x+dx[d]][y+dy[d]] != '#') return false;
    F(cx, cy, cd);
    const bool p = cx == tx && cy == ty && d == td;
    while (f[x][y] != '#') {
        if (!h2.insert(h(cx, cy, cd, x, y, d)).second) break;
        if (p && x == tx && y == ty) return true;
        if (acc(cx, cy, (cd+1)%4, x, y, (d+1)%4)) return true;
        if (acc(cx, cy, (cd+3)%4, x, y, (d+3)%4)) return true;
        x -= dx[d], y -= dy[d];
    }
    return false;
}

void solve() {
    memset(h1, 0, sizeof(h1));
    rep (i, H) rep (j, W) if (f[i][j] == 'K') {
        f[i][j] = '.';
        rep (d, 4) if (f[i+dx[d]][j+dy[d]] != '#') sx = i, sy = j, sd = d;
    }
    rep (i, H) rep (j, W) if (f[i][j] == 'M') {
        f[i][j] = '.';
        rep (d, 4) if (f[i+dx[d]][j+dy[d]] != '#') tx = i, ty = j, td = d;
    }
    if (!reach(sx, sy, sd)) puts("He cannot bring tea to his master.");
    else {
        h2.clear();
        rep (d, 4) if (acc(sx, sy, sd, sx, sy, d)) {
            puts("He can accomplish his mission.");
            return ;
        }
        puts("He cannot return to the kitchen.");
    }
}

int main() {
    for (;;) {
        scanf("%d%d", &W, &H);
        if (H == 0) return 0;
        rep (i, H) rep (j, W) scanf(" %c", f[i]+j);
        solve();
    }
}

Measured memory_bytes: 6036
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int mod=998244353;
const int MAXN=500005;
int pow_mod(int a,int b)
{
	int ret=1;
	for(;b;b>>=1,a=1LL*a*a%mod)if(b&1)ret=1LL*ret*a%mod;
	return ret;
}
int pre[MAXN],inv[MAXN];
int C(int n,int m)
{
	if(n<m)return 0;
	return 1LL*pre[n]*inv[m]%mod*inv[n-m]%mod;
}
int n,K;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
int main()
{
	pre[0]=1;for(int i=1;i<MAXN;i++)pre[i]=1LL*pre[i-1]*i%mod;
	inv[MAXN-1]=pow_mod(pre[MAXN-1],mod-2);
	for(int i=MAXN-2;i>=0;i--)inv[i]=1LL*inv[i+1]*(i+1)%mod;
	n=read();K=read();int ans=0;
	for(int r=K;r>=0&&r>=K-r&&r>=n;r--)
	{
		int b=K-r,t=r-(n-1);
		if(t>b)ad(ans,C(K,r));
		else if(r>b)ad(ans,(C(K,r)-C(K,r+t)+mod)%mod);
		else if(r==b)ad(ans,(C(K-1,r)-C(K-1,r+t)+mod)%mod);
	}pr2(ans);
	return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

/* 必ず要素数をコンストラクタに入れること */
class Union_Find {
public:
  vector<long long> par;
  vector<long long> rnk;

  Union_Find (long long n) {
    par.resize(n), rnk.resize(n);
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      rnk[i] = 0;
    }
  }

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

  // xとyの属する集合を併合
  void merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (rnk[x] < rnk[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rnk[x] == rnk[y]) rnk[x]++;
    }
  }

  // xとyが同じ集合に属するか否か
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

int main() {
  int n,k,l;
  cin >> n >> k >> l;
  Union_Find uf_road(n+1), uf_train(n+1);

  int r,s;
  rep(i,k) {
    cin >> r >> s;
    uf_road.merge(r, s);
  }

  rep(i,l) {
    cin >> r >> s;
    uf_train.merge(r, s);
  }

  /*for (int i = 1; i <= n; ++i) {
    cout << uf_train.find(i) << " ";
  }
  END;*/

  vector<pair<int,int> > com;
  map<pair<int,int>, int> mp;

  for (int i = 1; i <= n; ++i) {
    int a, b;
    a = uf_road.find(i);
    b = uf_train.find(i);
    com.push_back(make_pair(a,b));
    mp[make_pair(a,b)] += 1;
  }

  for (int i = 0; i < n; ++i) {
    cout << mp[com[i]] << " ";
  }

  END;
}


Measured memory_bytes: 19568
#include <stdio.h>
#define N 101

int n,hi[N][N];
int distance[N];

void width(int st);

int main(){
  int i,j,k,s,t;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      hi[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&s,&k);
    distance[s]=-1;      /*距離がないとき*/

    for(j=0;j<k;j++){
      scanf("%d",&t);
    
      hi[s][t]=1;
    }
  }

  distance[1]=0;     /*スタートからの距離が0*/
  width(1);

  for(i=1;i<=n;i++){
    printf("%d %d\n",i,distance[i]);
  }
  
  return 0;
}
      
void width(int st){
  int i;
  int max[N];
  int s=0,g=0;

  max[g]=st;
  ++g;

  while(1){
    if(s==g) break;

    st=max[s];
    ++s;

    for(i=1;i<=n;i++){
      if(hi[st][i]==1){
	if(distance[i]>=0)
	  continue;
	max[g]=i;
	++g;

	distance[i]=distance[st]+1;
      }
    }
  }
}

  



Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array);

const ll N=1000005;

const ll MOD=1000000007;
ll fact[N], invfact[N];

ll Power(ll base , ll e)
{
    if(e == 0) return 1;
    ll ans = base; e--;
    while(e)
	{
        if(e & 1) ans = (ans * base) %MOD;
        base = (base * base) %MOD;
        e >>= 1;
	}
	return ans %MOD;
}


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

    ll modinv(ll k)
    {
        return Power(k, MOD-2);
    }

    void precompute()
    {
        fact[0]=fact[1]=1;
        for(ll i=2;i<N;i++)
        {
            fact[i]=fact[i-1]*i;
            fact[i]%=MOD;
        }
        invfact[N-1]=modinv(fact[N-1]);
        for(ll i=N-2;i>=0;i--)
        {
            invfact[i]=invfact[i+1]*(i+1);
            invfact[i]%=MOD;
        }
    }

    ll nCr(ll x, ll y)
    {
        if(y>x)
            return 0;
        ll num=fact[x];
        num*=invfact[y];
        num%=MOD;
        num*=invfact[x-y];
        num%=MOD;
        return num;
    }



int main(){
	ll n;
	cin>>n;
	ll a[n];
	ll count[200005];
	fo(i,200005){
		count[i]=0;
		

	}
	fo(i,n){
		cin>>a[i];
		count[a[i]]++;

	}
	ll suum=0;
	fo(i,200005){
		suum+=(count[i]*(count[i]-1)/2);
	}
	//dbg(suum);
	ll tmp;
	ll tmp2;
	ll k;
	fo(i,n){
		tmp=a[i];
		tmp2=suum;
		k=count[tmp]-1;
		tmp2=tmp2-(count[tmp]*(count[tmp]-1)/2);
		tmp2=tmp2+(k*(k-1)/2);
		cout<<tmp2<<endl;


	}

}

Measured memory_bytes: 5760
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

//nCr mod m
#define MOD 1000000007
#define M 1000000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 0;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m;
	cin>>n>>m;
	vi in(n);
	rep(i,n)cin>>in[i];
	sort(all(in));
	int out=0;
	rep(i,n){
		(out+=MOD-nCr(n-i-1,m-1)*in[i]%MOD)%=MOD;
		(out+=nCr(i,m-1)*in[i]%MOD)%=MOD;
	}
	cout<<out<<endl;
}









Measured memory_bytes: 8832
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
const ll MAX=1010000;
//-----------------------------------------
int main(void){
    int b[MAX];
    REP(i,MAX)b[i]=0;
    ll N;cin>>N;
    REP(i,N){
        ll a;cin>>a;
        b[a]++;
    }

    FOR(i,1,MAX){
        if(b[i]){
            for(ll j=2;i*j<MAX;j++){
                b[i*j]=false;
            }
        }
    }
    ll cnt=0;
    REP(i,MAX)if(b[i]==1)cnt++;
    cout<<cnt<<"\n";
}

Measured memory_bytes: 7592
program sample
    implicit none
  
    integer(8) :: i,j,m,n,k,a
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) k
    if(mod(k,2)==0)then
        write(*,*)-1
        stop
    end if
    a=7
    m=0
    do i=1,k+1
        if(mod(a,k)==0)then
            write(*,*)i
            stop
        else
            a=mod(a,k)
            a=a*10+7
        end if
    end do
    write(*,*) -1
  
    stop
end program sample
  



Measured memory_bytes: 2792
N,M=map(int,input().split())
a=[0 for k in range(M)]
b=[0 for k in range(M)]
for k in range(M):
    a[k],b[k]=map(int, input().split())
def dfs(route,new):
    route=route+new
    if len(route)==N+1:
        return 1
    count=0
    for k in range(M):
        if a[k]==route[-1] and b[k] not in route:
            count+= dfs(route,[b[k]])
    for k in range(M):
        if b[k]==route[-1] and a[k] not in route:
            count+= dfs(route,[a[k]])
    return count

print(dfs([0],[1]))
            



Measured memory_bytes: 3188
#include<iostream>
#include<cstring>
#include<queue>
#include<map>
#include<cmath>
#include<set>
#include<stack>
#include<cstdio>
#include<sstream>
#include<vector>
#include<bitset>
#include<algorithm>

using namespace std;
#define read(x) scanf("%d",&x)
#define Read(x,y) scanf("%d%d",&x,&y)
#define gc(x)  scanf(" %c",&x);
#define mmt(x,y)  memset(x,y,sizeof x)
#define write(x) printf("%d\n",x)
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define ll long long
const ll mod =   1000000007;
const int N = 100000 + 100;
const int M = 2e6 + 1005;
int a[N];
ll c[3];
int main()
{
    int n;
    cin>>n;
    for(int i = 1;i <= n;++i){
        cin>>a[i];
    }
    ll sum = 1;
    for(int i = 1;i <= n;++i){
        ll cnt = 0;
        int id ;
        if(a[i] == c[0]) {cnt ++;id = 0;}
        if(a[i] == c[1] ) {cnt++;id = 1;}
        if(a[i] == c[2]) {cnt ++;id = 2;}
        sum *= cnt;
        sum %= mod;
        c[id] ++;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 640
from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)
for a in A:
    d[a] += 1
#print(d)

total = 0
for a in d:
    total += d[a] * (d[a] - 1) // 2
#print(total)

for i in range(N):
    a = A[i]
    print(total - (d[a] - 1))


Measured memory_bytes: 88140
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;

int main() {
  INCANT;
  cin >> N;
  int a;
  int cnt=0;
  rep(i, N) {
    cin >> a;
    if (i%2==0 && a%2==1) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3660
use std::io::*;

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

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

fn main() {
    let v = read_vec::<usize>();
    let mut ans = 0;
    for i in 1..v[0]+1 {
        let mut sum = 0;
        let mut n = i;
        while n > 0 {
            sum += n % 10;
            n /= 10;
        }
        if v[1] <= sum && sum <= v[2] {
            ans += i;
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;


int main() {

    int N;
    cin >> N;
    string S;
    cin >> S;

    if (N % 2 == 1) {
        cout << "No" << endl;
    } else {

        if (S.substr(0, N / 2) == S.substr(N / 2)) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;

}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;

    set<string> se;
    string s;
    rep (i, n)
    {
        cin >> s;
        se.insert(s);
    }

    cout << se.size() << "\n";
    return 0;
}



Measured memory_bytes: 19244
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N,K;
  cin>>N>>K;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  int answer=a[K-1]-a[0];
  for(int i=0;i<N-K+1;i++){
    if(answer>a[i+K-1]-a[i]){
      answer=a[i+K-1]-a[i];
    }
  }
  cout<<answer<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  ll a , b , c ;
  cin >> a >> b >> c ;
  if( a == 0 ) cout << b/c + 1 << endl;
  else cout << b/c - (a-1)/c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD 1000000007
#define ll long long int
#define pi pair <ll,ll>
#define vi vector <ll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>       //greater_equal<ll> or less<ll>
// find_by_key()   order_of_key()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
/*bool comp(string a, string b) {
if (a.size() != b.size()) return a.size() < b.size();
return a < b;
}*/


 
int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    /*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll i,j,m,t,l=0,x,prev=0,max1=0,flag=0,cnt=0,y,min1,q,sum=0,r,n,k,p,flag2=0,ind=0,b;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    ll dp[n]={0};  //logic starts from here
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(i=2;i<n;i++){
        dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
    }
    cout<<dp[n-1];
    
 
    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOJ_ITP_1_2_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            //大小関係に応じた出力をする
            if(a < b)
                Console.WriteLine("a < b");
            else if(a > b)
                Console.WriteLine("a > b");
            else
                Console.WriteLine("a == b");
        }
    }
}



Measured memory_bytes: 15960
#B問題
N,x = map(int,input().split())

if x == 1 or x == 2*N-1:
    print("No")
elif N == 2:
    print("Yes")
    print(1)
    print(2)
    print(3)
else:
    print("Yes")
    if x == 2:
        Key = [x+1,x,x-1,x+2]
    else:
        Key = [x-1,x,x+1,x-2]
    Unit = []
    for i in range(2*N-1):
        if (i+1) not in Key:
            Unit.append(i+1)
                
    for i in range(N-2):
        u = Unit.pop()
        print(u)
    for k in Key:
        print(k)
    for i in range(N-3):
        u = Unit.pop()
        print(u)

Measured memory_bytes: 11160
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
string ffind="aeiou";

int main(){
    int n;
L:while(cin>>n,n){
        vector<string>v(101);
        rep(i,n)cin>>v[i];
        int maxi=0;
        rep(i,n){
            string temp;
            maxi=max((int)v[i].length(),maxi);
            rep(j,v[i].length()){
                if(!j)temp.push_back(v[i][j]);
                if(j!=v[i].length()){
                    rep(k,5){
                        if(v[i][j]==ffind[k])
                            temp.push_back(v[i][j+1]);
                    }
                }
            }
            v[i]=temp;
        }
    for(int k=1;k<=maxi;k++){
            bool flag=true;
            rep(i,n){
                string pulum;
                if(v[i].length()>k)
                    pulum=v[i].substr(0,k);
                else
                    pulum=v[i];
                rep(j,n){
                    if(j==i)continue;
                    string com;
                    if(v[j].length()>k)
                        com=v[j].substr(0,k);
                    else
                        com=v[j];
                    if(com==pulum){flag=false; break;}
                }
            }
            if(flag){cout<<k<<endl; goto L;}
        }
    cout<<-1<<endl;
    }
}

Measured memory_bytes: 3076
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/aryan/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    vector<string> a={"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

    cin>>s;
    lli ans=7;
    for(auto x:a)
    {
        if(x==s)
            break;
        ans--;
    }
    cout<<ans<<endl;
}   aryanc403();
    return 0;
}

Measured memory_bytes: 256
// eddy1021
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
#define mod9 1000000009LL
#define mod7 1000000007LL
#define INF  1023456789LL
#define INF16 10000000000000000LL
#define eps 1e-9
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#define debug(...) printf(__VA_ARGS__)
#else 
#define debug(...)
#endif
inline LL getint(){
  LL _x=0,_tmp=1; char _tc=getchar();    
  while( (_tc<'0'||_tc>'9')&&_tc!='-' ) _tc=getchar();
  if( _tc == '-' ) _tc=getchar() , _tmp = -1;
  while(_tc>='0'&&_tc<='9') _x*=10,_x+=(_tc-'0'),_tc=getchar();
  return _x*_tmp;
}
inline LL add( LL _x , LL _y , LL _mod = mod7 ){
  _x += _y;
  return _x >= _mod ? _x - _mod : _x;
}
inline LL sub( LL _x , LL _y , LL _mod = mod7 ){
  _x -= _y;
  return _x < 0 ? _x + _mod : _x;
}
inline LL mul( LL _x , LL _y , LL _mod = mod7 ){
  _x *= _y;
  return _x >= _mod ? _x % _mod : _x;
}
LL mypow( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 1LL;
  LL _ret = mypow( mul( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = mul( _ret , _a , _mod );
  return _ret;
}
LL mymul( LL _a , LL _x , LL _mod ){
  if( _x == 0 ) return 0LL;
  LL _ret = mymul( add( _a , _a , _mod ) , _x >> 1 , _mod );
  if( _x & 1 ) _ret = add( _ret , _a , _mod );
  return _ret;
}
inline bool equal( D _x ,  D _y ){
  return _x > _y - eps && _x < _y + eps;
}
#define Bye exit(0)
int __ = 1 , _cs;
/*********default*********/
#define N 121
void build(){

}
int dp[ N ][ 9 ] , n;
char c[ 2 ][ N ];
void init(){
  n = getint();
  scanf( "%s" , c[ 0 ] );
  scanf( "%s" , c[ 1 ] );
}
bool okay( int c1 , int c2 , char d1 , char d2 ){
  if( c1 == c2 and d1 != d2 ) return false;
  if( c1 != c2 and d1 == d2 ) return false;
  return true;
}
void solve(){
  for( int i = 0 ; i < 3 ; i ++ )
    for( int j = 0 ; j < 3 ; j ++ ){
      if( i == j and c[ 0 ][ 0 ] != c[ 1 ][ 0 ] )
        continue;
      if( i != j and c[ 0 ][ 0 ] == c[ 1 ][ 0 ] )
        continue;
      dp[ 0 ][ i * 3 + j ] ++;
    }
  for( int i = 0 ; i + 1 < n ; i ++ )
    for( int msk = 0 ; msk < 9 ; msk ++ ){
      if( dp[ i ][ msk ] == 0 ) continue;
      int pu = msk / 3;
      int pd = msk % 3;
      for( int u = 0 ; u < 3 ; u ++ )
        for( int d = 0 ; d < 3 ; d ++ ){
          int nmsk = u * 3 + d;
          if( not okay( u , d , c[ 0 ][ i + 1 ] , c[ 1 ][ i + 1 ] ) )
            continue;
          if( not okay( pu , u , c[ 0 ][ i ] , c[ 0 ][ i + 1 ] ) )
            continue;
          if( not okay( pd , d , c[ 1 ][ i ] , c[ 1 ][ i + 1 ] ) )
            continue;
          dp[ i + 1 ][ nmsk ] = add( dp[ i + 1 ][ nmsk ] , dp[ i ][ msk ] );
        }
    }
  int ans = 0;
  for( int i = 0 ; i < 9 ; i ++ )
    ans = add( ans , dp[ n - 1 ][ i ] );
  cout << ans << endl;
}
int main(){
  build();
  //__ = getint();
  while( __ -- ){
    init();
    solve();
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
class UnionFind
{
public:
    vector<int> Parent;
    UnionFind(int N)
    {
        Parent = vector<int>(N, -1);
    }
    int root(int A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = root(Parent[A]);
    }

    int size(int A)
    {
        return -Parent[root(A)];
    }
    bool connect(int A, int B)
    {
        A = root(A);
        B = root(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};
int main()
{
    int n,m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    rep(i, m)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    int ans = 0;
    rep(i, m)
    {
        UnionFind uf(n);
        rep(j, m)
        {
            if(j == i)continue;
            uf.connect(a[j], b[j]);
        }
        if(uf.size(0) != n)
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int n;
  cin >> n;
  vector<int> A(n);
  loop(i,0,n) cin >> A[i];
  loop(i,0,n) {
    if (A[i]%2==1) continue;
    if (A[i]%3!=0 and A[i]%5!=0) {
      cout << "DENIED" << endl;
      return;
    }
  }
  cout << "APPROVED" << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n, k;
    cin >> n >> k;
    double ans = 0;
    for (int i = 1; i <= n; i++) {
        int cnt = 0;
        int j = i;
        while (j < k) {
            cnt++;
            j *= 2;
        }
        ans += pow(0.5, cnt) / (double)n;
    }
    cout << fixed << setprecision(20) << ans << endl;
}

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

#define nl '\n'

using namespace std;

typedef long long ll;

void solve() {
  int N, X, T;
  cin >> N >> X >> T;

  cout << (N + X - 1) / X * T;
}

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

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  // }

  return 0;
}

Measured memory_bytes: 3580
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char s[20];

int main()
{
    while (scanf("%s",s)!=EOF)
    {
        int len=strlen(s);
        if (s[0]!='A' || (s[1]>='A' && s[1]<='Z') || (s[len-1]>='A' && s[len-1]<='Z'))
        {
            puts("WA");
            continue;
        }
        int sum=0;
        bool f=true;
        for (int i=2;i<len-1;i++)
        {
            if (s[i]=='C') 
            {
                sum++;
                continue;
            }
            if (s[i]>='A' && s[i]<='Z')
            {
                f=false;
                break;
            }
        }
        if (sum!=1) f=false;
        if (f) puts("AC");
        else puts("WA");
    }
    return 0;
}

Measured memory_bytes: 128
package main
 
import (
	"fmt"
)
 
func main() {
	var N, M, K, V int
	fmt.Scan(&N)
	fmt.Scan(&M)
	l := make([]int, N)
	m := make(map[int]int, N)
	for i := 0; i < M; i++ {
	    fmt.Scan(&K)
		fmt.Scan(&V)
		m[K - 1] = m[K - 1] + 1
		if l[K-1] == 0 {
			l[K-1] = V
		} else if l[K-1] != V {
			fmt.Println(-1)
			return
		}
	}
	if N == 1 {
		fmt.Println(l[0])
	} else if l[0] == 0 && m[0] >= 1 {
		fmt.Println(-1)
		return
	} else if l[0] == 0 {
		l[0] = 1
		for _, v := range l {
			fmt.Print(v)
		}
	} else {
		for _, v := range l {
			fmt.Print(v)
		}
	}
}


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

int main() {
  int A, B, C, D, x, y;
  cin >> A >> B >> C >> D;
  if ((A + B) > (C + D)) {
    cout << "Left" << endl;
  } else if ((A + B) == (C + D)) {
    cout << "Balanced" << endl;
  } else if ((A + B) < (C + D)) {
    cout << "Right" << endl;
  } 
}

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

int ketasum(int n){
  int sum = 0;
  while (n > 0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  int ans = 0;
  for (int i = 1; i <= n; i++){
    if (a <= ketasum(i) && ketasum(i) <= b) ans += i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<pii, int> mpi;
typedef map<int, int> mii;

template <class T>
using lp_queue=priority_queue<T, vector<T>, greater<T>>;

typedef int Weight;
typedef pair<int, Weight> piw;
typedef pair<Weight, int> pwi;
typedef pair<Weight, Weight> pww;

const Weight INF=1<<29;

struct Edge {
    int src;
    int dst;
    Weight weight;
    Edge(void) {}
    Edge(int s, int d, Weight w=1) {
        src=s; dst=d; weight=w;
    }
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

typedef vector<Edge> Edges;
typedef vector<Edge> Vertex;
typedef vector<Vertex> Graph;

void join(Graph &g, int s, int d, Weight w=1) {
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, int s, int d, Weight w=1) {
    g[s].push_back(Edge(s, d, w));
}

vi shortest_path(Graph &g, int s) {
    /* Dijkstra */
    lp_queue<pwi> q;  // pair<ShortestDistance, IndexVertex>
    int V=g.size();
    vi d(V, INF);

    d[s] = 0;
    q.push(pwi(0, s));
    while (!q.empty()) {
        pwi p=q.top(); q.pop();
        int v=p.second;
        if (d[v] < p.first) continue;

        for (Edge &e: g[v])
            if (d[e.dst] > d[v]+e.weight) {
                d[e.dst] = d[v]+e.weight;
                q.push(pwi(d[e.dst], e.dst));
            }
    }
    return d;
}


void unite(Graph &g, int V, int s, int d, int c) {
    /* connect g[s] to g[d], with color c */
    static mpi parent;
    static set<pii> connected;

    pii src=pii(s, V+c), dst=pii(d, V+c);
    if (parent.count(src)) {
        if (parent.count(dst)) {
            if (!connected.count(pii(parent[src], parent[dst]))) {
                connected.insert(pii(parent[src], parent[dst]));
                join(g, parent[src], parent[dst], 0);
            }
        } else {
            join(g, d, parent[src], 1);
            parent[dst] = parent[src];
        }
    } else if (parent.count(dst)) {
        join(g, s, parent[dst], 1);
        parent[src] = parent[dst];
    } else {
        int C=g.size();
        g.resize(g.size()+1);
        join(g, s, C, 1);
        join(g, d, C, 1);
        parent[src] = parent[dst] = C;
    }
}


int main(void) {
    int N, M;
    cin >> N >> M;

    Graph g(N);
    mii index;
    int i, j;
    for (i=j=0; i<M; i++) {
        int p, q, c;
        scanf("%d %d %d", &p, &q, &c); p--; q--;

        if (!index.count(c))
            index[c] = j++;

        unite(g, N, p, q, index[c]);
    }

    int res=shortest_path(g, 0)[N-1]/2;
    printf("%d\n", res<INF>>1? res:-1);
    return 0;
}


Measured memory_bytes: 57224
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;




int main() {

	string s;
	cin >> s;
	vector<int> a(4);
	for (int i = 0; i < 4; i++) {
		a[i] = (s[i] - '0');
	}

	


	for (int i = 0; i < (1 << 3); i++) {
		int cal = a[0];

		for (int j = 0; j < 3; j++) {
			if ((i >> j) & 1) {
				cal += a[j + 1];
			}
			else {
				cal -= a[j + 1];
			}
		}

		if (cal == 7) {
			cout << a[0];
			for (int j = 0; j < 3; j++) {
				if ((i >> j) & 1) {
					cout << "+";
				}
				else {
					cout << "-";
				}
				cout << a[j + 1];
			}

			cout << "=7";

			break;
			
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[405][405];
ll sum[405];
ll a[405];
int main(){
	int n;
	scanf("%d",&n);
	memset(dp,0,sizeof(dp));
	for(int i = 1;i <= n;i++){
		scanf("%lld",&a[i]);
		sum[i] = sum[i - 1] + a[i];
	}
	for(int i = 2;i <= n;i++){
		for(int j = 1;i + j - 1 <= n;j++){
			int ends = i + j - 1;
			dp[j][ends] = 1e17;
			for(int k = j;k < ends;k++){
				dp[j][ends]=min(dp[j][ends],dp[j][k] + dp[k + 1][ends] + sum[ends] - sum[j - 1]);//中间重复的部分用前缀和加上去，妙啊！
			}
		}
	}
	printf("%lld\n",dp[1][n]);
	return 0;
}

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

int main(void){
    ll h, w;
    cin >> h >> w;
    string a[h];

    rep(i, h){
        cin >> a[i];
    }


    bool check_w[w];
    bool check_h[h];
    rep(i, h){
        bool check = true;
        rep(j, w){
            if(a[i][j] == '#')
                check = false;
        }
        if(check)
            check_h[i] = true;
        else
            check_h[i] = false;
    }
    rep(i, w){
        bool check = true;
        rep(j, h){
            if(a[j][i] == '#')
                check = false;
        }
        if(check)
            check_w[i] = true;
        else
            check_w[i] = false;
    }

    rep(i, h){
        if(check_h[i]) continue;
        rep(j, w){
            if(check_w[j]) continue;
            cout << a[i][j];
        }
        cout << endl;
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000ll
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

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

#define S second
#define F first
#define int long long  
///////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int n,k;
	cin>>n>>k;
	int a[n];
	int ans=0;
	for(int i=0;i<n;++i)
		cin>>a[i];
	for(int i=0;i<=k;++i)
	{
		for(int j=0;j<=i;++j)
		{
			if(i>n)
				continue;
			if(i+j>k)
				continue;
			// cout<<i<<" "<<j<<endl;
			for(int x=0;x<=i;++x)
			{
				vector<int> v;
				for(int y=0;y<x;++y)
				{
					v.push_back(a[y]);
				}
				for(int y=n-1;y>=n-(i-x);--y)
				{
					v.push_back(a[y]);
				}
				// cout<<v.size()<<endl;
				// for(auto r:v)
				// {
				// 	cout<<r<<" ";
				// }cout<<endl;
				sort(v.begin(), v.end());
				int va=0;
				for(int y=0;y<v.size();++y)
				{
					if(y>=j)
						va+=v[y];
				}
				ans=max(ans,va);
			}
			// cout<<endl;
			// cout<<ans<<endl;
		}
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 200005
int n,t[N],p[N],Q,ans;char s[N],op[10],tp[10];
int main()
{
	scanf("%d%d%s",&n,&Q,s+1);ans=n;
	for(int i=1;i<=Q;i++)scanf("%s%s",op+1,tp+1),p[i]=op[1],t[i]=tp[1]=='L';
	int l=0,r=n+1;
	for(int i=Q;i;i--)
	{
		if(t[i])
		{
			if(l<=n&&s[l+1]==p[i])l++;
			if(r<=n&&s[r]==p[i])r++;
		}else
		{
			if(l&&s[l]==p[i])l--;
			if(r&&s[r-1]==p[i])r--;
		}
		if(l>=r)return puts("0"),0;
	}
	printf("%d\n",r-l-1);
}

Measured memory_bytes: 2048
#!/usr/bin/env python3

import sys
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from fractions import gcd                    # for Python3.4.3


def main():
    mod = 10000007                  # 10^9+7
    inf = float('inf')
    input = sys.stdin.readline      # 改行文字が残ることに注意
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def ii():  return int(input())
    def mi():  return map(int, input().rstrip().split())
    def lmi(): return list(map(int, input().rstrip().split()))
    def li():  return list(input().rstrip())
    
    
    a, p = mi()
    print((p + a*3) // 2)

if __name__ == "__main__":
    main()

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

int main(){
    int N;
    long long K;
    cin >> N >> K;
    vector<int>A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        A.at(i)--;
        B.at(i) = -1;
    }
    int i = 0, j = 0;
    while(B.at(i) == -1) {
        B.at(i) = A.at(i);
        i = B.at(i);
        j++;
    }
    int k = 0, l = 0;
    while(k != i) {
        k = A.at(k);
        l++;
    }
    int ans = 0;
    if (K <= l) {
        for (int i = 0; i < K; i++) {
            ans = A.at(ans);
        }
    }
    else {
        ans = i;
        for (int i = 0; i < (K-l)%(j-l); i++) {
            ans = A.at(ans);
        }
    }
    cout << ans + 1;
}

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

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

  vector<int> L(M), R(M);
  rep(i, M) cin >> L[i] >> R[i];

  int l = 0;
  rep(i, M) l = max(l, L[i]);
  int r = 1e9;
  rep(i, M) r = min(r, R[i]);

  cout << max(0, r - l + 1) << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

int main(void)
{
    string S;
    ll N, i, a, b, s, t;
    double x, y;

    cin >> a >> b;

    for(i=0; i<=100000; i++){
        x = (double)i * 0.08;
        y = (double)i * 0.1;
        s = x; t = y;

        if(s==a && t==b){
            cout << i << endl;
            break;
        }

        if(i==100000){
            cout << -1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
f;main(a,b,h){scanf("%d%d%d",&a,&b,&h);
f|=a==99&&b<=18;
f|=a==38&&b>=44;
f|=a==27&&b<=18;
if(f||a==1||a==100||a==3||a==4){printf("%d\n",(a+b)*h/2);}}

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

#include <iostream>
#include <string>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

long long N, K;
vector<long long> P;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N >> K;
	for(int i=0; i<N; i++){
		long long tmp;
		cin >> tmp;
		P.push_back(tmp);
	}
	sort(P.begin(), P.end());

	long long ans = 0;
	for(int i=0; i<K; i++){
		ans += P[i];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3796