akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

vllvll grid(100, vll(100));
vllvll del(100, vll(100, 0));
ll H, W;

void allcol(ll row)
{
        bool flg = true;
        rep(i, 0, W) {
                if (grid[row][i] == 1) flg = false;
        }
        if (flg) {
                rep(i, 0, W) {
                        del[row][i] = 1;
                }
        }
}

void allrow(ll col)
{
        bool flg = true;
        rep(i, 0, H) {
                if (grid[i][col] == 1) flg = false;
        }
        if (flg) {
                rep(i, 0, H) {
                        del[i][col] = 1;
                }
        }
}

int main()
{      
        cin >> H >> W;
        rep(i, 0, H) {
                rep(j, 0, W) {
                        char x;
                        cin >> x;
                        if (x == '.') grid[i][j] = 0;
                        else grid[i][j] = 1;
                }
        }
        rep(i, 0, H) {
                allcol(i);
        }
        rep(i, 0, W) {
                allrow(i);
        }

        // print2d(del);
        rep(i, 0, H) {
                string ans;
                rep(j, 0, W) {
                        if (! del[i][j]) {
                                if (grid[i][j] == 0) {
                                        ans += '.';
                                } else {
                                        ans += '#';
                                }
                        }
                }
                if (len(ans)) {
                        cout << ans << endl;
                }
        }
}

Measured memory_bytes: 384
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<iostream>
#include<string>
#include<set>
#include<queue>
#include<random>

using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")

#define pb push_back
#define ld long double
#define ll long long
#define int long long 
#define mp make_pair

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<char> v{ 'R', 'G', 'B' };
	vector<pair<pair<char, int>, pair<char, int>>> kek(n);
	map<char, int> cnt;
	for (int i = n - 1; i > -1; i--) {
		bool x = 0;
		for (auto to : v) {
			if (to != s[i]) {
				if (!x) {
					kek[i].first = { to, cnt[to] };
					x = 1;
				}
				else {
					kek[i].second = { to, cnt[to] };
				}
			}
		}
		cnt[s[i]]++;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			if (s[i] != s[j]) {
				if (kek[j].first.first != s[i]) {
					if (j + abs(i - j) < n && s[j + abs(i - j)] == kek[j].first.first) {
						ans += kek[j].first.second - 1;
					}
					else {
						ans += kek[j].first.second;
					}
				}
				else {
					if (j + abs(i - j) < n && s[j + abs(i - j)] == kek[j].second.first) {
						ans += kek[j].second.second - 1;
					}
					else {
						ans += kek[j].second.second;
					}
				}
			}
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const ll LINF=1e18;
const int INF=0x3f3f3f3f;
const int MAXN=200050;
ll a[MAXN],sum[MAXN];
void solve(int T){
	int n;
	ll ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];
		sum[i]%=MOD; 
	}
	for(int i=1;i<=n;i++){
		ans+=(a[i]*((sum[n]-sum[i]+MOD)%MOD))%MOD;
		ans%=MOD; 
	}
	printf("%lld",ans);
}
signed main(){
	int t=1;
	//scanf("%d",&t);
	for(int i=1;i<=t;i++){
		solve(i);
	}
}

Measured memory_bytes: 6860
{
  const run = (input: string) => {
    const x = parseInt(input.trim())
    return x >= 30 ? 'Yes' : 'No'
  }

  const Main = (input: string) => {
    console.log(run(input))
  };

  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}


Measured memory_bytes: 29648
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) { os << "[ "; 
	for(auto v:V)os << v << " "; return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){ os << "{ "; 
	for(auto s:S) os<<s<<" ";  return os<<"}"; 
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os<<"("<<P.first<<","<< P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
	os<<"{ ";for(auto m:M)os<<"("<<m.F<<":"<<m.S<<")";
	return os<<"}";
}
#define cerr cout
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define I insert 
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define For(i,n) for(int i=0;i<(int)n;++i)
#define Rev(i,n) for(int i=(int)n-1;i>=0;--i)
#define Rep(i,n) for(int i=1;i<=(int)n;++i)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpii;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int main(){
	fio; cout<<fixed<<setprecision(25);	
	string s; cin >> s;
	int cnt = 0;
	for(int i = 0;i < s.size(); ++i){
		if(s[i] == '?')
			s[i] = 'D';
	}
	cout << s << endl;
	// for(int i = 0;i < s.size() ; ++i)
	// 	cnt += (s[i] == 'D');
	// for(int i = 0;i < s.size()-1 ; ++i){
	// 	if(s[i] == 'P' && s[i+1] == 'D')
	// 		++cnt;
	// }
	// cout << cnt << endl;










	return 0;
}


Measured memory_bytes: 3744
#include <stdio.h>
#include <iostream>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {
    int X, A, B;
    cin >> X >> A >> B;

    if (B - A <= 0) {
        cout << "delicious" << endl;
    } else if (B - A <= X) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
t_list=[]
is_arg_ok = False
try:
  t_list = [int(n) for n in input().split(' ')]
except:
  print('age,price must be numbers')
  sys.exit(1)

min_1 = 10000
min_2 = 10000
for i in range(len(t_list)):
    t1 = t_list[i]
    if min_1 > t1:
        min_2 = min_1
        min_1 = t1
    elif min_2 > t1:
        min_2 = t1
min_t = min_1 + min_2
print(min_t)

Measured memory_bytes: 3064
# inputs
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]

# solve
dp = [1] * (n+1)

for i in a:
    dp[i] = 0

for i in range(2, n+1):
    if dp[i] != 0:
        dp[i] = (dp[i - 1] + dp[i - 2]) % (10 ** 9 + 7)

print(dp[n])


Measured memory_bytes: 7824
#include <bits/stdc++.h>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 1000000+5
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef unsigned long long ull;
typedef double db;
namespace fastIO {
#define BUF_SIZE 100000
#define OUT_SIZE 100000
#define ll long long
	bool IOerror=0;
	inline char nc()
	{
		static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE;
		if (p1==pend) {
			p1=buf;
			pend=buf+fread(buf,1,BUF_SIZE,stdin);
			if (pend==p1) {
				IOerror=1;
				return -1;
			}
		}
		return *p1++;
	}
	inline bool blank(char ch)
	{
		return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';
	}
	inline void read(int &x)
	{
		bool sign=0;
		char ch=nc();
		x=0;
		for (; blank(ch); ch=nc());
		if (IOerror)return;
		if (ch=='-')sign=1,ch=nc();
		for (; ch>='0'&&ch<='9'; ch=nc())x=x*10+ch-'0';
		if (sign)x=-x;
	}
	inline void read(ll &x)
	{
		bool sign=0;
		char ch=nc();
		x=0;
		for (; blank(ch); ch=nc());
		if (IOerror)return;
		if (ch=='-')sign=1,ch=nc();
		for (; ch>='0'&&ch<='9'; ch=nc())x=x*10+ch-'0';
		if (sign)x=-x;
	}
#undef ll
#undef OUT_SIZE
#undef BUF_SIZE
};
using namespace fastIO;
typedef long long ll;
void print(ll x)
{
	if(x<0) {
		putchar('-');
		x=-x;
	}
	if(x>9){
		print(x/10);
	}
	putchar(x%10+'0');
}
struct node{
	ll l,r,id;
};
node g[DMAX];
ll n,m,k,blo;
ll a[DMAX];
ll ans=0;
ll out[DMAX];
ll cnt[DMAX];
bool Cmp(const node &p,const node &q)
{
	return (p.l/blo)^(q.l/blo) ? p.l<q.l : (((p.l/blo) & 1) ? p.r<q.r : p.r>q.r); 
}
void add(ll node){
	cnt[a[node]]++;
	if(cnt[a[node]]==1){
		ans++;
	}
}
void del(ll node){
	cnt[a[node]]--;
	if(cnt[a[node]]==0){
		ans--;
	}
}
int main(){
	read(n);
	read(m);
	for(ll i=1;i<=n;i++){
		read(a[i]);
	}
	blo=n/sqrt(m*4/5);
	for(ll i=1;i<=m;i++){
		read(g[i].l),read(g[i].r);
		g[i].id=i;
	}
	sort(g+1,g+m+1,Cmp);
	ll l=0,r=0;
	for(ll i=1;i<=m;i++){
		ll le=g[i].l,re=g[i].r;
		while(l<le){
			del(l);
			l++;
		}
		while(l>le){
			l--;
			add(l);
		}
		while(r>re){
			del(r);
			r--;
		}
		while(r<re){
			r++;
			add(r);
		}
		out[g[i].id]=ans;
	}
	for(ll i=1;i<=m;i++){
		print(out[i]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 27332
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,last=0,num=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		long long x,y,sum;
		cin>>x>>y;
		num+=y;
		sum=x*y+last;
		while(sum>=10){
			num+=sum/10;
			sum=sum/10+sum%10;
		}
		last=sum;
	}
	cout<<num-1<<endl;
}

Measured memory_bytes: 384
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.05.09 17:00:38
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (ll i = 0; i < x; i++)
#define rep1(i, x) for (ll i = 1; i <= x; i++)
#define rrep(i, x) for (ll i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (ll i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

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

int main() {
    ll n, k, a[100010];
    scanf("%lld%lld", &n, &k);
    rep(i, n) scanf("%lld", &a[i]);

    ll x = 0;
    rrep(i, 60) {
        ll mask = 1LL << i;
        ll ol = 0, zl = 0;
        rep(j, n) {
            if (a[j] & mask) {
                ol++;
            } else {
                zl++;
            }
        }
        if (zl > ol && (x | mask) <= k) {
            x |= mask;
        }
    }

    ll ret = 0;
    rep(i, n) {
        ret += x ^ a[i];
    }

    printf("%lld\n", ret);

    /* --------------------------------- */
    return 0;
}

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

using namespace std;

int n;
int a[50001];
int S[50001];


int main(){

while(cin >> n && n > 0){


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

  S[0] = 0;
  for (int i = 0; i < n ; ++i)
  {
    S[i + 1] = S[i] + a[i];
    
  }

int max = -100000;
  for (int i = 0; i < n + 1; ++i)
  {
    for (int k = 0; k < i ; ++k)
    {
      if(S[i] - S[k] > max) max = S[i] - S[k];
    }
  }

  cout << max << endl;

  }
}

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

int main(){
    string a, b;
  cin >> a >> b;
  a = a + b;
  int n = stoi(a);
  bool flag = false;
  for(int i = 1;i < 333;i++){
    if(n == i*i){
      flag = true;
      break;
    }
  }
  if(flag){cout << "Yes" << endl;}
  else{cout << "No" << endl;}
} 

Measured memory_bytes: 256
n,m = map(int,input().split())
ans = 0
lst = []
for i in range(1,int(m**0.5)+1):
    if m%i == 0:
        if m//i < n:
            break
        else:
            ans = i
            lst.append(m//i)
lst.sort()
for i in lst:
    if m//i < n:
        break
    else:
        ans = i

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<int> W(N);
    for(int i=0;i<N;i++){
        cin>>W.at(i);
    }
    int dif=100;
    for(int i=0;i<N-1;i++){
        int tmpdif=0;
        for(int j=0;j<=i;j++){
            tmpdif+=W.at(j);
        }
        for(int j=i+1;j<N;j++){
            tmpdif-=W.at(j);
        }
        if(dif>abs(tmpdif)){
            dif=abs(tmpdif);
        }
    }
    cout<<dif<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
using namespace std;
typedef long long ll;
const int Maxn = 1e5 + 5;
typedef int arr[Maxn];
//ll Add(ll x, ll y) { return (x += y) >= Mod ? x - Mod : (x < 0 ? x + Mod : x); }
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
int n;
int main()
{
	cin >> n;
	n %= 10;
	if (n == 3)
		puts("bon");
	else if (n == 0 || n == 1 || n == 6 || n == 8)
		puts("pon");
	else
		puts("hon");
	return 0;
}
//A

Measured memory_bytes: 3592
N,M,X = map(int,input().split())
books = {}
for i in range(N):
    books[i] = list(map(int,input().split()))

min_ = 10**10

for i in range(2**N):
    understanding = [0 for j in range(M)]
    cost = 0
    for j in range(N):
        if (i>>j)&1:
            for k in range(M):
                understanding[k] += books[j][k+1]
            cost += books[j][0]
    if all([a >= X for a in understanding]):
        min_ = min(min_,cost)

if min_ == 10**10:
    min_ = -1
print(min_)


Measured memory_bytes: 9124
n = int(input())
# if n % 4 == 0 or n % 7 == 0:
#   print("Yes")
# elif n % (4 + 7) == 0:
#   print("Yes")
# elif n % 4 % 7 == 0 or n % 7 % 4 == 0:
#   print("Yes")
# else:
#   print("No")
ans = "No"
for i in range(0,n//4 + 1):
  for j in range(0,n//7 + 1):
    if 4 * i + 7 * j == n:
      ans = "Yes"
print(ans)

Measured memory_bytes: 3060
n,k=map(int,input().split())
A=list(map(int,input().split()))
i=l=1
l=0
F=[0]*n
L=[]
while 1:
  i=A[i-1]
  if F[i-1]>0:
    break
  else:
    L.append(i)
    F[i-1]=l
    l+=1
print((L[F[i-1]:])[(k-F[i-1])%(l-F[i-1])-1] if k>F[i-1] else L[k-1])

Measured memory_bytes: 32400
#include <iostream>
using namespace std;
int main()
{
	int i,j;
	cin>>i>>j;
	if (i+j==15) cout<<"+"<<endl;
	else 
	{
		if (i*j==15) cout<<"*"<<endl;
		else cout<<"x"<<endl;
	}
	return 0;
}

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

const int N =1e3+5;
bool prime[N];
vector<int>v;
long long mod = 1e9+7;

void seive()
{
   for(int i=1;i<=N;i++)prime[i]=true;

   for(int i=2;i*i<=N;i++)
   {
       if(prime[i]==true)
       {
           for(int j=i*2;j<=N;j+=i)
           {
               prime[j]=false;
           }
       }
   }
 //  for(int i=2;i<=N;i++)if(prime[i])v.push_back(i);
}

int main()
{
    seive();
    int n;
    cin>>n;
    int arr[n+5];
    for(int i=1;i<=n;i++)arr[i]=i;
    map<int,int>mp;

   for(int i=2;i<=n;i++)
   {
       if(prime[i])
       {
           for(int j=1;j<=n;j++)
           {
               while(arr[j]%i==0)
               {
                   arr[j]/=i;
                   mp[i]++;
               }
           }
       }
   }

   long long sum=1;

   for(int i=1;i<=n;i++)
   {
       if(prime[i])
       {
          // cout<<mp[i]<<endl;
           sum*=(mp[i]+1);
           sum=sum%mod;
       }
   }
   cout<<sum<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=1e3+5;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,a,b;
    cin>>n>>a>>b;
    ll lun=a+b;
    ll ans1=n/lun*a;
    n%=lun;
    ll ans2=min(n,a);
    cout<<ans1+ans2<<'\n';





}










Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    int m= n*a;

    if(m<b or m==b)
    {
        cout<<m<<endl;
    }

    else
    {
        cout<<b<<endl;
    }

        return 0;
}


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

using namespace std;

int A[100];
int B[100];
long long dp[100001];

int main() {
  int n, m; cin >> n >> m;
  for(int i = 0; i < n; ++i)
    	cin >> A[i] >> B[i];
  
  memset(dp, -1, sizeof dp);
  dp[0] = 0;
  for(int i = 0; i < n; ++i)
    for(int j = 1e5 - B[i]; j >= 0; --j)
      if(dp[j] != -1) {
        if(dp[j + B[i]] == -1) dp[j + B[i]] = A[i] + dp[j];
        dp[j + B[i]] = min(dp[j + B[i]], A[i] + dp[j]);
        }
  for(int i = 1e5; i >= 0; --i)
    if(dp[i] != -1 && dp[i] <= m) { cout << i; break; }
  return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int l, r;
  l = a + b;
  r = c + d;
  
  if(l == r) {
    cout << "Balanced" << endl;
  }
  else if(l > r) {
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

char G[105][105];

const ll dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const ll dx[] = {1, 0, -1, 0, 1, 1, -1, -1};

inline bool inside(ll y, ll x, ll H, ll W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

ll cost[105][105];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll h,w; cin>>h>>w;
  
  rep(i,h) rep(j,w) cin>>G[i][j];
  
  rep(i,h) rep(j,w) cost[i][j]=LINF;
  if(G[0][0]=='#') cost[0][0]=1;
  else cost[0][0]=0;
  
  priority_queue<tuple<ll,ll,ll,ll>, vector<tuple<ll,ll,ll,ll>>, greater<tuple<ll,ll,ll,ll>>> q;
  q.emplace(cost[0][0],0,0,cost[0][0]);
  
  
  while(!q.empty()){
    ll c,y,x,prev;
    tie(c,y,x,prev) = q.top(); q.pop();
    if(cost[y][x]<c) continue;
    rep(i,2){
      ll ny=dy[i]+y, nx=dx[i]+x;
      if(inside(ny,nx,h,w)){
        if(G[ny][nx]=='#'){
          if(prev==1){
            if(chmin(cost[ny][nx], c)) q.emplace(c,ny,nx,1);
          }else{
            if(chmin(cost[ny][nx], c+1)) q.emplace(c+1,ny,nx,1);
          }
        }else{
          if(chmin(cost[ny][nx], c)) q.emplace(c,ny,nx,0);
        }
      }
    }
  }
  
  cout<<cost[h-1][w-1]<<endl;
  
  
}

Measured memory_bytes: 3744
N = int(input())
V = [int(_) for _ in input().split()]

odd = {}
even = {}
for i in range(N):
    if i%2==0:
        if V[i] in even:
            even[V[i]] += 1
        else:
            even[V[i]] = 1
    else:
        if V[i] in odd:
            odd[V[i]] += 1
        else:
            odd[V[i]] = 1
maxEven, maxOdd = max(even.values()), max(odd.values())
if max(even, key=even.get) != max(odd, key=odd.get):
    print(N-maxEven-maxOdd)
else:
    even[max(even, key=even.get)] = 0
    odd[max(odd, key=odd.get)] = 0
    maxEven2, maxOdd2 = max(even.values()), max(odd.values())
    if maxEven2 >= maxOdd2:
        if len(even) > 1:
            print(N-maxEven2-maxOdd)
        else:
            print(N-maxOdd)
    else:
        if len(odd) > 1:
            print(N-maxEven-maxOdd2)
        else:
            print(N-maxEven)


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

#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;

string replaceAll(string &replacedStr, string from, string to) {
    int pos = replacedStr.find(from);
    int toLen = to.length();
 
    if (from.empty()) {
        return replacedStr;
    }
 
    while ((pos = replacedStr.find(from, pos)) != string::npos) {
        replacedStr.replace(pos, from.length(), to);
        pos += toLen;
    }
    return replacedStr;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    replaceAll(s, "BC", "D");
    int N = s.size();
    int Anum = 0;
    int ans = 0;
    for (int i=0;i<N;i++){
        if (s[i] == 'A') Anum++;
        else if (s[i] == 'B') Anum = 0;
        else if (s[i] == 'C') Anum = 0;
        else {
            ans += Anum;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int a[maxn],n,_max,_max2;
int main()
{
	scanf("%d",&n);
	for(register int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]>_max)
		{
			_max2=_max;
			_max=a[i];
		}
		else
			if(a[i]>_max2)
				_max2=a[i];
	}
	for(register int i=1;i<=n;i++)
		if(a[i]==_max)
			printf("%d\n",_max2);
		else
			printf("%d\n",_max);
	return 0;
}

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

int main() 
{
    int n, a, b;
    cin >> n >> a >> b;

    int ans = min(a*n, b);
    cout << ans << endl;

    return 0;
}


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

using namespace std;

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

    if (s[0] == s.back())
        cout << (s.size() % 2 == 0 ? "First" : "Second") << endl;
    else
        cout << (s.size() % 2 == 1 ? "First" : "Second") << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define LL __int128
#define ll long long
#define sc(a) scanf("%d", &a)
#define sc2(a, b) scanf("%d%d", &a, &b)
#define sc3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define scl(a) scanf("%lld", &a)
#define scl2(a, b) scanf("%lld%lld", &a, &b)
#define ss(a) scanf("%s", a)
#define mem(a, b) memset(a, b, sizeof(a))
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PII pair<int, int>
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
ll POW(ll a, ll b){
	ll ans = 1;
	b %= (mod - 1);
	while(b){
		if(b & 1) ans = ans * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}
ll inv(ll a){
	return POW(a, mod - 2);
}
ll fac[maxn], ifac[maxn];
void init(){
	fac[0] = fac[1] = 1;
	for(int i = 2; i < maxn; i ++) fac[i] = fac[i - 1] * i % mod;
	ifac[maxn - 1] = inv(fac[maxn - 1]);
	for(int i = maxn - 2; i >= 0; i --) ifac[i] = ifac[i + 1] * (i + 1) % mod;
}
ll getc(int n, int m){
	if(n < m || m < 0) return 0;
	return fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
int main(){
	int n;
	cin >> n;
	init();
	if(n == 1) cout << 0 << endl;
	else if(n == 2) cout << 2 << endl;
	else{
		ll ans = POW(10, n);
		ans = (ans + mod - POW(8, n)) % mod;
		ll res = 1;
		for(int i = 1; i <= n; i ++){
			res = (res + getc(n, i) % mod * POW(8, n - i) % mod) % mod;
		}
		ans = (ans + mod - res * 2 % mod) % mod;
		cout << (ans + 2) % mod << endl; 

	}
	return 0;
}

Measured memory_bytes: 19260
#include<bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
typedef long long ll;
using namespace std;
//const ll MOD=(ll)1e9+7;
//const ll inf=(ll)1e14;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
int n,m,h,w;
string s;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  while(cin>>n>>m,n){
    int w[1502],h[1502];
    h[0]=0;
    for(int i=1;i<=n;i++){
      cin>>h[i];
    }
    w[0]=0;
    for(int i=1;i<=m;i++){
      cin>>w[i];
    }
    for(int i=0;i<=m;i++){
      if(i==0)continue;
      w[i]=w[i-1]+w[i];
    }
    for(int i=0;i<=n;i++){
      if(i==0)continue;
      h[i]=h[i-1]+h[i];
    }
    vector<int> v;
    for(int i=0;i<=n;i++){
      for(int j=i+1;j<=n;j++){
        v.push_back(h[j]-h[i]);
      }
    }
    sort(v.begin(),v.end());
    /*for(int i=0;i<(int)v.size();i++){
      cout<<v[i]<<" ";
    }*/
    //cout<<endl;
    int ans=0;
    for(int i=0;i<=m;i++){
      for(int j=i+1;j<=m;j++){
        int hen=w[j]-w[i];
        ans+=upper_bound(v.begin(),v.end(),hen)-lower_bound(v.begin(),v.end(),hen);
      }
    }
    cout<<ans<<endl;
  }
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}







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

int main() {
  int r;
  cin >> r;
  cout << r * r << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

int main(){
    ll n,a,b;cin>>n>>a>>b;
    cout << (n==3||n==5||n==7?"YES":"NO") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n;
  cin>>n;
  int arr[n];
  int fre[100005]={0};
  long long int sum=0;
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
    sum=sum+arr[i];
    fre[arr[i]]++;
  }
  int q;
  cin>>q;
  for(int i=0;i<q;i++)
  {
    int a,b;
    cin>>a>>b;
    int c=fre[a];
    fre[a]=0;
    fre[b]=fre[b]+c;
    sum=sum+c*(b-a);
    cout<<sum<<endl;
  }
    
}


Measured memory_bytes: 4292
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n;
    cin >> n;
    int m = 1e9+7;
    long long  ans = 1LL;
    for(int i = 1; i <= n; i++){
        ans *= i;
        ans = ans%m;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//atcoder clange
#include <stdio.h>

int main(void){
    int X,A;
      scanf("%d", &X);//数値の取得
        scanf("%d", &A);//数値の取得

    if(X < A){
      printf("0");
      return 0;
    }else if(X >= A){
     printf("10");
      return 0;
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define x first
#define y second

using namespace std;

const int N = 1e5+1, iters = 3000;

int n, m;
vector<int> g[N];

bool used[N];
int h[N], changed[N];
int dfs(int v, int p=-1){
    if(used[v]) return h[v] < h[p];
    used[v] = true;
    h[v] = (p == -1 ? 0 : h[p]+1);
    for(int u : g[v]){
        if(u == p)
            continue;
        changed[v] ^= 1^dfs(u, v);
    }
    return changed[v];
}

int main(){
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> n >> m;
    if(m&1){
        cout << "-1\n";
        return 0;
    }
    for(int i = 0; i < m; ++i){
        int u, v;
        cin >> u >> v;
        --u; --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(0);
    for(int v = 0; v < n; ++v)
        for(int u : g[v]){
            if(h[u] > h[v])
                continue;
            if(h[u]+1 != h[v]){
                cout << u+1 << ' ' << v+1 << '\n';
                continue;
            }
            if(changed[v])
                cout << v+1 << ' ' << u+1 << '\n';
            else cout << u+1 << ' ' << v+1 << '\n';
        }
}


Measured memory_bytes: 12416
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
int main(){
	string str;
	int i,l,s=0;cin>>str;
	 
	l=str.size();
	for(i=0;i<=l;i++){
		if(str[i]=='C'){
			s=1;
		}
		if(str[i]=='F'&&s==1){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
const int MAX = 510000;
const int MOD = 1000000007;

//二項係数ライブラリ
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k) {
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    if (n == k) {
        return 1;
    }
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
    int N;
    cin>>N;
    vector<int>A(N);
    vector<int>ansa(N+1);
    vector<int>ansb(N+1);
    int g=0;
    rep(i,N){
        cin>>A[i];
            g=__gcd(g,A[i]);
        	ansa[0]=A[N-1];
        ansa[i+1]=g;
    }
    int gc=0;
    rep(i,N){
            gc=__gcd(gc,A[N-i-1]);
        ansb[i+1]=gc;
    }
      ansb[0]=A[0];
    ll ans=0;
    rep(i,N){
        if(ans<__gcd(ansa[i],ansb[N-i-1])){
            ans=__gcd(ansa[i],ansb[N-i-1]);
        }
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 4576
#include <stdio.h>
#define ll long long
#define mod 1000000007

ll dp[105][4][4][4] = {0};

bool pan(int a, int b, int c) {
    if (a == 0 && b == 2 && c == 1) return false;
    if (a == 0 && b == 1 && c == 2) return false;
    if (a == 2 && b == 0 && c == 1) return false;
    return true;
}

bool pan1(int a, int b, int c) {
    if (a == 0 && b == 2 && c == 1) return false;
    return true;
}

int main () {
    int n;
    scanf("%d", &n);
    if (n == 1) {
        printf("4\n");
    } else if(n == 2) {
        printf("16\n");
    } else {
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                for (int p = 0; p < 4; p++) {
                    if (pan(i, j, p)) {
                        dp[3][i][j][p] = 1;
                    }
                }
            }
        }

        for (int k = 4; k <= n; k++) {
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j < 4; j++) {
                    for (int p = 0; p < 4; p++) {
                        //dp[k][i][j][p]
                        if (pan(i, j, p)) {
                            for (int q = 0; q < 4; q++) {
                                if (pan(q, i, j) && pan1(q, j, p) && pan1(q, i, p)) {
                                    dp[k][i][j][p] = (dp[k][i][j][p] + dp[k - 1][q][i][j]) % mod;
                                } 
                            }
                        }
                    }
                }
            }
        }

        ll ans = 0;
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                for (int p = 0; p < 4; p++) {
                    ans = (ans + dp[n][i][j][p]) % mod;
                }
            }
        }
        printf("%lld\n", ans);

    }
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=1LL << 60;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    ll n,k; cin >> n >> k;
    ll dp[n];
    ll a[n];
    for (int i=0;i<n;i++){
        cin >> a[i];
        dp[i]=INF;
    }
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    if (k>n){
        for(int i=2;i<n+1;i++){
            for (int j=1;j<i+1;j++){
            chmin(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
            }   
        }
    }
    else{
        for(int i=2;i<k;i++){
            for (int j=1;j<i+1;j++){
                chmin(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
            }
        }
        for (int i=k;i<n;i++){
            for (int j=1;j<k+1;j++){
                chmin(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
            }
        }
    }
    cout << dp[n-1] << "\n";
}















Measured memory_bytes: 5152
#include <bits/stdc++.h>
using namespace std;
int main() {
    static int N, Q;
    string S;
    cin >> N >> Q >> S;
    vector<int> ac(N);
    for(int i = 0; i < N - 1; ++i) {
        ac[i + 1] = ac[i];
        if(S[i] == 'A' && S[i + 1] == 'C')
            ac[i + 1]++;
    }
    for(int i = 0; i < Q;++i){
        static int l, r;
        cin >> l >> r;
        l--, r--;
        cout << ac[r] - ac[l] << endl;
    }
    return 0;
}


Measured memory_bytes: 1408
S = input()
ans = True
for n in range(len(S)):
    if n%2 == 0:
        if S[n] not in ["R","U","D"]:
            ans = False
    else:
        if S[n] not in ["L","U","D"]:
            ans = False
if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 233;
char s[maxn];
ll ans = 0;
int main()
{
	scanf("%s",s);
	int n = strlen(s);
	int cur = 0;
	for(int i=0;i<n;i++){
		if(s[i]=='<'){
			cur++;
			ans += cur;
		}
		else{
			int j = i;
			while(j+1<n&&s[j+1]==s[j])j++;
//			cout<<i<<"->"<<j<<endl;
			ll siz = j-i+1;
			if(siz>=cur){
				ans -= cur;
				ans += siz*(siz+1)/2;
			}
			else{
				ans += (siz-1)*(siz)/2;
			}
			cur = 0;
			i = j;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  vec a={0,1,0,2,0,2,0,0,2,0,2,0};
  ll x,y;
  cin >> x >> y;
  x--,y--;
  if(a[x]==a[y]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

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


int main() {
  int N,M,a;
  cin >> N >> M;
  vector<int> A(M),memo;
  memo = {-10000,2,5,5,4,5,6,3,7,6};
  rep(i,M) cin >> A[i];
  sort(A.rbegin(),A.rend());
  vector<vector<int>> dp(N+100,vector<int> (M,0));
  rep(i,M) {
    int t = A[i];
    dp[memo[t]][i] = 1;
  }
  rep(i,N) rep(j,M) {
    // cout << dp[i][j] << ' ';
    auto now = dp[i][j];
    if (now!=0) {
      rep(k,M) {
        if (i+memo[A[k]]>N) continue;
        auto tmp = dp[memo[A[k]]][k];
        chmax(dp[i+memo[A[k]]][k], now+1);
      }
    }
  }
  int d = *max_element(dp[N].begin(),dp[N].end()),cnt=d;
  // cout << "d: " << d << endl;
  // string res(d,'0');
  int nc = N;
  rep(i,d) {
    rep(j,M) {
      if (dp[nc][j]==cnt) {
        cout << A[j];
        cnt--;
        nc -= memo[A[j]];
        break;
      }
    }
  }
}

Measured memory_bytes: 896
#include <iostream>
using namespace std;
int main()
{
	int n,k;
	int ans = 1000;
	cin >> n;
	k = n % 1000;
	if (k == 0) {
		ans = 0;
	}
	else {
		ans = ans - k;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3572
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
#include <deque>
#include <queue>
#include <tuple>
using namespace std;

#define prec(i) cout << fixed << setprecision(i)

void output_yn(bool isYes) {
	if (isYes)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

const long long MOD = 1000000007;

long long fact(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

long long fact_mod(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum = (sum * i) % MOD;

	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

long long pow_mod(int a, int b) {
	long long ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}

long long powll(long long a, long long  b) {
	long long ans = 1;
	for (long long i = 0; i < b; i++)
		ans = ans * a;

	return ans;
}

long long modinv(long long a) {

	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;

	return u;
}

long long _gcd(long long a, long long b)
{
	if (a < b)
		swap(a, b);

	if (a % b == 0)
		return b;
	else
		return _gcd(b, a % b);
}

long long _lcm(long long a, long long b)
{
	return (((a * b) % MOD) * modinv(_gcd(a, b))) % MOD;
}

long long ncr(long long n, long long r) {
	long long sum = 1;
	for (long long i = r + 1; i <= n; i++)
		sum *= i;

	return sum;
}


int main()
{
	int n;
	long long sum = 0;
	cin >> n;

	vector<long long> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];

	for (int i = 1; i < n; i++) {
		if (a[i - 1] > a[i]) {
			sum += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	string s;
	cin >> s;
	int sub = 0;
	int S = 0;
	int T = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'S') {
			S++;
		}
		else {
			T++;
			if (S > 0) {
				S--; T--; sub+=2;
			}
		}
	}
	cout << s.size() - sub << endl;
	return 0;
}


Measured memory_bytes: 640
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

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


    stack<char> ch;
    FOR(i, 0, n) {
        char c = s[i];
        if (ch.size() && ch.top() == '(' && c == ')')
            ch.pop();
        else
            ch.push(c);
    }
    int leftp = 0, rightp = 0;
    while (ch.size()) {
        if (ch.top() == '(')
            leftp++;
        else
            rightp++;
        ch.pop();
    }
    s = string(rightp, '(') + s + string(leftp, ')');
    cout << s << endl;
    return 0;
}

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

// #define ANS  //for answer
#define CMP  //for compe
#ifdef CMP
using namespace std;
#else
#endif

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define nv(x) #x, (x)
#define ncv(x) #x, ":", (x)
#define ncvc(x) #x, ":", (x), ","
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
void pPRINT(std::ostream& ost) {}
template <class T, class... U>
void pPRINT(std::ostream& ost, const T t, const U... u) {
  ost << t << " ";
  pPRINT(ost, u...);
}
template <class... T>
void PRINT(const T... t) { pPRINT(std::cout, t...); }
template <class... T>
void PRINTl(const T... t) {
  pPRINT(std::cout, t...);
  std::cout << "\n";
}
template <class T>
void PRINTa(const T* const t, const ll size) {
  REP(i, size)
  PRINT(t[i]);
  PRINTl();
}
template <class T>
void PRINTal(const T* const t, const ll size) {
  REP(i, size)
  PRINTl(i, ":", t[i]);
}
#ifndef DBG
#define DEBUG(...)
void init() {}
#else
#define DEBUG(...)                                                     \
  {                                                                    \
    PRINT("##DEBUG##", "file :", __FILE__, ", line :", __LINE__, "["); \
    PRINT(__VA_ARGS__);                                                \
    PRINTl("]");                                                       \
  }
void init() {
  DEBUG("INIT");
  cin.tie(0);
  ios::sync_with_stdio(false);
}
#endif
#ifdef ANS
#else
#endif

void solve();

int main(int argc, char* argv[]) {
  DEBUG("MAIN");
  init();
  solve();

  return 0;
}

void solve() {
  DEBUG("SOLVE START");

  ll a, b;
  cin >> a >> b;
  ll l = a > b ? a : b;
  ll s = a > b ? b : a;

  ll mr = 1;
  DEBUG(ncv(s), ncv(l), ncv(mr));
  for (ll i = s; i > 0; i--) {
    if (s % i == 0 && l % i == 0) {
      DEBUG("match i:", i);
      mr = i;
      break;
    }
  }
  DEBUG(ncv(s), ncv(l), ncv(mr));

  PRINT(s * (l / mr));

  return;
}

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

using namespace std;

typedef long long ll;

int max_N = 100005;

ll N, M;
vector<int> colors(max_N, -1);
vector<vector<int>> g(max_N, vector<int>());

bool dfs(int v, int color){
	colors[v] = color;

	for(int x : g[v]){
		if(colors[x] == color) return false;
		if(colors[x] == -1 && !dfs(x, 1 - color)) return false;
	}

	return true;
}

bool is_bipartite(){
	return dfs(0, 1);
}

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

	cin >> N >> M;
	rep(i, M){
		int a, b;
		cin >> a >> b;
		g[a-1].push_back(b-1);
		g[b-1].push_back(a-1);
	}

	if(is_bipartite()){
		ll cnt = 0;
		for(int i = 0; i < N; i++){
			if(colors[i] == 1) {
				cnt++;
			}
		}

		cout << (N - cnt) * cnt - M << endl;
	}else{
		cout << N * (N - 1) / 2 - M << endl;
	}
}


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

using namespace std;
typedef long long ll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main() {
  ll N, K;
  cin >> N >> K;
  ll cnt = 0;
  if (K == 0) {
    cnt = N * N;
  } else {
    for (int b = K + 1; b <= N; b++) {
      int seq = (N + 1) / b;
      cnt += seq * (b - K);
      int r = (N + 1) - seq * b - K;
      if (r >= 1)
      cnt += r;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256