akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>
#define LL long long
#define FOR(i,s,t) for (int i = (int)s; i < (int)t; ++i)
using namespace std;
const int maxn = 100010;

int n, li[maxn];
LL L, sum[maxn], c[maxn];

struct Num{
    LL a, b;
    bool operator < (const Num& rhs) const{
        return a-b > rhs.a-rhs.b;
    }
}s[maxn];

void Init() {
    LL ca = 0;
    int idx = 1;
    FOR(i, 2, n+1) {
        ca = ca+s[i].a-s[i].b-c[idx];
        if(ca <= 0) break;
        ++ idx;
    }
    li[1] = idx;
    FOR(i, 2, n+1) {
        if(i-1 > idx) {li[i] = idx; continue;}
        if(idx == n) {li[i] = n; continue;}
        ca += s[i-1].a-s[i-1].b+s[i].b-s[i].a;
        while(ca > 0 && idx < n) {
            ++ idx;
            ca += s[idx+1].a-s[idx+1].b-c[idx];
        }
        li[i] = idx;
    }
}

int ff = n+1;

bool judge(int x) {
    -- x;
    FOR(i, 1, n+1) {
        LL lim = L-s[i].a;
        if(li[i] <= x) continue;
        if(i > x && sum[x] >= lim)  return true;
        if(i <= x && sum[x+1]-s[i].a+s[i].b >= lim) return true;
    }
    return false;
}

int main() {
    while(~scanf("%d%lld", &n, &L)) {
        LL mx = -1;
        FOR(i, 1, n+1)
            scanf("%lld%lld", &s[i].a, &s[i].b),
            mx = max(mx, s[i].a);
        s[n+1].a = s[n+1].b = 0;
        FOR(i, 1 ,n+1) scanf("%lld", c+i);
        if(mx >= L) {printf("1\n"); continue;}
        sort(s+1, s+n+1);
        ff = n;
        FOR(i, 1, n+1) if(s[i].a <= s[i].b) {ff = i; break;}
        sum[0] = 0;
        FOR(i, 1, n+1) sum[i] = sum[i-1]+s[i].a-s[i].b;
        Init();
        int l = 1, r = ff;
        if(l > r) {printf("-1\n"); continue;}
        while(l < r) {
            int mid = (l+r) >> 1;
            if(judge(mid))  r = mid;
            else    l = mid+1;
        }
        if(judge(l))    printf("%d\n", l);
        else    printf("-1\n");
    }
    return 0;
}

Measured memory_bytes: 6800
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <string>
#include <list>

using namespace std;

#define CVector CPoint
typedef long long LL;
typedef unsigned long long ULL;

const LL mod=1e9+7;
const double PI=acos(-1);
const long double EPS=1e-6;
const int INF=0x3f3f3f3f;

inline int readint(){
  int sum=0;char c=getchar();bool f=0;
  while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
  while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}
  if(f) return -sum;
  return sum;
}

inline LL readLL(){
  LL sum=0;char c=getchar();bool f=0;
  while(c<'0'||c>'9'){if(c=='-') f=1;c=getchar();}
  while(c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}
  if(f) return -sum;
  return sum;
}


char a[105];

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>a;
    int ans=INF;
    int l=strlen(a);
    int tmp;
    for(int i=0;i<26;i++){
        a[l]='a'+i;
        tmp=0;
        int cnt=0;
        for(int j=0;j<=l;j++){
            if(a[j]=='a'+i){
                tmp=max(tmp,cnt);
                cnt=0;
            }else{
                cnt++;
            }
        }
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}

//cout.setf(ios::fixed);
//cout<<fixed<<setprecision(10)<<s<<endl;


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    int N = Integer.parseInt(scanner.next());
	    int[] A = new int[N];

	    for (int i = 0; i < N; i++) {
	        A[i] = Integer.parseInt(scanner.next());
	    }

	    int allXor = 0;

	    for (int i = 0; i < A.length; i++) {
	        allXor = allXor^A[i];
	    }

	    A[0] = A[0]^allXor;
	    System.out.print(A[0]);
	    for (int i = 1; i < N; i++) {
		    System.out.print(" ");
		    A[i] = A[i]^allXor;
		    System.out.print(A[i]);
	    }
	}
}

Measured memory_bytes: 60896
import bisect

n = int(input())
u = list(map(int,input().split()))
m = list(map(int,input().split()))
d = list(map(int,input().split()))
u.sort()
m.sort()
d.sort()

ans = 0
for a in m:
    ans += bisect.bisect_left(u,a) * (n - bisect.bisect_right(d,a))
print(ans)

Measured memory_bytes: 23328
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

//高速な素因数分解O(logN)
template<typename T>
vector<T> sieve(T n){//n以下の整数について最小の素因数を調べる
    vector<T>prime(n+1);
		for(int i=0;i<=n;++i)prime[i]=i;
    for(int i=2;i*i<=n;i++){
        if(prime[i]<i)continue;
				for(int j=i*i;j<=n;j+=i){
					if(prime[j]>=i)prime[j]=i;
				}
    }
    return prime;
}

template<typename T>
vector<pair<T,int>> osa_k(T n,const vector<T>& min_factor){//min_factorはsieveで求めた配列を使う
  vector<pair<T,int>> ret;
  while(n>1){
		int cnt=0;
		T value=min_factor[n];
		while(value==min_factor[n]){
			n/=min_factor[n];
			++cnt;
		}
		ret.emplace_back(value,cnt);
	}
  return ret;
}

void solve()
{
	ll n;
	cin>>n;
	ll ans=0;
	auto s=sieve(n);
	REP(i,1,n+1){
		ll cul=1;
		for(auto x:osa_k((ll)i,s)){
			cul*=x.second+1;
		}
		ans+=cul*i;
	}
	cout<<ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 81344
//Md Fahad
// CSE 18

#include<bits/stdc++.h>

using  namespace  std;

#define PI              acos(-1.0)
#define lcm(a,b)        (a * (b / __gcd(a,b)))
#define en '\n'

#define READ_IN freopen("Input.txt","r",stdin);
#define READ_OUT freopen("Output.txt","w",stdout);
#define Infi                0x3f3f3f3f

const int fx[] = {+1,-1,+0,+0};                         // 4 X directions
const int fy[] = {+0,+0,+1,-1};                         // 4 Y directions
const int fx8[] = {+0,+0,+1,-1,-1,+1,-1,+1};            // King X Moves
const int fy8[] = {-1,+1,+0,+0,+1,+1,-1,-1};            // King Y Moves
const int kx[] = {-2, -2, -1, -1,  1,  1,  2,  2};      // Knight X Moves
const int ky[] = {-1,  1, -2,  2, -2,  2, -1,  1};      // Knight Y Moves



int  Set    (int N,int pos) {return N=N | (1<<pos);}    /// turn a bit on
int  reset  (int N,int pos) {return N= N & ~(1<<pos);}  /// turn a bit off
bool check  (int N,int pos) {return (bool)(N & (1<<pos));} /// check, if a bit is on or not

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define trace(x...)
#endif

typedef long long int           ll;
typedef unsigned long long int  llu;





int main(void)
{
    //READ_IN;
    //READ_OUT;

    int h,n;
    cin >> h >> n;
    ll sum =0;
    for(int i=0;i<n;i++)
    {
        int x;
        cin >> x;
        sum+=x;
    }

    if(sum>=h)
        cout << "Yes" << endl;
    else
        cout <<"No" << endl;

    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
             
public class Program
{
    public static void Main(string[] args)
    {
        new Program().Solve(new ConsoleInput(Console.In, ' '));
    }

    public void Solve(ConsoleInput cin)
    {
        int N =cin.ReadInt;
        int H = cin.ReadInt;
        int W = cin.ReadInt;
        Console.WriteLine((N - H + 1) * (N - W + 1));
    }
}

public class ConsoleInput
{
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
constexpr char newl = '\n';

constexpr int None = 1 << 30;

constexpr int h = 17;
constexpr int MaxN = 1 << h;
int n, q;

int dat[MaxN*2], laz[MaxN*2];

void apply(int p, int x, int i) {
  dat[p] = x << i;
  laz[p] = x;
}

void flush(int p) {
  repr(i, h) {
    int q = p >> i+1;
    if (laz[q] != None) {
      apply(q<<1, laz[q], i);
      apply(q<<1|1, laz[q], i);
      laz[q] = None;
    }
  }
}

void build(int p) {
  rep(i, h) {
    int q = p >> i+1;
    dat[q] = laz[q] != None ? laz[q] << i+1 : dat[q<<1] + dat[q<<1|1];
  }
}

int main() {
  cin >> n >> q;
  fill(laz, laz+MaxN*2, None);
  rep(_, q) {
    int c, s, t; cin >> c >> s >> t;
    if (c == 0) {
      int x; cin >> x;
      flush(s += MaxN); flush(t += MaxN);
      int s0 = s, t0 = t, i;
      for (i = 0, t++; s < t; s >>= 1, t >>= 1, i++) {
        if (s&1) apply(s++, x, i);
        if (t&1) apply(--t, x, i);
      }
      build(s0); build(t0);
    } else {
      flush(s += MaxN); flush(t += MaxN);
      int res = 0;
      for (t++; s < t; s >>= 1, t >>= 1) {
        if (s&1) res += dat[s++];
        if (t&1) res += dat[--t];
      }
      cout << res << newl;
    }
  }
}


Measured memory_bytes: 4924
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

string s;
ll ans=0;
ll sum[100010];
ll N,M;
int main() {
	cin>>N>>M;
	cin>>s;
	REP(i,1,s.size()){
		sum[i+1] = sum[i] + (s[i-1]=='A'&&s[i]=='C');
	}
	REP(i,0,M){
		ll l,r;
		cin>>l>>r;
		p(sum[r]-sum[l]);
	}

	return 0;
}


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

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

  //答を出すために配列を利用する
  vector<string> s(10);

  s[0] = "pon";
  s[1] = "pon";
  s[2] = "hon";
  s[3] = "bon";
  s[4] = "hon";
  s[5] = "hon";
  s[6] = "pon";
  s[7] = "hon";
  s[8] = "pon";
  s[9] = "hon";

  cout << s[n%10] << endl;
}


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

int main()
{
    int k, a, b, c, d;
    cin >> k >> a >> b;
    if(a%k==0 or b%k==0)cout << "OK";
    else
    {
        c=(a/k+1)*k, d=(b/k)*k;
        if(c<b or d>a)cout << "OK";
        else  cout << "NG";
    }
}


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

int main()
{
    int A[4];
    string input;
    cin >> input;
    for (int i = 0; i < 4; i++)
    {
        A[i] = input[i] - '0';
    }
    for (int i = 0; i < 8; i++)
    {
        int sum = 0;
        for (int j = 0; j < 4; j++)
        {
            if (j == 0 || i & 1 << (j - 1))
            {
                sum += A[j];
            }
            else
            {
                sum -= A[j];
            }
        }
        if (sum == 7)
        {
            for (int j = 0; j < 4; j++)
            {
                if (j >= 1)
                {
                    cout << ((i & 1 << (j - 1)) ? "+" : "-");
                }
                cout << A[j];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
    cout << "error" << endl;
}

Measured memory_bytes: 256
import sys
K = int(input())

DP = [[0] * 10 for _ in range(11)]

for i in range(10):
    DP[1][i] = 1

for j in range(2, 11):
    for i in range(10):
        if i == 0:
            DP[j][i] = DP[j-1][0] + DP[j-1][1]
        elif i == 9:
            DP[j][i] = DP[j-1][8] + DP[j-1][9]
        else:
            DP[j][i] = DP[j-1][i-1] + DP[j-1][i] + DP[j-1][i+1]

total = 0

ans = []

# j桁目がk


def dfs(j, k):
    global ans
    global total
    if j == 0:
        print(int("".join(ans)))
        sys.exit(0)

    if k == 0:
        kList = [0, 1]
    elif k == 9:
        kList = [8, 9]
    else:
        kList = [k-1, k, k+1]

    for i in kList:
        if total + DP[j][i] >= K:
            ans.append(str(i))
            dfs(j-1, i)
        else:
            total += DP[j][i]


for j in range(1, 11):
    for i in range(1, 10):
        if total + DP[j][i] >= K:
            ans.append(str(i))
            dfs(j-1, i)
        else:
            total += DP[j][i]


Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl '\n'
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld pi=3.141592653589793238;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll A;
    cin >> A;
    ll B;
    cin >> B;
    prt((A)*(B))

    return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<limits>
#include<deque>
#include<string>
#include<map>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>

using namespace std;

int main(){
	int n; cin >> n;
	int a;
	map<int, int> mp;

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

	int sum = 0;
	int check = 0;

	for (pair<int, int>x : mp) {
		if (x.second % 2 == 0) { check++; }
		sum++;
	}

	if (check % 2 == 1) { cout << sum - 1 << endl; }
	else { cout << sum << endl; }

	return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;

i64 h,w, block1, block2, block3;
/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    cin >> h >> w;

    /** two way to divide
     * 1.
     *      h*p | q*(w-p) | (h-q)*(w-p)
     *
     * 2.
     *      w*p | q*(h-p) | (w-q)*(h-p)
     *
     * まずでかい二つに分割する。次にでかい方を二つに分割する。
     * この時に最初の分割で得られたものに近くなるよう狙って探索する
     * 最初の分割も狙っていいw/4 <= p <= w/2のみ探す
     */

    i64 minDif = infll;
    // ver.1
    for(i32 p = max((i64)1, w/4); p <= w/2; ++p) {
        block1 = h*p;
        i64 nw = w-p;
        block2 = h*(nw/2);
        block3 = h*(nw - nw/2);
        chmin(minDif, abs(max({block1,block2,block3}) - min({block1,block2,block3})));
        block2 = nw*(h-h/2);
        block3 = nw*(h/2);
        chmin(minDif, abs(max({block1,block2,block3}) - min({block1,block2,block3})));
    }
    // ver.2
    for(i32 p = max((i64)1, h/4); p <= h/2; ++p) {
        block1 = w*p;
        i64 nh = h-p;
        block2 = w*(nh/2);
        block3 = w*(nh-nh/2);
        chmin(minDif, abs(max({block1,block2,block3}) - min({block1,block2,block3})));
        block2 = nh*(w/2);
        block3 = nh*(w-w/2);
        chmin(minDif, abs(max({block1,block2,block3}) - min({block1,block2,block3})));
    }

    cout << minDif << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h> //EXIT_FAILURE
#include <assert.h>

int main(){
	int x,k,ret;
	if((ret = scanf("%d %d",&k,&x))== EOF){
		return EXIT_FAILURE;
	}
	assert(1<= k && k <=100);
	assert(1 <= x && x <=100000);
	
	if(500*k >= x){printf("Yes\n");}
	else{printf("No\n");}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ordered_set<ll> ors;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ld PI=3.14159265359;

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll invmod(ll a, ll m)
{
    return power(a,m-2,m);
}

ll lp[100001];
vector<ll> pr;

void prime()
{
    repf(i,1,100001) lp[i]=i;
    repf(i,2,100001)
    {
        if(lp[i]==i)
        {
            for(ll j=2*i;j<100001;j+=i)
            {
                if(lp[j]==j) lp[j]=i;
            }
        }
    }
    repf(i,2,100001) if(lp[i]==i) pr.pb(i);
}


void solve(ll tt) {
    ll n;
    cin>>n;
    ll a[n],b[n],id[n];
    repf(i,0,n) cin>>a[i];
    repf(i,0,n) cin>>b[i];
    repf(i,0,n) {
        id[i]=upper_bound(b,b+n,a[i])-b;
        if(i) id[i]=max(id[i],id[i-1]+1);
    }
    repb(i,n-2,0) {
        id[i]=max(id[i],id[i+1]-1);
    }
    repf(i,0,n) if(a[i]==b[id[i]%n]) {
        cout<<"No\n";
        return;
    }
    cout<<"Yes\n";
    repf(i,0,n) cout<<b[id[i]%n]<<" ";
    cout<<endl;
} 


int main()
{
    IOS;
    prime();
    ll t=1;
    // cin>>t;
    repf(tt,1,t+1) {
        solve(tt);
    }
}     

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

using namespace std;

int n;
int f[100010];
char ch[200010], conv[200010];
int ans = 0;
const int MOD = 1e9 + 7;

int mul(long long a, long long b){
    return (a * b) % MOD;
}

int main(){
    scanf("%d", &n);

    f[0] = 1;
    for(int i = 1; i <= n; i++) f[i] = mul(f[i - 1], i);

    scanf(" %s", ch);
    
    int val = 0;

    ans = 1;
    for(int i = 0; i < 2 * n; i++){
        if(val & 1){
            if(ch[i] == 'W') conv[i] = 'L';
            else conv[i] = 'R';
        } else {
            if(ch[i] == 'W') conv[i] = 'R';
            else conv[i] = 'L';
        }

        if(conv[i] == 'L') val++;
        else ans = mul(ans, val), val--;

        if(val < 0) break;
    }

    if(val != 0) ans = 0;

    printf("%d\n", mul(ans, f[n]));
    
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pii;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;
ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b,a % b);}
struct cmp
{
	bool operator()(const pii & a, const pii & b)
	{
		return a.second > b.second;
	}
};
const ll mod = 23333333333333333;
const int maxn = 1e5+5;

int main()
{
	ll n;
	scanf("%lld",&n);
	ll s = 100;
	int k = 0;
	while (s < n)
	{
		s += s / 100;
		k ++ ;
	}
	printf("%d\n",k);
}

Measured memory_bytes: 3224
/*  ex7_1
    L40S38  */

#include <stdio.h>

typedef struct point{
    int x_elem;
    int y_elem;
}point;

point rot1(point* top, point* base){//baseを中心にtopを-90度回転
    //printf("rot\n");
    point p, dif;
    dif.x_elem=(top->x_elem-base->x_elem);
    dif.y_elem=(top->y_elem-base->y_elem);
    p.x_elem=dif.y_elem+base->x_elem;
    p.y_elem=-dif.x_elem+base->y_elem;
    return p;
};
point rot2(point* top, point* base){//baseを中心にtopを90度回転
    //printf("rot\n");
    point p, dif;
    dif.x_elem=(top->x_elem-base->x_elem);
    dif.y_elem=(top->y_elem-base->y_elem);
    p.x_elem=-dif.y_elem+base->x_elem;
    p.y_elem=dif.x_elem+base->y_elem;
    return p;
};

int main(void){
    int i;
    point square[4];
    //square[i]:問題文における(x_i+1,y_i+1)のpointのこと
    for(i=0;i<2;i++){
        scanf(" %d %d",&square[i].x_elem,&square[i].y_elem);
    }
    
    //square[2]の計算・出力
    square[2]=rot1(&square[0],&square[1]);
    printf("%d %d ",square[2].x_elem,square[2].y_elem);
    
    //square[3]の計算・出力
    square[3]=rot2(&square[1],&square[0]);
    printf("%d %d",square[3].x_elem,square[3].y_elem);
    return 0;
}

Measured memory_bytes: 1672
#define rep(i,N) for (int i = 0; i < N; i++)

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

int main(){
        int N,X;
        int m[100];
        int minn = 2000;
        int sum = 0;
        cin >> N >> X;
        rep(i,N) cin >> m[i];
        rep(i,N) minn = min(minn,m[i]);
        rep(i,N) sum += m[i];
        cout << (X-sum)/minn + N << endl;

        return 0;
}


Measured memory_bytes: 256
# include<stdio.h>
# include<math.h>

long long int Isp(long long int n)
{
    long long int i,flag=0;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0)
           {
               flag=1;
               break;
           }
    }
    if(flag==0)
        return 1;
    else
        return 0;
}
int main(void)
{
    long long int n,i,max=1;
    scanf("%lld",&n);
    if(Isp(n)==1)
        printf("%lld",n-1);
    else{
        for(i=2;i<=sqrt(n);i++)
            if(n%i==0&&i>max)
                max=i;
        printf("%lld",max+n/max-2);
    }
    return 0;


}




Measured memory_bytes: 128
#include <bits/stdc++.h>
    
using namespace std;
typedef long long ll;
    
int main()
{
    int a, b;
    cin >> a >> b;
    int diff = b - a;

    int count = 0;
    for (int i = 1; i <= diff; i++) {
        count += i;
    }
    // cout << count << "\n";

    cout << count - b;
    
    return 0;
}

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

template<typename T>
struct CumSum{
private:
  size_t size;
  vector<T> data;
public:
  CumSum(vector<T> dat){
    size = dat.size();
    data.resize(size+1,0);
    for(size_t i = 0; i < size; ++i)
      data[i+1] = data[i] + dat[i];
  }
  T getsum(size_t l, size_t r){//0-indexed, [l,r)
    assert(l <= r);
    return data[r] - data[l];
  }
  T getsum(size_t r){//0-indexed, [0,r)
    return data[r];
  }
};

int main(){
  long long N, M, V, P;
  cin >> N >> M >> V >> P;
  vector<long long> A(N);
  for(int i = 0; i < N; ++i)
    cin >> A[i];
  sort(A.begin(), A.end());

  CumSum<long long> cs(A);
  {
    for(auto  a : A)
      cerr << a << " ";
    cerr << endl;
  }
  for(int i = 0; i < P-1; ++i){
    A[N-1-i] += M;
  }
  int ans = P;
  for(int i = 0; i < N-P; ++i){
    long long r = M*V - (i+1)*M;
    r -= (P-1)*M;
    long long k = V - i - 1 - (P-1);
    int cnt = A.end() - upper_bound(A.begin(), A.end(), A[i]+M);
    if(cnt >= P) continue;
    if(k > 0){
      int jj = lower_bound(A.begin(), A.end(), A[i]+M) - A.begin();
      int d = jj-i-1;
      long long x = d*(A[i]+M) - cs.getsum(i+1,jj);
      // cerr << i << ", " << x << endl;
      r -= x;
    }
    // cerr << i << " " << r << endl;
    if(r <= 0) ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
#include<stdio.h>
#include<queue>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int a,p;
int dd(int x,int y)
{
    if(x>y) return x-y;
    return y-x;
}
int main()
{
    cin>>a>>p;
    int k=(a*3+p)/2;
    printf("%d\n",k);
//    if(k==0)
//        printf("We cannot make an apple pie in this case, unfortunately.\n");
    return 0;
}









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

int		main(void)
{
	int		A, B;

	cin >> A >> B;
	for (int i = 0; i < B; B--)
	{
		A++;
		if (A == 24)
			A = 0;
	}
	cout << A << endl;
}

Measured memory_bytes: 256
//青春の片道切符：：ワーシャルフロイド法

	/*for(int k=0;k<N;k++){//経由箇所(N<200)
		for(int i=0;i<N;i++){//スタート(N<200)
			for(int j=0;j<N;j++){//目的(N<200)
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}*/


#include<iostream>
#include<string>
#include<queue>
#include<utility>
#include<algorithm>
#include<cctype>
using namespace std;

long long gc[110][110];
long long gt[110][110];
int n,m;

void warshallfroid(){
	for(int k=0;k<m;k++){//経由箇所(N<200)
		for(int i=0;i<m;i++){//スタート(N<200)
			for(int j=0;j<m;j++){//目的(N<200)
				gc[i][j]=min(gc[i][j],gc[i][k]+gc[k][j]);
				gt[i][j]=min(gt[i][j],gt[i][k]+gt[k][j]);
			}
		}
	}
}



int main(){
	
	while(cin>>n>>m,n||m/*n,mが両方0のときお終わり*/){
		for(int i=0;i<m;i++){//スタート(N<200)
			for(int j=0;j<m;j++){//目的(N<200)
				gc[i][j]=9999999;//初期化
				gt[i][j]=9999999;//初期化
			}
		}
	

	
	for(int i=0;i<n;i++){
		int a,b,c,t;
		cin>>a>>b>>c>>t;
		a--,b--;
		gc[a][b]=gc[b][a]=c;
		gt[a][b]=gt[b][a]=t;
	}
	warshallfroid();
	
	int k;
	cin>>k;
	for(int i=0;i<k;i++){
	int p,q,r;
		cin>>p>>q>>r;
		p--,q--;
		if(r==0)cout<<gc[p][q]<<endl;
		else cout<<gt[p][q]<<endl;
	}
	
	}

}



Measured memory_bytes: 3276
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

int main() {
    int n;
    cin >> n;
    vector<int>x(n),y(n);
    vector<int>v;
    rep(i,n) {
        cin >> x[i] >> y[i];
        v.push_back(i);
    }
    double sum = 0;
    do{
        rep(i,n-1) {
            int dx = x[v[i]] - x[v[i+1]];
            int dy = y[v[i]] - y[v[i+1]];
            double dist = dx*dx + dy*dy;
            dist = sqrt(dist);
            sum += dist;
        }
    }   while (next_permutation(v.begin(),v.end()));
    int d = 1;
    rep(i,n) d *= i+1;
    double ans = sum/d;
    cout << printf("%.10f",ans) << endl;   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
    char C[3][3];
    string ans;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> C[i][j];
            if (i == j) {
                ans += C[i][j];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N, k;
    scanf("%d", &N);
    k=N%10;
    if(k==2 || k==4 || k==5 || k==7 || k==9)
        printf("hon");
    else if(k==3)
        printf("bon");
    else
        printf("pon");
    return 0;
}


Measured memory_bytes: 1732
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextInt();
            long m = in.nextInt();

            if (n == 2 || m == 2) {
                out.println(0);
            } else if (n == 1 && m == 1) {
                long ans = 1;
                out.println(ans);
            } else if (n == 1 && m >= 2) {
                long ans = (m - 2);
                out.println(ans);
            } else if (n >= 2 && m == 1) {
                long ans = (n - 2);
                out.println(ans);
            } else {
                long ans = (n - 2) * (m - 2);
                out.println(ans);
            }
        }

    }
}



Measured memory_bytes: 21972
#include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cmath>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<map>
    #define endl "\n"
    #define eb emplace_back
    #define FOR(i, a, b) for(long long i = a; i < b; ++i)
    #define FORR(n) for(long long i = n - 1; i >= 0; --i)
    #define FORE(n) for(const auto &i : n)
    #define MS(n, i) memset(n, i, sizeof(n))
    typedef long long ll;
    inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
    inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
    using namespace std;
    
    /*
    bool desc(pair<ll, ll> a, pair<ll, ll> b)
    {
        return b.second > a.second;
    }
    
    ll total(string a)
    {
        int len = a.size();
        ll s = 0;
        FOR(i, 0, len)
        {
            s += a[i];
        }
        return s;
    }
    void SeivePrime(int n)
    {
        bool prime[n + 1];
        memset(prime, true, sizeof(prime));
        for(int p = 2; p * p <= n; p++)
        {
            if(prime[p])
            {
                for(int i = p * p; i <= n; i += p)
                    prime[i] = false;
            }
        }
    }
    */

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int t;
        cin >> t;
        int cnt = 0;
        double d;
        cin >> d;
        while (t--)
        {
            long long x, y;
            cin >> x >> y;
            x = abs(x);
            y = abs(y);
            x = x * x;
            y = y * y;
            long double dis = sqrt(x + y);
            //cout << dis << endl;
            if(dis <= d)
                cnt++;
        }
        cout << cnt << endl;
    }


/*
input:
6
7
abacaba
7
???????
11
aba?abacaba
11
abacaba?aba
15
asdf???f???qwer
11
abacabacaba

output:
Yes
abacaba
Yes
abacaba
Yes
abadabacaba
Yes
abacabadaba
No
No
*/

Measured memory_bytes: 3736
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,q;
  int a;
  int c=0;
  vector<int> s,t;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    s.push_back(a);
  }
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> a;
    t.push_back(a);
  }
  sort(t.begin(),t.end());
  int i=s.size()-1;
  int j=t.size()-1;
  while(1){
    if(s[i]==t[j]){
      c++;
      i--;
      j--;
    }
    else if(s[i]>t[j])i--;
    else j--;
    if(i<0||j<0)break;
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 3532
N=int(input())
d=list(map(int,input().split()))
flag=0
buf=0
squaresum=0
for i in range(N):
   for j in range(N):
      buf=buf+d[i]*d[j]
   squaresum=squaresum+d[i]*d[i]

print(int((buf-squaresum)/2))

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

/**
 * YAML
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		Main main = new Main();

		StringTokenizer query = new StringTokenizer(br.readLine(), ".");
		List<String> lines = new ArrayList<>();
		Obj[] objs = new Obj[50_000];

		//read
		while ((line = br.readLine()) != null && !line.isEmpty()) {
			lines.add(line);
		}

		//parse
		for (int i = 0; i < lines.size(); i++) {
			String line1 = lines.get(i);

			//parent
			int n = 0;
			for (int j = 0; j < line1.length(); j++) {
				if (line1.charAt(j) == ' ') n++;
				else break;
			}
			if (objs[n] == null) {
				objs[n] = main.new Obj();
			}

			//prop
			words = line1.substring(n).split(":");
			if (words.length == 1) {
				//prop: object
				String line2 = lines.get(i + 1);
				//self
				int m = 0;
				for (int j = 0; j < line2.length(); j++) {
					if (line2.charAt(j) == ' ') m++;
					else break;
				}
				if (objs[m] == null) {
					objs[m] = main.new Obj();
				}
				String key = words[0];
				objs[n].put(key, objs[m]);
			} else {
				//prop: string
				String key = words[0];
				String string = words[1].substring(1);
				objs[n].put(key, string);
			}
		}

		Obj obj = objs[0];
		Object value = null;
		while (query.hasMoreTokens()) {
			value = obj.get(query.nextToken());
			if (value == null) break;
			if (value instanceof Obj) {
				obj = (Obj) value;
			} else {
				if (query.hasMoreTokens()) {
					value = null;
					break;
				}
			}
		}

		String ans = "";
		if (value == null) {
			ans = "no such property";
		} else if (value instanceof Obj) {
			ans = "object";
		} else if (value instanceof String) {
			ans = "string \"" + value + "\"";
		}
		System.out.println(ans);

	} //end main

	class Obj {
		private Map<String, Prop> props;

		Obj() {
			props = new HashMap<>();
		}

		Object get(String key) {
			if (props.containsKey(key)) {
				return props.get(key).value;
			} else {
				return null;
			}
		}

		Prop put(String key, Obj value) {
			return props.put(key, new Prop<Obj>(value));
		}

		Prop put(String key, String value) {
			return props.put(key, new Prop<String>(value));
		}
	}

	class Prop<T> {
		private T value;

		Prop(T value) {
			this.value = value;
		}
	}
}

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

int main(void){

    int n;
    cin >> n;
    
    vector<pair<pair<string, int>, int>> data(n);
    for(int i=0; i<n; i++) {
        cin >> data[i].first.first >> data[i].first.second;
        data[i].first.second = -data[i].first.second;
        data[i].second = i+1;
    }

    sort(data.begin(), data.end());
    
    for(int i=0; i<n; i++) {
        cout << data[i].second << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int asc(const void *a, const void *b){
  char *x=(char*)a, *y=(char*)b;
  return strcmp(x,y);
}

int main(void){
 
  int n, l, i;
  char s[200][200];
  
  scanf("%d %d", &n, &l);
  for(i=0; i<n; i++) scanf("%s",s[i]);
  
  qsort(s,n,sizeof(s[0]), asc);
  
  for(i=0; i<n; i++) printf("%s", s[i]);
  printf("\n");
  
    return 0;
}

Measured memory_bytes: 252
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r){
	if(l >= r) return;
	int root = pre[pos++];
	int m = distance(in.begin(), find(in.begin(), in.end(), root));
	rec(l,m);
	rec(m+1,r);
	post.push_back(root);
}

void solve(){
	pos = 0;
	rec(0, pre.size());
	for(int i=0;i<n;i++){
		if(i) cout << " ";
		cout << post[i];
	}
	cout << endl;
}

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

	for(int i=0;i<n;i++){
		cin >> k;
		pre.push_back(k);
	}

	for(int i=0;i<n;i++){
		cin >> k;
		in.push_back(k);
	}

	solve();

	return 0;
}

Measured memory_bytes: 3144
n=int(input())
h=[0]*n
h=list(map(int,input().split()))
ans=[0]*n

ans[0]=0
ans[1]=abs(h[1]-h[0])

for i in range(2,n):
  ans[i]=min(ans[i-2]+abs(h[i]-h[i-2]),ans[i-1]+abs(h[i]-h[i-1]))

print(ans[n-1])

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

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


Measured memory_bytes: 3596
//辺ABが最短経路に含まれない⇔2点A、Bを結ぶ回り道が最短となる。
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
using namespace std;

map<set<int>, int> weight;

bool chmin(int& a, int b){
    if (a > b) {a = b; return true;}
    else return false;
}

int dfs(int parent_node, int goal_node, vector<int> passed, map<int, vector<int>> connectTo, int base){
    int best = base;

    passed.push_back(parent_node); //無限ループを防ぐために通過したノードを順にメモ
    for (int i : connectTo[parent_node]){
        if (find(passed.begin(), passed.end(), i) != passed.end()) continue;
        if (i == goal_node){
            if (chmin(best, weight[{parent_node, i}])) break;
        }
        else if (weight[{parent_node, i}] <= base){
            if (chmin(best, weight[{parent_node, i}] + dfs(i, goal_node, passed, connectTo, base - weight[{parent_node, i}]))){
                break;
            }
        }
    }
    passed.pop_back(); //return前に通過メモを1段破棄
    return best;
}

int main(){
    int N, M;
    cin >> N >> M;
    map<int, vector<int>> connectTo;
    int a[M], b[M], c;
    for (int i=0; i<M; i++){
        cin >> a[i] >> b[i] >> c;
        connectTo[a[i]].push_back(b[i]);
        connectTo[b[i]].push_back(a[i]);
        weight[{a[i],b[i]}] = c;
    }
    int ans=0;
    vector<int> passed;
    for (int i=0; i<M; i++){
        int best = dfs(a[i], b[i], passed, connectTo, weight[{a[i],b[i]}]); //dfsで最短経路探索
        if (best != weight[{a[i],b[i]}]) ans++; 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define em emplace
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i <= n; i++)
#define int long long
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<29;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

ll beki(ll x, ll n, const ll &p) {
    ll ret = 1;
    while (n > 0) {
        if (n & 1) (ret *= x) %= p;
        (x *= x) %= p;
        n >>= 1;
    }
    return ret;
}

signed main(){
    int n, p;
    string s;
    cin >> n >> p >> s;
    reverse(all(s));
    ll ans = 0;
    if (p == 2 || p == 5){
        for (int i = 0; i < n; i++) {
            int x = s[i] - '0';
            if (x % p == 0) ans += n - i;
        }
    } else {
        int cnt[10101] = {0};
        cnt[0] = 1;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum = (sum + beki(10, i, p) * (s[i] - '0')) % p;
            cnt[sum]++;
        }
        for (int i = 0; i < p; i++) {
            ans += cnt[i] * (cnt[i] - 1) / 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 644
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while(sc.hasNext()){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int ab = a + b;

            String st = ab +"";
            System.out.println(st.length());
        }
    }
}

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

char get_win_hand(char com_hand) {
  if (com_hand == 'r') {
    return 'p';
  } else if (com_hand == 's') {
    return 'r';
  } else {
    return 's';
  }
}

int get_score(char my_hand, int R, int S, int P) {
  if (my_hand == 'r') {
    return R;
  } else if (my_hand == 's') {
    return S;
  } else {
    return P;
  }
}

int main() {
  int N, K, R, S, P;
  string T;
  cin >> N >> K;
  cin >> R >> S >> P;
  cin >> T;

  ll ans = 0;
  vector<int> score_list(K);
  rep (i, K) {
    ll tmp_score = 0;
    char before_my_hand = '*';
    string partialT = "";
    for (int j = 0; j * K + i < N; j++) {
      partialT.push_back(T[j * K + i]);
    }
    rep(j, partialT.size()) {
      char com_hand = partialT[j];
      char my_hand = get_win_hand(com_hand);
      if (my_hand == before_my_hand) {
        my_hand = '*';
      } else {
        tmp_score += get_score(my_hand, R, S, P);
      }
      before_my_hand = my_hand;
    }
    score_list[i] = tmp_score;
  }
  
  rep (i, K) ans += score_list[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 768
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n;
  scanf("%d", &n);
  vi acc(9, 0);
  int b;
  rep (i, n) {
    scanf("%d", &b);
    acc[min(8, b / 400)] += 1;
  }
  int mi = 0;
  int ma = 0;
  rep (i, 8) {
    if (acc[i] > 0) {
      mi += 1;
    }
  }
  if (acc[8] > 0) {
    mi = max(1, mi);
  }

  rep (i, 8) {
    if (acc[i] > 0) {
      ma += 1;
    }
  }
  ma += acc[8];

  printf("%d %d\n", mi, ma);
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
#define mem(a, b) memset(a, b, sizeof(a))
#define pi acos(-1)
#define pb push_back
using namespace std;
const int maxn = 1e5+5;
const ll mod = 1e9+7;
string s;
int k;
struct ch{
    char c;
    int id;
    bool friend operator < (ch &a, ch & b){
        return a.c < b.c;
    }
}str[maxn];
set<string> Set;
int main(){
//    freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> s >> k;
    int len = s.length();
    for(int i = 1; i <= k; i++){
        for(int j = 0; j <= len-i; j++){
            string temp = s.substr(j, i);
            Set.insert(temp);
        }
    }
    int cnt = 0;
    for(auto p : Set){
        ++cnt;
        if(cnt == k){
            cout << p << endl;
            return 0;
        }
    }
    return 0;
    
}







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


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

    int n,m,c;
    cin >> n >> m >> c;
    vector<int> b(m);
    vector<vector<int>> a(n, vector<int>(m));
    rep (i, m) cin >> b[i];
    rep (i, n) {
        rep (j, m) cin >> a[i][j];
    }
    int cnt=0;
    rep (i, n) {
        int sum=c;
        rep (j, m) {
            sum += b[j] * a[i][j];
        }
        if (sum > 0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,C;cin>>n>>C;
    vector<ll> end;
    vector<vector<P>> x(C);
    rep(i,n){
        ll s,t,c;cin>>s>>t>>c;
        x[c-1].push_back({s,t});
    }
    
    vector<P> st;
    rep(i,C){
        vector<P> xi = x[i];
        if(xi.size()==0)continue;
        sort(ALL(xi));
        ll s = xi[0].first,t=xi[0].second;
        rep2(j,1,xi.size()){
            P p = xi[j];
            if(t==p.first)t=p.second;
            else{
                st.push_back({2*s-1,2*t});
                s=xi[j].first,t=xi[j].second;
            }
        }
        st.push_back({2*s-1,2*t});
    }
    sort(ALL(st));

    rep(i,st.size()){
        P p = st[i];
        bool flag = false;
        rep(j,end.size()){
            if(end[j]<p.first){end[j]=p.second;flag=true;break;}
        }
        if(flag)continue;
        end.push_back(p.second);
    }
    cout<<end.size()<<endl;
    return 0;
}

Measured memory_bytes: 4856