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

int main() {
  int N;
  string S;
  cin >> N >> S;
  if (N > 1) {
  	string T = S.substr(0, N / 2);
    if (T + T == S) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
  	cout << "No" << endl;
  }
}

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   //最大値を求める
#define MIN(x) *min_element(ALL(x))   //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007      //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

//for (auto& e : array)



signed main()
{
    cout << fixed << setprecision(10);

    int A, B, H, M;
    cin >> A >> B >> H >> M;

    double ans = 0;
    double ang = 0;
    ang = abs((H*M_PI/6)+(M*M_PI/360)-(M*M_PI/30));

    ans = pow(A,2) + pow(B,2) - (2*A*B*cos(ang));

    cout << sqrt(ans) << endl;
    //cout << sqrt(pow(A,2) + pow(B,2) - (2*A*B*cos(abs((H*M_PI/6)+(M*M_PI/360)-(M*M_PI/30))))) << endl;

}


Measured memory_bytes: 4192
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ll long long
int main()
{
    ll n,k;
    cin>>n>>k;
    if(k==0)
    {
        cout<<n*n;
        return 0;
    }
    ll ans=0;
    for(ll i=k;i<n;i++)
    {
        ans+=(n-i);
    }
    for(ll i=k+1;i<=n;i++)
    {
        ll d=i+k;
        if(d>n)
        {
            break;
        }
        ll l,r,m;
        l=0;
        r=1e9;
        while(l<r)
        {
            m=(l+r+1)>>1;
            if(d+i*m<=n)
            {
                l=m;
            }
            else
            {
                r=m-1;
            }
        }
        ans+=(l*(i-k));
        d+=(i*l);
        ans+=min(i-k,n-d+1);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define NIL -1

struct Node {int p, l, r;};
struct Node T[10000];
int n;

void Preorder(int x) {
   if (x == NIL) {
      return;
   }
   printf(" %d", x);
   Preorder(T[x].l);
   Preorder(T[x].r);
}

void Inorder(int x) {
   if (x == NIL) {
      return;
   }
   Inorder(T[x].l);
   printf(" %d", x);
   Inorder(T[x].r);
}

void Postorder(int x) {
   if (x == NIL) {
      return;
   }
   Postorder(T[x].l);
   Postorder(T[x].r);
   printf(" %d", x);
}

int main() {
   int i, l, r, n, j, k;

   scanf("%d", &n);
   for (j = 0; j < n; j++) {
      T[j].p = NIL;
   }
   for (j = 0; j < n; j++) {
      scanf("%d %d %d", &i, &l, &r);
      T[i].l = l;
      T[i].r = r;
      if (l != NIL) {
         T[l].p = i;
      }
      if (r != NIL) {
         T[r].p = i;
      }
   }

   for (j = 0; j < n; j++) {
      if (T[j].p == NIL) {
         k = j;
      }
   }

   printf("Preorder\n");
   Preorder(k);
   printf("\nInorder\n");
   Inorder(k);
   printf("\nPostorder\n");
   Postorder(k);
   printf("\n");

   return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int N;

	cin >> N;
	string ans = "No";

	for (int i = 1; i <= 9; i++)
	{
		for (int j = 1; j <= 9; j++)
		{
			if (N == i * j)
				ans = "Yes";
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <functional>
 
using namespace std;
 
int main(void) {
    long int n = 0, sum = 0, co = 0, ans = 0;
    cin >> n;
    long int x[n];
    rep(i, n){
        cin >> x[i];
        sum += x[i];
    }
    co = round(double(sum) / n);
    rep(i, n){
        ans += pow(x[i] - co, 2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4,sse4.1,sse4.2,avx,tune=native")
#include <bits/stdc++.h>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){if(a < b) a = b;}

ll gcd(ll x, ll y){ return y? gcd(y, x%y): x; }
int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VL a(n);
	rep(i, n) cin >>a[i];
	int mcnt=0; ll mnabs=1e16;
	ll ans = 0;
	rep(i, n){
		mcnt += a[i] < 0;
		mnabs = min(mnabs, abs(a[i]));
		ans += abs(a[i]);
	}
	if(mcnt & 1) ans -= 2 * mnabs;
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define gcd __gcd
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define mp make_pair
#define pb push_back
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sbits(a) __builtin_popcount(a)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define nani(x) cerr << #x << " is " << x << endl;
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

typedef long long ll;

const int N = 1e5 + 5;

int A[N];

int main()
{
    fast;

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

    int a, b;
    cin >> a >> b;

    if (a < 10 && b < 10)
        cout << a * b;
    else
        cout << -1;
    return 0;
}


Measured memory_bytes: 256
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())

n = N
ans = ''
even = False
for i in range(100):
    if n % 2 == 1:
        ans += '1'
    else:
        ans += '0'
    n += even
    n //= 2
    even = not even
ans = ans[::-1].lstrip('0')
if ans:
    print(ans)
else:
    print(0)


Measured memory_bytes: 3188
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int k;
    cin>>k;
    
        if(a>=b)
        {
            while(b<=a && k){
            b=b*2;
            --k;}
        }
        if(b>=c)
        {
            while(c<=b && k){
                c=c*2;
                --k;
            }
        }
        
    
    if(a<b && b<c)
    cout<<"Yes"<<"\n";
    else
    cout<<"No"<<"\n";
    
    return 0;
}


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

int main() {
  int N; // 3~50
  string S;
  cin >> N;
  cin >> S;
  int cnt=0;
  for (int i=0; i < N-2; i++) {
    string s = S.substr(i, 3);
    if (s == "ABC") cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
h, w, a, b = map(int, input().split())
ans = [[0] * w for _ in range(h)]

for i in range(b):
    for j in range(a):
        ans[i][j] = 1

for i in range(b, h):
    for j in range(a, w):
        ans[i][j] = 1

for i in range(h):
    print("".join(map(str, ans[i])))


Measured memory_bytes: 13556
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
int main(){
    string s; cin >> s;
    Int D; cin >> D;
    constexpr Int mod = 1e9 + 7;
    auto dp    = vectors(s.size(),D,2, 0LL);
    auto visit = vectors(s.size(),D,2,false);
    function<Int(Int,Int,bool)> solve = [&](Int idx, Int cmod, bool bind){
        Int res = 0;
        if(idx + 1 == s.size()){
            Int ub = ( not bind ? 9 : s[idx] - '0');
            for(Int i = 0; i <= ub; ++i)
                res += (i % D == cmod);
            return res;
        }
        if(visit[idx][cmod][bind])
            return dp[idx][cmod][bind];
        Int num = (not bind ? 9 : s[idx] - '0' );
        for(Int i = 0; i <= num; ++i){
            res += solve(idx + 1,(D + cmod - i % D)%D,bind and num == i);
            res %= mod;
        }
        visit[idx][cmod][bind] = true;
        return dp[idx][cmod][bind] = res;
    };
    cout << (mod + solve(0LL,0LL,true) - 1 ) % mod << endl;
}



Measured memory_bytes: 127488
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

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

int main() {

int n;
int m;
int a;
int b;
int e=0;
int o=0;
int d;
cin>>n>>m;

	for(int i=1; i<m+1; i++){
		cin>>a;
		cin>>b;
		d=b-a;
		d=d/2;
		if(d>0){
		e+=d;
		}
		if(o<d){
			o=d;
		}

	}
cout<<e-o<<endl;
}

Measured memory_bytes: 3080
#include<cstdio>
    int main(){
    	int n,m;
    	scanf("%d%d",&n,&m);
    	long long int d[10][10]={};
    	for(int i=0;i<10;i++){
    		for(int j=0;j<10;j++){
    			scanf("%lld",&d[i][j]);
    		}
    	}
    	for(int i=0;i<10;i++){
    		for(int j=0;j<10;j++){
    			for(int k=0;k<10;k++){
    				if(i!=k && d[j][k]>d[j][i]+d[i][k]){
    					d[j][k]=d[j][i]+d[i][k];
    				}
    			}
    		}
    	}
    	long long int ans=0;
    	int t;
    	for(int i=0;i<n*m;i++){
    		scanf("%d",&t);
    		if(t!=-1)ans+=d[t][1];
    	}
    	printf("%lld\n",ans);
    	return 0;
    }

Measured memory_bytes: 128
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
input=lambda :sys.stdin.readline().rstrip()
N,S=map(int,input().split())
A=list(map(int,input().split()))
mod=998244353

gyaku=pow(2,mod-2,mod)
N2=pow(2,N-1,mod)
dp=[[0,0] for n in range(3001)]
for n in range(N):
    a=A[n]
    for s in range(0,S+1)[::-1]:
        if s+a<=S:
            dp[s+a][1]+=dp[s][1]*gyaku%mod
            dp[s+a][1]%=mod
    dp[a][1]+=N2

print(dp[S][1])
#print(c)


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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int N;
    string s;
    cin >> N >> s;

    int cnt = 0;
    int left = 0, right = N-1;
    while(left < right){
        while(left < N && s[left] != 'W'){
            left++;
        }
        while(right > 0 && s[right] != 'R'){
            right--;
        }
        if(left < right){
            s[left] = 'R';
            s[right] = 'W';
            cnt++;
        }
    }

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

Measured memory_bytes: 3848
n, m = list(map(int,input().split()))

penalty = 0

corrected = {}
wa = {}

for i in range(m):
  pi, si = input().split()
  if (si == 'AC' and not corrected.get(pi)):
    corrected[pi] = True
  elif (si == 'WA' and not corrected.get(pi)):
    wa[pi] = wa[pi] + 1 if wa.get(pi) else 1

correct = len(corrected.keys())
for i in corrected.keys():
	penalty += wa[i] if  wa.get(i) else 0

print("{} {}".format(correct, penalty))
    


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

int main() {
  int N,K;
  cin >> N >> K;

	vector<int> d(K);
	vector<int> sunuke(N,0);
	vector<vector<int>> A(100,vector<int>(100));
	for(int i=0;i<K;i++){
		cin >> d.at(i);

		for (int j=0;j<d.at(i);j++){
			cin >> A.at(i).at(j);
			sunuke.at(A.at(i).at(j)-1) ++;
		}
	}

	int cnt =0;

	for(int i=0;i<N;i++){
		if(sunuke.at(i)==0){
			cnt ++;
		}
	}
	cout << cnt << "\n";
}

Measured memory_bytes: 3676
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		List<Integer> x = new ArrayList<>();
		List<Integer> y = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			x.add(scan.nextInt());
			y.add(scan.nextInt());
		}
		double tmp = 0;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				tmp += Math.sqrt(
						(x.get(i) - x.get(j)) * (x.get(i) - x.get(j)) + (y.get(i) - y.get(j)) * (y.get(i) - y.get(j)));
			}
		}
		System.out.println(tmp / n);
	}
}

Measured memory_bytes: 21972
#include <iostream>

using namespace std;

int main()
{
  int X;
  cin >> X;
  int cnt = 0;
  
  while(X >= 500)
  {
    X -= 500;
    cnt += 1000;
  }
  while(X >= 5)
  {
    X -= 5;
    cnt += 5;
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
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;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;
struct PrimalDual{
	struct edge{
		int to,cap,cost,rev;
	};
	vector<vector<edge>>graph;
	bool negative=false;
	void add_edge(int from,int to,int cap,int cost){
		graph[from].push_back({to,cap,cost,len(graph[to])});
		graph[to].push_back({from,0ll,-cost,len(graph[from])-1});
		if(cost<0)negative=true;
	}
	int minCostFlow(int s,int t,int f){
		int V=len(graph);
		vector<int>potential(V),minCost,prevv(V,-1),preve(V,-1);
		int res=0;
		if(negative){
			minCost.assign(V,inf);
			minCost[s]=0;
			rep(_,V-1){
				rep(i,V){
					rep(j,len(graph[i])){
						edge &e=graph[i][j];
						if(e.cap>0&&chmin(minCost[e.to],minCost[i]+e.cost+potential[i]-potential[e.to])){
							prevv[e.to]=i;
							preve[e.to]=j;
						}
					}
				}
			}
			if(minCost[t]==inf)return -1;
			rep(i,V)potential[i]+=minCost[i];
			for(int i=t;i!=s;i=prevv[i]){
				graph[prevv[i]][preve[i]].cap--;
				graph[i][graph[prevv[i]][preve[i]].rev].cap++;
			}
			res+=potential[t];
		}
		vector<bool>used(V);
		while(f>0){
			minCost.assign(V,inf);
			used.assign(V,0);
			minCost[s]=0;
			priority_queue<P,vector<P>,greater<>>que;
			que.push({0,s});
			while(!que.empty()){
				P p=que.top();que.pop();
				if(minCost[p.second]<p.first)continue;
				rep(i,len(graph[p.second])){
					edge &e=graph[p.second][i];
					if(e.cap>0&&chmin(minCost[e.to],p.first+e.cost+potential[p.second]-potential[e.to])){
						prevv[e.to]=p.second;
						preve[e.to]=i;
						que.push({minCost[e.to],e.to});
					}
				}
			}

			if(minCost[t]==inf)return -1;
			rep(i,V)potential[i]+=minCost[i];
			int addflow=f;
			for(int i=t;i!=s;i=prevv[i])chmin(addflow,graph[prevv[i]][preve[i]].cap);
			f-=addflow;
			res+=addflow*potential[t];
			for(int i=t;i!=s;i=prevv[i]){
				edge &e=graph[prevv[i]][preve[i]];
				e.cap-=addflow;
				graph[i][e.rev].cap+=addflow;
			}
		}
		return res;
	}
	PrimalDual(int V):graph(V){};
};

int N,M;
char c[55][55];
bool used[55][55];
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>N>>M;
	rep(i,N)rep(j,M)cin>>c[i][j];
	PrimalDual F(N*M+2);
	int cnt=0;
	rep(i,N)rep(j,M){
		if(c[i][j]=='o'){
			cnt++;
			memset(used,0,sizeof(used));
			F.add_edge(N*M,i*M+j,1,0);
			F.add_edge(i*M+j,N*M+1,1,mod);
			used[i][j]=true;
			rep(k,N)rep(l,M){
				if((k!=i||l!=j)&&used[k][l]){
					F.add_edge(i*M+j,k*M+l,1,mod-(k-i+l-j));
				}
				if(c[k+1][l]!='#')used[k+1][l]|=used[k][l];
				if(c[k][l+1]!='#')used[k][l+1]|=used[k][l];
			}
		}else F.add_edge(i*M+j,N*M+1,1,0);
	}
	cout<<cnt*mod-F.minCostFlow(N*M,N*M+1,cnt)<<"\n";
}


Measured memory_bytes: 9648
h, w = map(int, input().split())

s = [list(input()) for _ in range(h)]

DX = [-1, 0, 1, 0]
DY = [0, -1, 0, 1]

ans = True

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            continue
        flag = 0
        for k in range(4):    
            if not(0<=j+DX[k]<=w-1 and 0<=i+DY[k]<=h-1):
                continue
            if s[i + DY[k]][j + DX[k]] == "#":
                flag = 1
                break
        if flag == 0:
          ans = False
          break
print("Yes" if ans else "No")


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

const int INF = 2e9;

int main(){
    int a,b;
    cin >> a >> b;
    cout << max((a - 2*b),0) << endl;
}

Measured memory_bytes: 256
using System;

namespace AGC038
{
    class A
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int H = int.Parse(input[0]);
            int W = int.Parse(input[1]);
            int A = int.Parse(input[2]);
            int B = int.Parse(input[3]);

            if (W / 2 < A || H / 2 < B) { Console.WriteLine("No"); return; }

            //int[,] s = new int[H, W];

            int[,] s = new int[2, W];
            string a = "";
            string b = "";
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < W; j++)
                {

                    if (i == 0)
                    {
                        if (j < W - A) a += "0";
                        else if (W - A <= j) a += "1";
                    }

                    if (i == 1)
                    {
                        if (j < W - A) b += "1";
                        else if (W - A <= j) b += "0";
                        //if (j < W - A) s[i, j] = 1;
                        //else if (W - A <= j) s[i, j] = 0;
                    }
                }
            }

            for (int i = 0; i < H; i++)
            {

                if (i < H - B) Console.WriteLine(a);
                else Console.WriteLine(b);
                /*
                for (int j = 0; j < W; j++)
                {
                    if (i < H - B && j < W - A) s[i, j] = 0;
                    else if (i < H - B && W - A <= j) s[i, j] = 1;

                    if (H - B <= i && j < W - A) s[i, j] = 1;
                    else if (H - B <= i && W - A <= j) s[i, j] = 0;

                    Console.Write(s[i, j]);
                }
                 */
            }
        }
    }
}


Measured memory_bytes: 14148
#include <bits/stdc++.h>
using namespace std;
 
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}
 
void solve(){
 
 
}

ll dp[2009][2009];
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();

    vector<pair<ll, ll>> a;
    int n;cin>>n;
    a.resize(n,{0,0});
    rep(i,n)cin>>a[i].fst,a[i].fst*=-1,a[i].snd=i;
    sort(all(a));
    repA(s,1,n)repA(l,0,n-s){
        int r=l+s;
        dp[l][r]=max(dp[l][r], a[n-s].fst*-1ll*abs(a[n-s].snd-l)+dp[l+1][r]);
        dp[l][r]=max(dp[l][r], a[n-s].fst*-1ll*abs(a[n-s].snd-r+1)+dp[l][r-1]);
    }
    cout<<dp[0][n];



	return 0;
}
 



Measured memory_bytes: 26332
#include<stdio.h>
int main(){
    int n,x,l[101],i,r=1,s=0;
    scanf("%d%d",&n,&x);
    for(i=0;i<n;i++)scanf("%d",&l[i]);
    while(s<=x){
        s+=l[r-1];
        r++;
    }
    printf("%d",r-1);
    return 0;
}

Measured memory_bytes: 128
use strict;
use warnings;
package SuffixArray;
sub sa_is(\@$);
sub sa_is(\@$){
	my@s=@{$_[0]};
	my$upper=$_[1];
	my$n=@s;
	if($n==0){
		return();
	}
	elsif($n==1){
		return(0);
	}
	my@sa;
	my@ls;
	for(my$i=$n-2;$i>=0;$i--){
		$ls[$i]=$s[$i]==$s[$i+1]?$ls[$i+1]:$s[$i]<$s[$i+1];
	}
	my@sum_l=(0)x($upper+1);
	my@sum_s=(0)x($upper+1);
	$ls[$_]?$sum_l[$s[$_]+1]++:$sum_s[$s[$_]]++for 0..$n-1;
	for(0..$upper){
		$sum_s[$_]+=$sum_l[$_];
		$sum_l[$_+1]+=$sum_s[$_]if$_<$upper;
	}
	my$induce;
	$induce=sub{
		my@sa=(-1)x$n;
		my@buf=@sum_s;
		for(@_){
			next if$_==$n;
			$sa[$buf[$s[$_]]++]=$_;
		}
		@buf=@sum_l;
		$sa[$buf[$s[$n-1]]++]=$n-1;
		for(@sa){
			$sa[$buf[$s[$_-1]]++]=$_-1if$_>=1&&!$ls[$_-1];
		}
		@buf=@sum_l;
		for(my$i=$n-1;$i>=0;$i--){
			my$v=$sa[$i];
			$sa[--$buf[$s[$v-1]+1]]=$v-1if$v>=1&&$ls[$v-1];
		}
		return@sa;
	};
	my@lms=grep!$ls[$_-1]&&$ls[$_],1..$n-1;
	my@lms_map=(-1)x($n+1);
	my$m=@lms;
	for(0..$m-1){
		$lms_map[$lms[$_]]=$_;
	}
	@sa=$induce->(@lms);
	if($m){
		my@sorted_lms=grep$lms_map[$_]!=-1,@sa;
		my@rec_s;
		my$rec_upper=0;
		$rec_s[$lms_map[$sorted_lms[0]]]=0;
		for(1..$m-1){
			my$l=$sorted_lms[$_-1];
			my$r=$sorted_lms[$_];
			my$end_l=$lms[$lms_map[$l]+1]//$n;
			my$end_r=$lms[$lms_map[$r]+1]//$n;
			my$different;
			if($end_l-$l!=$end_r-$r){
				$different=1;
			}
			else{
				$l++,$r++while$l<$end_l&&$s[$l]==$s[$r];
				$different=$l==$n||$s[$l]!=$s[$r];
			}
			$rec_s[$lms_map[$sorted_lms[$_]]]=$rec_upper+=$different;
		}
		my@rec_sa=sa_is(@rec_s,$rec_upper);
		$sorted_lms[$_]=$lms[$rec_sa[$_]]for 0..$m-1;
		@sa=$induce->(@sorted_lms);
	}
	return@sa;
}
sub suffix_array($){
	my@s=map ord,split"",$_[0];
	return sa_is(@s,255);
}
package LcpArray;
sub lcp(\@\@){
	my@s=@{$_[0]};
	my$n=@s;
	my@sa=@{$_[1]};
	my@rnk;
	$rnk[$sa[$_]]=$_ for 0..$n-1;
	my@lcp;
	my$h=0;
	for(0..$n-1){
		$h--if$h>0;
		next if$rnk[$_]==0;
		my$j=$sa[$rnk[$_]-1];
		$h++while$j+$h<$n&&$_+$h<$n&&$s[$j+$h]==$s[$_+$h];
		$lcp[$rnk[$_]-1]=$h;
	}
	return@lcp;
}
sub lcp_array($@){
	my@s=map ord,split"",shift;
	return lcp(@s,@_);
}
package main;
my$s=<>;
chomp$s;
my@lcp=LcpArray::lcp_array($s,SuffixArray::suffix_array($s));
my$ans=length($s)*(length($s)+1)/2;
$ans-=$_ for@lcp;
print$ans,$/;


Measured memory_bytes: 263172
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a;
  b = a % 10;
  a = a - b;
  c = a % 100 / 10;
  a = a - c*10;
  d = a % 1000 / 100;
  cout << b+c+d << endl;
}

Measured memory_bytes: 256
N = int(input())
MOD = 10 ** 9 + 7
MAX = 10 ** 6 + 1000
fact = [0] * MAX
invfact = [0] * MAX
fact[0] = 1
for i in range(1, MAX):
    fact[i] = fact[i - 1] * i % MOD
invfact[MAX - 1] = pow(fact[MAX - 1], MOD-2, MOD)
for i in range(MAX - 2, -1, -1):
    invfact[i] = invfact[i+1] * (i+1) % MOD

def nCk(n, k):
    if k < 0 or n < k: return 0
    return (fact[n] * invfact[k] % MOD) * invfact[n-k] % MOD

def nPk(n, k):
    if k < 0 or n < k: return 0
    return fact[n] * invfact[n-k] % MOD



allcnt = pow(10,N,MOD)
notcnt = pow(8,N,MOD)
for i in range(1,N+1):
    notcnt += pow(8,N-i,MOD) * invfact[i] * invfact[N-i] * fact[N] * 2
    notcnt %= MOD

print((allcnt - notcnt) % MOD)


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

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


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

  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdbool.h>

int main(){
    int i, j, n;
    char mark;
    char marks[4]={'S', 'H', 'C', 'D'};
    int num;
    bool cards[4][13]={false};

    scanf("%d ", &n);
    for(i=0;i<n;i++){
        scanf("%c %d ", &mark, &num);
        for(j=0;j<4;j++){
            if(mark==marks[j]){
                cards[j][num-1]=true;
                break;
            }
        }
    }
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(!cards[i][j]){
                printf("%c %d\n", marks[i], j+1);
            }
        }
    }
    return 0;
}

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

int main() {
  int r,c;
  cin>>r>>c;
  vector<vector<int > > X(r+1,vector<int>(c+1));
  
  for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
      cin>>X.at(i).at(j);
       }}
  //合計値を計算する
  int sumi,sumj,sumij=0;
  for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
      sumi+=X.at(i).at(j); //縦sumj,横sumi,
    }
    X.at(i).at(c)=sumi;sumi=0;
    }
  
  for(int j=0;j<c;j++){
   for(int i=0;i<r;i++){
      sumj+=X.at(i).at(j);
    }
    X.at(r).at(j)=sumj;sumj=0;
    }
    
   for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
      sumij+=X.at(i).at(j);}}
  
    X.at(r).at(c)=sumij;
  
   for(int i=0;i<r+1;i++){
    for(int j=0;j<c+1;j++){
     cout<< X.at(i).at(j);
      if(j<c){cout<<" ";}
    }
      cout<<endl;
    }
  
  return 0;
}


Measured memory_bytes: 3128
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] s = br.readLine().toCharArray();
		long n = s.length;
		char[] t = br.readLine().toCharArray();
		TreeSet<Integer>[] poss = new TreeSet[26];
		for(int c = 0; c < 26; c++){
			poss[c] = new TreeSet<>();
		}
		for(int i = 0; i < n; i++){
			poss[s[i]-'a'].add(i);
		}
		int prev = -1;
		long count = 0;
		for(char c: t){
			if(poss[c-'a'].isEmpty()){
				System.out.println("-1"); return;
			}
			Integer curr = poss[c-'a'].higher(prev);
			if(curr == null){
				curr = poss[c-'a'].first();
				count++;
				prev = curr;
			}
			else{
				prev = curr;
			}
		}
		System.out.println(((long)count) * n + (long)prev + 1L);
	}

}


Measured memory_bytes: 32252
#include<iostream>
#include<vector>
using namespace std;
int main(){
int n,a,sum=0,max=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    sum+=a;
    if(a>max) max=a;
  }
  sum-=max/2;
  cout<<sum<<endl;
  return 0;
}

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



int main(){
    
    string S;
    cin >> S;
    
    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());
    
    string T;
    T="abcdefghijklmnopqrstuvwxyz";
    
    for(char y:S){
        int itr=T.find(y);
        T.erase(T.begin()+itr);
    }
    if(T==""){
        cout <<"None"<<endl;
    }
    else{
        cout << T[0] <<endl;
        }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_
void debug_out() {cerr << endl;}
template<typename Head,typename... Tail> void debug_out(Head H,Tail... T){cerr << ' ' << H; debug_out(T...);}
#define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:",debug_out(__VA_ARGS__)
#define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl;
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

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

    ll N; cin >> N;
    ll X,M; cin >> X >> M;

    ll now = X;
    vector<int> visited(M,0);
    vector<int> route;
    while (!visited[now]) {
        visited[now] = 1;
        route.push_back(now);
        now = now*now%M;
    }

    ll n = X;
    int idx = 0;
    while (n != now) {
        n = n*n%M;
        ++idx;
    }

    ll loop = 0;
    int sz = (int)route.size() - idx;
    vector<ll> bf(idx);
    vector<ll> x(sz);
    for (int i = 0;i < idx;++i) bf[i] = route[i];
    for (int i = idx;i < (int)route.size(); ++i) {
        x[i - idx] = route[i];
        loop += route[i];
    }

    ll ans = 0;
    if (N <= idx) {
        rep(i,N) ans += bf[i];
    } else {
        rep(i,idx) ans += bf[i];
        N -= idx;
        ans += loop * (N/sz);
        rep(i,N%sz) ans += x[i];
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 4188
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
 
int main(){
  int N;
  string S;
  cin >> N;
  cin >> S;
  map<char,int> mp;
  for(int i=0;i<N;i++){
    mp[S[i]]++;
  }
  long long ans = 1; 
  for(pair<char,int> p : mp){
    ans *= p.second+1;
    ans %= INF;
  }
  cout << ans-1 << endl;
}

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

using namespace std;

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

typedef long long ll;

int main(){
    
    while(true){
        int n;
        cin>>n;
        if(n==0)break;
        
        string s;
        cin>>s;
        
        REP(d,n){
        char x=s[0];
        int cnt=0;
        string nexts;
        for(int i=0;i<s.size();i++){
            if(x!=s[i]){
                nexts=nexts+to_string(cnt)+x;
                x=s[i];
                cnt=0;
            }
            cnt++;
        }
            nexts=nexts+to_string(cnt)+x;
            s=nexts;
        }
        
        cout<<s<<endl;
        
    }
    return 0;
}

Measured memory_bytes: 3408
#include <stdio.h>

int main(){
    char number[1001];
    int i, sum;
    while(1){
        scanf("%s", number);
        if(number[0]=='0')break;
        sum=0;
        for(i=0;number[i]!='\0';i++){
            sum+=number[i]-'0';
        }
        printf("%d\n", sum);
    }

    return 0;
}


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0;(i) < (ll)(n);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1;(i) >= 0LL;(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, M;
    ll temp;
    ll count;
    cin >> N >> M;
    count = min(N, M / 2);
    temp = M - 2 * N;
    cout << count + max(0LL, temp / 4) << endl;
    return 0;
}


Measured memory_bytes: 256
import itertools
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
target= range(1,n+1)
p_len=0
q_len=0
for i,v in enumerate(itertools.permutations(target,n)):
    tmp=list(v)
    if p==tmp:
        p_len=i
    if q==tmp:
        q_len=i
print(abs(p_len-q_len))

Measured memory_bytes: 9100
N = int(input())
H = list(map(int, input().split()))

for i in reversed(range(1, N)):
  if H[i] < H[i-1]:
    if H[i] == H[i-1] - 1:
      H[i-1] -= 1      
    else:
      print("No")
      exit()
print("Yes")


Measured memory_bytes: 14396
#1行に入力が複数の場合
a, b = map(int, input().split())

#絶対値が等しい＝距離が等しいと考える（なんかSさんに怒られそうな表現ww）
#a-bから距離が等しいということはa-b間にKがあるのは自明
#a-bの外側にKは存在しない
#また、そのような値は2点の中点であることは自明

#ただし、制約でKは整数なので中点が整数にならない場合
#条件を満たすKは存在しない

#a-bの中点が2で割り切れる=中点が整数である場合
if (a + b) % 2 == 0:
    #2点の中点を出力
    print((a + b) // 2)
#整数となるKが存在しない場合
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 38256
/**
 * @author torith
 * @date 2018-10-24
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; cin >> N;

    int C[500],S[500],F[500];
    for (int i = 0; i < N - 1; ++i) {
        int c,s,f;
        cin >> c >> s >> f;
        C[i] = c;
        S[i] = s;
        F[i] = f;
    }

    for (int i = 0; i < N - 1; ++i) {
        ll ans = 0;
        ans += S[i] + C[i];
        for (int j = i + 1; j < N - 1; ++j) {
            if (ans <= S[j]) ans = S[j] + C[j];
            else {
                int a = S[j];
                while(a < ans) a += F[j];
                ans = a + C[j];
            }
        }
        cout << ans << "\n";
    }
    cout << "0" << "\n";

    return 0;
}



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

int main() {
    string S, A, C;
    char SS, AA, CC;
    cin >> A >> S >> C;
    
    SS = S.at(0), AA = A.at(0), CC = C.at(0);
    
    cout << AA << SS << CC << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
int main()
{
    string a,b;
    cin>>a>>b;
    int len1 = a.size();
    int len2 = b.size();
    int ans = 0;
    for(int i = 0; i < len1; i++){
        if(a[i] != b[i]){
            ans++;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3892
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
cumA = [0] * (N+1)
cumB = [0] * (M+1)

point = 0
for i in range(N):
    cumA[i+1] = cumA[i] + A[i]
for i in range(M):
    cumB[i+1] = cumB[i] + B[i]

# 尺取りの要領でiを増やしjを減らす
res, j = 0, M
for i in range(N+1):
    if cumA[i] > K:
        break
    while cumB[j] > K - cumA[i]:
        j -= 1
    res = max(res, i+j)

print(res)

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

int main()
{
	int i,s=0,c=0,n;
	cin>>n;
	int a[n+1];
	for(i=1;i<=n;i++)  cin>>a[i];
	sort(a+1,a+n+1);
	for(i=1;i<=n;i+=2)
	s+=a[i];
	for(i=2;i<=n;i+=2)
	c+=a[i];
	cout<<fabs(s-c)<<endl;
	return 0;  
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
ao = []
for i in range(N):
    ao.append(input())

ao_cnt = Counter(ao)

M = int(input())
aka = []
for i in range(M):
    aka.append(input())

aka_cnt = Counter(aka)

ao_cnt.subtract(aka_cnt)
if ao_cnt.most_common(1)[0][1] <= 0:
    print(0)
else:
    print(ao_cnt.most_common(1)[0][1])

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

int main(){
    int A,B,X;
    char op;
    cin>>A>>op>>B;
    if (op=='+'){
        X = A + B;
    }
    else if(op=='-'){
        X = A - B;
    }
    cout<<X<<endl;
    }


Measured memory_bytes: 256
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let n: usize = read!();
    println!("{}", solve(n));
}

fn solve(n: usize) -> usize {
    let s = n.to_string();
    let sum: usize = s.chars().map(|c| c.to_digit(10).unwrap() as usize).sum();
    let s = n.to_string();
    let f = s.chars().next().unwrap().to_digit(10).unwrap() as usize;
    let l = s.chars().count() - 1;
    sum.max(f - 1 + 9 * l)
}


Measured memory_bytes: 2192
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        while (true) {
            int n = Integer.parseInt(scan.next());
            if (n == 0) {
                break;
            }

            int[] w = new int[n];
            for (int i = 0; i < n; i++) {
                w[i] = Integer.parseInt(scan.next());
            }

            int dp[][] = new int[n + 1][n + 1];
            for (int i = 2; i <= n; i++) {
                for (int j = 0; j + i <= n; j++) {
                    for (int k = j; k <= j + i; k++) {
                        dp[j][j + i] = Math.max(dp[j][j + i], dp[j][k] + dp[k][j + i]);
                    }

                    if (dp[j + 1][j + i - 1] == i - 2 && Math.abs(w[j] - w[j + i - 1]) <= 1) {
                        dp[j][j + i] = i;
                    }
                }
            }

            System.out.println(dp[0][n]);
        }
        scan.close();
    }

}



Measured memory_bytes: 56124
#include<stdio.h>
#include<limits.h>
int main(void){
	int n,m = INT_MIN,s,i ;
	scanf("%d",&n);
	
	int a[n];
	for(i = 0;i < n;i++){
		scanf("%d",&a[i]);
	}
	s = a[0];
	for(i = 1;i < n;i++){
		if(m <=a[i]-s){
			m = a[i]-s;
		}
		if(s>a[i]){
			s = a[i];
		}
	}
	printf("%d\n",m);
	
}


Measured memory_bytes: 2564
// Created by arjun_singh12 (Arjun Singh) on [21-04-2020 03:05:39]
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define M 1000000007
#define INF LLONG_MAX
#define vll vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>>
#define pb push_back
#define pll pair<ll,ll>
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define repr(i,n,a) for(ll i=n;i>=a;i--)
#define endl "\n"
#define db(x); cout<<"Debug: "<<#x<<" = "<<x<<endl;
#define dbv(v); cout<<"Debug: Vector "<<#v<<" = "; for(ll i=0;i<sz(v);i++) cout<<v[i]<<" "; cout<<endl;
using namespace std;
int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	ll test=1;
	// cin>>test;
	while(test--)
	{
	    ll n; cin>>n;
	    vll v(n);
	    rep(i,0,n)
	    {
	    	cin>>v[i];
	    }
	    vll dp(n);
	    dp[0]=0;
	    dp[1]=dp[0]+abs(v[1]-v[0]);
	    rep(i,2,n)
	    {
	    	dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
	    }
	    // dbv(dp);
	    cout<<dp[n-1]<<endl;
	}
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(){
	int arr[3][3];
	int tc;
	int add;
	int check[3][3]= {0};
	int count;
	int i,j;
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			scanf("%d", &arr[i][j]);
		}
	}
	scanf("%d",&tc);
	int k;
	
	for(k=0;k<tc;k++){
		scanf("%d",&add);
		int j;
		for(i=0;i<3;i++){
			for(j=0;j<3;j++){
				if(arr[i][j]== add){
					check[i][j] = 1;
				}
			}
		}
	}
	if(check[0][0]+ check [1][1]+ check[2][2]== 3 || check [0][2]+check [1][1]+ check[2][0]==3){
		printf("Yes\n");
		return 0;
	}
	for(i=0;i<3;i++){
		if(check[i][0]+check[i][1]+check[i][2]==3 || check [0][i]+check[1][i]+check[2][i]==3){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	
	return 0;
}

Measured memory_bytes: 1632
#include <stdio.h>

int main(void)
{
	int a,b,c,d,e,k;
	if(scanf("%d%*c%d%*c%d%*c%d%*c%d%*c%d%*c", &a, &b, &c, &d, &e, &k) < 0) {
		return 0;
	}

	if(e-a <= k) printf("Yay!");
	else printf(":(");
	
	return 0;
}


Measured memory_bytes: 128
use std::io::BufRead;

fn main() {
    let stdin = std::io::stdin();
    let (a, b): (u32, u32) = stdin.lock().gets().split(' ').values();
    println!("{}", if a <= b { a } else { a - 1 });
}

trait Gets { fn gets(&mut self) -> String; }
impl<T: std::io::BufRead> Gets for T {
    fn gets(&mut self) -> String { self.lines().next().unwrap().unwrap() } }

trait Values<T> { fn values(&mut self) -> T; }
impl<'a, I, T1, T2> Values<(T1, T2)> for I
    where I: Iterator<Item=&'a str>,
          T1: std::str::FromStr, T1::Err: std::fmt::Debug,
          T2: std::str::FromStr, T2::Err: std::fmt::Debug {
    fn values(&mut self) -> (T1, T2) {
        (self.next().unwrap().parse().unwrap(),
         self.next().unwrap().parse().unwrap())
    }
}


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

int main() {
  string s,t;
  cin >> s >> t;
  int cnt = 0;
  rep(i,3) {
    if (s.at(i) == t.at(i)) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
    #define sz(a) (int)(a).size()
     
    using namespace std;
     
    template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
    template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
    const int INF = 2e5+2;
    const long long hell = 998244353ll;
    
    void solve(){
          int n;
          cin>>n;
          cout<<(3*n*n)<<endl;
    }

    int main(){
    	
    	ios_base::sync_with_stdio(0);cin.tie(0);
    	
    	int q=1;
    #ifdef LOCAL
      	cin>>q;
#endif
	while(q--){
	 solve();
	}

    #ifdef LOCAL
        cout << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
    #endif	
    	return 0;
    }

Measured memory_bytes: 256
use std::collections::*;
use std::cmp::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        s: String,
    };

    let res;
    if s == "AAA".to_string() || s == "BBB".to_string() {
        res = "No";
    } else {
        res = "Yes";
    }
    println!("{}", res);

}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            string s = Console.ReadLine();
            Console.WriteLine(100 * (7 + s.Count(x => x == 'o')));

            //Console.Out.Flush();
            
        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}



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

const int N=2e5+100;
const int mod=1e9+7;
typedef long long ll;
ll a[N];
ll sum[N];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    sum[n]=a[n];
    for(int i=n-1;i>=2;i--){
        sum[i]=(sum[i+1]+a[i])%mod;
    }

    ll ans=0;
    for(int  i=1;i<=n-1;i++){
        ans=(ans+a[i]*sum[i+1]%mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6712
n, m = map(int, input().split())
p_y_num_list = sorted([list(map(int, input().split())) + [i] for i in range(m)])
now = p_y_num_list[0][0]
num = 1
for pyn in p_y_num_list:
    if pyn[0] != now:
        num = 1
        now = pyn[0]
        pyn.append(num)
    else:
        pyn.append(num)
    num += 1
p_y_num_list.sort(key=lambda x: x[2])
for p, y, i, n in p_y_num_list:
    print("{:06}{:06}".format(p, n))

Measured memory_bytes: 31372