akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <cassert>
#include <queue>
#include <climits>
#include <algorithm>

using namespace std;

struct edge {
  int t;
  long long c;
  edge(){}
  edge(int t,long long c):t(t),c(c){}
};

struct state {
  int n;
  long long c;
  state(){}
  state(int n,long long c):n(n),c(c){}
  bool operator>(const state& e)const{
    return c>e.c;
  }
};

vector<edge> g[111111];
int h[111111];
long long cost[111111];

int main(void)
{
  int n,m;
  long long x;
  scanf("%d%d%lld",&n,&m,&x);
  for( int i = 0; i < n; i++ ) {
    scanf("%d",h+i);
  }
  for( int i = 0; i < m; i++ ) {
    int f,t,c; scanf("%d%d%d",&f,&t,&c); --f; --t;
    if( h[f] >= c ) {
      g[f].push_back(edge(t,c));
    }
    if( h[t] >= c ) {
      g[t].push_back(edge(f,c));
    }
  }
  priority_queue<state,vector<state>,greater<state> > q;
  q.push(state(0,0));
  for( int i = 0; i < n; i++ ) cost[i] = LLONG_MAX;
  cost[0] = 0;
  long long res = LLONG_MAX;
  while( !q.empty() ) {
    state p = q.top(); q.pop();
    //printf("%d %d %d\n",p.n,p.c,p.x);
    if( p.c >= x ) {
      //assert(p.x == 0);
    }
    //if( cost[p.n] < p.c ) continue;
    if( p.n == n-1 ) {
      if( p.c <= x ) {
        res = min(res,p.c+h[p.n]-(x-p.c));
      } else {
        res = min(res,p.c+h[p.n]);
      }
      //printf("%lld\n",p.c+h[p.n]-p.x);
      continue;
    }
    for( int i = 0; i < int(g[p.n].size()); i++ ) {
      edge& e = g[p.n][i];
      long long c = p.c+e.c;
      //printf("%d %d\n",p.c,e.c*2);
      if( p.c <= x ) {
        int now = x-p.c;
        if( now-e.c > h[e.t] ) {
          //printf("%d %d %d %d\n",c,now,e.c,h[e.t]);
          c += now-e.c-h[e.t];
        } else if( now-e.c >= 0 ) {
        } else if( now - e.c < 0 ) {
          c += e.c-now;
        }
      } else {
        c += e.c;
      }
      if( cost[e.t] > c ) {
        cost[e.t] = c;
        q.push(state(e.t,c));
      }
    }
  }
  if( res == LLONG_MAX ) puts("-1");
  else printf("%lld\n",res);
  return 0;
}

Measured memory_bytes: 20780
<?php

$args = [];
$input = explode(' ', trim(fgets(STDIN)));

$expend = (int)$input[0];
$count = (int)$input[1];

while(true){
	$input = explode(' ', trim(fgets(STDIN)));
	foreach ($input as $value) {
		if ($value !== '') {
			$args[] = $value;
		}
		if (count($args) >= $count) {
			break;
		}
	}
	if (count($args) >= $count) {
		break;
	}
}
sort($args);
$c = count($args);

while (true) {
	$str = (string)$expend;
	$flg = true;
	for ($i=0; $i < $c; $i++) { 
		if (strpos($str, $args[$i]) === false) {
			continue;
		}else{
			$flg = false;
			$expend = $expend + 1;
			break;
		}
	}
	if ($flg) {
		break;
	}
}
echo $expend;

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;
    string S;
    cin >> S;

    Vi stats(N, -1);
    bool ok = false;

    constexpr ll edges[][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};

    for (ll idx = 0; idx < 4; idx++) {
        stats.assign(N, -1);
        stats[0] = edges[idx][0], stats[N - 1] = edges[idx][1];
        for (ll i = 0; i < N - 1; i++) {
            ll left = i - 1, right = i + 1;
            if (left < 0) left = N - 1;
            if (right >= N) right = 0;
            if (stats[i] == 0) {
                if (S[i] == 'o') {
                    stats[right] = stats[left];
                }
                else {
                    stats[right] = 1 - stats[left];
                }
            }
            else {
                if (S[i] == 'o') {
                    stats[right] = 1 - stats[left];
                }
                else {
                    stats[right] = stats[left];
                }
            }
        }

        if (stats[N - 1] == edges[idx][1]) {
            if (S[N - 1] == 'o') {
                if (stats[N - 1] == 0) {
                    if (stats[N - 2] == stats[0]) ok = true;
                }
                else {
                    if (stats[N - 2] != stats[0]) ok = true;
                }
            }
            else {
                if (stats[N - 1] == 0) {
                    if (stats[N - 2] != stats[0]) ok = true;
                }
                else {
                    if (stats[N - 2] == stats[0]) ok = true;
                }
            }
        }

        if (ok) {
            break;
        }
    }

    if (ok) {
        for (ll i = 0; i < N; i++) {
            cout << (stats[i] == 0 ? 'S' : 'W');
        }
        cout << "\n";
    }
    else {
        cout << -1 << "\n";
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 976
H, W = map(int, input().split())
a = [list(map(int, input().split())) for i in range(H)]

ans = []

for i in range(H-1):
    for j in range(W):
        if a[i][j] % 2:
            a[i][j] -= 1
            a[i+1][j] += 1
            ans.append((i+1, j+1, i+2, j+1))

for i in range(W-1):
    if a[-1][i] % 2:
        a[-1][i] -= 1
        a[-1][i+1] += 1
        ans.append((H, i+1, H, i+2))

print(len(ans))
for row in ans:
    print(*row)

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

int main() {
  int N, K;
  cin >> N >>K;
  
  int sum = 0;
  for( int i=0; i<N; i++ ){
    int x;
    cin >> x;
    
    if( x < (K - x) ){
      sum += 2 * x;
    }
    else{
      sum += 2 * (K - x);
    }
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main() {
   int x, y, A = 0, B = 0;
   int a[7] = {1, 3, 5, 7, 8, 10, 12};
   int b[4] = {4, 6, 9, 11};
   cin >> x >> y;
   if (x == y) {
       cout << "Yes" << endl;
       return 0;
   }
   for (int i = 0; i < 7; i++) {
       if(x == a[i]){
           A++;
       }
       if(y == a[i]){
           A++;
       }
   }
   for (int i = 0; i < 4; i++) {
       if(x == b[i]){
           B++;
       }
       if(y == b[i]){
           B++;
       }
   }
   if (A == 2 || B == 2) {
       cout << "Yes" << endl;
   } else {
       cout << "No" << endl;
   }
   return 0;
}

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

using namespace std;

typedef pair<int, int> P;

P p[1000];
int w[1000], s[1000], v[1000];
long dp[1001][20001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> w[i] >> s[i] >> v[i];
        p[i] = P(s[i]+w[i], i);
    }
    sort(p, p+N);
    long ans = 0;
    for(int j = 1; j <= 20000; j++){
        dp[0][j] = -100000000000000;
    }
    for(int i = 0; i < N; i++){
        int idx = p[i].second;
        //cout << s[idx] << ' ' << w[idx] << endl;
        for(int j = 0; j <= 20000; j++){
            dp[i+1][j] = dp[i][j];
        }
        for(int j = 0; j <= s[idx]; j++){
            dp[i+1][j+w[idx]] = max(dp[i+1][j+w[idx]], dp[i][j]+v[idx]);
            ans = max(ans, dp[i+1][j+w[idx]]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 156800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    ll N,a,b,M=0;
    vector<ll> A,B,As(214514,0),Bs(214514,0);
    
    cin >> N;
    REP(i,N){cin >> a;M=max(M,a+1);A.push_back(a);As[a]++;}
    REP(i,N){cin >> b;M=max(M,b+1);B.push_back(b);Bs[b]++;}
    
    REP(i,M){
        if(As[i]+Bs[i]>N){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    
    
    reverse(B.begin(),B.end());
    
    //この時点でかぶってるのは一つの区間のみ
    ll T=-1;
    REP(i,N){
        if(A[i]==B[i]){
            T=A[i];
            break;
        }
    }
    
    //かぶりがないのでオワオワリ
    if(T==-1){
        REP(i,N){
            cout << B[i];
            if(i==N-1){cout << endl;}else{cout << " ";}
        }
        return 0;
    }
    
    
    //以降かぶりがある
    //Bのかぶりを先頭にうつしちゃう
    ll ib=0;
    REP(i,N){
        if(A[i]==B[i]){
            swap(B[ib],B[i]);
            ib++;
        }
    }
    
    //REP(i,N){cout << B[i] << " ";}cout << Endl;
    
    ll ia=N-1;
    REP(i,N){
        if(A[i]==B[i]){
            swap(A[ia],A[i]);
            ia--;
        }
    }
    
    vector<pair<ll,ll>> Ans;
    REP(i,N){
        Ans.push_back({A[i],B[i]});
        if(A[i]==B[i]){
            assert(false);
        }
    }
    sort(Ans.begin(),Ans.end());
    
    REP(i,N){
        cout << Ans[i].second;
        if(i==N-1){cout << endl;}else{cout << " ";}
    }
    
    
    return 0;
}



Measured memory_bytes: 13916
#include <stdio.h>
int main(){
	int H, W, i, j;
	for(;;){
        	scanf("%d %d",&H ,&W);
        	if(H == 0  && W == 0)break ;
        	for ( i = 0; i < H; i++ ){
        		for ( j = 0; j < W; j++ ){
        			if( i==0 || i==H-1 || j==0 || j==W-1){
        				printf("#");
        			} else {
        				printf(".");
        			}           
        		}
        		printf("\n");
        	}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

int main(){
    int p,q,r;
    cin>>p>>q>>r;
    int ans=p+q+r;
    if(p>=q&&p>=r)ans-=p;
    else if(q>=r)ans-=q;
    else ans-=r;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 105
#define PI 3.141592653589793
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)
#define mem(x, a) memset(x, a, sizeof x)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcl pair<char, ll>
#define psl pair<string, ll>


ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
map<ll, char> mp;
set<char> s;
string S = "";
ll cases;

int main() {
	go;
    cin >> N;
    ll cnt = 0;
    fi(i, 1, 400, 1) {
    	mp[i] = 'h';
    }
    fi(i, 400, 800, 1) {
    	mp[i] = 'i';
    }
    fi(i, 800, 1200, 1) {
    	mp[i] = 'j';
    }
    fi(i, 1200, 1600, 1) {
    	mp[i] = 'k';
    }
    fi(i, 1600, 2000, 1) {
    	mp[i] = 'd';
    }
    fi(i, 2000, 2400, 1) {
    	mp[i] = 'e';
    }
    fi(i, 2400, 2800, 1) {
    	mp[i] = 'f';
    }
    fi(i, 2800, 3200, 1) {
    	mp[i] = 'g';
    }
    fi(i, 0, N, 1) {
    	cin >> arr[i];
    	if(arr[i] < 3200) {
    		s.insert(mp[arr[i]]);
    	}
    	else {
    		cnt++;
    	}
    }
    ll sz = s.size();
    // trace2(sz, cnt);
    ll ans = sz + cnt;
   	ll ans1 = max(1ll, sz);
    cout << ans1 << " " << ans << "\n";

	return 0;
}
/*
	Powered by Buggy Plugin
*/




Measured memory_bytes: 3808
#include <algorithm>
#include <iostream>
#include <string>

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

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))
#define each(i, map) for (auto& i : map)

int main()
{
    long long N; cin >> N;
    const int digits = 26;
    const string chars = "Xabcdefghijklmnopqrstuvwxyz";

    string ans = "";
    while (true) {
        long long x = N % digits;

        // 余りが0の場合：つまりzの場合、26
        if (x == 0) {
            x = 26;
        }
        ans += chars[x];

        // xを引いて、26で割る
        N -= x;

        // 0なら終了
        if (N == 0) break;

        N /= digits;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 3572
def main():
    N, T = (int(x) for x in input().split())
    c=None
    for i in range(N):
        c_tmp, t_tmp = (int(x) for x in input().split())
        if t_tmp<=T:
            if c is None or c_tmp<c:
                c=c_tmp

    if c is None:
        print('TLE')
    else:
        print(c)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
module Main where

import           Control.Monad

main :: IO ()
main = do
    [h, _] <- (map read . words) <$> getLine :: IO [Int]
    list   <- map (map read . words) <$> (replicateM h) getLine :: IO [[Int]]
    let res1    = (map goRight . enumerate2d) list
    let list2   = (map snd) res1
    let result1 = (concatMap fst) res1
    let res2    = (goRight . map last) list2
    let result2 = fst res2
    let result  = concat [result1, result2]

    putStr
        $ (unlines . (((show . length) result) :) . map
              (unwords . (\((a, b), (c, d)) -> (map show) [a, b, c, d]))
          )
              result

    return ()
goRight
    :: [((Int, Int), Int)] -> ([((Int, Int), (Int, Int))], [((Int, Int), Int)])
goRight []  = ([], [])
goRight [x] = ([], [x])
goRight (a@(aPoint, aValue) : b@(bPoint, _) : xs) = if even aValue
    then mapSnd (a :) (goRight (b : xs))
    else
        let (resMove, resMap) = goRight (mapSnd (+ 1) b : xs)
        in  ((aPoint, bPoint) : resMove, mapSnd (subtract 1) a : resMap)

enumerate :: [a] -> [(Int, a)]
enumerate = zip [1 ..]

enumerate2d :: [[a]] -> [[((Int, Int), a)]]
enumerate2d =
    (map (\(y, a) -> (map (\(x, b) -> ((y, x), b)) . enumerate) a) . enumerate)

mapTuple :: (t1 -> a) -> (t2 -> b) -> (t1, t2) -> (a, b)
mapTuple f1 f2 (a, b) = (f1 a, f2 b)

mapFst :: (t1 -> a) -> (t1, b) -> (a, b)
mapFst = flip mapTuple id

mapSnd :: (t2 -> b) -> (a, t2) -> (a, b)
mapSnd = mapTuple id


Measured memory_bytes: 63100
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
int main(void){
   int N,H,W;
   cin>>N>>H>>W;
   int ans=(N-H+1)*(N-W+1);
   cout<<ans;
   return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;

    std::array<int, 8> dy{ -1, -1, -1, 0, 0, 1, 1, 1 };
    std::array<int, 8> dx{ -1, 0, 1, -1, 1, -1, 0, 1 };

    vector<string> table(h);
    for (auto& row : table)
    {
        cin >> row;
    }
    for (int y = 0; y < h; y++)
    {
        for (int x = 0; x < w; x++)
        {
            if (table[y][x] == '#')
            {
                cout << '#';
            }
            else
            {
                int count = 0;
                for (int i = 0; i < 8; i++)
                {
                    const int ny = y + dy[i];
                    const int nx = x + dx[i];
                    if (0 <= ny && ny < h && 0 <= nx && nx < w && table[ny][nx] == '#')
                    {
                        count++;
                    }
                }
                cout << count;
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

dp = [0] * (M+1)
for i, s in enumerate(S):
    dp2 = dp[:]
    for j, t in enumerate(T):
        dp2[j+1] += dp2[j] - dp[j]
        if s == t:
            dp2[j+1] += dp[j] + 1
    dp = dp2

print((dp[M]+1) % 1000000007)


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

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
int character_count(string text, char character){ int ans = 0; for(int i = 0; i < text.size(); i++){ ans += (text[i] == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class itr, class func> void array_output(itr start, itr goal, func out = [](itr x) { return x; } ){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr, class func> void nint_output(itr start, itr goal, func out = [](itr x) { return x; } ){ string ans; for(auto i = start; i != goal; i++){ ans += string(out(*i)) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcount(n)

int main(){
    long a, b;
    while(cin >> a >> b){
        cout << gcd(a, b) << " " << a / gcd(a, b) * b << endl;
    }
}



Measured memory_bytes: 3092
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static void Main(string[] args)
        {
            int N = ReadInt();
            var A = new int[N];
            for (int i = 0; i < N; ++i) { A[i] = ReadInt(); }
            Console.WriteLine(A.All(a => a % 2 == 0) ? "second" : "first");
        }
    }
}


Measured memory_bytes: 15452
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

#define INF LLONG_MAX/5
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define enld endl

//(x^n)%mを返す
int power(int x, int n, int m) {
	int res = 1;
	x %= m;
	while (n > 0) {
		if (n % 2 == 1) {
			res = res * x % m;
		}
		x = x * x % m;
		n /= 2;
	}
	return res;
}

//nの逆元を返す
int invmod(int n, int m) {
	int ret = 0;
	ret = power(n, m - 2, m);
	return ret;
}

//nCk%MODを返す
//O(k)
int comb(int n, int k, int m) {
	int ans = 1;
	rep(i, k) {
		ans *= n - i;
		ans %= m;
		ans *= invmod(k - i, m);
		ans %= m;
	}
	return ans;
}

signed main() {
	int N;
	cin >> N;
	cout << (MOD*2+power(10, N, MOD) + power(8, N, MOD) - 2 * power(9, N, MOD))%MOD << enld;
}

Measured memory_bytes: 3516
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
void Yes() {
    cout << "Yes" << endl;
}
void No() {
    cout << "No" << endl;
}
int main(void) {
    vector<int> x(5);
    rep(i, 5) cin >> x[i];
    int ans;
    rep(i, 5) if (x[i] == 0) ans = i + 1;
    cout << ans;
}


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

int main(){
  priority_queue<int> pq;
  int A,B;
  cin >> A >> B;
  pq.push(A);
  pq.push(B);
  int ans=0;
  ans+=pq.top();
  pq.push(pq.top()-1);
  pq.pop();
  ans+=pq.top();
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

typedef pair<string, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	int N;
	cin >> N;
	long long int num = 0;
	map<string, long long int> m;
	for(int i = 0; i < N; i++){
		string S;
		cin >> S;
		m[S] += 1;
		num = max(num, m[S]);
	}
	for(P p : m){
		if(p.second == num){
			cout << p.first << endl;
		}
	}
	return 0;
}

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

int gcd(int,int);
void swap(int *,int *);

int main()
{
  int x,y,ans;

  scanf("%d%d",&x,&y);
  ans=gcd(x,y);

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

  return 0;
}

int gcd(int x,int y)
{
  int r;

  if( x<y )
    {
      swap( &x,&y );
    }

  while( y>0 )
    {
      r=x%y;
      x=y;
      y=r;
    }

  return x;
}

void swap(int *x,int *y)
{
  int r;
  r=*x;
  *x=*y;
  *y=r;
}




Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;

void solve(){
    int n; cin >> n;
    switch(n%10){
        case 2: case 4: case 5: case 7: case 9:
            cout << "hon\n";
            break;
        case 0: case 1: case 6: case 8:
            cout << "pon\n";
            break;
        case 3:
            cout << "bon\n";
            break;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


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

#define PrintLn(X) cout << X << endl
#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)

long long A[100000];
long long N;

int main(void)
{
	cin >> N;
	long long sum = 0;
	Rep(i, N){
		cin >> A[i];
		sum += A[i];
	}

	if(sum % (N * (N + 1) / 2) != 0){
		PrintLn("NO");
		return 0;
	}
	long long count = sum / (N * (N + 1) / 2);

	Rep(i, N){
		if(A[i] < count){
			PrintLn("NO");
			return 0;
		}
		A[i] += (count % N) * (N - i - 1);
		A[i] %= N;
	}

	Rep(i, N){
		if(A[i] != A[0]){
			PrintLn("NO");
			return 0;
		}
	}
	PrintLn("YES");
	return 0;
}


Measured memory_bytes: 1024
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
sys.setrecursionlimit(int(1e+6))
MOD = int(1e+9) + 7
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

def main():
    A, B, C = i2nn()
    n = max(C - (A - B), 0)
    print(n)

main()


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <string>
using namespace std;
using pint = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }




// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string &S) {
    int n = (int)S.size();
    vector<vector<int> > res(n+1, vector<int>(2, n));
    for (int i = n-1; i >= 0; --i) {
        for (int j = 0; j < 2; ++j) res[i][j] = res[i+1][j];
        res[i][S[i]-'0'] = i;
    }
    return res;
}

int main() {
    string S, T; cin >> S >> T;
    auto nextS = calcNext(S), nextT = calcNext(T);
    int n = (int)S.size(), m = (int)T.size();
    
    vector<vector<int> > dp(n+2, vector<int>(m+2, 1<<29));
    vector<vector<pair<char,pint> > > recon(n+2, vector<pair<char,pint> >(m+2, {'0', pint(n,m)}));
    dp[n][m] = 1;
    dp[n+1][m+1] = 0;
    for (int i = n+1; i >= 0; --i) {
        for (int j = m+1; j >= 0; --j) {
            if (i == n+1 && j == m+1) continue;
            for (int k = 0; k < 2; ++k) {
                int ni, nj;
                if (i >= n) ni = n; else ni = nextS[i][k];
                if (j >= m) nj = m; else nj = nextT[j][k];
                if (chmin(dp[i][j], dp[ni+1][nj+1] + 1)) {
                    recon[i][j] = {'0'+k, pint(ni+1,nj+1)};
                }
            }
            //cout << i << ", " << j << ": " << dp[i][j] << ", " << recon[i][j] << endl;
        }
    }
    string res = "";
    int i = 0, j = 0;
    for (int k = 0; k < dp[0][0]; ++k) {
        auto p = recon[i][j];
        res += p.first;
        i = p.second.first;
        j = p.second.second;
    }
    
    cout << res << endl;
}


Measured memory_bytes: 253956
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;

int main() {
	int n;
	int m;
	cin >> n >> m;
	int c[10][10];
	int a[n][m];
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			int tmp;
			cin >> tmp;
			c[i][j] = tmp;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			int tmp;
			cin >> tmp;
			a[i][j] = tmp;
		}
	}

	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
			}
		}
	}

	int ret = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (a[i][j] >= 0) {
				ret += c[a[i][j]][1];
			}
		}
	}

	cout << ret << endl;
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int n,m,p,q,N,Q;
int ans[100001],tim[100001][11];
int nex[200001],fir[100001],to[200001];
void add(int p,int q)
{
	nex[++N]=fir[p];fir[p]=N;to[N]=q;
	nex[++N]=fir[q];fir[q]=N;to[N]=p;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
		scanf("%d%d",&p,&q),add(p,q);
	scanf("%d",&Q);
	for(int i=1;i<=Q;i++)
		scanf("%d%d%d",&p,&q,&ans[i]),tim[p][q]=i;
	for(int i=10;i>0;i--)
		for(int j=1;j<=n;j++)
		{
			tim[j][i-1]=max(tim[j][i-1],tim[j][i]);
			for(int k=fir[j];k;k=nex[k])
				tim[to[k]][i-1]=max(tim[to[k]][i-1],tim[j][i]);
		}
	for(int i=1;i<=n;i++)
		printf("%d\n",ans[tim[i][0]]);
	return 0;
} 

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <queue>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
    string s; cin >> s;
    int ans0=-1, ans1=-1;
    vector<int> last(26, -3);
    for(int i=0; i<s.size(); ++i){
        int j=s[i]-'a';
        int len=i-last[j]+1;
        if(len==2 || len==3){
            ans0=last[j]+1;
            ans1=i+1;
            break;
        }
        last[j]=i;
    }
    cout << ans0 << " " << ans1 << endl;
    return 0;
}


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

#define ll long long

using namespace std;

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0; i<s.length(); i++){
        int x=s[i]-'A';
        x=(x+n)%26;
        cout<<char('A'+x);

    }
    cout<<endl;





}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

ll n,x;

int main(){
	cin >> n >> x;
	ll ans = 0;
	ll cnt = 0;
	rep(i,n){
		if(ans <= x)cnt++;
		ll l;
		cin >> l;
		ans += l;
	}
	if(ans <= x)cnt++;
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

map<ll,ll> mp;
ll n,a,b,c,d;

ll cost(ll x, ll div, ll y){
    if(x >= 2e9) return y;
    return min(y, x/div*(div-1)*d);
}

ll rec(ll x){
    if(x == 2) return min(2*d, a+d);
    if(x == 1) return d;
    if(x == 0) return 0;
    if(mp.find(x) != mp.end()) return mp[x];
    ll res = linf;
    if(x & 1){
        chmin(res, rec(x/2) + cost(x-1, 2, a) + d);
        chmin(res, rec(x/2+1) + cost(x+1, 2, a) + d);
    }
    else chmin(res, rec(x/2) + cost(x, 2, a));
    if(x % 3 == 0) chmin(res, rec(x/3) + cost(x, 3, b));
    else{
        REP(i,1,3){
            if((x+i) % 3 == 0){
                chmin(res, rec((x+i)/3) + cost(x+i, 3, b) + i*d);
            }
            if((x-i) % 3 == 0){
                chmin(res, rec((x-i)/3) + cost(x-i, 3, b) + i*d);
            }
        }
    }
    if(x % 5 == 0) chmin(res, rec(x/5) + cost(x, 5, c));
    else{
        REP(i,1,5){
            if((x+i) % 5 == 0){
                chmin(res, rec((x+i)/5) + cost(x+i, 5, c) + i*d);
            }
            if((x-i) % 5 == 0){
                chmin(res, rec((x-i)/5) + cost(x-i, 5, c) + i*d);
            }
        }
    }
    return mp[x] = res;
}

int main(){
    ll t; cin >> t;
    while(t--){
        cin >> n >> a >> b >> c >> d;
        cout << rec(n) << endl;
        mp.clear();
    }
}

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

using namespace std;

int main (void) {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> A(M);
    for ( int i = 0; i < M; i++ ) {
        cin >> A.at(i);
    }

    vector<int> a(N+1, 0);
    for ( int i = 0; i < M; i++ ) {
        a.at(A.at(i)) = 1;
    }

    vector<int> a_sum(N+1);
    a_sum.at(0) = a.at(0);
    for ( int i = 1; i <= N; i++ ) {
        a_sum.at(i) = a_sum.at(i-1) + a.at(i);
    }

    int ans = min(a_sum.at(X), a_sum.at(N) - a_sum.at(X));

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <numeric>

using namespace std;

int N,K;
string S;
vector<int> count01;
vector<char> map01;

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

    char current = '9';
    int index = -1;
    for (int i=0; i<S.length(); i++) {
        if (current != S[i]) {
            current = S[i];
            index++;            
            count01.push_back(1);
            map01.push_back(S[i]);
        } else {
            count01[index]++;
        }
    }

    int answer = -1;
    int length = map01.size();
    for (int i=0; i<length; i++) {
        if (map01[i] == '0') {
            int count = i == 0 ? 0 : count01[i-1];
            int j = i;
            for (int k=0; k<K; k++) {
                if (j < length) {
                    count += count01[j];
                }
                if (j+1 < length) {
                    count += count01[j+1];
                }
                j += 2;
            }
            answer = max(answer, count);
        }
    }

    if (answer == -1) {
        answer = accumulate(count01.begin(), count01.end(), 0);
    }

    cout << answer << endl;
}


Measured memory_bytes: 1020
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            sample[] SP = new sample[N];
            for (int i = 0; i < N; i++)
            {
                string[] inpval = Console.ReadLine().Split(' ');
                SP[i] = new sample { index = i + 1, city = inpval[0], score = int.Parse(inpval[1]) };
            }

            SP = SP.OrderBy(z => z.city).ThenByDescending(x => x.score).ToArray();

            for (int p = 0; p < N; p++)
            {
                Console.WriteLine(SP[p].index);
            }
        }
        class sample
        {
            public int index { get; set; }
            public string city { get; set; }
            public int score { get; set; }
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

Measured memory_bytes: 11612
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		String S = in.next();

		int front = Integer.parseInt(S.substring(0, 2));
		int back = Integer.parseInt(S.substring(2));

		// frontがYYの時
		if ( front == 0 || 13 <= front ) {

			// backがMM
			if ( 1 <= back && back <= 12 ) {
				System.out.println("YYMM");
			} else {
				System.out.println("NA");
			}
		// frontがMMの時	
		} else {
			// backがYYの時
			if ( back == 0 || 13 <= back ) {
				System.out.println("MMYY");
			// backがMMの時
			} else {
				System.out.println("AMBIGUOUS");
			}
		}
	}
}

Measured memory_bytes: 23508
import math
N = int(input())
A = list(map(int,input().split()))
l = list()
ll = list()
for i in range(len(A)):
  if A[i]%4 == 0:
    l.append(A[i])
  if A[i]%2 == 0:
    ll.append(A[i])
four = len(l)
two = len(ll)-four
zero = N-two
a = math.floor(N/2)
if a <= four:
  print("Yes")
elif a-two/2 <= four:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 96748
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n, i;
  cin >> n >> i;
  cout << n - i + 1 << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
 
using namespace std;
 
#define int long long
 
signed main(){
	


	int a,b,c;
	cin>>a>>b>>c;

	if(a==b){
		cout<<c<<endl;
	}else if(b==c){
		cout<<a<<endl;
	}else{
		cout<<b<<endl;
	}
}

Measured memory_bytes: 256
def main():
    n = int(input())
    p = [int(a) for a in input().split()]
    count = 0
    for i in range(1, len(p) - 1):
        p_ = p[i - 1 : i + 2]
        p_.sort()
        if p[i] == p_[1]:
            count += 1
    print(count)
main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  vector<int> vec(N);
  int sum = 0;
  for(int i = 0 ; i<N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

 for(int i = 0 ; i<K; i++){
   sum += vec.at(i);
 }

   cout << sum << endl;
        
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

int n, u, v;
const int maxn = 100005;
vector<vector<int> > g(maxn);
vector<vector<int> > t(2, vector<int>(maxn, inf));
int key;
void dfs(int now) {
    for (int nxt : g[now]) {
        if (chmin(t[key][nxt], t[key][now] + 1)) {
            dfs(nxt);
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    
    
    cin >> n >> u >> v;
    u--; v--;
    
    rep(i, n - 1) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].eb(v);
        g[v].eb(u);
    }
    
    t[0][u] = 0;
    t[1][v] = 0;
    dfs(u);
    key = 1;
    dfs(v);
    int ans = 0;
    // rep(i, 2) { rep(j, n) cout << t[i][j] << " "; cout << endl; }
    rep(i, n) if (t[0][i] < t[1][i]) chmax(ans, t[1][i]);
    cout << ans - 1 << endl;
}



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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long, long>;
using pdd = pair<ld, ld>;

template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<ll>;
V(size_t) -> V<ll>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

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 (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<endl;}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<endl;};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    string S, T;
    cin >> S >> T;
    ll N = S.size(), M = T.size();
    ll res = INF;
    REP(i, N-M+1){
        ll tmp = 0;
        REP(j, M){
            if(S[i+j] != T[j]) tmp++;
        }
        //dump(tmp)
        chmin(res, tmp);
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3616
import numpy as np

def main():
    H,W = map(int,input().split())
    use = np.zeros((H,W),dtype=int)
    for i in range(H):
        s = input()
        for j,st in enumerate(s):
            if st == ".":
                use[i][j] = 10**10
            else:
                use[i][j] = 0
    
    for i in range(1,H):
        use[i,:] = np.minimum(use[i,:],use[i-1,:]+1)
    for i in reversed(range(H-1)):
        use[i,:] = np.minimum(use[i,:],use[i+1,:]+1)
    for j in range(1,W):
        use[:,j] = np.minimum(use[:,j],use[:,j-1]+1)
    for j in reversed(range(W-1)):
        use[:,j] = np.minimum(use[:,j],use[:,j+1]+1)
    
    print(np.max(use))

if __name__ == "__main__":
    main()


Measured memory_bytes: 20188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
    int n;
    cin >> n;

    if(n%10==9 || n/10==9) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 384
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n=I()
if n%1000==0:
    print(0)
else:
    print(1000-n%1000)

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

// m桁の短歌数の総数
ll total(int m){
    return 81*(bit(m-1)-1);
}

string rec(ll n,int m,int f){
    rep(x,10){
        ll block = (f != x ? bit(m-1) : (bit(m-1)-1)*9);
        if(n > block){
            n -= block;
        }else{
            if(f == x){
                return to_string(x)+rec(n,m-1,f);
            }
            int g = x;
            if(f < g) swap(f,g);
            n--;
            string str = to_string(x);
            for(int k = m-2; k >= 0; k--){
                str += to_string(n&bit(k) ? f : g);
            }
            return str;
        }
    }
    assert(false);
}


int main(){
    ll n;
    while(cin>>n, n){
        int m = 2;
        while(n > total(m)){
            n -= total(m);
            m++;
        }
        assert(n > 0);
        int f = 0;
        rep1(x,9){
            ll block = total(m)/9;
            if(n > block){
                n -= block;
            }else{
                f = x;
                break;
            }
        }
        assert(f > 0);
        cout<<to_string(f)<<rec(n,m-1,f)<<endl;
    }
    return 0;
}



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

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

using namespace std;


signed main(){
  int N;
  cin>>N;
  int A[N];
  rep(i, N){
    cin >> A[i]; 
  }
  int max=0;
  int sum=0;
  int count=0;
  rep(i, N){
    if(A[i]<0){
      count++;
      A[i]=A[i]*(-1);
    }
    sum+=A[i];
  }  
  sort(A, A+N);
  if(count%2==1){
    //cout << "e??"<<endl;
    sum-=A[0]*2;
  }
  //cout << count << endl;
  //cout << A[0] << endl;
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1024