akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

bool ok = false;
int A, B, C, K;

void dfs(int a, int b, int c, int cnt) {
    if(ok) {
        return;
    }
    if(a < b && b < c) {
        ok = true;
        return;
    }
    if(cnt == K) {
        return;
    }
    dfs(a * 2, b, c, cnt + 1);
    dfs(a, b * 2, c, cnt + 1);
    dfs(a, b, c * 2, cnt + 1);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> A >> B >> C >> K;
    dfs(A, B, C, 0);
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3644
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        Scanner sc = new Scanner(is);

        /* read */
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (0 < a && a <= 9 && 0 < b && b <= 9) {
            os.println(a * b);
        } else {
            os.println(-1);
        }
    }
}

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

int main()
{
    long long n, r = 0, b = 0, g = 0;
    string s;
    cin >> n >> s;

    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'R') r++;
        else if (s[i] == 'B') b++;
        else g++;
    }

    long long ans = r * g * b;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (s[i] == s[j]) continue;

            int k = 2 * j - i;
            if (k >= n) break;
            if(s[k]!=s[i]&&s[k]!=s[j]) --ans;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3612
if __name__ == '__main__':
    while 1:
        w,h = list(map(int,input().strip().split()))
        if w == h ==0:break
        imap = [list(map(int,input().strip().split())) for _ in range(h)]
        visited = []
        count = 0

        for j in range(h):
            for i in range(w):
                stack =[]
                if not (j,i) in visited and imap[j][i] == 1:
                    count +=1
                    stack.append((j,i))
                    visited.append(((j,i)))
                while len(stack) !=0:
                    y,x = stack.pop()
                    for dx in [-1,0,1]:
                        for dy in [-1,0,1]:
                            if  0<= x + dx < w and 0<= y + dy <h and not (y+dy,x+dx)in visited:
                                if imap[y + dy][x + dx] == 1:
                                    stack.append((y+dy,x+dx))
                                    visited.append(((y+dy,x+dx)))
        print(count)

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

const int N = 800 + 10, inf = N * N;
typedef pair <int, int> pii;

string grid[N];
int n, m, k, dist[N][N];
int dx[] = {1, -1, 0, 0};
int dy[] = {0 , 0, -1, 1};

bool ok (int x, int y) {
	return 1 ^ (x < 0 || y < 0 || x >= n || y >= m || (grid[x][y] == '#'));
}

void bfs(int x, int y)
{
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++)
			dist[i][j] = inf;
	}
	dist[x][y] = 0;
	queue <pii> q;
	q.push({x, y});
	while(!q.empty()) {
		pii e = q.front();
		q.pop();
		x = e.first, y = e.second;
		for (int i = 0; i < 4; i++) {
			int nx = x + dx[i], ny = y + dy[i];
			if(ok(nx, ny) && dist[nx][ny] == inf)	{
				dist[nx][ny] = dist[x][y] + 1;
				q.push({nx, ny});
			}
		}
	}
}

int main () {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m >> k;
	int x, y;
	for (int i = 0; i < n; i++) {
		cin >> grid[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if(grid[i][j] == 'S') {
				x = i, y = j;
				break;
			}
		}
	}
	bfs(x, y);
	int ans = N;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if(dist[i][j] <= k) {
				ans = min(ans, (i / k) + (bool)(i % k) + 1);
				ans = min(ans, (j / k) + (bool)(j % k) + 1);
				ans = min(ans, (n - i - 1) / k + (bool) ((n - i - 1) % k) + 1);
				ans = min(ans, (m - j - 1) / k + (bool) ((m - j - 1) % k) + 1);
			}
		}
	}
	if(x == 0 || y == 0 || x == n - 1 || y == m - 1)	ans = 0;
	cout << ans << "\n";
}

Measured memory_bytes: 3456
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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



int main(){
	
    ll n,m,k;
    cin >> n >> m >> k;

   
    if(k %n == 0 || k%m == 0)Yes;
    else {

        int flag = 0;
        rep(j,0,m+1){
            ll a = n * (j);
            
            rep(i,0,n){
               a += max((ll)0,m-(j)*2);
               if(a == k){
                  Yes;
                   flag = 1;
                  break;
                  //ret 0;
               }
            }
            if(flag == 1)break;
        }

        if(flag == 0)No;

    }

    
	return  0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * TITLE : Sum of Three Integers
 * URL : https://atcoder.jp/contests/abc051/tasks/abc051_b
 */
public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int s = sc.nextInt();

		int count = 0;
		for (int x = 0; x <= k; x++) {
			for (int y = 0; y <= k; y++) {
				int temp = s - x - y;
				if (temp >= 0 && temp <= k) count++;
			}
		}
		System.out.println(count);
		sc.close();
	}
}


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

using namespace std;

int main() {
	vector <int> a(26, 0);
	string str;
	cin >> str;
	int n = str.size();
	for (int i = 0; i < n; i++) {
		a[str[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		if (a[i] & 1) {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

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

namespace program
{
    class Program
    {
        static void Main()
        {
          Dictionary<char,int> alp = new Dictionary<char,int>();
          string a = "abcdefghijklmnopqrstuvwxyz";
          for(int i=0;i<a.Length;i++)
            alp.Add(a[i],0);
          
          string s = Input.ScanStr();
          for(int i=0;i<s.Length;i++){
            if(alp[s[i]]++>0){ Out("no"); return; }
          }
          
          Out("yes");
        }
        static public void Out(object s) { Console.WriteLine(s); }
    }
    
    static class Input {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(); }
    }

    static class MyMath {
        public static int DistanceL1(int[] a, int[] b){
            if(a.Length != b.Length) return -1;
            int[] c = new int[a.Length];
            for(int i=0;i<a.Length;i++)
              c[i] = Math.Abs(a[i]-b[i]);
            return c.Sum();
        }

        public static double DistanceL2(int[] a, int[] b){
            if(a.Length != b.Length) return -1;
            int[] c = new int[a.Length];
            for(int i=0;i<a.Length;i++)
              c[i] = (a[i]-b[i])*(a[i]-b[i]);
            return Math.Sqrt(c.Sum());
        }
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13152
#include <stdio.h>

int main(){
    char str[15];
    char ans[15];
    int idx = 0;
    scanf("%s", str);
    
    for (int i=0; str[i] != '\0'; i++){
        if (str[i] != 'B'){
            ans[idx++] = str[i];
            if (str[i+1] == 'B'){
                idx--;
            }
            ans[idx] = '\0';
        }
        else{
            if (idx >= 0){
                ans[idx] = '\0';
                if (str[i+1] == 'B'){
                    (idx == 0) ? idx = 0 : idx--;
                }
            }
        }
    } 
    printf("%s\n", ans); 
    return 0;
}   

Measured memory_bytes: 1612
#include<stdio.h>

int main(void){

  int i,j;
  char h_wall[5][4];
  char v_wall[4][5];
  int x,y,p;
  int flag;

  for(i=0;i<9;i++){
    if(i%2){
      for(j=0;j<5;j++)scanf(" %c ",&v_wall[i/2][j]);
    }else{
      for(j=0;j<4;j++)scanf(" %c ",&h_wall[i/2][j]);
    }
  }

  x = 0;
  y = 0;
  p = 1;

  while(1){
    if( (x == 0 && y == 0 && p == 0) || (x == 0 && y == 0 && p == 3) )break;

    flag = 0;
    i = p;
    while(1){
      if(i == 1){
	if( y > 0 && v_wall[y-1][x] == '1'){
	  putchar('U');
	  p = 0;
	  y--;
	  flag = 1;
	}
      }

      if(i == 2){
	if( x < 4 && h_wall[y][x] == '1'){
	  putchar('R');
	  p = 1;
	  x++;
	  flag = 1;
	}
      }
      if(i == 3){
	if( y < 4 && v_wall[y][x] == '1'){
	  putchar('D');
	  p = 2;
	  y++;
	  flag = 1;
	}
      }
      if(i == 0){
	if( x > 0 && h_wall[y][x-1] == '1'){
	  putchar('L');
	  p = 3;
	  x--;
	  flag = 1;
	}
      }

      i++;
      if(i>3)i-=4;
      if(flag)break;
    }
  }
  putchar('\n');

  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main(void)
{
 int a;
 scanf("%d",&a);
 if (a < 40)
 a = 40;
 int b;
 scanf("%d",&b);
 if (b < 40)
 b = 40;
 int c;
 scanf("%d",&c);
 if (c < 40)
 c = 40;
 int d;
 scanf("%d",&d);
 if (d < 40)
 d = 40;
 int e;
 scanf("%d",&e);
 if (e < 40)
 e = 40;
 int f;
 f = a+b+c+d+e;
 int g;
 g = f /5;
 printf("%d\n",g);
 return 0;
}

Measured memory_bytes: 600
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
----
local c = read.l()
print(string.char(c:byte(1,1)+1))

Measured memory_bytes: 1008
import sys
sys.setrecursionlimit(10 ** 7)
h, w = map(int, input().split())
s = [input() for _ in range(h)]
seen = [[False for _ in range(w)] for _ in range(h)]

def dfs(bx, by, sx, sy):
    if s[sx][sy] == '.':
        b_cnt, w_cnt = 0, 1
    else:
        b_cnt, w_cnt = 1, 0
    for dx, dy in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
        px, py = sx + dx, sy + dy
        #print('=', px, py)
        if bx == px and by == py:
            #print(px, py, 'flg1')
            continue
        if px < 0 or h <= px or py < 0 or w <= py:
            #print(px, py, 'flg2')
            continue
        if seen[px][py]:
            #print(px, py, 'flg3')
            continue
        if s[sx][sy] == s[px][py]:
            #print(px, py, 'flg4')
            continue
        seen[px][py] = True
        b_add, w_add = dfs(sx, sy, px, py)
        b_cnt += b_add
        w_cnt += w_add

    return b_cnt, w_cnt

ans = 0
#print(dfs(-1, -1, 1, 1))
for i in range(h):
    for j in range(w):
        if seen[i][j] == False:
            seen[i][j] = True
            b_cnt, w_cnt = dfs(-1, -1, i, j)
            ans += b_cnt * w_cnt

print(ans)

Measured memory_bytes: 349880
#include<stdio.h>
int main(void)
{
 	int i,n,k,s,s1,cnt;
	scanf("%d %d",&n,&k);
	s=1;
	s1=0;
	for(i=1;i<=n;i++){
		s=s*2;
		cnt++;
		if(s>=k){
			break;
		}
	}
	for(i=1;i<=n-cnt;i++){
		s1=s1+k;
	}
	printf("%d\n",s+s1);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
//int maxn = 1e6 + 7;
//ll nums[maxn];
int main() {
    ll n;
    cin >> n;

    if(n == 1) cout << 1 << endl;
    else {
        ll pre = 1;
        ll ch = 2;
        ll now = 3;
        ll j = 1;
        while (1) {
            if (n > pre && n <= now) {
                cout << now << endl;
                break;
            }
            ch += pow(2, j);
            j++;
            pre = now;
            now += ch;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <map>
#include <fstream>
#include <sstream>
#include <iterator>
#include <complex>
using namespace std;

long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcd(long long a,long long b){return a*b / gcd(a,b) / gcd(a,b);}
int main()
{
	int N,M;
	cin>>N>>M;
	vector<int> a(M);

	for(int i=0; i<M; i++)
	{
		cin>>a[i];
	}
	int result = N - accumulate(a.begin(),a.end(),0);
	if(result<0)
	{
		cout<<-1<<endl;
	}
	else
	{
		cout<<result<<endl;
	}
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define vll vector<ll>
#define vvll vector<vll>
#define pi pair<int, int>
#define ll long long

int main(){
	int n, W;
	cin >> n>> W;
	vector<ll> dp(100001,1e12);
	dp[0] = 0;
	//dp[i] = minimum weight for value sum exactly equal to i
	int ans = 0;
	int val_sum = 0;
	for(int i=0;i<n;++i){
		int wt, val;
		cin >> wt>> val;
		val_sum += val;
		for(int vsum = 100000;vsum>=0;--vsum){
			if(vsum-val>=0){
				dp[vsum] = min(dp[vsum],wt+dp[vsum-val]);
			}
		}
	}
	for(int vsum = val_sum;vsum>=0;--vsum){
		if(dp[vsum]<=W){
			ans = vsum;
			break;
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	int N;
	int[] A;
	int minj,key;
	int count=0;
	
	public void input(){
		N=sc.nextInt();
		A = new int[N];
		for(int i=0; i<N; i++){
			A[i]=sc.nextInt();
		}
	}
	
	public void selectionsort(){
		for(int i=0; i<N-1; i++){
			minj=i;
			for(int j=i; j<=N-1; j++){
				if(A[j] < A[minj]){
					minj = j;
				}
			}
			key = A[i];
			A[i] = A[minj];
			A[minj] = key;
			if(i != minj) count++;
		}
	}
	
	public void output(){
		System.out.print(A[0]);
		for(int i=1; i<N; i++){
			System.out.print(" "+A[i]);
		}
		System.out.println("\n"+count);
	}
	
	public static void main(String[] args){
		Main obj = new Main();
		obj.input();
		obj.selectionsort();
		obj.output();
	}
}




Measured memory_bytes: 26256
#include <stdio.h>

long long int MAX = 1;
long long int x[100010];

int main()
{
	for(int i=1;i<=18;i++) MAX*=10;
	
	int a;
	scanf("%d",&a);
	for(int i=1;i<=a;i++) scanf("%lld",&x[i]);
	for(int i=1;i<=a;i++)
	{
		if(x[i]==0)
		{
			printf("0");
			return 0;
		}
	}
	
	long long int s =1;
	for(int i=1;i<=a;i++)
	{
		if(x[i]>=(MAX/s)+1)
		{
			printf("-1");
			return 0;
		}
		s*=x[i];
	}
	printf("%lld",s);
}

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

typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;

#define sp         ' '
#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back`
#define pb         push_back
#define mp         make_pair 
#define GCD(x,y)   __gcd(x,y)
#define lb         lower_bound
#define up         upper_bound
#define setp       setprecision
#define bs         binary_search
#define all(x)     x.begin(),x.end()
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define spc(x)     cout<<fixed<<setp(x)

const   long long  inf = 1e18;
const   long long  cs =  200005;
const   long long  mod = 1000000007;
const   double     PI =  2 * acos(0.0);
void solve()
{
    ll t,n,m,a,b,c,d,e,i,j,k,x,y,z,cnt=0,cnt1=0;
    bool flag = false;   
    
    cin>>n;
    lve v(n),v1;
    for(auto &ss:v) cin>>ss;
    x=v[0];
    for(i=1;i<n;i++)
    {
        if(v[i]<=x) {cnt++;x=v[i];}
        else 
        {
            x=v[i];
            v1.pb(cnt);
            cnt=0;
        }
    }
    v1.pb(cnt);
    x=*max_element(all(v1));
    cout<<x<<endl;
    
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);

    // freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);

    // int32_t tc;
    // cin>>tc;
    // while(tc--)
    solve();

    return 0;
}


Measured memory_bytes: 5024
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using ll = long long;


int main() {
	int n;
	cin >> n;
	int x[110], y[110], h[110];
	rep (i, n) {
		cin >> x[i] >> y[i] >> h[i];
		if (h[i]>0) {
			swap(x[i], x[0]);
			swap(y[i], y[0]);
			swap(h[i], h[0]);
		}
	}
	for (int cx=0; cx<=100; cx++) {
		for (int cy=0; cy<=100; cy++) {
			bool flg = true;
			int base_h = h[0] + abs(cx-x[0]) + abs(cy-y[0]);
			for (int i=1; i<n; i++) {
				if (max(base_h-abs(cx-x[i])-abs(cy-y[i]), 0) != h[i]) {
					flg = false;
					break;
				}
			}
			if (flg) {
				cout << cx << " " << cy << " " << base_h << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i < b; i++)
typedef long long ll;
typedef std::vector<int> vi;

using namespace std;

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

    int n;
    cin >> n;
    vi a(n), b(n);
    REP(i, 0, n) cin >> a[i] >> b[i];
    bool ok = false;
    int cnt = 0;
    REP(i, 0, n) {
        if (a[i] == b[i])
            cnt++;
        else
            cnt = 0;

        if (cnt >= 3)
            ok = true;
    }
    if (ok)
        cout << "Yes" << "\n";
    else 
        cout << "No" << "\n";

    return 0;
}

Measured memory_bytes: 3632
a,b,c,x,y=map(int,input().split())
A=a*x
B=b*y
ABa=c*x*2
ABab=b*(y-x) if y>x else 0
ABb=c*y*2
ABba=a*(x-y) if x>y else 0
AB=2*c*x if x>y else 2*c*y
print(min(A+B,ABa+ABab,ABb+ABba,AB))


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

public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(input.readLine());

        System.out.println(n % getSum(n) == 0 ? "Yes" : "No");

    }

    public static int  getSum(int n){
        int sum = 0;
        while (n > 9){
            sum += n % 10;
            n /= 10;
        }

        if (n > 0)
            sum +=n;

        return sum;
    }
}


Measured memory_bytes: 22740
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] result = new int[N];
        for(int i = 0; i < N; i++){
            int A = sc.nextInt();
            result[A - 1] = i + 1;
        }
        for(int i = 0; i < N; i++){
            System.out.print(result[i] + " ");
        }
        System.out.println();
    }
}


Measured memory_bytes: 63060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }
 
    // 素数である
    return 1;
}


 
int main(){
 lint H,W,ans=0;
 cin>>H>>W;
 char d[H][W] ;
    rep(i,H){
        rep(j,W){
                cin>>d[i][j];
                if(d[i][j]=='#')ans++;
        }
    }
    queue <tuple<lint,lint,lint>> f;
    vector <lint>x={1,-1,0,0};
     vector <lint>y={0,0,1,-1};
        f.emplace(0,0,1);
     while(!f.empty()){
            lint xx,yy,count;
            tie(yy,xx,count)=f.front();
            f.pop();
            if(xx==(W-1)&&yy==(H-1)){
                    cout<<H*W-count-ans;
                    return 0;
            }
            rep(i,4){
                if((xx+x[i])<0||(xx+x[i])>(W-1)||(yy+y[i])<0||(yy+y[i])>(H-1)){
                    continue;
                }
               if(d[yy+y[i]][xx+x[i]]=='.'){
                    f.emplace(yy+y[i],xx+x[i],count+1);
                    d[yy+y[i]][xx+x[i]]='#';
               }
            }

     }
     cout<<-1<<endl;

}

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

int main(){
    std::ios_base::sync_with_stdio(0);  cin.tie(NULL);  cout.tie(NULL);
    vector <int> vec(3) ;
    for(int i = 0 ; i < 3 && cin >> vec[i] ; i++) ;
    int count_5 = 0, count_7 = 0;
    for(int i = 0 ; i < 3 ; i++){
        if(vec[i] == 5) count_5++ ;
        else if(vec[i] == 7) count_7++ ;
    }
    cout << ( count_5 == 2 && count_7 == 1 ? "YES" : "NO") ;
    return 0 ;
}

Measured memory_bytes: 3664
/* Name        : c
 * Creat       : Fri Jul 12 18:00:02 CST 2019
 * Accept      : Fri Jul 12 18:09:11 CST 2019
 * Author      : landcold7
 * Motivation  : Action speaks louder more than words
 */
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

void solve() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  auto go = [&](ll x) {
    ll ret = x - x / c - x / d + x / (c * d / __gcd(c, d));
    trace(x, ret, c, d);
    return max(ret, 0ll);
  };
  cout << go(b) - go(a - 1) << "\n";
}

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


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

int main(){
  int N;
  ll M;
  cin >> N >> M;
  vector<int> A(N);
  rep(i, N){
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  vector<ll> s(N+1, 0);
  rep(i, N){
    s.at(i+1) = s.at(i) + A.at(i);
  }
  auto calc = [&](int x){
    ll tot = 0;
    ll num = 0;
    rep(i, N){
      int j = lower_bound(A.begin(), A.end(), x-A.at(i)) - A.begin();
      tot += s.at(N) - s.at(j);
      tot += A.at(i) * (ll)(N-j);
      num += N-j;
    }
    return make_pair(tot, num);
  };
  int l = 0;
  int r = 200001;
  while(l + 1 < r){
    int c = (l + r) >> 1;
    if(calc(c).second >= M){
      l = c;
    }
    else{
      r = c;
    }
  }
  auto q = calc(l);
  ll hp = q.first;
  hp -= (q.second - M) * l;
  cout << hp << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll N; cin >> N; 
  set<char> s;
  for (ll i = 0; i < N; i++) {
    char c; cin >> c; s.insert(c);
  }
  if (s.size() == 4) {cout << "Four" << endl;}
  else {cout << "Three" << endl;}
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	String s=sc.next(),t=sc.next();
    int a=sc.nextInt(),b=sc.nextInt();
    String u=sc.next();
    if(u.equals(s)){
      a=a-1;
    }else if(u.equals(t)){
      b=b-1;
    }else{}
    System.out.println(a+" " + b);
  }
}


Measured memory_bytes: 21972
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;


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

    vi v(3);
    REP(i, 3) cin >> v[i];

    sort(ALL(v), greater<>());

    int k;
    cin >> k;

    print(v[0] * (1 << k) + v[1] + v[2]);


}


Measured memory_bytes: 256
N = int(input())
hlist = [int(h)-1 for h in input().split()]
dp = [0 for _ in range(N)]
for i in range(1,N):
  if i == 1 or (dp[i-1] + abs(hlist[i-1]-hlist[i])) < (dp[i-2] + abs(hlist[i-2]-hlist[i])):
    dp[i] = dp[i-1] + abs(hlist[i-1]-hlist[i])
  else:
    dp[i] = dp[i-2] + abs(hlist[i-2]-hlist[i])
print(dp[-1])

Measured memory_bytes: 52720
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <functional>
 
using namespace std;

int main() {
    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <string.h>
void solve(void)
{
	char a[102], b[102];
	
	scanf("%s %s", a, b);
	if(strlen(a) < strlen(b)){
		printf("LESS\n");
	} else if(strlen(a) > strlen(b)){
		printf("GREATER\n");
	} else if(strcmp(a, b) <0){
		printf("LESS\n");
	} else if(strcmp(a, b) >0){
		printf("GREATER\n");
	} else {
		printf("EQUAL\n");
	}
}
int main(int argc, char **argv)
{
	solve();
	return 0;
}


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

const int Maxn = 200005;

int n;
int a[Maxn];
int my[Maxn];
vector <int> res;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for (int i = n; i > 0; i--) {
        int cur = 0;
        for (int j = i + i; j <= n; j += i)
            cur += my[j];
        if (cur % 2 != a[i] % 2) {
            my[i] = 1;
            res.push_back(i);
        }
    }
    printf("%d\n", int(res.size()));
    for (int i = 0; i < res.size(); i++)
        printf("%d%c", res[i], i + 1 < res.size()? ' ': '\n');
    return 0;
}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


int main(){
  int n;
  cin >> n;
  int a[n];
  rep(i,n)  cin >> a[i];
  int head = 0,tail = 0;
  long long cnt = 0;
  pair<int,int> xorSum = make_pair(0,0);



  while(tail < n){
    //head ++
    while(head < n && (xorSum.first ^ a[head]) == (xorSum.second + a[head])){
      xorSum.first  ^= a[head];
      xorSum.second += a[head];
      head++;
    }
    cnt += head - tail;
    xorSum.first  ^= a[tail];
    xorSum.second -= a[tail];
    tail ++;
  }

  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1024
import math
N=int(input())
point=[list(map(int,input().split())) for _ in range(N)]
l=[i+1 for i in range(N)]
dist1=0
dist=[]
for i in range(0,N,1):
    for j in range(i+1,N,1):
        dist1=dist1+math.sqrt(pow(point[i][0]-point[j][0],2)+pow(point[i][1]-point[j][1],2))
print(dist1*2*(N-1)/(N*(N-1)))

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

typedef long long ll;
const int N = 32000, K = 110, MOD = 1000 * 1000 * 1000 + 7;

int sum(int a, int b) {
	a += b;
	if(a < 0)
		a += MOD;
	else if(a >= MOD)
		a -= MOD;
	return a;
}

void _sum(int &a, int b) {
	a = sum(a, b);
}

int mul(int a, int b) {
	return 1LL * a * b % MOD;
}

int n, k, sq, dp[K][N], ps[K][N], add[K][N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> k;
	if(k == 1) { // ehtemalan lazem nist
		cout << n;
		return 0;
	}
	while(sq * sq <= n)
		sq++;
	sq--;
	dp[0][1] = 1;
	fill(ps[0] + 1, ps[0] + N, 1);
	for (int i = 0; i <= k + 1; i++) {
		for (int j = sq; ~j; j--)
			_sum(add[i][j], add[i][j + 1]);
		for (int j = 1; j <= sq; j++) {
			if(i)
				dp[i][j] = ps[i - 1][min(n / j, sq)];
			if(i >= 2) {
				_sum(dp[i][j], mul(ps[i - 2][j], n / j - sq));
				_sum(dp[i][j], add[i][j]);
			}
			_sum(add[i + 2][j - 1], mul(dp[i][j], n / j - sq));
			ps[i][j] = sum(ps[i][j - 1], dp[i][j]);
		}
	}
	cout << dp[k + 1][1];
	return 0;
}

Measured memory_bytes: 41216
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int r,d,x;
	cin>>r>>d>>x;
	for(int i=1;i<=10;i++)
	{
		int ans=r*x-d;
		cout<<ans<<endl;
		x=ans;
	}
	return 0;
}

Measured memory_bytes: 256
def check(x, y, z):
    return 10000*x + 5000*y + 1000*z

def main():
    N, Y = map(int, input().split())
    for x in range(2001):
        for y in range(0, 2001):
            z = N - (x+y)
            if z < 0:
                break
            if check(x, y, z) == Y:
                ans = (x, y, z)
                print(*ans)
                return
            if check(x, y, z) > Y:
                break
    ans = [-1, -1, -1]
    print(*ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <stdio.h>

int main(){
	int a=0;
	int b=0;
	int n=0;
	int m=0;
	
	printf("");
	scanf("%d %d",&a,&b);
	
	while(1){
		if(a>=1 && a<=100 && b>=1 && b<=100){
			break;
		}else{
			printf("");
			scanf("%d %d",&a,&b);
			continue;
		}
			
	}
	m=a*b;
	n=2*a+2*b;
	
	printf("%d %d\n",m,n);
	
	return 0;
	
}

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

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

const int MAXH = 18;
const int MAXN = (1<<18);
const ll MOD = 1e9+7;

int H, P[MAXN+10];
ll A[MAXN+10], ans;

void solve(int node, int tl, int tr)
{
	if(tl==tr) return;
	int mid=tl+tr>>1;
	solve(node*2, tl, mid);
	solve(node*2+1, mid+1, tr);

	vector<int> LV1, LV2, RV1, RV2;
	for(int i=tl; i<=mid; i++) LV1.push_back((1<<(H-1))-1+i);
	for(int i=tl; i<=mid; i++) LV2.push_back(P[i]+(1<<(H-1))-1);
	for(int i=mid+1; i<=tr; i++) RV1.push_back((1<<(H-1))-1+i);
	for(int i=mid+1; i<=tr; i++) RV2.push_back(P[i]+(1<<(H-1))-1);

	for(int i=0; i<RV1.size(); i++)
	{
		int u=RV1[i]; ll val=node;
		while(u!=node)
		{
			val=val*u%MOD;
			u/=2;
		}
		int v=RV2[i];
		while(v)
		{
			val=val*v%MOD;
			A[v]=(A[v]+val)%MOD;
			v/=2;
		}
	}
	for(int i=0; i<LV1.size(); i++)
	{
		int u=LV1[i]; ll val=1;
		while(u!=node)
		{
			val=val*u%MOD;
			u/=2;
		}
		int v=LV2[i];
		ll bef=0;
		while(v)
		{
			ans+=val*(A[v]-bef*v%MOD);
			ans=(ans%MOD+MOD)%MOD;
			bef=A[v];
			val=val*v%MOD;
			v/=2;
		}
	}
	for(int i=0; i<RV1.size(); i++)
	{
		int v=RV2[i];
		while(v)
		{
			A[v]=0;
			v/=2;
		}
	}
}

int main()
{
	scanf("%d", &H);
	for(int i=1; i<=(1<<(H-1)); i++) scanf("%d", &P[i]);

	solve(1, 1, (1<<(H-1)));
	printf("%lld\n", ans);
}

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

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

	vector<ll> ac(1e5 + 1, 0);
	ll s = 0;
	for (int i = 0; i < n; ++i) {
		ll a;
		cin >> a;
		
		s += a;
		++ac[a];
	}

	int q;
	cin >> q;
	
	for (int i = 0; i < q; ++i) {
		ll b, c;
		cin >> b >> c;

		s -= (b * ac[b]);
		s += (c * ac[b]);
		ac[c] += ac[b];
		ac[b] = 0;

		cout << s << endl;
	}
	
	return 0;
}
	

Measured memory_bytes: 3992
#include <cstdio>
#include <cstdint>
#include <vector>

int main() {
  size_t N;
  int x;
  scanf("%zu %d", &N, &x);

  std::vector<int> a(N);
  for (auto& ai: a) scanf("%d", &ai);

  intmax_t res = 0;
  if (a[0] > x) {
    res = a[0]-x;
    a[0] = x;
  }
  for (size_t i = 1; i < N; ++i) {
    if (a[i]+a[i-1] > x) {
      int d = a[i]+a[i-1]-x;
      res += d;
      a[i] -= d;
    }
  }
  printf("%jd\n", res);
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int n,f[101][5][5][5];
string mp[5];
bool check(int a,int b,int c, int d) 
{
    if(mp[a]+mp[c]+mp[b]=="AGC") return 0;
    if(mp[a]+mp[b]+mp[d]=="AGC") return 0;
    if(mp[a]+mp[c]+mp[d]=="AGC") return 0;
    if(mp[b]+mp[c]+mp[d]=="AGC") return 0;
    if(mp[b]+mp[d]+mp[c]=="AGC") return 0;
    if(mp[c]+mp[b]+mp[d]=="AGC") return 0;
    return 1;
}
int main()
{
    f[0][0][0][0]=1;
    cin>>n;
    mp[1]="A";
    mp[2]="G";
    mp[3]="C";
    mp[4]="T";
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=4;j++)
        {
            for(int k=0;k<=4;k++)
            {
                for(int l=0;l<=4;l++)
                {
                    for(int p=0;p<=4;p++)
                    {
                        if(check(p,l,k,j))(f[i][j][k][l]+=f[i-1][k][l][p])%=1000000007;
                    }
                }
            }
        }
    }
    int ans=0;
    for(int j=1;j<=4;j++)
    {
        for(int k=1;k<=4;k++)
        {
            for(int l=1;l<=4;l++)
            {
                (ans+=f[n][j][k][l])%=1000000007;
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
int main(void)
{
  char S[1001],T[1001];
  if(!scanf("%s %s",S,T)){return -1;}int change=strlen(T);
  rep(i,(int)strlen(S)-(int)strlen(T)+1)
  {
    int diff=0;
    rep(j,(int)strlen(T)){if(S[i+j]!=T[j]){diff++;}}
    change=diff<change?diff:change;
  }
  return printf("%d\n",change),0;
}

Measured memory_bytes: 1716
N=int(input())
div=[0]*(N+1)

for i in range(1,N+1):
    j=2
    while i!=1:
        if i%j==0:
            i//=j
            div[j]+=1
        else: j+=1

a,b,c,d,e=0,0,0,0,0
for i in range(N+1):
    if div[i]>=74:
        a+=1
        b+=1
        c+=1
        d+=1
        e+=1
    elif div[i]>=24:
        a+=1
        b+=1
        c+=1
        d+=1
    elif div[i]>=14: 
        a+=1
        b+=1
        c+=1
    elif div[i]>=4:
        a+=1
        b+=1
    elif div[i]>=2:
        a+=1

if a<3 or b<2: print(0)
else:
    ans=b*(b-1)*(a-2)//2
    ans+=d*(a-1)
    ans+=c*(b-1)
    ans+=e
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

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

vector<int> distance_list(vector<vector<int>> tree,int u){
    vector<int> color(tree.size(),0);
    vector<int> distance_list(tree.size());
    distance_list[u] = 0;
    color[u] = 1;
    queue<int> s;
    s.push(u);
    while(!s.empty()){
        int v = s.front();
        s.pop();
        REP(i,tree[v].size()){
            if(color[tree[v][i]] == 0){
                s.push(tree[v][i]);
                color[tree[v][i]] = 1;
                distance_list[tree[v][i]] = distance_list[v] + 1;
            }
        }
    }

    return distance_list;
}


int main(void)
{
    int n,u,v;
    cin >> n >> u >> v;
    u--;
    v--;
    vector<vector<int>> tree(n);

    REP(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    
    vector<int> distance_from_u = distance_list(tree,u);
    vector<int> distance_from_v = distance_list(tree,v);

    int max = 0;
    bool zero_flag = false;
    bool one_flag = false;
    REP(i,n){
        if(distance_from_u[i] < distance_from_v[i] && max < distance_from_v[i]){
            max = distance_from_v[i];
        }
        else if(distance_from_u[i] == distance_from_v[i] ){
            one_flag = true;
        }
        else{
            zero_flag = true;
        }
    }

    if(max != 0){
        cout << max - 1 << endl;
    }
    else if(one_flag){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
    

    return 0;
}

Measured memory_bytes: 12496
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define pi acos(-1)
#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<lli> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;


void solve()
{

    lli n;
    cin>>n;
    lli a[n + 1];
    for(int i = 1; i <= n; i ++) {
        cin>>a[i];
    }

    lli X = 0;

    for(int i = n ; i > 1; i --) {
        if(i & 1) {
            X += a[i];
        }
        else {
            X -= a[i];
        }
    }

    lli x = a[1] - X;
    x /= 2;
//    cout<<x<<endl;

    lli ans[n + 1] = {};
    ans[1] = 2 * (a[1] - x);
    ans[2] = 2 * x;
    X = x;
    for(int i = 3; i <= n; i ++) {
        X = (a[i - 1] - X);
        ans[i] = 2 * X;
    }

    for(int i = 1; i <= n; i ++) {
        cout<<ans[i]<<' ';
    }

    cout<<"\n";
    return ;
}

/*
*/

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

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	string S;
	cin >> S;
	if (S[0] == S[1] || S[1] == S[2] || S[2] == S[3])cout << "Bad";
	else cout << "Good";
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <deque>
#include <algorithm>
#include <set>
#include <string>
#include <math.h>
#include <stdio.h>
#include<iomanip>
#include <cstring>
#include <climits>

#define ll long long
using namespace std;
//const ll MOD = (int) 10e9 + 7;

/*ll dp[100001];
vector<vector<ll>>adj;
ll dfs(ll node)
{
    if (dp[node] != -1)
        return dp[node];

    ll ans = 0;
    for (int i = 0; i < adj[node].size(); i++)
    {
        ans = max(dfs(adj[node][i]) + 1, ans);

    }
    return dp[node] = ans;
}
*/


ll factorial(ll n)
{
    if (n == 1 || n == 0)
        return 1;
    return  n * factorial(n - 1);
}

int main()
{
   // ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    ll n;
    cin >> n;
    ll ans = 0;
    ll arr[n];
    ll dp[n][n];
    ll pre[n + 1];
    pre[0] = 0;
    for (ll i = 0; i < n; i++)
    {
        cin >> arr[i];
        pre[i + 1] = arr[i];
        pre[i + 1] += pre[i];
        dp[0][i] = 0;
    }

    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            dp[i][j] = 9223372036854775807 ;
            for (int z = 1; z <= i ; z++)
            {
                dp[i][j] = min(dp[i][j], min(dp[i - z][j] + dp[z - 1][i - z + j + 1] + (-pre[j] + pre[i + j + 1]), dp[z - 1][j] + dp[i - z][z - 1 + j + 1] + (-pre[j] + pre[i + j + 1])));
                //  dp[i][j] = min(dp[i][j], min(dp[i - z][j] + dp[z][j + i - z + 1], dp[i - z][j + z] + dp[z][j])) - pre[j] + pre[i + j + 1];
                //  cout << dp[i - z][j] << ' '<<dp[z][j + i - z + 1] << ' '<<dp[i - z][j + z] << ' '<<dp[z][j]<< ' ';
            }
            if (i == 1)
            {
                dp[i][j] = arr[j];
                if (j + 1 < n)
                    dp[i][j]  += arr[j + 1];
                else
                    dp[i][j] = 9223372036854775807 ;
            }
        }
    }
    cout << dp[n - 1][0];
    /*std::cout<<std::fixed;
    std::cout<<std::setprecision(10)<<ans;*/
             //   dp[i][i + 1 + j] = min(dp[i][i + j] + (pre[i + j + 2] - pre[i]),dp[i + 1][i + 1 + j] + (pre[i + j + 2] - pre[i]));

    return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

void swap(int *a, int *b)
{
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

void print(int A[], int N)
{
	int i;
	for (i = 0; i < N; i++)
	{
		if (i == N - 1)
			printf("%d\n", A[i]);
		else
			printf("%d ", A[i]);
	}
}

void insertion_sort(int A[], int N)
{
	int i,j;

	print(A, N);

	for (i = 1; i < N; i++)
	{
		j = i;
		while (j >= 1 && A[j - 1] > A[j])
		{
			swap(&A[j - 1], &A[j]);
			j--;
		}
		print(A, N);
	}
}

int GCD(int x, int y)
{
	if (x < y)
		swap(&x, &y);

	if (y == 0)
		return x;
	else
		return GCD(y, x % y);
}

int prime(int x)
{
	int i;

	for (i = 2; i <= sqrt(x); i++)
	{
		if (x % i == 0)
			return 0;
	}
	return 1;
}

int main()
{
	int n, num;
	int i, count = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%d", &num);
		count += prime(num);
	}

	printf("%d\n", count);
}


Measured memory_bytes: 2056
#include<bits/stdc++.h>
#define ll long long int
#define Y printf("YES\n")
#define N printf("NO\n")
#define mp make_pair
#define pb push_back
#define tp make_tuple
#define sc(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define pr(a) printf("%lld\n",a)
using namespace std;

int main()
{
    ll t,i,j,n,q,x,y,k;

    cin>>n;

    cout<<n+n*n+n*n*n<<endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
inline int read(){
	char ch=getchar();int x=0,f=1;
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while('0'<=ch&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
int main() {
	//freopen("a.in","r",stdin);
	int n=read();
	long long Ans=0;
	bool flag=0;
	int mn=2e9;
	rep(i,1,n){
		int x=read(),y=read();
		if(x!=y)flag=true;
		Ans+=x;
		if(x>y)mn=min(mn,y);
	}
	if(!flag)printf("0");
	else printf("%lld\n",Ans-mn);
}

Measured memory_bytes: 256