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

int main(){
	int n, cnt = 0;
	vector<int> A(101);
    cin >> n;
	for(int i = 0; i < n; i++) cin >> A[i];

    int minj;
    for(int i = 0; i < n; i++)
    {
        minj = i;
        for(int j = i+1; j < n; j++)
        {
            if(A[minj] > A[j]) minj = j;
        }
        
        if(i != minj) cnt++;
        
        swap(A[i], A[minj]);

    }

    for(int i = 0; i < n; i++)
    {
        if(i > 0) cout << ' ';
        cout << A[i];
    }

    cout << endl << cnt << endl;
    
    
}


Measured memory_bytes: 3084
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 100005

using namespace std;
typedef long long int ll;

int S[SIZE],T[SIZE];
char str[SIZE];

int main()
{
	scanf("%s",&str);
	int n=strlen(str);
	for(int i=0;i<n;i++)
	{
		if(str[i]=='A') S[i]=1;
		else S[i]=2;
		if(i>0) S[i]+=S[i-1];
	}
	scanf("%s",&str);
	n=strlen(str);
	for(int i=0;i<n;i++)
	{
		if(str[i]=='A') T[i]=1;
		else T[i]=2;
		if(i>0) T[i]+=T[i-1];
	}
	int Q;
	scanf("%d",&Q);
	for(int i=0;i<Q;i++)
	{
		int a,b,c,d;
		scanf("%d %d %d %d",&a,&b,&c,&d);a--,b--,c--,d--;
		int s=S[b]-(a==0?0:S[a-1]);
		int t=T[d]-(c==0?0:T[c-1]);
		if(s%3==t%3) puts("YES");
		else puts("NO");
	}
	return 0;
}


Measured memory_bytes: 1408
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                   0.000000000000001
#define endl                        '\n'
#define sz(a)                int((a).size())
#define all(c)               (c).begin(),(c).end()
#define tr(c,i)              for(typeof(c).begin() 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 pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[100010],vis(100010,0),dis(100010,0),par(100010,0);
bool cmp(pair<ll,ll> p1,pair<ll,ll> p2)
{
    if(p1.ss>p2.ss)
        return true;
    else if(p1.ss==p2.ss&&p1.ff<p2.ff)
        return true;
    else
        return false;
        
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    int n,m;
    cin>>n>>m;
    vector<pair<ll,ll>> v;
    f(i,n)
    {
        int a,b;
        cin>>a>>b;
        v.pb({a,b});
    }
    sort(all(v),cmp);
    ll sum=0;
    set<ll> mt;
    for(int i=1;i<=m;i++)
    {
        mt.insert(i);
    }
    for(int i=0;i<n;i++)
    {
        auto itr=mt.lower_bound(v[i].ff);
        if(itr!=mt.end())
        {
            sum=sum+v[i].ss;
            mt.erase(itr);
        }
    }
    cout<<sum<<endl;
}


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

int main(void) {

	int i=0, count[4]={0};
	char c[3];
	
	while( scanf("%d, %s", &i, c) != EOF) {
		if(strcmp(c,"A")==0) count[0]++;
		else if(strcmp(c,"B")==0) count[1]++;
		else if(strcmp(c,"O")==0) count[3]++;
		else count[2]++;
	}
	for(i=0; i<4; i++)
		printf("%d\n", count[i]);
	
	return 0;
}

Measured memory_bytes: 596
using System;
class Qsort
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        long x = long.Parse(str[0]);
        long a = long.Parse(str[1]);

        if (x < a)
            Console.WriteLine(0);
        else
            Console.WriteLine(10);

    }


}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

void solve()
{
	ll n;
	cin>>n;
	ll ans=(n-1)*n/2;
	cout<<ans;

}
int main()
{


	int t;
	// cin>>t;
	t = 1;
	while (t--) solve();


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

#include <atcoder/convolution>
#include <atcoder/dsu>
#include <atcoder/fenwicktree>
#include <atcoder/lazysegtree>
#include <atcoder/math>
#include <atcoder/maxflow>
#include <atcoder/mincostflow>
#include <atcoder/modint>
#include <atcoder/scc>
#include <atcoder/segtree>
#include <atcoder/string>
#include <atcoder/twosat>

using namespace atcoder;
//typedef modint998244353 mint;

int main(){
  int N,D;
  cin>>N>>D;
  VI X(N),Y(N);
  rep(i,N) cin>>X[i]>>Y[i];
  two_sat ts(N);
  rep(i,N) rep(j,N){
    if(i>=j) continue;
    if(abs(X[i]-X[j])<D) ts.add_clause(i, false, j, false);
    if(abs(X[i]-Y[j])<D) ts.add_clause(i, false, j, true);
    if(abs(Y[i]-X[j])<D) ts.add_clause(i, true, j, false);
    if(abs(Y[i]-Y[j])<D) ts.add_clause(i, true, j, true);
  }
  if(!ts.satisfiable()){
    cout<<"No"<<endl;
    return 0;
  }
  auto ans=ts.answer();
  cout<<"Yes"<<endl;
  rep(i,N){
    if(ans[i]) cout<<X[i]<<endl;
    else cout<<Y[i]<<endl;
  }
}


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

using namespace std;

int map_h[1500];
int map_w[1500];
int hh[1500001];
int ww[1500001];

int main(){
    while(1){
        int h,w;
        cin >> h >> w;
        if(h+w == 0)break;
        for(int i = 0;i < h;i++)cin >> map_h[i];
        for(int i = 0;i < w;i++)cin >> map_w[i];
        int Max = 0;
        for(int i = 0;i <= 1500000;i++){
            hh[i] = 0;
            ww[i] = 0;
        }
        for(int i = 0;i < h;i++){
            int sum = 0;
            for(int j = i;j >= 0;j--){
                sum = sum + map_h[j];
                hh[sum]++;
            }
            Max = max(Max, sum);
        }
        for(int i = 0;i < w;i++){
            int sum = 0;
            for(int j = i;j >= 0;j--){
                sum = sum + map_w[j];
                ww[sum]++;
            }
            Max = max(Max, sum);
        }
        int ans = 0;
        for(int i = 0;i <= Max;i++){
            ans = ans + hh[i]*ww[i];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 12888
X, Y = gets.split("\s").map(&:to_f)
x = (4*X - Y) / 2.0
y = (Y - 2*X) / 2.0

print x % 1 == 0 && y % 1 == 0 && x >= 0 && y >= 0 ? 'Yes' : 'No'

Measured memory_bytes: 14352
#include<stdio.h>
int main(){
int a,b,i,N,K[100],P[100];
	scanf("%d",&N);
	
	for(i=0;i<N;i++){
		scanf("%d %d",&K[i],&P[i]);
	}
	
	for(a=0;a<N;a++){
		b=K[a]%P[a];
		if(b==0){
			b=P[a];
		}
		printf("%d\n",b);
	}
	
return 0;
}

Measured memory_bytes: 596
import Control.Applicative

data Dice = Dice { diceTop    :: String
                 , diceFront  :: String
                 , diceRight  :: String
                 , diceLeft   :: String
                 , diceBack   :: String
                 , diceBottom :: String
                 } deriving Show

makeDice :: [String] -> Dice
makeDice (t:f:r:l:b:bo:[]) = Dice t f r l b bo

diceToN :: Dice -> Dice
diceToN dice = dice { diceTop    = diceFront dice
                    , diceFront  = diceBottom dice
                    , diceBottom = diceBack dice
                    , diceBack   = diceTop dice
                    }

diceToS :: Dice -> Dice
diceToS dice = dice { diceTop    = diceBack dice
                    , diceFront  = diceTop dice
                    , diceBottom = diceFront dice
                    , diceBack   = diceBottom dice
                    }

diceToE :: Dice -> Dice
diceToE dice = dice { diceTop    = diceLeft dice
                    , diceLeft   = diceBottom dice
                    , diceBottom = diceRight dice
                    , diceRight  = diceTop dice
                    }

diceToW :: Dice -> Dice
diceToW dice = dice { diceTop    = diceRight dice
                    , diceLeft   = diceTop dice
                    , diceBottom = diceLeft dice
                    , diceRight  = diceBottom dice
                    }

diceMoveTo :: Char -> Dice -> Dice
diceMoveTo 'N' = diceToN
diceMoveTo 'S' = diceToS
diceMoveTo 'E' = diceToE
diceMoveTo 'W' = diceToW

diceMoves :: String -> Dice -> Dice
diceMoves []     dice = dice
diceMoves (s:ss) dice = diceMoves ss $ diceMoveTo s dice

diceMoveToTopFront :: String -> String -> Dice -> Dice
diceMoveToTopFront top front = moveToTop top . moveToFront front
  where
      moveToTop top dice
        | top == diceTop dice    = dice
        | top == diceBottom dice = diceMoves "EE" dice
        | top == diceLeft dice   = diceMoves "E"  dice
        | top == diceRight dice  = diceMoves "W"  dice
      moveToFront front dice
        | front == diceTop dice    = diceMoves "S"  dice
        | front == diceBottom dice = diceMoves "N"  dice
        | front == diceFront dice  = dice
        | front == diceBack dice   = diceMoves "NN" dice
        | front == diceLeft dice   = diceMoves "ES" dice
        | front == diceRight dice  = diceMoves "WS" dice


main :: IO ()
main = do
    labels <- words <$> getLine
    n <- getLine >>= return . (\n -> read n :: Int)

    doMoveDice n labels
  where
      doMoveDice 0 _ = return ()
      doMoveDice n labels = do
          [top, front] <- words <$> getLine
          putStrLn $ diceRight . diceMoveToTopFront top front $ makeDice labels
          doMoveDice (n - 1) labels



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

const int mod = 1000000007;

int N, K;
int a[110];

int dp[110][100010];

int main() {
    cin >> N >> K;
    for(int i = 0; i < N; i++)
        cin >> a[i];

    dp[0][0] = 1;
    for(int i = 0; i < N; i++) {
        // 累積和を取る
        int sum[100010];
        sum[0] = 0;
        for(int j = 0; j <= K; j++)
            sum[j + 1] = (sum[j] + dp[i][j]) % mod;

        for(int j = 0; j <= K; j++)
            // 負の mod に気を付ける
            dp[i + 1][j] = (sum[j + 1] - sum[max(0, j - a[i])] + mod) % mod;
    }

    cout << dp[N][K] << endl;

    return 0;
}

Measured memory_bytes: 41216
a,b = map(int, input().split() )


count = 0
for i in range(a, b + 1):
    l1 = i//10000
    l2 = (i//1000)%10
    r1 = i%10
    r2 = (i%100)//10

    b = l1==r1 and l2==r2
#    print((i,l1,l2,r2,r1,b))

    count += 1 if b else 0

print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	lint n,k;
	cin>>n>>k;
	cout<<min({n%k,abs(n%k-k),n})<<endl;
}

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

int main()
{
  string s, t;
  cin >> s >> t;
  int m = s.size(), n = t.size();

  vector<vector<int>> dp(m + 1, vector<int>(n + 1, 0));
  for (int i = 0; i < m; i++)
  {
    for (int j = 0; j < n; j++)
    {
      if (s[i] == t[j])
        dp[i + 1][j + 1] = dp[i][j] + 1;
      else
        dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
    }
  }

  string res = "";
  int i = m, j = n;
  while (i > 0 && j > 0)
  {
    if (dp[i][j] == dp[i - 1][j])
      i--;
    else if (dp[i][j] == dp[i][j - 1])
      j--;
    else
    {
      res = s[i - 1] + res;
      i--, j--;
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 38968
from decimal import Decimal
a, b, c =  map(lambda x : x**Decimal(0.5),map(Decimal, map(int, input().split())))
#print('Yes' if (c-a-b)>0 and 4*a*b < (c - a- b)**2 else 'No')
print('Yes' if a+b < c else 'No')

Measured memory_bytes: 5076
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int N,M,R;
int d[201][201];
int r[9];
int A,B,C;
int res;
bool used[9];


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a;
    cin>>n>>a;
    cout<<n*n-a<<endl;
}

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

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

int main(){

  int h,w,m;
  cin>>h>>w>>m;
  vector<map<int,int>> target(h);
  vector<int> row(h),col(w);
  rep(i,m){
    int hi,wi;
    cin>>hi>>wi;
    hi--;wi--;
    target[hi][wi] = 1;
    row[hi]++;
    col[wi]++;
  }

  vector<int> w_candidate,h_candidate;
  {
    int w_max = 0;
    rep(wi,w)
      w_max = max(w_max,col[wi]);
    rep(wi,w)
      if(col[wi]==w_max)
        w_candidate.emplace_back(wi);
  }
  {
    int h_max = 0;
    rep(hi,h)
      h_max = max(h_max,row[hi]);
    rep(hi,h)
      if(row[hi]==h_max)
        h_candidate.emplace_back(hi);
  }

  int ans = 0;
  for(int hi:h_candidate)for(int wi:w_candidate){
    if(target[hi].count(wi))
      ans = max(ans,row[hi]+col[wi]-1);
    else{
      ans = max(ans,row[hi]+col[wi]);
      goto loopend;
    }
  }
loopend:

  cout<<(ans)<<endl;

}

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

int main(){
    
    while(1){
        int x, y;
        cin >> x >> y;
        if( x == 0 && y == 0) break;
        if( x < y){
            cout << x << " " << y << endl;
        }else{
            cout << y << " " << x << endl;
        }
    }
    return 0;
}


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

int main() {
  string N;
  cin >> N;
  char a=N.at(0),b=N.at(1),c=N.at(2),d=N.at(3);
  if ((a == b && b == c && c == a)||(b == c && c == d && d == b)){
  cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
 }


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

int main(){
  int r,c,m;
  string grid[50];
  int cost[50][50],on[50][50],off[50][50];
  bool use[50][50];
  vector<pair<int,int> > route[50][50];
  vector<pair<int,int> > task;
  int y,x,prvy,prvx;

  cin >> r >> c >> m;

  for(int i=0;i<r;i++)cin >> grid[i];

  for(int i=0;i<r;i++){
    for(int j=0;j<c;j++)cin >> cost[i][j];
  }
  for(int i=0;i<r;i++){
    for(int j=0;j<c;j++)cin >> on[i][j];
  }
  for(int i=0;i<r;i++){
    for(int j=0;j<c;j++)cin >> off[i][j];
  }

  cin >> prvy >> prvx;
  task.push_back(make_pair(prvy,prvx));
  for(int i=1;i<m;i++){
    cin >> y >> x;

    for(int j=0;j<r;j++){
      for(int k=0;k<c;k++){
	use[j][k] = false;
	route[j][k].clear();
      }
    }

    queue<pair<int,int> > q;
    q.push(make_pair(prvy,prvx));
    use[prvy][prvx] = true;

    while(q.size()){
      pair<int,int> tmp;
      tmp = q.front();
      q.pop();
      int f = tmp.first,s = tmp.second;
      if(f==y && s==x)break;
      int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};

      for(int k=0;k<4;k++){
	int sy = f+dy[k], sx = s+dx[k];

	if(sy<0 || sx<0 || sy>=r || sx>=c)continue;
	if(use[sy][sx] || grid[sy][sx]=='#')continue;

	for(int l=0;l<(int)route[f][s].size();l++){
	  route[sy][sx].push_back(route[f][s][l]);
	}
	route[sy][sx].push_back(make_pair(sy,sx));
	use[sy][sx] = true;
	q.push(make_pair(sy,sx));
      }
    }
    for(int j=0;j<(int)route[y][x].size();j++)task.push_back(route[y][x][j]);
   
    prvy = y;prvx = x;
  }

  //for(int i=0;i<(int)task.size();i++)cout << task[i].first << " " << task[i].second << endl;

  vector<int> visit[50][50];
  for(int k=0;k<(int)task.size();k++)visit[task[k].first][task[k].second].push_back(k);

  int res = 0;

  for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
      if(visit[i][j].size())res += on[i][j] + off[i][j];

      for(int k=0;k<(int)visit[i][j].size();k++){
	if(k+1<(int)visit[i][j].size()){
	  if( (visit[i][j][k+1] - visit[i][j][k])*cost[i][j] < on[i][j] + off[i][j]){
	    res += (visit[i][j][k+1] - visit[i][j][k])*cost[i][j];
	  }else{
	    res += on[i][j] + off[i][j];
	  }
	}
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 28000
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <time.h>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}


struct UnionFind {
	vector<int> par, rank, cnt;
	UnionFind(int n) : par(n), rank(n, 0), cnt(n, 1){
		for(int i=0; i<n; ++i) par[i] = i;
	}
 
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
 
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
 
		if (rank[x] < rank[y]) swap(x, y);
 
		par[y] = x;
		cnt[x] += cnt[y];
		if (rank[x] == rank[y]) rank[x]++;
	}
 
	bool same(int x, int y) {
		return find(x) == find(y);
	}
 
	int size(int x) {
		return cnt[find(x)];
	}
};


int main(){
    long long N,M; cin >> N >> M;
    vector<long long> a(M),b(M);
    for (int i = 0; i < M; i++){
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }
    UnionFind uf(N);

    long long num = N*(N-1)/2;
    vector<long long> ans(M);
    for (int i = M-1; i >= 0; i--){
        ans[i] = num;
        if (!uf.same(a[i],b[i])){
            num -= (long long)uf.size(a[i])*(long long)uf.size(b[i]);
            uf.unite(a[i],b[i]);
        }
    }
    for (auto i : ans){
        cout << i << endl;
    }
}

Measured memory_bytes: 4864
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n, m; cin >> n >> m;
    vector<int> s(m), c(m);
    rep(i, m) {
        cin >> s[i] >> c[i];
    }
    for(int x = 0; x <= 999; ++x) {
        int cnt = 0;
        int x_ = x;
        while(x_ != 0) {
            ++cnt;
            x_ /= 10;
        }
        if(x == 0) cnt = 1;
        if(cnt != n) continue;
        bool check = true;
        rep(i, m) {
            if(cnt == 3) {
                if(s[i] == 1) {
                    int k = x / 100;
                    if(k != c[i]) check = 0;
                } else if(s[i] == 2) {
                    int k = x % 100;
                    k /= 10;
                    if(k != c[i]) check = 0;
                } else {
                    int k = x % 10;
                    if(k != c[i]) check = 0;
                }
            } else if(cnt == 2) {
                if(s[i] == 1) {
                    int k = x / 10;
                    if(k != c[i]) check = 0;
                } else if(s[i] == 2) {
                    int k = x % 10;
                    if(k != c[i]) check = 0;
                }
            } else {
                if(s[i] == 1) {
                    int k = x;
                    if(k != c[i]) check = 0;
                }
            }
        }
        if(check) {
            cout << x << endl;
            return;
        }
    }
    cout << -1 << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

#define rep(i,n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar,val) memset(ar, val, sizeof(ar))
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
  ll n = 0, k = 0, ans = 0, a = 0, b = 0, c = 0;
  cin >> n >> k >> a >> b;
  cout << (n - a) * (k - b) << endl;
  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm> 
#include<cstring>
#define ll long long
using namespace std;
int n,a,single,four; 
int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		a=read();
		if(a%2==1)single++;
		if(a%4==0)four++;
	}
	if(single<=four||(single==four+1&&single+four==n))printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');

            int[] a = new int[3];
            for (int i = 0; i < 3; i++)
            {
                a[i] = int.Parse(str[i]);
            }
            Array.Sort(a);

            int ans = a[2] - a[0];

            Console.WriteLine("{0}", ans);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    string S;
    cin >> S;
    vector<string> A = {"KIHBR","KIHBRA","KIHBAR","KIHABR","AKIHBR","KIHBARA","KIHABRA"
                        ,"KIHABAR","AKIHBRA","AKIHABRA","AKIHBAR", "AKIHABAR", "AKIHABRA"
                        ,"AKIHBARA","KIHABARA","AKIHABARA"};
    for (int i = 0; i < 16; i++){
        if (A.at(i) == S){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#define ll long long

using namespace std;

int main() {
	string str;
	ll k;
	cin >> str;
	cin >> k;
	string tmp_str = "abcdefghijklmnopqrstuvwxyz";
	unordered_map<char, ll> um;
	for (ll i = 0; i < tmp_str.size(); ++i)
	{
		um[tmp_str[i]] = i;
	}
	for (ll i = 0; i < str.size(); ++i)
	{
		if(str[i] == 'a') continue;
		if(26 - um[str[i]] <= k){
			k -= 26 - um[str[i]];
			str[i] = 'a';
		}

	}
	int last_id = um[str[str.size() - 1]];
	str[str.size() - 1] = tmp_str[(last_id + k) % 26 ] ;
	cout << str << endl;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


int main()
{
	int n, m, a;
	while (cin >> n >> m >> a, n | m | a)
	{
		vector<int> p[1024], q[1024];
		while (m--)
		{
			int h, pp, qq;
			cin >> h >> pp >> qq;
			p[h].push_back(pp);
			q[h].push_back(qq);
		}

		for (int i = 1000; i > 0; --i)
		{
			for (int j = 0; j < p[i].size(); ++j)
			{
				if (a == p[i][j])
				{
					a = q[i][j];
					break;
				}
				else if (a == q[i][j])
				{
					a = p[i][j];
					break;
				}
			}
		}

		cout << a << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+5;
int a[MAXN],dp[MAXN];
vector<int> sv[MAXN];
bool cmp(int a,int b)
{
	return a>b;
}
void dfs(int now)
{
	if(sv[now].size()==0)
	{
		return ;
	}
	vector<int> tmp;
	for(int i=0;i<sv[now].size();i++)
	{
		dfs(sv[now][i]);
		tmp.push_back(dp[sv[now][i]]+1);
	}
	sort(tmp.begin(),tmp.end(),cmp);
	for(int i=0;i<tmp.size();i++)
	{
		dp[now]=max(dp[now],tmp[i]+i);
	}
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int n,ans=0;
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sv[a[i]].push_back(i);
	}
	dfs(1);
	printf("%d\n",dp[1]);
	return 0;
}

Measured memory_bytes: 15872
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define it vector<int>::iterator 
bool next_combination ( it first1 ,
  it last1 ,
  it first2 ,
  it last2 ){
  if (( first1 == last1 ) || ( first2 == last2 )) {
    return false ;
  }
  it m1 = last1 ;
  it m2 = last2 ; --m2;
  while (--m1 != first1 && !(*m1 < *m2 )){
  }
  bool result = (m1 == first1 ) && !(*first1 < *m2 );
  if (! result ) {
    while ( first2 != m2 && !(*m1 < *first2 )) {
      ++ first2 ;
    }
    first1 = m1;
    std :: iter_swap (first1 , first2 );
    ++ first1 ;
    ++ first2 ;
  }
  if (( first1 != last1 ) && ( first2 != last2 )) {
    m1 = last1 ; m2 = first2 ;
    while (( m1 != first1 ) && (m2 != last2 )) {
      std :: iter_swap (--m1 , m2 );
      ++ m2;
    }
    std :: reverse (first1 , m1 );
    std :: reverse (first1 , last1 );
    std :: reverse (m2 , last2 );
    std :: reverse (first2 , last2 );
  }
  return ! result ;
}
bool next_combination(it first,it middle,it last){
  return next_combination (first , middle , middle , last );
}
int main(){
	int m,n;
	cin>>n>>m;
	vector<vector<double> > in(n,vector<double>(3));
	rep(i,n)rep(j,3)cin>>in[i][j];
	double out=0;
	vi t(n);
	rep(i,n)t[i]=i;
	do{
		double sum=0;
		rep(i,m)loop(j,i+1,m)rep(k,3)sum+=(in[t[i]][k]-in[t[j]][k])*(in[t[i]][k]-in[t[j]][k]);		
		if(sum>out)out=sum;
	}while(next_combination(t.begin(),t.begin()+m,t.end()));
	printf("%.8f\n",out);
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(std::string b){
    if(b[0] == 'A') cout << "T" << endl;
    if(b[0] == 'C') cout << "G" << endl;
    if(b[0] == 'G') cout << "C" << endl;
    if(b[0] == 'T') cout << "A" << endl;
}

int main(){

    std::string b;
    std::cin >> b;
    solve(b);
    return 0;
}



Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
const int MAXN = 1e5 + 5; 
int N,M,a[MAXN],b[MAXN],p[MAXN]; 
int pa[MAXN]; 
int getf(int x) { while (x != pa[x]) x = pa[x] = pa[pa[x]]; return x; } 
vector<int> G[MAXN]; 
long long f[MAXN], sum[MAXN];
bool vis[MAXN]; 
int main () { 
	N = read(), M = read();
	for (int i = 1; i <= N; i++) { 
		a[i] = read(), b[i] = read(); 
		a[i] = max(a[i] - b[i], 0);
		p[i] = i, pa[i] = i; 
	} 
	sort(&p[1], &p[N + 1], [](const int &l, const int &r) { return a[l] < a[r]; } ); 
	for (int i = 1; i <= M; i++) { 
		int u = read(), v = read(); 
		G[u].push_back(v), G[v].push_back(u); 
	} 
	for (int i = 1; i <= N; i++) { 
		vector<int> son;
		int x = p[i]; 
		vis[x] = 1, sum[x] = b[x]; 
		for (auto v : G[x]) {
			if (!vis[v] || getf(x) == getf(v)) continue; 
			son.push_back(getf(v)); 
			sum[x] += sum[getf(v)]; 
			pa[getf(v)] = x; 
		} 
		f[x] = sum[x] + a[x]; 
		for (auto v : son) f[x] = min(f[x], sum[x] - sum[v] + max(1ll * a[x], f[v])); 
	} 
	printf("%lld\n", f[p[N]]); 
    return 0; 
} 

Measured memory_bytes: 12616
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	single_source_shortest_path
# CreatedDate:  2020-06-08 21:54:58 +0900
# LastModified: 2020-06-08 22:28:47 +0900
#


import os
import sys
from collections import deque
#import numpy as np
#import pandas as pd


def main():
    n = int(input())
    graph = [[] for _ in range(n)]
    for _ in range(n):
        line = list(map(int,input().split()))
        u,k = line[0],line[1]
        path = line[2:]
        for i in range(0,2*k,2):
            graph[u].append([path[i+1],path[i]])
    
#    print(graph)
    s=0
    distance=[-1]*n
    Q = deque([s])
    distance[0]=0
    

    while Q:
        u = Q.popleft()
        for dis,v in graph[u]:
            if distance[v]==-1:
                distance[v]=distance[u]+dis
                Q.append(v)

            if distance[v]>distance[u]+dis:
                distance[v]=distance[u]+dis
                Q.append(v)
            


    for i,dis in enumerate(distance):
        print(i,dis)


if __name__ == "__main__":
    main()



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

int main(){
  string s;
  cin >> s;
  while(s!=""){
    s.erase(s.end()-1);
    s.erase(s.end()-1);
    int it=s.length()/2;
    if(s.substr(0,it)==s.substr(it)) break;
  }
  cout << s.length() << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#define chmax(x, y) if(x < y) x = y
using namespace std;
using ll = int64_t;
using P = pair<int, int>;

constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};

int main(){
    int h, w; cin >> h >> w;
    char map[h][w];
    rep(i, h)rep(j, w) cin >> map[i][j];

    bool vis[h][w];
    int d[h][w];

    int ans = -1;
    rep(i, h)rep(j, w){
        if(map[i][j] == '#') continue;
        memset(vis, 0, sizeof(vis));
        memset(d, 0, sizeof(d));
        queue<P> q;
        vis[i][j] = true;
        d[i][j] = 0;
        q.push({i, j});
        while(q.size()){
            P now = q.front(); q.pop();
            rep(k, 4){
                int ni = now.first + di[k], nj = now.second + dj[k];
                if(0 <= ni && ni < h && 0 <= nj && nj < w && !vis[ni][nj] && map[ni][nj] == '.'){
                    d[ni][nj] = d[now.first][now.second] + 1;
                    vis[ni][nj] = true;
                    q.push({ni, nj});
                }
            }
        }
        rep(i, h)rep(j, w) chmax(ans, d[i][j]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    from collections import deque
    S = deque(readline().strip().decode())
    Q = int(readline())
    Query = readlines()
    rev_flg = False
    for q in Query:
        if q[0] == ord('1'):
            rev_flg = not rev_flg
        else:
            _, f, c = q.decode().split()
            if int(f)-(rev_flg) == 1:
                S.appendleft(c)
            else:
                S.append(c)
    S = ''.join(S)
    if rev_flg is True:
        S = S[::-1]
    print(S)

    return
if __name__ == '__main__':
    main()



Measured memory_bytes: 17888
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S;
	cin >> S;
	string a = S.substr(0,3);
	int b = stoi(a);
	int c = abs(b-753);
	for (int i = 0; i < S.size()-2; i++){
		string A = S.substr(i,3);
		int B = stoi(A);
		int C = abs(B-753);
		c = min(c,C);
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;


template <typename T>using ordered_set = tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;

#define PI              acos(-1.0)
#define en '\n'
#define Infi 0x3f3f3f3f
#define LInfi 0x3f3f3f3f3f3f3f3f



#define READ_IN freopen("Input.txt","r",stdin);
#define READ_OUT freopen("Output.txt","w",stdout);


const int dx[] = {+1,-1,+0,+0};                         // 4 X directions
const int dy[] = {+0,+0,+1,-1};                         // 4 Y directions
const int dx8[] = {+0,+0,+1,-1,-1,+1,-1,+1};            // King X Moves
const int dy8[] = {-1,+1,+0,+0,+1,+1,-1,-1};            // King Y Moves
const int kx[] = {-2, -2, -1, -1,  1,  1,  2,  2};      // Knight X Moves
const int ky[] = {-1,  1, -2,  2, -2,  2, -1,  1};      // Knight Y Moves



int  Set    (int N,int pos) {return N=N | (1<<pos);}    /// turn a bit on
int  reset  (int N,int pos) {return N= N & ~(1<<pos);}  /// turn a bit off
bool check  (int N,int pos) {return (bool)(N & (1<<pos));} /// check, if a bit is on or not

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define trace(x...)
#endif

typedef long long int  ll;
typedef unsigned long long int llu;

vector<int> weight;
vector<int> cost;

llu dp[102][100005];

llu knap(int id,int w){

    if(w==0)return 0;
    if(id==cost.size()){
       return 0;
    }

    if(dp[id][w]!=LInfi)return dp[id][w];

    llu p1;

    bool bol = false;

    if(w-weight[id]>=0){
    p1 = cost[id] + knap(id+1,w-weight[id]);
    bol = true;

    }

    llu p2 = knap(id+1,w);

    if(bol)
    return dp[id][w] = max(p1,p2);
    else
        return dp[id][w] = p2;
}


int main(void){

    int N,W;

    cin >> N >> W;

    for(int i=0;i<N;i++){
        int w,c;
        cin >> w >> c;

        weight.push_back(w);
        cost.push_back(c);
    }
    memset(dp,LInfi,sizeof(dp));

   cout << knap(0,W) << endl;


    return 0;
}


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

int main()
 {
    string s,t;
    cin>>s>>t;
    int n = s.size();
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]!=t[i])
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;
}








Measured memory_bytes: 3844
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 7;

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};


/////////////////////////////////////////////////////////////////////////////////////////
int main(){
    int MAX = 2*1e5+1;
    string s,t;
    cin >> s >> t;
    map<char,char> tot,tos;

    bool ans = true;
    for (int i = 0;i < s.size();i++){
        if (tot.count(s[i]) == 0){
            tot[s[i]] = t[i];
        }
        else {
            if (tot[s[i]] != t[i]){
                ans = false;
            }
        }

        if (tos.count(t[i]) == 0){
            tos[t[i]] = s[i];
        }
        else {
            if (tos[t[i]] != s[i]){
                ans = false;
            }
        } 
    }

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;

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

   vector<pair<int,int>> z(n);

   rep(i,n){
      cin>>z[i].first>>z[i].second;
   }
   sort(z.begin(),z.end());
   double ans=0.0;
   int count=0;

   do{
      int a=0,b=0,c=0,d=0;
      rep(i,n-1){
         a=z[i].first;
         c=z[i].second;
         b=z[i+1].first;
         d=z[i+1].second;
         ans+=sqrt(pow(a-b,2.0)+pow(c-d,2.0));
      }
      count++;
   }while(next_permutation(z.begin(),z.end()));

   ans/=count;
   cout<<setprecision(10)<<ans<<endl;



return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <map>
using namespace std;
int main(){
    int a[6],q,l,r,ans;
    map<int,int> m;
    for(int i=0;i<6;i++){
        scanf("%d",&a[i]);
        m.insert({a[i],i});
    }
    scanf("%d",&q);
    while(q--){
        scanf("%d%d",&l,&r);
        l=m[l];
        r=m[r];
        if(l==0){
            if(r==1)ans=2;
            else if(r==2)ans=4;
            else if(r==3)ans=1;
            else ans=3;
        }
        else if(l==1){
            if(r==0)ans=3;
            else if(r==2)ans=0;
            else if(r==3)ans=5;
            else ans=2;
        }
        else if(l==2){
            if(r==0)ans=1;
            else if(r==1)ans=5;
            else if(r==4)ans=0;
            else ans=4;
        }
        else if(l==3){
            if(r==0)ans=4;
            else if(r==1)ans=0;
            else if(r==5)ans=1;
            else ans=5;
        }
        else if(l==4){
            if(r==0)ans=2;
            else if(r==2)ans=5;
            else if(r==3)ans=0;
            else ans=3;
        }
        else {
            if(r==1)ans=3;
            else if(r==2)ans=1;
            else if(r==3)ans=4;
            else ans=2;
        }
        printf("%d\n",a[ans]);
    }
}


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

int main() {
  int n;
  cin >> n;
  
  vector<int> v(n);
  
  for (int i = 0; i < n; i++)
    cin >> v.at(i);
  
  long long h = 0;
  
  for (int i = 0; i < n - 1; i++) {
    if (v.at(i) > v.at(i + 1)) {
      h += v.at(i) - v.at(i + 1);
      v.at(i + 1) = v.at(i);
    }
  }
  
  cout << h << endl;
  
}
      

Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	vector< pair< int,int > > stu;
	vector< pair< int,int > > chk;
	for(int i=1;i<=n;i++){
		int a,b;
		cin>>a>>b;
		stu.push_back(make_pair(a,b));
	}

	for(int i=1;i<=m;i++){
		int a,b;
		cin>>a>>b;
		chk.push_back(make_pair(a,b));
	}

	for(int i=0;i<n;i++){
		int ans,minn=10e8+1;
		for(int j=0;j<m;j++){
			int temp=abs(stu[i].first-chk[j].first)+abs(stu[i].second-chk[j].second);
			if(temp<minn){
				minn=min(minn,temp);
				ans=j+1;
			}
		}
		cout<<ans<<"\n";
	}
}

Measured memory_bytes: 256
N,M = map(int,input().split())
switch = [0]*N
for m in range(M):
    ss = list(map(int, input().split()))[1:]
    for s in ss:
        switch[s-1] |= 2**m
li = 0
for index,p in enumerate(list(map(int, input().split()))):
    if p==1: li += 2**index
answer = 0
for n in range(2**N):
    l = 0
    for s in range(N):
        if (n>>s)&1: l^=switch[s]
    if li==l: answer+=1
print(answer)

Measured memory_bytes: 3064
n = int(input())
a = list(map(int,input().split()))
col = [0]*8
over_cnt = 0
cnt_min = 0
cnt_max = 0
for i in range(n):
	if a[i] < 3200:
		col[(a[i])//400] += 1
		#print(col)
	else:
		over_cnt += 1
for j in range(8):
	#print(j)
	if col[j] > 0:
		cnt_min += 1
if cnt_min == 0:
	cnt_min = 1
	cnt_max = over_cnt
else:
	cnt_max = cnt_min+over_cnt
print(cnt_min,cnt_max)

Measured memory_bytes: 9196
#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define INF 1e9 + 1
#define MAX 10000
#define NIL -1
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

int n;
struct Node {
    int p, l, r;
};
struct Node T[MAX];

// preorder(先行順巡回)
void preParse(int u) {
    if (u == NIL) return;
    cout << " " << u;
    preParse(T[u].l);
    preParse(T[u].r);
}

// inorder(中間順巡回)
void inParse(int u) {
    if (u == NIL) return;
    inParse(T[u].l);
    cout << " " << u;
    inParse(T[u].r);
}

// postorder(後方順巡回)
void postParse(int u) {
    if (u == NIL) return;
    postParse(T[u].l);
    postParse(T[u].r);
    cout << " " << u;
}

int main() {
    int v, l, r, root;
    cin >> n;
    REP(i, n) T[i].p = NIL;

    REP(i, n) {
        cin >> v >> l >> r;
        T[v].l = l;
        T[v].r = r;
        if (l != NIL) T[l].p = v;
        if (r != NIL) T[r].p = v;
    }

    REP(i, n) {
        if (T[i].p == NIL) root = i;
    }

    cout << "Preorder" << endl;
    preParse(root);
    cout << endl;

    cout << "Inorder" << endl;
    inParse(root);
    cout << endl;

    cout << "Postorder" << endl;
    postParse(root);
    cout << endl;
}


Measured memory_bytes: 3096