akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#include <unistd.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
 
 
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx_ori[4] = { -1,0, 1,0 }, dy_ori[4] = { 0,1,0,-1 };
int dx[4] = {0, 0, 0, 0}, dy[4] = {0, 0, 0, 0};
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
  int n;
  cin >> n;
  rep1 (x, n) {
    int y = x * 1.08;
    if (y == n) {
      cout << x << endl;
      return 0;
    }
  }
  cout << ":(" << endl;

}


Measured memory_bytes: 256
function main()
  S = chomp(readline())
  l = length(S)
  t = S[1:2:l]
  u = S[2:2:l]
  c = 1
  for i = 1:length(t)
    if t[i] == 'L'
      c = 0
    end
  end
  for i = 1:length(u)
    if  u[i] == 'R'
      c = 0
    end
  end
  c == 1 ? println("Yes") : println("No")
end

main()

Measured memory_bytes: 108556
# include <bits/stdc++.h>
# define pb push_back
# define ll long long
# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG

using namespace std;

const int N = 50 + 7;
const int mod = 1e9 + 7;

int n, a[N], b[N], c[N], p = -1, ans;

int main()
{
    speed;
    /// Author: Dilshod--Imomov
    #ifdef DEBUGd
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG
    cin >> n;
    for ( int i = 1; i <= n; i++ ) cin >> a[i];
    for ( int i = 1; i <= n; i++ ) cin >> b[i];
    for ( int i = 1; i < n; i++ ) cin >> c[i];
    for ( int i = 1; i <= n; i++ ) {
        ans += b[ a[i] ];
        if ( a[i] == p + 1 ) ans += c[p];
        p = a[i];
    }
    cout << ans;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
//const int MM = 1e9;
const int MOD = 1e9+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
// priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > pq;

template<typename T> //最大公約数
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T> //最小公倍数
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}

long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}


// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}


bool IsPrime(int x){
    for (int i = 2; i*i <= x; i++){
        if (x % i == 0){
            return false;
        }
    }
    return true;
}

vector<pair<ll, ll> > PrimeFactor(ll N){
    vector<pair<ll, ll> > prime;
    for (int i = 2; i*i <= N; i++){
        if (N % i != 0) continue;
        int cnt = 0;
        while (N % i == 0){
            cnt++;
            N /= i;
        }
        prime.push_back({i, cnt});
    }
    if (N > 1){
        prime.push_back({N, 1});
    }
    return prime;
}

vector<pair<ll, ll> > CountPrime(ll N){
    vector<pair<ll, ll> > prime;
    for (ll i = 2; i * i <= N; i++){
        if (N % i != 0) continue;
        ll cnt = 0, n = N;
        while (n % i == 0){
            cnt++;
            n /= i;
        }
        prime.push_back({i, cnt});
    }
    prime.push_back({N, 1});
    return prime;
}

int main(){
    ll A, B; cin >> A >> B;
    ll g = GCD(max(A, B), min(A, B));
    //cout << g << endl;
    int res = 1;
    ll G = g;
    for (ll i = 2; i * i <= G; i++){
        if (g % i != 0) continue;
        while (g % i == 0){
            g /= i;
        }
        res++;
        //cout << i << endl;
    }
    if (g > 1){
        res++;
    }
    cout << res << endl;
}

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


int main(){
    int n;
    cin >> n;
    vector<vector<int>> d(n+2, vector<int>(2));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 2; j++) {
        cin >> d.at(i).at(j);
        }
    }
    d.at(n).at(0)= 4;
    d.at(n).at(1)= 5;
    d.at(n+1).at(0)= 6;
    d.at(n+1).at(1)= 7;
    for(int i=0;i<n;i++){
        if(d.at(i).at(0)==d.at(i).at(1) && d.at(i+1).at(0)==d.at(i+1).at(1) && d.at(i+2).at(0)==d.at(i+2).at(1)){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

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

    int n, k;
    cin >> n >> k;

    set<int> s;
    vector<int> p(n);
    int inc;
    bool added = false;
    for (int i = 0; i < n; i++){
        cin >> p[i];
    }

        
    int res = 1;
    for (int i = 0; i < k; i++){
        s.insert(p[i]);
        if (i > 0 && p[i] > p[i - 1])
            inc++;
        else inc = 1;
        if (inc >= k)
            added = true;
    }

    for (int i = k; i < n; i++){
        if (p[i] > p[i - 1])
            inc++;
        else 
            inc = 1;
        if (!(p[i] > *s.rbegin() && p[i - k] == *s.begin())){
            if (inc < k || !added)
                res++;
            if (inc >= k)
                added = true;
        }
        s.erase(p[i - k]);
        s.insert(p[i]);
    }
    
    cout << res << "\n";
  
    return 0;
}


//case 1: sorted segment

//case 2: segment overlap (i,  i + k - 1) vs (i + 1, i + k)
    //a[i] = min, a[i + k] = max


Measured memory_bytes: 10368
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break

    ans = 0
    for a in range(1, x // 3):
        for b in range(a + 1,  x // 2):
            c = x - a - b
            if b < c <= n:
                ans += 1    
    print(ans)



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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  for (int i=0 ; i<K ; i++) {
    if (i%2 == 0) {
      if (A%2 == 1) {
        A -= 1;
      }
      B += A/2;
      A -= A/2;
    } else {
      if (B%2 == 1) {
        B -= 1;
      }
      A += B/2;
      B -= B/2;
    }
  }
  cout << A << " " << B << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a, b, i, j, ans;
    int d[100];
    scanf("%d", &a);
    for(i = 0; i < a; i++){
        scanf("%d", &d[i]);
    }
    ans = 0;
    for(i = 0; i < a; i++){
        for(j = 0; j < i; j++){
            ans = ans + d[i] * d[j];
        }
    }
    printf("%d", ans);
}


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

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

  int info[4][3][10];

  for(int i = 0; i < 4; i++)
  {
    for(int j = 0; j < 3; j++)
    {
      for(int k = 0; k < 10; k++)
      {
        info[i][j][k] = 0;
      }
    }
  }

  for(int i = 0; i < n; i++)
  {
    int b = 1, f = 1, r = 1, v;
    cin >> b >> f >> r >> v;
    info[b-1][f-1][r-1] += v;
  }

  for(int i = 0; i < 4; i++)
  {
    for(int j = 0; j < 3; j++)
    {
      for(int k = 0; k < 10; k++)
      {
        if(k == 0)
        {
          cout << " ";
        }

        cout << info[i][j][k];

        if(k < 9)
        {
          cout << " ";
        }
        else
        {
          cout << endl;
          if(i != 3 && j == 2)
          {
            for(int m = 0; m < 20; m++)
            {
              cout << "#";
            }
            cout << endl;
          }
        }
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
#define pb push_back
#define ob pop_back
#define xx first
#define yy second
#define dob double
#define int long long int
#define gcd __gcd
#define f(i,m,x) for(int i = 0 ; i , m ; i+= x);
#define ss size()
using namespace std;
const long long M = 1e9 + 7 , maxn = 1e5 + 10 ;

int ans , n , m , k , x , y , q , dp[110][maxn] , sum[110][maxn];

int32_t main(){

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


      cin >> n >> k;

      int a[n];

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

      sum[0][0] = dp[0][0] = 1;

      for(int i = 1 ; i <= k ; i++){
      	dp[0][i] = (a[0] >= i);
      	sum[0][i] = sum[0][i-1] + dp[0][i];
      	//cout << 0 << " : "  << i << " : " << dp[0][i] << " : " << sum[0][i] << endl;
      }

      for(int i = 1 ; i < n ; i ++){
	    	dp[i][0] = 1;
		sum[i][0] = 1;
		//cout << i << " : " << 0 << " : " << dp[i][0] << " : " << sum[i][0] << endl;
      	for(int j = 1 ; j <= k ; j++){
      		if(j > a[i]){
      			dp[i][j] = (sum[i-1][j] - sum[i-1][j-a[i]-1] + M) % M;
      		}
      		else{
      			dp[i][j] = sum[i-1][j];
      		}
      		sum[i][j] = (sum[i][j-1] + dp[i][j]) % M;
      		dp[i][j] %= M;
			//cout << i << " : " << j << " : " << dp[i][j] << " : " << sum[i][j] << endl;
      	}
      }

      cout << dp[n-1][k] ;
     
	return 0;
}

Measured memory_bytes: 162048
import java.util.Scanner;
//import java.util.Random;

class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		
		final int n=stdIn.nextInt();
		long ans=0;
		for(int i=1;i<=n;++i){
			if(i%3==0 || i%5==0){}
			else ans+=i;
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 35700
import scala.io.StdIn

object Main extends App{
//  println("hello, world")
  val N = StdIn.readInt()
  val K = StdIn.readInt()
  val X = StdIn.readInt()
  val Y = StdIn.readInt()

  val fee = if(N > K) X * K + (N - K) * Y else X * N

  println(fee)


}


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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());


signed main()
{
    gearup;
    ll x,y; cin >> x >> y;
    ll a[] = {4,6,9,11};
    ll b[] = {1,3,5,7,8,10,12};
    map<ll,ll> aa,bb;
    rep(i,4)aa[a[i]]++;
    rep(i,7)bb[b[i]]++;
    if(x == 2){
        if(y == 2)out("Yes");
        else out("No");
    }
    else if(aa[x]){
        if(aa[y])out("Yes");
        else out("No");
    }
    else{
        if(bb[y])out("Yes");
        else out("No");
    }
}

Measured memory_bytes: 3612
X=int(input())
Y=[i for i in range(100005)]
for j in range(2,333):
  k=100004 // j  
  for a in range(2,k+1):
    Y[a*j] = 0 
b=X
while True:
  if Y[b] != 0:
    print(b)
    break
  else:
    b += 1



Measured memory_bytes: 7064
#include<iostream>
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define rep(i, j) FOR(i, 0, j, 1)
#define rrep(i, j) RFOR(i, j, 0, 1)
#define MP make_pair
#define PB push_back
#define INF (ll)1e9
#define endl "\n"
#define MOD 1000000007
#define DEB(x) cout<<"##"<<x<<"##"<<endl;
void solve()
{  
    ll n,k;
    int i=1,ans;
    cin>>n>>k;
    int ar[n+1];
    for(int i=1;i<=n;i++)
        cin>>ar[i];
    map<int,int>mp;
    vector<int>v;
    while(1)
    {
        mp[i]++;
        if(mp[i]>=2)
        {
            ans=i;
            break;
        }
        //cout<<i<<" ";
        v.PB(i);
        i=ar[i];
    }
    //cout<<ans;
    //rep(i,v.size())cout<<v[i]<<" ";
    //k++;
    for(int i=0;i<v.size();i++)
    {
        if(v[i]==ans)
        {
            //k++;
            cout<<v[i+k%(v.size()-i)];
            break;
        }
        k--;
        if(k==0)
        {
            cout<<v[i+1];
            break;
        }
    }
}

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
    solve();
    return 0;
}

Measured memory_bytes: 13792
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=2e5+100;

ll vis[N];
int32_t main(){
    ll n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    string y="";
    for (int i=0;i<2*n;i++){
        if (i%2==0){
            y+=s[i/2];
        }
        else{
            y+=t[i/2];
        }
    }
    cout << y << endl;
}


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

int main(){
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  long long kotae=a*x+b*y;
  for(int i=1;i<=max(x,y);i++){
    int a_mai=max(x-i,0);
    int b_mai=max(y-i,0);
    long long tmp=a*a_mai+b*b_mai+c*2*i;
    if(kotae>tmp)kotae=tmp;
    else break;
  }
  cout<<kotae<<endl;
  return 0;
}


Measured memory_bytes: 3576
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

//Winter Bells
public class Main{

	int[] d;
	void run(){
		Scanner sc = new Scanner(System.in);
		int INF = 1<<27;
		for(;;){
			int n = sc.nextInt(), m = sc.nextInt(), p = sc.nextInt();
			if((n|m|p)==0)break;
			int[][] wf = new int[n][n], e = new int[n][n];
			for(int[]a:wf)Arrays.fill(a, INF);
			for(int[]a:e)Arrays.fill(a, INF);
			for(int i=0;i<n;i++)wf[i][i]=0;
			for(int i=0;i<m;i++){
				int s = sc.nextInt(), t = sc.nextInt(), c = sc.nextInt();
				e[s][t] = e[t][s] = wf[s][t] = wf[t][s] = c;
			}
			for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)wf[i][j]=Math.min(wf[i][j], wf[i][k]+wf[k][j]);
			d = new int[n];
			PriorityQueue<Integer> q = new PriorityQueue<Integer>(n, new Comparator<Integer>() {
				public int compare(Integer o1, Integer o2) {
					return d[o1]-d[o2];
				}
			});
			double[] K = new double[n];
			K[n-1] = 1;
			for(int i=0;i<n;i++){
				d[i] = -wf[0][i]; q.add(i);
			}
			while(!q.isEmpty()){
				int v = q.poll();
				for(int i=0;i<n;i++){
					if(i==v || e[i][v]==INF)continue;
					if(wf[0][n-1]==wf[0][i]+e[i][v]+wf[v][n-1]){
						K[i]+=K[v];
					}
				}
			}
			double[] res = new double[n];
			res[0] = 1;
			for(int i=0;i<n;i++){
				d[i]=wf[0][i];
				q.add(i);
			}
			while(!q.isEmpty()){
				int v = q.poll();
				for(int i=0;i<n;i++){
					if(i==v || e[v][i]==INF)continue;
					if(wf[0][n-1]==wf[0][v]+e[v][i]+wf[i][n-1]){
						res[i]+=res[v]*K[i]/K[v];
					}
				}
			}
			while(p--!=0)System.out.printf("%.8f\n", res[sc.nextInt()]);
			System.out.println();
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
//Author - Rahil Malhotra
#include "bits/stdc++.h"
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int ct=0;
    int fl=0;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        if(a==b)
            ct++;
        else
            ct=0;
        if(ct>=3)
        {
            fl=1;
            break;
        }
    }
    if(fl)
        print("Yes");
    else
        print("No");
}   


Measured memory_bytes: 3636
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]
#![allow(clippy::suspicious_arithmetic_impl)]

// using Rust(1.42.0)
// My Library Repo is at "https://github.com/Loptall/prcn_lib"
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"

/*
    AtCoder Language Update 2020204 お疲れ様でした! 有難いです
*/

// Dep crates are...
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::{i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_integer::{binomial, gcd, lcm, Integer};
use permutohedron::Heap;
use petgraph::unionfind::UnionFind;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

// code...
fn main() {
    input! {
        n: usize, m: usize, x: usize,
        books: [(usize, [usize; m]); n]
    }

    let mut bit = 0;
    let mut ans = std::usize::MAX;

    while bit < 1 << n {
        let mut exp = vec![0; m];
        let mut price = 0;
        for b in 0..n {

            if bit & (1 << b) != 0 {

                price += books[b].0;
                for tc in 0..m {
                    exp[tc] += books[b].1[tc];
                }
            }
        }

        if exp.iter().all(|e| *e >= x) && ans >= price {
            ans = price;
        }
        bit += 1;
    }

    println!(
        "{}",
        if ans != std::usize::MAX {
            ans.to_string()
        } else {
            "-1".to_string()
        }
    );
}


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

int main(){
  int64_t h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h){
    cin >> s.at(i);
  }
  int maxdepth = 0;
  rep(i,h){
    rep(j,w){
      if(s.at(i).at(j) == '.'){
        vector<vector<int>> maze(w,vector<int>(h));
        rep(k,h){
          rep(l,w){
            if(s.at(k).at(l) == '#'){
              maze.at(l).at(k) = -1;
            }else{
              maze.at(l).at(k) = -2;
            }
          }
        }
        int pmaxdepth = 0;
        queue<pair<int,pair<int,int>>> DPSque;
        DPSque.push(pair<int,pair<int,int>>(0,pair<int,int>(j,i)));
        maze.at(j).at(i)=0;
        while(!DPSque.empty()){
          int depth = DPSque.front().first;
          if(pmaxdepth < depth){
            pmaxdepth = depth;
          }
          int x = DPSque.front().second.first;
          int y = DPSque.front().second.second;
          if(x-1>=0 && maze.at(x-1).at(y)!=-1 && maze.at(x-1).at(y)== -2){
            maze.at(x-1).at(y) = depth+1;
            DPSque.push(pair<int,pair<int,int>>(depth+1,pair<int,int>(x-1,y)));
          }
          if(x+1<=w-1 && maze.at(x+1).at(y)!=-1 && maze.at(x+1).at(y) == -2){
            maze.at(x+1).at(y) = depth+1;
            DPSque.push(pair<int,pair<int,int>>(depth+1,pair<int,int>(x+1,y)));
          }
          if(y-1>=0 && maze.at(x).at(y-1)!=-1 && maze.at(x).at(y-1) == -2){
            maze.at(x).at(y-1) = depth+1;
            DPSque.push(pair<int,pair<int,int>>(depth+1,pair<int,int>(x,y-1)));
          }
          if(y+1<=h-1 && maze.at(x).at(y+1)!= -1 && maze.at(x).at(y+1) == -2){
            maze.at(x).at(y+1) = depth+1;
            DPSque.push(pair<int,pair<int,int>>(depth+1,pair<int,int>(x,y+1)));
          }
          DPSque.pop();
        }
        if(pmaxdepth > maxdepth){
          maxdepth = pmaxdepth;
        }//
      }
    }
  }
  cout << maxdepth << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int MX = 100010;
ll sum[MX];
int n, m, a[MX], b[MX], p[MX];
vector<vi> e;
int root(int x){
	return p[x] == x ? x : (p[x] = root(p[x]));
}
void merge(int a, int b){
	a = root(a); b = root(b);
	if(a != b){
		p[b] = a;
		sum[a] += sum[b];
	}
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> n >> m; e.resize(n);
	rep(i, n) cin >> a[i] >> b[i];
	rep(i, m){
		int x, y; cin >> x >> y; x--; y--;
		e[x].pb(y);
		e[y].pb(x);
	}
	
	if(n == 1){
		cout << max(a[0], b[0]) << endl;
		return 0;
	}
	
	vector<tuple<ll, int, int>> es;
	rep(i, n) for(int j : e[i]) es.emplace_back(a[j] - b[j] - sum[i], i, j);
	sort(all(es));
	
	rep(i, n) p[i] = i, sum[i] = b[i];
	
	ll ans = 0;
	while(es.size()){ //計算量？
		ll mn = 1e18;
		vector<tuple<ll, int, int>> next;
		for(auto i : es){
			ll p; int q, r; tie(p, q, r) = i;
			int Q = root(q), R = root(r);
			if(Q == R) continue;
			
			ll c = a[r] - b[r] - sum[Q];
			ll st = sum[Q] > b[q] ? 0 : a[q] - b[q];
			if(ans >= st && ans >= c){
				merge(q, r);
			}
			else{
				next.emplace_back(c, q, r);
			}
			mn = min(mn, max(st, c));
		}
		if(mn < 1e18) ans = max(ans, mn);
		es = next;
		sort(all(es));
	}
	cout << ans + sum[root(0)] << endl;
	return 0;
}

Measured memory_bytes: 19820
m,d=input().split()
m,d=int(m),int(d)

c=0
if d<22:
    print(0)
else:
    for j in range(m):
        for i in range(d-21):
            d1,d10=int(str(i+22)[1]),int(str(i+22)[0])
            #print(d1)
            #print(d10)
            if d1>1 and d10>1 and d1*d10==j+1:
                c+=1
                #print(j+1,i+22)
    print(c)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}
int keta(long long x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
ll gcd(ll x, ll y){ll a,b; if(x>y){a=x; b=y;} else{a=y;b=x;} return (a%b==0 ? b: gcd(b,a%b));}
ll lcm(ll x, ll y){return x/gcd(x,y) * y;}

int main(){
  int N; cin >> N;
  cout << ( (N%10 == N/100) ? "Yes\n": "No\n");
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n,k,h,cnt=0;
  scanf("%d%d",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%d",&h);
    if(h>=k){
      cnt++;
    }
  }
  printf("%d",cnt);
  return 0;
}


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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  LL k, q;
  vector<LL> d;
  Solver2(LL k, LL q) : k(k), q(q), d(k){};

  void solve() {
    for (int i = 0; i < k; ++i) {
      cin >> d[i];
    }
    for (int i = 0; i < q; ++i) {
      LL n, x, m;
      cin >> n >> x >> m;
      cout << calc(n, x, m) << endl;
    }
  }
  LL calc(LL n, LL x, LL m) {
    DBG(n, x, m)
    vector<LL> rd(k);
    LL zero = 0, sumzero = 0;
    LL sumrd = 0, sum = x % m;
    for (int i = 0; i < k; ++i) {
      rd[i] = d[i] % m;
      sumrd += rd[i];
      if (rd[i] == 0) zero++;
    }
    LL c = n - 1;
    sum += sumrd * (c / k);
    sumzero += zero * (c / k);
    for (int i = 0; i < c % k; ++i) {
      sum += rd[i];
      if (rd[i] == 0) sumzero++;
    }
    DBG(sum)
    LL pop = sum / m;
    return n - 1 - pop - sumzero;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, m;
  std::cin >> n >> m;

  Problem::Solver2 sol(n, m);
  sol.solve();
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INF 1000000000000000001
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll K;
bool find_lower(ll a, vector<ll>& A)
{
  for (ll i = 0; i < K; ++i)
  {
    a -= a % A.at(i);
    if (a < 2)
    {
      return false;
    }
  }
  // cout << a << endl;
  return true;
}

bool find_uppper(ll a, vector<ll>& A)
{
  for (ll i = 0; i < K; ++i)
  {
    a -= a % A.at(i);
    if (a <= 2)
    {
      return false;
    }
  }
  // cout << a << endl;
  return true;
}

int main()
{
  cin >> K;
  vector<ll> A(K);
  pll ans;
  for (ll i = 0; i < K; ++i)
  {
    cin >> A.at(i);
  }
  ll lower_l = 1, lower_r = INF;
  ll m;
  while (lower_l != lower_r - 1)
  {
    m = (lower_r + lower_l) / 2;
    if (find_lower(m, A))
    {
      lower_r = m;
    }
    else
    {
      lower_l = m;
    }
  }
  ans.first = lower_r;
  ll upper_l = 1, upper_r = INF;
  while (upper_l != upper_r - 1)
  {
    m = (upper_r + upper_l) / 2;
    if (find_uppper(m, A))
    {
      upper_r = m;
    }
    else
    {
      upper_l = m;
    }
  }
  ans.second = upper_l;
  if (ans.first > ans.second)
  {
    cout << -1 << endl;
    return 0;
  }
  cout << ans.first << ' ' << ans.second << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  while(R n && n) {
    vector<string> v[33];
    map<string,int> m;
    rep(i,n) {
      string s;
      int k;
      cin >> s >> k;
      rep(j,k) {
        int x;
        R x;
        v[x].pb(s);
      }
      m[s]=0;
    }
    rep(i,33) {
      rep(j,v[i].size()) {
        m[v[i][j]]+=n-(int)v[i].size()+1;
      }
    }
    string ans="";
    int M=MAX;
    tr(it,m) {
      string s=it->F;
      int x=it->S;
      if(M>x) {
        M=x;
        ans=s;
      } else if(M==x) ans=min(ans,s);
    }
    pr(M,ans);
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3136
//#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;

#define all(a) begin(a),end(a)
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int mul(int a,int b){
  return ((a)*1ll*(b))%mod;
}

void add(int &a,int b){
  a+=b;
  if(a>=mod)a-=mod;
}

int sub(int a,int b){
  a-=b;
  if(a<0){
    a+=mod;
  }
  return a;
}

int powz(int a,int b){
  int res=1;
  while(b){
    if(b&1){
      res=mul(res,a);
    }
    b/=2;
    a=mul(a,a);
  }
  return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
  input>>x.F>>x.S;
  return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}

template<typename T>
vector<pair<T,int>> getvec(int n){
  vector<pair<T,int>>a(n);
  for(int i=0;i<a.size();i++){
    cin>>a[i].F;
    a[i].S=i;
  }
  return a;
}

void clr(auto &a,int n){
  a.clear();
  a.resize(n);
}

void unq(auto &a){
  sort(all(a));
  a.resize(unique(all(a))-a.begin());
}

const int N=200005;

vector<int>fc,inv;

int nCr(int n,int r){
  if(n<r){
    return 0;
  }
  return mul(mul(fc[n],inv[r]),inv[n-r]);
}

void prec(int n){
  fc.resize(n);
  inv.resize(n);
  fc[0]=1;
  for(int i=1;i<n;i++){
    fc[i]=mul(fc[i-1],i);
  }
  inv[n-1]=powz(fc[n-1],mod-2);
  for(int i=n-2;i>=0;i--){
    inv[i]=mul(inv[i+1],i+1);
  }
}

void solve(){
  int n,m;
  cin>>n>>m;
  cout<<(n*(n-1))/2+(m*(m-1))/2;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc=1;
  //cin>>tc;
  for(int _=0;_<tc;_++){
    //cout<<"Case #"<<_+1<<": ";
    solve();
    if(_!=tc-1){
      cout<<'\n';
    }
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int i,j,k,K,S,ans=0;
	cin>>K>>S;
	for(i=0;i<=K;i++)
		for(j=0;j<=K;j++)
		{
			k=S-i-j;
			if(k<=K&&k>=0) ans++;
		}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import Data.Ratio
import qualified Data.Map as M
main=do{([_,m,n]:s)<-map(map read.words).lines<$>getContents;print$M.findWithDefault(-1)(m%n)$M.mapKeysWith min(uncurry(%))$M.deleteMin.foldl(\h[a,b,c]->M.unionWith min h$M.mapKeys(\(k,l)->(k+a,l+b))$M.map(+c)h)(M.singleton(0,0)0)$s}

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

int main() {
  int a;
  cin >> a;
  a = a % 1000;
  if(a > 0) {
    a = 1000 - a;
    cout << a << endl;
  } else{
    cout << 0 << endl;    
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 2005;
int dp[100005], h[100005];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &h[i]);
    memset(dp, 0x3f, sizeof dp);
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for (int i = 2; i < n; i++) dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
    printf("%d\n", dp[n-1]);
    return 0;
}

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

using namespace std;

typedef long long ll;


int N, arr[3][105], dp[3][105];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= 2; ++i){
		dp[i][0] = 0;
		for (int j = 1; j <= N; ++j){
			cin >> arr[i][j];
			dp[i][j] = arr[i][j] + max(dp[i-1][j],dp[i][j-1]);
		}
	}
	cout << dp[2][N] << '\n';
	cout << flush;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    bool ok=false;
    int mn=1e9+1;
    ll sum=0;
    rep(i,n){
        cin>>a[i];
        if(a[i]<=0)ok=!ok;
        mn=min(mn,abs(a[i]));
        sum+=abs(a[i]);
    }
    if(ok==false){
        cout<<sum<<endl;
    }
    else{
        cout<<sum-(mn*2)<<endl;
    }
}

Measured memory_bytes: 640
module DirectedGraph
  (* 道の表現 *)
  (Path : sig
    type t
    (* 辺の名前 *)
    type edge
    (* 長さ0の道 *)
    val nil : t
    (* 道の後ろに辺を付け足した道 *)
    val snoc : t -> edge -> t
  end) :
sig
  (* BFSにより，重みのないグラフの最短経路を求める *)
  val bfs :
    (* 頂点数（Hashtblを用いるので目安程度） *)
    int ->
    (* 辺の名前が付いた隣接リスト *)
    ('v -> ('v * Path.edge) list) ->
    (* 始点 *)
    'v ->
    (* 最短経路を返す関数 辿り着けなければNoneを返す） *)
    ('v -> Path.t option)
end = struct
  let rec bfs_aux es d frontier t =
    try Some (Hashtbl.find d t) with
    | Not_found ->
        match !frontier with
        | [] -> None
        | _ :: _ ->
            frontier := List.fold_right (fun u ->
              List.fold_right (fun (v, e) frontier ->
                if Hashtbl.mem d v
                then frontier
                else (Hashtbl.add d v (Path.snoc (Hashtbl.find d u) e); v :: frontier))
              (es u)) !frontier [];
            bfs_aux es d frontier t

  (*
   * 終点に辿り着いた時点で探索を切り上げるが，
   * 戻り値の関数を覚えておくと，途中まで探索した結果が再利用される
   * （#trace bfs_aux すると分かりやすい）
   *)
  let bfs n es s =
    let d = Hashtbl.create n in
    Hashtbl.add d s Path.nil;
    let frontier = ref [s] in
    bfs_aux es d frontier
end

module G = DirectedGraph (struct
  type t = int
  type edge = unit
  let nil = 0
  let snoc p () = p + 1
end)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ ->
    Scanf.scanf "%d\n" @@ fun a -> a - 1 in
  Printf.printf "%d\n" @@
  match G.bfs n (fun v -> [(as_.(v), ())]) 0 1 with
  | None -> -1
  | Some n -> n

Measured memory_bytes: 8192
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long h = in.nextLong();
            out.println(q(h));
        }

        private long q(long h) {
            if (h == 0)
                return 0;
            if (h == 1)
                return 1;
            return 1 + 2 * q(h / 2);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



Measured memory_bytes: 23252
p=2019
s,a,d,z=input()[::-1],0,0,[0]*p
for i,j in enumerate(s):
	d=(d+(int(j)*pow(10,i,p)))%p
	z[d]+=1
r=z[0]
for i in range(p):
	l=z[i]
	r+=l*(l-1)//2
print(r)

Measured memory_bytes: 9372
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 10005
using namespace std;
int n;
string in[M];
int main()
{
    
    while (~scanf("%d",&n)) {
        int ans = 0;
        REP(i,1,n) cin >> in[i];
        REP(i,1,n) REP(j,1,(int)in[i].length()-1) {
            if (in[i][j-1]=='A' && in[i][j]=='B')
                ans++;
        }

        int a=0, b=0, ab=0;
        REP(i,1,n) {
            if (in[i][0]=='B' && in[i].back()=='A') {
                ab++;
            } else if (in[i][0]=='B') {
                a++;
            } else if (in[i].back() == 'A') {
                b++;
            }
        }

        if (ab) {
            ans += ab-1;
            ab = 1;
        }
        if (ab) {
            if (b && a) {
                ans += 2;
                ab--;
                b--;
                a--;    
            } else if (b) {
                ab--;
                ans++;
            } else if (a) {
                ab--;
                ans++;
            }
        }
        ans += min(a,b);
        printf("%d\n", ans);
    }
    return 0;
}







Measured memory_bytes: 768
N,M,C = map(int,input().split())
bli = list(map(int,input().split()))

ans = 0
for i in range(N):
  a = list(map(int,input().split()))
  tmp = 0
  for j in range(M):
    tmp += a[j]*bli[j]
  if tmp + C > 0:
    ans += 1
print(ans)

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

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

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

  int result = 0;

  rep(i, b - a + 1) {
    string str = to_string(a + i);

    if (str[0] == str[4] && str[1] == str[3]) {
      result++;
    }
  }

  cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>

using namespace std;

typedef vector<int> VI;
typedef pair<int, int> P;
typedef long long ll;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

#define ALL(a)  (a).begin(),(a).end()
#define UNIQUE(a)  (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_buck
#define EACH(i,c) REP(i,(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,n,0)

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";

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

int n, m, s, t;
ll k;
VI es;
string str;
ll a[100000];
int b[100000];

ll d[31];
ll ans=0;
void smax(ll f){
	ll res=0;
	REP(i,n)if((f|a[i]) == f){
		res+=b[i];
	}
	ans=max(ans, res);
}

void dfs(int highest, ll f){
	if(highest >= 0 && ((1<<highest) & k)){
		dfs(highest-1, f|(1<<highest));
		smax(f | ((1<<highest)-1));
	}else{
		if(highest>0){
			dfs(highest-1, f);
		}else{
			smax(f);
		}
	}
}

int main() {
	cin>>n>>k;
	REP(i,n){
		cin>>a[i]>>b[i];
	}
	dfs(29, 0);
	cout << ans << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdint>

int main() {
  int N;
  std::int64_t D;
  std::cin >> N >> D;
  int count = 0;
  for (int i = 0; i < N; ++i) {
    std::int64_t X, Y;
    std::cin >> X >> Y;
    count += X * X + Y * Y <= D * D;
  }
  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 3632
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto N = RD;
	auto S = RD!string;
	
	auto cnt = new long[][](N+1, 3);
	auto str = ['R':0, 'G':1, 'B':2];
	foreach_reverse (i; 0..N)
	{
		cnt[i][] += cnt[i+1][];
		auto j = str[S[i]];
		++cnt[i][j];
	}

	long ans;
	foreach (i; 0..N)
	{
		auto c1 = str[S[i]];
		foreach (j; i+1..N)
		{
			auto c2 = str[S[j]];
			if (c1 == c2) continue;
			auto c3 = 3 - (c1+c2);
			ans += cnt[j][c3];
			auto d = j - i;
			if (j+d >= N) continue;
			if (str[S[j+d]] == c3)
				--ans;
		}
	}

	writeln(ans);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 2868
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vvi				vector< vi > 
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define loop(i,n)		for(int i=0;i<n;i++)
#define Loop(i,n)		for(int i=1;i<=n;i++)
#define sz(a)			int(a.size())
#define all(c) 			c.begin(),c.end()
#define tr(c,i) 		for(auto i = c.begin(); i != c.end(); i++)
#define present(c,x) 	(c.find(x) != c.end())
#define cpresent(c,x) 	(find(all(c),x) != c.end())
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
void Gur27()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
 
int32_t main()
{
    Gur27();
    int a,b,c,d,k=1;
    cin>>a>> b>> c>> d;
    while(a>0 && c>0)
    {
    if(k%2!=0)
    {
        c=c-b;
        if(c<=0) break;
    }
    else
    {
        a=a-d;
        if(a<=0) break;
    }
    k++;
    }
    cout<<(k%2?"Yes":"No");
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,a; cin >> n >> a;
    ll ans=n;
    for(int i=2;i<50;i++){
        ll left=1,right=10000001;
        while(right-left>1){
            ll mid=(left+right)/2;
            ll tmp=1;
            for(int j=0;j<i;j++){
                tmp*=mid;
                if(tmp>n)break;
            }
            if(tmp>n){
                right=mid;
            }
            else{
                left=mid;
            }
        }
        for(int j=0;j<i+1;j++){
            ll tmp=1;
            for(int k=0;k<j;k++){
                tmp*=left;
            }
            for(int k=0;k<i-j;k++){
                tmp*=right;
            }
            if(tmp>=n){
                ans=min(ans,left*i+i-j+a*(i-1));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
function main(lines) {
    const input = lines.split(' ').map(function(val){return parseInt(val);})
    const a = input[0]
    const b = input[1]
    const c = input[2]
    let count = 0
    for(let i=a; i<=b; i++){
        if(c%i === 0){
            count++
        }
    }
    console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 15396