akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;

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

	int a, M, m;
	long long s = 0;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (i == 0)M = m = a;
		M = a > M ? a : M;
		m = a < m ? a : m;
		s += a;
	}
	cout << m << " " << M << " " << s << endl;
	return 0;
}

Measured memory_bytes: 1164
object Main extends App{
  override def main(args: Array[String]) : Unit = {
    val scanner = new java.util.Scanner(System.in)
    
    val a,b = scanner.nextInt

    val (area,round) = solve(a,b)
    println(area + " "+round)
  }
  
  def solve(a: Int , b : Int) :(Int, Int) = {
    val x = area(a,b)
    val y = round(a,b)
    (x,y)
  }

  def area(a:Int, b:Int) : Int = {
    a*b
  }

  def round(a:Int, b:Int) : Int = {
    a*2 + b*2
  }
}

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

int main(int argc, char const *argv[]) {
  int n;
  int sum=0;
  std::cin >> n;
  int a[n+1];
  for (size_t i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  for (size_t j = 0; j < n; j++) {
    if (a[a[j]-1]==j+1) {
      sum++;
    }
  }
  std::cout << sum / 2 << std::endl;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>

using namespace std;

int main() {
  char s[16];
  while (scanf("%s", s) == 1) {
    for (int i = 0; i < 10; i++)
      s[i] -= '0';
    for (int j = 9; j >= 1; j--)
      for (int i = 0; i < j; i++)
        s[i] = (s[i] + s[i+1]) % 10;
    printf("%c\n", s[0] + '0');
  }
  return 0;
}

Measured memory_bytes: 0
N,*H = map(int,open(0).read().split())
maxLen = 0
tmpCnt = 0
for i in range(N-1):
  if H[i] >= H[i+1]:
    tmpCnt += 1
  else:
    tmpCnt = 0
  maxLen = max(maxLen,tmpCnt)

print(maxLen)

Measured memory_bytes: 71228
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
bool saw[1000000];
int main(){
  long long K;
  cin >> K;
  
  long long cur_mod = 7 % K;
  int count = 1;
  while(true){
    if(cur_mod == 0){
      cout << count << endl;
      return 0;
    }
    if(saw[cur_mod]){
      break;
    }
    saw[cur_mod] = true;
    count ++;
    cur_mod = ((10 * cur_mod) % K + 7 % K)% K;
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 4524
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int m, n; scanf("%d%d", &m, &n);
	std::vector<int> p(n);
	std::vector<std::string> s(n);
	for(int i = 0; i < n; i++) cin >> p[i] >> s[i];

	int penalty = 0, ac = 0;
	std::vector<int> cnt(m + 1);
	std::vector<bool> used(m + 1, false);
	for(int i = 0; i < n; i++) {
		if(used[p[i]]) continue;
		if(s[i] == "WA") {
			cnt[p[i]]++;
		} else {
			used[p[i]] = true;
			penalty += cnt[p[i]];
			ac++;
		}
	}

	printf("%d %d\n", ac, penalty);
	return 0;
}


Measured memory_bytes: 6528
import math

def main():
    N, D = map(int, input().split())
    l = []
    for i in range(N):
        l.append(list(map(int, input().split())))
    cnt = 0
    for i in range(N):
        x = l[i][0]
        y = l[i][1]
        a = math.sqrt(x ** 2 + y ** 2)
        if a <= D:
            cnt += 1
    print(cnt)
    
main()  

Measured memory_bytes: 45452
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int A,B;
  cin>>A>>B;
  if(A+B<10) cout<<A+B;
  else cout<<"error";
return 0;}

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

int main(){
    int N; cin >> N;
    vector <int> A(N),B(N);
    for (int i=0; i<N; i++){
        cin >> A[i];
        B[i]=A[i];
    } 
    
    sort(A.begin(),A.end());
    int cnt=0;
    for (int i=0; i<N; i++){
        if (A[i]!=B[i]) cnt++;
    }
    
    if (cnt<=2) cout << "YES";
    else cout << "NO";
}

Measured memory_bytes: 256
// g++ -Wall -Wextra -pedantic -std=c++17 -O3 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -fsanitize=address -fno-sanitize-recover -fstack-protector contest.cpp

#include <bits/stdc++.h>

// #define _GLIBCXX_DEBUG 1
// #define _GLIBCXX_DEBUG_PEDANTIC 1
// #define _FORTIFY_SOURCE 2

using namespace std;
#define int long long
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
int invmod(int a, int md){return powmod(a,md-2,md);}
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii;
typedef vector<ll> vl; typedef pair<ll,ll> pll; typedef vector< pair<ll,ll> > vll;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return ((a%md)*(b%md))%md;}
int addmod(int a, int b, int md) {return (a+b)%md;}
int submod(int a, int b, int md) {return (((a-b)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
const int MX = 400010;

int f[MX];
int rf[MX];

int C(int l,int k, int md) 
{
    if (k<0||k>l){
        return 0;
    }
    return f[l]*rf[k]%md*rf[l-k]%md;
}

void precfac() {
    f[0]=1;
    for (int i=1;i<MX;i++){
        f[i]=f[i-1]*i%MOD;
    }
    rf[MX-1]=powmod(f[MX-1],MOD-2, MOD);
    for (int i=MX-2;i>=0;i--){
        rf[i]=rf[i+1]*(i+1)%MOD;
    }
}


signed main(void)
{
	IOS;
	precfac();
	int n,k; cin>>n>>k;
	if(k>=n) {
		k=n;
	}
	int ans=1;
	for(int i = 1; i <= k; i++) {
		int tp=C(n,i,MOD)*C(n-1,n-i-1,MOD);
		tp%=MOD;
		ans+=tp;
		ans%=MOD;
	}
	cout<<ans<<endl;
	// int ans=0;
	// for(int i = 0; i <= n; i++) {
	// 	int tp=0;
	// 	if(n-i-1<0 || n+k-2*i-1<0) break;
	// 	tp=C(n,i,MOD)*powmod(2,i,MOD);
	// 	tp%=MOD;
	// 	tp*=C(n+k-2*i-1,n-i-1,MOD);
	// 	tp%=MOD;
	// 	ans += tp;
	// 	tp%=MOD; 
	// }
	// cout<<ans<<endl;
	time();
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;
 
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int N;
  cin >> N;
  int A[N];
  for(int i = 0;i<N;i++){
    cin >> A[i];
  }
  sort(A, A+N);
  int ans = INF;
  int ans1 = INF;
  if(A[N-1]%2 == 0){
    for(int i=0;i<N-1;i++){
      if(ans > abs(A[N-1]/2-A[i])){
        ans = abs(A[N-1]/2-A[i]);
        ans1 = A[i];
      }
    }
    cout << A[N-1] << endl;
    cout << ans1 << endl;
    return 0;
  }
  else{
    for(int i=0;i<N-1;i++){
      if(ans > min(abs(A[N-1]/2-A[i]), abs(A[N-1]/2-A[i]+1))){
        ans = abs(A[N-1]/2-A[i]);
        ans1 = A[i];
      }
    }
    cout << A[N-1] << endl;
    cout << ans1 << endl;
    return 0;
  }
}

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

using namespace std;
typedef long long ll;
const int maxn = 1005;

int main()
{
    int n,k;
    string s;
    while(cin>>n>>k>>s){
        int ans = 0;
        int head = 0, tail = 0;
        int k2 = k;
        while(head < n){
            while(head < n && s[head] == '1') head++;
            ans = max(ans , head - tail);
            bool flag = false;
            while(head < n && s[head] == '0') head++, flag = true;
            if(flag)
                k2--;
            if(k2 < 0){
                while(tail < n && s[tail] == '1')
                    tail++;
                while(tail < n && s[tail] == '0')
                    tail++;
            }
            ans = max(ans, head - tail);
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

	
			var inputArray = retreiveLongArray();
			var inputCount = 3;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			long M = inputArray[1];
			long X = inputArray[2];

			 var sankoushoInfo = new Dictionary<long,Dictionary<int,long>>();

			for (int i = 0; i < N; i++) {
				var sankousho = retreiveLongArray();
				var sankouDic = new Dictionary<int, long>();
				for (int j = 0; j <= M; j++) {
					sankouDic.Add(j, sankousho[j]);
				}
				sankoushoInfo.Add(i,sankouDic);
			}
			_sankoushoInfo = sankoushoInfo;

			long minMoney = int.MaxValue;

			//ビット全探索
			for (int i = 0; i < Math.Pow(2,N); i++) {

				long currentMoney = 0;

				var gakuryoku = new Dictionary<long, long>();

				for (int j = 1; j <= M; j++) {
					gakuryoku.Add(j, 0);
				}

				for (int j = 0; j < N; j++) {

					var x = (i >> j) & 1;
					var buyorNot = (x == 1);
					//買う場合は学力を向上させる
					if (buyorNot) {
						var sankousho = _sankoushoInfo[j];
						for (int k = 1; k <= M; k++) {
							gakuryoku[k] += sankousho[k];
						}
						//金額を加算する
						currentMoney += sankousho[0];
					}
				}
				//学力が基準を満たしているか判定
				var hantei = true;
				for (int k = 1; k <= M; k++) {
					if (gakuryoku[k] < X) {
						hantei = false;
						break;
					}
				}

				if (hantei) {
					minMoney = Math.Min(minMoney, currentMoney);
				}

			}

			//答えの出力
			var ans = minMoney == int.MaxValue? -1:minMoney;
			Console.WriteLine(ans);

		}



		private static Dictionary<long, Dictionary<int, long>> _sankoushoInfo;

		

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 32488
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), m = in.nextInt();
		StringBuilder sb = new StringBuilder();
		do {
			sb.setLength(0);
			int[] point = new int[m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					point[j] += in.nextInt();
				}
			}
			for (int i = 0; i < n; i++) {
				int cp = n - i;
				for (int j = 0; j < m; j++) {
					if (point[j] == cp) {
						sb.append(' ');
						sb.append(j + 1);
					}
				}
			}
			System.out.println(sb.substring(1));
			n = in.nextInt();
			m = in.nextInt();
		} while (n != 0 || m != 0);
		in.close();
	}
}

Measured memory_bytes: 80500
N=int(input())
can=set()

can.add(1)
i=1
ans=0
while True:
  ans=6**i
  if ans<=100000:
    can.add(ans)
    i+=1
  else:
    break
    
j=1
ans=0
while True:
  ans=9**j
  if ans<=100000:
    can.add(ans)
    j+=1
  else:
    break

dp=[0]*(N+1)
dp[0]=0
dp[1]=1

for k in range(2,N+1):
  mini=10000000
  for item in can:
    if k-item>=0:
      mini=min(mini, dp[k-item]+1)
  dp[k]=mini

print(dp[-1])

Measured memory_bytes: 3828
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]


N, X = map(int, input().split())
L = [0] + list(map(int, input().split()))

now = 0
ans = 1
for i in range(1, N+1):
    now = now + L[i]
    if now <= X:
        ans += 1
print(ans)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define  ll long long
const int N = 100005;
const int mod = 1e9+7;
ll x[N];
int main()
{
    ll n,a,b;
    scanf("%lld%lld%lld",&n,&a,&b);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&x[i]);
    }
    ll ans=0;
    for(int i=2;i<=n;i++)
    {
        ll t1=(x[i]-x[i-1])*a;
        ll t2=b;
       if(t1>t2)
        ans+=t2;
       else
        ans+=t1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, K, S;
    cin >> N >> K >> S;
    vector<int> A(N);
    if(S != 1e9) {
        rep(i, N) {
            if(i < K)
                A[i] = S;
            else
                A[i] = 1e9;
        }
    } else {
        rep(i, N) {
            if(i < K)
                A[i] = S;
            else
                A[i] = 1;
        }
    }
    rep(i, N) cout << A[i] << (i == N - 1 ? '\n' : ' ');
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b;
  char f = 'a';
  string s, t;
  in2(s, t);
  vector<ll> c(26, 0), d(26, 0);
  rep(i, 26){
    rep(j, s.size()){
      if(s[j] == f)
        c[i]++;
      if(t[j] == f)
        d[i]++;
    }
    f++;
  }
  sort(all(c));
  sort(all(d));
  a = 0;
  rep(i, 26){
    if(c[i] != d[i])
      a++;
  }
  if(a)
    out("No");
  else
    out("Yes");
  memi;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

struct UnionFindTree {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;

    void init(int n) {
        par.resize(n);
        rank.resize(n);
        siz.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        siz[x] += siz[y];
    }
    bool is_same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        x = find(x);
        return siz[x];
    }
};

int main() {
    while(1){
        int n, m;
        cin >> n >> m;
        if(n==0)break;
        vector<P> v(m);
        bool ok = true;
        REP(i,m){
            cin >> v[i].first >> v[i].second;
            if(v[i].first==v[i].second)ok=false;
        }
        SORT(v);
        UnionFindTree g;
        g.init(n+1);
        vector<int> cnt(n+1,0);
        REP(i,m){
            int a = v[i].first, b=v[i].second;
            if(!g.is_same(a,b) && cnt[a]<2 && cnt[b]<2){
                g.unite(a,b);
                cnt[a]++;
                cnt[b]++;
            }
            else {
                ok = false;
                break;
            }
        }
        cout << (ok?"yes":"no") << endl;
    }
    return 0;
}



Measured memory_bytes: 7020
#include"bits/stdc++.h"
using namespace std;

void Main() {
  string s;
  cin >> s;

  long long int ans = 0;
  for (int i = 0; i < (1 << (s.length() - 1)); i++) {
    long long int res = 0, tmp = 0;
    for (int j = 0; j < s.length(); j++) {
      int num = s[j] - '0';
      tmp = tmp * 10 + num;
      if (i & (1 << j)) {
        res += tmp;
        tmp = 0;
      }
    }
    res += tmp;
    ans += res;
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(){
    int n,m,*a,sum;
    sum=0;
    scanf("%d %d",&n,&m);
    a=(int*)malloc(sizeof(int));
    for(int i=0;i<m;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    if(sum>n){
        printf("-1");
    }
    else{
        printf("%d",n-sum);
    }
}

Measured memory_bytes: 1764
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define watch(x) cout << #x << " is " << x << endl;
#define print(a, l, r)          \
	for (int i = l; i < r; i++) \
		cout << a[i] << (i == (r - 1) ? endl : " ");
const long long M = 1000000007;
int main()
{

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

	int n;
	cin >> n;
	int sum = 0;
	int a[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		ans += a[i] * (sum - a[i]);
	}
	ans /= 2;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<fstream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define Set(a) memset(a,0,sizeof(a))
#define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define openf(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define re register
#define ri re int
#define il inline
typedef long long ll;
typedef unsigned long long ull;
template<typename T> inline T rd(T& x)
{
	T f=1;x=0;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(; isdigit(c);c=getchar()) x=(x<<3)+(x<<1)+(T)(c-'0');
	x*=f;
	return x;
}
ll rd(){ll x;rd(x);return x;}
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
const int inf=1<<30;

ll ans[100005];int tot=0;
const ll mx=3234566667ll;
void dfs(ll k)
{
	if(k>mx) return;
	ans[++tot]=k;
	int d=k%10;
	if(d>=1) dfs(k*10+d-1);
	dfs(k*10+d);
	if(d<=8) dfs(k*10+d+1);
}
int main()
{
	F(i,1,9) dfs(i);
	sort(ans+1,ans+100001);
	cout<<ans[rd()]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

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

void checkace(int &hand, int &ace){
	if(ace && hand > 21){
		hand -= 10;
		ace--;
	}
}

int main(){
	int dataset;
	cin >> dataset;
	map<char, int> card;
	rep(i, 9){
		card['1'+i] = 1+i;
	}
	rep(i, 4){
		card["TJQK"[i]] = 10;
	}
	card['A'] = 11;
	while(dataset--){
		int hand = 0, ace = 0;
		rep(i, 2){
			char c;
			cin >> c;
			int n = card[c];
			hand += n;
			if(n == 11) ace++;
		}
		checkace(hand, ace);

		queue<int> pile;
		rep(i, 8){
			char c;
			cin >> c;
			pile.push(card[c]);
		}
		bool bj = hand==21;
		while(hand <= 16 || (hand == 17 && ace > 0)){
			int n = pile.front();
			pile.pop();
			hand += n;
			if(n == 11) ace++;
			checkace(hand, ace);
		}

		if(hand > 21) cout << "bust" << endl;
		else{
			if(bj){
				cout << "blackjack" << endl;
			}else{
				cout << hand << endl;
			}
		}
	}

	return 0;
}

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a);i>(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1000000000;
const LL MOD = 1000000007;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

int main() {
  LL N;
  cin >> N;
  cout << N*(N-1)/2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    string S;
    cin >> S;

    ll zeroStart = 0;
    ll oneStart = 0;
    rep(i, S.size()){
        if(i % 2 == 0){
            if(S[i] == '0'){
                oneStart++;
            }else{
                zeroStart++;
            }
        }else{
            if(S[i] == '0'){
                zeroStart++;
            }else{
                oneStart++;
            }
        }
    }

    cout << min(zeroStart, oneStart) << endl;

    return 0;
}

Measured memory_bytes: 3656
#include <cstring>
#include <iostream>
#include <cstdio>

const int M = 500500;
char c[M], ch[M];
int len;

int main()
{
	scanf("%s", c + 1);
	len = strlen(c + 1);
	for (int i = 1; i <= len; ++i)
	{
		switch (c[i])
		{
			case 'b':{
				ch[i] = 'd';
				break;
			}
			case 'd':{
				ch[i] = 'b';
				break;
			}
			case 'p':{
				ch[i] = 'q';
				break;
			}
			case 'q':{
				ch[i] = 'p';
				break;
			}
		}
	}
	for (int i = 1; i <= len; ++i)
		if (c[i] != ch[len - i + 1])
		{
			puts("No");
			return 0;
		}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 384
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>


using namespace std;
#define modd 1000000007



typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};


class SegmentTree {
private:
	int n;
	vector <ll> node;

public:
	// 元の配列　v をセグメントツリーで表現する。
	SegmentTree(vector<ll> v) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく。
		//セグ木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1; 
		while (n < sz)n *= 2;

	}

};




long long N, M, K, a, b, c, d, e, H, W, L;
ll A[300005] = {};
ll B[300005] = {};
ll C[300005] = {};
bool f, ff;
string S;
set <long long>sll;
pl bufpl;
vector <long long>vl[100005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset;
multiset<ll> llmset;


struct ST
{
	int kaisuu;
	int dan;
	int score;
	char situ[52][2][2];
	

	bool operator<(const ST& another) const
	{
		return dan < another.dan;//比較
	};

};



/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


ll minn, maxx;
double ansa;

string SS;
char ca;



int main() {



	for (int i = 0; i < 26; i++) {
		B[i] = 'A' + i;
	}
	for (int i = 0; i < 26; i++) {
		B[i + 26] = 'a' + i;
	}

	while (true) {


		cin >> N;

		if (N == 0) {
			break;
		}

		for (int i = 0; i < N; i++) {
			cin >> A[i];
		}


		cin >> SS;

		a = 0;
		f = false;

		for (int i = 0; i < SS.size(); i++) {

			if(SS[i]-'a'>=0){
				a = SS[i] - 'a';
				a += 26;
			}
			else {
				a = SS[i] - 'A';
			}
			a -= A[i % N];


			if (a < 0) {
				a += 52;
			}
			
			S += B[a];

		}


		cout << S << endl;

		S = "";
		SS = "";

	}

	return 0;

}



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

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

    auto x = vector<vector<int>>(n);
    for (auto &x_i : x) {
        x_i.resize(d);
        for (auto &x_ij : x_i)
            cin >> x_ij;
    }

    auto counter = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            auto sum = 0LL;
            for (int dim = 0; dim < d; dim++) {
                auto dx = x[j][dim] - x[i][dim];
                sum += dx * dx;
            }

            for (int m = 1; m * m <= sum; m++) {
                if (m * m == sum) {
                    counter++;
                    break;
                }
            }
        }
    }

    cout << counter;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>

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

using namespace std;

int n,m,card[100000];

int solve(const int A[500][500],int win){ // win : 揃えるべき列の個数
	static int X[1000001],Y[1000001];
	rep(i,1000001) X[i]=-1;
	rep(i,n) rep(j,n) X[A[i][j]]=j, Y[A[i][j]]=i;

	int tate[500]={},yoko[500]={},naname1=0,naname2=0;
	rep(i,m){
		if(X[card[i]]==-1) continue;

		int x=X[card[i]],y=Y[card[i]];
		if(++tate[x]==n) win--;
		if(++yoko[y]==n) win--;
		if(x-y== 0  && ++naname1==n) win--;
		if(x+y==n-1 && ++naname2==n) win--;

		if(n==1) win+=3; // コーナーケース!!!!!

		if(win<=0) return i;
	}
	return m;
}

int main(){
	int usagi,neko; scanf("%d%d%d%d",&n,&usagi,&neko,&m);
	static int U[500][500],N[500][500];
	rep(i,n) rep(j,n) scanf("%d",U[i]+j);
	rep(i,n) rep(j,n) scanf("%d",N[i]+j);
	rep(i,m) scanf("%d",card+i);

	int ans_u=solve(U,usagi);
	int ans_n=solve(N,neko);
	if     (ans_u<ans_n) puts("USAGI");
	else if(ans_u>ans_n) puts("NEKO");
	else                 puts("DRAW");

	return 0;
}

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

using namespace std;
#define ll long long
class gfg 
{ 
 public : ll gcd(ll a, ll b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
  
   
// Function to return LCM of two numbers  
  ll lcm(ll a, ll b)  
 {  
    return (a*b)/gcd(a, b);  
 }  
} ; 

int main()
{
	ll a, b;
	cin >> a >> b;
	gfg g;
	cout << g.lcm(a, b);
	return 0;
}


Measured memory_bytes: 256
# include <iostream>
using namespace std;
int main() {
   
  int n, count_r = 0;
  string st; 
  cin >>  n >> st;;
  for (int i = 0; i < n; ++i) {
      if (st[i] == 'R')  ++count_r;
  }
  string ans = "No";
  if (count_r > n - count_r)   ans = "Yes";
  cout << ans << endl;
 return 0;
}

Measured memory_bytes: 256
x = 0
n = int(input())
s = str(input())
s = list(s)
data = []
for i in range(n):
    if s[i] == 'I':
        x += 1
    elif s[i] == 'D':
        x = x-1
    data.append(x)
m = max(data)
if m > 0:
    print(m)
else:
    print(0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vi a(n); rep(i,n) cin >> a[i];
  rep(i,n){
    if(a[i] % 2 == 1){
      cout << "first\n";
      return 0;
    }
  }
  cout << "second";
  cout << "\n";
  return 0;
}


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

int main(){
  int h, w;
  cin >> h >> w;
  int mpt[10][10];
  for(int i=0; i<10; ++i) for(int j=0; j<10; ++j){
    cin >> mpt[i][j];
  }
  int t[10];
  for(int i=0; i<10; ++i) t[i] = mpt[i][1];
  mpt[1][1] = 0;
  for(int i=0; i<9; ++i){
    for(int j=0; j<10; ++j) for(int k=0; k<10; ++k){
      t[j] = min(t[j], mpt[j][k] + t[k]);
    }
  }
  /*
  for(int i=0; i<10; ++i) cout << t[i] << " ";
  cout << endl;
  */
  int ans = 0;
  for(int i=0; i<h; ++i) for(int j=0; j<w; ++j){
    int x;
    cin >> x;
    if(x == -1) continue;
    ans += t[x];
  }
  cout << ans << endl;
}


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

int main()
{
	int X;
	scanf("%d", &X);
	
	int c;
	c = (X - (X % 100)) / 100;
	
	if(c >= 20) printf("1");
	else if ( X % 100 > 5*c ) printf("0");
	else printf("1");
	
	return 0;
}


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

bool smaller(const pair<int, int>& x, const pair<int, int>& y) {
    return x.second < y.second;
}

int main() {
    int H, W, M;
    cin >> H >> W >> M;
    map<int, int> rowMap;
    map<int, int> colMap;
    map<pair<int, int>, int> mat;
    for (int i = 0; i < M; ++i) {
        int h, w;
        cin >> h >> w;
        ++rowMap[h];
        ++colMap[w];
        ++mat[make_pair(h, w)];
    }
    vector<pair<int, int>> row;
    vector<pair<int, int>> col;
    vector<int> rowVec;
    vector<int> colVec;
    row.reserve(H);
    rowVec.reserve(H);
    col.reserve(W);
    colVec.reserve(W);
    for (auto x : rowMap) {
        row.push_back(x);
        rowVec.push_back(x.second);
    }
    for (auto x : colMap) {
        col.push_back(x);
        colVec.push_back(x.second);
    }

    sort(row.begin(), row.end(), smaller);
    sort(col.begin(), col.end(), smaller);
    sort(rowVec.begin(), rowVec.end());
    sort(colVec.begin(), colVec.end());

    auto maxRowSize = distance(lower_bound(rowVec.begin(), rowVec.end(), rowVec.back()), rowVec.end());
    auto maxColSize = distance(lower_bound(colVec.begin(), colVec.end(), colVec.back()), colVec.end());

    if (maxRowSize * maxColSize > M) {
        cout << row.back().second + col.back().second << endl;
        return 0;
    }
    else {
        for (auto i = 0; i < maxRowSize; ++i) {
            for (auto j = 0; j < maxColSize; ++j) {
                auto idR = row[row.size() - maxRowSize + i].first;
                auto idC = col[col.size() - maxColSize + j].first;
                if (mat[make_pair(idR,idC)] == 0)  {
                    cout << row.back().second + col.back().second << endl;
                    return 0;
                }
            }
        }
    }
    cout << row.back().second + col.back().second - 1 << endl;
    return 0;
 
}

Measured memory_bytes: 57104
#include<bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define endl '\n'
#ifndef CODE_JAM
#undef CASE_INFO
#endif
#else
#pragma GCC optimize "trapv"
#endif
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(n) for(int i = 0; i < n; i++)
#define repj(n) for(int j = 0; j < n; j++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
template<class X=int>inline X mid(X s,X e){return (s+(e-s)/2);}
template<class X=int>inline X len(X s,X e){return (e-s+1);}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int oo = 987654321;
const ll OO = 1e18;

class Timer {
public:
	clock_t start;
	Timer() {start = clock();}
	~Timer() {cerr << (double)(clock() - start)/CLOCKS_PER_SEC << "\n";}
};

class MST {
	vector<vector<int>> T;
	int n;
public:
	MST(const vector<int>& A) {
		n = A.size();
		T.assign(2*n, vector<int>());
		for(int p = n; p < 2*n; p++)
			T[p].push_back(A[p - n]);
		for(int p = n - 1; p > 0; p--) {
			T[p].resize(T[p<<1].size() + T[p<<1|1].size());
			merge(all(T[p<<1]), all(T[p<<1|1]), T[p].begin());
		}
	}

	int query(int l, int r) {
		int thresh = l, ret = 0;
		for(l += n, r += n + 1; l < r; l>>=1, r>>=1) {
			if(l & 1) ret += lower_bound(all(T[l]), thresh) - T[l].begin(), l++;
			if(r & 1) --r, ret += lower_bound(all(T[r]), thresh) - T[r].begin();
		}
		return ret;
	}
};

void solve() {
	int n, Q;
	cin >> n >> Q;
	vi c(n); rep(n) cin >> c[i];
	vi cur(n, -1), prevOcc(n, -1);
	for(int i = 0; i < n; i++) {
      c[i]--;
		prevOcc[i] = cur[c[i]];
		cur[c[i]] = i;
	}
	MST mst(prevOcc);
	while(Q--) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		cout << mst.query(l, r) << endl;
	}
}

signed main() {
	Timer ti;
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int T = 1;
	#ifdef TEST_CASES
	cin >> T;
	#endif
	for(int t = 1; t <= T; t++) {
		#ifdef CASE_INFO
		cout << "Case #" << t << ": ";
		#endif
		solve();
	}
	return 0;
}


Measured memory_bytes: 95736
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N, M, K;
    cin >> N >> M >> K;

    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= M; j++){
            if((N - i) * j + i * (M - j) == K){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3664
r,c=map(int,input().split())
l=[]
for i in range(r):
    ll=list(map(int,input().split()))
    lsum=sum(ll)
    ll.append(lsum)
    l.append(ll)
sumcl=[]
for i in range(c+1):
    sumc=0
    for j in range(r):
        sumc=sumc+l[j][i]
    sumcl.append(sumc)
l.append(sumcl)
for i in range(r+1):
    print(' '.join(str(l[i][j]) for j in range(c+1)))


Measured memory_bytes: 5704
using System;
using System.Collections.Generic;
using System.Text;

namespace ALDS1_8_B
{
    class Program
    {
        const int NIL = -1;
        const int ROOT = 0;
        static StringBuilder sbi;
        static StringBuilder sbp;
        class node
        {
            public int key; public int left; public int right;
            public node(int key)
            {
                this.key = key; left = NIL; right = NIL;
            }
        }
        static void Main(string[] args)
        {
            int m = int.Parse(Console.ReadLine());
            var T = new List<node>();
            int listnum = 0;
            for (int i = 0; i < m; i++)
            {
                var a = Console.ReadLine().Split(' ');
                if (a[0] == "insert")
                {
                    insert(T, int.Parse(a[1]), listnum++);
                }
                else if(a[0]=="print")
                {
                    sbi = new StringBuilder();
                    sbp = new StringBuilder();
                    inorder(T, 0);
                    Console.WriteLine(sbi);
                    preorder(T, 0);
                    Console.WriteLine(sbp);
                }
                else if (a[0]=="find")
                {
                    find(T, int.Parse(a[1]));
                }
            }

        }
        static void find(List<node> T,int k)
        {
            int x = ROOT;
            while(x!=NIL)
            {
                if (k < T[x].key) x = T[x].left;
                else if (k > T[x].key) x = T[x].right;
                else
                {
                    Console.WriteLine("yes");
                    return;
                }
            }
            Console.WriteLine("no");
        }    
        static void insert(List<node> T, int z, int listnum)
        {
            int y = NIL;
            T.Add(new node(z));
            if (listnum == 0) return;
            int x = ROOT;
            while (x != NIL)
            {
                y = x;
                if (z < T[x].key) x = T[x].left;
                else x = T[x].right;
            }
            if (z < T[y].key) T[y].left = listnum;
            else T[y].right = listnum;

        }

        static void preorder(List<node> T, int i)
        {
            sbp.Append(" " + T[i].key);
            if (T[i].left != NIL) preorder(T, T[i].left);
            if (T[i].right != NIL) preorder(T, T[i].right);
        }
        static void inorder(List<node> T, int i)
        {
            if (T[i].left != NIL) inorder(T, T[i].left);
            sbi.Append(" " + T[i].key);
            if (T[i].right != NIL) inorder(T, T[i].right);
        }
    }
}

Measured memory_bytes: 68508
// SeeAlso: https://atcoder.jp/contests/abc154/tasks/abc154_b

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main (){ 
    string s;
    cin >> s;
    int m = s.size();

    rep(i,m) {
        cout << "x";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a ; i <= b; ++ i) 
const int N = 2e5 + 5, M = N , mo = 1e9 + 7 ;
const ll inf = 1e17 ;
using namespace std ;

struct poi {
    int l, r, ans ;
} a[N], b[N] ;
multiset <int> S ;
int n, bit[N] ;

bool cmpl(poi a, poi b) {
    return a.l < b.l ;
}

bool cmpr(poi a, poi b) {
    return a.r < b.r ;
}

int solve() {
    rep(i, 0, M - 5) bit[i] = 0 ;
    rep(i, 1, n) ++ bit[a[i].l], -- bit[a[i].r] ;
    rep(i, 1, M - 5) bit[i] += bit[i - 1] ;
    int res = 0 ;
    rep(i, 0, M - 5) res = max(res, bit[i]) ;
    return res ;
}

void put(int x) {
    for ( ; x <= M - 5 ; x += x & (- x)) bit[x] ++ ;
}

int get(int x) {
    int res = 0 ;
    for ( ; x ; x -= x & (- x)) res += bit[x] ;
    return res ;
}

int l[N],r[N];

int SOLVE() {
	rep(i,1,M-5) bit[i]=0;
    sort(a + 1, a + n + 1, cmpl) ;
    rep(i, 1, n) a[i].ans = n ;
    rep(i, 1, n) {
        a[i].ans -= get(a[i].l) ;
        put(a[i].r) ;
    }
    rep(i, 0, M - 5) bit[i] = 0 ;
    sort(a + 1, a + n + 1, cmpr) ;
    for (int i = n ; i; -- i) {
        a[i].ans -= get(M - 5 - a[i].r) ;
        put(M - 5 - a[i].l) ;
    }
    int res = 0 ;
    rep(i, 1, n) res = max(res, a[i].ans) ;
    return res ;
}

int main() {
    scanf("%d", &n) ;
    rep(i, 1, n) scanf("%d%d", &a[i].l, &a[i].r) ;
    int r=solve();
    printf("%d %d\n", SOLVE(), r) ;
    return 0 ;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

// dp1[i][j] : Xがi番目、Yがj番目でXの手番なときのスコア最大値
// dp1[i][j] = max(dp2[j+1-n][j])
//li dp1[2020][2020];
// dp2[i][j] : Xがi番目、Yがj番目でYの手番なときのスコア最小値
// dp2[i][j] = min(dp1[])
//li dp2[2020][2020];

// X,Yの初期値が関係するのは本当にわずかなシーンだけなので、それ以外をまず計算する
// dp1[i] : Yがi番目を取ってた時のスコア最大値（Xのターン）
li dp1[3030];
// dp2[i] : Xがi番目を取ってた時のスコア最小値（Yのターン）
li dp2[3030];

li n, z, w;
li a[2020];

int main() {
    cin >> n >> z >> w;
    rin{
        cin >> a[i];
    }
    if (n == 1) {
        cout << abs(a[0] - w) << endl;
        return 0;
    }
    dp1[n - 2] = abs(a[n - 2] - a[n - 1]);
    dp2[n - 2] = abs(a[n - 2] - a[n - 1]);
    for (li i = n - 3; i >= 0; i--) {
        dp1[i] = abs(a[i] - a[n - 1]);
        repp(j, i + 1, n - 1) {
            dp1[i] = max(dp1[i], dp2[j]);
        }
        dp2[i] = abs(a[i] - a[n - 1]);
        repp(j, i + 1, n - 1) {
            dp2[i] = min(dp2[i], dp1[j]);
        }
    }

    li res = abs(w - a[n - 1]);
    rep(i, n - 1) {
        res = max(res, dp2[i]);
    }

    cout << res << endl;


    return 0;
}

Measured memory_bytes: 256