akhauriyash/Code-Regression huggingface dataset:
import java.awt.geom.Point2D;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String str[];
		Point2D.Double p[];
		boolean flag;

		p = new Point2D.Double[4];
		while (sc.hasNext()) {
			str = sc.next().split(",");
			flag = true;
			for (int i = 0; i < 4; i++) {
				p[i] = new Point2D.Double(Double.valueOf(str[2 * i]), Double.valueOf(str[2 * i + 1]));
			}

			for (int i = 0; i < 4; i++) {
				double k = 0.0;
				double a, b;
				if (p[i].x == p[(i + 1) % 4].x) {
					a = Double.POSITIVE_INFINITY;
					b = Double.NaN;
				} else {
					a = (p[(i + 1) % 4].y - p[i].y) / (p[(i + 1) % 4].x - p[i].x);
					b = p[i].y - a * p[i].x;
				}
				for (int j = 0; j < 4; j++) {
					if (j == i || j == (i + 1) % 4) {
						continue;
					}
					if (k == 0.0) {
						if (Double.isNaN(b)) {
							k = p[j].x - p[i].x;
						} else {
							k = p[j].y - (a * p[j].x + b);
						}
					} else {
						if (Double.isNaN(b)) {
							if ((p[j].x - p[i].x) * k < 0) {
								flag = false;
							}
						} else {
							if ((p[j].y - (a * p[j].x + b)) * k < 0) {
								flag = false;
							}
						}
					}
				}
			}
			if (flag) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <iostream>
#include <vector>
#include <cassert>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <set>
#include <cstdlib>
#include <string>
#include <unordered_map>
#include <map>
#include <sstream>
#include <bitset>
#include <random>
#include <tuple>
#include <array>
#include <tgmath.h>
#include <functional>
#include <climits>
#include <complex>
#include <unistd.h>
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef pair<lli, lli> plli;
typedef unsigned char byte;
typedef unsigned int uint;
typedef unsigned long long int ulli;

typedef tuple<lli, lli, lli, lli> tl4;

lli arr[200100], psum[200100];

tl4 find_midway(lli *arr, int cnt, lli *psum) {
    //printf("call: %d %lld\n", cnt, *psum);
    lli v = psum[0] + (psum[cnt] - psum[0]) / 2;
    int idx_where = (int)(upper_bound(psum, psum+cnt+1, v) - psum);
    lli a, b, c, d;
    if (idx_where) {
        tie(a, b, c, d) = tl4(
            psum[idx_where] - psum[0], psum[cnt] - psum[idx_where],
            psum[idx_where - 1] - psum[0], psum[cnt] - psum[idx_where - 1]
        );
        if (a > b) swap(a, b);
        if (c > d) swap(c, d);
        //printf("%lld %lld %lld %lld\n", a, c, b, d);
        return tl4(a, c, b, d);
    }
    tie(a, b) = plli(psum[idx_where] - psum[0], psum[cnt] - psum[idx_where]);
    if (a > b) swap(a, b);
    //printf("= %lld %lld %lld %lld\n", a, a, b, b);
    return tl4(a, a, b, b);
}

int main() {
    int n;
    scanf("%d", &n);
    int i;
    for (i=1; i<=n; ++i) {
        scanf("%lld", arr+i);
        psum[i] = psum[i-1] + arr[i];
    }
    lli diff = 1e18;
    lli a, b, c, d, e, f, g, h;
    for (i=2; i<=n-2; ++i) {
        tie(a, b, c, d) = find_midway(arr, i, psum);
        tie(e, f, g, h) = find_midway(arr+i, n-i, psum+i);
        diff = min({
            diff,
            max(c, g) - min(a, e),
            max(d, g) - min(b, e),
            max(c, h) - min(a, f),
            max(d, h) - min(b, f)
        });
    }
    printf("%lld\n", diff);
    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int ans=0,x[20],tot=0;

void dfs(int dep,int lim,int sum)
{
    if (dep>tot) 
    {
        ans=max(ans,sum);return;
    }
    if (!lim) dfs(dep+1,lim,sum+9);
    else 
    {
        dfs(dep+1,1,sum+x[dep]);
        if (x[dep]) dfs(dep+1,0,sum+x[dep]-1);
    }
}

int main()
{
    ll n=readll();
    while (n)
    {
        x[++tot]=n%10;n/=10;
    }
    reverse(x+1,x+1+tot);
    dfs(1,1,0);
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
N = int(input())

bin=[]
p = ['00','10','01','11']
m = ['00','11','01','10']
ans=[]
if N < 0:
    N = -1*N
    minus = True
else:
    minus = False
if N == 0:
    print(0)
else:
    while(N != 0):
        n = N % 4
        N = N // 4
        if minus:
            ans.append(m[n])
            if n == 3: N += 1
        else:
            ans.append(p[n])
            if n == 2 or n == 3: N += 1
    bin.append(n)
    ans ="".join(ans)
    ans = ans[::-1]
    print(ans[ans.find('1'):])
 

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

// Binary Indexed Tree (Fenwick Tree)
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

int main(){

    int N, Q;
    string S;
    cin >> N >> S >> Q;
    
    vector<BIT<int>> indices(26, BIT<int>(N));

    //rep(i,N) indices[S[i]-'a'].insert(i);
    rep(i,N) indices[S[i]-'a'].add(i,1);

    rep(i,Q){
        int type; cin >> type;
        if (type == 1){
            int index; cin >> index;
            index--;
            char letter; cin >> letter;
            indices[S[index]-'a'].add(index,-1);
            indices[letter-'a'].add(index,1);
            S[index] = letter;
            /*
            indices[S[index]-'a'].erase(index);
            indices[letter-'a'].insert(index);
            S[index] = letter;
            */
        }
        else{
            int left, right;
            cin >> left >> right;
            left--;
            int ans = 0;
            rep(i,26){
                /*
                int left_index = *indices[i].lower_bound(left);
                int right_index = *indices[i].lower_bound(right);
                if (right_index > left_index) ans++;
                */
                if (indices[i].sum(left,right) > 0) ans++;
            }
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 56824
h,n=map(int,input().split())
L=[]
maA=0
inf=float("inf")
for i in range(n):
      a,b=map(int,input().split())
      L.append((a,b))
      maA=max(maA,a)

dp=[inf]*(h+maA+1)
dp[0]=0
for i in range(h):
      for j in L:
            dp[i+j[0]]=min(dp[i+j[0]],dp[i]+j[1])
      
print(min(dp[h:]))   

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

int main() {
    int t;
    cin >> t;
    for(int I = 0; I < t; I++) {
        int n;
        cin >> n;
        bitset<200> b[64];
        for(int j = 0; j < n; j++) {
            long a;
            cin >> a;
            for(int k = 0; k < 63; k++)
                if(a & 1l << k)
                    b[k][n - 1 - j] = 1;
        }
        string s;
        cin >> s;
        int i = 0;
        for(int j = 0; j < n; j++) {
            int r = i;
            [&i, &j](bitset<200> *m, int R) {
                int k;
                for(k = i; k < R; k++)
                    if(m[k][j])
                        goto p;
                return;
            p:
                swap(m[k], m[i]);
                for(k = i; k < R; k++)
                    if(k != i && m[k][j])
                        m[k] ^= m[i];
                i++;
            }(b, 63);
            if(s[n - j - 1] == '1' && i > r) {
                cout << "1\n";
                goto o;
            }
        }
        cout << "0\n";
    o:;
    }
    return 0;
}


Measured memory_bytes: 3520
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
#define pf push_front
#define TIME ios_base::sync_with_stdio(0);
using namespace std;

const long long N = 3e3 + 1;

double n, m, h, x, y, cnt, a[N], b[N], r[N];
string s;
int main()
{
    TIME;
    cin >> n;
    for ( int i=0; i<n; i++ ){
        cin >> a[i];
        cnt += 1 / a[i];
    }
    cout << 1 / cnt;    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main(void){
  char s[3];
  char t;
  cin >> s[0] >> s[1] >> s[2];
  int sum = 0;
  for (int i = 0;i < 3;i++){
    cin >> t;
    if(t == s[i]){
      sum++;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 760
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <cstdio>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define SIZE 100000
#define MOD 1000000007
using namespace std;
typedef long long ll;

class ModFact {
    int inv[SIZE+1];
    int fact[SIZE+1];
public:
    constexpr ModFact() : fact(), inv() {
        ll f = 1;
        fact[0] = f;
        for (int i = 0; i <= SIZE; i++) {
            f = f*(i+1)%MOD;
            fact[i+1] = f;
        }
        f = power(f, MOD-2);
        for (int i = SIZE; i >= 0; i--) {
            inv[i] = fact[i] * f % MOD;
            f = f * (i+1) % MOD;
        }
    }
    inline constexpr ll power(ll a, ll b) {
        ll r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%MOD;
            a = (a*a)%MOD;
            b >>= 1;
        }
        return r;
    }
	inline int operator[](int index) {
		return inv[index];
	}

	inline int getfact(int index) {
		return fact[index];
	}
    
} fact;

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
    if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
    return *ci++;
}

inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
    else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
    return A;
}

int main() {
    ll ans = 0, d;
    int a, N, prev, now;
    N = getint();
    prev = getint();
    REP(i, N-1) {
        now = getint();
        d = now - prev;
        prev = now;
        a = (a + fact[i]) % MOD;
        ans += a * d;
    }
    printf("%lld\n", ((ans%MOD)*fact.getfact(N-1))%MOD);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;

long pathi(long N, long X) {
    if(N==0){
        if(X==1){
            return 1;
        }
        else {
            return 0;
        }
    }
    else {
        if (X==1){
            return 0;
        }
        else if(X<=pow(2, N+1)-2){
            return pathi(N-1, X-1);
        }
        else if(X == pow(2, N+1)-1) {
            return pathi(N-1, pow(2, N+1)-3) + 1;
        }
        else if(X<=pow(2, N+2)-4){
            return pathi(N-1, pow(2, N+1)-3) + 1 + pathi(N-1, X-pow(2, N+1)+1);
        }
        else {
            return 2*pathi(N-1, pow(2, N+1)-3) + 1;
        }
    }
}

int main() {
    long N, X;
    cin>>N>>X;
    long ans = pathi(N, X);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    int n,m,x,y,a,b;
    string ans = "War";
    cin >> n >> m >> x >> y;
    rep(i,n){
        cin >> a;
        if(a>x) x=a;
    }
    rep(i,m){
        cin >> b;
        if(b<y) y=b;
    }
    if(x < y)
        ans = "No War";
    cout << ans << endl;
    return 0;
}

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

using namespace std;


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000009
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl			'\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

const int maxn = 1e5 + 5;
void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

set<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	set<int> primes;

	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.insert(i);
	}
	return primes;
}
set<int> primeFactors(int  n)
{
	set<int> factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors.insert(2);

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		// int count = 0;
		while (n % i == 0)
		{
			factors.insert(i);
			n /= i;
		}
	}
	if (n > 2)
		factors.insert(n);
	return factors;
}

int power(int x, unsigned int y, int p)
{
	int res = 1;

	x = x % p;

	if (x == 0) return 0;
	;
	while (y > 0)
	{

		if (y & 1)
			res = (res * x) % p;

		y = y >> 1; // y = y/2
		x = (x * x) % p;
	}
	return res;

}

void lcs(string text1, string text2)
{
	int n = text1.length();
	int m = text2.length();

	int cache[n + 1][m + 1];
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= m; j++)
		{
			if (i == 0 || j == 0)
			{
				cache[i][j] = 0;
			}
			else if (text1[i - 1] == text2[j - 1])
			{
				cache[i][j] = 1 + cache[i - 1][j - 1];
			}
			else
			{
				cache[i][j] = max(cache[i - 1][j], cache[i][j - 1]);
			}
		}
	}
	int index = cache[n][m];
	char ans[index + 1];
	ans[index] = '\0';
	int i = n, j = m;
	while (i > 0 && j > 0)
	{
		if (text1[i - 1] == text2[j - 1])
		{
			ans[index - 1] = text1[i - 1];
			i--;
			j--;
			index--;
		}
		else if (cache[i - 1][j] > cache[i][j - 1])
		{
			i--;
		}
		else
			j--;
	}
	cout << ans << endl;

}


// Graph------------------------------------------------------------------------


int32_t main()
{
	FIO;
	// c_p_c();
	// --------------------------------------------------
	// Never GIVE UP !!!!
	string s1, s2;
	cin >> s1;
	cin >> s2;

	lcs(s1, s2);

}

Measured memory_bytes: 73972
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> data(N,vector<int>(D));
    for(int i=0; i<N; i++){
        for(int j=0; j<D; j++){
            cin >> data.at(i).at(j);
        }
    }
    int count =0;
    for(int i=0; i<N; i++){
        for( int j=i+1; j<N; j++){
            double dis =0;
            for(int k=0; k<D; k++){
                dis += pow(data.at(i).at(k) - data.at(j).at(k),2);
            }
            dis = double(sqrt(dis));
            if( ceil(dis) == floor(dis)){
                count++;
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;

int main() {
    ll A,B;
    cin>>A>>B;
    if(A+B<=9){cout<<A+B<<endl;}
    else{cout<<"error"<<endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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 = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


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

  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll sum = SUM(a);

  vector<ll> x(n);

  x[0] = sum;
  rep(i, n/2) {
    x[0] -= 2 * (a[i*2 + 1]);
  }

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

  rep(i, n) {
    cout << x[i] << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 2944
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


const int INF = 1e9 + 5;

int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    int N, K;
    cin >> N >> K;
    vector<int> H(N);

    for (int &h : H)
        cin >> h;

    vector<int> dp(N, INF);
    dp[0] = 0;

    for (int i = 1; i < N; i++)
        for (int j = max(i - K, 0); j < i; j++)
            dp[i] = min(dp[i], dp[j] + abs(H[i] - H[j]));

    cout << dp.back() << '\n';
}


Measured memory_bytes: 1024
x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    p = list(map(int,input().split()))
    p.sort()
    for i in range(100):
        if x-i not in p:
            print(x-i)
            break
        elif x+i not in p:
            print(x+i)
            break


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

int main() {
  int N;
  cin >> N;
  vector<int> num(N);
  for(int i = 0; i < N; i++){
    cin >> num.at(i);
  }
  sort(num.begin(),num.end());
  reverse(num.begin(),num.end());
  int A = 0;
  int B = 0;
  for(int i = 0; i < N; i++){
    if(i % 2 == 0)
      A += num.at(i);
    else
      B += num.at(i);
  }
  cout << A - B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = b-1; i >= a; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

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


int main() {
    ll n; cin >> n;
    Vs s(n);
    rep(i, 0, n) cin >> s[i];

    ll ans = 0;
    ll a = 0, ba = 0, b = 0;
    rep(i, 0, n){
        rep(j, 0, sz(s[i])-1){
            if(s[i][j]=='A'&&s[i][j+1]=='B') ans++;
        }
        if(s[i][0] == 'B' && s[i][sz(s[i])-1] == 'A') ba++;
        else if(s[i][0] == 'B') b++;
        else if(s[i][sz(s[i])-1] == 'A') a++;
    }
    if(a && ba) ans++, a--;
    if(b && ba) ans++, b--;
    ans += max(0LL, min(a,b));
    ans += max(ba-1, 0LL);
    co(ans);

    return 0;
}




Measured memory_bytes: 3764
#include<stdio.h>

int main(){
  int n,A[101];
  int i,j,cnt=0,minj,a;

  scanf("%d",&n);

  if (n>=1 && n<=100){
    for (i=0; i<n; i++) scanf("%d",&A[i]);
    
    for (i=0; i<n; i++){
      minj = i;
      for (j=i; j<n; j++){
	if (A[j] < A[minj]){
	  minj = j;
	}
      }
      if (minj != i){
	a = A[i];
	A[i] = A[minj];
	A[minj] = a;
	cnt++;
      }
    }
    for (i=0; i<n-1; i++) printf("%d ",A[i]);
    printf("%d\n",A[i]);
    printf("%d\n",cnt);
  }

  return 0;
}



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

int main() {
	int n , k ;
	cin >> n >> k ;
	int a[n]  , mval = 0;
	for(int i = 0 ; i < n ; i++) cin >> a[i] ;
	for(int start = -1 ; start < n ; start++){
		for(int end = n ; end >= 0 ; end--){
			if(start >= end) continue ;
			vector<int> v ;	
			for(int i = 0 ; i <= start ; i++) v.push_back(a[i]) ;
			for(int i = end ; i < n ; i++ ) v.push_back(a[i]) ;
			if(v.size() > k) continue ;
			sort(v.begin(),v.end()) ;
			int rem = k - v.size() ;
			int x = accumulate(v.begin(),v.end(),0) ;
			for(auto i : v){
				if(rem && i < 0) x -= i , rem--;
				else break ;
			}
			mval = max(x,mval) ;
		}
	}
	cout << mval ;
	return 0;
}

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

using namespace std;

int main()
{
  int n, x, y;
  cin >> n >> x >> y;
  vector<vector<int>> e(n + 1);
  int a, b;
  for (int i = 0; i < n; i++)
  {
    cin >> a >> b;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  vector<int> dx(n + 1), dy(n + 1);
  function<void(int, int, int, vector<int> &)> dfs = [&](int cur, int par, int i, vector<int> &d) {
    for (int nex : e[cur])
    {
      if (nex == par)
        continue;
      dfs(nex, cur, i + 1, d);
    }
    d[cur] = i;
  };
  dfs(x, -1, 0, dx);
  dfs(y, -1, 0, dy);
  int res = 0;
  for (int i = 1; i <= n; i++)
  {
    if (dy[i] < dx[i])
      continue;
    res = max(res, dy[i]);
  }
  cout << (res - 1) << "\n";
  return 0;
}


Measured memory_bytes: 15488
#include <cstdio>
#include <cassert>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <array>

using namespace std;

#define all(c) begin(c), end(c)
#define dump(c) cerr << "> " << #c << " = " << (c) << endl
#define REP(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)

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

const int INF = 1001001001;
const double EPS = 1e-10;


template<typename T1,typename T2>
ostream& operator<<(ostream& os, const pair<T1,T2>& p){
  return os << '(' << p.first <<',' << p.second << ')';
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& a){
  os << '[';
  rep(i,a.size()) os << (i ? " " : "") << a[i];
  return os << ']';
}

int main() {
  int Q; cin >> Q;
  while(Q--) {
    int R; cin >> R;
    int ans = 0;
    set<int> memo;
    while(R >= 10) {
      string r = to_string(R);
      set<int> s;
      rep(i, r.size() - 1) {
        int a = stoi(r.substr(0, i + 1));
        int b = stoi(r.substr(i + 1));
        s.insert(a * b);
      }
      R = *s.rbegin();
      if(memo.count(R)) {
        ans = -1;
        break;
      }
      memo.insert(R);
      ans++;
    }

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

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s; cin >> s;
    int minval = 100000;
    for(int i=0;i<s.size()-2;i++){
        int x = (s[i] - '0') * 100 + (s[i+1] - '0') * 10 + (s[i+2] - '0');
        minval = min(abs(x - 753), minval);
    }
    cout << minval << endl;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    int A, B;
    cin >> A >> B;
    cout << (A - 1) * (B - 1) << endl;
    return 0;
}

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

int main(){
  int n;
  cin >>n;
  int a[n];
  rep(i,n)cin >> a[i];
  sort(a,a+n);
  ll ans=0;
  rep(i,n)for(int i2=1+i;i2<n;i2++)for(int i3=i2+1;i3<n;i3++){
        if(a[i]+a[i2]>a[i3])ans++;
      }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int l, r;
    cin >> l >> r;
    if (r - l > 3000)cout << 0 << endl;
    else {
        int ret = 1145141919;
        for (int i = l; i <= r; i++) {
            for (int j = i + 1; j <= r; j++) {
                int a = i % 2019;
                int b = j % 2019;
                ret = min(ret, (a * b) % 2019);
            }
        }
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

#define cabs(a) ((a)<0?-(a):(a))
#define fmin(a,b) ((a)<(b)?(a):(b))

int n,m,c,a[110][110],flag,nowa,nowb;

void cas1(int x,int y){
	a[(x-1)*4+1][(y-1)*4+1]=1;
	a[(x-1)*4+1][(y-1)*4+2]=1;
	a[(x-1)*4+1][(y-1)*4+3]=1;
	a[(x-1)*4+2][(y-1)*4+1]=1;
	a[(x-1)*4+2][(y-1)*4+3]=1;
	a[(x-1)*4+3][(y-1)*4+1]=1;
	a[(x-1)*4+3][(y-1)*4+2]=1;
	a[(x-1)*4+3][(y-1)*4+3]=1;
}

void cas2(int x,int y){
	a[(x-1)*4+1][(y-1)*4+1]=1;
	a[(x-1)*4+1][(y-1)*4+2]=1;
	a[(x-1)*4+1][(y-1)*4+3]=1;
	a[(x-1)*4+2][(y-1)*4+1]=1;
	a[(x-1)*4+2][(y-1)*4+2]=1;
	a[(x-1)*4+2][(y-1)*4+3]=1;
	a[(x-1)*4+3][(y-1)*4+1]=1;
	a[(x-1)*4+3][(y-1)*4+2]=1;
	a[(x-1)*4+3][(y-1)*4+3]=1;	
}

void work(){
	if(n>m){
		flag=1;
		int t=n;
		n=m,m=t;
	}
	for(register int i=1;i<=n-1;i++){
		nowa++;
		if(nowa>25) nowa=1,nowb++;
		cas1(nowa,nowb);
	//	printf("%d %d\n",nowa,nowb);
	}
	for(register int i=1;i<=m-n+1;i++){
		nowa++;
		if(nowa>25) nowa=1,nowb++;
		cas2(nowa,nowb);
	//	printf("%d %d\n",nowa,nowb);
	}
}

int main(){
	scanf("%d%d",&n,&m);
	nowb=1;
	printf("100 100\n");
	work();
	if(flag)
	for(register int i=1;i<=100;i++){
		for(register int j=1;j<=100;j++)
			printf("%c",a[i][j]?'.':'#');
		putchar('\n');
	}
	else
	for(register int i=1;i<=100;i++){
		for(register int j=1;j<=100;j++)
			printf("%c",a[i][j]?'#':'.');
		putchar('\n');
	}		
	return 0;
}

Measured memory_bytes: 256
//============================
// ABC135b 0 or 1 Swap
//
// 2019/08/13
//============================

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

using namespace std;

void swap(int& a, int& b);

int main(int argc, char* argv[])
{
  int N;
  cin >> N;

  int p[50];
  for(int i=0; i<N; i++)  cin >> p[i];

  int s=0;
  for(int i=0; i<N; i++)
  {
    if(i+1 != p[i])
    {
      swap(p[i], p[p[i]-1]);
      s++;
      if (s>=2) break;
    }
  }

  if(s>=2)  cout << "NO"  << endl;
  else      cout << "YES" << endl;

  return 0;
}

void swap(int& a, int& b)
{
  int temp;
  temp = a;
  a = b;
  b = temp;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <set>
#include <deque>
#include <map>
#include <bitset>
#include <functional>
#include <cmath>

#define INF 10000000000
using namespace std;
using P = pair<long, long>;

int main(){
	static const double pi = 3.141592653589793;
    double a, b;
	cin >> a >> b;
	double h, m;
	cin >> h >> m;

	double angle1 = h*30 + m*0.5;
	double angle2 = m*6;
	double theta = angle1 - angle2;

	if(theta < 0) theta = -theta;
	if(theta >= 180) theta = 360 - theta;

	//cout << theta << endl;


	double ans = sqrt(a*a + b*b - 2*a*b*cos(theta/180.0*pi));

	printf("%.15lf\n", ans);
}

Measured memory_bytes: 4192
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;

#define MaxN 100001
#define MaxM MaxN*4
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
template<typename T> T abs(T val){return val>0?val:-val;}
int N;
struct Edge
{
    int v,next;
}edge[MaxM];
int cont,head[MaxN];
void add(int u, int v)
{
    edge[cont].v = v, edge[cont].next = head[u], head[u] = cont++;
}

int DFS(int u, int pre)
{
    int flag = 0;
    for(int i=head[u];i!=-1;i=edge[i].next)
    {
        int v = edge[i].v;
        if(v==pre) continue;
        flag ^= DFS(v,u);
    }
    return flag+1;
}
void solve()
{
    if(DFS(1,0)!=1) puts("Alice");
    else puts("Bob");
}

void init()
{
    cont = 0;
    MST(head,-1);
}
int main()
{
    //std::ios::sync_with_stdio(false);
    while(scanf("%d", &N)!=EOF)
    {
        init();
        int a,b;
        for(int i=1;i<N;i++)
        {
            scanf("%d%d", &a, &b);
            add(a,b);add(b,a);
        }
        solve();
    }
    //system("pause");
    //printf("%lld\n", (x%mod+mod)%mod );
}


Measured memory_bytes: 6912
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
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;
}
int main() {
    string str;
    cin >> str;

    auto itrBegin = str.find_first_of("A");
    auto itrEnd   = str.find_last_of("Z");

    cout << (itrEnd - itrBegin + 1) << endl;

    return 0;
}

Measured memory_bytes: 3712
/*Author : Kartik Bansal
 *Date : 02/08/19
 *Time : 17:46 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define tc int t ;cin>>t ;while(t--)
#define pb push_back
#define FOR(i,n) for(int i =0;i<n;i++)
#define Sort(v) sort(v.begin() ,v.end())
int inf = INT_MAX ;
int32_t main()
{
  int n , k ;
  cin>>n>> k  ;
  vector<int> v(n+1) ;
  v[0] = 0 ;
  for(int i=1 ;i<=n ;i++)
  {
    cin>>v[i] ;
  }
  vector<int> dp(n+1 , inf ) ;
  dp[1] = 0 ;

  for(int i = 1 ;i<=n;i++)
  {
    for(int j=i+1 ;j<=k+i;j++)
    {
      dp[j] = min(dp[j] , dp[i] + abs(v[j]-v[i])  ) ;
    }
  }
  cout<<dp[n] ;

  return 0 ;
}


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


template<class Ty>
class priority {
public:
	vector<Ty> inst;

	bool empty() const { return inst.empty(); }
	size_t size() const { return inst.size(); }
	void shrink_to_fit() { inst.shrink_to_fit(); }
	void reserve(size_t s) { inst.reserve(s); }
	void insert(const Ty & a) {
		size_t i = size();
		inst.push_back(a);
		while (i != 0) {
			if (inst[i] >= inst[(i - 1) / 2]) break;
			swap(inst[i], inst[(i - 1) / 2]);
			i = (i - 1) / 2;
		}
	}
	void insert(Ty && a) {
		size_t i = size();
		inst.push_back(a);
		while (i != 0) {
			if (inst[i] >= inst[(i - 1) / 2]) break;
			swap(inst[i], inst[(i - 1) / 2]);
			i = (i - 1) / 2;
		}
	}
	const Ty &get() {
		return inst.front();
	}
	void pop() {
		swap(inst.front(), inst.back());
		inst.pop_back();
		size_t i = 0;
		while (true) {
			if (size() <= i * 2 + 1) break;
			if (size() > i * 2 + 2) {
				int j = (inst[i * 2 + 1] < inst[i * 2 + 2]) ? (i * 2 + 1) : (i * 2 + 2);
				if (inst[j] < inst[i]) {
					swap(inst[j], inst[i]);
					i = j;
					continue;
				}
			}
			else if (size() > i * 2 + 1) {
				if (inst[i * 2 + 1] < inst[i]) {
					swap(inst[i * 2 + 1], inst[i]);
					i = i * 2 + 1;
					continue;
				}
			}
			break;
		}
	}
	Ty pick() {
		Ty buf = move(inst.front());
		pop();
		return move(buf);
	}
};



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

	priority<int> t;

	t.reserve(100000);
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		t.insert(-a);
	}
	for (int i = 0; i < m; i++) {
		int j = t.pick();
		t.insert(j / 2);
	}
	auto &v = t.inst;
	long long b = 0;
	for (int i = 0; i < v.size(); i++) {
		b += -v[i];
	}

	cout << b << endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,M; cin>>N>>M;
  vi A(N),B(N),C(N),P={1,-1};
  rep(i,0,N) cin>>A[i]>>B[i]>>C[i];
  int ans=0;
  rep(a,0,2){
    rep(b,0,2){
      rep(c,0,2){
        vi D(N);
        rep(i,0,N){
          D[i]=P[a]*A[i]+P[b]*B[i]+P[c]*C[i];
        }
        sort(ALL(D));
        reverse(ALL(D));
        int sum=0;
        rep(i,0,M){
          sum+=D[i];
        }
        ans=max(ans,sum);
      }
    }
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define MAXN
#define MAXM
#define scanf(a) scanf("%d",&a)
#define print(a) printf("%d",a)
#define printn(a) printf("%d\n",&a);
using namespace std;
int k;
int n[10];

int main()
{
	for (int i=1;i<=5;i++)
	{
		scanf(n[i]);
	}
	sort(n+1,n+6);
	int maxn=n[5]-n[1];
	scanf(k);
	if (maxn<=k)
	{
		printf("Yay!");
		return 0;
	}
	printf(":(");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define NUM 10000

void input(int *p1, int *p2, int t);
void output(int *p1, int *p2);
void comp(int *p1, int *p2, char *p_c, int t);
void score(int *p1, int *p2, int t);

int a[NUM] = {0}, b[NUM] = {0}, score_a[NUM] = {0}, score_b[NUM] = {0};
char tmp[NUM];
int cnt = 0;

int main()
{
	int n;
	while(1) {
		scanf("%d", &n);
		if(n == 0) {
			break;
		}
		input(a, b, n);
		comp(a, b, tmp, n);
		score(score_a, score_b, n);
		cnt++;
	}
	output(score_a, score_b);
	return 0;
}

// ???????????\?????????prog
void input(int *p1, int *p2, int t)
{
	int i = 0;
	while(1) {
		if (i == t) {
			break;
		}
		scanf("%d %d", &*(p1 + i), &*(p2 + i));
		i++;
	}
}

// ???????????????
void output(int *p1, int *p2)
{
	int i = 0;
	for (i = 0; i < cnt; i++) {
		printf("%d %d\n", *(p1 + i), *(p2 + i));
	}
}

// ??????
void comp(int *p1, int *p2, char *p_c, int t)
{
	int i = 0;
	while(1) {
		if (i == t) {
			break;
		}
		if (*(p1 + i) > *(p2 + i)) {
			*(p_c + i) = 'a';
		}
		if (*(p1 + i) < *(p2 + i)) {
			*(p_c + i) = 'b';
			}
		if (*(p1 + i) == *(p2 + i)) {
			*(p_c + i) = 'e';
		}
		i++;
	}
}

// ?¨????
void score(int *p1, int*p2, int t)
{
	int sum_a = 0, sum_b  = 0, i = 0;
	
	while(1) {
		if (i == t) {
			break;
		}
		if(tmp[i] == 'a') {
			sum_a = sum_a + a[i] + b[i];
		}
		if(tmp[i] == 'b') {
			sum_b = sum_b + a[i] + b[i];
		}
		if(tmp[i] == 'e') {
			sum_a = sum_a + a[i];
			sum_b = sum_b + b[i];
		}
		i++;
	}
	
	*(p1+cnt) = sum_a;
	*(p2+cnt) = sum_b;
	
	sum_a = 0;
	sum_b = 0;
}

Measured memory_bytes: 696
using System;
using System.Linq;

namespace AtCoder.ABC043
{
    class ProblemB
    {
        static void Main()
        {
            var texts = ReadLine();
            var ans = "";
            for (var i = 0; i < texts.Length; i++)
            {
                if (texts[i] == 'B')
                {
                    if (ans != "")
                    {
                        ans = ans.Substring(0, ans.Length - 1);
                    }
                }
                else
                {
                    ans += texts[i];
                }
            }

            Console.WriteLine(ans);
        }

        public static string ReadLine() => Console.ReadLine();

        public static int ReadInt() => int.Parse(ReadLine());

        public static int[] ReadIntArray() => ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
    }
}


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

int main()
{
    int N; cin>>N;
    string s; cin>>s;
    for(int i=0;i<s.size();i++){
        int t=(s[i]-'A'+N)%26;
        s[i]=(char)('A'+t);
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getLine

  let sumModDigits [] res = res
      sumModDigits (c:cs) res = let res' = (res + read [c]) `mod` 9
                                in sumModDigits cs res'

      dmod9 = sumModDigits n 0

  if dmod9 == 0
    then putStrLn "Yes"
    else putStrLn "No"


Measured memory_bytes: 11988
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 1000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector


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

int a, b; cin >> a >> b;
string A, B;
rep(_, 0, b) A.push_back((char)(a + '0'));
rep(_, 0, a) B.push_back((char)(b + '0'));

cout << min(A, B) << "\n";

}
// 書いて考える．場合分け．情報整理．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(true) {
			int a=sc.nextInt();
			if(a==0) {
				System.exit(0);
			}
			String[] ary=new String[a];
			int maxlen=0;
			for(int i=0; i<a; i++) {	//プリアンブル
				String s=sc.next();
				StringBuilder sb=new StringBuilder();
				sb.append(s.charAt(0));
				for(int k=0; k<s.length()-1; k++) {
					if(s.charAt(k)=='a'||s.charAt(k)=='i'||s.charAt(k)=='u'||s.charAt(k)=='e'||s.charAt(k)=='o') {
						sb.append(s.charAt(k+1));
					}
				}
				ary[i]=sb.toString();
				maxlen=Math.max(maxlen, ary[i].length());
				//System.out.println(ary[i]);
			}
			HashSet<String> airport=new HashSet<String>();
			boolean kan=false;
			for(int i=1; i<=maxlen; i++) {
				airport=new HashSet<String>();
				for(int j=0; j<a; j++) {
					String tmp=ary[j].substring(0, Math.min(i, ary[j].length()));
					if(airport.contains(tmp)) {
						break;
					}
					else {
						airport.add(tmp);
					}
					if(j==a-1) {
						System.out.println(i);
						kan=true;
						break;
					}
				}
				if(kan) {
					break;
				}
			}
			if(!kan) {
				System.out.println(-1);
			}
			/*HashSet<String> airport=new HashSet<String>();
			boolean kan=false;
			for(int i=1; i<=maxlen; i++) {
				for(int j=0; j<a; j++) {
					String tmp=ary[j].substring(0, Math.min(maxlen-1,Math.min(ary[j].length(),i)));
					if(airport.contains(tmp)) {
						break;
					}
					else {
						airport.add(tmp);
					}
					if(j==a-1) {
						System.out.println(i);
						kan=true;
						break;
					}
				}
				if(kan) {
					break;
				}
			}
			if(!kan) {
				System.out.println(-1);
			}*/
		}
	}
}


Measured memory_bytes: 36356
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;

int main(){
  int n, m;
  cin>>n>>m;
  PL mise[n];
  REP(i, n){
    cin>>mise[i].first>>mise[i].second;
  }

  sort(mise, mise+n);
  int count=0, j=0;
  LL ans=0;
  while(count<m){
    if(mise[j].second+count>=m){
      ans += mise[j].first*(m-count);
      count=m;
    }
    else{
      ans += mise[j].first*mise[j].second;
      count+=mise[j].second;
    }
    ++j;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
A,B=list(map(int,input().split()))
l=[[] for i in range(100001)]
for i in range(A):
   X,Y,Z=list(map(int,input().split()))
   for j in range(X-1,Y):
      l[j].append(Z)
ans=0
for i in l:
   ans=max(ans,len(set(i)))
print(ans)

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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a.at(i);
    int i=1,cnt=1;
    while(i<n){
        if(a.at(i)-a.at(i-1)==0) i++;
        else if(a.at(i)-a.at(i-1)>0){
            while(i<n && a.at(i)-a.at(i-1)>=0) i++;
            i++;
            if(i!=n+1) cnt++;
        }else{
            while(i<n && a.at(i)-a.at(i-1)<=0) i++;
            i++;
            if(i!=n+1) cnt++;
        }
    }
    if(cnt==0) cnt++;
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

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

int main(void) {
  string s;
  cin >> s;
  int cnt = 0;
  int mx = 0;
  rep(i, s.size()) {
    if (s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T') {
      cnt++;
      mx = max(mx, cnt);
    }
    else {
      cnt = 0;
    }
  }
  cout << mx << endl;

  return 0;
}


Measured memory_bytes: 256
import itertools
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
per = []
for v in itertools.permutations(P):
    per.append(''.join(str(n) for n in v))
per.sort()
# print(per)
a = per.index(''.join(str(n) for n in P))
b = per.index(''.join(str(n) for n in Q))
ans = abs(a - b)
print(ans)

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

int main(){
  
  long long n,k,i,ans=0;
  string s;
  
  cin>>n>>k;
  
  cin>>s;
  
  for(i=0;i<n;i++){
   
    if((s[i]=='L')&&(i>0)){
     if(s[i-1]=='L')
       ans++;}
    
    else if((s[i]=='R')&&(i<n-1)){
     if(s[i+1]=='R')
       ans++;}}
  
  cout<<min(n-1,ans+2*k)<<endl;
  
  return 0;}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,A;
  A = 1;
  cin >> N >>K;
  for( int i = 0;i < N; i++){
    if (A * 2 > A + K){
      A += K;
    }
    else if (A * 2 <= A + K){
      A *= 2;
    }
  }
  cout << A <<endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define vpii vct<pii>
#define vpll vct<pll>
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define print(v) for(auto it:v)cout<<it<<endl;
#define PI 2*acos(0.0)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define yes cout<<"Yes"<<endl
#define no cout<<"-1"<<endl
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
///................Graph's Move.................
///const int dx[] = {+1,-1,+0,+0}; ///Rock's Move
///const int dy[] = {+0,+0,+1,-1}; ///Rock's Move
///const int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
///const int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int dx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's Move
///const int dy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's Move
///*.....................-_-........................*///
struct type{
int a,b,c;
};
int main()
{
    FIO;
    int n,i,j;
    cin>>n;
    vct<type>v(n);
    for(i=0; i<n; i++)
        cin>>v[i].a>>v[i].b>>v[i].c;
    for(i=1; i<n; i++)
    {
        v[i].a += max(v[i-1].b,v[i-1].c);
        v[i].b += max(v[i-1].a,v[i-1].c);
        v[i].c += max(v[i-1].a,v[i-1].b);
    }
    cout<<max3(v[n-1].a,v[n-1].b,v[n-1].c)<<endl;
}


Measured memory_bytes: 4492