akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
  int n;
  int a, b;
  int maxv = -1;
  int id = 21;
  
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a >> b;
    if ( maxv == b ) {
      if( id > a ) {
	maxv = b;
	id = a;
      }
    } else if ( maxv < b ) {
      maxv = b;
      id = a;
    }
  }

  cout << id << " " << maxv << endl;
  return 0;
}

Measured memory_bytes: 1164
a, b, c = map(int, input().split())
k = int(input())

while True:
    if b > a:
        break
    b *= 2
    k -= 1

while True:
    if c > b:
        break
    c *= 2
    k -= 1

if k < 0:
    print('No')
else:
    print('Yes')

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


#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ll long long


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int a, b;

    cin >> a >> b;

    if ( a >= 13 ) {
    	cout << b << endl;
    } else if ( a >= 6 ) {
    	cout << b / 2 << endl;
    } else {
    	cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
l = [1] + [0]*(n-1)
#既に変更した桁を記録するset
check = set()
for i in range(m):
    s,c = map(int,input().split())
    #既に変更した桁について、他の数字へ変更されていないかチェック
    if s in check and l[s-1] != c:
        l[0] = -1
        break
    #1桁ではない数字で、一番上の桁が0に変更されていないかチェック
    elif s==1 and c==0 and n!=1:
        l[0] = -1
        break
    else:
        check.add(s)
        l[s-1] = c
if l[0] == -1:
    print(l[0])
elif n==1 and m==0:
    print(0)
else:
    print(*l,sep="")

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		var A = GetLong();
		var B = GetLong();
		var N = GetLong();
		WriteLine((N >= B - 1) ? f(A, B, B - 1) : f(A, B, N));
	}

	private long f(long A, long B, long x) => (A * x) / B - A * (x / B);
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 27492
#include <stdio.h>

#define inf 500000

int h=0,a[10001][2],b[10000];

void mh(int i){//big <- small
  int l,r,big,t;
    while(1){
      l = i*2;
      r = i*2 + 1;
    
      if(l<=h && a[l][1]<a[i][1])big = l;
      else big = i;
      if(r<=h && a[r][1] < a[big][1])big = r;
    
      if(big!=i){
        t=b[a[i][0]];
        b[a[i][0]]=b[a[big][0]];
        b[a[big][0]]=t;
    
        t=a[i][0];
        a[i][0]=a[big][0];
        a[big][0]=t;
        
        t=a[i][1];
        a[i][1]=a[big][1];
        a[big][1]=t;
        
        i=big;
      }
      else break;
    }
}

void in(int num,int key){
  int t,tt;
  h++;
  tt=h;
  b[num]=h;
  a[h][0]=num;
  a[h][1] = key;
  while(1<tt && a[tt/2][1]>a[tt][1]){
    t=b[a[tt][0]];
    b[a[tt][0]]=b[a[tt/2][0]];
    b[a[tt/2][0]]=t;

    t=a[tt][0];
    a[tt][0] = a[tt/2][0];
    a[tt/2][0] = t;
    
    t=a[tt][1];
    a[tt][1] = a[tt/2][1];
    a[tt/2][1] = t;
    
    tt = tt/2;
  }
}

void delete2(int j){
  int i,t,tt;
  i=b[j];
  b[j]=inf;

  b[a[h][0]]=i;
  a[i][0]=a[h][0];
  a[i][1]=a[h][1];
  h--;
  mh(i);

  tt=i;
  while(1<tt && a[tt/2][1]>a[tt][1]){
    t=b[a[tt][0]];
    b[a[tt][0]]=b[a[tt/2][0]];
    b[a[tt/2][0]]=t;

    t=a[tt][0];
    a[tt][0]=a[tt/2][0];
    a[tt/2][0]=t;

    t=a[tt][1];
    a[tt][1]=a[tt/2][1];
    a[tt/2][1]=t;

    tt=tt/2;
  }
}

int ex(void){
  int t;

  t=a[1][0];
  b[a[h][0]]=1;
  a[1][0] = a[h][0];
  a[1][1] = a[h][1];
  h--;
  mh(1);

  b[t]=inf;

  return t;
}
int v[10000][1000][2],vnum[10000];
int main(){
  int i,j,n,m,d[10002],s[10002],t,tt;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    b[i]=inf;
    d[i]=inf;
    s[i]=0;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&t,&vnum[i]);
    for(j=0;j<vnum[i];j++){
      scanf("%d%d",&t,&tt);
      v[i][j][0]=t;
      v[i][j][1]=tt;
    }
  }
  d[0]=0;
  in(0,0);
  while(h!=0){
    t=ex();
    s[t]=1;
    for(i=0;i<vnum[t];i++){
      tt=v[t][i][0];
      if(s[tt]==0){
        if(d[t] + v[t][i][1] < d[tt]){
            if(b[tt]!=inf){
            delete2(tt);
           }
           d[tt] = d[t] +v[t][i][1];
           in(tt,d[tt]);
        }
      }
    }
  }

  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
  
  return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n), h(n);
  int ax, by, ch;
  rep(i, n){
    cin >> x[i] >> y[i] >> h[i];
    if(h[i] > 0){
      ax = x[i];
      by = y[i];
      ch = h[i];
    }
  } 
  rep(tx,101){
    rep(ty,101){
      bool ok = true;
      int H = ch + abs(tx - ax) + abs(ty - by);
      rep(i,n){
        if(h[i] != max(H - abs(tx - x[i]) - abs(ty- y[i]), 0)){
          ok = false;
          break;
        }
      }
      if(ok){
        cout << tx << " " << ty << " " << H << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)
const ll MOD = (ll) 1e9 + 7;

int main() {
	ios::sync_with_stdio(false);

	ll n; cin >> n;

	vector<pll> heights(n);
	vl values(n);
	vector<pll> flowers;

	FOR(i,0,n) {
		cin >> heights[i].xx;
		heights[i].yy = i;
	}
	FOR(i,0,n) {
		cin >> values[i];
	}
	sort(all(heights));

	FOR(i,0,n) {
		pll idx = heights[i];
		// xx = idx, yy = value
		flowers.pb({idx.yy, values[idx.yy]});
	}

	// xx = height, yy = value
	set<pll> reihe;
	reihe.insert({0,0});
	// maps von idx auf val
	FOR(i,0,n) {
		auto it = reihe.lower_bound(flowers[i]);
		it--;
		pll newelem = {flowers[i].xx,
			flowers[i].yy + it->yy};
		it++;
		while (it != reihe.end()) {
			if (it->yy < newelem.yy) {
				auto blob = it;
				it++;
				reihe.erase(blob);
			} else {
				break;
			}
		}
		reihe.insert(newelem);

		/*
		for(const auto i: reihe) {
			cerr << "(" << i.xx << "," << i.yy << "), ";
		}
		cerr << endl;
		*/
	}

	cout << (*reihe.rbegin()).yy << endl;

	return 0;
}


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

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

    string s;
    cin >> s;

    int ans = 1;
    for(int i = 0; i < n - 1; i++) {
        if(s[i] != s[i + 1]) {
            ans += 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

d, n = map(int, input().split())

a = 0
if d == 0:
    a = n
    if n == 100:
        a += 1
elif d == 1:
    a = 100 * n
    if n == 100:
        a += 100
elif d == 2:
    a = 100 * 100 * n
    if n == 100:
        a += 100 * 100

print(a)


Measured memory_bytes: 2940
import sys

N = int(input())
H = list(map(int,input().split()))
for i in reversed(range(N)):
	if i != 0:
		# print(i)
		# print(H[i-1],',',H[i])
		gap = H[i-1] - H[i]
		# print('gap:',gap)
		if gap <= 0:
			continue
		elif gap == 1:
			H[i-1] -= 1
		else:
			print('No')
			sys.exit()
	else:
		pass
print('Yes')

Measured memory_bytes: 14396
#include <iostream>
#include <string>
using namespace std;
 
int main() {
    string s;
    cin >> s;
    int counter = 0;
    if (s[0] == 'o') ++counter;
    if (s[1] == 'o') ++counter;
    if (s[2] == 'o') ++counter;
    cout << 700 + 100*counter << endl;
}

Measured memory_bytes: 256
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
T = []

for i in range(D):
    l = S[i].index(max(S[i]))
    T.append(l+1)
    
print(*T, sep="\n")

Measured memory_bytes: 9404
#! -*- coding:utf-8 -*-
n = int(input())
S = [''] * n
m = 51
for i in range(n):
    S[i] = list(str(input()))
    if m > len(S[i]):
        m = len(S[i])
arr = []
for i in range(len(S[0])):
    x = S[0][i]
    flag = 0
    count = 0
    for j in range(2,n):
        count += 1
        for k in range(len(S[j])):
            if S[j][k] == x:
                flag += 1
                S[j][k] = ''
                break
    if flag == count:
        arr.append(x)

arr.sort()
res = "".join(arr)
print(res)


Measured memory_bytes: 3064
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <math.h>
#include <iomanip>

using namespace std;

int main()
{
	int cnt = 0;
	string s;
	cin >> s;
	for (int i = 0; i < s.length(); i++) {
		cnt += (s[i] == 'o');
	}
	cout <<700 + cnt * 100 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef long double ld;

const int N = 100006;


int main() {

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

    int n;
    cin >> n;

    vector<int>  w(n + 6, 0), r(n + 6, 0);

    for(int i = 1; i <= n; i++) {

        char x;
        cin >> x;

        w[i] = w[i - 1] + (x == 'W');
        r[i] = r[i - 1] + (x == 'R');

    }
    
    // rrrrrwwwww

    int ans = 2e9;

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

        int l_red = r[i];
        int l_white = w[i];

        int r_red = r[n] - r[i];
        int r_white = w[n] - w[i];

        if (l_red == i) {
            ans = min(ans, r_red);
        } else {
            
            int mn = min(l_white, r_red);

            l_white -= mn;
            r_red -= mn;

            ans = min(ans, mn + l_white + r_red);
        }

    }

    cout << ans << '\n';
    return 0; 
}


Measured memory_bytes: 4772
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
#include<string>
#define ll long long
#define vl vector<ll> 
#define vvl vector<vector<ll> >
#define vb vector<bool> 
#define vvb vector<vector<bool> >
#define INF 1145141919810
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b:i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
using namespace std;

int main(){
	ll a,b,c; cin>>a>>b>>c;
	ll root_a=a;
	vb table(b,false);
	while(1){
		if(a % b ==c){
			cout<<"YES"<<endl;
			exit(0);
		}if(table[a%b]) break;
		table[a%b]=true;
		a+=root_a;
	}cout<<"NO"<<endl;
	return 0;
}

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

int main()
{
    int n;
    long long int ans=1;
    cin>>n;
    int x;
    long long int bb;
    bb=1;
    for(int i=0;i<n;i++){
        cin>>x;
        if(x%2==0)
            ans*=2LL;
        bb*=3LL;
    }
    cout<<bb-ans;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cctype>
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
using namespace std;

inline char gc() {
//	static char buf[100000],*p1,*p2;
//	return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
	return getchar();
}

template<class T>
int read(T &ans) {
	ans=0;char ch=gc();T f=1;
	while(!isdigit(ch)) {
		if(ch==EOF) return -1;
		if(ch=='-') f=-1;
		ch=gc();
	}
	while(isdigit(ch))
		ans=ans*10+ch-'0',ch=gc();
	ans*=f;return 1;
}

template<class T1,class T2>
int read(T1 &a,T2 &b) {
	return read(a)!=EOF&&read(b)!=EOF?2:EOF;
}

template<class T1,class T2,class T3>
int read(T1 &a,T2 &b,T3 &c) {
	return read(a,b)!=EOF&&read(c)!=EOF?3:EOF;
}

typedef long long ll;
const int Maxn=110000;
const int inf=0x3f3f3f3f;

int n,a[Maxn],b[Maxn],c[Maxn],f[Maxn][3];

signed main() {
//	freopen("test.in","r",stdin);
	read(n);
	for(int i=1;i<=n;i++) read(a[i],b[i],c[i]);
	for(int i=1;i<=n;i++) {
		f[i][0]=max(f[i-1][1],f[i-1][2])+a[i];
		f[i][1]=max(f[i-1][0],f[i-1][2])+b[i];
		f[i][2]=max(f[i-1][1],f[i-1][0])+c[i];
	}
	printf("%d\n",max(max(f[n][0],f[n][1]),f[n][2]));
	return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    ll p[A], q[B], r[C];
    rep(i, A) cin >> p[i];
    rep(i, B) cin >> q[i];
    rep(i, C) cin >> r[i];
    sort(p, p+A, greater<ll>());
    sort(q, q+B, greater<ll>());
    sort(r, r+C, greater<ll>());
    int a = X-1, b = Y-1, c = 0;
    ll sum = 0;
    rep(i, X) sum += p[i];
    rep(i, Y) sum += q[i];
    while((a >= 0 || b >= 0) && c <= C-1){
        if(a < 0){
            if(r[c] <= q[b]) break;
            sum += (r[c]-q[b]);
            c++, b--;
        }
        elif(b < 0){
            if(r[c] <= p[a]) break;
            sum += (r[c]-p[a]);
            c++, a--;
        }
        else{
            if(p[a] > q[b]){
                if(r[c] <= q[b]) break;
                sum += (r[c]-q[b]);
                c++, b--;
            }
            else{
                if(r[c] <= p[a]) break;
                sum += (r[c]-p[a]);
                c++, a--;
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 2560
/*
17/10/2017
*/
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
string s,t;
cin>>s>>t;
int ans=mod;
for(int i=0;i+t.length()<=s.length();i++)
{
int cnt=0;
for(int o=0;o<t.length();o++)
{
if(s[o+i]!=t[o])
{
cnt++;
}
}
ans=min(ans,cnt);
}
cout<<ans;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h> 
#include <boost/multiprecision/cpp_int.hpp> 
using boost::multiprecision::cpp_int; 
using namespace std;
int main(){
cpp_int j,x=1,mod=1000000000000000000;
long long i,n;
bool ok=0;
  cin>>n;
for(i=0;i<n;i++){
    cin>>j;
    if(x==0)continue;
    if(j==0){
        x=0;
    }
    if(x>=1)x*=j;
    if(x>=1 && x>mod){
        x=-1;
    }
}
cout<<x<<"\n";
}

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

int main(){
	int H,W;
	vector<vector<char>> frame(102,vector<char>(102));
	cin >> H >> W;

	for(int i=0; i<=W+1; i++){
		frame.at(0).at(i)='#';
		frame.at(H+1).at(i)='#';
	}
	for(int i=0; i<=H+1; i++){
		frame.at(i).at(0)='#';
		frame.at(i).at(W+1)='#';
	}


	for(int i=1; i<=H; i++)
		for(int j=1; j<=W; j++){
			cin >> frame.at(i).at(j);
		}

	for(int i=0; i<=H+1; i++){
		for(int j=0; j<=W+1; j++){
			cout << frame.at(i).at(j);
		}cout << endl;
	}


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
// chctxdy
ll a, b, c, d, k;
bool check(ll mid){
	ll na = mid, nb = max(0LL, (na - 1) / k);
	if (b - nb <= (a - na + 1) * k) return true;
	else return false; 
}
ll bs(){
	ll l = 0, r = a + 1;
	// real answer is always < r 
	// and >= l
	while (l + 1 < r){
		ll mid = (l + r) / 2;
		if (check(mid)) l = mid; // since na >= mid
		else r = mid; // since na < mid
	}
	return l;
}
int main(){
	ll q; cin >> q;
	while (q--){
		cin >> a >> b >> c >> d;
		k = (max(a, b) - 1) / (min(a, b) + 1) + 1;
		ll rna = bs(), rnb = max(0LL, (rna - 1) / k);
		// now that we have found the amount of a and b in the prefix
		ll fp = rna + rnb;
		string ans;
		for (ll i = c; i <= d; i++){
			// case 1: i belongs to the first part. (i <= fp)
			if (i <= fp){
				// i = 'B' if i modulo (k + 1) = 0, else i = 'A'.
				if (i % (k + 1) == 0) ans.pb('B');
				else ans.pb('A');
			}
			// case 2: ... otherwise
			else{
				// real value of i in respective to parts
				ll ri = (a + b) - i + 1;
				if (ri % (k + 1) == 0) ans.pb('A');
				else ans.pb('B');
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const long mod=998244353;
/*ll comb(int n,int r)
{
	ll p=1,q=1,m;
	if(n-r<r)
		r=n-r;
	while(r)
	{
		p*=n;
		q*=r;
		m=__gcd(p,q);
		p/=m;
		q/=m;
		n--;r--;
	}
	return p;
}
*/
/*int checkpermute(string s1,string s2)
{
	int n=s1.length(),i;
	vector <int> a1(26,0),a2(26,0);
	for(i=0;i<n;i++)
	{
		a1[s1[i]-'a']++;
		a2[s2[i]-'a']++;
	}
	for(i=0;i<26;i++)
		if(a1[i]!=a2[i])
			return 0;
	return 1;
}*/
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
	t=1;
    while(t--)
	{
		ll n;
		cin>>n;
		ll ne=floor(sqrt(n));
		cout<<ne*ne;
	}
    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = list(input())
 
# N=O(10^5)なのでO(N)で解く
# 連続する同じ文字を1つのグループと見るときに、何グループできるか？
# 文字が変化する点に着目すればよい。するとグループ数は（変化点+1）個と求まる！
 
ans = 1
for i in range(N-1):
  if S[i] != S[i+1]: ans += 1

print(ans)

Measured memory_bytes: 9780
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<ll> a(3*n);
	ll ans = -1e18;
	for(int i = 0; i<3*n; i++)
		cin>>a[i];
	priority_queue<ll> pq1;
	priority_queue<ll, vector<ll> , greater<ll> > pq2;
	ll sum1[n+1],ans1=0;
	for(int i = 0 ;i<2*n; i++)
	{
		pq2.push(a[i]);
		ans1 += a[i];
		if(i==n-1)
			sum1[0] = ans1;
		else if(i>n-1)
		{
			ans1-= pq2.top();
			sum1[i-n+1] = ans1;
			pq2.pop();
		}
	}
	ans1 = 0;
	for(int i = 3*n-1; i>=n; i--)
	{
		pq1.push(a[i]);
		ans1 += a[i];
		if(i==2*n)
			ans = max(ans,sum1[n]-ans1);
		else if(i<2*n)
		{
			ans1 -= pq1.top();
			ans = max(ans,sum1[i-n]-ans1);
			pq1.pop();
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) cin >> a[i];
	int start = 1;
	int count = 0;
	for (int i = 0; i < n; i++) {
		if (start != a[i]) count++;
		if (count > 2) {
			cout << "NO" << '\n';
			return 0;
		}
		start++;
	}
	cout << "YES" << '\n';
	return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  int q;
  cin >> q;
  while(q--) {
    int b, e, t;
    cin >> b >> e >> t;
    swap_ranges(a.begin()+b, a.begin()+e, a.begin()+t);
  }
  for(int i = 0; i < n; ++i) cout << a[i] << " \n"[i==n-1];
  return 0;
}



Measured memory_bytes: 3052
n, x = map(int, input().split())
a = list(map(int,input().split()))

cnt = 0
if a[0] > x:
    cnt +=a[0]-x
    a[0] = x

for i in range(n-1):
    if a[i]+a[i+1]>x:
        cnt+=a[i+1]-(x-a[i])
        a[i+1]=x-a[i]
print(cnt)


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

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

  string S; cin >> S;
  int N = S.size();
  int g = 0, p = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'g') g++;
    else p++;
  }
  ll ans = max((g - p) / 2, 0);
  cout << ans << '\n';
  return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using tsii = tuple<string, int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll n,x,ans=1;
    cin>>n>>x;
    vector<ll> l(n);
    for (int i = 0; i < n; i++)
    {
        cin>>l[i];
    }
    ll now =0;
    for (int i = 0; i < n; i++)
    {
        now+=l[i];
        if(now<=x) ans++;
    }
    
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n,m;cin>>n>>m;
    ll a[n];
    vector<ll> v;
    rep(i,0,n){
        cin>>a[i];
        v.push_back(a[i]);
    }
    sort(v.begin(),v.end());
    ll u=200001,d=0;
    while(u-d>1){
        ll mid=(u+d)/2;
        ll sum=0;
        rep(i,0,v.size()){
            ll t=mid-v[i];
            ll y=lower_bound(v.begin(),v.end(),t)-v.begin();
            sum+=n-y;
        }
        if(sum>=m)d=mid;
        else u=mid;
    }
   // cout<<d<<endl;
    ll ans=0;
    ll sum[n+1];
    sum[0]=0;
    rep(i,0,n)sum[i+1]=sum[i]+v[i];
    ll summ=0;
    rep(i,0,v.size()){
        ll t=d-v[i];
        ll y=lower_bound(v.begin(),v.end(),t)-v.begin();
        ans+=sum[n]-sum[y];
        ans+=v[i]*(n-y);
        summ+=n-y;
    }
    ans-=(summ-m)*d;
    cout<<ans<<endl;
}


Measured memory_bytes: 2676
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  ll ans=1;
  V<ll> v(n);
  rep(i,0,n)cin>>v[i];
  sort(all(v));

  rep(i,0,n){
    ll x=v[i];
    if(log10(ans)+log10(x)>18){
      cout<<-1<<ENDL;
      return 0;
    }
    ans*=x;
  }
  if(ans<=1000000000000000000)cout<<ans<<ENDL;
  else cout<<-1<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 4028
#include <cstdio>
 
int N, M;
int t[21][21];
 
int main() {
  while (true) {
    scanf("%d", &N);
    if (N == 0) break;
    for (int i=0;i<=20;i++) {
      for (int j=0;j<=20;j++) t[i][j] = 0;
    }
    for (int i=0;i<N;i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      t[x][y]++;
    }
    scanf("%d", &M);
    int rx = 10, ry = 10;
    for (int i=0;i<M;i++) {
      char d;
      int  l;
      scanf(" %c %d", &d, &l);
      for (int j=0;j<l;j++) {
        switch (d) {
        case 'N': ry++; break;
        case 'E': rx++; break;
        case 'S': ry--; break;
        case 'W': rx--; break;
        }
        N -= t[rx][ry];
        t[rx][ry] = 0;
      }
    }
    if (N == 0) puts("Yes");
    else puts("No");
  }
  return 0;
}


Measured memory_bytes: 2568
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b){
        if(b!=c){
            cout << "Yes";
            return 0;
        }
    }
    else if(a==c){
        if(c!=b){
            cout << "Yes";
            return 0;
        }
    }
    else if(b == c){
        if(c!=a){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";

    return 0;
}

Measured memory_bytes: 3640
/*	MASTER HAS FAILED MORE TIMES
	THAN BEGINNER HAS EVER TRIED
*/

#include <bits/stdc++.h>

using namespace std;

#define endl             '\n'
#define all(a)           a.begin(), a.end()
#define mem(a, n)        memset(a, n, sizeof(a))
#define Unique(n)        (n).erase(unique(all(n)), (n).end())
#define NumofDigits(n)   ((long long)log10(n)+1)
#define repeat(i, a, n)  for(int i=a; i<n; i++)
#define isPowerOfTwo(n)  (n && !(n & (n - 1)))

typedef long long ll;
typedef long double ld;

int sieve(int n);
unsigned long long pow(long long base, long long power);
long long gcd(long long a, long long b){ return a%b ? gcd(b, a%b) : b; }
long long lcm(long long a, long long b){ return a*b/gcd(a, b); }

void quicken(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
void file(){
#ifdef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif /*ONLINE_JUDGE*/
}

int main(){
    quicken();

    int n; cin >> n;
    ll arr[n];
    map<ll, ll> mp;
    set<ll> st;
    repeat(i, 0, n)
        cin >> arr[i], mp[arr[i]]++, st.insert(arr[i]);

    ll all = 0;
    for(auto &it:st)
        all += mp[it]*(mp[it]-1)/2;

    repeat(i, 0, n)
        if(mp[arr[i]]>1){
            cout << all - mp[arr[i]]*(mp[arr[i]]-1)/2 + (mp[arr[i]]-1)*(mp[arr[i]]-2)/2;
            cout << '\n';
        }else cout << all << endl;

    return 0;
}

unsigned long long pow(long long base, long long power){  /// mod?
    if(power==0)
        return 1;
    if(power==1)
        return base;

    unsigned long long ans = pow(base, power/2); /// mod?
    ans *= ans; /// ((ans%mod)*(ans%mod))%mod;

    if(power&1)
        return ans*base; /// ((ans%mod)*(base%mod))%mod;
    return ans;
}

int sieve(int n){
    int c = 0;
    vector<bool> isPrime(n+1, true);
    isPrime[0] = isPrime[1] = 0;

    for(long long i=2; i*i<=n; i++)
        if(isPrime[i])
            for(long long j=i*2; j<=n; j+=i)
                isPrime[j] = 0;
    repeat(i, 0, n+1)
    if(isPrime[i])
        c++;
    return c; /// primeCount [1:n]
}


Measured memory_bytes: 17024
import java.util.*;
public class Main{
    static long[] dp = new long[1000000];
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Arrays.fill(dp, Long.MAX_VALUE);
        dp[0] = 0;
        
        int n = sc.nextInt();
        int k = sc.nextInt();
        int h[] = new int[n+100];

        for(int i=0; i<n; i++) h[i] = sc.nextInt();

        dp[1] = Math.abs(h[0]-h[1]);
        for(int i=0; i<n; i++){
            for(int j=1; j<=k; j++)
            dp[i+j] = Math.min(dp[i+j],dp[i]+Math.abs(h[i]-h[i+j]));
        }
        System.out.println(dp[n-1]);
        
    }
    
}


Measured memory_bytes: 68992
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
string s;
ll ans[100010] = {0};
ll l, r = 0;
int main(){
    cin >> s;
    while(s[l] == 'R')l++;
 
    rep(i, s.size()){
        if(s[i] == 'R'){
            while(s[l] == 'R' || l < i)l++;
            r = i;
            ll dis = l - i;
            if(dis%2 == 0)ans[l]++;
            else ans[l-1]++;
        }
        else {
            ll dis = i - r;
            if(dis%2 == 0)ans[r]++;
            else ans[r+1]++;
        }
    }
    rep(i, s.size()) cout << ans[i] << " ";
}

Measured memory_bytes: 1408
def combs_mod(n,k,mod):
  #nC0からnCkまで
  inv = [1]*(k+1)
  for i in range(1,k+1):
    inv[i] = pow(i,mod-2,mod)
  ans = [1]*(k+1)
  for i in range(1,k+1):
    ans[i] = ans[i-1]*(n+1-i)*inv[i]%mod
  return ans

def solve():
  ans = 0
  mod = 998244353
  N, M, K = map(int, input().split())
  lis = combs_mod(N-1,K,mod)
  for i in range(K+1):
    ans += M*lis[i]*pow(M-1,N-1-i,mod)
    ans %= mod
  return ans
print(solve())

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

int main() {
  int H,W;
  cin >> H >> W;
  
  vector<string> temp(H);
  vector<vector<char>> data(H, vector<char>(W));
  vector<int> flag_h(H,0);
  vector<int> flag_w(W,0);
  
  for(int i=0;i<H;i++){
    cin >> temp.at(i);
    for(int j=0;j<W;j++){
      data.at(i).at(j) = temp.at(i).at(j);
      if(temp.at(i).at(j)=='#'){
        flag_h.at(i) = 1;
      }
    }
  }
  for(int i=0;i<W;i++){
    for(int j=0;j<H;j++){
      if(temp.at(j).at(i)=='#'){
        flag_w.at(i) = 1;
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(flag_h.at(i)==1 && flag_w.at(j)==1){
        cout << data.at(i).at(j) ;
      }
    }
    if(flag_h.at(i)==1){
      cout <<  endl;
    }
  }   


}

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

int getDigit(ll n){
    return to_string(n).length();
}

int main(){
    ll N;
    cin>>N;

    int min_digit=getDigit(N);

    for(ll i=1ll;i*i<=N;i++){
        if(N%i)continue;
        ll j=N/i;
        int cur=max(getDigit(i),getDigit(j));

        if(min_digit>cur)min_digit=cur;
    }
    cout<<min_digit<<"\n";
    return 0;    
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map &:to_i
b = gets.split.map &:to_i

ans = 0
n.times{|i|
    ans += [a[i], b[i]].min
    b[i] -= [a[i], b[i]].min
    ans += [a[i+1], b[i]].min
    a[i+1] -= [a[i+1], b[i]].min
}
p ans

Measured memory_bytes: 21408
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String l1 = sc.next();
    String l2 = sc.next();
    String l3 = sc.next();
    System.out.println("" + l1.charAt(0) + l2.charAt(1) + l3.charAt(2));
  }
}

Measured memory_bytes: 23636
while True:
    n, m = map(int, input().split())
    if m == 0 and n == 0:
        break
    a = list(map(int, input().split()))
    ans = 0
    for i in range(n - 1):
        for j in range(i + 1, n):
            if m >= a[i] + a[j]:
                ans = max(ans, a[i] + a[j])
    if ans == 0:
        print("NONE")
    else:
        print(ans)


Measured memory_bytes: 5620
import fractions

def lcm(a, b):
    return (a * b) // fractions.gcd(a, b)

A, B, C, D = map(int, input().split())
n = B - A + 1
n -= (B // C) - ((A - 1) // C)
n -= (B // D) - ((A - 1) // D)
n += (B // lcm(C, D)) - ((A - 1) // lcm(C, D))
print(n)

Measured memory_bytes: 64012
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int arr[10];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,k;
    cin>>n>>k;
    for(int i=0;i<k;i++){
        int a;
        cin>>a;
        arr[a]=1;
    }
    int ans=0;
    for(ll i=n;;i++){
        ll l=i;
        while(l>0){
            int m=l%10;
            if(arr[m]==1){
                break;
            }
            l/=10;
            if(l==0){
                ans=1;
            }
        }
        if(ans==1){
            cout<<i;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;} 
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
    string s;
    cin >> s;
    if(s[5] == '0' && s[6] <= '4' && (s[8] < '3' || (s[8] == '3' && s[9] == '0'))) cout << "Heisei\n";
    else cout << "TBD\n"; 
    return 0;
}


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

#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define maxin(v) *max_element(v.begin(), v.end())
#define minin(v) *min_element(v.begin(), v.end())
#define sumall(vect) accumulate(vect.begin(), vect.end(), 0)
#define count(x, vect) count(vect.begin(), vect.end(), x)
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 100000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "------------------------------------\n"
#define min(a, b, c) min(a, min(b, c))
#define max(a, b, c) max(a, max(b, c))
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp;
string str;
set<ll> s;
vll v;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>a>>b>>n;
	if(a+b+n>=22)
	{
	    cout<<"bust";
	    
	}
	else
	cout<<"win";
}

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

using namespace std;
using ll = long long;
using lli = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vlli = vector<lli>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define all(v) v.begin(), v.end()
#define debug(x) cout << x << endl
#define vout(v) rep(i, v.size()) cout << v[i] << " ";

int A, B, M;

void solve(vi a, vi b, vi x, vi y, vi c) {
	int ans = 1000000;
	//割引券あり
	rep(i, M) { ans = min(ans, a[x[i] - 1] + b[y[i] - 1] - c[i]); }
	//割引券なし
	int minA = 1000000;
	rep(i, A) { minA = min(minA, a[i]); }
	int minB = 1000000;
	rep(i, B) { minB = min(minB, b[i]); }

	ans = min(ans, minA + minB);
	cout << ans;
}

int main() {
	cin >> A >> B >> M;

	vi a(A), b(B);
	vi x(M), y(M), c(M);
	rep(i, A) { cin >> a[i]; }
	rep(i, B) { cin >> b[i]; }
	rep(i, M) { cin >> x[i] >> y[i] >> c[i]; }

	solve(a, b, x, y, c);
	return 0;
}

Measured memory_bytes: 4224
import java.util.Scanner;

public final class Main {
        public static void main(String[] args) {
                Scanner s = new Scanner(System.in);
                int sx = s.nextInt();
                int sy = s.nextInt();
                int tx = s.nextInt();
                int ty = s.nextInt();

                int dx = tx-sx;
                int dy = ty-sy;

                boolean fx = dx > 0;
                boolean fy = dy > 0;

                // s to t
                if (fy) repeat ('U', dy);
                else repeat('D', dy);

                if (fx) repeat ('R', dx);
                else repeat('L', dx);

                // t to s
                if (fy) repeat ('D', dy);
                else repeat('U', dy);

                if (fx) repeat ('L', dx+1);
                else repeat('R', dx+1);

                // s to t again
                if (fy) repeat ('U', dy+1);
                else repeat('D', dy+1);

                if (fx) repeat ('R', dx+1);
                else repeat ('L', dx+1);
                if (fy) repeat ('D', 1);
                else repeat ('U', 1);

                // t to s again
                if (fx) repeat('R', 1);
                else repeat('L', 1);

                if (fy) repeat('D', dy+1);
                else repeat('U', dy+1);

                if (fx) repeat('L', dx+1);
                else repeat('R', dx+1);

                if (fy) repeat('U', 1);
                else repeat('D', 1);

                System.out.println();
        }

        public static void repeat(char c, int n) {
                for (int i=0; i<n; i++)
                        System.out.print(c);
        }
}


Measured memory_bytes: 28712
#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($( { splits.next().unwrap().parse::<$t>().unwrap() },)*)
    }}
}

#[allow(unused_macros)]
macro_rules! invec {
    ( $ t : ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s
                .trim()
                .split_whitespace()
                .map(|s| s.parse::<$t>().unwrap())
                .collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }};
}



#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, ) = input!(usize);
    let mut ls = invec!(u32);

    ls.sort();

    let mut l = 0;
    let mut r = 2;

    let mut total = 0;
    while l + 1 < r && r < n {
        for m in (l+1)..r {
            if ls[r] < ls[l] + ls[m] {
                total += r - m;
                break;
            }

        }
        r += 1;
        if r == n {
            l += 1;
            r = l + 2;
        }
    }

    println!("{}", total);
}

fn main() {
    solve();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
string s;
int zeronum=0,onenum=0;
int main(int argc,char const* argv[])
{
  cin >> s;
  for(int i=0;i<int(s.size());i++)
    {
      if(s[i]=='0') zeronum++;
      else if(s[i]=='1') onenum++;
    }
  cout << 2*min(zeronum,onenum) << endl;
  return 0;
}


Measured memory_bytes: 512
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


int main(){
    ll m,n;
    cin>>m>>n;
    vector<vector<pll>> A(n);
    vector<ll> com(m+1,0);
    for(int i=1;i<=m;i++){
        ll k;
        cin>>k; com[i]=k;
        for(int t=0;t<k;t++){
            ll ty,T;
            string s;
            cin>>ty>>s>>T;
            ty--;
            if(s[0]=='<'){
                com[i]--;
                A[ty].push_back({T,i});
            }
            else{
                if(T==0){com[i]--;}
                else{A[ty].push_back({T,-i});}
            }
        }
    }
    for(auto &I:A){sort(I.begin(),I.end(),greater<pll>());}
    bool j=true;
    while(j){
        j=false;
        for(int i=0;i<n;i++){
            while(!A[i].empty() && com[abs(A[i].back().S)]==0){A[i].pop_back();}
            while(!A[i].empty() && A[i].back().S<0){
                com[abs(A[i].back().S)]--;
                A[i].pop_back();
                j=true;
            }
        }
    }
    for(auto &I:com){
        if(I!=0){cout<<"No"<<endl; return 0;}
    }
    cout<<"Yes"<<endl;
    
    
    return 0;
}



Measured memory_bytes: 3256
N = int(input())
S = input()

tmp = 0

for s in S[1:]:
  if s == 'E':
    tmp += 1

rlt = tmp

for i in range(1,N):
  if S[i-1] == 'W':
    tmp += 1
  if S[i] == 'E':
    tmp -= 1
  if rlt > tmp:
    rlt = tmp
    
print(rlt)

Measured memory_bytes: 43232
#include<bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
using namespace atcoder;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll r,c;
  cin >>r >> c;

  char e[r+2][c+2];

  for(ll i=0;i<r+2;i++){
    for(ll j=0;j<c+2;j++){
      if( i==0 || i==r+1 || j==0 || j==c+1)e[i][j]='#';
      else cin >> e[i][j];
    }
  }

  // for(ll i=0;i<r+2;i++){
  //   for(ll j=0;j<c+2;j++)cout << e[i][j] ;
  //   cout << endl;
  // }

  ll ans=0;
  mf_graph<ll> g(r*c+2);
  vector<vector<bool>> G(r+2,vector<bool>(c+2,false));
  for(ll i=1;i<r+1;i++){
    for(ll j=1;j<c+1;j++){
      if(e[i][j]=='#')continue;
      if(G[i][j]==true)continue;
      mat d(r+2,vec(c+2,-1));
      d[i][j]=0;
      queue<vec> q;
      q.push({i,j});
      ll n=0;
      while(!q.empty()){
        vector<ll> v =q.front();
        q.pop();
        G[v[0]][v[1]]=1;
        n++;
        for(int i=0;i<4;i++){
          if(d[v[0]+dx[i]][v[1]+dy[i]]== -1 && e[v[0]+dx[i]][v[1]+dy[i]]=='.'){
            d[v[0]+dx[i]][v[1]+dy[i]]=d[v[0]][v[1]]+1;
            q.push({v[0]+dx[i],v[1]+dy[i]});
          }
        } 
      }

      for(ll i=1;i<r+1;i++){
        for(ll j=1;j<c+1;j++){
          if(d[i][j]==-1)continue;
          if(d[i][j]&1){
            g.add_edge(c*(i-1)+j,r*c+1,1);
          }
          else{
            g.add_edge(0,c*(i-1)+j,1);
            for(int k=0;k<4;k++){
              if(e[i+dx[k]][j+dy[k]]=='.'){
                g.add_edge(c*(i-1)+j,c*(i+dx[k]-1)+j+dy[k],1);
              }
            }
          }
        }
      }

      //cout << i << " " << j << endl;
    }
  }

  ans=g.flow(0,r*c+1);

  cout << ans << endl;

  auto E=g.edges();

  for(ll i=0;i<E.size();i++){
    ll a,b;
    a=E[i].from;
    b=E[i].to;
    if(a==0 || b==r*c+1 || E[i].flow==0)continue;
    ll a1,a2,b1,b2;
    a1=(a-1)/c+1;
    a2=a%c;
    if(a2==0)a2=c;
    b1=(b-1)/c+1;
    b2=b%c;
    if(b2==0)b2=c;
    if(a1==b1){
      if(a2<b2){
        e[a1][a2]='>';
        e[b1][b2]='<';
      }
      else{
        e[a1][a2]='<';
        e[b1][b2]='>';
      }
    }
    else{
      if(a1<b1){
        e[a1][a2]='v';
        e[b1][b2]='^';
      }
      else{
        e[a1][a2]='^';
        e[b1][b2]='v';
      }
    }
  }

  for(ll i=1;i<r+1;i++){
    for(ll j=1;j<c+1;j++)cout << e[i][j] ;
    cout << endl;
  }

}

Measured memory_bytes: 6260
/*input
1817181712114
*/
#include <bits/stdc++.h>
using namespace std; 
#define int long long int
#define max(x, y) ((x) > (y) ? (x) :(y))
#define pii pair< int , int> 
#define vi vector<int>
#define fore( i ,st) for ( int i= 0 ; i < (int)(st) ; i ++)
#define REP( i , st , en ) for ( int i =st; i < (int)en; i++)
#define REPD( i , en , st ) for ( int i =en; i >= (int)st; i--)
#define SZ(a) (int)a.size()
#define all(v) v.begin() , v.end()
#define pb push_back
#define F first
#define S second
#define bitch_i_m_on_fiyaah_yeahhhh ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

// const int mod = 998244353;
const int mod = 1e9+7;
ostream& operator << ( ostream&  o, vector<int> s){for ( int i = 0;  i < (int)s.size() ; i++)o << s[i] << " ";o << "\n";return o;}
void  add( int &a, int b){a = a + b;if ( a< 0 ) a += mod; if ( a> mod ) a-= mod;}
void sub( int &a, int b){a = a - b;if ( a < 0) a += mod;}
int mul( int a , int b){return ((a %mod) * (b %mod) ) %mod;}
int exp( int a , int pow){ return (pow == 0 ? 1 : ( pow & 1  ? mul ( a ,exp( mul(a, a) , pow /2) ) : exp(mul(a ,a) , pow/2)));}
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
// const int inf = 1e18;
const int maxn = 2e5 + 5;


void solve(int test ) 
{		
	string s;
	cin >> s;
	int n = s.size();
	int M=  2019;
	map<int , int > m;
	int sum =0;
	int pow =1;
	m[0] =1;
	int ans=0;
	for ( int i = n -1; i >= 0; i--){
		sum =(sum%M + ((s[i] - '0')*pow)%M)%M;
		pow = (pow%M * 10)%M;
		if ( m[sum] > 0) ans+=m[sum];
		m[sum]++;
		// cout << i << " " << sum << "\n";
	}
	cout<< ans;

}
signed main(){
	bitch_i_m_on_fiyaah_yeahhhh
	int t =1; 
	// cin >> t;
	for ( int i = 0 ; i < t; i++)
	solve(i+1 );
}

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

using namespace std;

int mon[100002], her[100001];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n + 1; ++i)
		scanf("%d", &mon[i]);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &her[i]);

	long long ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (mon[i] > her[i]) {
			ans += her[i];
			mon[i] -= her[i];
			her[i] = 0;
		}
		else {
			ans += mon[i];
			her[i] -= mon[i];
			mon[i] = 0;

			if (mon[i + 1] > her[i]) {
				ans += her[i];
				mon[i + 1] -= her[i];
				her[i] = 0;
			}
			else {
				ans += mon[i + 1];
				her[i] -= mon[i + 1];
				mon[i + 1] = 0;
			}
		}
	}

	printf("%lld", ans);

	return 0;
}

Measured memory_bytes: 1024
#import <stdio.h>
int main() {
        int n;
        scanf("%d", &n);
        for(int i=1;i<=9;i++){
           for(int j=1;j<=9;j++){
               if (i*j==n){
                   puts("Yes");
                   return 0;
               }
           }
        }
    puts("No");
    return 0;
}


Measured memory_bytes: 7504