akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
P sch(int h, int w, int top, int l, const vvi &u, const vvi &suv, int over, vector<vector<vector<vector<P>>>> &memo) {
  int mag = 1;
  int ma = suv[top+h][l+w] - suv[top][l+w] - suv[top+h][l] + suv[top][l] - over;
  P res = make_pair(mag, ma);
  if(ma < 0) return {-1, -1};
  for(int i=0;i<h-1;++i) {
    if(ma + over < 2 * over) break;
    P p1, p2;
    if(memo[i+1][w][top][l] == make_pair(-1, -1)) {
      p1 = sch(i+1, w, top, l, u, suv, over, memo);
      memo[i+1][w][top][l] = p1;
    } else {
      p1 = memo[i+1][w][top][l];
    }
    if(memo[h-i-1][w][top+i+1][l] == make_pair(-1, -1)) {
      p2 = sch(h-i-1, w, top+i+1, l, u, suv, over, memo);
      memo[h-i-1][w][top+i+1][l] = p2;
    } else {
      p2 = memo[h-i-1][w][top+i+1][l];
    }
    if(p1.first == -1 || p2.first == -1) continue;
    P tmp = make_pair(p1.first + p2.first, min(p1.second, p2.second));
    res = max(res, tmp);
  }
  for(int i=0;i<w-1;++i) {
    if(ma + over < 2 * over) break;
    P p1, p2;
    if(memo[h][i+1][top][l] == make_pair(-1, -1)) {
      p1 = sch(h, i+1, top, l, u, suv, over, memo);
      memo[h][i+1][top][l] = p1;
    } else {
      p1 = memo[h][i+1][top][l];
    }
    if(memo[h][w-i-1][top][l+i+1] == make_pair(-1, -1)) {
      p2 = sch(h, w-i-1, top, l+i+1, u, suv, over, memo);
      memo[h][w-i-1][top][l+i+1] = p2;
    } else {
      p2 = memo[h][w-i-1][top][l+i+1];
    }
    if(p1.first == -1 || p2.first == -1) continue;
    P tmp = make_pair(p1.first + p2.first, min(p1.second, p2.second));
    res = max(res, tmp);
  }
  return res;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    int h, w, s; cin >> h >> w >> s;
    if(h == 0) break;
    vvi u(h, vi(w));
    vvi suv(h+1, vi(w+1, 0));
    int su = 0;
    for(int i=0;i<h;++i) {
      for(int j=0;j<w;++j) {
        cin >> u[i][j];
        su += u[i][j];
        suv[i+1][j+1] = suv[i+1][j] + suv[i][j+1] - suv[i][j] + u[i][j];
      }
    }
    int over = su - s;
    vector<vector<vector<vector<P>>>> memo(h+1, vector<vector<vector<P>>>(w+1, vector<vector<P>>(h+1, vector<P>(w+1, {-1, -1}))));
    P ans = sch(h, w, 0, 0, u, suv, over, memo);
    cout << ans.first << " " << ans.second << endl;
  }
}



Measured memory_bytes: 13748
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>

long parse100x(const char* str)
{
	auto s = const_cast<char*>(str);
	std::int64_t n0 = 0;
	std::int64_t n1 = 0;
	bool decimal = false;

	while (*s)
	{
		if (*s == '.')
		{
			decimal = true;
			s++;
			continue;
		}

		if (isdigit(*s))
		{
			if (decimal)
				n1 = n1 * 10 + static_cast<std::int64_t>(*s - '0');
			else
				n0 = n0 * 10 + static_cast<std::int64_t>(*s - '0');
		}

		s++;
	}

	return n0 * 100 + n1;
}

int main()
{
	std::int64_t a;
	std::string b;
	std::cin >> a;
	std::cin >> b;
	std::cout << (std::int64_t)(a * parse100x(b.c_str()) / 100) << std::endl;
}


Measured memory_bytes: 3196
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }


int main() {
	
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int t = c / b;
	if (c % b != 0) t++;
	int ao = a / d;
	if (a % d != 0) ao++;
	if (t <= ao) {
		cout << "Yes" << endl;

	}
	else {
		cout << "No" << endl;

	}

}




Measured memory_bytes: 3652
// AOJ 1503: Numbers
// 2017.10.11 bal4u@uu

#include <stdio.h>

#define N       1000000000
#define MAXINT  500
#define MAXBUF  4200

void mpNum2Str(char *str, int *num)
{
    int  i, j;
    char *ss;
    int  x;

    if (*num == 0 || (*num == 1 && *(num+1) == 0)) {
        *str++ = '0';
        *str = '\0';
        return;
    }

    ss = str - 1;
    for (i = *num; i > 0; i--) {
        x = *++num;
        for (j = 1; j < N; j *= 10) {
            *++ss = x % 10 + '0';
            x /= 10;
        }
    }
    while (*ss == '0') ss--;

    *(ss + 1) = '\0';    
    while (str < ss) {
        x = *str;
        *str++ = *ss;
        *ss-- = x;
    }
}

void mpAdd(int *ret, int *a, int *b)
{
    int  i;
    int  lr, la, lb;
    int  *rr;
    int  x;

    la = *a;
    lb = *b;
    lr = (la >= lb) ? la : lb;

    rr = ret;
    x = 0;
    for (i = 1; i <= lr; i++) {
        if (i <= la) x += *++a;
        if (i <= lb) x += *++b;
        if (x < N) {
            *++rr = x;
            x = 0;
        } else {
            *++rr = x - N;
            x = 1;
        }
    }
    *++rr = x;
    *ret = lr + x;
}

void mpMul(int *ret, int *a, int *b)
{
    int  i, j;
    int  la, lb;
    int  *aa;
    int  ca;
    long long x;

    la = *a;
    lb = *b;

    if (la == 0 || lb == 0) {
        *ret = 0;
        return;
    }

    for (i = la + lb; i > 0; i--) *(ret + i) = 0;

    for (j = 1; j <= lb; j++) {
        ca = 0;
        b++;
        for (i = 1, aa = a; i <= la; i++) {
            x = *++aa;
            x = x * *b + *(ret + i + j - 1) + ca;
            *(ret + i + j - 1) = x % N;
            ca = x / N;
        }
        *(ret + i + j - 1) = ca;
    }
    
    *ret = (ca != 0) ? la + lb : la + lb - 1;
}

int  f[2][MAXINT];
char buf[MAXBUF];

int main()
{
	int n, i, k1, k2;
	int a[2];

	scanf("%d", &n);
	if (n == 1) { puts("4\n2"); return 0; }
	f[0][0] = f[0][1] = 1, a[0] = 1;
	for (k1 = 0, k2 = 1, i = 2; i <= n+1; i++, k1 = k2, k2 = !k2) {
		a[1] = i;
		mpMul(f[k2], f[k1], a);
	}
	a[1] = 2;
	mpAdd(f[k2], f[k1], a);
	mpNum2Str(buf, f[k2]);
	puts(buf);
	for (i = 1; i <= n; i++) printf("%d\n", i+1);
	return 0;
}

Measured memory_bytes: 1832
open System

let rec isSubList xs ys =
    match xs, ys with
    | [], _ -> true
    | _, [] -> false
    | x::xs, y::ys when x = y -> isSubList xs ys
    | xs, y::ys -> isSubList xs ys

let n = stdin.ReadLine() |> int
let s = stdin.ReadLine() |> Seq.toList

let a = List.sum [
    for i in ['0'..'9'] do
    for j in ['0'..'9'] do
    for k in ['0'..'9'] ->
    if isSubList [i; j; k] s then 1 else 0 ]
 
printfn "%d" a

Measured memory_bytes: 22248
#include <stdio.h>

int main(void) {
  int N, K, i, j, temp;
  int sum = 0;
  int x[1000];

  scanf("%d %d", &N, &K);
  for(i=0; i<=N-1; i++)
    scanf("%d", &x[i]);

  for(i=0; i<N-1; i++) {
    for(j=N-1; j>i; j--) {
      if (x[j-1] > x[j]) {
        temp = x[j-1];
        x[j-1] = x[j];
        x[j] = temp;
      }
    }
  }
  for(i=0; i<=K-1; i++)
    sum += x[i];
  printf("%d", sum);

  return 0;
}

Measured memory_bytes: 1736
#include<iostream>
#include<string>
using namespace std;
int main(){
	int t,n,s,f;
	while(true){
	cin>>t;
	if(t==0)
		break;
	cin>>n;
	int count=0;
	for(int i=0;i<n;i++){
		cin>>s>>f;
		count+=f;
		count-=s;
	}
	if(count>=t)
		cout<<"OK"<<endl;
	else
		cout<<t-count<<endl;
	}
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

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

	long long max = -1e18;

	if (a * c > max)
		max = a * c;
	if (a * d > max)
		max = a * d;
	if (b * c > max)
		max = b * c;
	if (b * d > max)
		max = b * d;

	cout << max << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll fexp (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = fexp (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return fexp (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/gcd(num1,num2))*num2;}
// end of Template
bool vis[100010];
int c,a[100010],ans,n;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

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

    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    int idx = 1;
    ans = -1;
    while(idx!=2){
        vis[idx] = true;
        idx = a[idx];
        if(vis[idx])break;
        c++;
        if(idx==2)ans = c;
    }
    cout<<ans<<newl;
}


Measured memory_bytes: 768
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

int syo(int x,int y){
  if(x>y)return y;
  else return x;
}  

void enque(P x){
  Q[tail]=x;
  tail=(tail+1)%LEN;

}

P deque(){

  P y=Q[head];
  head=(head+1)%LEN;
  return y;
}


int main(){
  int elaps=0,c,i,q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head=1;
  tail=n+1;
  while(head!=tail){
    u=deque();
    c=syo(q,u.t);
    u.t=u.t-c;
    elaps=elaps+c;
    if(u.t>0)enque(u);
    else printf("%s %d\n",u.name,elaps);
  }
  return 0;
}



Measured memory_bytes: 11852
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;
	static boolean[] isPrime;
	static final int MAX_INDEX = 123456*2;
	public static void main(String[] args) {
		makePrime();
		while(read()){
			solve();
		}
	}
	static void makePrime(){
		isPrime = new boolean[MAX_INDEX + 1];
		isPrime[1] = false;
		for(int i = 2; i < isPrime.length; i++)isPrime[i] = true;
		for(int i = 2; i <= MAX_INDEX; i++){
			if(isPrime[i] == true){
				for(int j = 2; j*i <= MAX_INDEX; j++){
					isPrime[i*j] = false;
				}
			}
		}
	}
	static boolean read(){
		n = sc.nextInt();
		if(n == 0)return false;
		return true;
	}
	static void solve(){
		int count = 0;
		for(int i = n+1; i <= 2*n; i++){
			if(isPrime[i] == true)count++;
		}
		System.out.println(count);
	}
}

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

int main(){
	char yoho[4], jitu[4];
	scanf("%s", yoho);
	scanf("%s", jitu);
	int count=0;
	for(int i=0; i<3; i++){
		if(yoho[i]==jitu[i]) count++;
	}
	printf("%d", count);
	
	return 0;
}

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

int main()
{
	long long n = 0, k = 0, l = 10000000, m = 0;

	cin >> n;
	m = n;
	
	for (int i = 0; i < 8; i++) {
		k += m / l;
		m = m % l;
		l /= 10;
	}

	if(n % k == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
I = [i+1 for i in range(N)]
S, P = [], []
for _ in range(N):
    inp = input().split()
    S.append(inp[0])
    P.append(int(inp[1]))

for i in range(N-1):
    for j in range(i+1, N):
        if S[i] > S[j] or (S[i] == S[j] and P[i] < P[j]):
            tmp = S[i]
            S[i] = S[j]
            S[j] = tmp
            tmp = P[i]
            P[i] = P[j]
            P[j] = tmp
            tmp = I[i]
            I[i] = I[j]
            I[j] = tmp

for i in I:
    print(i)


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

int main(){
 long long N,b,c,d,p;
cin>>N;
  double ans,ans2;
  ans2=0;
  vector<double>a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
    ans2+=1.0/a[i];
  }
  ans=1.0/ans2;
    cout<<std::setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int N,i,j,flag,temp=0,count=0;

  scanf("%d",&N);

  int A[N];

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }


  for(i=0;i<N;i++){

  flag = 1;

  while(flag){
    flag=0;
    for(j=N-1;1<=j;j--){
	if(A[j] < A[j-1]){
	  temp = A[j-1];
	  A[j-1] = A[j];
	  A[j] = temp;
	  flag=1;
	  count++;
	}

      }
  }
  }

  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);
  printf("%d\n",count);


  return 0;
}
      

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

int main(){
    int n,ans=0,na=0,nb=0,c=1;
    string temp;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>temp;
        if(temp.front()=='B'){
            nb++;
            if(temp.back()!='A'){c=0;}
        }
        if(temp.back()=='A'){na++;}
        for(int j=0;j<temp.size()-1;j++){
            if(temp[j]=='A'){
                if(temp[j+1]=='B'){ans++;}
            }
        }
    }
    if(na==nb && na>0 && c==1){ans+=min(na,nb)-1;}
    else{ans+=min(na,nb);}
    cout<<ans<<endl;
}


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

int n ;
int w_size , s_size ;
string word ;
string s ;

int f( int p ){
	
	for( int k=1 ; k<w_size ; k++ ){
		if( word[k] == s[p%s_size] ) p++ ;
		else return 0 ;
	}
	
	return 1 ;
}

int main(){
	
	cin >> word ;
	cin >> n ;
	
	w_size = word.size() ;
	
	int ans=0 ;
	for( int i=0 ; i<n ; i++ ){
		cin >> s ;
		s_size = s.size() ;
		for( int j=0 ; j<s_size ; j++ ){
			if( word[0] == s[j] && f(j+1) ){
				ans++;
				break ;
			}
		}
	}
	
	cout << ans << endl ;
	
return 0 ;
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {        
    int n;
    cin >> n;
    unordered_set<int> us1, us2;
    us1.insert(1);
    vector<int> c(13, 0);
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        c[t]++;
        int max_val = 0;
        for (auto tt : us1) {
            int last = -1;
            int flag = 1;
            for (int i = 0; i < 24; i++) {
                if ((tt & (1 << i)) > 0) {
                    if (last != -1) {
                        if (i - last == 1) {
                            flag = 0;
                            break;
                        }
                    }
                    last = i;
                }
            }
            if (flag == 0) continue;
            if ((tt & (1 << t)) == 0) us2.insert(tt | (1 << t));
            if ((tt & (1 << (24 - t))) == 0 && t != 0) us2.insert(tt | (1 << (24 - t)));
        }
        swap(us1, us2);
    }

    for (int i = 1; i <= 12; i++) {
        if (c[i] >= 3 || c[0] > 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    int res = 1;
    for (auto t : us1) {
        vector<int> v;
        for (int i = 0; i < 24; i++) {
            if ((t & (1 << i)) > 0) v.push_back(i);
        }
        if (n + 1 > v.size()) continue;
        int r = 24;
        if (v.size() > 0) r = min(r, -v.back() + 24 + v[0]);
        for (int i = 0; i < v.size() - 1; i++) {
            r = min(r, v[i + 1] - v[i]);
        }
        res = max(r, res);
    }
    cout << res << endl;
}


Measured memory_bytes: 10880
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	static final Scanner in = new Scanner(System.in);
	
	private static int[] input(){
		int len = in.nextInt();
		len *= 2;
		int a[] = new int[len];
		for(int i=0; i<len; i++)
		{
			a[i] = in.nextInt();
		}
		return a;
	}
	
	private static int solve(int a[])
	{
		Arrays.sort(a);
		int ingr = 0;
		for(int i=0; i<a.length; i+=2)
		{
			ingr += a[i];
		}
		return ingr;
	}

	public static void main(String[] args) {
		System.out.println(solve(input()));
	}

}


Measured memory_bytes: 9808
import java.util.*;

public class Main {
    public static final void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        HashSet<Long> set = new HashSet<>();
        for (int i = 0; i < N; i++) {
            long a = sc.nextLong();
            if (set.contains(a)) set.remove(a);
            else set.add(a);
        }
        System.out.println(set.size());
    }
}


Measured memory_bytes: 64172
#include<bits/stdc++.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if((a==1&&b==2)||(a==2&&b==1))
    {
        printf("3");
    }
    else if((a==2&&b==3)||(a==3&&b==2))
    {
        printf("1");
    }
    else
    {
        printf("2");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
n = int(input())
t,a = map(int, (input().split()))
h = map(int, input().split())
h = list(h)
m = float(1000000)
index = -1
for i in range(n):
    tt = t - (h[i] * 0.006)
    diff = abs(a - tt)
    if diff < m:
        m = diff
        index = i + 1
print(index)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

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

	int x, a;
	scanf("%d%d", &x, &a);
	printf("%d\n", (x < a)? 0 : 10);
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        // ?¨??????\??????????????????????????????????????????                                    
        Scanner sc = new Scanner(System.in); int w = sc.nextInt();
        int n = sc.nextInt();
        int[] values = new int[w];
        for (int i = 0; i < values.length; i++) {
            values[i] = i + 1;
        }
        for (int i = 0; i < n; i++) {
            String str = sc.next();
            String[] ab = str.split(",");
            int a = Integer.parseInt(ab[0]) - 1;
            int b = Integer.parseInt(ab[1]) - 1;
            // a??¨b????????£???values??????????????????                                   
            int	c;
            c =	values[a];
            values[a] =	values[b];
            values[b] =	c;
        }
        // values??????????????????                                           
        for(int i = 0; i < n; i++){
            System.out.println(values[i]);
        }
    }
 }

Measured memory_bytes: 26216
#include <stdio.h>

main(void)
{
	int H,W,a,b;
	
	while(1){
		scanf("%d%d",&H,&W);
		
		if(H==0 && W==0) break;
		
		for(a=1;a<=H;a++){
			for(b=1;b<=W;b++){
				if(a%2==1){
					if(b%2==1)printf("#");
					else if(b%2==0)printf(".");
				}
				
				else if(a%2==0){
					if(b%2==1)printf(".");
					else if(b%2==0)printf("#");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}
	

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;

int main() {
    int N;
    string S;
    cin >> N >> S;

    vector<int> a_l(N,0);
    vector<int> a_r(N,0);

    rep(i,1,N) {
        if (S[i-1]=='W') {
            a_l[i] = a_l[i-1]+1;
        }
        else {
             a_l[i] = a_l[i-1];
        }
    }

    for (int i=N-2; i>=0;i--) {
        if (S[i+1]=='E') {
            a_r[i] = a_r[i+1]+1;
        }
        else {
             a_r[i] = a_r[i+1];
        }
    }

    int ans = INF;

    rep(i,0,N) {
        ans = min(ans,a_l[i]+a_r[i]);

    }

    cout << ans << endl;

 }



Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int t1=n;
	int t2=m;
	for(int i=0;i<t2-1;i++)
	{
		n = n*10+t1;
	}
	for(int i=0;i<t1-1;i++)
	{
		m = m*10+t2;
	}
	if(n>=m)
	cout<<n;
	else
	cout<<m;
	return 0;
}

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

int main(void){
  int N,a,b,c,d,e,f,g,x,y;
  int i,t,j;
  long H,ans,T;
  t=0;
  if(scanf("%ld",&H)>1){
    exit(1);
  }
  //printf("%ld\n",H);
  ans=0;
  //T=1;
  for(i=0;;i++){
    //printf("%ld %d\n",H,i);
    H=H/2;
    ans+=1*pow(2.0,i);
    if(H<1)break;
  }
  printf("%ld",ans);
  return 0;
}


Measured memory_bytes: 128
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
lint n,a;

lint doit(lint a,lint b){
  __int128 x=a*(__int128)b;
  if(x>n) return n;
  return x;
}
int main(){
  cin>>n>>a;

  lint lb=0,ub=1.1e12;
  while(ub-lb>1){
    lint md=(lb+ub)>>1;

    bool suc=false;
    for(lint i=0;i<50;++i){
      lint time=md-i*a;
      if(time<0) continue;

      lint dur=time/(i+1);
      lint x=time%(i+1),y=(i+1)-x;//x for dur+1, y for dur

      lint mul=1;
      REP(i,x) mul=doit(mul,dur+1);
      REP(i,y) mul=doit(mul,dur);
      if(mul>=n) suc=true;
    }
    if(suc) ub=md;
    else lb=md;
  }
  cout<<ub<<endl;
  return 0;
}





Measured memory_bytes: 384
fn main() {
  let (n, m): (usize, usize) = read_tuple();
  let edges: Vec<(usize, usize)> = read_tuples(m);

  let mut graph: Vec<Vec<usize>> = vec![vec![]; n+1];
  for (v,w) in edges {
    graph[v].push(w);
    graph[w].push(v);
  }

  match is_bipartite(&graph) {
    (p, _) if !p     => {println!("{}", n * (n-1) / 2 - m)},
    (_, Some((b,w))) => {println!("{}", b*w - m)},
    _ => unreachable!()
  }
}

fn is_bipartite(g: &Vec<Vec<usize>>) -> (bool, Option<(usize, usize)>) {
  fn dfs(v: usize, p: bool, g: &Vec<Vec<usize>>, cv: &mut Vec<Option<bool>>) -> bool {
    match cv[v] {
      None => {
        let next = &g[v];
        cv[v] = Some(p);
        next.iter().all(|&w|dfs(w,!p,g,cv))
      },
      Some(q) if q == p => {true},
      Some(q) if q != p => {false},
      _ => unreachable!()
    }
  }

  let mut canvas: Vec<Option<bool>> = vec![None; g.len()];
  let ans = dfs(1, false, g, &mut canvas);
  let b = canvas.iter().filter(|&&v|v==Some(false)).count();
  let w = canvas.iter().filter(|&&v|v==Some(true)).count();
  (ans, if ans {Some((b,w))} else {None})
}

fn read_tuple<T1: std::str::FromStr, T2: std::str::FromStr>() -> (T1, T2) {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  let mut it = buf.trim().split_whitespace();
  let x = it.next().unwrap().parse::<T1>().ok().unwrap();
  let y = it.next().unwrap().parse::<T2>().ok().unwrap();
  (x, y)
}

fn read_tuples<T1: std::str::FromStr, T2: std::str::FromStr>(n: usize) -> Vec<(T1, T2)> {
  let mut vec: Vec<(T1, T2)> = vec![];
  for _ in 0 .. n {
    vec.push(read_tuple());
  }
  vec
}

Measured memory_bytes: 12796
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair 
#define pii pair<int,int> 

int main () {
	string s;
	cin >> s;
	int ans = 0;
	fop (i,0,s.length()/2) {
		if (s[i] != s[s.length()-i-1]) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int result;
		if(A != B) {
			if(A >= B) {
				result = A * 2 - 1;
			}else {
				result = B * 2 - 1;
			}
		}else {
			result = A + B;
		}
		System.out.println(result);
	}

}


Measured memory_bytes: 21844
int bubbleSort(int *A, int N){
    
    int flag = 1;
    int i;
    int tmp;
    int rtn =0;
    while(flag){
        flag = 0;
        for(i = N-1; i>0; i--){
            if(A[i-1] > A[i]){
                tmp = A[i-1];
                A[i-1] = A[i];
                A[i] = tmp;
                flag = 1;
                rtn++;
            }
        }
    }
    return rtn;
}

int main(void){
    int N;
    int A[100];
    int swap_num;
    int i;
    scanf("%d", &N);
    for(i=0; i<N; i++) scanf("%d", &A[i]);
    
    swap_num = bubbleSort(A, N);
    
    for(i = 0; i< N; i++){
        if(i==N-1){
            printf("%d\n", A[i]);
        }else{
            printf("%d ", A[i]);
        }
    }
    printf("%d\n", swap_num);
    
    return 0;
}

Measured memory_bytes: 600
import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val n = input.nextLine().toInt
      val as = input.nextLine().split(" ").map(_.toInt)

      val result = as.sum - as.length

      output.println(result)
    }

  }

}


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

long long int factorial[100010];

long long int reciprocal[100010];

long long int MOD = static_cast<long long int>(1e9) + 7;

long long int my_pow(long long int a, long long int k) {
    if (k == 0) return 1;
    long long int res = my_pow(a, k / 2);
    res = res * res % MOD;
    if (k & 1) res = res * a % MOD;
    return res;
}

long long int comb(long long int n,long long int r){

    if(n < r){
        return 0;
    }

    if(r == 0){
        return 1;
    }

    return (factorial[n] * reciprocal[n-r] % MOD * reciprocal[r]) % MOD;

}

int main() {

    factorial[0] = 1;
    reciprocal[0] = 1;

    for(long long int i=1; i<100010; i++){
        factorial[static_cast<int>(i)] = factorial[static_cast<int>(i-1)]*i;
        factorial[static_cast<int>(i)] %= MOD;
        reciprocal[static_cast<int>(i)] = my_pow(factorial[static_cast<int>(i)],MOD - 2);
        reciprocal[static_cast<int>(i)] %= MOD;
    }

    int n;

    cin >> n;

    int a[n];

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

    set<int> s;
    int my_left=0,my_right=0;

    for(int i=0; i<n+1; i++){
        if(s.find(a[i]) != s.end()){
            my_right = i;
            for(int j=0; j<n+1; j++){
                if(a[j] == a[i]){
                    my_left = j;
                    break;
                }
            }
            break;
        }
        s.insert(a[i]);
    }

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

        long long int all_c = comb(n+1,k);
        long long int same_c = comb(my_left+n-my_right,k-1);

        cout << (all_c - same_c + MOD)%(MOD) << endl;
    }

    return 0;
}

Measured memory_bytes: 7808
#![allow(dead_code)]
use std::io;

fn main() {
    solve_d();
}

fn solve_d() {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    let n = n.trim().parse::<usize>().unwrap();

    let mut min = 0;
    //let mut max = 1;
    let mut already = 0;
    let mut diff = i64::min_value();
    let mut vv = vec![0; n];
    for i in 0..n {
        let mut v = String::new();
        io::stdin().read_line(&mut v).unwrap();
        vv[i] = v.trim().parse::<i64>().unwrap();

        if 1 < i {
            for j in already..i {
                //println!("already: {:?}, j: {}, i: {}", already, j, i);
                if vv[j] < vv[min] {
                    min = j;
                    //println!("min: {:?}", min);
                }
            }
            already = i - 1;
        }
        if 0 < i {
            let diff_tmp = vv[i] as i64 - vv[min] as i64;
            //println!("diff_tmp: {:?}, i: {}, min: {}", diff_tmp, i, min);
            if diff < diff_tmp {
                diff = diff_tmp
            }
        }

        /*
        for j in min..max {
            let new_diff = vv[max] as i64 - vv[j] as i64;
            if diff < new_diff {
                diff = new_diff;
                min = j;
            }
        }
        */
        //println!("min: {:?}, max: {:?}, diff_tmp: {:?}", min, max, diff_tmp);
    }
    println!("{}", diff);
}



Measured memory_bytes: 7092
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}

struct node
{
    int x, id;
    bool operator<(const node &o) const {
        return x < o.x;
    }
};
node a[maxn];

int main(void) {
    FAST_IO;
    
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i].x;
        a[i].id = i + 1;
    }
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
        if (i == 0) cout << a[i].id;
        else cout << ' ' << a[i].id;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
s = input()
cnt = 0
idx = 1
tmp = ''
hit = True
while(hit):
	hit = False
	for i in range(idx, len(s)):
		if s[i-1:i+1] == '01' or s[i-1:i+1] == '10':
			tmp = s[0:i-1] + s[i+1: ]
			cnt += 2
			idx = i - 1 if i > 1 else 1
			hit = True
			s = tmp
			break
            
print (cnt)

Measured memory_bytes: 3428
#include<bits/stdc++.h>
using namespace std;
string s;
int l;
int main(){
    cin>>s;
    l=s.size();
    for(int i=0;i<l;i++)
        if(s[i]=='C')
        for(int j=i+1;j<l;j++)
        if(s[j]=='F') return cout<<"Yes",0;
    cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int w,h;
  int i,j,k,c,t,r,x[2600],y[2600],ny,nx;
  int X[]={1,1,1,0,0,-1,-1,-1};
  int Y[]={1,0,-1,1,-1,1,0,-1};
  while(scanf("%d %d",&w,&h),w||h){
    int d[52][52]={0};
    for(i=c=0;i<h;i++){
      for(j=0;j<w;j++){
	scanf("%d",&d[i+1][j+1]);
      }
    }
    for(i=1;i<=h;i++){
      for(j=1;j<=w;j++){
	if(d[i][j]){
	  y[  0]=i; 
	  x[t=0]=j;
	  d[i][j]=0;
	  c++;
	  for(r=1;r-t;t++){
	    for(k=0;k<8;k++){
	      ny=y[t]+Y[k];
	      nx=x[t]+X[k];
	      if(d[ny][nx]==0)continue;
	      x[r  ]=nx;
	      y[r++]=ny;
	      d[ny][nx]=0;
	    }
	  }
	}
      }
    }
    printf("%d\n",c);
  }
  return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

bool is_prime[200100];
int prime[200100];

void sieve(int n) {
	int p = 0;
	fill(is_prime, is_prime + 200100, 1);
	is_prime[0] = 0;
	is_prime[1] = 0;
	for (int i = 2; i < n; i++) {
		if (is_prime[i] == 1) {
			prime[p] = i;
			p++;
			for (int j = 2 * i; j < n; j += i) {
				is_prime[j] = 0;
			}
		}
	}
}

ll n, p;

int main() {
	sieve(200000);
	while (cin >> n >> p&&n + p != -2) {
		ll now = 0;
		REP(i, 200100) {
			if (prime[i] > n) {
				now = i;
				break;
			}
		}
		vector<ll> vp;
		//cout << now << " " << now + p << endl;
		FOR(i, now, now + p + 1) {
			FOR(j, i, now + p + 1) {
				vp.push_back(prime[i] + prime[j]);
			}
		}
		sort(ALL(vp));
		//REP(i, vp.size()) {
		//	cout << vp[i] << endl;
		//}
		cout << vp[p - 1] << endl;
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N), ans(100001);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < N; i++) {
    ans.at(a.at(i))++;
    ans.at(a.at(i) + 1)++;
    if (a.at(i) != 0) {
      ans.at(a.at(i) - 1)++;
    }
  }
  sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  cout << ans.at(0) << endl;
}

Measured memory_bytes: 1024
S=list(input())
N=int(len(S))
c0=0
c1=0
for i in range(N):
  if i%2==0 and S[i]=="1":
    c1=c1+1
  elif i%2!=0 and S[i]=="0":
    c0=c0+1
ch0=N-c0-c1
ch1=N-ch0
print(ch0 if ch0<=ch1 else ch1)

Measured memory_bytes: 3956
#include<stdio.h>
#include<string.h>

void turn(int *DICE,char com);
int check(int *DICE1,int *DICE2);

int main(void){
int i,j,k,f,n,top,front;
int DICE[105][7];
char com[105];
scanf("%d",&n);
for(j=0;j<n;j++){
	for(i=0;i<6;i++){scanf("%d",&DICE[j][i]);}
	}
for(k=0;k<n-1;k++){
	top=DICE[k][0];front=DICE[k][1];
	for(j=k+1;j<n;j++){
		i=0;
		strcpy(com,"SSSSESSSS");
		while(DICE[j][1]!=front){
			if(com[i]=='\0'){break;}
			turn(&DICE[j][0],com[i]);
			i++;
			}
		i=0;
		strcpy(com,"EEEE");
		while(DICE[j][0]!=top){
			if(com[i]=='\0'){break;}
			turn(&DICE[j][0],com[i]);
			i++;
			}
		if(check(&DICE[k][0],&DICE[j][0])==0){printf("No\n");return 0;}
		}
	}
	printf("Yes\n");
return 0;
}
int check(int *DICE1,int *DICE2){
	int i;
for(i=0;i<6;i++){
/*	printf("%d %d\n",*(DICE1+i),*(DICE2+i));*/
	if(*(DICE1+i) != *(DICE2+i)){return 1;}
	}
	return 0;
}
void turn(int *DICE,char com){
int temp;
switch(com){
	case 'N':
		temp     =*DICE;
		*DICE    =*(DICE+1);
		*(DICE+1)=*(DICE+5);
		*(DICE+5)=*(DICE+4);
		*(DICE+4)=temp;
		break;
	case 'S':
		temp     =*DICE;
		*DICE    =*(DICE+4);
		*(DICE+4)=*(DICE+5);
		*(DICE+5)=*(DICE+1);
		*(DICE+1)=temp;
		break;
	case 'E':
		temp     =*DICE;
		*DICE    =*(DICE+3);
		*(DICE+3)=*(DICE+5);
		*(DICE+5)=*(DICE+2);
		*(DICE+2)=temp;
		break;
	case 'W':
		temp     =*DICE;
		*DICE    =*(DICE+2);
		*(DICE+2)=*(DICE+5);
		*(DICE+5)=*(DICE+3);
		*(DICE+3)=temp;
		break;
	}
}

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

bucket = [[] for _ in range(11)]
for i, num in enumerate(S):
    num = int(num)
    bucket[num].append(i)
#print(bucket)

def binsearch(threshold, lst):
    left, right = -1, len(lst)
    while right - left > 1:
        mid = (right + left) // 2
        if lst[mid] > threshold:
            right = mid
        else:
            left = mid
    return right

cnt = 0
for i in range(10):
    if bucket[i]:
        for j in range(10):
            if bucket[j]:
                for k in range(10):
                    if bucket[k]:
                        b_index = binsearch(bucket[i][0], bucket[j])
                        if b_index < len(bucket[j]):
                            c_index = binsearch(bucket[j][b_index], bucket[k])
                            if c_index < len(bucket[k]):
                                #print(i,j,k, b_index)
                                cnt += 1
print(cnt)


Measured memory_bytes: 40048
#include<bits/stdc++.h>
using namespace std;
#define     bolt     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     text     freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define     F        first
#define     S        second
#define     pb       push_back
#define     lb       lower_bound
#define     ub       upper_bound
#define     endl     "\n"
typedef long long ll;
typedef long double ld;
const ll mod = 1e9+7 ;
const ld pi=3.1415926535897932384626433;
const ll inf = 1e18;
ll power(ll x,ll y){ll res=1;x=x%mod;while(y>0){if(y&1)res=((res%mod)*(x%mod))%mod;y=y>>1;x=((x%mod)*(x%mod))%mod;}return res;}

int main()
{
   bolt;
   ll n;
   cin>>n;
   ll ans=0;
   for (ll i=1;i<=n;i++)
   {
      for (ll j=1;j<=n;j++)
      {
         for (ll k=1;k<=n;k++)
         {
            ans+=__gcd(i,__gcd(j,k));
         }
      }
   }
   cout<<ans;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll pow_mod(ll n, ll k, ll mod) {
    if(k == 0) {
        return 1;
    } else if(k % 2 == 1) {
        return pow_mod(n, k - 1, mod) * n % mod;
    } else {
        ll t = pow_mod(n, k / 2, mod);
        return t * t % mod;
    }
}
int main() {
	// your code goes here
 cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    ll p=2019;
    
    string s;
    cin >> s;
    n=s.length();
    vector<ll> a(n);
    for(ll i = 0; i < n; i++) {
        a[i] = (ll)(s[i] - '0');
    }
    reverse(a.begin(),a.end());
    vector<int> sum(n + 1, 0);
    for(ll i = 0; i < n; i++) {
        sum[i + 1] = sum[i] + a[i] * pow_mod(10, i, p) % p;
        //cout<<sum[i+1]<<"\n";
        sum[i + 1] %= p;
        
    }
    map<ll, ll> mp;
    for(ll i = 0; i < n + 1; i++) {
        // cout << sum[i] << " ";
        mp[sum[i]]++;
    }
    // cout << endl;
    ll ans = 0;
    
    for(const auto &p : mp) {
        ans += (p.second - 1) * p.second / 2;
    }
    cout << ans << endl;
     
     
	return 0;
}

Measured memory_bytes: 6000
#include <bits/stdc++.h>
using namespace std;
#define ll long int
  int mypowerfun(int sets,int b)
{
	if(b==0)
	return 1;
	if(b==1)
	return sets;
	int x=mypowerfun( sets,b/2);
	if(b%2==0)
	return x*x;
	else
	return x*x*sets;
}
void pri_arr(int sets[],int n )
{
   int i;
   for(i=0;i<n;i++)
	  printf("%d ",sets[i]);
   printf("\n");
}
void pri_vec(vector<int> a,int n)
{
for (std::vector<int>::iterator it = a.begin() ; it != a.end(); ++it)
    std::cout  << *it;
  std::cout << '\n';
}
int mygcd(int sets,int b)
{
	if (b != 0)
       return mygcd(b, sets%b);
    else
       return sets;
}
int main()
{
	int nn=0;
	ll tt=0;
	ll result=0;
	ll bb=0;
	scanf(" %d %ld",&nn,&tt);
	for(int i=0;i<nn;i++){
		ll ii=0;scanf(" %ld",&ii);
		if(i==0){bb=ii;continue;}
		// cout << x1 << " " << w2 << endl;
		ll ss=ii-bb;
		if(ss<tt){	result+=ss;}
		else{result+=tt;}bb=ii;
		// cout << x1 << " " << w2 << endl;
	}
	// cout << x1 << " " << w2 << endl;
	result+=tt;printf("%d\n",result);
	return 0;
}


Measured memory_bytes: 256
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

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

int a,b,c;
signed main(){
    cin >> a >> b >> c;
    int mx = max(a,b); mx = max(mx,c);
    int r = 0;
    while( mx - a > 1) { a+=2; r++; }
    while( mx - b > 1) { b+=2; r++; }
    while( mx - c > 1) { c+=2; r++; }
    cout << r + (a+b+c)%3 << endl;

}

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

using namespace std;

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

    vector<int> wanted(n);
    for (auto &elem : wanted) {
        cin >> elem;
    }
    sort(wanted.begin(), wanted.end());

    auto happy = 0;
    auto given = 0;

    for (const auto &elem : wanted) {
        given += elem;
        if (given <= candy) {
            happy += 1;
        } else {
            break;
        }
    }

    if (given < candy) {
        happy -= 1;
    }

    cout << happy << "\n";
    return 0;
}


Measured memory_bytes: 256
S = input()

list_S = list(S)
list_S = [int(s) for s in list_S]

a = list_S[0]
hantei = 1
for i in list_S[1:]:
    if a == i:
        hantei = 0
    a = i
if hantei==0:
    print("Bad")
else:
    print("Good")



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int D; //365
    cin >> D;
    int c[26];
    rep(i, 0, 26) {
        cin >> c[i];
    }
    int s[D][26];
    rep(i, 0, D) {
        rep(j, 0, 26) {
            cin >> s[i][j];
        }
    }
    int t[D];
    rep(i, 0, D) {
        cin >> t[i];
        t[i]--;
    }
    ll score[D] = {};
    rep(i, 0, D) score[i] = 1;
    /*vector<int> last_day(26, -1);
    rep(i, 0, D) {
        if (i != 0) score[i] = score[i - 1];
        score[i] += s[i][t[i]];
        last_day[t[i]] = i;
        int decrease = 0;
        rep(j, 0, 26) {
            decrease += c[j] * (i - last_day[j]);
        }
        score[i] -= decrease;
    }*/
    rep(i, 0, D) {
        cout << score[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3676
import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines
from collections import deque

S=deque(readline().rstrip().decode())
Q=int(readline())
query=readlines()

flag=False
for q in query:
    if q[0]==ord('1'):
        flag= not flag
    else:
        _,f,c=q.decode().split()
        f=int(f)
        if flag^(f==1):
            S.appendleft(c)
        else:
            S.append(c)
ans=''.join(S)
if flag:
    ans=ans[::-1]
print(ans)


Measured memory_bytes: 17888
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<sstream>
#include<set>
#include<cctype>
#include<iomanip>
#include<cstring>
#include<limits>
using namespace std;
int dp[10010], w[10010];
bool choice[10010][110];
int cmp1(int a, int b){ return a > b;}
int main()
{//ios::sync_with_stdio(false);
/***
#ifdef ONLINE_JUDGE
#else
    freopen("1.txt", "r", stdin);
#endif
//ios::sync_with_stdio(false);
****/
int n;

cin>>n;
int a[n+1];
for(int i=1;i<=n;i++)
    cin>>a[i];
int dp[n+1];
dp[1]=0;
dp[2]=abs(a[2]-a[1]);
for(int i=3;i<=n;i++)
    dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
cout<<dp[n]<<endl;

    return 0;

}


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

typedef long long ll;
using namespace std;

ll f(ll x, ll y) {
    if (x < 0) return 0;
    return x / y;
}

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    ll r = a % b;
    while (r) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

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

    ll cv = f(b, c) - f(a - 1, c);
    ll dv = f(b, d) - f(a - 1, d);
    ll cdlcm = lcm(c, d);
    ll cdv = f(b, cdlcm) - f(a - 1, cdlcm);

    ll total = b - a + 1;
    ll ans = total - (cv + dv - cdv);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
def solve(k):
    a_mod = 0
    for i in range(1000000):
        a_mod += 7 * pow(10, i, k)
        a_mod %= k
        if a_mod == 0:
            return i + 1
    return -1


def main():
    k = int(input())
    res = solve(k)
    print(res)


def test():
    assert solve(101) == 4
    assert solve(2) == -1
    assert solve(999983) == 999982


if __name__ == "__main__":
    test()
    main()


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

int main(){
  int h,w,d;
  cin >> h >> w >> d;
  int a[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> a[i][j];
    }
  }
  int q;
  cin >> q;
  int l[q],r[q];
  for(int i=0;i<q;i++) cin >> l[i] >> r[i];
  int n=h*w;
  int x[n],y[n];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      x[a[i][j]-1]=i;
      y[a[i][j]-1]=j;
    }
  }
  int dis[n-d];
  for(int i=0;i<n-d;i++){
    dis[i]=abs(x[i]-x[i+d])+abs(y[i]-y[i+d]);
  }
  int k=n/d+1;
  int sum[d][k];
  for(int i=0;i<d;i++){
    sum[i][0]=0;
    for(int j=1;j<k;j++){
      sum[i][j]=sum[i][j-1]+dis[d*(j-1)+i];
    }
  }
  /*for(int i=0;i<4;i++){
    for(int j=0;j<7;j++){
      cout << sum[i][j] << " ";
    }
    cout << endl;
  }*/
  for(int i=0;i<q;i++){
    l[i]--,r[i]--;
    int p=l[i]%d;
    cout << sum[p][(r[i]-p)/d]-sum[p][(l[i]-p)/d] << endl;
  }
}

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

int f(int d){
  return d*d;
}

int main()
{
  int d,S=0;

  while(cin>>d){
    int Z=d;
    for(;d<=(600-Z);d+=Z){
      S+=Z*f(d);
    }
    cout<<S<<endl;
    S=0;
  }
}

Measured memory_bytes: 0