akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int a[n], b[n], c[n];
    for (int i = 0; i < n; i++){
        scanf("%d",&a[i]);
    }
    int ans = 0;
    for (int i = 0; i < n; i++){
        scanf("%d",&b[i]);
        ans+= b[i];
    }
    for (int i = 1; i < n; i++){
        scanf("%d",&c[i]);
    }
    for (int i =1 ; i < n; i++){
        if (a[i] == a[i-1]+1){
            ans += c[a[i-1]];
        }
    }
    printf("%d",ans);
}


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

int main()
{
  int N, x;
  std::cin >> N >> x;
  int a[N];
  for ( int i = 0; i < N; i++ ) std::cin >> a[i];
  
  std::sort(a, a + N);
  int ans = 0;

  bool is_all = false;
  for ( int i = 0; i < N; i++ ) {
    if ( x >= a[i] ) {
      x -= a[i];
      ans++;
      if ( i == N - 1 ) is_all = true;
    } else {
      break;
    }
  }
  if ( x > 0 && is_all ) ans--;

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


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

int main(){

  int h,w;

  while(1){

    cin>>h>>w;
    if(h==0 && w==0) break;

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cout<<"#";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  
  return 0;
}



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

ll I,O,T,J,L,S,Z;

int main()
{
	scanf("%lld%lld%lld%lld%lld%lld%lld",&I,&O,&T,&J,&L,&S,&Z);

	ll ans = 0;
	if(I && J && L){
		ans = 3 + (I - 1) / 2 * 2 + (J - 1) / 2 * 2 + (L - 1) / 2 * 2 + O;
	}
	ans = max(ans,I / 2 * 2 + J / 2 * 2 + L / 2 * 2 + O);

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

	return 0;
}


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

void lcm(int &a,int b){
  a=a*b/__gcd(a,b);
}
template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int n,m,a=1;cin>>n>>m;
  for(int i=0;i<n;i++){
    int b;cin>>b;
    int T=__gcd(a<<1,b);b>>=1;
    if(i&&(a-b+T)%T)fin(0);
    lcm(a,b);
    if(m<a)fin(0);
  }
  cout<<((m/a+1)>>1)<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program{
    public static void Main(){
        var n=int.Parse(Console.ReadLine());
        var lst=new LinkedList<int>();
        for(; n>0; n--){
            var s=Console.ReadLine().Split(' ');
            switch (s[0]) {
                case "insert":{
                    lst.AddFirst(int.Parse(s[1]));
                    break;
                }
                case "delete":{
                    lst.Remove(int.Parse(s[1]));
                    break;
                }
                case "deleteFirst":{
                    lst.RemoveFirst();
                    break;
                }
                case "deleteLast":{
                    lst.RemoveLast();
                    break;
                }
            }
        }

        while(true){
            Console.Write(lst.First.Value);
            lst.RemoveFirst();
            if(lst.Count>0){
                Console.Write(" ");
            } else{
                Console.WriteLine();
                break;
            }
        }
    }
}

Measured memory_bytes: 82292
// Justice will be served
// شهید حاج قاسم سلیمانی

#include <bits/stdc++.h>
using namespace std ;

#define all(x) x.begin() , x.end()

#define PB push_back
#define F first
#define S second
#define _sz(x) (int)x.size()

#define debug(x) cerr << #x << " = " << x << endl

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

const int MAX_N = -1 ;
const int inf = 2e9 + 19 ;

int main() {
        ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;
        int n ;
        cin >> n ;
        cout << fixed << setprecision(10) << 1.0 * double(((n / 2 + n % 2))) / n ;
        return (0) ;
}


Measured memory_bytes: 256
N = gets.to_i
A = gets.to_i
B = 20
ans = 0
(A+1).times do |a|
 (B+1).times do |b|
  m = a+(b*500);
  ans = ans+1 if m == N
  break if m > N
 end
end

puts ans > 0 ? "Yes":"No"

Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <utility>
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl

typedef long long ll;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
using namespace std;
char in[120];
pair<pair<string,int>,int> p[110];

int main(){
    int a;
    scanf("%d",&a);
    for(int i=0;i<a;i++){
        int t;scanf("%s%d",in,&t);
        string tmp=in;
        p[i]=make_pair(make_pair(in,-t),i);
    }
    sort(p,p+a);
    for(int i=0;i<a;i++)printf("%d\n",p[i].second+1);
    return 0;
}

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

int main(){
  vector<string> list;
  string s;
  getline(cin,s);
  for(int i=0;i<s.size()&&s.size()!=0;i++){
    if(s[i]=='.' || s[i]==' ' || s[i]== ','){
      if(i!=0)list.push_back(s.substr(0,i));
      s = s.substr(i+1);
      i=-1;
    }
  }
  vector<string> ans ;
  for(int i=0;i<list.size();i++){
    if(2<list[i].size()&&list[i].size()<7){
      ans.push_back(list[i]);
    }
  }
  for(int i=0;i<ans.size()-1;i++){
    cout<<ans[i]<<" ";
  }cout<<ans[ans.size()-1]<<endl;
}

Measured memory_bytes: 1188
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
	cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	cout << head;
	if (sizeof...(tail) != 0) cout << " ";
	print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
	for (auto& a : vec) {
		cout << a;
		if (&a != &vec.back()) cout << " ";
	}
	cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
	for (auto& vec : df) {
		print(vec);
	}
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	auto N = IN();
	vector<i64> a(N);
	for (auto& v : a)
	{
		cin >> v;
	}
	ALL(sort, a, greater<i64>());
	i64 A = 0, B = 0;
	REP(i, SIZE(a))
	{
		if (i % 2 == 0)
			A += a[i];
		else
			B += a[i];
	}
	print(A - B);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        final int A = sc.nextInt();
        final int B = sc.nextInt();
        final int C = sc.nextInt();

        out.println(A * C <= B ? C : B / A);

        out.flush();
    }
}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int MOD = (int) 1e9 + 7;
const int inf = (int) 1e9;
const int maxn = (int) 2e5 + 20;
const int maxm = (int) 5e5 + 20;

int n;
char s[maxn];
int d[maxn];

int dp(int i, bool b)
{
    if(d[i] != -1 && !b) return d[i];
    if(i == n) return d[i] = 1;

    if(!b) return d[i] = dp(i + 1, 0) * 3LL % MOD;
    else
    {
        if(s[i] == '1')
            return (dp(i + 1, 0) * 1LL + dp(i + 1, 1) * 2LL) % MOD;
        else
            return dp(i + 1, 1);
    }
}

void work()
{
    cin >>s;
    n = strlen(s);
    fill(d, d + n + 1, -1);

    cout <<dp(0, 1) <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
    int tc = 1;
//    cin >>tc;
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

struct unionfind {
    vector<int> data;
    unionfind(int size) : data(size, -1) {}
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

struct edge {
    int u, v, cost;
};

int main(){
    int V, E;
    while (cin >> V >> E, V | E){
        vector<int> h(V);
        vector<edge> es(E);
        set<int> hs;
        hs.insert(0);
        rep(i, V){
            cin >> h[i];
            hs.insert(h[i]);
        }

        rep(i, E){
            int a, b, c; cin >> a >> b >> c;
            a--; b--;
            es[i] = { a, b, c };
        }
        sort(all(es), [](edge a, edge b){
            return a.cost < b.cost;
        });

        int ans = 0;
        unionfind uf(V);
        for (auto it = hs.rbegin(); it != hs.rend(); ++it){
            int th = *it;
            set<int> s;
            rep(i, V){
                if (th <= h[i]){
                    s.insert(i);
                }
            }
            rep(j, E){
                const edge& e = es[j];
                if (!uf.same(e.u, e.v) && s.count(e.u) && s.count(e.v)){
                    uf.unite(e.u, e.v);
                    ans += e.cost;
                }
            }
            if (s.size() != uf.size(*s.begin())){
                ans = 0;
                uf = unionfind(V);
            }
        }
        if (uf.size(0) != V) ans = 0;
        cout << ans << endl;
    }
}

Measured memory_bytes: 1468
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, long long> P;  // to, cost

int main(void) {
    int N;
    cin >> N;
    vector<vector<P>> g(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        long long w;
        cin >> u >> v >> w;
        u--;
        v--;
        g[u].push_back(P(v, w));
        g[v].push_back(P(u, w));
    }
    vector<long long> dist(N, LLONG_MAX);
    dist[0] = 0;
    queue<P> que;
    que.push(P(0, -1));
    while (!que.empty()) {
        P front = que.front();
        que.pop();

        for (auto v : g[front.first]) {
            if (dist[v.first] != LLONG_MAX) continue;
            dist[v.first] = dist[front.first] + v.second;
            que.push(v);
        }
    }

    for (int i = 0; i < N; i++) {
        cout << (dist[i] % 2 == 0 ? '0' : '1') << endl;
    }

    return 0;
}

Measured memory_bytes: 8704
N=int(input())
P=[(0,0,0)]*(N+1)

D=[0]*(N+1)

P[0]=(0,0,0)
D[0]=1
for i in range(1,N+1):
    t,x,y=map(int,input().split())
    dt=t-P[i-1][0]
    dx=abs(x-P[i-1][1])
    dy=abs(y-P[i-1][2])
    if dt < (dx+dy): #時間<移動距離
        print('No')
        break
    if ((dx+dy)==0 and dt%2!=0): #移動しない場合には時間はmod2==0
        print('No')
        break
    #if (dt-(dx+dy))%2==0 or dt%(dx+dy)==0:
    if (dt-(dx+dy))%2!=0:
        print('No')
        break
    
    P[i]=(t,x,y)
else:
    print('Yes')    

Measured memory_bytes: 23012
import sys
sys.setrecursionlimit(4100000)
import math
import itertools
INF = float('inf')
from heapq import heapify, heappop, heappush
import collections
import bisect

def main():
    n = int(input())
    S = input()

    array = [0]
    for i in range(len(S)):
        if S[i] == 'I':
            array.append(array[i]+1)
        if S[i] == 'D':
            array.append(array[i]-1)
    print(max(array))


if __name__ == '__main__':
    main()


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

string week[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
map<string, int> weekmap;

void CreateWeekMap()
{
  for(int i = 7; i > 0; i--)
    weekmap[week[7 - i]] = i;
}

int main()
{
  string S;
  cin >> S;
  CreateWeekMap();
  cout << weekmap[S] << endl;
  return 0;
}

Measured memory_bytes: 3636
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] h = new int[N];
		int ans = 0;
		
		for (int i=0; i<N; i++) {
			h[i] = sc.nextInt();
			if (K <= h[i]) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 49836
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<set>
#include<iomanip>
int elem[11][11];
using namespace std;

int main() {
	int n; 
	while(cin >> n, n != 0){
		int allsum = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> elem[i][j];
				allsum += elem[i][j];
			}
		}
		elem[n][n] = allsum;
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				sum += elem[i][j];
			}
			elem[i][n] = sum;
		}
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = 0; j < n; j++) {
				sum += elem[j][i];
			}
			elem[n][i] = sum;
		}
		
		for(int i=0; i<=n; i++){
			for (int j = 0; j <= n; j++) {
				cout << setw(5) << elem[i][j];
			}cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3152
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        var d = ReadLine().Split().Select(int.Parse).ToArray();
        long ans = 0;
        for (int i = 0; i < N-1; i++)
        {
            for (int j = i+1; j < N; j++)
            {
                ans += d[i] * d[j];
            }
        }
        WriteLine(ans);
    }
}


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

static const int N = 100;

int main() {
  int n, p[N + 1], m[N + 1][N + 1];
  cin >> n;
  for ( int i = 1; i <= n; i++ ) {
    cin >> p[i - 1] >> p[i];
  }

  for ( int i = 0; i <= n; i++ ) m[i][i] = 0;
  for ( int l = 2; l <= n; l++ ) {
    for ( int i = 1; i <= n - l + 1; i++ ) {
      int j = i + l - 1;
      m[i][j] = (1 << 21);
      for ( int k = i; k <= j - 1; k++ ) {
        m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
      }
    }
  }

  cout << m[1][n] << endl;
}


Measured memory_bytes: 3112
import scala.math._

object Main extends App {

  val YES = "YES"
  val Yes = "Yes"
  val NO = "NO"
  val No = "No"
  ///////////////////////////////////////////

  val sc = new java.util.Scanner(System.in)
  val n, d = sc.nextInt
//  val a = List.fill(n + 1)(sc.nextLong)

  val range = d * 2 + 1
  val ans = if (n % range == 0) n / range else n / range + 1

  println(ans)

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

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

Measured memory_bytes: 27292
#input

n = int(input())
c = [0 for i in range(n-1)]
s = [0 for i in range(n-1)]
f = [0 for i in range(n-1)]
for i in range(n-1):
    c[i], s[i], f[i] = list(map(int, input().split()))

#引数　（始まりの駅, 現在の時間）
def calcTime(start, time):

    #着いていたら、現在の時間を返す
    if start == n - 1:
        return time
    #発車時刻より早くついてしまった場合は、発車時刻まで待つ
    if time < s[start]:
        time = s[start]
    #発車時刻より後でも、f[i]の倍数でないと電車が発車しないため、そこまで待つ
    if time % f[start] != 0:
        time += f[start] - (time % f[start])
    #次の駅に着いた時間
    time += c[start]
    #次の駅に着いたので、次の駅の時間を求める。
    return calcTime(start + 1, time)
for i in range(n):
    print(calcTime(i, 0))


Measured memory_bytes: 3572
n, k = map(int, input().split())
A = list(map(int, input().split()))
s = sum(A)
def md(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors
P = md(s)
def test(x):
  L = sorted([a%x for a in A])
  M = sum(L)
  c = M//x
  for _ in range(c):
    M -= L.pop()
  return M <= k

for p in P:
  if test(p):
    print(p)
    break

Measured memory_bytes: 42076
import collections

n,u,v=map(int,input().split())
g=[[] for _ in range(n+1)]
for _ in range(n-1):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
q=collections.deque()
q.append((v,0))
checked=[0]*(n+1)
dist1=[0]*(n+1)
while len(q)!=0:
  tv,td=q.popleft()
  checked[tv]=1
  dist1[tv]=td
  for tu in g[tv]:
    if checked[tu]==1:
      continue
    q.append((tu,td+1))
q=collections.deque()
q.append((u,0))
checked=[0]*(n+1)
dist2=[0]*(n+1)
while len(q)!=0:
  tv,td=q.popleft()
  checked[tv]=1
  dist2[tv]=td
  for tu in g[tv]:
    if checked[tu]==1:
      continue
    q.append((tu,td+1))
ans=0
for tv in range(1,n+1):
  if dist1[tv]>dist2[tv]:
    ans=max(ans,dist1[tv]-1)
print(ans)

Measured memory_bytes: 34276
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
//library begin
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int log(int a){
    int b=a;
    int cnt=0;
    while(b%2==0){
        b/=2;
        cnt++;
    }
    return cnt;
}
//library end
int n;
string s;
int l=0,r=0;
int cnt=0;
signed main(){
    cin>>n>>s;
    rep(i,n){
        if(s[i]=='(')cnt++;
        else cnt--;
        if(cnt<0){
            l++;
            cnt++;
        }
    }
    if(cnt>0)r=cnt;
    rep(i,l)cout<<"(";
    cout<<s;
    rep(i,r)cout<<")";
    cout<<endl;
    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可
//乗算の際にオーバーフローに注意せよ！！（適切にmodをとれ）

const ll INF=1e18;

signed main(){
    int n;
    cin>>n;
    ll a,b;
    cin>>a>>b;
    V<ll> h(n);
    cinf(n,h);
    sort(all(h));
    ll left=-1,right=1e9+1;
    while(right-left>1){
        ll mid=(left+right)/2;
        ll cnt=0;
        bool ok=1;
        for(int i=0;i<n;i++){
            if(b*mid>=h[i]) continue;
            ll u;
            if((h[i]-b*mid)%(a-b)==0) u=(h[i]-b*mid)/(a-b);
            else u=(h[i]-b*mid)/(a-b)+1;
            cnt+=u;
            if(cnt>mid){
                ok=0;
                break;
            }
        }
        if(ok) right=mid;
        else left=mid;
    }
    cout<<right<<endl;
}

Measured memory_bytes: 1024
n = int(input())
h = tuple(map(int, input().split()))

INF = float('inf')
dp = [INF] * n
dp[0] = 0
dp[1] = abs(h[0] - h[1])
# dp[i] = (足場iにたどり着いた時点でのコストの最小値)

for i in range(2, n):
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),
                dp[i - 2] + abs(h[i] - h[i - 2]))

print(dp[n - 1])


Measured memory_bytes: 20508
#include <bits/stdc++.h>
//#define int long long
using namespace std;

int main() {
    int n;
    cin >> n;
    int n2 = n;
    int sum = 0;;
    while (true) {
        sum += n % 10;
        n /= 10;
        if (n == 0) break;
    }
    string ans = "No";
    if (n2 % sum == 0) ans = "Yes";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
const int MaxN = 1000;

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	for(int i = 1; i <= 100; i++) {
		if( i != 2 && a * i % b == c) {
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
h,w = gets.split.map(&:to_i)

arr = []
anskey = 0
ans = []

h.times{
   arr<<gets.split.map(&:to_i) }
   
i = 0
h.times{
    
    
    j = 0
    (w-1).times{
        
        if arr[i][j]%2 == 1
        anskey+=1
        ans<<"#{i+1} #{j+1} #{i+1} #{j+2}"
        arr[i][j]-=1
        arr[i][j+1]+=1
        
        end
        
        j+=1
    }
    
    
    if i<h-1 && arr[i][-1]%2 == 1
        
        anskey+=1
        ans<< "#{i+1} #{j+1} #{i+2} #{j+1}"
        arr[i][j]-=1
        arr[i+1][j]+=1
        
        
        
        
    end
    
    
    
  i+=1  
}

puts anskey

s = 0
anskey.times{
    
    puts ans[s]
    
    
   s+=1 
}




Measured memory_bytes: 18044
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramE
    {
        private class Edge {
            public int From {get;set;}
            public int To {get;set;}
            public long Cost {get;set;}
        }
        static void Main()
        {
            int n = NextInt, m = NextInt, p = NextInt;
            var edges = TakeLine(m).Select(l => new Edge{From = (int)l[0] - 1, To = (int)l[1] - 1, Cost = l[2] - p}).ToArray();
            var distance = Enumerable.Repeat(long.MinValue >> 2, n).ToArray();
            distance[0] = 0;
            var negatives = Enumerable.Repeat(false, n).ToArray();

            for (int i = 0; i <= 2 * n; i++)
            {
                foreach (var edge in edges)
                {
                    if (distance[edge.From] != long.MinValue >> 2 && distance[edge.To] < distance[edge.From] + edge.Cost)
                    {
                        if (i >= n - 1 && edge.To == n - 1)
                        {
                            System.Console.WriteLine(-1);
                            return;
                        }
                        else if (i >= n - 1)
                        {
                            distance[edge.To] = long.MaxValue >> 2;
                        }
                        else
                        {
                            distance[edge.To] = distance[edge.From] + edge.Cost;
                        }
                    }
                }
            }

            System.Console.WriteLine(Math.Max(0, distance[n - 1]));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 15644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const ll INF = numeric_limits<ll>::max();
int main()
{
    ll x, y; cin >> x >> y;
    ll a = 4*x - y;
    ll b = y - 2*x;
    bool f = false;
    if (a >= 0 && b >= 0 && a%2 == 0 && b%2 == 0 ) {
        f = true;
    }
    cout << (f?"Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 3604
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
  let mut line: String = String::new();
  io::stdin().read_line(&mut line);
  line.trim().parse().ok().unwrap()
}

fn main() {
  let n: usize = input();
  let mut pre = 1;
  let mut prepre = 2;
  if n == 1 {
    println!("1");
    return
  }
  let mut num: u64 = 0;
  for _ in 0..n-1 {
    num = pre + prepre;
    //println!("{}, {}, {}", num , pre, prepre);
    prepre = pre;
    pre = num;
  }
  println!("{}", num);
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n  = Integer.parseInt(br.readLine());
		String[] AStr = br.readLine().split(" ");
		int[] Aint = new int[n];

		for(int i = 0 ; i < n ; i++){
			Aint[i] = Integer.parseInt(AStr[i]);
		}

		int j = partation(Aint,0,n);

		StringBuilder sb = new StringBuilder();
		for(int i = 0 ; i < n ; i++){
			if(i == j){
				sb.append("[");
				sb.append(String.valueOf(Aint[i]));
				sb.append("]");
				sb.append(" ");
			}else{
				sb.append(String.valueOf(Aint[i]));
				sb.append(" ");
			}
		}

		System.out.println(sb.toString().trim());

	}

	private static int partation(int[] A,int p,int r){

		int x = A[r-1];
		int j = -1; //?????¨???x???????°??????????????????§???indx
		int tmp;
		for(int i = 0; i < r-1 ; i++){
			if(x >= A[i]){
				j++;
				tmp = A[i];
				A[i] = A[j];
				A[j] = tmp;
			}
		}

		j++;
		tmp = A[r-1];
		A[r-1] = A[j];
		A[j] = tmp;
		return j;
	}

}

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

using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 1010;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; 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;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}

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

ll dp[1010][1010];
ll v[110], w[110];

//long longしか使わない
//素数は1より大きい
int main() {
	ll n;
	cin >> n;
	rep(i, n) {
		string s, t;
		cin >> s >> t;
		rep(i, s.length()) {
			rep(j, t.length()) {
				if (s[i] == t[j]) {
					dp[i + 1][j + 1] = dp[i][j] + 1;
				}
				else {
					dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
				}
			}
		}
		cout << dp[s.length()][t.length()] << endl;
	}
	return 0;
}



Measured memory_bytes: 11052
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>

using namespace std;

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

int main() {

	int N;
	vector<int> s(123),t;

	scanf("%d", &N);

	REP(i, N *(N - 1) / 2) {
		int A, B, C, D;
		scanf("%d %d %d %d", &A, &B, &C, &D);
		s[A-1] += (C > D) ? 3 : 0;
		s[B-1] += (C < D) ? 3 : 0;
		if (C == D) {
			s[A-1]++;
			s[B-1]++;
		}
	}

	t = s;
	sort(t.begin(), t.begin() + N);

	REP(i, N) {
		printf("%d\n", N - distance(t.begin(), upper_bound(t.begin(), t.begin() + N, s[i])) + 1);
	}

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

vl x;
vl idx;
ll ans = INF;

int main(){
  idx = vl(5);
  iota(idx.begin(),idx.end(),0ll);
  x = vl(5);
  for(ll i = 0;i < 5;i++) cin >> x[i];
  do{
    ll h = 0;
    for(ll i = 0;i < 5;i++){
      if(h%10 != 0) h += 10-(h%10);
      h += x[idx[i]];
    }
    ans = min(ans,h);
  }while(next_permutation(idx.begin(),idx.end()));
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, wcnt, wstart, rcnt;
  string s;
  cin >> n >> s;
  wcnt = rcnt = 0;
  wstart = -1;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'W') {
      if (wstart == -1) {
        wstart = i;
      }
      wcnt++;
    } else {
      if (wstart >= 0) {
        rcnt++;
      }
    }
  }
  int wcnt2 = 0;
  for (int i = wstart; i < wstart + rcnt && wstart + rcnt < n; i++) {
    if (s[i] == 'W') {
      wcnt2++;
    }
  }
  // cout << "wstart=" << wstart << " rcnt=" << rcnt << " wcnt=" << wcnt << "
  // wcnt2=" << wcnt2 << endl;
  cout << min(wcnt, wcnt2) << endl;
  return 0;
}

Measured memory_bytes: 3732
#include<stdio.h> 
#include<string> 
#include<iostream> 
using namespace std;   
struct TA{ 
	string name; int po; int rr;
};     
int main(){ 
	int n; 
	struct TA N[11];  
	bool ty=true;
	while(1){ scanf("%d",&n);
	if(n==0)break; 
		if(ty==false)cout<<endl;
	ty=false;
	for(int i=0;i<n;i++) 

	
	{cin>>N[i].name;int a,b,c; cin>>a>>b>>c; 
	N[i].po=a*3+c*1; N[i].rr=i; } 
	for(int i=0;i<n;i++) for(int j=n-1;j>i;j--) 
		if(N[j].po>N[j-1].po){struct TA T=N[j];N[j]=N[j-1];N[j-1]=T;}   
		for(int i=0;i<n;i++) 
		cout<<N[i].name<<","<<N[i].po<<endl;         
	}
	return 0;
} 

Measured memory_bytes: 1260
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H,W; cin>>H>>W;
  vector<vector<char>>A(H+2,vector<char>(W+2,'.'));
  for(int i=1;i<H+1;i++){
    string S; cin>>S;
    for(int j=1;j<W+1;j++)A[i][j]=S.at(j-1);
  }
  int a=1,b=1;
  for(int i=0;i<H+W-2;i++){
    if((A[a+1][b]=='#'&&A[a][b+1]=='#')||(A[a-1][b]=='#'&&A[a][b-1]=='#')){cout<<"Impossible"<<endl;return 0;}
    else if(A[a+1][b]=='#'){a++;continue;}
    else if(A[a][b+1]=='#'){b++;continue;}
    cout<<"Impossible"<<endl;
    return 0;
  }
  if(A[a-1][b]=='#'&&A[a][b-1]=='#'){cout<<"Impossible"<<endl; return 0;}
  cout<<"Possible"<<endl;
}

Measured memory_bytes: 3576
#include <cstdio>
#include <iostream>
using namespace std;
int main(){
  int n,a,b;
  int t,ans;
  cin >> n >> a >> b;
  for(int i=0;i<n;i++){
    cin >> t;
    if(!(a<=t && t<b))ans++;
  }
  cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> A(50);
    A[0] = A[1] = 1;
    for(int i = 2; i <= N; i++){
        A[i] = A[i - 1] + A[i - 2];
    }
    cout << A[N] << endl;
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <cstdio>
#include <iomanip>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;(i)>=0;(i)--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;



int main(){
  
    while(true){
        
        int penarty[51][11]={};
        int time_solve[51][11]={};
    
    int T,P,R;
    cin>>T>>P>>R;
        
        if(T==0&&P==0&&R==0)break;
    
    REP(i,R){
        int tID,pID,time;
        string Judge;
        cin>>tID>>pID>>time>>Judge;
        if(Judge=="WRONG"){
            if(time_solve[tID][pID]==0)penarty[tID][pID]++;
        }else{
            if(time_solve[tID][pID]==0)time_solve[tID][pID]=time;
        }
    }
    
    int cor[51]={};
    for(int i=1;i<=50;i++){
        for(int j=1;j<=10;j++){
            if(time_solve[i][j]!=0)cor[i]++;
        }
    }
    
    int pena[51]={};
    for(int i=1;i<=50;i++){
        for(int j=1;j<=10;j++){
            if(time_solve[i][j]!=0)pena[i]+=1200*penarty[i][j];
            pena[i]+=time_solve[i][j];
        }
    }
    
    vector<vector<int>> ans;
        for(int i=0;i<T;i++){
        ans.push_back({cor[i+1],1000000000-pena[i+1],50-(i+1)});
    }
    
    sort(ans.begin(),ans.end());
    reverse(ans.begin(),ans.end());
    
    REP(i,T){
        int ju=50-ans[i][2];
        cout<<ju<<" "<<ans[i][0]<<" "<<pena[ju]<<endl;
    }
    }
    
    return 0;
}

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

string columns = "zabcdefghijklmnopqrstuvwxy";

int main(int argc, char *argv[])
{
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    long long N;
    cin >> N;
    
    string name;
    string id;
    while (N > 0) {
        long long mod = N % 26;
        id.insert(id.begin(), columns[N % 26]);
        if (mod == 0) {
            N -= 26;
        }
        N /= 26;
    }
    
    //reverse(name.begin(), name.end());
    
    cout << id << endl;
    
    return 0;
}


Measured memory_bytes: 3600
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

double velocity[200000];
int accel[200000];


signed main() {
	int n;
	cin >> n;
	if (n >= 1000) {
		cout << "ABD\n";
	}
	else {
		cout << "ABC\n";
	}


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int a,b;
	cin>>a>>b;
	if(abs(a-b)%2==0)cout<<min(a,b)+abs(a-b)/2<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

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

#define ALL(v) v.begin(), v.end()
typedef long long ll;



using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	int ans = 0;

	if (b == 1) {
		cout << 0 << endl;
	}
	else 
	{
		for (int i = 1; ; i++)
		{
			if (i == 1) {
				if (a >= b) {
					ans = 1;
					break;
				}
			}

			int count = (a - 1) * (i - 1) + a;
			if (count >= b) {
				ans = i;
				break;
			}
		}


		cout << ans << endl;

	}

}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>

int n;
int dec[105]={};
int dp[105][4][4]={};

void modadd(int &p,int q){
	p=(p+q)%10000;
}

int rec(int d,int p1,int p2){
	if(dp[d][p1][p2]!=-1)return dp[d][p1][p2];
	int r=0;
	if(d==2){
		if((dec[d]!=0 && dec[d]!=p2) || (dec[d-1]!=0 && dec[d-1]!=p1))goto re;
		r=1;
		goto re;
	}
	else{
		if((dec[d]!=0 && dec[d]!=p2) || (dec[d-1]!=0 && dec[d-1]!=p1))goto re;
		for(int i=1;i<=3;i++){
			if( !(i==p1 && p1==p2) ) modadd(r,rec(d-1,i,p1));
		}
	}
re:;
	dp[d][p1][p2]=r;
	return r;
}

int main(void){
	memset(dp,-1,sizeof(dp));
	int k,a,b;
	scanf("%d%d", &n, &k);
	for(int i=0;i<k;i++){
		scanf("%d%d", &a, &b);
		dec[a]=b;
	}
	int r=0;
	for(int i=1;i<=3;i++){
		for(int j=1;j<=3;j++){
			modadd(r,rec(n,i,j));
		}
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 1032
#include <stdio.h>

int main()
{
    int n,  d1, d2;

    scanf("%d", &n);
    d1 = n/10;
    d2 = n%10;

    if(d1==9)
    {
        printf("Yes");

    }
    else if(d2==9)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }

    return 0;
}


Measured memory_bytes: 1656
class Rectangle:
    def __init__(self, height, pos):
        self.height = height
        self.pos = pos


def getLargestRectangleInRow(size, buffer):
    s = []
    maxv = 0
    buffer.append(0)
    for i in range(size + 1):
        rect = Rectangle(buffer[i], i)
        if len(s) == 0:
            s.append(rect)
        else:
            if s[-1].height < rect.height:
                s.append(rect)
            elif s[-1].height > rect.height:
                target = i
                while len(s) != 0 and s[-1].height >= rect.height:
                    pre = s.pop()
                    area = pre.height * (i - pre.pos)
                    maxv = max(maxv, area)
                    target = pre.pos
                rect.pos = target
                s.append(rect)

    return maxv


def getLargestRectangle(H, W, buffer):
    t = [[0] * W for i in range(H)]
    for i in range(H):
        for j in range(W):
            if buffer[i][j] == 1:
                t[i][j] = 0
            else:
                if i > 0:
                    t[i][j] = t[i-1][j] + 1
                else:
                    t[i][j] = 1

    maxv = 0
    for i in range(H):
        maxv = max(maxv, getLargestRectangleInRow(W, t[i]))
    return maxv



if __name__ == '__main__':
    h, w = [int(v) for v in input().split()]
    c = []
    for i in range(h):
        c.append([int(v) for v in input().split()])

    print(getLargestRectangle(h, w, c))


Measured memory_bytes: 65468
# E

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

K = 0
R = 0

for i in range(N):
    q = a_list[i] // (N+1)
    if q >= 2:
        a_list[i] -= (q-1)*(N+1)
        R += (q-1)
        K += (q-1)

if R >= N:
    K += (R - N)*N
    R = N

for i in range(N):
    a_list[i] += R
    
while max(a_list) >= N:
    p = a_list.index(max(a_list))
    K += 1
    for i in range(N):
        if i == p:
            a_list[i] -= N
        else:
            a_list[i] += 1
    
print(K)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace A
{
    partial class Program
    {
        public IEnumerable<string> Solve()
        {
            var n = Num;
            var ps = new List<long>();
            for (int i = 0; i < n; i++)
            {
                ps.Add(Num);
            }

            var res = 0;
            for (int i = 1; i < n - 1; i++)
            {
                if (ps[i - 1] < ps[i] && ps[i] < ps[i + 1])
                    res++;
                if (ps[i - 1] > ps[i] && ps[i] > ps[i + 1])
                    res++;

            }


            yield return res.ToString();
        }
    }

    class StartingPoint
    {
        static void Main(string[] args)
        {
            if (args?.Any() == true)
            {
                var assembly = Assembly.GetExecutingAssembly();
                var resourceName = "AtCoder.Resources.In.txt";
                var stream = assembly.GetManifestResourceStream(resourceName);
                var streamReader = new StreamReader(stream, Encoding.UTF8);
                var str = streamReader.ReadToEnd();
                var textReader = new StringReader(str);
                Console.SetIn(textReader);
            }

            try
            {
                foreach (var s in new Program().Solve())
                {
                    Console.WriteLine(s);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                if (args?.Any() != true)
                    throw e;
            }

            if (args?.Any() == true)
                Console.ReadLine();
        }
    }

    partial class Program
    {
        long[] Nums(long count) => Enumerable.Range(0, (int)count).Select(_ => Num).ToArray();
        long Num => long.Parse(Str);
        double NumD => (double)Num;

        StringBuilder sb = new StringBuilder();

        string Str => GetStr();
        string GetStr()
        {
            sb.Clear();

            int r = 0;
            bool? b = null;
            do
            {
                r = Console.Read();
                b = IsBreak(r);
            } while (b == true);

            if (b == null)
                throw new Exception("input error: unexpected end of stream");

            do
            {
                sb.Append((char)r);
                r = Console.Read();
                b = IsBreak(r);
            } while (b == false);

            return sb.ToString();
        }

        bool? IsBreak(int c)
        {
            switch (c)
            {
                case -1:
                    return null;
                case (int)' ':
                case (int)'\n':
                case (int)'\r':
                    return true;
                default:
                    return false;
            }
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;

int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  int sum=0;
  for(int i=0;i<N;i++){
    cin>>a.at(i);
    sum+=a.at(i)-1;
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String s = "";
        
        while (true) {
            if (n%-2 == 0) {
                s = "0" + s;
                
            }
            else {
                s = "1" + s;
                n--;
            }
            if (n/-2==0) break;
            n /= -2;
        }
        
        System.out.println(s);
    }
}





Measured memory_bytes: 23252