akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,A=0,B=0; cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) {
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  
  for(int i=0;i<n;i+=2) {
    A+=a.at(i);
  }
  for(int i=1;i<n;i+=2) {
    B+=a.at(i);
  }
  if(A<B){
    cout << B-A << endl;
  }
  else {
    cout << A-B << endl;
  }
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll a, b, c;
    cin >> a >> b >> c;

    if(a+b == c){
        cout << "Yes" << endl;
        return 0;
    }
    if(b+c == a){
        cout << "Yes" << endl;
        return 0;
    }
    if(c+a == b){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3580
import java.util.Arrays;
import java.util.Scanner;

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

		char[] sChar = s.toCharArray();
		char[] tChar = t.toCharArray();

		Arrays.sort(sChar);
		Arrays.sort(tChar);

		String sString = String.valueOf(sChar);
		StringBuffer sb = new StringBuffer(String.valueOf(tChar));
		String tString = sb.reverse().toString();

		System.out.println(sString.compareTo(tString) < 0 ? "Yes" : "No");
	}
}


Measured memory_bytes: 23764
//ABC - 143
//19 - 10 - 2019
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define MOD 1000000007

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i < n;i++)
		cin >> a[i];
	sort(a.begin(),a.end());
	ll ans = 0;
	for(int i = 0;i < n;i++){
		for(int j = i + 1;j < n;j++){
			int m = lower_bound(a.begin(),a.end(),a[j] + a[i]) - a.begin();
			int k = upper_bound(a.begin(),a.end(),a[j] - a[i]) - a.begin();
			m -= 2;
			if(a[j] - a[i] >= a[i])
			k -= 1;
			ans += (m - k);
		}
	}
	cout << ans/3 << "\n";
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val an = readLine()!!.split(" ").map(String::toInt)

    val fourTimes = an.count { it % 4 == 0 }
    val even = an.count { it % 2 == 0 }

    val odd = an.count { it % 2 == 1 }

    var num = if (0 < fourTimes && (even - fourTimes) in 0..1) {
        n - 1
    } else {
        n
    }

    if (1 < even - fourTimes) {
        num -= (even - fourTimes)
    }
    if (num <= fourTimes * 2) {
        println("Yes")
    } else {
        println("No")
    }
}




Measured memory_bytes: 53520
import math
def ip():return int(input())
def inp():return map(int,input().split())
def linp():return list(map(int,input().split()))

n,x=inp()
l=linp()
d=0
ans=1
for i in range(1,n+1):
    d=l[i-1]+d
    if d<=x:ans+=1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    const int MOD = 1000000;

    string pattern[] = {"0xxxxxxx",
                        "110yyyyx10xxxxxx",
                        "1110yyyy10yxxxxx10xxxxxx",
                        "11110yyy10yyxxxx10xxxxxx10xxxxxx"};

    vector<bitset<32> > p0(4), p1(4), px(4), py(4);
    for(int i=0; i<4; ++i){
        for(int j=0; j<8*(i+1); ++j){
            if(pattern[i][j] == '0')
                p0[i][j] = true;
            if(pattern[i][j] == '1')
                p1[i][j] = true;
            if(pattern[i][j] == 'x')
                px[i][j] = true;
            if(pattern[i][j] == 'y')
                py[i][j] = true;
        }
    }

    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<bitset<32> > b0(n+1), b1(n+1), bx(n+1);
        for(int i=1; i<=n; ++i){
            for(int j=0; j<8; ++j){
                char c;
                cin >> c;
                if(c == '0')
                    b0[i][j] = true;
                if(c == '1')
                    b1[i][j] = true;
                if(c == 'x')
                    bx[i][j] = true;
            }
        }

        vector<long long> dp(n+1, 0);
        dp[0] = 1;
        for(int i=1; i<=n; ++i){
            bitset<32> a0, a1, ax;
            for(int j=0; j<min(i,4); ++j){
                a0 <<= 8;
                a1 <<= 8;
                ax <<= 8;
                a0 |= b0[i-j];
                a1 |= b1[i-j];
                ax |= bx[i-j];
                if((a1 & p0[j]).any() || (a0 & p1[j]).any())
                    continue;

                int numX = 1 << (ax & px[j]).count();
                int numY = 1 << (ax & py[j]).count();
                if(j > 0 && (a1 & py[j]).none())
                    -- numY;
                dp[i] += (dp[i-j-1] * numX) % MOD * numY;
                dp[i] %= MOD;
            }
        }

        cout << dp[n] << endl;
    }
}

Measured memory_bytes: 0
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
using namespace std;
using ll = long long;
typedef pair <int, int> pii;

//void kansuu(int n, string t)
//{
//	if (n == len)
//	{
//		//cout << t << endl;
//
//		int z = 0;
//		string u,v;
//		//cout << stoll(t) << endl;
//		while (1)
//		{
//			if (z==t.length()-1)
//			{
//				u += t[z];
//				//cout << "last sum+=" << stoll(u) << endl;
//
//				sum += stoll(u);
//				return;
//			}
//			else if (t[z] == 'a')
//			{
//				//cout <<"sum+="<< stoll(u) << endl;
//
//				sum += stoll(u);
//				z++;
//				u = v;
//				/*u = t[z];
//				z++;*/
//			}
//			else
//			{
//				u += t[z];
//			z++;
//			}
//		}
//
//		return;
//	}
//	/*sum += stoll(t);
//	cout << stoll(t) << endl;
//*/
//	t += s[n];
//	//t = "aaaaaaa";
//	/*sum += stoll(t);
//	cout << stoll(t) << endl;
//
//	t = s[n];*/
//	kansuu(n + 1, t);
//	//t += "a";
//	if (n!=s.length()-1)
//	{
//
//	t += "a";
//	kansuu(n + 1, t);
//	}
//	return;
//}
int main()
{

	//int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, i = 0, j = 0, k = 0, l = 0, ans = 0;
	//cout << LONG_MAX << endl;
	//long long n, A[1000000000];
	ll n, m, q;
	//int   y[100001], z[100001], x[10001] = {};
	//pii y[100001];
	//pair<int, float> pii[100001];
	string s;
	cin >> s;
	//x = s[0];
	//x = '0';
	for (a = 0; a < 2; a++)
	{
		for (b = 0; b < 2; b++)
		{
			for (c = 0; c < 2; c++)
			{
				if (a == 0)
				{
					d = s[1] - '0';
				}
				else
				{
					d = -s[1] + '0';
				}
				if (b == 0)
				{
					e = s[2] - '0';
				}
				else
				{
					e = -s[2] + '0';
				}
				if (c == 0)
				{
					f = s[3] - '0';
				}
				else
				{
					f = -s[3] + '0';
				}

				if (s[0] - '0' + d + e + f == 7)
				{
					cout << s[0];
					if (a == 0)
					{
						cout << '+';
					}
					else
					{
						cout << '-';
					}
					cout << s[1];
					if (b == 0)
					{
						cout << '+';
					}
					else
					{
						cout << '-';
					}
					cout << s[2];
					if (c == 0)
					{
						cout << '+';
					}
					else
					{
						cout << '-';
					}
					cout << s[3]<<"=7"<<endl;
					return 0;
				}
			}
		}
	}





	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define Max 100000+5
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define pb push_back
int mod = 1000000007;
int mod1 = 998244353;
vector<int> g[Max];
bool vis[Max];
int d, x, y;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
void ex(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        ex(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}


void dfs(int u){

	vis[u]=1;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(vis[v]!=1)
			dfs(v);
	}
}



int power(int a,int b){
    if(b==1)return a;
    if(a>mod)a%=mod;
    int r=1;
    while(b){
        if(b&1)r=r%mod*a%mod;
        a=a%mod*a%mod;
        b/=2;
    }
    return r;
}
class uf{
    vector<int> v;
    vector<int> sz;
    
    
    public :
    uf(int n){
        v.resize(n+1);
        iota(v.begin()+1,v.end(),1);
        sz.resize(n+1,1);
        //1 to sz
    }
    int root(int b){
        while(v[b]!=b){
            b = v[b];
        }   
        return b;
    }
    void u(int a, int b){
        //combine a and b
        
        int ra=root(a);
        int rb=root(b);
        if(ra==rb)return ;
        if(sz[ra]<sz[rb]){
            v[ra] = v[rb];
            sz[rb]+=sz[ra];
        }else{
            v[rb]=v[ra];
            sz[ra]+=sz[rb];
        }
    }
    bool f(int a,int b){
        //same set
        return (root(a)==root(b));
    }
   
    
};
vector<int> matmul(vector<int> a,vector<int> b){
    vector<int> c(4,0);
    c[0] = (a[0]%mod*b[0]%mod + a[1]%mod*b[2]%mod)%mod;
    c[1] = (a[0]%mod*b[1]%mod + a[1]%mod*b[3]%mod)%mod;
    c[2] = (a[2]%mod*b[0]%mod + a[3]%mod*b[2]%mod)%mod;
    c[3] = (a[2]%mod*b[1]%mod + a[3]%mod*b[3]%mod)%mod;
    return c;
}
vector<int> id={1,0,0,1};

int32_t main(){
	IO
	//freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
	int x,y;
  	cin>>x>>y;
  	if(x>y)x=x%y;
  	cout<<min(x,y-x);
}


Measured memory_bytes: 5924
gets
a=gets.split
n=0
b=a.sort_by &l=->(i){[i[1],n+=1]}
c=b.map{r=a.min_by &l;a[a.index r]=a[0];a.shift;r}
puts b*" ",d=:Stable,c*" ",b==c ?d :"Not stable"

Measured memory_bytes: 6100
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
#define YMAX 250001
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int A,B,C;
	scan(A);scan(B);scan(C);
	int saidai,nokori;
	if(A>B&&A>C){
		saidai=A;
		nokori=B+C;
	}
	else if(B>C){
		saidai=B;
		nokori=C+A;
	}
	else{
		saidai=C;
		nokori=A+B;
	}
	prin(10*saidai+nokori);
	return 0;
}


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

int main() {
	int A, B, C;

	cin >> A >> B >> C;

	if( A == B && B == C && C == A ) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define dbg(n) cout<<#n<<' '<<n<<endl;
int power(ll x,ll y){ll res = 1;while(y>0){if(y&1)res = (res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
ll a[10000001]={0};
int main(){ 
	for(int i=1;i<=10000000;i++){
		for(int j=i;j<=10000000;j+=i)
			++a[j];	
	}
	ll n;
	cin>>n;
	ll ans=0;
	for(ll i=1;i<=n;i++){
		ans=ans+(i*a[i]);
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 81768
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.14159265358979
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int X, N;
  cin >> X >> N;
  if (N == 0)
  {
    cout << X << endl;
    return 0;
  }
  else
  {
    vector<int> a(105);
    for (int i = 0; i < N; i++)
    {
      int p;
      cin >> p;
      a[p]++;
    }
    int nearX = INT_INF;
    int ans = -1;
    for (int i = 0; i <= 101; i++)
    {
      if (!a[i])
      {
        int tmp = abs(X - i);
        if (tmp < nearX)
        {
          nearX = min(nearX, tmp);
          ans = i;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3660
import qualified Data.ByteString.Char8 as B
import Data.List
import qualified Data.Vector.Unboxed as V
readIntPair :: B.ByteString -> (Int,Int)
readIntPair s = p
    where
    Just p = do
        (n1, s') <- B.readInt s
        (n2, _ ) <- B.readInt (B.tail s')
        return (n1,n2)

(&) :: a -> (a -> b) -> b
(&) a b = b a

infixl 1 &

main :: IO ()
main = do
    (n,w_limit) <- fmap readIntPair B.getLine
    items <- fmap (map readIntPair . B.lines) B.getContents 
    let v_limit = 1000 * n + 1
        v_end = items 
                    & foldl' step s0 
                    & V.findIndices (<=w_limit) 
                    & V.maximum
        inf = w_limit + 1
        step :: V.Vector Int -> (Int, Int) -> V.Vector Int
        step tbl (wi, vi) = tbl'
            where
            tbl' = V.generate v_limit $ \v -> 
                    min (tbl V.! v) 
                        (if v >= vi then (tbl V.! (v - vi)) + wi 
                                    else w_limit+1)
        s0 = V.generate v_limit $ \i -> if i == 0 then 0 else inf
    print (v_end :: Int)
    


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

constexpr int si = 1001 * 1002, si_log = 7 + 10, mod = static_cast<int>(1e9) + 7;
constexpr long double eps = 1.0e-9;
int n, ar[si];
//string s1;
//vector<int> gr[si];

int64_t sol() {
   int ret = 0;
   if (ar[1] == 1)
   {
      ret++;
      swap(ar[1], ar[2]);
   }
   if (ar[n] == n)
   {
      ret++;
      swap(ar[n-1], ar[n]);
   }

   for (int i = 2; i < n; i++) {
      if (ar[i] == i)
      {
         ret++;
         swap(ar[i+1], ar[i]);
      }
   }

   return ret;
}

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

   while ((cin >> n)) {
      memset(ar, 0, sizeof ar);
      //for (int i = 1; i <= n; i++) { int x; cin >> x; ar[x]++; }
      for (int i = 1; i <= n; i++) { cin >> ar[i]; }
      //for (int i = 1; i <= n; i++) { gr[i].clear(); }
      //for (int i = 1; i < n; i++) {
      //   int a, b; cin >> a >> b; gr[a].push_back(b); gr[b].push_back(a);
      //}

      auto s =
      sol();
      //cout << (s ? "Yes": "No") << '\n';
      cout << s << '\n';
   }
   return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<vector<int>> p(10,vector<int>(10,0));
  
  for(int k=1; k<=n; k++) {
    ostringstream oss2;
    oss2 << k;
    string num = oss2.str();
    int begin = int(num[0]-'0');
    int end = int(num[num.size()-1]-'0');
    p[begin][end]++;
  }
  
  int ans = 0;
  for(int i=1; i<=9; i++) {
    for(int j=1; j<=9; j++) {
      ans += p[i][j]*p[j][i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
//typedef long long LL;
using namespace std;

int main(){
    int num;
    string s;
    bool easy = true;
    cin >> s;
    num = s.size();
    for(int i=0; i<num; i++){
        if(i%2==0 && s[i]=='L'){
            easy = false;
            break;
        }else if(i%2==1 && s[i]=='R'){
            easy = false;
            break;
        }
    }
    if(easy==true){
        cout << "Yes";
    }else{
        cout << "No";
    }
    cout << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  string s;
  cin >> s;
  for (auto itr : s) {
    if (itr == '7') {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;


}

Measured memory_bytes: 3596
#include <vector>
#include <limits>
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) cin >> a[i];

	long ans = numeric_limits<long>::max();
	for (int i = -100; i <= 100; i++) {
		long cost = 0;
		for (auto ai : a) {
			cost += (ai - i) * (ai - i);
		}

		ans = min(ans, cost);
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20)
#define fi first
#define se second
ll INF = 1LL << 60;
ll mod = 1e9 + 7;
ll modn = 998244353;

int main() {
	string s,t; cin >> s >> t;
	int a=0;
	rep(i,s.size()) {
		if(s[i]!=t[i]) a++;
	}
	cout << a << endl;
}

Measured memory_bytes: 3856
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

set<int> prime;

map<int, int> primeFactor(int n) {
	map<int, int> res;
	for (int i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			prime.emplace(i);
			++res[i];
			n /= i;
		}
	}
	if (n != 1) {
		res[n] = 1;
		prime.emplace(n);
	}
	return res;
}

signed main() {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	vector<map<int, int>> m(n);
	rep(i, n) { m[i] = primeFactor(a[i]); }

	int ans = 0;
	for (auto i : prime) {
		int cnt = 0;
		rep(j, n) {
			if (m[j].count(i)) { cnt += a[j]; }
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
}



Measured memory_bytes: 3356
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;

    cin>>n;

    for(int i=1;i<=n;i++)
        A[i] = A[i/10]+1;

    for(int i=1;i<=n;i++)
        if(A[i]&1)cnt++;

    cout<<cnt<<"\n";

    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>

#define ll long long

int main(){
  ll n, m;
  scanf("%lld %lld", &n, &m);
  
  ll g;
  for(int i = m / n; i >= 1; i--){
    if(m % i == 0){
      g = i;
      break;
    }
  }
  
  printf("%lld", g);
  
  return 0;
}


Measured memory_bytes: 128
// Problem : C - A x B + C
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#define int long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 1000000007
#define mod 998244353
#define bug cout<<"HY"<<endl
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define numize(A) A.numize(unique(A.begin(), A.end()) - A.begin())
typedef pair<int,int> P;
int power(int a,int b)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return (power((a*a)%mod,b/2))%mod;
    return (a*(power((a*a)%mod,b/2))%mod)%mod;
}
int modInv(int n)
{
    return power(n, MOD-2);
}
int nCr(int n, int r, int p=MOD)
{
   if (r==0)
      return 1;
    int Fact[n+1];
    Fact[0] = 1;
    for (int i=1 ; i<=n; i++)
    {
        Fact[i] = (Fact[i-1]*i)%p;
    }
    return (((Fact[n]* modInv(Fact[r])) % MOD) *(modInv(Fact[n-r]) % MOD)) % MOD;
}
double PI=3.14159265359;
void solve()
{
	int n,i,j,ans=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		ans+=(n/i);
		if(n%i==0)
			ans--;
	}
	cout<<ans<<endl;
}
int32_t main()
{
    boost;
    int  t=1;
    // cin>>t;
    while(t--)
    {
    	solve();
    }
}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(W<x+r||H<y+r||0>x-r||0>y-r){
	cout<<"No"<<endl;
	}else{
	cout<<"Yes"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int A,B;
  cin >> A >> B;
  if (A % 3 != 0 && B % 3 != 0 && (A + B) % 3 != 0) {
    cout << "Impossible" << endl;
  } else {
    cout << "Possible" << endl;
  }
  return 0;
}

Measured memory_bytes: 3592
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define llong long long
#define ldouble long double
#define uint unsigned int
#define ullong unsigned long long
#define udouble unsigned double
#define uldouble unsigned long double
#define modinc(x) {if(x>=P) x-=P;}
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>
#define piiii pair<pair<int,int>,pair<int,int> >
#define pli pair<llong,int>
#define pll pair<llong,llong>
#define Memset(a,x) {memset(a,x,sizeof(a));}
using namespace std;

const int N = 100;
int a[N+2];
int n;

int absl(int x) {return x>=0 ? x : -x;}

int main()
{
	scanf("%d",&n); int sum = 0ll;
	for(int i=0; i<n; i++) scanf("%d",&a[i]),sum+=a[i];
	int t = 0;
	for(int i=1; i<n; i++)
	{
		if(absl(a[t]*n-sum)>absl(a[i]*n-sum)) t = i;
	}
	printf("%d\n",t);
	return 0;
}

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

using namespace std;

typedef long long int ll;

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

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

int main()
{
	int a,b,c,d;
	cin >> a >>b>>c>>d;
	if(abs(a-c)<=d || (abs(a-b)<=d &&abs(b-c)<=d)) cout << "Yes" << endl;
	else cout <<"No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define PI 3.14159265358979323846
#define vll vector<long long>
#define vvll vector<vector<long long>>
using namespace std;
using ll = long long;
using ld = long double;

// ----本問について----
// 問題：Depth First Search
// 問題文URL：https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_11_B
// 所要時間：
// 学んだこと：
// ------------------

// ----ここから本問のソースコード----
static const ll N_MAX = 110;

// グローバル変数（入力）
ll n, t, A[N_MAX][N_MAX], d[N_MAX], f[N_MAX], state[N_MAX];

// 入力
void input() { cin >> n; }

// 深さ優先探索
void dfs(ll u) {
  d[u] = ++t;
  state[u] = 1; // 発見
  rep(i, n) {
    ll v = i + 1;
    if (A[u][v] == 1 && state[v] == 0) { // 辺が存在かつ未発見なら
      dfs(v);
    }
  }
  f[u] = ++t;
  state[u] = 2; // 完了
}

void solve() {
  // 隣接リストを隣接行列に変換して二次元配列Aに格納
  rep(i, n) {
    ll v, k;
    cin >> v >> k;
    rep(j, k) {
      ll v2;
      cin >> v2;
      A[v][v2] = 1;
    }
  }

  t = 0;
  rep(i,n){
    if (state[i+1]==0){
      dfs(i+1);
    }
  }

  // 出力
  rep(i, n) { cout << i + 1 << " " << d[i + 1] << " " << f[i + 1] << endl; }
}

int main() {
  input();
  solve();
  return 0;
}



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

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

int main(){
  int A[5],k;
  rep(i,5)
    cin>>A[i];
  cin>>k;
  int count=0;
  rep(i,5){
    for(int j=i+1;j<5;j++){
      if(abs(A[i]-A[j])>k)
	count++;
    }
  }
  if(count>0)
    cout<<":("<<endl;
    else
      cout<<"Yay!"<<endl;



  return 0;
}
  


Measured memory_bytes: 256
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from operator import attrgetter
from collections import namedtuple

Point = namedtuple('Point', 'x y')

def linear(p1, p2):
    gradient = (p1.y - p2.y) / (p1.x - p2.x)
    y_intercept = p1.y - gradient * p1.x
    return lambda x: gradient * x + y_intercept

def takeout(seq):
    gen = (Point(next(seq), next(seq)) for _ in xrange(3))
    for p in sorted(gen, key=attrgetter('x')):
        yield p
    yield Point(next(seq), next(seq))

for line in stdin:
    A, B, C, P = takeout(float(s) for s in line.split())
    assert A.x <= B.x <= C.x
    if P.x <= A.x or C.x <= P.x:
        print('NO')
        continue
    if A.x == B.x or B.x <= P.x <= C.x:
        L = (linear(B, C), linear(A, C))
    elif B.x == C.x or A.x <= P.x <= B.x:
        L = (linear(A, B), linear(A, C))
    else:
        print('NO')
        continue

    y1, y2 = sorted(f(P.x) for f in L)
    if y1 < P.y < y2:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 4804
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

#define NIL -1

struct Point{
    int location;
    int x;
    int y;
};

bool asc_x(const Point& l, const Point& r) {
    return l.x < r.x;
}

bool asc_y(const Point& l, const Point& r) {
    return l.y < r.y;
}

struct Node{
    Point p;
    Node* left;
    Node* right;
};

class Tree{
private:
    Node* top;
    Node* AddNode(vector<Point>& P, int l, int r, int depth){
        if (l > r) return NULL;
        Node* N = new Node;
        int m = (l + r) / 2;
        if (depth % 2) {
            sort(P.begin() + l, P.begin() + r + 1, asc_y);
        } else {
            sort(P.begin() + l, P.begin() + r + 1, asc_x);
        }
        N->p = P[m];
        N->left  = AddNode(P, l    , m - 1, depth + 1);
        N->right = AddNode(P, m + 1, r    , depth + 1);
        return N;
    }
    void findNode(int s_x, int t_x, int s_y, int t_y,
                  Node* N, int depth, vector<int>& ans){
        if (N == NULL) return;
        if (s_x <= N->p.x && N->p.x <= t_x &&
            s_y <= N->p.y && N->p.y <= t_y) {
                ans.push_back(N->p.location);
            }
        if (depth % 2) {
            if (N->p.y <= t_y) {
                findNode(s_x, t_x, s_y, t_y, N->right, depth + 1, ans);
            }
            if (N->p.y >= s_y) {
                findNode(s_x, t_x, s_y, t_y, N->left , depth + 1, ans);
            }
        } else {
            if (N->p.x <= t_x) {
                findNode(s_x, t_x, s_y, t_y, N->right, depth + 1, ans);
            }
            if (N->p.x >= s_x) {
                findNode(s_x, t_x, s_y, t_y, N->left , depth + 1, ans);
            }
        }
    }
public:

    int MakeTree(vector<Point>& P){
        top = AddNode(P, 0, P.size() - 1, 0);
    }

    void find(int s_x, int t_x, int s_y, int t_y, vector<int>& ans){
        findNode(s_x, t_x, s_y, t_y, top, 0, ans);
    }
};

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

    int n;
    scanf("%d", &n);
    // cin >> n;
    vector<Point> P(n);

    for (int i = 0; i < n; i++) {
        // cin >> P[i].x >> P[i].y;
        scanf("%d %d", &P[i].x, &P[i].y);
        P[i].location = i;
    }
    Tree T;
    T.MakeTree(P);
    // T.display();
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int s_x, t_x, s_y, t_y;
        // cin >> s_x >> t_x >> s_y >> t_y;
        scanf("%d %d %d %d", &s_x, &t_x, &s_y, &t_y);
        vector<int> ans;
        T.find(s_x, t_x, s_y, t_y, ans);
        sort(ans.begin(), ans.end());
        for (int j = 0; j < ans.size(); j++) {
            // cout << ans[j] << endl;
            printf("%d\n", ans[j]);
        }
        // cout << endl;
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 31324
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
from itertools import accumulate
a=list(accumulate(a))
ans=0
for i in range(n-1):
    if 2*a[i]>=a[i+1]-a[i]:
        ans+=1
    else:
        ans=0
print(ans+1)

Measured memory_bytes: 64616
program colorful_slimes
  implicit none
  integer :: n, i, j, k
  integer(8) :: x, a(4000), b(4000,0:2000), m, t
  a = 0_8
  b = 0_8
  read(*,*) n, x
  read(*,*) a(1:n)
  a(n+1:2*n) = a(1:n)
  b(1:2*n,0) = a(1:2*n)
  m = sum(a(1:n))
  do k = 1, n-1
    do i = n+1, 2*n
      b(i,k) = min(b(i,k-1),a(i-k))
    end do
    t = k*x+sum(b(n+1:2*n,k))
    m = min(m,t)
  end do
  write(*,'(i0)') m
  stop
end program colorful_slimes

Measured memory_bytes: 63104
#include <stdio.h>
#include <string.h>

int main()
{
    const int SIZE = 100;

    int n;
    int t = 0, h = 0;
    char tc[SIZE+1], hc[SIZE+1];

    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        scanf("%s", tc);
        scanf("%s", hc);
        int rc = strcmp(tc, hc);
        if(rc == 0)
        {
            h++;
            t++;
        }
        else if(rc < 0)
        {
            h += 3;
        }
        else
        {
            t += 3;
        }
    }
    printf("%d %d\n", t, h);

    return 0;
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
#include <cmath>
typedef long long int ll;
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);
	int n,d;cin>>n>>d;
	ll ans = n/(2*d+1);
	if(ans*(2*d+1)<n){
		ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
n,k = gets.chomp!.split
d = [0,1,2,3,4,5,6,7,8,9] - gets.split.map(&:to_i)
a = [0] + n.split("").map(&:to_i)
l = a.size

(1..l-1).each do |i|
    next if d.include?(a[i])

    if (s = d.find{|x| x > a[i]}) then
        a[i] = s
        (i+1..l-1).each do |j|
            a[j] = d[0]
        end
    else
        while (s = d.find{|x| x > a[i-1]}) == nil do
            i -= 1
        end
        a[i-1] = s
        (i..l-1).each do |j|
            a[j] = d[0]
        end
    end

    break
end

puts a.inject{|x,y| 10 * x + y}

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

string s1, s2;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n, m;
	string s, t;
	cin >> n >> m >> s >> t;

	if (s[0] != t[0])
	{
		cout << -1 << en;
		return 0;
	}
	else if (n == m && s != t)
	{
		cout << -1 << en;
		return 0;
	}
	else
	{
		int x = __gcd(n, m);
		for (int i = 0; i < n; i += (n / x))
		{
			s1 += s[i];
		}
		for (int i = 0; i < m; i += (m / x))
		{
			s2 += t[i];
		}
		if (s1 != s2)
		{
			cout << -1 << en;
			return 0;
		}
		else
		{
			cout << (n * m) / x << en;
		}
		// int y = (n * m) / (__gcd(n, m));
		// map<int, int>mt;
		// int z = y / n;
		// int i = 0;
		// while (z * i < y)
		// {
		// 	mt[z * i] = z * i + 1;
		// 	i++;
		// }
		// z = y / m;
		// i = 0;
		// while (z * i < y)
		// {
		// 	if (mt[z * i] > 0)
		// 	{
		// 		int a = z * i / m;
		// 		int b = z * i / n;
		// 		if (s[a] != t[b] && (z * i) % m == 0 && (z * i) % n == 0)
		// 		{
		// 			cout << -1 << en;
		// 			return 0;
		// 		}
		// 	}
		// 	i++;
		// }
		// cout << y << en;
	}



	return 0;
}



Measured memory_bytes: 640
/* AOJ 0031
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0031
 */

#include <stdio.h>
#define MAX 1024

int main(){
  int w;
  int i;
  int u;
  int isfirst;
  while(scanf("%d", &w)==1){
    u = 1;
    isfirst = 1;
    for(i=0;i<10;i++){
      if(0x1&w){
        if(isfirst){
          isfirst = 0;
        }else{
          printf(" ");
        }
        printf("%d", u);
      }
      w = w >> 1;
      u=u*2;
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define vec vector<int,int> 
#define int long long 
int visited[100001];

int dfs(int i,vector<int> v[],int val[],int n){
	if(v[i].size()==0){
		visited[i]=1;
		val[i]=0;
		return 0;
	}
	if(visited[i]==1){
		return val[i];
	}
	int ans=0;
	rep(j,v[i].size()){
	if(visited[v[i][j]]==0){
		ans=max(ans,dfs(v[i][j],v,val,n));
	}
	else{
		ans=max(val[v[i][j]],ans);
		}
	}
	val[i]=1+ans;
	visited[i]=1;
	return val[i];
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ios_base& scientific (ios_base& str);
	
	int t=1;
//	cin>>t;
	while(t--){
		int n,m;
		cin>>n>>m;
		vector<int> v[n+1];
		for(int i=0;i<m;i++){
			int a,b;
			cin>>a>>b;
			v[a].pb(b);
		}
		rep(i,n+1){
			visited[i]=0;
		}
		int val[n+1]={0};
		for(int i=1;i<=n;i++){
			if(visited[i]==0){
				int ans=0;
				rep(j,v[i].size()){
					if(visited[v[i][j]]==0){
						ans=max(ans,dfs(v[i][j],v,val,n));
					}
					else{
						ans=max(val[v[i][j]],ans);
					}
				}
				val[i]=1+ans;
				visited[i]=1;
			}
		}
		int ans=0;
		rep(i,n+1){
			ans=max(ans,val[i]);
		}
		cout<<ans<<endl;
	}
	//exit();
	return 0;
}


Measured memory_bytes: 11392
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(1000000000)

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

dp = [[float("inf")]*(N+1) for _ in range(N+1)]

for shift_i in range(N+1):
    for i in range(N+1):
        if i+shift_i >= N+1:
            continue
        if shift_i == 0:
            dp[i][i] = 0
        elif ((i+shift_i)-i)%2 == N%2: # 先手番
            dp[i][(i+shift_i)] = max(a[i] + dp[i+1][(i+shift_i)], a[(i+shift_i)-1] + dp[i][(i+shift_i)-1])
        else:
            dp[i][(i+shift_i)] = min(-a[i] + dp[i+1][(i+shift_i)], -a[(i+shift_i)-1] + dp[i][(i+shift_i)-1])

print(dp[0][N])

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

int main(){
  int i,n,v,j,k;
  int *A;

  scanf("%d", &n);
  A = (int *)malloc(n*sizeof(int));  //配列を確保

  for(i=0; i<n; i++) scanf("%d", A+i); //配列Aに値を入力

  // 下のfor文を1から回すため、あらかじめi=0の時の結果出力
  for(k=0; k<n-1; k++) printf("%d ", A[k]);
  printf("%d\n", A[n-1]);

  //for(i=0; i<n; i++){
  for(i=1; i<=n-1; i++){
    v = A[i];  //仮置き
    j = i-1;
    while(j>=0 && A[j]>v){ //iよりも前の要素と比較
      A[j+1] = A[j];       //一つ右にずらす
      j--;
    }
    A[j+1] = v;

    //結果出力
    for(k=0; k<n-1; k++) printf("%d ", A[k]);
    printf("%d\n", A[n-1]);
  }
  return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#pragma warning (disable : 4996)

int p[100001];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &p[i]);
	int ans = 0;
	for (int i = 1; i < n; i++)
		if (p[i] == i&&p[i + 1] == i + 1)
		{
			swap(p[i], p[i + 1]);
			ans++;
		}
	for (int i = 1; i <= n; i++) if (p[i] == i) ans++;
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;

int main(){
  int n;
  cin>>n;
  int sum = 0;
  sum +=n + pow(n,2) + pow(n,3);
  cout<<sum<<endl;

  return 0;
}


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

#define int         long long
#define nn          3001
#define FAST        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int n;
int dp[nn][nn][2],a[nn];

int solve(int i,int j,int turn){
    if(i>j)
        return 0;

    if(dp[i][j][turn] != -1)
        return dp[i][j][turn];

    if(turn == 1)
        return dp[i][j][turn] = max(a[i] + solve(i+1,j,0), a[j] + solve(i,j-1,0));
    
    else
        return dp[i][j][turn] = min(solve(i+1,j,1), solve(i,j-1,1));
}

int32_t main() {
    memset(dp,-1,sizeof(dp));
    cin>>n;
    int sum = 0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum += a[i];
    }

    cout<<2*solve(1,n,1) - sum;
}


Measured memory_bytes: 141184
f s t = f' s t 0
    where
        f' [] _ n = n
        f' s@(sx:sxs) t@(tx:txs) n
            = f' sxs txs $ if sx /= tx then n + 1 else n

main = do
    s <- getLine
    t <- getLine
    print $ f s t


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

int main() {
  char a, b; cin >> a >> b;
  if (a=='H' && b=='H') cout << "H";
  else if (a=='H' && b=='D') cout << "D";
  else if (a=='D' && b=='H') cout << "D";
  else cout << "H";
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i > 1) {
      a[i] += a[i - 2];
    }
  }
  vector<long long> dp(n);
  for (int i = 1; i < n; i++) {
    if (i & 1) {
      dp[i] = a[i - 1];
    } else {
      dp[i] = dp[i - 1];
    }
    if (i > 1) {
      dp[i] = max(dp[i], dp[i - 2] + a[i] - a[i - 2]);
    } else {
      dp[i] = max(dp[i], a[i]);
    }
  }
  cout << dp[n - 1] << '\n';
  return 0;
}

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

int main() { 
  int n;

  cin >> n;

  if(n <= 9) {
    cout << n << endl;
  } else if (n <= 99){
    cout << 9 << endl;
  } else if (n <= 999){
    cout << 9 + n-100+1 <<endl;
  } else if (n <= 9999){
    cout << 909 << endl;
  } else if (n <= 99999){
    cout << 909 + n-10000+1 << endl;
  } else if (n == 100000){
    cout << 90909 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

vector<string> split(string,string);

//template<typename T>
//void swap(T*,T*);
//char ToUpper (char cX) { return toupper(cX); }

int main()
{
    int a[12] {0,1,0,2,0,2,0,0,2,0,2,0};
    int x,y;
    cin >> x >> y;
    if(a[x-1] == a[y-1])
    {
        Yes(true);
    }
    else
    {
        Yes(false);
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>


using namespace std;

int main(){
  int N;
  cin>>N;
  int A[N];
  for(int i=0;i<N;i++)cin>>A[i];
  for(int i=0;i<N;i++)A[i]=A[i]-i-1;
  long long ave=0;
  for(int i=0;i<N;i++)ave+=A[i];
  ave=int(round(double(ave)/N));
  long long ans=99999999999999;
  sort(A,A+N);
  for(int i=N/2-2;i<N/2+2;i++){
    long long temp=0;
    int b=ave+i-N/2;
    for(int j=0;j<N;j++)temp+=int(abs(A[j]-A[i]));
    if(temp<ans)ans=temp;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
x,y=map(int,input().split())
s0=1<<(x-1)|1<<(y-1)
s1=sum(list(map(lambda x:1<<(x-1),[1,3,5,7,8,10,12])))&s0
s2=sum(list(map(lambda x:1<<(x-1),[4,6,9,11])))&s0
s3=sum(list(map(lambda x:1<<(x-1),[2])))&s0

if s1==s0 or s2==s0 or s3==s0:
  print('Yes')
else:
  print('No')


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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP(a, b) make_pair(a, b)
#define F first
#define S second
#define Y first
#define X second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int w, h, maze[128][128], dy[] = {0,-1,0,1}, dx[] = {-1,0,1,0};;

int main(){
  while(scanf("%d%d", &w, &h) && w+h){
    rep(i, 2*h-1){
      rep(j, (i%2)?w:w-1) scanf("%d", &maze[i][j]);
    }

    map<pi, int>m;
    queue<pi>q;
    q.push(MP(0, 0));
    m[MP(0, 0)] = 1;
    int res = 1;
    while(!q.empty()){
      //      printf("%d\n", res);
      int qsize = (int)q.size();
      rep(i, qsize){
	pi now = q.front(); q.pop();
	//	printf("%d %d\n", now.Y, now.X);
	rep(d, 4){
	  int ny = now.Y + dy[d], nx = now.X + dx[d];
	  if(ny < 0 || nx < 0 || ny >= h || nx >= w || m.count(MP(ny,nx))) continue;
	  if(d == 0){
	    if(maze[now.Y*2][now.X-1]) continue;
	  }else if(d == 1){
	    if(maze[now.Y*2-1][now.X]) continue;
	  }else if(d == 2){
	    if(maze[now.Y*2][now.X]) continue;
	  }else if(d == 3){
	    if(maze[now.Y*2+1][now.X]) continue;
	  }

	  //	  printf("%d %d\n", ny, nx);
	  m[MP(ny, nx)] = 1;
	  q.push(MP(ny, nx));
	  if(ny == h-1 && nx == w-1){
	    printf("%d\n", res+1);
	    goto e;
	  }
	}
      }
      res++;
    }
    puts("0");
  e:;
  }
  return 0;
}

Measured memory_bytes: 1304
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    string s,t; cin>>s>>t;
    int ans=0;
    rep(i,s.size()){
        if(s[i]!=t[i]) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3916
n,x,y = map(int,input().split())

dis = [0] * (n-1)

# 頂点iから頂点jまでの距離
for i in range(1, n):
    for j in range(i+1, n+1):
        if i <= x:
            if j <= x:
                tmp = j-i
            if x < j < y:
                tmp = (x-i) + min(j-x, y-j+1)
            if j >= y:
                tmp = (x-i) + (j-y) + 1

        if x < i < y:
            if x < j < y:
                tmp = min(j-i, (i-x)+(y-j)+1)
            if j >= y:
                tmp = min(i-x+1, y-i) + (j-y)
        
        if i >= y:
            tmp = j-i

        dis[tmp-1] += 1

for ans in dis:
    print(ans)



Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll max_v=1e15;
string ll_to_str(ll n){
  ll digit=0,ten=1;
  while(n/ten>0){
    digit++;
    ten*=10;
  }
  ten/=10;
  string ret;
  while(ten>0){
    ll now_digit=n/ten;
    ret.push_back((char)(now_digit+'0'));
    n-=now_digit*ten;
    ten/=10;
  }
  return ret;
}
ll str_to_ll(string s){
  ll ret=0;
  ll kt=1;
  for(int i=s.length()-1;i>=0;i--){
    ret+=(ll)(s[i]-'0')*kt;
    kt*=10;
  }
  return ret;
}
ll func(ll n){
  string s="0";
  s+=ll_to_str(n);
  bool f=true;
  for(int i=1;i<s.length();i++){
    if(s[i]!='9') f=false;
  }
  if(f) return n;
  ll now_ans=n,now_digit=0;
  for(int i=0;i<s.length();i++) now_digit+=(ll)(s[i]-'0');
  for(int i=s.length()-1;i>=0;i--){
    if(s[i]!='9'){
      int p_d=(int)(s[i]-'0');
      string ks=s;
      for(int j=i+1;j<ks.length();j++) ks[j]='9';
  //    cout<<n<<" "<<i<<" "<<ks<<endl;
      for(int hk=p_d;hk<=9;hk++){
        ks[i]=(int)(hk+'0');
        ll k_num=str_to_ll(ks);
        ll k_digit=0;
        for(int j=0;j<ks.length();j++) k_digit+=(ll)(ks[j]-'0');
        if(k_num==n) continue;
      //  cout<<now_ans<<" "<<now_digit<<" "<<k_num<<" "<<k_digit<<" "<<ks<<endl;
        if(now_ans*k_digit-k_num*now_digit>0){
          now_ans=k_num;
          now_digit=k_digit;
        }
        else if(now_ans*k_digit-k_num*now_digit==0&&now_ans>k_num){
          now_ans=k_num;
          now_digit=k_digit;
        }
      }
    }
  }
  return now_ans;
}
int main(){
  ll k;
  cin>>k;
  ll ans=1;
  for(int i=0;i<k;i++){
    cout<<ans<<endl;
    ans=func(ans+1);
  }
}


Measured memory_bytes: 256