akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;
const int oo = 1e8+7;

string s;
vector<vector<int>> dp;
int n;

// dp[i][c] - min number of movements required to have valid arrangement
// if tile i has color col

int solve(int ind, int col) {
    
    if(dp[ind][col] != -1) {
        return dp[ind][col];
    } else if(ind >= n-1) {
        return 0;
    }
    
    int ans = oo;

    if(col != s[ind+1]-'0') {
        ans = solve(ind+1, (col+1)%2);
        //pasamos al siguiente no podemos tocar nada
    } else if(col == s[ind+1]-'0') {
        ans = 1+solve(ind+1, (col+1)%2);
        //cambiamos el siguiente, nos cuesta 1
    }
    
    dp[ind][col] = ans;
    return ans;
}

int main() {
    
    getline(cin, s);
    n = (int)s.size();
    dp.assign(n, vector<int>(2, -1));
    
    int ans = oo;
    ans = min(ans, solve(0, 0) + (s[0] != '0' ? 1 : 0));
    ans = min(ans, solve(0, 1) + (s[0] != '1' ? 1 : 0));
    
    debug() << imie(dp);
    
    cout << ans << endl;
    
    return 0;
}




Measured memory_bytes: 10496
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;
const ll MAX=1e5+5;

ll lcm(ll x,ll y)
{
	return ((x*y)/ __gcd(x,y));
}
void test_cases()
{
ll n,b;
cin>>n>>b;

ll cost=b;
if(n>5&&n<=12)
{
	cost=b/2;
}
else if(n<=5)cost=0;

cout<<cost;

}

int main()
{
    fast;
	
	ll t;
//	cin>>t;
	t=1;
	while(t--)
	test_cases();





    
}

		
	
	
	
	


Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;


int main(){
  long n,m;
  cin>>n>>m;
  if(n>m/2)
    printf("%ld\n",m/2);
  else
    printf("%ld\n",n+(m-2*n)/4);
}

Measured memory_bytes: 256
import sys
s = input()
k = int(input())
if len(set(list(s))) == 1:
	print((len(s)*k)//2)
	sys.exit()
tmp = s[0]
cnt = 1
base = 0
is_first = True
for i in range(1, len(s)):
	if s[i] == tmp:
		cnt += 1
	else:
		if is_first:
			is_first = False
			first = cnt//2
		else:
			base += cnt//2
		tmp = s[i]
		cnt = 1

if s[0] != tmp:
	base += cnt//2
	print((first+base)*k)
else:
	i = 0
	last = cnt//2
	while s[i] == tmp:
		cnt += 1
		i += 1
	base += cnt//2
	#print(first, base, last)
	print(first + base*k - cnt//2 + last)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
typedef long long int lli;
using namespace std;

//1
/*
int main(){
	int hoge[5];
	int sum=0;
	for(int i=0; i<5; ++i){
		cin >> hoge[i];
		if(hoge[i]<40) hoge[i]=40;
		sum+=hoge[i];
	}
	cout << sum/5 << "\n";
	return 0;
}*/

//2
/*
int main(){
	int N,M;
	cin >> N >> M;
	vector<int> cost(N);
	vector<int> border(M);
	vector<int> pnt(N);
	for(int i=0; i<N; ++i){
		cin >> cost[i];
	}
	for(int i=0; i<M; ++i){
		cin >> border[i];
	}
	for(int i=0; i<M; ++i){
		for(int j=0; j<N; ++j){
			if(border[i]>=cost[j]){
				++pnt[j];
				break;
			}
		}
	}
	int max_p=-1;
	int ans;
	for(int i=0; i<N; ++i){
		if(pnt[i]>max_p) {
			max_p=pnt[i];
			ans=i+1;
		}
	}
	cout << ans << "\n";
	return 0;
}*/

/*
const int INF=10000000;
const int MAX_W=10000;
const int MAX_H=10000;
int dx[6]={-1,-1,0,1,1,0};
int dy[6]={0,-1,-1,0,1,1};
int H,W,N;
int maze[MAX_W+1][MAX_H+1];
int d[MAX_W+1][MAX_H+1];

int main(){
	cin >> W >> H >> N;
	vector<int> ans(N+1);
	vector<int> gx(N+1);
	vector<int> gy(N+1);
	for(int i=1; i<N+1; ++i){
		cin >> gx[i] >> gy[i];
	}
	for(int i=0; i<W+1; ++i)
		for(int j=0; j<H+1; ++j) d[i][j]=INF;
	int sx=gx[1],sy=gy[1];
	d[sx][sy]=0;
	for(int i=2; i<N+1; ++i){
		queue<int> qux;
		queue<int> quy;
		int x;
		int y;
		qux.push(sx);
		quy.push(sy);
		while(qux.size()&&quy.size()){
			//cout << "ok";
			x=qux.front();
			y=quy.front();
			qux.pop();
			quy.pop();

			if(x==gx[i]&&y==gy[i]){
				ans[i]=d[x][y];
				for(int j=0; j<W+1; ++j)
					for(int k=0; k<H+1; ++k) d[j][k]=INF;
				sx=x;
				sy=y;
				d[sx][sy]=0;
				break;
			}
			for(int j=0; j<6; ++j){
				int nx=x+dx[j],ny=y+dy[j];
				if(1<=nx&&nx<=W&&1<=ny&&ny<=H&&d[nx][ny]==INF){
					if((x<=nx&&nx<=gx[i]&&y<=ny&&ny<=gy[i])||(gx[i]<=nx&&nx<=x&&y<=ny&&ny<=gy[i])||(gx[i]<=nx&&nx<=x&&gy[i]<=ny&&ny<=y)||(x<=nx&&nx<=gx[i]&&gy[i]<=ny&&ny<=y)){
					qux.push(nx);
					quy.push(ny);
					d[nx][ny]=d[x][y]+1;
					}
				}
			}
		}
	}
	long long int ANS=0;
	for(int i=1; i<=N; ++i){
		//cout << ans[i] << "\n";
		ANS+=ans[i];
	}
	cout << ANS << "\n";
}*/

int main(){
	string word,LONG="",MAX_S;
	map<string,int> cnt;
	int MAX_I=0;
	while(cin>>word){
		if(word.size()>LONG.size()){
			LONG=word;
		}
		++cnt[word];
	}
	map<string,int>::iterator it=cnt.begin();
	for( ; it!=cnt.end(); ++it){
		if(it->second>MAX_I) {
			MAX_I=it->second;
			MAX_S=it->first;
		}
	}
	cout << MAX_S << " " << LONG << "\n";
	return 0;
}

Measured memory_bytes: 1188
fun main(args: Array<String>) {
    val inputs = readLine()?.split(" ")?.map { it.toInt() } ?: return
    val n = inputs[0]
    val y = inputs[1]

    val result = searchCombination(n, y)
    println("${result.third} ${result.second} ${result.first}")
}

/**
 * 合計がsumな1000円,5000円,10000円の組み合わせを探す
 * 見つからなかった場合 -1, -1, -1を返す
 *
 * @param numberOfSheet 枚数
 * @param sum 合計
 * @return Triple<Int, Int, Int>: 1000円,5000円,10000円の枚数
 */
fun searchCombination(numberOfSheet: Int, sum: Int): Triple<Int, Int, Int> {
    for (i1000 in 0..numberOfSheet) {
        for (i5000 in 0..numberOfSheet) {
            for (i10000 in 0..(numberOfSheet - i1000 - i5000)) {
                if (i1000 + i5000 + i10000 != numberOfSheet) continue
                if ((i1000 * 1000 + i5000 * 5000 + i10000 * 10000) == sum)
                    return Triple(i1000, i5000, i10000)
            }
        }
    }
    return Triple(-1, -1, -1)
}

Measured memory_bytes: 38008
#include<stdio.h>
int main(){
  long long int n,W,w[110],v[110],i,j,dp[110][100010],ans=0;
  scanf("%lld %lld\n",&n,&W);
  for(i=1;i<=n;i++){
    scanf("%lld %lld\n",&w[i],&v[i]);
  }
  for(i=0;i<=W;i++){
    dp[0][i]=0;
  }
  for(i=1;i<=n;i++){
    for(j=0;j<=W;j++){
      if(j-w[i]>=0){
        if(dp[i-1][j]<dp[i-1][j-w[i]]+v[i]){
          dp[i][j]=dp[i-1][j-w[i]]+v[i];
        }
        else{
          dp[i][j]=dp[i-1][j];
        }
      }
      else{
        dp[i][j]=dp[i-1][j];
      }
    }
  }
  for(i=0;i<=W;i++){
    if(ans<dp[n][i]){
      ans=dp[n][i];
    }
  }
  printf("%lld\n",ans);
  return 0;
}

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

int main()
{
    int H,W,k,ans=0;
    cin>>H>>W>>k;
    vector<string> c(H);
    for(int i=0;i<H;i++) cin>>c[i];
    
    for(int bith=0;bith<(1<<H);++bith) for(int bitw=0;bitw<(1<<W);++bitw)
    {
        int count=0;
        for(int h=0;h<H;++h) for(int w=0;w<W;++w)
        {
            if((bith>>h)&1) continue;
            if((bitw>>w)&1) continue;
            if(c[h][w]=='#') count++;
        }
        if(count==k) ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
typedef cpp_int ll;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 998244353

// typedef long long ll;
typedef pair<ll, ll> p;

ll mod_pow(ll a, int p){
  if(p == 0) return 1;
  if(p % 2 == 0){
    int half_p = p / 2;
    ll half = mod_pow(a, half_p);
    return half * half % MOD;
  }else{
    return a * mod_pow(a, p-1) % MOD;
  }
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> v(n);
  map<ll, int> mp;
  rep(i, n){
    cin >> v[i];
    mp[v[i]]++;
  }
  ll res = 1;
  if(v[0] != 0 || mp[0] != 1) res = 0;


  for (int i = 1; i < n; i++) {
    res *= mod_pow(mp[i-1], mp[i]);
    res %= MOD;
  }
  cout << res << endl;

}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll k; cin >> k;
    int n = 50;
    cout << n << endl;
    for (int i = 0; i < n; ++ i) {
        cout << i + (k + i) / 50 << " \n"[i + 1 == n];
    }
    return 0;
}


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


long long fact[10005];
long long inv[10005];
long long finv[10005];
long long init(int n){
	fact[0]=finv[0]=1;
	inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(MOD-(MOD/i)*inv[MOD%i]%MOD)%MOD;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
long long comb(long long n, long long k){
    if( n < k || k < 0 )return 0;
    return fact[n]*finv[n-k]%MOD*finv[k]%MOD;
}

int main(){
    init(6000);
    int N, K; cin >> N >> K;
    int red = N-K, blue = K;


    long long ans = 1;
    for( int i = 1; i <= K; i++ ){
        ans *= comb( red + 1 , i );
        ans *= comb( blue - 1 , i - 1 );
        ans %= MOD;

        cout << ans << endl;
        ans = 1;
    }
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  int n,c,m1,s1,m2,s2,m3,s3,m4,s4,time;
  while(cin>>n){
    if(n==0) break;
    int anst[4]={0};
    int ans[4];
    for(int i=0;i<2;i++) anst[i] = 1000000;
    for(int i=0;i<n;i++){
      cin >> c >> m1 >> s1 >> m2 >> s2 >> m3 >> s3 >> m4 >> s4;
      time=m1*60+s1+m2*60+s2+m3*60+s3+m4*60+s4;
      if(anst[0]>time){
	anst[1] = anst[0];
	ans[1] = ans[0]; 
	anst[0] = time;
	ans[0] = c; 
      }
      else if(anst[1]>time){
	anst[1] = time;
	ans[1] = c;
      }
      if(anst[3]<time){
	anst[2] = anst[3];
	ans[2] = ans[3];
	anst[3] = time;
	ans[3] = c;
      }
      else if(anst[2]<time){
	anst[2] = time;
	ans[2] = c;
      }
    }
    cout << ans[0] << endl << ans[1] << endl << ans[2] << endl;
  }
  return 0;
}

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


#define ll long long int
#define pb push_back


int main()
{
  
  ll x,y;
  cin>>x>>y;
  ll total=0;
  
  ll f=300000;
  ll s=200000;
  ll t=100000;
  
  ll ctr=0;
  if(x==1)
  {
      total+=f;
      ctr++;
  }
  if(x==2)
  total+=s;
  if(x==3)
  total+=t;
  if(y==1)
  {
      total+=f;
      ctr++;
  }
  if(y==2)
  total+=s;
  if(y==3)
  total+=t;
  
  if(ctr==2)
  total+=400000;
  
  cout<<total;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<set>
#include<queue>
#include<vector>
#include<cstdio>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
  long long a,b,c,x,y,ans1,ans2,ans3;
  cin>>a>>b>>c>>x>>y;
  ans1=min(x,y)*c*2+(x-min(x,y))*a+(y-min(x,y))*b;
  ans2=x*a+y*b;
  ans3=max(x,y)*c*2;
  cout<<min(ans1,min(ans2,ans3));
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [int(_) for _ in input().split()]

dp = [[0]*2 for _ in range(N)]
dp[1][0] = A[0]+A[1]
dp[1][1] = -A[0]-A[1]

if N > 2:
	for i in range(2, N):
		dp[i][0] = max(dp[i-1][0]+A[i], dp[i-1][1]+A[i])
		dp[i][1] = max(dp[i-1][0]-A[i-1]*2-A[i], dp[i-1][1]+A[i-1]*2-A[i])

print(max(dp[-1]))

Measured memory_bytes: 24780
class UnionFind():
    
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
      
N, M = list(map(int,input().split()))
p = list(map(int,input().split()))
x = []
y = []
for i in range(M):
    in1, in2 = list(map(int,input().split()))
    x.append(in1)
    y.append(in2)

uf = UnionFind(N)
for i in range(M):
    uf.union(x[i] - 1, y[i] - 1)
ans = 0
for i in range(N):
    ans += uf.same(i, p[i] - 1)
print(ans)

Measured memory_bytes: 95728
#include <stdio.h>
#define maxn 200010
int head[maxn],tot,n,m,d[maxn],pre[maxn],q[maxn*10],vis[maxn];
struct node{
	int to,next;
}e[maxn<<1];
void add_edge(int u,int v){
	tot++,e[tot].to=v,e[tot].next=head[u],head[u]=tot;
}
void init(){
	int i,u,v;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++){
		scanf("%d%d",&u,&v);
		add_edge(u,v),add_edge(v,u);
	}
}
void spfa(){
	int h,t,i,u,v,b;
	for(i=1;i<=n;i++)d[i]=maxn;
	d[1]=0,h=t=1,q[t]=1,t++,vis[1]=1;
	while(h<t){
		u=q[h];
		for(b=head[u];b;b=e[b].next){
			v=e[b].to;
			if(d[v]>d[u]+1){
				pre[v]=u;
				d[v]=d[u]+1;
				if(!vis[v])vis[v]=1,q[t]=v,t++;
			}
		}
		h++;
		vis[u]=0;
	}
	for(i=1;i<=n;i++)
		if(d[i]==maxn){printf("No\n");return;}
	printf("Yes\n");
	for(i=2;i<=n;i++)printf("%d\n",pre[i]);
}
int main(){
	init();
	spfa();
	return 0;
}

Measured memory_bytes: 8284
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(llint i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define Pll pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
const ll mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
const ll INF = 1000000000;

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

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
llint C(llint n, llint r, llint m) {
	llint ans = 1;
	for (llint i = 0; i < r; i++) {
		ans *= n - i;
		ans %= m;
	}
	for (llint i = 1; i <= r; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}


int main() {
	int n;
	cin >> n;
	bool ans = false;
	int c = 0;
	rep(i, 0, n) {
		int a, b;
		cin >> a >> b;
		if (a == b)c++;
		else {
			c = 0;
		}
		if (c == 3)ans = 1;

	}
	Yes(ans);
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>


int main(){
  int A,B,C,D,taka,ao;
  scanf("%d%d%d%d",&A,&B,&C,&D);
  taka=A/D;
  ao=C/B;
  if(A%D!=0)taka++;
  if(C%B!=0)ao++;
  if(taka<ao)printf("No");
  else printf("Yes");
};
   

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int d;
	d = a - b;
	int ans = 0;
	if (c - d < 0) {
		ans = 0;
	}
	else {
		ans = c - d;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
import static java.lang.Math.*;
import static java.util.Arrays.*;

import java.util.*;
import java.io.*;

public class Main {
	
	int[] coint = {10, 50, 100, 500};
	int max = 20000;
	int INF = 1<<28;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		boolean f = false;
		for(;;) {
			int v = sc.nextInt();
			if( v == 0 ) break;
			if(f) {
				System.out.println();
			}
			int[] coins = new int[4];
			int sum = 0, c = 0;
			for(int i=0;i<4;i++) {
				coins[i] = sc.nextInt();
				c += coins[i];
			}
			int[] ans = new int[4]; int min = INF;
			for(int i=0;i<=coins[0];i++) for(int j=0;j<=coins[1];j++) 
			for(int k=0;k<=coins[2];k++) for(int l=0;l<=coins[3];l++) {
				sum = i*coint[0] + j*coint[1] + k*coint[2] + l*coint[3] - v;
				if(sum < 0) continue;
				int cnt = c - i - j - k - l;
				for(int m=3;m>=0;m--) {
					cnt += sum/coint[m];
					sum %= coint[m];
				}
				if( min > cnt ) {
					min = cnt;
					ans = new int[] {i, j, k, l};
				}
			}
			for(int i=0;i<4;i++) if(ans[i] > 0){
				System.out.println(coint[i] + " " + ans[i]);
			}
			f = true;
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 36248
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
int cnt[10][10];
int main()
{
	int n;cin>>n;
//	if(n<10){
//		cout << n << endl;
//		return 0;
//	}
	for(int i=1;i<=n;i++){
		int x = i;
		int y = i%10;
		while(x>=10)x/=10;
		cnt[x][y]++;
	}
	ll ans = 0;
	for(int i=0;i<10;i++)
	for(int j=0;j<10;j++)
		ans += 1LL*cnt[i][j]*cnt[j][i];
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
using namespace std;
vector<int> h(100009);
vector<int> dp(100009);
ll ans;
int calc(ll i,ll n)
{
	for(i=0;i<n;i++)
	{
		dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
		if(i+2>n)
			continue;
		dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
	}
	
}
int main()
{
	ll n,i;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>h[i];
		dp[i]=INT_MAX;
	}
	dp[0]=0;
	calc(0,n-1);
	cout<<dp[n-1];
	return 0;
}

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



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

    double r; cin >> r;
    cout << fixed << setprecision(12) << 2.0*r*M_PI << endl;
}

Measured memory_bytes: 3804
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>

using namespace std;

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b < c){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e8;
using namespace std;

#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define debug system("pause")

int main(void)
{
	
	ll n;
	ll x;
	ll ans = 0;
	cin >> n >> x;

	vector<ll> ame(n);

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

	sort(ame.begin(), ame.end());

	int i = 0;
	while (i<n)
	{
		if (ame[i] <= x)
		{
			x -= ame[i];
			ans++;
		}
		else
			break;

		i++;
	}

	if (x > 0&&ans==n)
		ans--;

	cout << ans << endl;

}

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

///    ____ ____ ____ ____ ____
///   ||a |||t |||o |||d |||o ||
///   ||__|||__|||__|||__|||__||
///   |/__\|/__\|/__\|/__\|/__\|
///

using namespace std;

long long n, A, B, C, D;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> A >> B >> C >> D;
    for(long long m = 0; m <= n - 1; m++)
    {
        if(-D * m + C * (n - 1 - m) <= B - A && B - A <= -C * m + D * (n - 1 - m))
        {
            cout << "YES\n";
            return 0;
        }
    }
    cout << "NO\n";
    return 0;
}


Measured memory_bytes: 3656
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<map>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
int n;
map<ll,int> a;
queue<pii> q;
set<int> l[100010];
int f[100010];
int find(int x)
{
	return f[x]==x?x:f[x]=find(f[x]);
}
ll getid(int x,int y)
{
	if(x>y)
		swap(x,y);
	return ll(x)*n+y;
}
void link(int x,int y)
{
	l[x].insert(y);
	l[y].insert(x);
	ll v=getid(x,y);
	a[v]++;
	if(a[v]==3)
	{
		printf("NO\n");
		exit(0);
	}
	if(a[v]==2)
		q.push(pii(x,y));
}
int main()
{
	scanf("%d",&n);
	int i,x,y;
	for(i=1;i<=2*n-2;i++)
	{
		scanf("%d%d",&x,&y);
		link(x,y);
	}
	for(i=1;i<=n;i++)
		f[i]=i;
	for(i=1;i<n;i++)
	{
		while(1)
		{
			if(q.empty())
			{
				printf("NO\n");
				return 0;
			}
			x=q.front().first;
			y=q.front().second;
			x=find(x);
			y=find(y);
			q.pop();
			if(x!=y)
				break;
		}
		if(l[x].size()>l[y].size())
			swap(x,y);
		f[x]=y;
		a.erase(getid(x,y));
		l[y].erase(x);
		for(auto v:l[x])
		{
			v=find(v);
			if(v==y)
				continue;
			link(v,y);
			a.erase(getid(x,v));
			l[v].erase(x);
			l[x].erase(v);
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 37376
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<bool> vbool;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<llint> vllint;
typedef vector<vllint> vvllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define coutans rep(i, ans.size())cout << ans[i] << endl;
#define mod (llint)1000000007
#define int_max 2147483647
#define ll_max (llint)9223372036854775807

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aのb乗を求める(1000000007で割った余りやで)
llint modpow(llint a, llint b) {
	if (b == 0)return 1;
	if (b == 1)return a;
	llint tmp = modpow(a, b / 2);
	tmp %= mod;
	tmp = tmp * tmp % mod;
	if (b % 2)return tmp * a % mod;
	else return tmp;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= mod;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, mod);
		ans %= mod;
	}
	return ans;
}


int main() {
	string s;
	cin >> s;
	if (s.size() == 3) {
		cout << s[2] << s[1] << s[0] << endl;
	}
	else cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
ans = 0

for i in range(N):
    if i == 0:
        a = A[i]
        count = 1
    else:
        if a == A[i]:
            count += 1
            continue
        else:
            ans += count // 2
            a = A[i]
            count = 1
ans += count // 2
print(ans)


Measured memory_bytes: 3060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Objects;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CBBuBBBlesort solver = new CBBuBBBlesort();
        solver.solve(1, in, out);
        out.close();
    }

    static class CBBuBBBlesort {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

        /*
        高橋君は誕生日に長さNの数列をもらった。
        i番目の要素がA _ i で与えられる。
        どの要素も互いに異なる
        - 連続する2要素を選び反転
        - 連続する3要素を選び反転
        ができる。これを用いてソートする場合の最小回数を求めよ。

        なんもわからんけどどうせ偶奇のパリティかなんかでどうにかなるんじゃない？
        ソート後が偶数なら偶数に入れればジャンプジャンプで乗り切れそう
        indexとペアを組んでソートする
         */

            int n = in.nextInt();
            ArrayList<Pair<Integer, Integer>> p = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                p.add(new Pair<>(i, in.nextInt()));
            }

            p.sort(Comparator.comparing(o -> o.u));


            // 思ったけどp.tとp.uってわかりづらいな、o1o2にしようかしら
            // ソートのキーを間違いました。
            // o1o2に書き直します
            // と思ったけど面倒だからあとでいいや
            // さて証明をする必要がある…が
            // とりあえずAC取りに行くか


            int cnt = 0;
            for (int i = 0; i < n; i++) {
                if (i % 2 != p.get(i).t % 2) {
                    cnt++;
                }
            }

            out.println(cnt / 2);


        }

    }

    static class Pair<T, U> {
        public T t;
        public U u;

        public Pair(T t, U u) {
            this.t = t;
            this.u = u;
        }

        public String toString() {
            return "Pair{" +
                    "t=" + t.toString() +
                    ", u=" + u.toString() +
                    '}';
        }

        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Pair<?, ?> pair = (Pair<?, ?>) o;
            return Objects.equals(t, pair.t) &&
                    Objects.equals(u, pair.u);
        }

        public int hashCode() {
            return Objects.hash(t, u);
        }

    }
}



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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#pragma GCC optimize("Ofast")
//1.0 * clock() / CLOCKS_PER_SEC

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int NN = 1e6 + 7;
const int N = 2e5 + 7;
const int M = 20;
const ll mod = 998244353;
const ll inf = 1e18 + 7;
const dl rf = 1e-14;

void solve1()
{
    int n,m;
    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); srand(time(0));
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}


ll mpow(ll a,ll x){
  ll ret=1;
  while(x>0){
    if(x&1){ret*=a;}
    x>>=1;
    if(x>0){a*=a;}
  }
  return ret;
}

ll atai(ll div,ll n){
  div=abs(div);
  if(div>9){return 0;}
  if(n==0){return 9-div;}
  return 10-div;
}

ll dfs(ll num,ll K,ll n){
  ll ret=0;
  num=abs(num);
  ll dif=mpow(10,K-n)-mpow(10,n);
  if(K==2*n){return num==0?10:0;}
  if(K<2*n){return num==0?1:0;}
  ll div=num/dif,rem=num%dif;
  if(atai(div,n)!=0){ret+=atai(div,n)*dfs(rem,K,n+1);}
  if(atai(div+1,n)!=0){ret+=atai(div+1,n)*dfs(rem-dif,K,n+1);}
  //cout<<num<<" "<<K<<" "<<n<<" "<<ret<<endl;
  return ret;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll D;
  cin>>D;
  ll ans=0;
  for(int i=1;i<18;i++){ans+=dfs(D,i,0);}
  cout<<ans<<endl;

  return 0;
}


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

int main()
{
    long long int n, i, sum=0;
    cin>>n;
    for(i=1;i<sqrt(n);i++){
        if(n%i==0){
            if(n/i-1>i)
                sum+=n/i-1;
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 764
while true
  d = gets.chomp.split
  a,b,c = d.map(&:to_i)
  count = 0
  count_add = 0

  for x in a..b
    if ( d[2].to_i % x.to_i ) == 0
      # count_add = ( d[2].to_i / x.to_i )
      # count += count_add
      count += 1
    end
  end

break
end

puts count



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

int main() {
  int n;
  cin >> n;
  int ans = n*n*n;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import math

n = int(input())

def F(a, b, c, d) :
    return lambda x : a * x**3 + b * x**2 + c * x + d
    
def X(a, b, c) :
    a = 3 * a
    b = 2 * b
    
    try :
        D = math.sqrt(b**2 - 4 * a * c)
        
        if D == 0 :
            return 0
        else :
            return (-b + D) / (2 * a), (-b - D) / (2 * a)
        
    except :
        return -1
def boa(fz, lmax, lmin, p, n) :
    if fz > 0 :
        if lmin > 0 :
            p, n = 2, 1
        else :
            n = 3
    elif fz == 0 :
        if 0 < lmin and lmax < 0 :
            p, n = 1, 1
        elif lmax > 0 :
            p = 2
        else :
            n = 2
    else :
        if lmax > 0 :
            p = 3
        else :
            p, n = 1, 2
        
    return p, n
            
def ao(fz, lmax, p, n) :
    if fz > 0 :
        n = 2
    elif fz == 0 :
        if lmax == 0 :
            p = 1
        else :
            n = 1
    else :
        if lmax > 0 :
            p = 2
        else :
            p, n = 1, 1
        
    return p, n

def bo(fz, lmin, p, n) :
    if fz > 0 :
        if lmin > 0 :
            p, n = 1, 1
        else :
            n = 2
    elif fz == 0 :
        if lmin == 0 :
            n = 1
        else :
            p = 1
    else :
        p = 2
        
    return p, n
      
def aob(fz, p, n) :
    if fz > 0 :
        n = 1
    elif fz < 0 :
        p = 1
        
    return p, n
    
def P(x, y) :
    if x > 0 :
        print(y, 0)
    elif x < 0 :
        print(0, y)
    else :
        print(0, 0)
        
for i in range(n) :
    a, b, c, d = map(int, input().split())
    if a < 0 :
        a *= -1
        b *= -1
        c *= -1
        d *= -1
        
    f = F(a, b, c, d)
    
    p = 0
    # Positive integer
    n = 0
    # Negative integer
    
    if X(a, b, c) == -1 :
        P(-d, 1)
            
    elif X(a, b, c) == 0 :
        if f(-b / (3 * a)) == 0 :
            P(-b, 3)
        else :
            P(-d, 1)
            
    else :
        if f(X(a, b, c)[0]) < f(X(a, b, c)[1]) :
            lmax = X(a, b, c)[1]
            # Local maximum
            lmin = X(a, b, c)[0]
            # Local minimum
        else :
            lmax = X(a, b, c)[0]
            lmin = X(a, b, c)[1]
        
        fmax = f(lmax)
        fmin = f(lmin)
        fz = f(0)
        
        if lmax == lmin :
            if lmax < 0 :
                print(0, 3)
            elif lmax > 0 :
                print(3, 0)
            else :
                print(0, 0)
                
        elif fmin < 0 and 0 < fmax :
            pn = boa(fz, lmax, lmin, p, n)
            print(pn[0], pn[1])
            
        elif fmax == 0 :
            pn = ao(fz, lmax, p, n)
            print(pn[0], pn[1])
            
        elif fmin == 0 :
            pn = bo(fz, lmin, p, n)
            print(pn[0], pn[1])
            
        else :
            pn = aob(fz, p, n)
            print(pn[0], pn[1])


Measured memory_bytes: 5760
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll i,f=1,N='z'-'a'+1,cnt=0;
  string s,t;
  cin>>s>>t;
  vec v(N,-1);
  rep(i,(ll)s.size()){
    if(v[s[i]-'a']<0){
      v[s[i]-'a']=t[i]-'a';
    }else if(v[s[i]-'a']!=t[i]-'a'){
      cout<<"No"<<endl;
      return 0;
    }
  }
  set<ll> se;
  rep(i,N){
    if(v[i]>0){
      if(v[i]!=i)cnt++;
      auto p=se.insert(v[i]);
      if(!p.second){
        cout<<"No"<<endl;
        return 0;
      }
    }else{
      f=0;
    }
  }
  if(cnt%2*f){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }
  return 0;
}

Measured memory_bytes: 916
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<deque>

using namespace std;

typedef pair<int,int>P;

const int maxn=1e3+5;
int inf=500;

int h,w,n,sx,sy,goal[10],book[maxn][maxn],Next[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
char s[maxn][maxn];

int judge(int row,int col)
{
    if(row>=0&&row<h&&col>=0&&col<w){
        return 1;
    }
    return 0;
}

int bfs()
{
    int res=0;
    deque<P>q;
    for(int ci=0;ci<n;ci++){
        fill(book[0],book[0]+maxn*maxn,inf);
        q.push_back(P(sx,sy));
        book[sx][sy]=0;
        while(!q.empty()){
            int x=q.front().first;
            int y=q.front().second;
            q.pop_front();
            if((int)s[x][y]==49+ci){
                goal[ci]=book[x][y];
                sx=x;
                sy=y;
                break;
            }
            for(int i=0;i<4;i++){
                int nx=x+Next[i][0];
                int ny=y+Next[i][1];
                if(judge(nx,ny)&&s[nx][ny]!='X'&&book[nx][ny]==inf){
                    q.push_back(P(nx,ny));
                    book[nx][ny]=book[x][y]+1;
                }
            }
        }
        q.clear();
        res+=goal[ci];
    }
    return res;
}

int main()
{
    cin>>h>>w>>n;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>s[i][j];
            if(s[i][j]=='S'){
                sx=i;
                sy=j;
            }
        }
    }
  //  cout<<sx<<" "<<sy<<endl;
    int res=bfs();
    cout<<res<<endl;
    return 0;
}



Measured memory_bytes: 8000
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor.hpp>
#include <boost/algorithm/string.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;

using ll = long long;
namespace bst = boost;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> N, M;
  invec<int> H(N);
  multimap<int,int> AB;
  vector<bool> isgood(N, true);
  REP(i,M) {
    int A, B;
    cin >> A >> B;
    AB.emplace(A, B);
    AB.emplace(B, A);
    
    if (H[A-1] <= H[B-1]) {
      isgood[A-1] = false;
    }
    if (H[A-1] >= H[B-1]) {
      isgood[B-1] = false;
    }


  }

  int r = 0;
  for(auto i : isgood)
    if (i)
      r++;

  return r;
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}



Measured memory_bytes: 13024
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define _ << " " <<
#define all(v) v.begin(), v.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	cout << 180 * (n - 2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
int main() {
	int a, b; cin >> a >> b;
	cout << (b - a)*(b - a - 1) / 2 - a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[256];
char s[256];
int main()
{
    cin>>s;
    int l=1;
    for(int i=0; s[i]; i++)a[s[i]]=1,l++;
    for(int c='z'; c>='a'; c--)
        if(!a[c])s[l++]=c;
    if(next_permutation(s,s+l))
        cout<<s;
    else
        cout<<-1;
    return 0;
}


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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
//   cout<<std::setprecision(12)<<


int main()
{
    deque<char>s;
    string ss;
    cin >> ss;
    for(int i=0;i<ss.size();i++)s.pb(ss[i]);
    int i,j,k,l,m,n,q,cnt=0;

    cin>>q;

    while(q--)
    {
        cin>>l;

       if(l == 1)cnt++;
       else
       {
           cin >> l;
           char ch;
           cin >> ch;
           if(cnt%2 == 0){
           if(l == 2)s.pb(ch);
           else s.push_front(ch);
           }
           else
           {
               if(l == 1)s.pb(ch);
           else s.push_front(ch);
           }
       }
    }
if(cnt&1)reverse(all(s));

    for(auto x : s)cout<<x;
    cout<<endl;
}


Measured memory_bytes: 896
n = int(input())
ab = []
for _ in range(n):
  a,b = map(int,input().split())
  ab.append([a,b])
ab.sort(key = lambda x:x[0]+x[1] ,reverse = True)
ans = sum([x[0]+x[1] for x in ab[0:n:2]])-sum([x[1] for x in ab])
print(ans)




Measured memory_bytes: 69336
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String w = sc.next();
        for (char c = 'a'; c <= 'z'; c++) {
            int count = 0;
            for (int i = 0; i < w.length(); i++) {
                if (c == w.charAt(i))
                    count++;
            }
            if (count % 2 != 0) {
                System.out.println("No");
                System.exit(0);
            }
        }
        System.out.println("Yes");
    }
}


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

int main()
{
  int N; cin >> N;
  vector<int> p(N);
  rep(i,N) cin >> p[i];
  int temp = 0;
  int count = 0;
  rep(i,N)
  {
    if(p[i] != i+1) count++;
  }
  if(count <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const int N=2010;
const int V=4020;
const int mo=1e9+7;
int c[V*2+10][V+10];
int Sum(int x,int y) {
    x+=y;
    return (x>=mo)?x-mo:x;
}
int Sub(int x,int y) {
    x-=y;
    return (x<0)?x+mo:x;
}
int Mul(int x,int y) {
    return (long long)x*y%mo;
}
int n;
int vis[V+10][V+10],f[V+10][V+10];
void Calcvalue(int x,int y) {
    int nx=x+N,ny=y+N;
    f[nx][ny]=Sum((nx==0?0:f[nx-1][ny]),((ny==0)?0:f[nx][ny-1]));
    if (x<=0&&y<=0) f[nx][ny]=Sum(f[nx][ny],vis[-x][-y]);
}
void Prework() {
    
    c[0][0]=1;
    for (int i=1;i<=V*2;i++) {
        c[i][0]=1;
        for (int j=1;j<=min(i,V);j++)
            c[i][j]=Sum(c[i-1][j],c[i-1][j-1]);
    }
}
int main() {
    Prework();
    int ans=0;
    scanf("%d",&n);
    for (int i=1;i<=n;i++) {
        int x,y;
        scanf("%d%d",&x,&y);
        vis[x][y]++;
        ans=Sub(ans,c[(x+y)*2][x*2]);
    }
    for (int i=-N;i<=N;i++)
        for (int j=-N;j<=N;j++)
            Calcvalue(i,j);
    for (int i=0;i<=N;i++)
        for (int j=0;j<=N;j++)
            ans=Sum(ans,Mul(vis[i][j],f[i+N][j+N]));
    printf("%d\n",Mul(ans,(mo+1)/2));
    return 0;
}


Measured memory_bytes: 225024
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define ull unsigned long long
#define EPS 1e-8
using namespace std;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
const double pi = acos(-1.0);
int read()
{
	int ret=0;char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	for(;ch>='0'&&ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret;
}
int a,b,c; 
int main()
{
 	#ifdef TEST
	 	freopen("input.txt","r",stdin);
	#endif
	scanf("%d%d%d",&a,&b,&c);
	printf("%d\n",a^b^c);
	return 0;
}



Measured memory_bytes: 256