akhauriyash/Code-Regression huggingface dataset:
using System;

namespace Sort
{
    class Program
    {
        static void Main()
        {
            Console.ReadLine();
            var i = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int count = 0;
            for (int j = 0; j < i.Length; j++)
                for (int k = 0; k < i.Length - 1; k++)
                    if (i[k] > i[k + 1])
                    {
                        int t = i[k];
                        i[k] = i[k + 1];
                        i[k + 1] = t;
                        count++;
                    }
            var r = Array.ConvertAll(i, e => e.ToString());
            Console.Write("{0}\n{1}\n", string.Join(" ", r), count);
        }
    }
}

Measured memory_bytes: 9276
#include <stdio.h>

void swap(int* x, int* y)
{
    int swap = *x;
    *x = *y;
    *y = swap;
}

int main(void)
{
    int i, len1, len2, len3, n_iteration;

    scanf("%d", &n_iteration);

    for (i = 0; i < n_iteration; i++) {
        scanf("%d %d %d", &len1, &len2, &len3);
        if (len2 < len3) {
            swap(&len2, &len3);
        }
        if (len1 < len2) {
            swap(&len1, &len2);
        }
        if (len1 * len1 == len2 * len2 + len3 * len3) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }
    return 0;
}    

Measured memory_bytes: 1008
(defmacro read-to-let* ((&rest args) &body body)
  `(let* ,(mapcar #'(lambda (arg)
		     (if (listp arg)
			 arg
			 `(,arg (read))))
		 args)
     ,@body))

(read-to-let* (a b c d (ans (- (min b d) (max a c))))
  (princ (if (minusp ans) 0 ans)))

Measured memory_bytes: 12264
import sys
#template by uwi 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
ns()
ar = na()
ans = sum(na())
cr = na()
prev = -1
for i in range(len(ar)):
    if prev+1 == ar[i]:
        ans += cr[prev-1]
    prev = ar[i]
print(ans)



Measured memory_bytes: 38256
#include <iostream>

using namespace std;

int main()
{
  int a, b, c; cin>> a >> b >> c;
  bool flag = false;
  if(a==b and a!=c)
    flag = true;
  else if(a==c and a!=b)
    flag = true;
  else if(b==c and a!=b)
    flag = true;
  
  cout << (flag ? "Yes" : "No");
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pi 3.1415926535
#define endl '\n'
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll inf=1e19;
/*ll power(ll x,ll y,ll m)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%m;
        x=(x*x)%m;
        y=y/2;
    }
    return res;
}*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(10);
    cout.setf(ios::fixed,ios::floatfield);
    ll n,k,i;
    cin>>n>>k;
   long double a,b,c,s=0.000;
    vector<long double>v;
    for(i=1;i<=n;i++)
    {
        cin>>c;
        c=((c+1))/2.0;
        v.pb(c);
    }
    b=0.00;
    for(i=0;i<k;i++)
        b=b+v[i];
    s=max(s,b);
    for(i=k;i<n;i++)
    {
        b=b-v[i-k];
        b=b+v[i];
        s=max(s,b);
    }
    cout<<s<<endl;
}


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

const int MAX_N = 100000;
char s[MAX_N];
string t;
int len;

void solve() {
  len = strlen(s);
  for (int i = 0; i < len; i++){
    if (i % 2 == 0) {
      t.push_back(s[i]);
    }
  }
  cout << t << endl;
  
}

int main() {
  cin >> s ;

  solve();

  return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

const int M=2*100000+1;
const vi emp;

ll Pow_mod(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

ll Division_mod(ll n,ll m){
	return n*Pow_mod(m,mod-2)%mod;
}

vl fact(M);

void Init(){
	fact[0]=1;
	for(int i=1;i<M;i++) fact[i]=fact[i-1]*i%mod;
}

int n,x,y;
vvi a;

int main(){
	cin>>n>>x>>y;
	int cnt=0;
	map<int,int> m;
	for(int i=0;i<n;i++){
		int c,w;
		cin>>c>>w;
		if(m.find(c)==m.end()){
			m[c]=cnt;
			cnt++;
			a.push_back(emp);
		}
		a[m[c]].push_back(w);
	}
	int S=m.size();
	if(S==1){
		cout<<1<<endl;
		return 0;
	}
	for(int i=0;i<S;i++) sort(a[i].begin(),a[i].end());
	sort(a.begin(),a.end());
	vi b(S);
	for(int i=0;i<S;i++){
		auto it=upper_bound(a[i].begin(),a[i].end(),y-a[0][0]);
		if(it==a[i].begin()) break;
		b[i]=upper_bound(a[i].begin(),a[i].end(),x-a[i][0])-a[i].begin();
		if(i) b[i]=max(b[i],(int)(it-a[i].begin()));
		else b[i]=max(b[i],(int)(upper_bound(a[i].begin(),a[i].end(),y-a[1][0])-a[i].begin()));
	}
//	for(int i=0;i<S;i++) cout<<b[i]<<' ';
//	cout<<endl;
	Init();
	ll res=1,sum=0;
	for(int i=0;i<S;i++){
		(res*=fact[b[i]])%=mod;
		sum+=b[i];
	}
	res=Division_mod(fact[sum],res);
	cout<<res<<endl;
}

Measured memory_bytes: 20016
import math
N, K = map(int, input().split())
for i in range(1, K+1):
  ans = 0
  blue = math.factorial(K-1) // (math.factorial(i-1)*math.factorial(K-i))
  if N-K+1-i < 0:
    red = 0
  else:
    red = math.factorial(N-K+1) // (math.factorial(i)*math.factorial(N-K+1-i))
  ans = blue * red
  ans = ans % (10**9+7)
  print(int(ans))

Measured memory_bytes: 9252
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

struct UnionFind{
  vector<int> d;
  UnionFind(int n) : d(n, -1){}
  int find(int x){
    if(d.at(x) < 0) return x;
    return d.at(x) = find(d.at(x));
  }
  bool unite(int x, int y){
    x = find(x); y = find(y);
    if(x == y) return false;
    if(d.at(x) > d.at(y)) swap(x, y);
    d.at(x) += d.at(y);
    d.at(y)= x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d.at(find(x)); }
};

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s.at(i);
  UnionFind uf(h*w);
  int di[] = {1, 0, -1, 0}, dj[] = {0, 1, 0, -1};
  rep(i, h)rep(j, w){
    rep(k, 4){
      int ni = i + di[k], nj = j + dj[k];
      if(nj < 0 || w <= nj || ni < 0 || h <= ni) continue;
      if(s.at(i).at(j) != s.at(ni).at(nj)){
        // cerr << ni << " " << nj << " " << ni*h+nj << endl;
        uf.unite(i*w+j, ni*w+nj);
      }
    }
  }

  vector<int> cw(h*w, 0);
  rep(i, h)rep(j, w){
    if(s.at(i).at(j) == '.'){
      cw.at(uf.find(i*w+j))++;
    }
  }
  ll ans = 0;
  rep(i, uf.d.size()){
    if(uf.d.at(i) < 0 && uf.d.at(i) != -1){
      int cb = uf.d.at(i) * -1 - cw.at(i);
      ans += (ll)cw.at(i) * cb;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4816
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def get_sum(bit, i):
    s = 0
    while i:
        s += bit[i]
        i -= i & -i
    return s

def add(bit, i, x):
    while i < len(bit):
        bit[i] += x
        i += i & -i

def main(A, LR):
    N = len(A)
    L, R = LR[::2], LR[1::2]
    Q = len(L)
    query_order = np.argsort(R)
    L, R = L[query_order], R[query_order]
    ind = np.searchsorted(R, np.arange(N + 2))
    right_end = np.zeros(N + 1, np.int64)
    bit = np.zeros(N + 1, np.int64)
    answers = np.empty(Q, np.int64)
    for r in range(1, N + 1):
        a = A[r - 1]
        p = right_end[a]
        if p:
            add(bit, p, -1)
        right_end[a] = r
        add(bit, r, 1)
        for i in range(ind[r], ind[r + 1]):
            l, r, i = L[i], R[i], query_order[i]
            answers[i] = get_sum(bit, r) - get_sum(bit, l - 1)
    return answers

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i4 = numba.int32
    i8 = numba.int64
    cc = CC('my_module')

    def cc_export(f, signature):
        cc.export(f.__name__, signature)(f)
        return numba.njit(f)

    get_sum = cc_export(get_sum, (i8[:], i8))
    add = cc_export(add, (i8[:], i8, i8))
    main = cc_export(main, (i8[:], i8[:]))
    cc.compile()

from my_module import main

N, Q = map(int, readline().split())
A = np.array(readline().split(), np.int64)
LR = np.array(read().split(), np.int64)

ans = main(A, LR)
print('\n'.join(map(str, ans.tolist())))

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

ll items[3000+1][3000+1];
ll dp[4][3000+1][3000+1];

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int R, C, K; cin >> R >> C >> K;
    rep(i, R+1) rep(j, C+1) items[i][j] = 0;
    rep(i, K){
        int r, c; cin >> r >> c;
        ll v; cin >> v;
        items[r-1][c-1] = v;
    }
    
    rep(i, 4) rep(j, R+1) rep(k, C+1) dp[i][j][k] = -LLINF;
    dp[0][0][0] = 0;
    for(int r = 0; r <= R; r++){
        for(int c = 0; c <= C; c++){
            for(int have = 0; have <= 3; have++){
                if(have == 3){
                    if(r+1 <= R) dp[0][r+1][c] = max(dp[0][r+1][c], dp[3][r][c]);
                    if(c+1 <= C) dp[3][r][c+1] = max(dp[3][r][c+1], dp[3][r][c]);
                }
                else{
                    if(r+1 <= R){
                        if(items[r][c] != 0){
                            dp[0][r+1][c] = max(dp[0][r+1][c], dp[have][r][c] + items[r][c]);
                        }
                        else dp[0][r+1][c] = max(dp[0][r+1][c], dp[have][r][c]);
                    }
                    if(c+1 <= C){
                        if(items[r][c] != 0){
                            dp[have][r][c+1] = max(dp[have][r][c+1], dp[have][r][c]);
                            dp[have+1][r][c+1] = max(dp[have+1][r][c+1], dp[have][r][c] + items[r][c]);
                        }
                        else dp[have][r][c+1] = max(dp[have][r][c+1], dp[have][r][c]);
                    }
                }
            }
        }
    }
    ll ans = 0;
    rep(have, 4) ans = max(ans, dp[have][R][C]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 355292
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AizuOnline
{
    class Program
    {
        static void Main(string[] args)
        {
            for( int i = 1; i <= 9; i++)
            {
                for(int j = 1; j <= 9; j++)
                {
                    Console.WriteLine("{0}x{1}={2}", i, j, i * j);
                }
            }

            
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 5636
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

const int N = 2 * (int)1e5;
int dp1[N];
int dp2[N];

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

	string str;
	cin >> str;
	int n = str.size();

	// Always take either single letters or letters of length two
	dp1[0] = 1;
	dp2[0] = -1;
	for (int i = 1; i < n; ++i) {
		if (str[i] != str[i-1]) dp1[i] = dp1[i-1] + 1;
		if (i >= 2) {
			dp1[i] = max(dp1[i], dp2[i-1] + 1);
			dp2[i] = max(dp2[i], dp1[i-2] + 1);
			if (i >= 3) {
				if (str[i-3] != str[i-1] || str[i-2] != str[i]) dp2[i] = max(dp2[i], dp2[i-2] + 1);
			}
		} else dp2[i] = 1;
	}
	cout << max(dp1[n-1], dp2[n-1]) << '\n';
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define pb push_back
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

int ans,n;

void func(ll x,int counter){
    if(x>n)return;
    if(counter==7)ans++;
    func(x*10+3,counter|4);
    func(x*10+5,counter|2);
    func(x*10+7,counter|1);
}

vint allcount(1000000);

int main(){
    string a,b;
    map<char,char> table;
    cin>>a>>b;
    rep(i,26)table['a'+i]='A';
    rep(i,a.length()){
        if(table[a[i]]!='A' && table[a[i]]!=b[i]){
            cout<<"No"<<endl;
            return 0;
        }
        else{
            table[a[i]]=b[i];
        }
    }

    rep(i,26)table['a'+i]='A';
    rep(i,a.length()){
        if(table[b[i]]!='A' && table[b[i]]!=a[i]){
            cout<<"No"<<endl;
            return 0;
        }
        else{
            table[b[i]]=a[i];
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 4740
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>

using namespace std;
using ll=long long;

string s, t;

int dp[3005][3005];

int main()
{
    cin >> s >> t;
    int slen = s.length();
    int tlen = t.length();
    for(int i = 1;i <= slen;i++)
        for(int j = 1;j <= tlen;j++)
        {
               if(s[i-1] == t[j-1])
               {
                   dp[i][j] = dp[i-1][j-1] + 1;
               }
               else
               {
                   dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
               }
        }
    int len = dp[slen][tlen];
    string ans(len, 'A');
    int l = len;
    int i = slen;
    int j = tlen;
    while(l > 0)
    {
        if(s[i-1] == t[j-1])
        {
            l--;
            ans[l] = s[i-1];
            i--;
            j--;
        }
        else if(dp[i][j] == dp[i][j-1])
        {
            j--;
        }
        else
        {
            i--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 35456
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;



int main(void){
    long long N,K;
    long long N_tmp;

    cin>>N>>K;



    N_tmp = N%K;
    if(N_tmp > abs(N_tmp - K)){
        N=abs(N_tmp - K);
    }else{
        N=N_tmp;
    }
    

    cout<<N<<endl;



    return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=[[int(s) for s in input()] for _ in range(n)]
    B=[a[:] for a in A]
    from itertools import product
    # 対角以外の0をINF
    for i,j in product(range(n),repeat=2):
        if i==j: continue
        if B[i][j]==0: B[i][j]=INF
    # Warshall-Floyd
    for k,i,j in product(range(n),repeat=3):
        B[i][j]=min(B[i][j],B[i][k]+B[k][j])
    # 直径となる始点を1つ取得
    dia=0; p=0
    for i,j in product(range(n),repeat=2):
        if dia<B[i][j]:
            dia=B[i][j]
            p=i
    for i,j in product(range(n),repeat=2):
        if i>=j: continue # i<j
        if A[i][j]:
            if abs(B[i][p]-B[j][p])!=1:
                print(-1)
                return
    print(dia+1)
resolve()

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int A[400][400];
int main(){
    int N, M;
    cin >> N >> M;
    REP(i,N){
        REP(j,M){
            int a;
            cin >> a;
            a--;
            A[i][j] = a;
        }
    }

    int ans = 1e5;
    set<int> se;
    REP(i,M) se.insert(i);

    REP(i,M){
        map<int, int> ma;
        REP(n,N){
            REP(m,M){
                int a = A[n][m];
                if(se.find(a) != se.end()){
                    ma[a]++;
                    break;
                }
            }
        }

        int maxidx;
        int tmp = 0;
        for(auto&& p : ma){
            if(tmp < p.second){
                tmp = p.second;
                maxidx = p.first;
            }
        }
        chmin(ans, tmp);
        se.erase(maxidx);
    }

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


Measured memory_bytes: 768
N = int(input())
S = list(input())

for i in range(2*N):
    if (2*N-i)%2==1:
        S[i] = 'B' if S[i]=='W' else 'W'
        
if S.count('B')!=N:
    print(0)
    exit()

ans = 1
MOD = 10**9+7
B = 0

for Si in S:
    if Si=='B':
        B += 1
    else:
        ans *= B
        ans %= MOD
        B -= 1

fact = [1]

for i in range(1, N+1):
    fact.append(fact[-1]*i%MOD)

ans *= fact[N]
ans %= MOD

print(ans)

Measured memory_bytes: 61552
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val n = readLine.trim.toInt
  val goods = Array.tabulate(n){_ ⇒ readLine.trim.toInt}
  println(
    goods.sum - goods.max / 2
  )
  implicit class Extenion[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}

Measured memory_bytes: 25420
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cerr << i << " "; cerr << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int h, w;
VVI a;
VVI p;

void re(int y, int x) {
	int y2, x2;
	if (y % 2) {
		if (x == 0) { y2 = y + 1; x2 = 0; }
		else { y2 = y; x2 = x - 1; }
	}
	else {
		if (x == w - 1) { y2 = y + 1; x2 = w - 1; }
		else { y2 = y; x2 = x + 1; }
	}

	if (a[y][x] % 2) {
		a[y][x]--;
		a[y2][x2]++;
		p.pb({ y + 1,x + 1,y2 + 1,x2 + 1 });
	}
}

int main() {
	cin >> h >> w;
	a.resize(h, VI(w));
	rep(i, h)rep(j, w)cin >> a[i][j];

	rep(i, h) {
		if (i % 2) {
			for (int j = w - 1; j >= (i == h - 1 ? 1 : 0); j--) {
				re(i, j);
			}
		}
		else {
			rep(j, (i == h - 1 ? w - 1 : w)) {
				re(i, j);
			}
		}
	}

	//print
	Cout(sz(p));
	for (auto v : p) {
		cout << v[0] << " " << v[1] << " " << v[2] << " " << v[3] << endl;
	}
}

Measured memory_bytes: 9904
s = input()
length = len(s)
count_dict = {}

'''for i in range(length-4):
    for j in range(i+4,length+1):
        num = int(s[i:j])
        if num%2019 == 0:
            count += 1'''

num = int(s)%2019
count_dict[num] = 1

# num = int(s[-1])
# count_dict[num] = 1

for i in range(1,length):
    num = (num-int(s[-i])*pow(10,(i-1),2019))%2019
    # num = num+int(s[-i])
    if num not in count_dict:
        count_dict[num] = 1
    else:
        count_dict[num] += 1


count = 0
for k,v in count_dict.items():
    count += v*(v-1)/2
    if k == 0:
        count += v

print(int(count))

Measured memory_bytes: 9256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <math.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define repP(i, a, b) for(int i = a; i < b; i++)
#define repM(i, a, b) for(int i = a - 1; i >= b; i--)

using namespace std;

int main()
{
  int a = 0 , b = 0, c = 0, d = 0, e = 0, f = 0, i = 0, j = 0;
  int sum = 0, num = 0, count = 0, ans = 0, min = 0, max = 0;
  double d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0;
  int a1[999999], a2[999999], a3[999999];
  //char s1[200000], s2[200000], s3[200000];
  string s1, s2, s3;
  
  cin >> a >> s1;
  s2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(i = 0; i < s1.size(); i++){
    for(j = 0; j < 26; j++){
      if(s1[i] == s2[j]){
        if(j + a >= 26){
          cout << s2[j + a - 26];
        }else{
          cout << s2[j + a];
        }
      }
    }
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int fib[1004], cfib[1001];
int V, d;

void init() {
    fib[0] = 0, fib[1] = 1;
    for (int i = 2; i <= 1003; i++) {
        fib[i] = (fib[i-1]+fib[i-2]) % 1001;
    }
}

void solve() {
    for (int i = 0; i <= V; i++) cfib[i] = 0;
    for (int i = 0; i < V; i++) {
        cfib[i] = fib[i+3];
    }
    sort(cfib, cfib+V);
    int sum = 1;
    for (int i = 1; i <= V; i++) {
        if (cfib[i] - cfib[i-1] >= d) sum++;
    }
    printf("%d\n", sum);
}

int main() {
    init();
    while(scanf("%d %d", &V, &d) != EOF) {
        solve();
    }
    return 0;
}



Measured memory_bytes: 2752
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(a, b) for (int i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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 cmb(int n, int k)
{
    ll coef = 1;
    vector<ll> sieve(n + 1, 0);
    if (n < k)
    {
        coef = 0;
        return coef;
    }
    if (n == k || k == 0)
    {
        coef = 1;
        return coef;
    }
    k = min(k, n - k);
    for (ll p = 2; p <= n; p++)
    {
        if (sieve.at(p) == 0)
        {
            for (ll i = p * p; i <= n; i += p)
            {
                sieve.at(i) = 1;
            }
            for (ll prime = p; prime <= n; prime *= p)
            {
                ll cnt = n / prime - k / prime - (n - k) / prime;
                REP(j, cnt)
                {
                    coef *= p;
                    coef %= MOD;
                }
            }
        }
    }
    return coef;
}

int main(){
    int n,m;
    cin >> n >> m;
    ll ans=cmb(m,2)+cmb(n,2);
    cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    a = [list(map(int, input().split())) for _ in range(n)]
    a.sort(key=lambda x: x[1], reverse=True)
    lim = float("inf")
    for p, q in a:
        if q < lim:
            lim = q
        lim -= p
    if 0 <= lim:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 47372
//R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first 
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))  
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double 
#define pii std::pair<int, int> 
#define pll std::pair<ll, ll>  
#define vi vector<int>  
#define vl vector<ll>
#define vvi vector<vi > 
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>


using namespace std;

void solve()
  {
    int n,w;
    cin>>n>>w;
    int wt[n],val[n];
    rep(i,n)cin>>wt[i]>>val[i];
    int dp[n+1][w+1];
    memset(dp,-1,sizeof dp);
    dp[0][0]=0;
    rep(i,n+1)dp[i][0]=0;
    rep(i,w+1)dp[0][i]=0;
    
    repA(j,1,w)
    {
        repA(i,1,n)  
        {
            
            if(j-wt[i-1]>=0) dp[i][j]=max(dp[i-1][j],dp[i-1][j-wt[i-1]]+val[i-1]);          
            else dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][w];
    


  }



signed main()
{
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   t=1;
   //cin>>t;
   while(t--)
    {
        solve();
    }


   return 0;
}


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

int main() {
  int n, m, v, p;
  cin>>n>>m>>v>>p;
  long a[n];
  for (int i=0; i<n; i++) cin>>a[i];

  sort(a, a + n);

  int right = n - p;
  while (right > 0 && a[right-1] == a[right]) {
    --right;
  }
  if (right == 0) {
    cout<<n<<endl;
    return 0;
  }
  if (a[0] + m >= a[right]) {
    if (v - 1 <= p - 1) {
      cout<<n<<endl;
      return 0;
    }
    int v2 = v - p;
    long b = a[0] + m;
    queue<long> q;
    for (int i=1; i<n-p+1; i++) {
      q.push(min(b - a[i], (long)m));
    }
    bool ok = true;
    for (int i=0; i<v2; i++) {
      int m2 = m;
      while (m2 > 0) {
        if (q.empty()) {
          ok = false;
          break;
        }
        long front = q.front();
        q.pop();
        if (front > m2) {
          q.push(front - m2);
          m2 = 0;
        } else {
          m2 -= front;
        }
      }
      if (!ok) {
        break;
      }
    }
    if (ok) {
      cout<<n<<endl;
      return 0;
    }
  }
  int orig_right = right;
  int left = 0;
  while (right - 1 > left) {
    int mid = (left + right) / 2;
    if (a[mid] + m < a[orig_right]) {
      left = mid;
      continue;
    }
    int v2 = v - (p - 1) - mid - 1;
    if (v2 <= 0) {
      right = mid;
      continue;
    }
    long b = a[mid] + m;
    queue<long> q;
    for (int i=mid+1; i<n-p+1; i++) {
      q.push(min(b - a[i], (long)m));
    }
    bool ok = true;
    for (int i=0; i<v2; i++) {
      int m2 = m;
      while (m2 > 0) {
        if (q.empty()) {
          ok = false;
          break;
        }
        long front = q.front();
        q.pop();
        if (front > m2) {
          q.push(front - m2);
          m2 = 0;
        } else {
          m2 -= front;
        }
      }
    }
    if (ok) {
      right = mid;
    } else {
      left = mid;
    }
  }
  cout<<n - right<<endl;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
//typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

int n,tmp;
vector<P> vec;
const int MOD=1e9+7;

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

	cin>>n;
	REP(i,2*n) {
		cin>>tmp;
		vec.pb(P(tmp,(int)(i>=n)));
	}
	sort(ALL(vec));
	ll ans=1;
	int cnt_a=0,cnt_b=0;
	for(auto v:vec) {
		if(v.se==0) {
			if(cnt_b==0) cnt_a++;
			else (ans*=cnt_b)%=MOD,cnt_b--;
		}
		if(v.se==1) {
			if(cnt_a==0) cnt_b++;
			else (ans*=cnt_a)%=MOD,cnt_a--;
		}
		//cout<<cnt_a<<' '<<cnt_b<<' '<<ans<<endl;
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 2420
#include <stdio.h>
#include <stdlib.h>
#define VMAX 10000

void C(unsigned short *, unsigned short *, int);

int main(){
    unsigned short *A, *B;
    int n, i, j;

    scanf("%d", &n);

    A = malloc(sizeof(short)*n+1);
    B = malloc(sizeof(short)*n+1);

    /* your code */
    for(i = 0; i < n; i++){
        scanf("%hu",&A[i]);
    }

    C(A, B, n);

    for(j = 1; j < n; j++)
        printf("%u ",B[j]);
    printf("%u\n",B[j]);

  return 0;
}

void C(unsigned short *A, unsigned short *B, int n){
    int i, j;
    int C[VMAX+1];

    for(i = 0; i <= VMAX; i++)C[i] = 0;

    for(j = 0; j < n; j++)C[A[j]] = C[A[j]] + 1;

    for(i = 1; i <= VMAX; i++)C[i] = C[i] + C[i-1];

    for(j = n-1; j >= 0; j--){
        B[C[A[j]]] = A[j];
        C[A[j]] = C[A[j]] - 1;
    }
}



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

int main(){
	int w, h;
	int i, j;
	
	while (1){
		scanf("%d %d", &h ,&w);
		if (w == 0 && h == 0) break;


		for (i = 0;i < h; i++){
			printf("#");
			for (j = 0; j < w-2; j++){
				if (i == 0 || i == h - 1){
					printf("#");
				}else{
					printf(".");
				}
				
			}
			printf("#\n");
		}

		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
	int a;cin>>a;
	cout<<a+a*a+a*a*a;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);	
#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif 
	int T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3644
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n_ := nextLine()
	n, _ := strconv.Atoi(n_)

	var ans float64
	for i := 0; i < n; i++ {
		s := nextLine()
		in := strings.Split(s, " ")

		num, _ := strconv.ParseFloat(in[0], 64)
		if in[1] == "JPY" {
			ans += num
		} else {
			ans += num * 380000.0
		}
	}
	fmt.Println(ans)
}


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

//ビット列から式を計算する
long long pplus(bitset<9> o,string S){
  char* s = 0;
  long long M;
  if (o == 0){
    //cout << stoi(S) << endl;
    istringstream iss(S);
    iss >> M;
   return M; 
  }
  //oとSから和を作る
  long long sum = 0;
  int front = -1;
  for (int i = 0;i<9;i++){
    M = 0;
    //何文字取り出すか変数
    int a = 0;
    //
    //cout << "this is i ";
    //cout << i << endl;
    //
   int j = 8 -i;
    //
    //cout << "this is j ";
    //cout << j << endl;
    //
    if (o.test(j)){
      //何文字取り出すか
       a = i - front;
      //
      //cout << "SUM!! -->" << to_string(sum) + " + " + S.substr(front+1,a) + "= ";
      //
      istringstream iss(S.substr(front+1,a));
      iss >> M;
       sum = sum + M;
      //cout << sum << endl;
      front = i;
      //
      //cout << "=" << sum << endl;
      //
      }
      if (i == 8){
        //cout << "SUM!! -- > ";
        //cout << sum << " + " + S.substr(front+1) + "= ";
        istringstream iss(S.substr(front+1));
        iss >> M;
       sum = sum +  M;
        //cout << sum << endl;
    }    
  }
  //cout << sum << endl;
  return sum;
}
 
int main() {
  // ここにプログラムを追記
  long long sum;
  string S;
  cin >> S;
  int l = S.size();
  while (S.size() < 10){
   S = "0" + S; 
  }
  for (int i = 0;i < (1 << (l-1));i++){
    bitset<9> s(i);
    sum += pplus(s,S);
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int days[1001][11][21] = {};
    int cnt = 1;
    for(int i = 1; i <= 1000; i++)
    {
        for(int j = 1; j <= 10; j++)
        {
            if(i % 3 == 0 or j % 2)
            {
                for(int k = 1; k <= 20; k++)
                {
                    days[i][j][k] = cnt++;
                }
            }
            else
            {
                for(int k = 1; k <= 19; k++)
                {
                    days[i][j][k] = cnt++;
                }
            }
        }
    }
    for(int i = 0; i < n; i++)
    {
        int y, m, d; cin >> y >> m >> d;
        cout << days[1000][1][1] - days[y][m][d] << endl;
    }
    return 0;
}





Measured memory_bytes: 4128
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n;i>s;i--)
#define rep_re(i,s,n)for(ll i = n;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;
void divider_s(set<ll> &s, ll n) {
	for (ll i = 1; i*i <= n; i++) {
		if (!(n % i)) {
			s.insert(i);
			if (i*i != n) s.insert(n / i);
		}
	}
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
int main() {
	set<ll> s1;
	set<ll> s2;

	ll a, b; cin >> a >> b;
	divider_s(s1, a);
	divider_s(s2, b);

	vector<ll> v;
	for (set<ll>::iterator it = s1.begin(); it != s1.end(); it++) {
		if (s2.count(*it) != 0) {
			v.push_back(*it);
		}
	}

	ll V = v.size();
	ll ans = 0;
	ll X = 1;
	rep(l, 0, V) {
		if (gcd(X, v[l]) == 1) {
			X *= v[l];
			ans++;
		}
	}

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

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

int main(void) {
  int K, A, B;

  cin >> K >> A >> B;

  for (int i = A; i <= B; i++) {
    if (i % K == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;

  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;


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

	string s;
	cin >> s;
	cout << s[0] << s[1] << s[2] << endl;

	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll A,V,B,W,T;
  cin >> A>> V>> B >> W >>  T;
  if(A==B){
    cYES;
  }
  else{
    if((V-W)*T>=abs(A-B)){
      cYES;
    }
    else {
      cNO;
    }
  }
}

Measured memory_bytes: 3636
n, ma, mb = [int(i) for i in input().split()]
lst = [[int(i) for i in input().split()] for _ in range(n)]
lst.sort(key=lambda x: x[2])
dic = {}
def push(k,v):
    if k in dic:
        dic[k] = min(dic[k],v)
    else:
        dic[k] = v


for i in lst:
    k, v = i[0] * mb - i[1] * ma, i[2]
    l = [[j, dic[j]] for j in dic]
    for item in l:
        push(item[0] + k, item[1] + v)
    push(k, v)

print(dic[0] if 0 in dic else '-1')

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
static const long long MOD = 1000000000+7;
static const double PI = 3.141592653589793;
vector<long long> vecmodfact(2,1);

long long modpow(long long x, long long n, long long mod = 0) {
  if (mod == 0) {
      long long res=1;
    while (n > 0) {
      if (n%2 == 1) {
        res = ( res*x );
      }
      x = (x*x);
      n /= 2;
    }
    return res;
  }

  long long res=1;
  while (n > 0) {
    if (n%2 == 1) {
      res = ( res*x ) % mod;
    }
    x = (x*x) % mod;
    n /= 2;
  }
  return res;
}

long long modinverse(long long x, long long mod) {
  // mod must be prime number.
  return modpow(x, mod-2, mod);
}

long long modfact(long long n, long long mod) {
  if (vecmodfact.size()-1 >= n) return vecmodfact.at(n);
  int i=vecmodfact.size();
  vecmodfact.resize(n+1);
  for (; i<=vecmodfact.size()-1; i++) {
    vecmodfact.at(i) = vecmodfact.at(i-1)*i % mod;
  }
  return vecmodfact.at(n);
}

long long modcomb(long long m, long long n, long long mod){
  if (m < n || n < 0) return 0;
  if (n == 0 || n == m) return 1;
  long long ans = modfact(m,mod) * modinverse(modfact(n,mod), mod) % mod;
  ans = ans * modinverse(modfact(m-n,mod), mod) % mod;
  return ans;
}



int main() {
  long long n;
  cin >> n;
  vector< long long> v(n);
  bool isZero = false;
  for (int i=0; i<n; i++) {
    long long a;
    cin >> a;
    if (a == 0) {
      isZero = true;
    }
    v.at(i) = a;
  }

  if (isZero) {
    cout << 0 << endl;
    return 0;
  }

  unsigned long long ans=1;
  unsigned long long prevAns =1;
  long long keta=0;
  for (int i=0; i<n; i++) {
    long long k = log10(v.at(i));
    keta += k;
    if (k > 18) {
      cout << -1 << endl;
      return 0;
    }
    ans *= v.at(i);
    if (ans > 1000000000000000000) {
      cout << -1 << endl;
      return 0;
    }
    if (ans < prevAns) {
      cout << -1 << endl;
      return 0;
    }
    prevAns = ans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
//ll visit[100001]={0};
//vector<ll> adj[1000001];

bool sortinrev(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{
       if(a.first!=b.first) return(a.first > b.first);
       else return (a.second<b.second);
} 
ll power(ll x,ll n,ll m)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%m;
        x=(x*x)%m;
        n=n/2;
    }
    return result%m;
}
bool isPrime(ll k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    ll i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}
 
ll bin(ll n)
{
    int di= 0;
    while(n)
    {   di=di+n%10;
        n=n/10;
        
    }
    return di;
}

int main(){
   IOS;
ll t;t=1;//cin>>t;
while(t--){
ll n;cin>>n;
ll a[n+1];ll k;cin>>k;
for(ll i=1;i<n+1;i++) cin>>a[i];
ll dp[n+1];
for(ll i=1;i<=n;i++){dp[i]=LONG_MAX;}
dp[1]=0;
dp[2]=abs(a[2]-a[1]);
for(int i=3;i<=n;i++){
    for(int j=1;j<=k;j++){
        if(i-j>=1){
            dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
        }
    }
}

    cout<<dp[n]<<"\n";
    
}
    
    
    
    





return 0;}


Measured memory_bytes: 5112
from collections import deque
import sys
N, M, K = map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b  = [0], [0]
for n in range(N):
    a.append(a[n]+A[n])
    #print(a)
for m in range(M):
    b.append(b[m]+B[m])
    #print(b)
ans, j = 0, M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 49164
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i = 1; i <= n; ++i) {
        cin >> a[n - i];
    }
    for(int i = 0; i < n - 1; ++i) {
        cout << a[i] << " ";
    }
    cout <<  a[n - 1] << endl;
    return 0;
}


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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;

const int B = 1e6 + 7;

const int N = 250005;

const int mod1 = 1e9 + 7;
const int mod2 = 1e9 + 9;

int cnt = N - 5, pw[2][2 * N], lmao[N], n, hs[2][N];

long long sum = 0;

string s;

ii type;

map<ii, int> mymap;

int BinPow(int x, int m, int mod) {
    if(m == 0)
        return 1;
    else if(m == 1)
        return x % mod;
    else {
        int sum = BinPow(x, m >> 1, mod);
        sum = (1ll * sum * sum) % mod;
        if(m % 2)
            sum = (1ll * sum * x) % mod;
        return sum;
    }
}

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n;
    cin >> s;
    s = "+" + s;
    pw[0][0] = pw[1][0] = 1;
    for(int i = 1; i <= 2 * N - 10; i++) {
        pw[0][i] = (1ll * pw[0][i - 1] * B) % mod1;
        pw[1][i] = (1ll * pw[1][i - 1] * B) % mod2;
    }
    for(int i = 1; i <= n; i++) {
        lmao[i] = cnt;
        if(s[i] == '+') {
            hs[0][i] = (1ll * hs[0][i - 1] + pw[0][cnt]) % mod1;
            hs[1][i] = (1ll * hs[1][i - 1] + pw[1][cnt]) % mod2;
        }
        if(s[i] == '-') {
            hs[0][i] = (1ll * hs[0][i - 1] - pw[0][cnt]) % mod1;
            hs[1][i] = (1ll * hs[1][i - 1] - pw[1][cnt]) % mod2;
            hs[0][i] = (1ll * hs[0][i] + mod1) % mod1;
            hs[1][i] = (1ll * hs[1][i] + mod2) % mod2;
        }
        if(s[i] == '>'){
            cnt++;
            hs[0][i] = (1ll * hs[0][i - 1] + mod1) % mod1;
            hs[1][i] = (1ll * hs[1][i - 1] + mod2) % mod2;
        }
        if(s[i] == '<'){
            cnt--;
            hs[0][i] = (1ll * hs[0][i - 1] + mod1) % mod1;
            hs[1][i] = (1ll * hs[1][i - 1] + mod2) % mod2;
        }
    }
    int x1 = (1ll * hs[0][n] * BinPow(pw[0][lmao[1]], mod1 - 2, mod1)) % mod1;
    int x2 = (1ll * hs[1][n] * BinPow(pw[1][lmao[1]], mod2 - 2, mod2)) % mod2;
    type = {x1, x2};
    for(int i = n; i >= 1; i--) {
        mymap[{hs[0][i], hs[1][i]}]++;
        x1 = ((1ll * type.fi * pw[0][lmao[i]]) % mod1 + 1ll * hs[0][i - 1]) % mod1;
        x2 = ((1ll * type.se * pw[1][lmao[i]]) % mod2 + 1ll * hs[1][i - 1]) % mod2;
        sum += mymap[{x1, x2}];
    }
    cout << sum << "\n";
}


Measured memory_bytes: 38556
import java.util.*;

public class Main { 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
		int cardNum = Integer.parseInt(sc.next());
        int gateNum = Integer.parseInt(sc.next());
      	int lowNum = 1;
      for (int y = 1; y <= gateNum; y++) {
        int low = Integer.parseInt(sc.next());
        int high = Integer.parseInt(sc.next());
		lowNum = lowNum<low?low:lowNum;
        cardNum = high<cardNum?high:cardNum;
      }
      System.out.println(cardNum-lowNum+1>=0?cardNum-lowNum+1:0);
  }
}

Measured memory_bytes: 49456
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str, T: str):
    if S==T[:len(T)-1]:
        print(YES)
        exit()
    print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()


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

//freopen("file_name.in", "r", stdin);
//freopen("file_name.out", "w", stdout);

#define fr(i,n) for(int i=0;i<n;i++)
#define frr(i,a,b) for(int i =a;i<=b;i++)

typedef long long ll;

#define eb emplace_back

#define all(v) (v).begin(),(v).end()

#define fi first
#define se second
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

//-DBL_MAX
//__builtin_popcountll(ll x) - __builtin_popcount(int x)

#define prin(a) cout << #a << " = " << (a) << endl
#define prinv(v) {cout << #v << " = "; for(auto it : v) cout << it << " "; cout << endl;}
#define ppal(a)  cout << #a << endl

const int N = -1;

const ll MOD = 1e9+7;

vector<vector<ll>> mm(vector<vector<ll>> a, vector<vector<ll>> b){
    int l = a.size();
    int c = b[0].size();
    vector<vector<ll>> ans(l,vector<ll>(c));
    
    fr(i,l){
        fr(j,c){
            ll tot = 0;
            fr(k,a[0].size()) tot = (tot+a[i][k]*b[k][j])%MOD;
            ans[i][j] = tot;
        }
    }
    return ans;
}

vector<vector<ll>> em(vector<vector<ll>> m, ll exp){
    if(exp==1) return m;
    vector<vector<ll>> mid = em(m,exp/2);
    if(exp&1) return mm(mm(mid,mid),m);
    return mm(mid,mid);
}

int main(){
	int n;
	ll k;
	
	cin >> n >> k;
	
	vector<vector<ll>> m(n,vector<ll>(n));
	
	fr(i,n){
	    fr(j,n) scanf("%lld", &m[i][j]);
	}
	
	m = em(m,k);
	
	ll ans = 0;
	fr(i,n){
	    fr(j,n) ans = (ans+m[i][j])%MOD;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 1664