akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
  int i,j,n;
  int temp,A[100],ch=0;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }
  
  for(i = n-1 ; i > 0 ; i--){
    for(j = n-1 ; j > 0 ; j--){
      if(A[j] < A[j-1]){
	temp = A[j];
	A[j] = A[j-1];
	A[j-1] = temp;
	ch++;
      }
    }
  }
  
  for(j = 0 ; j < n ; j++){
    if(j != n-1){
      printf("%d ",A[j]);
    }
    else if(j == n-1){
      printf("%d\n",A[j]);
    }
  }
  printf("%d\n",ch);
  
  return 0;
}



Measured memory_bytes: 2128
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Main tr = new Main();
		tr.test(sc);
		sc.close();
	}
	
	void test(Scanner sc){
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] a = new int[N+1];
		a[1] = sc.nextInt();
		int here=-1;
		for (int i = 2; i <= N; i++) {
			a[i] = sc.nextInt();
			if(a[i-1]<= 0 && a[i] > 0){
				here = i;
			}
		}
		int out=0;
		if(here==-1){
			// all in one side
			if(a[1]>=0){
				out += a[K]; 
			}else{
				out += (-1 * a[N+1-K]);
			}
		}else{
			out  = Integer.MAX_VALUE;
			here--;
			int left = here>K?here-1-K:1;
			int right = left + K -1;
			here++;
			while(left<=here && right <= N){
				int dist = a[right]-a[left];
				int addme=0;
				if(a[left]<0){
					addme = (-1 * a[left]);
				}else{
					addme =a[left];
				}
				
				addme = addme>a[right]?a[right]:addme;
				
				dist+=addme;
				if(out>dist){
					out=dist;
				}
				left++;
				right++;
			}
		}
		System.out.println(out);
	}
}


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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#else
#define TEST(n) ((void)0)
#endif

using namespace std;

const int MOD = 1e9 + 7;
int DP[2][100];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt", "r", stdin));
	TEST(freopen("output.txt", "w", stdout));
	TEST(freopen("debug.txt", "w", stderr));
	string K;
	int D, d;
	cin >> K >> D;
	for (int i = 0; i < K[0] - '0'; i++) DP[0][i%D]++;
	d = (K[0] - '0') % D;
	for (int i = 1; i < K.size(); i++) {
		int c = K[i] - '0';
		for (int j = 0; j < D; j++) DP[i & 1][j] = 0;
		for (int j = 0; j < c; j++) DP[i & 1][(j + d) % D] = (DP[i & 1][(j + d) % D] + 1) % MOD;
		for (int j = 0; j < D; j++) {
			for (int k = 0; k < 10; k++) {
				DP[i & 1][(j + k) % D] = (DP[i & 1][(j + k) % D] + DP[(i - 1) & 1][j]) % MOD;
			}
		}
		d = (d + K[i] - '0') % D;
	}
	cout << (DP[(K.size() - 1) & 1][0] + (d == 0) + MOD - 1) % MOD << '\n';
	return 0;
}

Measured memory_bytes: 256
import java.lang.Math

fun main(args: Array<String>) {
    val (N, C) = readInputLine().split(" ").let { Pair(it[0].toInt(), it[1].toLong()) }

    val sushi = Array(N) {
        readInputLine().split(" ").let {
            Pair(it[0].toLong(), it[1].toLong())
        }
    }

    val clockwiseMax = LongArray(N)

    var currentCal = sushi[0].second
    clockwiseMax[0] = Math.max(0L, currentCal - sushi[0].first)

    for (i in 1 until N) {
        currentCal += sushi[i].second
        clockwiseMax[i] = Math.max(clockwiseMax[i - 1], currentCal - sushi[i].first)
    }

    val unclockwiseMax = LongArray(N)

    currentCal = sushi[N - 1].second
    unclockwiseMax[N - 1] = Math.max(0L, currentCal - (C - sushi[N - 1].first))

    for (i in N - 2 downTo 0) {
        currentCal += sushi[i].second
        unclockwiseMax[i] = Math.max(unclockwiseMax[i + 1], currentCal - (C - sushi[i].first))
    }

    var ans = 0L
    ans = Math.max(ans, clockwiseMax[N - 1])
    ans = Math.max(ans, unclockwiseMax[0])

    for (i in 0 until N - 2) {
        ans = Math.max(ans, clockwiseMax[i] + unclockwiseMax[i + 1] - sushi[i].first)
    }
    for (i in N - 1 downTo 1) {
        ans = Math.max(ans, unclockwiseMax[i] + clockwiseMax[i - 1] - (C - sushi[i].first))
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 62272
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
String s=sc.next();
if(s.length()==2){out.println(0);
}else{
    for (int i = 1; i <s.length(); i++) {
    String temp1=s.substring(0,(s.length()-i*2)/2);
    String temp2=s.substring((s.length()-i*2)/2,s.length()-i*2);
    if(temp1.equals(temp2)){
        out.println(2*temp1.length());
        break;
    }
    }
}
}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

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

int main()
{
    long long N; cin >> N;
    vector<long long> X, CP_X;
    rep (i, 0, N) {
        long long in; cin >> in;
        X.push_back(in); CP_X.push_back(in);
    }

    sort(CP_X.begin(), CP_X.end());
    long long med_a = CP_X[N/2-1];
    long long med_b = CP_X[N/2];
    rep (i, 0, N) {
        if (X[i] < med_b) cout << med_b << endl;
        else cout << med_a << endl;
    }
}

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

int main() {
  bool is_not_prime[100001];
  for (int i=2; i<=100000; i++) {
    if (!is_not_prime[i]) {
      for (int j=i+i; j<=100000; j+=i) {
        is_not_prime[j]=true;
      }
    }
  }
  int count[100002]={0};
  for (int i=3; i<=100000; i+=2) {
    if (!is_not_prime[i] && !is_not_prime[(i+1)/2]) {
      count[i]++;
    }
  }
  for (int i=3; i<=100000; i++) {
    count[i]+=count[i-1];
  }
  int N;
  scanf("%d",&N);
  int L, R;
  while (N--) {
    scanf("%d %d",&L,&R);
    printf("%d\n",count[R]-count[L-1]);
  }
  return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
int pw(int n,int k){
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}
//main
signed main(){
  int N,K;cin>>N>>K;
  std::vector<int> v(N),w(N),nk;
  for(int i=0;i<N;i++)cin>>w[i]>>v[i];
  int a=0,b=1;
  nk.push_back(K);
  while(b<=K){
    int res=0;
    if(K>>a&1){
      res=(K&(~(b*2-1)))|(b-1);
      //cout<<a<<" "<<b<<" "<<res<<endl;
      nk.push_back(res);
    }
    a++;b*=2;
  }
  int fans=0;
  for(int p:nk){
    int ans=0;
    for(int i=0;i<N;i++)if((p|w[i])<=p)ans+=v[i];
    //cout<<p<<" "<<ans<<endl;
    fans=max(ans,fans);
  }
  cout<<fans<<endl;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
int main(){
	char s[101]="",ss[101]="",sss[101]="";
	fscanf(stdin, "%s %s %s", s,ss,sss);
	fprintf(stdout, "%c%c%c\n", s[0],ss[0],sss[0]);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,i,j;
	for(i=1;i<10;i++){
		for(j=1;j<10;j++){
			a=i*j;
			printf("%dx%d=%d\n",i,j,a);
		}
	}
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;

using namespace std;
using ll = mp::cpp_int;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

// #define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// debug
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}
#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif

template <typename T> T gcd(T m, T n) {
  if (m < n)
    return gcd(n, m);
  if (n == 0)
    return m;
  return gcd(n, m % n);
}

int main() {
  int N; ll M;
  cin >> N >> M;

  ll lcm = 1;
  ll A[N];
  int d[N];
  rep(i, N) {
    cin >> A[i];
    ll a = A[i] / 2;
    ll two = 1;
    rep(j, 100) {
      if (A[i] % two != 0) {
        d[i] = j;
        break;
      }
      if (A[i] < two)
        break;
      two *= 2;
    }
    lcm *= a / gcd(lcm, a);
    if (lcm > M) {
      cout << 0 << endl;
      return 0;
    }
  }
  rep(i, N-1) {
    if (d[i] != d[i+1]) {
      cout << 0 << endl;
      return 0;
    }
  }

  cout << ((ll)M / lcm + 1) / 2 << endl;

  return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int n,m,sx,sy,num;
int grd[11][11];
const int mx[]={1,0,-1,0},my[]={0,1,0,-1};
int dfs(int x,int y){
	if(num==0)	return (x==sx||y==sy);
	int ans=0;
	grd[y][x]=0;
	rep(i,4){
		int tx=x+mx[i],ty=y+my[i];
		while(0<=tx&&tx<n&&0<=ty&&ty<m){
			if(grd[ty][tx]==1){
				num--;
				ans+=dfs(tx,ty);
				num++;
				break;
			}
			tx+=mx[i];	ty+=my[i];
		}
	}
	grd[y][x]=1;
	return ans;
}

int main(){
	while(true){
		cin>>n>>m;
		if(n==0)	return 0;
		memset(grd,0,sizeof(grd));
		num=0;
		rep(i,m)	rep(j,n){
			cin>>grd[i][j];
			if(grd[i][j]==2){
				sx=j,sy=i;
			}
			else if(grd[i][j]==1)	num++;
		}
		cout<<dfs(sx,sy)<<endl;
	}
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CsharpSpiral {
    partial class Program {
        static void Main(string[] args) {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }
        public void Solve(ConsoleInput cin) {
            var X = new Stack<int>();
			foreach(var token in cin.ReadLine.Split(' ')) {
				int i;
				if(int.TryParse(token, out i)) {
					X.Push(i);
				} else {
					var x2 = X.Pop();
					var x1 = X.Pop();
					switch(token[0]) {
						case '+':
							X.Push(x1 + x2);
							break;
						case '-':
							X.Push(x1 - x2);
							break;
						case '*':
							X.Push(x1 * x2);
							break;
					}
				}
			}
			Console.WriteLine(X.Pop());
        }
    }

    static class ExtendClass {
        public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
    }

    class ConsoleInput {
        private readonly TextReader _stream;
        private readonly char _separator = ' ';
        private readonly Queue<string> inputStream;
        public ConsoleInput(TextReader stream, char separator = ' ') {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read {
            get {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) {
            var ret = new string[N];
            for(long i = 0; i < N; ++i)
                ret[i] = Read;
            return ret;
        }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }

}



Measured memory_bytes: 20404
import math
N = int(input())
x = []
y = []

for i in range(N):
    xi, yi = map(int, input().split(" "))
    x.append(xi)
    y.append(yi)


route = 0
for i in range(N):
    for j in range(i, N):
        route += math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)

# print(route * math.factorial(N-1) * 2 / math.factorial(N))
print(route * 2 / N)


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

#define rep(i, n) for(int i=0;i<n;i++)
#define IOS() ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define INT_MINI -987654321
#define INT_MAXI 987654321
#define ABS(X) ((X) < 0 ? -(X) : (X))


using namespace std;

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

char a[103];

void input() {

    cin >> a;

}

int process(int left, int right, int lv) {

    int t_left = left;
    int t_right = right;

    while(left < right) {
       if(a[left++] != a[right--]) {
           return 0;
       }
    }


    if(left == right && lv == 0) {
        int t1 = process(t_left, (t_right-1)/2, 1);
        int t2 = process((t_right+3)/2, t_right, 1);
        if(t1 && t2) return 1;
        else return 0;
    }

    return 1;
}

int main() {

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    input();
    if(process(0, strlen(a)-1, 0)) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))
def plis(a): return " ".join(list(map(str, a)))

N = ri()
A = rli()
A.sort(reverse=True)

st = -1
l1 = 0
l2 = 0
for i in A:
    if i == st:
        if(l1 != 0):
            l2 = i
            break
        else:
            l1 = i
        st = -1
    else:
        st = i
print(l1*l2)

Measured memory_bytes: 14556
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>

using namespace std;

int main()
{
    int N;
    cin >> N;
    int* A = new int[N];
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    std::sort(A, A + N);
    std::reverse(A, A + N);
    uint64_t comfort = A[0];
    for (int i = 2; i < N; ++i) {
        comfort += A[(i) / 2];
    }
    cout << comfort << endl;
    return 0;
}


Measured memory_bytes: 4332
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<pair<int,int> > A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i].second >> A[i].first;
		A[i].second *= -1;
	}
	sort(A.begin(), A.end());
	for (int i = 0; i < N; i++) {
		A[i].second *= -1;
		swap(A[i].first, A[i].second);
	}
	vector<int> X(N);
	vector<int> Y(N);
	int INF = (int)1 << 60;
	int mxL = -1;
	int mnR = INF;
	for (int i = N - 1; i >= 0; i--) {
		mnR = min(mnR, A[i].second);
		mxL = max(mxL, A[i].first);
		X[i] = max((int)0, mnR - mxL + 1);
	}


	mxL = -1;
	mnR = INF;
	for (int i = 0; i < N; i++) {
		mnR = min(mnR, A[i].second);
		mxL = max(mxL, A[i].first);
		Y[i] = max((int)0, mnR - mxL + 1);
	}

	for (int i = 1; i < N; i++) {
		res = max(res, Y[i - 1] + X[i]);
	}
	vector<int> Xs;
	vector<int> Ys;
	for (int i = 0; i < N; i++) {
		Xs.push_back(A[i].first);
		Ys.push_back(A[i].second);
	}
	sort(Xs.begin(), Xs.end());
	sort(Ys.begin(), Ys.end());
	//res = 0;
	for (int i = 0; i < N; i++) {
		int ans = A[i].second - A[i].first + 1;
		int r = Ys[0];
		int l = Xs[N - 1];
		if (r == A[i].second) {
			r = Ys[1];
		}
		if (l == A[i].first) {
			l = Xs[N - 2];
		}
		ans += max((int)0, r - l + 1);
		res = max(res, ans);
	}

	cout << res << endl;
}

Measured memory_bytes: 5228
PROGRAM ATCODER

implicit none
integer :: a(5),k,i,j

do i = 1,5
  read*, a(i)
end do

read*, k

do i = 1, 5, 1
  do j = 1, 5, 1
    if ( i == j ) cycle
    if ( abs(a(i)-a(j)) > k ) then
      print'(a)', ':(' 
      stop
    end if
  end do
end do

print'(a)', 'Yay!'

END PROGRAM ATCODER

Measured memory_bytes: 768
a, b, c, K = map(int, input().split())

res = 'Unfair'
if K % 2 == 0:
    if abs(a - b) <= 10 ** 18:
        res = a - b
else:
    if abs(a - b) <= 10 ** 18:
        res = b - a
print(res)


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

using namespace std;
typedef long long ll;

const int N = 200'010;
ll a[N], dp[3][N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    dp[0][1] = a[1];
    dp[1][2] = a[2];
    if (n >= 3) {
        dp[0][3] = a[1] + a[3];
        dp[2][3] = a[3];
    }
    for (int i = 4; i <= n; i++) {
        if (i % 2 == 1) {
            dp[0][i] = dp[0][i - 2] + a[i];
            dp[2][i] = dp[2][i - 2] + a[i];
            dp[2][i] = max(dp[2][i], dp[1][i - 3] + a[i]);
            dp[2][i] = max(dp[2][i], dp[0][i - 4] + a[i]);
        } else {
            dp[1][i] = dp[1][i - 2] + a[i];
            dp[1][i] = max(dp[1][i], dp[0][i - 3] + a[i]);
        }
    }
    ll ans;
    if (n % 2 == 0) {
        ans = max(dp[0][n - 1], dp[1][n]);
    } else {
        ans = max(dp[0][n - 2], dp[1][n - 1]);
        ans = max(ans, dp[2][n]);
    }
    printf("%lld\n", ans);
}


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

int main() {
  int N;
  cin >> N;
  vector<int> t(N+1), x(N+1), y(N+1);  
  for(int i = 0; i < N; i++){
    cin >> t.at(i+1) >> x.at(i+1) >> y.at(i+1);
  }
  
  for(int i = 0; i < N; i++){
    int dt, dx, dy;
    dt = t.at(i+1)-t.at(i);
    dx = x.at(i+1)-x.at(i);
    dy = y.at(i+1)-y.at(i);
    if(dx + dy > dt || (dt-dx-dy)%2 == 1){
      cout << "No" << endl;
      break;
    }
    else if(i == N-1){
      cout << "Yes" << endl;
    }
  }
}

Measured memory_bytes: 1408
#include<stdio.h>
int main()
{
    int n,i,f=0;
    scanf("%d",&n);
    int num[n+1];
    for(i=1;i<=n;i++)
    {
        scanf("%d",&num[i]);
    }
    for(i=1;i<=n;i++)
    {
        if(num[i]!=i) f++;
    }
    if(f==0 || f==2) printf("YES");
    else printf("NO");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
    ll n, ans1 = 0, ans2 = 0;
    cin >> n;
    while(n/10!=0){
        ans1 += 9;
        ans2 += n%10;
        n/=10;
    }
    cout<<max(ans1 + n - 1, ans2 + n) << endl;
    return 0;
}

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

int n;
int A[3000];

long long int dp[3001][3001];

int main(){
  scanf("%d", &n);
  for(int i = 0; i < n; i++) scanf("%d", A+i);
  for(int i = n-1; i >= 0; i--){
    for(int j = i + 1; j <= n; j++){
      dp[i][j] = std::max(A[j-1] - dp[i][j-1], A[i] - dp[i+1][j]);
    }
  }
  printf("%lld\n", dp[0][n]);
  return 0;
}


Measured memory_bytes: 69888
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
	int n;

	while (scanf("%d", &n), n) {
		int s[5001];

		for (int i = 1; i <= n; ++i) {
			int a; scanf("%d", &a);
			s[i] = a + s[i - 1];
		}

		int ma = -100000;

		for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
			ma = max(ma, s[i] - s[j - 1]);
		}

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

Measured memory_bytes: 1048
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ON			1										// 汎用フラグ - ON
#define D_OFF			0										// 汎用フラグ - OFF
#define D_BUILD_MAX		15										// 最大建物数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1Build[D_BUILD_MAX];								// 建物
static int siBCnt;												// 建物数
static int siWCnt;												// 見える建物数
static long long slMin;											// 最小金額

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// 最小金額 - セット
int
fSetMin(
	int *pipWatch				// <I> 見える建物
)
{
	int i;

	// 合計金額 - 取得
	int liNow = si1Build[0];
	long long llSum = 0;
	for (i = 1; i < siBCnt; i++) {
		if (si1Build[i] > liNow) {					// 以前より大きい
			liNow = si1Build[i];
		}
		else {										// 以前より小さい
			if (pipWatch[i] == D_ON) {					// 見える建物
				int liUp = liNow - si1Build[i] + 1;
				llSum += liUp;
				liNow = si1Build[i] + liUp;
			}
		}
	}

	// 最小金額 - 更新
	if (slMin > llSum) {
		slMin = llSum;
	}

	return 0;
}

// 見える建物 - 選択
int
fSelBuild(
	int piBNo					// <I> 建物
	, int *pipWatch				// <I> 見える建物
	, int piWCnt				// <I> 見える建物数
)
{
	// 終了チェック
	if (piWCnt == siWCnt) {
		fSetMin(pipWatch);
		return 0;
	}

	// 選択 - あり
	pipWatch[piBNo] = D_ON;
	fSelBuild(piBNo + 1, pipWatch, piWCnt + 1);
	pipWatch[piBNo] = D_OFF;

	// 選択 - なし
	if (siBCnt - piBNo > siWCnt - piWCnt) {		// 残建物数 > 必要選択数
		fSelBuild(piBNo + 1, pipWatch, piWCnt);
	}

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	int i;
	char lc1Buf[1024], lc1Out[1024];

	// データ - 初期化
	slMin = LLONG_MAX;											// 最小金額

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 建物数・見える建物数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siBCnt, &siWCnt);

	// 建物 - 取得
	for (i = 0; i < siBCnt; i++) {
		fscanf(szpFpI, "%d", &si1Build[i]);
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 見える建物 - 選択
	int li1Watch[D_BUILD_MAX];
	memset(li1Watch, D_OFF, sizeof(li1Watch));
	fSelBuild(1, li1Watch, 1);

	// 結果 - セット
	sprintf(lc1Out, "%lld\n", slMin);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n, m, x = map(int, input().split())
a = map(int, input().split())
left = 0
right = 0
for aa in a:
    if aa < x:
        left += 1
    else:
        right += 1
print(min(left, right))


Measured memory_bytes: 3832
N, M = map(int, input().split())

abLst = [list(map(int, input().split())) for i in range(N)]
cdLst = [list(map(int, input().split())) for i in range(M)]

ansLst = [0] * N

for i in range(N):
    tmpMin = 100000000000
    ans = 0
    for j in range(M):
        tmp = abs(abLst[i][0] - cdLst[j][0]) + abs(abLst[i][1] - cdLst[j][1])
        if tmpMin > tmp:
            tmpMin = tmp
            ans = j + 1
    ansLst[i] = ans

for i in ansLst:
    print(i)

Measured memory_bytes: 3064
#pragma region 
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<cstring>
#include<string>
typedef long long ll;
template <typename T>void read(T &x){x=0;char ch=getchar();ll f=1;while(!isdigit(ch)){if(ch=='-')f*=-1;ch=getchar();}while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}x*=f;}
#define IO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
#pragma endregion
const int maxn = 1e5 + 5;
bool vis[maxn];

int main() {
    IO;
    int n, k;
    cin >> n >> k;
    memset(vis, 0, sizeof(vis));
    for (int i = 1; i <= k;++i) {
        int d;
        cin >> d;
        while (d--) {
            int x;
            cin >> x;
            vis[x] = 1;
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n;++i) 
        if (!vis[i])
            ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3764
use std::io::*;
use std::str::FromStr;

fn main(){
    let (n,a,b) = (read::<i32>(),read::<i32>(),read::<i32>());
    let mut r = 0;
    for i in 1..n+1{
        let k = kakuinowa(i);
        if a <= k && k <= b{
            r += i;
        }
    }
    println!("{}",r)
}
fn kakuinowa(num : i32) -> i32{
    let nums = format!("{}", num).chars().collect::<Vec<char>>();
    let mut r = 0;
    for i in nums{
        let k : i32 = i as i32 - 48;
        r += k;
    }
    r
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder01
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            string[] input = Console.ReadLine().Split();
            int[] T = new int[N];

            for (int i = 0; i < N; i++) T[i] = int.Parse(input[i]);

            //2を含む数
            int x2 = 0;
            int y4 = 0;
            for (int i = 0; i < N; i++)
            {
                //if (T[i] == 2)
                //{
                //    x2++;
                //    continue;
                //}
                //if ((T[i] % 2) == 0)
                //{
                //    y4++;
                //}
                if ((T[i] % 4) == 0)
                {
                    y4++;
                    continue;
                }
                if ((T[i] % 2) == 0)
                {
                    x2++;
                }

            }
            //if (x2 != 0) x2--;
            //string out01 = "No";
            //if ((y4 == 0) && (x2 == N-1))
            //{
            //    out01 = "Yes";
            //}
            //else if ((y4 == 1) && (y4 * 3 + x2 >= N))
            //{
            //    out01 = "Yes";
            //}
            //else if((y4 > 1) && (y4 * 2 + 1 + x2 >= N))
            //{
            //    out01 = "Yes";
            //}
            if (x2 != 0) x2--;
            string out01 = "No";
            if ((y4 == 0) && (x2 +1 == N))
            {
                out01 = "Yes";
            }
            else if ((y4 >= 1) && (y4 * 2 + 1 + x2 >= N))
            {
                out01 = "Yes";
            }
            Console.WriteLine(out01);
        }
    }
}

Measured memory_bytes: 20448
H,W,A,B=map(int,input().split())
mat=[]
for _ in range(B):
  r='0'*A+'1'*(W-A)
  mat.append(r)

for _ in range(H-B):
  r='1'*A+'0'*(W-A)
  mat.append(r)

for i in range(H):
  print(mat[i])

Measured memory_bytes: 4980
#include <iostream>
using namespace std;
int main ()
{
  int k;
  int s;
  cin >> k;
  cin >> s;
  int m=0;
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
      if (0 <= s - (x + y) && s - (x + y) <= k){
          m++;}}}
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
	int n,k,i;
	cin>>n>>k;
	vector<int> v;
	for(i=0;i<n;i++)
	{
		int x;
		cin>>x;
		v.push_back(x);
	}
	int dp[k+1]={0};
	for(i=0;i<=k;i++)
	{
		for(int x:v)
		{
			if(i>=x && !dp[i-x])
				dp[i]=1;
		}
	}
	if(dp[k])cout<<"First\n";
	else cout<<"Second\n";

}


Measured memory_bytes: 640
<?php
fscanf(STDIN, "%d %d", $n, $m);
$ans = 0;
for($i = 0; $i < $n; $i++){
    for($j = 0; $j < $n; $j++){
        $graph[$i][$j] = false;
    }
}

function dfs($a){
    global $vis;
    global $n;
    global $graph;

    if($vis[$a]) return;
    $vis[$a] = true;
    for($i = 0; $i < $n; $i++){
        if($graph[$a][$i]) dfs($i);
    }
}

for($i = 0; $i < $m; $i++){
    fscanf(STDIN, "%d %d", $a[$i], $b[$i]);
    $a[$i]--;
    $b[$i]--;
    $graph[$a[$i]][$b[$i]] = $graph[$b[$i]][$a[$i]] = true;
}

for($i = 0; $i < $m; $i++){
    $graph[$a[$i]][$b[$i]] = $graph[$b[$i]][$a[$i]] = false;
    for($j = 0; $j < $n; $j++) $vis[$j] = false;
    dfs(0);
    if(in_array(false, $vis, true)) $ans++;
    $graph[$a[$i]][$b[$i]] = $graph[$b[$i]][$a[$i]] = true;
}

print $ans;

Measured memory_bytes: 4604
#include<stdio.h>
int main()
{
  int sum=0,one,i;
  while(1){
    scanf("%d",&sum);
    if(sum==0)break;
    for(i=0;i<9;i++){
      scanf("%d",&one);
      sum-=one;
    }
    printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 1028
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n, l[SIZE];

  scanf("%d", &n);
  for(int i=0;i<n;i++) scanf("%d", l+i);

  sort(l, l+n);

  int sum = 0;
  for(int i=0;i<n-1;i++) sum += l[i];

  if (sum > l[n-1]) {
    puts("Yes");
  } else {
    puts("No");
  }

  return 0;
}


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

int main() {
    int n;
    scanf("%d", &n);
    vector<int> vec(n);
    int s1=0, s2=0;
    rep(i,n) {
        scanf("%d", &vec.at(i));
        s2 += vec.at(i);
    }
    int ans = s2-s1;
    rep(i,n) {
        s1 += vec.at(i);
        s2 -= vec.at(i);
        ans = min(ans, abs(s1-s2));
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,k,n;
    int p[1000];
    int l=0;
    cin >> a >> b >>k;
    
    n = max(a,b);
    for(int i=1;i<n+1;i++){
        if(a%i == 0 && b%i == 0){
           p[l]= i;
           l++;
        }
    }
    cout << p[l-k] << endl;
    
    
    
}


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

typedef long long ll;

int main()
{
    ll i,j,k,l;
    ll v,e;
    cin >> v >> e;
    vector<vector<ll>> graph(v, vector<ll>(v, 1e18));
    for(i = 0;i < v;++i){
        graph.at(i).at(i) = 0;
    }
    for(i = 0;i < e;++i){
        ll s,t,d;
        cin >> s >> t >> d;
        graph.at(s).at(t) = d;
    }
    bool flag = true;
    for(l = 0;l < 2;++l){
        for(k = 0;k < v;++k){
            for(i = 0;i < v;++i){
                for(j = 0;j < v;++j){
                    ll cost = graph.at(i).at(k) + graph.at(k).at(j);
                    if(cost < graph.at(i).at(j)){
                        if(l == 1){
                            flag = false;
                        }else{
                            graph.at(i).at(j) = cost;
                        }
                    }
                }
            }
        }
    }
    if(flag){
        for(i = 0;i < v;++i){
            for(j = 0;j < v;++j){
                ll cost = graph.at(i).at(j);
                if(j != v-1){
                    if(cost >= 1e13){
                        cout << "INF" << " ";
                    }else{
                        cout << cost << " ";
                    }
                }else{
                    if(cost >= 1e12){
                        cout << "INF" << endl;
                    }else{
                        cout << cost << endl;
                    }
                }
            }
        }
    }else{
        cout << "NEGATIVE CYCLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 3244
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(i64, N, M);
    var(string, s);

    const auto findNext = [&](int cur) {
        for (int j = M; j > 0; --j) {
            if (cur - j < 0) continue;
            if (s[cur - j] == '0') return cur - j;
        }
        return -1;
    };

    vector<int> ans;
    ans.reserve(N);

    int cur = N;
    while (cur != 0) {
        const int nxt = findNext(cur);
        if (nxt == -1) {
            print(-1);
            return 0;
        }
        ans.push_back(cur - nxt);
        cur = nxt;
    }

    reverse(all(ans));
    print(ans);

    return 0;
}


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

const int N = 2e5 + 5;

queue <int> q;

int du[N][2], n, m, x, y;

bool vis[N];

vector <int> G[N];

char s[N];

main() {
	scanf("%d%d", &n, &m);
	scanf("%s", s + 1);
	for(int i = 1; i <= m; ++ i) {
		scanf("%d%d", &x, &y);
		++ du[x][s[y] - 'A'];
		G[y].push_back(x);
		++ du[y][s[x] - 'A'];
		G[x].push_back(y);
	}
	for(int i = 1; i <= n; ++ i) {
		if(!du[i][0] || !du[i][1]) {
			q.push(i);
			vis[i] = 1;
		}
	}
	while(!q.empty()) {
		int ind = q.front();
		q.pop();
		for(int i = 0; i < (int) G[ind].size(); ++ i) {
			if(-- du[G[ind][i]][s[ind] - 'A'] == 0) {
				if(!
				vis[G[ind][i]]) {
					vis[G[ind][i]] = 1;
					q.push(G[ind][i]);
				}
			}
		}
	}
	for(int i = 1; i <= n; ++ i) if(!vis[i]) return 0 * puts("Yes");
	puts("No");
}

Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    string s;
    cin>>n;
    for (int i=0;i<n;i++) {
        long long int count=0;
        cin>>s;
        while (1) {
            if (count>1000000000) {
                cout<<-1<<endl;
                break;
            } else {
                if (s.size()==1) {
                    cout<<count<<endl;
                    break;
                } else {
                    long long int max=0;
                    for (int i=1;i<s.size();i++) {
                        string one=s.substr(0,i);
                        string another=s.substr(i,s.size()-i);
                        long long int tmp=stoi(one)*stoi(another);
                        if (tmp>max) {
                            max=tmp;
                        }
                    }
                    s=to_string(max);
                    //cout<<s<<endl;
                    count++;
                }
            }
        }
    }
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
const double pi=acos(-1);
int n,l;
double t[3003],x,y;
inline void add(double rad,int cnt)
{
    x+=cos(rad)*cnt;
    y+=sin(rad)*cnt;
}
int main()
{
    scanf("%d%d",&n,&l);
    for(int i=0;i<n;i++) scanf("%lf",&t[i]),t[i]=t[i]/l*2*pi;
    sort(t,t+n);
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
		{
            double m1=(t[i]+t[j])/2,m2=m1+pi;
            add(m1,i+n-j-1);
            add(m2,j-i-1);
        }
    double all=1.0*n*(n-1)*(n-2)/6;
    x/=all,y/=all;
    printf("%.11f %.11f\n",x,y);
}

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

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let (n, m) = input_tuple();
    if n == m {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

int a[200020][2];
int main(void){
    int n,m;cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        int x,y;cin >> x >> y;
        if(x == 1)a[y][0]++;
        if(x == n)a[y][1]++;
        if(y == 1)a[x][0]++;
        if(y == n)a[x][1]++;
    }

    for (int i = 0; i < n; ++i)
    {
        if(a[i][0] and a[i][1]){
            printf("POSSIBLE\n");return 0;
        }
    }
    printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <map>
#include <deque>
#define MAX_N 100
#define MAX_T 200
#define INF 1000000000000
typedef long long ll;
using namespace std;

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  if((b-a)%2==0)cout<<"Alice"<<endl;
  else cout<<"Borys"<<endl;    
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a, b;
    scanf("%d %d",&a, &b);
    int sum, dif, mult;
    sum = a + b;
    dif = a - b;
    mult = a * b;
    if(sum >= dif && sum >= mult)
        printf("%d\n", sum);
    else
        if(dif >= mult)
            printf("%d\n", dif);
        else
            printf("%d\n", mult);
    

    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int cost[20][20];
int INF = 1e9;
int n;

int dikst(int s, int g)
{
    bool used[n] = {};
    int d[n];
    rep(i, n) d[i] = INF;
    d[s] = 0;
    while (1)
    {
        int minv = INF;
        int u;
        rep(i, n)
        {
            if (!used[i] && d[i] < minv)
            {
                minv = d[i];
                u = i;
            }
        }
        if (minv == INF)
            break;

        used[u] = 1;
        rep(i, n)
        {
            if (!used[i] && cost[u][i] != INF && d[i] > cost[u][i] + d[u])
                d[i] = cost[u][i] + d[u];
        }
    }
    return d[g];
}

int main()
{
    int m;
    cin >> n >> m;
    rep(i, 20) rep(j, 20) cost[i][j] = INF;
    char ch;
    rep(i, m)
    {
        int a, b, c, d;
        cin >> a >> ch >> b >> ch >> c >> ch >> d;
        --a, --b;
        cost[a][b] = c;
        cost[b][a] = d;
    }

    int s, g, v, p;
    cin >> s >> ch >> g >> ch >> v >> ch >> p;
    --s, --g;

    OP(v - p - dikst(s, g) - dikst(g, s));
    return 0;
}


Measured memory_bytes: 3012
#include<iostream>
#include<string>
#include<cstdio>
#include <cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
const int inf = 1e+6;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int N; cin >> N;
    int Ma, Mb; cin >> Ma >> Mb;
    int a[44], b[44], c[44];
    rep(i, N) cin >> a[i] >> b[i] >> c[i];
    int dp[44][440][440];
    memset(dp, inf, sizeof(dp));
    dp[0][0][0] = 0;
    rep(i, N) {
        rep(ca, 410) {
            rep(cb, 410) {
                dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb]);
                if(ca - a[i] >= 0 && cb - b[i] >= 0) dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca - a[i]][cb - b[i]] + c[i]);
            }
        }
    }
    int ans = inf;
    rep1(ca, 410) {
        rep1(cb, 410) {
            if(ca * Mb == cb * Ma) ans = min(ans, dp[N][ca][cb]);
        }
    }
    if(ans == inf) cout << -1 << endl;
    else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 33536
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 100200;
int n,b[N][18];Vi e[N];
void dfs(int u, int fa){
	int mx=0;
	rep(i,0,SZ(e[u])-1)if(e[u][i]!=fa){
		dfs(e[u][i],u);int v=e[u][i];
		rep(j,0,17)umax(mx,b[u][j]+b[v][j]==2?j:0),b[u][j]|=b[v][j];
	}
	mx++;while(b[u][mx])mx++;
	b[u][mx]=1;rep(i,0,mx-1)b[u][i]=0;
}
int main() {
	read(n);rep(i,1,n-1){int u,v;read(u);read(v);e[u].pb(v);e[v].pb(u);}
	dfs(1,0);int res=0;rep(i,0,17)if(b[1][i])res=i;
	cout<<res-1;
	return 0;
}


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

typedef long long ll;

const ll MOD = 1000000007;

ll mod_add(ll a, ll b){
    return ((a % MOD) + (b % MOD)) % MOD;
}

ll mod_sub(ll a, ll b){
    return ((a + MOD) - b) % MOD;
}
 
ll mod_mul(ll a, ll b){
    return ((a % MOD) * (b % MOD)) % MOD;
}

ll mod_pow(ll x, ll r){
    if (r == 0) return 1;

    else if (r == 1) return x % MOD;

    else if (r % 2 == 0){
        ll t = mod_pow(x, r/2) % MOD;
        return mod_mul(t, t);
    }

    else{
        ll t = mod_pow(x, r/2) % MOD;
        ll k = mod_mul(t, t);
        return ((k % MOD) * (x % MOD)) % MOD;
    }
}

ll mod_div(ll a, ll b){
    return mod_mul(a, mod_pow(b, MOD - 2));
}

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

    ll s;
    cin >> s;
    
    vector<ll> dp(s+20, 0);
    dp[3] = dp[4] = dp[5] = 1;
    const int mod = 1000000007;
    for(ll i = 6; i < s+20; ++i){
        ll v = 0;
        for(ll j = i-3; j >= 6; --j){
            v = (v + mod_sub(dp[j], 1)) % mod;
        }
        dp[i] = (i-4 + v) % mod;
    }

    cout << dp[s] << endl;

    return 0;
}

Measured memory_bytes: 3664
X, n = map(int, input().strip().split())
if not n:
    print(X)
    exit()

L = list(map(int, input().strip().split()))
dist=0
while True:
    if X-dist not in L:
        ans=X-dist
        break
    elif X+dist not in L:
        ans=X+dist
        break
    dist+=1
print(ans)

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

int main()
{

    //  #ifndef oj
    //freopen("in", "r", stdin);
    //freopen("out.txt","w",stdout);
    //#endif
    // system("cls");
    //getchar();

    string s;
    cin>>s;
    string s1;
    s1=s;
    int cnt=0;
    reverse(s.begin(),s.end());
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=s1[i])
            cnt++;
    }
    cout<<cnt/2<<endl;

}


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

using namespace std;

int main()
{
    string S; long long K;
    cin >> S >> K;
    for(int i = 0; i < min((long long)S.size(), K); i++) {
        if(S[i] >= '2') { cout << S[i] << endl; return 0; }
    }
    cout << '1' << endl;
    return 0;
}

Measured memory_bytes: 256