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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define _upgrade                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template <typename _T>
inline void _DBG(const char *s, _T x)
{
    cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a)
{
    while (*s != ',')
        cerr << *s++;
    cerr << " = " << x << ',';
    _DBG(s + 1, a...);
}

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr \
    if (0)   \
    cout
#endif

// ********************** CODE ********************** //

const int N = 1e5 + 7;

int n, m, vis[N], cnt[N], vis2[N];
LL A[N];
vector < int > G[N];
vector < PLL > v;

void dfs(int ve, int r)
{
    v.push_back({A[ve], r});
    vis[ve] = 1;
    for(auto u: G[ve])
    {
        if(!vis[u])
            dfs(u, r);
    }
}

int main()
{
    _upgrade
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        cin >> A[i];
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a++, b++;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int sp = n - m;

    for(int i = 1; i <= n; i++)
    {
        if(!vis[i])
        {
            dfs(i, i);
        }
    }

    LL res = 0, ile = 0;
    sp--;
    if(sp == 0)
    {
        cout << 0 << "\n";
        return 0;
    }
    sort(all(v));

    for(int i = 0; i < n; i++)
    {
        PII p = v[i];
        if(cnt[p.second] == 0)
        {
            cnt[p.second]++;
            ile++;
            res += p.first;
            vis2[i] = 1;
        }
    }

    for(int i = 0; i < n; i++)
    {
        PII p = v[i];
        if(ile == 2 * sp || vis2[i]) continue;
        if(cnt[p.second] < sp)
        {
            cnt[p.second]++;
            ile++;
            res += p.first;
        }
    }

    if(ile == 2 * sp)
        cout << res << "\n";
    else
        cout << "Impossible";

    return 0;
}


Measured memory_bytes: 9972
#include <stdio.h>
 
int main() {
	char s1[11], s2[11], s3[11];
	scanf("%s %s %s", s1, s2, s3);
	printf("%c%c%c\n", s1[0] - 32, s2[0] - 32, s3[0] - 32);
	return 0;
}

Measured memory_bytes: 1696
# -*- coding: utf-8 -*-
import sys;
import string;
sys.setrecursionlimit(20000) # 再起呼び出しの最大数をセット

import copy
import itertools

from functools import lru_cache
#@lru_cache(maxsize = None)

PPP = 1000000007

# 整数の入力
#n = int(input())

# スペース区切りの整数の入力
#w = [x for x in map(int, input().split())]
x, a = map(int, input().split())
#print("sp", n, k, file=sys.stderr)
#p, q, r = map(int, input().split())

# 改行区切りの整数の入力
#a = []
#for x in range(n):
#  a.append(int(input()))
#  a.append([int(x) for x in input().split()])
#p = [int(x) for x in input().split()]
#a.sort()
#print(a, file=sys.stderr)

# 文字列の入力
#s = input()

# 出力
#print("{} {}".format(a+b+c, s))
#a.sort()
#print(set(a), file=sys.stderr)
#print(len(set(a)))

#cache = dict()

import re

def doit():
  if x < a:
    return 0
  else:
    return 10

#print(doit([0] * 4))
#doit(s)
try:
  print(doit())
except Exception as e:
  print("e", e, file=sys.stderr)


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

typedef long long ll;
void solve() {
	ll a, b, n;
	scanf("%lld%lld%lld", &a, &b, &n);
	
	ll fir = a * min(n, (b - 1)) / b;
	printf("%lld\n", fir);
}

int main()
{
	int T = 1;
	//scanf("%d", &T);
	
	while(T--) {
		solve();
	}
}

Measured memory_bytes: 3760
#include<cstdio>
using namespace std;
int main(){
    int n,m,l;
    scanf("%d %d %d",&n,&m,&l);
    int A[n][m],B[m][l];
    long long int C[n][l];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf(" %d",&A[i][j]);
        }
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<l;j++){
            scanf(" %d",&B[i][j]);
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            long long int sum=0;
            for(int k=0;k<m;k++){
                sum+=A[i][k]*B[k][j];
            }
            C[i][j]=sum;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
           printf("%lld",C[i][j]);
           if(j!=l-1){
               printf(" ");
           }
        }
        printf("\n");
    }
    
}



Measured memory_bytes: 2828
#include <stdio.h>          // printf(), scanf()

int
main(int argc, char** argv)
{
	long min, max, sum;

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

	sum = 0;
	int i;
	for (i = 0; i < n; ++i)
	{
		int x;
		scanf("%d", &x);
		sum += x;
		if (i == 0 || x < min)
			min = x;

		if (i == 0 || x > max)
			max = x;
	}

	printf("%ld %ld %ld\n", min, max, sum);
	return 0;
}

Measured memory_bytes: 600
N,M = map(int,input().split())
K = [list(map(int,input().split())) for i in range(M)]
P = list(map(int,input().split()))
ans = 0
for i in range(2**N):
    count = 0#幾つの電球がonになっているか
    on_or_off = [0]*M #M個の電球それぞれに対し、割り当てられたスイッチのうち、幾つがonになっているか
    for j in range(N):
        if(i>>j)&1:#スイッチjがonになっているとき
            for k in range(M):
                if j+1 in K[k][1:]:#スイッチjが電球kにつながっているなら、電球kのスイッチカウントをプラス
                    on_or_off[k] += 1
    for l in range(M):#幾つの電球が点灯しているか
        if on_or_off[l]%2==P[l]:
            count += 1
    if(count == M):#全ての電球が点灯していたら+1
        ans += 1
print(ans)


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

using namespace std;

int main() {
	int e[4];
	for(int i = 0; i < 4; ++i) cin >> e[i];
	sort(e, e + 4);
	if(e[0] == e[1] && e[2] == e[3]) cout << "yes" << endl;
	else cout << "no" << endl;
	return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <stack>
#include <vector>

int main() {
  std::stack<int> down;
  std::stack<std::pair<int, int>> pool;
  
  int sum = 0;
  
  char temp;
  for (int i=0; std::cin >> temp; ++i) {
    if (temp == '\\') {
      down.push(i);
    } else if (temp == '/' && !down.empty()) {
      auto j = down.top();
      down.pop();
      sum += i - j;
      
      auto k = i - j;
      
      while (!pool.empty() && pool.top().first > j) {
        k += pool.top().second;
        pool.pop();
      }
      pool.emplace(j, k);
    }
  }
  
  std::vector<int> ans;
  while (!pool.empty()) {
    ans.emplace_back(pool.top().second);
    pool.pop();
  }
  
  std::cout << sum << std::endl << ans.size();
  if (ans.size() == 0) {
    std::cout << std::endl;
  } else {
    std::cout << " ";
    for (auto i=ans.rbegin(); i!=ans.rend()-1; ++i) {
      std::cout << *i << " ";
    }
    std::cout << ans.front() << std::endl;
  }
}


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

int main(){
  int n;
  cin >> n;
  double pi = 3.14;
  cout << pi*n*2 << endl;


}



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

int main() {
  
  int K, N;
  cin >> K >> N;
  
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  int time_min;
  
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    if (i == 0){
      B.at(i) = A.at(i) + K - A.at(N - 1);
    }
    else {
      B.at(i) = A.at(i) - A.at(i - 1);
    }
  }
  
  vector<int> C(N);
  for (int i = 0; i < N; i++) {
    C.at(i) = K - B.at(i);
  }
  
  sort (C.begin(), C.end());
  
  cout << C.at(0) << endl;
    
}

Measured memory_bytes: 2560
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

class CColon {
public:
	void solve(std::istream& in, std::ostream& out) {
        static const double pi = 3.141592653589793;
        ll a,b,h,m;
        in>>a>>b>>h>>m;
        double hd = h/12.0+(m/60.0*(1/12.0));
        hd *= 2*pi;
        double md = m/60.0*2*pi;


        double c_kaku = min(abs(hd-md),360-abs(hd-md));
//        out<<c_kaku<<endl;
        double c;
        c = sqrt(a*a+b*b-2*a*b*cos(c_kaku));
        printf("%.16f",c);

	}
};


int main() {
	CColon solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main()
{
  int N;
  cin >> N;
  bool ans = false;
  for (int i = 0; i <= N/4; i++) {
    int n = N - i*4;
    if (n%7==0) ans = true;
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3624
//8方向
//0が海、1が島

#include <iostream>
#include <vector>
using namespace std;

// 入力
int H, W;
vector<vector<int>> field;

// 探索
void dfs(int h, int w) {
	field[h][w] = 0;

	// 八方向を探索
	for (int dh = -1; dh <= 1; ++dh) {
		for (int dw = -1; dw <= 1; ++dw) {
			//if(dh*dw!=0) continue; //4方向にするときはここを有効に
			int nh = h + dh, nw = w + dw;

			// 場外アウトしたり、0 だったりはスルー
			if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
			if (field[nh][nw] == 0) continue;

			// 再帰的に探索
			dfs(nh, nw);
		}
	}
}

int main() {
	// 入力受け取り
	while (cin >> W >> H) {
		if (H == 0 || W == 0) break;
		field.assign(H, vector<int>(W, 0));
		for (int h = 0; h < H; ++h) {
			for (int w = 0; w < W; ++w) cin >> field[h][w];
		}

		// 探索開始
		int count = 0;
		for (int h = 0; h < H; ++h) {
			for (int w = 0; w < W; ++w) {
				if (field[h][w] == 0) continue; // 残島じゃなかったらスルー
				dfs(h, w);
				++count;
			}
		}
		cout << count << endl;
	}
}


Measured memory_bytes: 3336
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
A = LI()

A = sorted(A,reverse=True)

a = (N-1)//2

b = 0
for i in range(a+1):
    b += A[i]


if N % 2 == 1:
    print(2*b-A[0]-A[a])
else:
    print(2*b-A[0])

Measured memory_bytes: 93888
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
/*
12345671234567
 234566223456
  3456622345
   45662234
*/
int main() {
    int n, x;
    cin >> n >> x;
    if (x == 1 || x == n*2-1) {
        cout << "No" << endl;
    } else {
        vector<int> post;
        int n2 = n*2-1;
        cout << "Yes" << endl;
        for(int i = n; i < n*2-1; i++) {
            cout << (1+(x+i-1)%n2) << endl;
        }
        for(int i = 0; i < n; i++) {
            cout << (1+(x+i-1)%n2) << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 1536
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int a = fs.nextInt();
		int b = fs.nextInt();
		int c = fs.nextInt();
		
		if(a == b && b == c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}


}


Measured memory_bytes: 23124
#include<stdio.h>
int main ()
{
  int min,t,n,count=0;
  scanf("%d",&n);
  min=n;
  while(n>0)
  {
    scanf("%d",&t);
    if(min>=t)
      count++,min=t;
    n--;
  }
  printf("%d",count);
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;

const int N = 1e5;
const int LOG = 61;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLMOD = 998244353;
const ll LLINF = 1e18;

unordered_map<int, int> t;

void update(int v, int tl, int tr, int pos, int val) {
    if (tl == tr) t[v] = val;
    else {
        int tm = (tl + tr) / 2;
        if (pos <= tm) update(2 * v, tl, tm, pos, val);
        else update(2 * v + 1, tm + 1, tr, pos, val);
        t[v] = max(t[2 * v], t[2 * v + 1]);
    }
}

int get(int v, int tl, int tr, int l, int r) {
    if (tr < l || r < tl) return 0;
    if (l <= tl && tr <= r) return t[v];
    else {
        int tm = (tl + tr) / 2;
        return max(get(2 * v, tl, tm, l, r), get(2 * v + 1, tm + 1, tr, l, r));
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];
    vi dp(n);
    int ans = 0;
    forn(i, n) {
        dp[i] = get(1, 0, INF, a[i], INF) + 1;
        update(1, 0, INF, a[i], dp[i]);
        ans = max(ans, dp[i]);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 118864
import sys
import heapq
input=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(a)
for _ in range(m):
    mina=int(heapq.heappop(a)/2)
    heapq.heappush(a,mina)
print(sum(a)*(-1))

Measured memory_bytes: 14176
unittest
{
	assert( [ "2", "1 5", "3 3" ].parse.expand.solve == 3 );
	assert( [ "3", "6 5", "-1 10", "3 3" ].parse.expand.solve == 5 );
	assert( [ "4", "7 10", "-10 3", "4 3", "-4 3" ].parse.expand.solve == 16 );
	assert( [ "20", "-8 1", "26 4", "0 5", "9 1", "19 4", "22 20", "28 27", "11 8", "-3 20", "-25 17", "10 4", "-18 27", "24 28", "-11 19", "2 27", "-2 18", "-1 12", "-24 29", "31 29", "29 7" ].parse.expand.solve == 110 );
	
	assert( ( [ "200000" ].chain( iota( -100000, 100000 ).map!( ( a ) => format( "%s %s", a, 1000000 ) ) ) ).parse.expand.solve == 200001 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto xds = new long[ 2 ][ n ];
	foreach( ref xd; xds )
	{
		input.popFront;
		xd = input.front.split.to!( long[] );
	}
	return tuple( xds );
}

auto solve( long[ 2 ][] xds )
{
	const M = 998244353L;
	
	// 各ロボットを起動したときの除外数を計算
	auto rs = new long[ xds.length ];
	{
		auto xds_s = xds.sort();
		auto st = SegmentTree!( max, long.min )( xds.length );
		foreach_reverse( i, xd; xds )
		{
			// 自分の移動距離
			auto dt = xd[ 0 ] + xd[ 1 ];
			
			// 連鎖した各ロボットのうちの最大移動距離
			auto fs = xds_s[ i .. $ ].lowerBound( [ dt, long.min ] );
			auto dm = max( dt, st.query( i, i + fs.length ) );
			st.set( i, dm );
			
			// 最大移動距離で何台除外されるか
			if( dt < dm ) fs = xds_s[ i .. $ ].lowerBound( [ dm, long.min ] );
			rs[ i ] = fs.length;
		}
	}
	
	// dp[ i番目 ] = 通り数
	auto dp = new long[ rs.length + 1 ];
	dp[ 0 ] = 1;
	foreach( i, r; rs )
	{
		dp[ i + 1 ] = ( dp[ i + 1 ] + dp[ i ] ) % M;		// 起動しない
		dp[ i + r ] = ( dp[ i + r ] + dp[ i ] ) % M;		// 起動する
	}
	return dp[ $ - 1 ];
}

// セグメント木
struct SegmentTree( alias op = ( ( a, b ) => a + b ), long I = long.init )
{
	long   n;
	long   nc;
	long   bc;
	long[] ps;
	
	this( long n )
	{
		this.n = n;
		for( nc = 1; nc < n; nc <<= 1 ){ /* nop */ }
		bc = nc - 1;
		ps.length = nc + bc;
		static if( I != long.init ) ps[] = I;
	}
	
	this( long[] qs )
	{
		this( qs.length );
		ps[ bc .. bc + qs.length ] = qs;
		foreach_reverse( i, ref p; ps[ 0L .. bc ] ) p = op( ps[ i * 2 + 1 ], ps[ i * 2 + 2 ] );
	}
	
	void set( long i, long v )
	{
		i = bc + i;
		ps[ i ] = v;
		while( 0 < i )
		{
			i = ( i - 1 ) / 2;
			ps[ i ] = op( ps[ i * 2 + 1 ], ps[ i * 2 + 2 ] );
		}
	}
	
	auto get( long i )
	{
		return ps[ bc + i ];
	}
	
	auto query( long l, long r )
	{
		long f( long l, long r, long i, long il, long ir )
		{
			if( ir <= l || r <= il ) return I;
			if( l <= il && ir <= r ) return ps[ i ];
			auto im = ( il + ir ) / 2;
			return op( f( l, r, i * 2 + 1, il, im ), f( l, r, i * 2 + 2, im, ir ) );
		}
		return f( l, r, 0, 0, nc );
	}
	
	auto length()
	{
		return n;
	}
	
	auto toString()
	{
		return ps[ bc .. bc + n ].to!( string );
	}
}


Measured memory_bytes: 12796
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N ;
	for(int i=0;i<=500000;i++){
		if((i*108)/100 == N){
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    int N,Q;
    long K;
    cin>>N;cin>>K;cin>>Q;
    long point[N];
    fill(point,point+N,K-Q);
    for(int i=0;i<Q;i++){
        int num;
        cin>>num;
        point[num-1]++;
    }
    for(int i=0;i<N;i++){
        if(point[i]<=0){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int a[5];
    int ans=0;
    rep(i,5){
        cin>>a[i];
        ans+=(a[i]+9)/10*10;
    }
    int ma=10;
    rep(i,5)if(a[i]%10!=0)ma=min(a[i]%10,ma);
    if(ma!=0)cout<<ans+ma-10<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	sc.close();
    	System.out.println(B % A == 0 ? A + B : B - A);
    }

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
int main(){
  int N,M;cin>>N>>M;
  vector<vector<int>>to(N+1),from(N+1);
  vector<int>fromcount(N+1,0);
  for(int i=1;i<=N-1+M;i++){
    int A,B;cin>>A>>B;
    to[A].push_back(B);
    from[B].push_back(A);
    fromcount[B]++;
  }
  
  vector<pair<int,int>>no(N+1,{0,-1});
  queue<int>que;
  for(int i=1;i<=N;i++){
    if(from[i].size()==0){
      que.push(i);
      no[i]={0,0};
    }
  }
  while(!que.empty()){
    int now=que.front();que.pop();
    for(int f:from[now]){
      if(no[now].second<no[f].second+1){
        no[now].second=no[f].second+1;
        no[now].first=f;
      }
    }
    for(int t:to[now]){
      fromcount[t]--;
      if(fromcount[t]==0){
        que.push(t);
      }
    }
  }
  for(int i=1;i<=N;i++){
    cout<<no[i].first<<endl;
  }
}

Measured memory_bytes: 12928
n,k = map(int,input().split())
h = [int(i) for i in input().split()]
inf = 10**9
dp = [inf] * n
dp[0] = 0

for i in range(n-1):
    for j in range(1,k+1):
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j])) 

print(dp[n-1])


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

#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=2e5+5;
int p[N],a[N],du[N],q[N];
unordered_set<int>have[N];
int may[N][2];

int get(int x,int j)
{
	while(have[x].count(j))++j;
	return j;
}
int x;
int check(int v)
{
	a[x]=v;
	int y=x;
	while(1)
	{
		int f=p[y];
		if(f==x)break;
		a[f]=may[f][a[y]==may[f][0]];
		y=f;
	}
	return a[y];
}

int main()
{
	int n;
	cin>>n;
	rep(i,1,n){scanf("%d",p+i);++du[p[i]];}
	int tail=0;
	rep(i,1,n)
	if(!du[i])q[++tail]=i;
	rep(head,1,tail)
	{
		int x=q[head];
		a[x]=get(x,0);
		have[p[x]].insert(a[x]);
		if(!--du[p[x]])q[++tail]=p[x];
	}
	x=1;
	while(!du[x])++x;
	for(int y=x;;)
	{
		may[y][0]=get(y,0);
		may[y][1]=get(y,may[y][0]+1);
		if((y=p[y])==x)break;
	}
	if(check(may[x][0])!=may[x][0]||check(may[x][1])==may[x][0])puts("POSSIBLE");
	else puts("IMPOSSIBLE");
}

Measured memory_bytes: 25216
import numpy as np
if __name__ == "__main__":
    # 入力パターン．
    # 要素の数がわかっているパターン
    ### a b
    N, K = map(int, input().split())
    nums = np.array(range(N+1))
    a = np.cumsum(nums)
    b = np.cumsum(nums[::-1])
    #print(a)
    #print(b)
    ans = 0
    for k in range(K, N+1+1):
        #print("k:{}, b:{}, a:{}".format(k, b[k-1], a[k-1]))
        #print(b[k-1] - a[k-1] + 1)
        ans += b[k-1] - a[k-1] + 1
    print(ans % (10**9+7))


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

int main(){
  ll x;
  cin >> x;
  int onecoin = x /500;
  int goen = (x % 500)/5;
  cout << onecoin*1000+goen*5 << endl;
}


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

using namespace std;
#define lint long long
#define P pair<int, int>

const int INF = 1E9;
int mem[(1LL << 26)];

int main(){
    string S;
    cin >> S;
    
    int len = S.length();

    fill(mem, mem + (1LL << 26), INF);
    mem[0] = 0;
    
    lint Cnt[len + 1];
    Cnt[0] = 0;
    for(int i = 1; i < len + 1; ++i){
        Cnt[i] = Cnt[i - 1] ^ (1LL << (S[i - 1] - 'a'));
    }
    
    int dp[len + 1];
    fill(dp, dp + len + 1, INF);
    dp[0] = 0;
    
    for(int i = 1; i < len + 1; ++i){
        for(int j = 0; j < 26; ++j){
            if(mem[Cnt[i] ^ (1LL << j)] < INF){
                dp[i] = min(dp[i], dp[mem[Cnt[i] ^ (1LL << j)]] + 1);
            }
        }
        if(mem[Cnt[i] ^ 0] < INF){
            dp[i] = min(dp[i], dp[mem[Cnt[i] ^ 0]] + 1);
        }
        
        if(mem[Cnt[i]] == INF || dp[mem[Cnt[i]]] > dp[i]){
            mem[Cnt[i]] = i;
        }
        
        
//        cout << dp[i] << " ";
    }
    
    cout << dp[len] << endl;
}

Measured memory_bytes: 265092
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;

int countBit(int bit){
	if(bit == 0){
		return 0;
	}
	if( bit & (1<<0)){
		return 1 + countBit( (bit>>1));
	}else{
		return countBit( (bit>>1));
	}
}

int main()
{
	int N,K;
	cin>>N>>K;
	N--;
	K--;
	int leftEnd;
	cin>>leftEnd;
	int *a = new int[N];
	rep(i,N) cin>>a[i];
	ll ans = 1000000000000;
	for(int bit = 0; bit < (1<<N); bit++){
		int leftHeight = leftEnd;
		if( countBit(bit) == K){
			ll localCostSum = 0;
			for(int i = 0; i < N; i++){
				if( bit & (1<<i)){
					if( leftHeight >= a[i]){
						leftHeight += 1;
						localCostSum += (leftHeight - a[i]); 
					}else{
						leftHeight = a[i];
					}
				}else{
					leftHeight = max(leftHeight,a[i]);
				}
			}
			ans = min(ans,localCostSum);
		}
	}
	cout<<ans<<endl;
	return 0;
}



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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define vuni(v) v.erase(unique(v.begin(), v.end()), v.end());
#define mins(m, s) m.insert(make_pair(s, 1));
#define mfin(m, s) m.find(s) != m.end()

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9 + 7;

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

    int cnt = 0;
    while(n > 0) {
        n -= 2 * d + 1;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long long int ll;
#define REP(i, I, N) for (int i = I; i < N; ++i)
#define rep(i, N) REP(i, 0, N)

int main() {
    ll N, m = 1000000000000001, order = 5;
    cin >> N;
    
    vector<ll> capacities(order);
    rep(i, order) cin >> capacities[i];
    rep(i, order) m = min(capacities[i], m);

    ll ans = (N / m + (N % m == 0 ? 0 : 1) + order - 1);

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


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

string key="qwertasdfgzxcvb";

bool left(char c){
	if(key.find(c) != string::npos) return 1;
	else return 0;
}

int main(void){
	string s;
	while(cin >> s && s != "#"){
		int32 cnt = 0;
		REP(i, s.size()-1){
			if((left(s[i]) && !left(s[i+1])) || (!left(s[i]) && left(s[i+1]))) cnt++;
		}
		cout << cnt << endl;
	}
}


Measured memory_bytes: 3160
import java.util.Scanner;

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

        String keyword = sc.next();
        String word;
        int count = 0;

        while(!((word = sc.next()).equals("END_OF_TEXT"))){
            if(word.equalsIgnoreCase(keyword)){
                count++;
            }
        }

        System.out.println(count);
    }
}



Measured memory_bytes: 26380
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    string ans;
    if(a + b > c + d) ans = "Left";
    else if(a + b < c + d) ans = "Right";
    else ans = "Balanced";

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


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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i=0;i<N;i++)
    cin >> d.at(i);
  
  // バブルソート
  for (int i=0;i<N;i++) {
    for (int j=i;j<N;j++) {
      if (d.at(i)<d.at(j)) {
        int tmp = d.at(i);
        d.at(i) = d.at(j);
        d.at(j) = tmp;
      }
    }
    
  }
  
  int count = 1;
  for (int i=0;i<N-1;i++) {
     if (d.at(i)>d.at(i+1))
       count++;    
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

const COMMAX int = 1000000
const MOD int = 1000000007

var fac [COMMAX]int
var finv [COMMAX]int
var inv [COMMAX]int

// テーブル作成
func COMinit() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := 2; i < COMMAX; i++ {
		fac[i] = fac[i-1] * i % MOD
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD
		finv[i] = finv[i-1] * inv[i] % MOD
	}
}

// 二項係数nCk
func COM(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

func perm(n, k int) int {
	return (COM(n, k) * fac[k]) % MOD
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	COMinit()
	n, m := nextInt(), nextInt()

	ans := 0
	for k := 0; k <= n; k++ {
		p1, p2 := perm(m, k), perm(m-k, n-k)
		add := (((((COM(n, k) * p1) % MOD) * p2) % MOD) * p2) % MOD
		if k%2 == 1 {
			add = -add + MOD
		}
		ans += add % MOD
		ans %= MOD
	}

	puts(ans)
}


Measured memory_bytes: 25236
inl=map(int, raw_input().split())

if inl[0]>=inl[2]+inl[4] and inl[2]-inl[4]>=0 and inl[1]>=inl[3]+inl[4] and inl[3]-inl[4]>=0:
  print "Yes"
else:
  print "No"

Measured memory_bytes: 6444
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    s, t = list(map(str, readline().rstrip().decode('utf-8').split()))
    a, b = list(map(int, readline().split()))
    u = str(readline().rstrip().decode('utf-8'))
    if s == u:
        print(a - 1, b)
    else:
        print(a, b - 1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
from collections import deque

def main():
    N,M=map(int,input().split())
    H=[int(x) for x in input().split()]
    S=[list(map(int,input().split())) for _ in range(M)]
    
    A=[0]*(N+1)
    for i in S:
        A[i[0]]=max(A[i[0]],H[i[1]-1])
        A[i[1]]=max(A[i[1]],H[i[0]-1])
        
        
    ans=0
    tmp=0
    for i in A[1:]:
        if H[tmp]>i:
            ans+=1
        tmp+=1
        
    print(ans)
   
    
if __name__=="__main__":
    main()


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

int main() {
  int X;
  cin >> X;
  
  int D = X/100;
  int M = X%100;
  
  int T = (M + 4) / 5;
  
  cout << (T <= D ? 1 : 0) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

// mint
template<int64_t Prime>
struct mod_int {
  int64_t v_;
  mod_int(int64_t x=0) : v_(x) { normalize(); }
  void normalize() { ((v_ %= Prime) += Prime) %= Prime; }
  mod_int operator+=(mod_int const& r){ (v_ += r.v_) %= Prime; return *this; }
  mod_int operator-=(mod_int const& r){ (v_ += Prime - r.v_) %= Prime; return *this; }
  mod_int operator*=(mod_int const& r){ (v_ *= r.v_) %= Prime; return *this; }
  mod_int operator+(mod_int const& r) const { mod_int res(*this); return res += r; }
  mod_int operator-(mod_int const& r) const { mod_int res(*this); return res -= r; }
  mod_int operator*(mod_int const& r) const { mod_int res(*this); return res *= r; }
  mod_int pow(int x) const {
    int64_t res = 1, v = v_;
    while(x > 0) {
      if(x&1) (res *= v) %= Prime;
      x/=2; (v *= v) %= Prime;
    }
    return mod_int(res);
  }
  mod_int inv() const { return pow(Prime-2); }
};

int64_t const MOD = 1e9+7;
typedef mod_int<MOD> mint;

// fact
template<typename INT>
struct factorial {
  std::vector<INT> fact, ifact;
  void init(int64_t N) {
    fact.resize(N+1); ifact.resize(N+1);
    fact[0] = fact[1] = INT(1);
    for(int i = 2; i <= N; ++i) fact[i] = fact[i-1]*i;
    ifact[N] = fact[N].inv();
    for(int i = N-1; i >= 0; --i) ifact[i] = ifact[i+1]*(i+1);
  }
  INT comb(int64_t n, int64_t k) { // nCk
    if(k > n || k < 0) return INT(0);
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N, M, K; std::cin >> N >> M >> K;
  factorial<mint> F;
  F.init(N*M);
  mint ans;
  for(int i = 0; i < N; ++i) for(int j = 0; j < M; ++j) {
    mint t = mint(N-i)*mint(M-j)*mint(i+j);
    ans += t;
    if(i!=0 && j!=0) ans += t;
  }
  ans *= F.comb(N*M-2, K-2);
  fin(ans.v_);
  return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define     bit_1(a)       __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     pb             push_back
#define     pf             push_front
#define     mpr            make_pair
#define     ins            insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     vstr           vector<string>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))
#define     orderset1      tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define     orderset2      tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>

//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move

int main()
{
    /*string str;
    cin>>str;
    int sz=str.size();
    if(str[sz-1]!='s')cout<<str<<"s\n";
    else cout<<str<<"es\n";*/
    int n;
    cin>>n;
    int A[n+5],B[n+5],cnt=0;
    for(int i=0;i<n;i++)cin>>A[i]>>B[i];
    for(int i=0;i<n;){
        if(A[i]==B[i]){
            cnt=0;
            while(A[i]==B[i]){
                i++;
                cnt++;
                if(i>=n)break;
            }
            if(cnt>=3){
                cout<<"Yes\n";
                return 0;
            }
        }
        else i++;
    }
    cout<<"No\n";
    /*int n,cnt=0;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n/i;j++){
            int m=i*j;
            int dif=n-m;
            if(dif>0 && dif<n)cnt++;
        }
    }
    cout<<cnt<<endl;*/
}




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

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)

const int N = 2e5 + 5;

struct dsu {
  int sz[N], par[N];
  int n;
  dsu(int _n) : n(_n) {
    fill(sz+1, sz+1+n, 1);
    memset(par, 0, sizeof par);
    iota(par+1, par+1+n, 1);
  }
  int find(int u) {
    return par[u] == u ? u : par[u] = find(par[u]);
  }
  int unite(int u, int v) {
    u = find(u);
    v = find(v);
    if(u != v) {
      if(sz[u] > sz[v]) swap(u, v);
      sz[v] += sz[u];
      par[u] = v;
      return 1;
    } return 0;
  }
};

int n, k, l;

int main(int argc, char const *argv[])
{
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  scanf("%d %d %d", &n, &k, &l);
  dsu road(n), rail(n);
  for(int i = 0; i < k; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    road.unite(u, v);
  }
  for(int i = 0; i < l; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    /*if(road.find(u) == road.find(v)) {
      rail.unite(u, v);
    }*/
    rail.unite(u, v);
  }
  map<ii, int> cnt;
  for(int i = 1; i <= n; ++i) {
    cnt[ii(road.find(i), rail.find(i))]++;
  }
  for(int i = 1; i <= n; ++i) {
    // printf("%d ", rail.sz[rail.find(i)]);
    printf("%d ", cnt[ii(road.find(i), rail.find(i))]);
  }
  puts("");
  return 0;
}

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

int main() {
  int N, a, b;
  cin >> N;
  vector<int> ans(N);
  for (int x = 1; x < N; x++) {
    for (int y = 1; y < N; y++) {
      for (int z = 1; z < N; z++) {
        int q = x*(x+y)+y*(y+z)+z*(z+x);
        if (q > N) {
          a = y;
          b = z;
          break;
        }
        ans[q-1] += 1;
      }
      if (b == 1) break;
    }
    if (a == 1) break;
  }
  for (int &e : ans) cout << e << endl;
}


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

using namespace std;

const int MAX_N = 20000;
const int MAX_M = 16;
const int INF = 1 << 29;

int C[MAX_M];
int X[MAX_N];
int dp[2][256];

int sub_pow ( int a, int b )
{
	int c = a - b;
	return c * c;
}

int main ( void )
{
	int n, m;
	while (cin >> n >> m, n|m) {
		for (int i = 0; i < 2; ++i) {
			fill(dp[i], dp[i]+256, INF);
		}
		for (int i = 0; i < m; ++i) {
			cin >> C[i];
		}
		for (int i = 0; i < n; ++i) {
			cin >> X[i];
		}
		dp[0][128] = 0;
		for (int i = 0; i < n; ++i) {
			int a = i & 1, b = (i + 1) & 1;
			fill(dp[b], dp[b]+256, INF);
			for (int j = 0; j < 256; ++j) {
				if (dp[a][j] == INF) { continue; }
				for (int k = 0; k < m; ++k) {
					int x = min(max(0, j + C[k]), 255);
					dp[b][x] = min(dp[b][x], dp[a][j] + sub_pow(x, X[i]));
				}
			}
		}
		int ans = INF;
		for (int i = 0; i < 256; ++i) {
			ans = min(ans, dp[n & 1][i]);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define pb push_back
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define ld double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007

#define par pair<int, int>
#define maxn 100005

using namespace std;
///All indexing is 0-based
using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

ll N,sol,a,b,P[maxn],Dp[maxn],L[maxn],u,v;
vector<int> G[maxn];

void dfs(int nod)
{
    Dp[nod]=1;
    for(auto ady:G[nod])
    {
        if(P[ady])
            continue;
        P[ady] = nod;
        L[ady] = L[nod]+1;
        dfs(ady);
        Dp[nod] = max(Dp[nod],Dp[ady]+1);
    }

}
int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N >> u >> v;

    for(int i=1;i<=N;i++){
        cin >> a >> b;
        G[a].pb(b);
        G[b].pb(a);
    }
    P[v] = -1;
    dfs(v);

    int l = 1;

    int nod = u;
    while(l *2 <= L[u]+1 ){
        sol=max(sol,L[nod]-1 + Dp[nod] - 1) ;
        nod = P[nod];
        l++;
    }

    cout << sol;


}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	char a;
	cin >> a;
	if (a >= 'A' && a <= 'Z')
		cout << 'A' << endl;
	else
		cout << 'a' << endl;

	return 0;
}


Measured memory_bytes: 3488
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  long long int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  long long int g=a+b,h=0;
  vector<pair<long long int,char>>f(c+d+e);
  rep(i,c){
	cin>>f.at(i).first;
    f.at(i).second='r';
  }
    rep(i,d){
	cin>>f.at(i+c).first;
    f.at(i+c).second='b';
  }
    rep(i,e){
	cin>>f.at(i+c+d).first;
    f.at(i+c+d).second='n';
  }
  sort(f.begin(), f.end());
  reverse(f.begin(), f.end());
  rep(i,c+d+e){
    if(a==0&&f.at(i).second=='r')continue;
    if(b==0&&f.at(i).second=='b')continue;
    h+=f.at(i).first;
    g-=1;
    if(f.at(i).second=='r')a--;
    if(f.at(i).second=='b')b--;
    if(g==0)break;
  }
  cout<<h;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<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; }



int main(int argc, char const *argv[]) {
  int n, k;
  cin >> n >> k;
  vector<ll> V(n);
  rep(i,n) cin >> V[i];
  ll ans = -INF;
  for (int l = 0; l <= min(n,k) ; l++) {
    for (int r = 0; r <= min(n,k) ; r++){
      if (l + r > n || l + r > k) continue;
      vector<ll> v;
      ll rec = 0;
      rep(i, l) v.pb(V[i]);
      rep(i, r) v.pb(V[n - 1 - i]);
      sort(all(v));
      rep(i, sz(v)) rec += v[i];
      rep(i, min(sz(v),k - l - r)) {
        if (v[i] < 0) rec -= v[i];
      }
      chmax(ans, rec);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_N=200005;
int n;
int A[MAX_N];
int rec[32];
int res[MAX_N];
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>A[i];
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<30;j++)
		{
			if(A[i]&(1<<j))
			{
				res[i]=max(res[i],rec[j]);
				rec[j]=i;
			}
		}
		res[i]=max(res[i],res[i-1]);
		ans+=i-res[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
////////////////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {  // O( log(a) )
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * (b / my::gcd(a, b)); }  // O( log(a) )
bool isPrime(ll n) {                                    // O( sqrt(n) )
  bool flag = true;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      flag = false;
      break;
    }
  }
  return flag;
}
vector<pair<ll, ll>> primeFac(ll n) {  // O( sqrt(n) )
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}
template <typename T>
void input_vec(vector<T> &a, ll n) {
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
}
template <typename T>
void input_set(set<T> &a, ll n) {
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.insert(tmp);
  }
}
}  // namespace my
////////////////////////////////////////////////

int main() {
  string s;
  cin >> s;
  ll tmp = 0;
  for (auto &si : s) {
    tmp += my::ctoi(si);
    tmp %= 9;
  }
  if (tmp == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3748
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long N = lread();
    long r;
    {
        long ok = 0;
        long ng = 100_000_000;
        while (ng - ok > 1)
        {
            long m = (ok + ng) / 2;
            long s = m * (m + 1) / 2;
            if (s < N)
            {
                ok = m;
            }
            else
            {
                ng = m;
            }
        }
        r = ng;
    }
    long s = r * (r + 1) / 2;
    long e = s - N;
    foreach (x; 1 .. r + 1)
        if (x != e)
        {
            writeln(x);
        }
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main() {

	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 1;

	REP(i, n - 1) {
		if (s[i] != s[i + 1])ans++;
	}
	cout << ans << endl;
}




Measured memory_bytes: 512