akhauriyash/Code-Regression huggingface dataset:
//Selection Sort
#include <iostream>
#include <algorithm>

using namespace std;

int selectionSort(int A[], int n) {
    int count = 0;
    for(int i=0; i<n-1; i++) {
        int minj = i;
        for(int j=i+1; j<n; j++) {
            if(A[j] < A[minj]) minj = j;
        }
        if(i != minj) {
            swap(A[i], A[minj]);
            count++;
        }
    };
    return count;
}

int main() {
    int n;
    cin >> n;
    int A[n];
    for(int i=0; i<n; i++) cin >> A[i];

    int count = selectionSort(A, n);

    for(int i=0; i<n-1; i++) cout << A[i] << " ";
    cout << A[n-1] << endl;
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

typedef long long int ll;

int main(){

    ll n;
    ll count = 0;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0;i < n;i++){
        cin >> a[i];
        count+=a[i];
    }
    cout << count-n << endl;

    return 0;
}

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


def solve(r: int):
    print(int(r**2))


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

if __name__ == '__main__':
    main()


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

int main()
{
	int a,b;
	cin>>a>>b;
	if(a>=13)
	{
		cout<<b;
		return 0;
	}
	if(a<=5)
	{
		cout<<0;
		return 0;
	}
	cout<<b/2;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  vi A(N),B(N),C(N);
  rep(i,N) {
    cin >> A[i];
    A[i]--;
  }
  rep(i,N) {
    cin >> B[i];
  }
  rep(i,N-1) {
    cin >> C[i];
  }
  int ans = 0;
  rep(i,N) {
    ans += B[A[i]];
    if(i > 0 && A[i] == A[i-1]+1) {
      ans += C[A[i]-1];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
#define mp make_pair
#define MAX 20000
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<long long> vll;
typedef vector<ii> vii;
#define EPS 1e-9
#define LSOne(S) (S & (-S))
#define INF 1e18+10
const int N = 1e5+10;
int w[110],v[110];
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    for(int i = 0; i < n; ++i)
    {
        cin>>w[i]>>v[i];
    }
    ll sum = 0;
    for(int i = 0; i < n; ++i)
        sum+=v[i];
    vector<ll> dp(sum + 1, INF);
    dp[0] = 0;
    for(int i = 0; i < n; ++i)
    {
        for(int j = sum - v[i]; j>=0; --j)
        {
            dp[j+v[i]] = min(dp[j+v[i]],w[i] + dp[j]);
        }
    }
    int ans = 0;
    for(int i = 0; i <= sum; ++i)
        if(dp[i]<=m)
            ans = max(ans,i);
    cout<<ans;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {

	int n = 0;		//?????????????????¨
	int i = 0;		//for???????????????????????°
	int b = 0;		//??????????????°
	int t = 0;		//i???10??§?????£?????????????´?????????????????????°

	scanf("%d", &n);

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

		b = 0 ;				//????????°????????????
		t = i ;

		/*3????????°?????????????????????*/
		if(i%3 == 0){
			b = 1;
		}

		/*????????????3?????????????????????????????????*/
		do{
			if(t%10 == 3){		//10??§?????£????????????3???1?????????3
				b = 1;
			}
			t /= 10 ;			//t???????????????????????¨???10?????????1???????????????)

		}while(t);				//t???0??????????????\???????????????do?????????????????????

		if(b == 1){				//????????°????????£???????????°????????¨i?????????
			printf(" %d",i);
		}


	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 2e5 + 5;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;
 
int fac[MAX_N], inv[MAX_N];
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b, bool usemod = true) {ll c = 1LL; while (b > 0) {if (b & 1LL) {if(!usemod)c*=a;else c = a * c%mod;}if (!usemod) a*=a;else a = a * a%mod; b >>= 1LL;}return c;}
void _nCr() {fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) {fac[i] = fac[i - 1LL] * i%mod;}for (int i = 0; i < MAX_N; i++) {inv[i] = POW(fac[i], mod - 2);}}
ll nCr(ll n, ll r) {return (fac[n] * inv[r] % mod)*inv[n - r] % mod;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}

bool solve() {
	int n; cin >> n;
	vi d(n); REP (i,n) cin >> d[i];
	sort(ALL(d));
	int mi = d[n/2-1];
	int ma = d[n/2];
	cout << ma - mi << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}

Measured memory_bytes: 1152
n, m = map(int, input().split(' '))
a = map(int, input().split(' '))

d = {0: 1}
asum = 0
for aa in a:
    asum = (asum + aa) % m
    if asum in d:
        d[asum] += 1
    else:
        d[asum] = 1


ans = 0
for v in d.values():
    ans += int(v * (v - 1) / 2)

print(ans)

Measured memory_bytes: 57328
for i in range(1, 101):
    count = 0
    temp = 0
    SetCount = 0

    try:
        str1 = input()
        list1 = str1.split(" ")
        str2 = input()
        list2 = str2.split(" ")
        list2.sort(key=int, reverse=True)
        for m in range(0, int(list1[0])):
            if (m+1) % int(list1[1]) == 0:
                SetCount = SetCount + 1
            #elif (m+1) % int(list1[1]) != 0 | SetCount == int(list1[0])//int(list1[1]):
             #   count = count + int(list2[m])
            else:
                count = count + int(list2[m])
        print(count)

    except:
        break



Measured memory_bytes: 5716
module Main where

import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Char
import qualified Data.Map.Strict as M
-- import Debug.Trace

main :: IO ()
main = do
  [a, b] <- unfoldr (BS.readInteger . BS.dropWhile isSpace) <$> BS.getLine
  print . succ . M.size . M.filter (/= 0) . M.fromAscList . primeFactor $ gcd a b


-- http://qiita.com/myuon_myon/items/ad006568bd187223f494#2-4
primes = 2:3:[x|i<-[1..], j<-[-1,1], let x = 6*i+j, isPrime x] where
  isPrime n = null [i|i<-takeWhile (\x -> x*x <= n) primes, rem n i == 0]

-- | returns [(PrimeFactor, Exponent)]
-- >>> primeFactor 9
-- [(2,0),(3,2)]
primeFactor x = go x primes
  where       
    ub = floor . sqrt $ fromIntegral x
    go x (p:ps) 
      | p <= ub = let (x', e) = gogo x p 0 
        in (p, e) : go x' ps
      | x == 1 = []
      | otherwise = [(x, 1)]
      where
        gogo x p e = case quotRem x p of
          (q, 0) -> gogo q p (e + 1)
          (q, _) -> (x, e)


Measured memory_bytes: 13820
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int treeLength = in.nextInt();
		ArrayList<Integer> values = new ArrayList<>();
		for (int i=0; i<treeLength; i++) {
			int tempInt = in.nextInt();
			values.add(tempInt);
		}
		//reading input complete
		for (int i=0; i<values.size(); i++) {
			System.out.print("node "+(i+1)+": key = "+values.get(i)+", ");
			if (i>0) {
				System.out.print("parent key = "+values.get((i-1)/2)+", ");
			}
			if ((2*i+1)<values.size()) {
				System.out.print("left key = "+values.get(2*i+1)+", ");
			}
			if ((2*i+2)<values.size()) {
				System.out.print("right key = "+values.get(2*i+2)+", ");
			}
			System.out.println();
		}
	}

}



Measured memory_bytes: 27264
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace Template
{
    public static class Scan
    {
        public static string NextLine => Console.ReadLine();
        public static int NextInt => int.Parse(NextLine);
        public static long NextLong => long.Parse(NextLine);
        public static double NextDouble => double.Parse(NextLine);
 
        public static string[] StrAry(char separator = ' ') => Console.ReadLine().Split(separator);
        public static int[] IntAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), int.Parse);
        public static long[] LongAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), long.Parse);
        public static double[] DoubleAry(char separator = ' ') => Array.ConvertAll(StrAry(separator), double.Parse);
    }
 
    internal class Template
    {
        public static void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
        private static void Fill<T>(T[] src, T value, int len) { for (int i = 0; i < len; i++) { src[i] = value; } }
 
        static void Solve() 
        {            
            var str = Scan.StrAry(',');
            Console.WriteLine(string.Join(" ", str));            
        }
 
        private static void Main()
        {
            Console.SetOut(new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Console.Out.Flush();
        }
    }
}

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

typedef long long ll;

ll GCD(ll m, ll n)
{
    if (n == 0)
        return m;
    return GCD(n, m % n);
}

int main()
{
    int W;

    int H;
    int C;

    cin >> W;
    cin >> H;
    cin >> C;

    int g = GCD(W, H);
    cout << H * W / (g * g) * C << endl;
    return 0;
}

Measured memory_bytes: 3100
#include <stdio.h>

int main(void)
{
int w,h,x,y,r;
scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
if(w>=x+r&&h>=y+r&&x-r>=0&&y-r>=0){
	printf("Yes\n");
}
else{
	printf("No\n");
}
	return 0;
}


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

int main(){
	string st;
	cin >> st;
    int q = 0;
    cin >> q;
    int in0, in2;
    char ch = ' ';
    int zi = 1;
    vector<char> ma(0);
    vector<char> se(0);
    rep(i, q){
      cin >> in0;
      if(in0 == 1){
        zi *= -1;
      }else{
        cin >> in2 >> ch;
        if(in2 == 1){
          in2 = 1;
        }else{
          in2 = -1;
        }
        if(zi*in2 == 1){
          se.push_back(ch);
        }else{
          ma.push_back(ch);
        }
      }
    }
    if(zi == 1){
      for(int i=se.size()-1; i>=0; i--) cout << se.at(i);
      cout << st;
      for(int i=0; i<ma.size(); i++) cout << ma.at(i);
      cout << endl;
    }else{
      for(int i=ma.size()-1; i>=0; i--) cout << ma.at(i);
      for(int i=st.size()-1; i>=0; i--) cout << st.at(i);
      for(int i=0; i<se.size(); i++) cout << se.at(i);
      cout << endl;
    }
}

Measured memory_bytes: 1024
X,K,D=map(int,input().split())
X=abs(X)
E=X%D
A=(X-E)/D
A=K-A
if X>=K*D:
  print(X-K*D)
else:
  E=X%D
  A=(X-E)/D
  A=K-A
  A=A%2
  if A==0:
    print(E)
  else:
    print(D-E)


Measured memory_bytes: 9188
/**
 * @brief ユーザ定義リテラル
 * @author えびちゃん
 */

#ifndef H_int_literals
#define H_int_literals
#include <cstddef>
#include <cstdint>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

#endif  /* !defined(H_int_literals) */

#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

int main() {
  size_t n;
  intmax_t d, a;
  scanf("%zu %jd %jd", &n, &d, &a);

  std::vector<intmax_t> xh(n);
  for (auto& p: xh) {
    unsigned x, h;
    scanf("%u %u", &x, &h);
    p = static_cast<uintmax_t>(x) << 32 | h;
  }

  std::sort(xh.begin(), xh.end());

  intmax_t res = 0;
  std::vector<intmax_t> acc(n+2);
  size_t j = 0;
  for (size_t i = 0; i < n; ++i) {
    intmax_t h = (xh[i] & ((1_jd << 32) - 1)) + acc[i];
    if (h > 0) {
      while (j < n && (xh[j] >> 32) <= (xh[i] >> 32) + d+d) ++j;
      intmax_t t = (h+a-1) / a;
      res += t;
      acc[i] -= t * a;
      acc[j] += t * a;
    }
    acc[i+1] += acc[i];
  }
  printf("%jd\n", res);
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll x;
ll dfs(ll a,ll b){
	if(b==0) return 0;
	if(a==0) return 1;
	ll m = 1ll<<a;
	if(b<2*m-1) return dfs(a-1,b-1);
	return m+dfs(a-1,b-2*m+1);
}
int main(){
	cin>>n>>x;
	cout<<dfs(n,x)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi acos(-1)
using namespace std;
typedef long long ll;
inline ll read(){
	ll ret=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9') {if (ch=='-') f=-f;ch=getchar();}
	while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return ret*f;
}
ll X1,Y1,X2,Y2;
ll a[200005],c[200005],n=0,m,len,iter;
struct node{ll x,y;}tmp[200005];
bool cmp(node a,node b){return X1>X2?a.x>b.x:a.x<b.x;}
int main(){
	X1=read();Y1=read();X2=read();Y2=read();
	if(Y1>Y2)swap(X1,X2),swap(Y1,Y2);
	m=read();
	for(ll i=1;i<=m;i++)tmp[i].x=read(),tmp[i].y=read();
	sort(tmp+1,tmp+1+m,cmp); 
	for(ll i=1;i<=m;i++)
	if(min(X1,X2)<=tmp[i].x&&tmp[i].x<=max(X1,X2))
	if(min(Y1,Y2)<=tmp[i].y&&tmp[i].y<=max(Y1,Y2))
	a[++n]=tmp[i].y;c[1]=a[1];len=1;
	for(ll i=2;i<=n;i++){
		if(a[i]>c[len])len++,c[len]=a[i];
		else iter=lower_bound(c+1,c+len,a[i])-c,c[iter]=a[i];
	}
	if(n==0)len=0;
	double pre=1.00*(abs(X2-X1)+abs(Y2-Y1));
	double stp=20-pi*5; 
	printf("%.13lf\n",len==min(abs(X2-X1)+1,abs(Y2-Y1)+1)?pre*100*1.00-len*1.00*stp+pi*5:pre*100*1.00-len*1.00*stp);
	return 0;
}

Measured memory_bytes: 6528
#include <assert.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> VX(N);
  vector<int> VY(M);
  for(auto i=0; i<N; ++i) {
    cin >> VX[i];
  }
  for(auto i=0; i<M; ++i) {
    cin >> VY[i];
  }
  sort(VX.begin(), VX.end());
  sort(VY.begin(), VY.end());

  for(auto i=X+1; i<=Y; ++i) {
    if((VX.back() < i) && (VY.front() >= i)) {
      cout << "No War" << endl;
      return 0;
    }
  }
  cout << "War" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	IOS;
	 
    ll n; cin>>n;
    string s;
    n--;
    while(1)
    {
        ll g = n%26;
        s.pb('a'+g);
        n/=26;
        n--;
        if(n<0) break;
    }
    reverse(all(s));
    cout<<s;
	return 0;
}


Measured memory_bytes: 3652
use text_io::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;

fn main() {
    let mut n:usize = read!();
    let mut x:usize = read!();
    let mut t:usize = read!();
    println!("{}",((n+x-1)/x)*t)
}

Measured memory_bytes: 2076
#include <iostream>
#include <vector>
#include <list>
#include<utility>
#include <new>
#include <string>
#include<cmath>
#include<unordered_set>
#include<iomanip>
#include <stack>
#include<queue>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll =  long long int;
/*bool cmp(pair<ll,ll>a,pair<ll,ll>b){
return a.second<b.second;
}*/
int main()
{  string a,b;
cin>>a>>b;
int x=a.length();
int y=b.length();
vector<vector<int>>dp(x+1,vector<int>(y+1,0));
for(int i=1;i<x+1;i++){
    for(int j=1;j<y+1;j++){
        if(a[i-1]==b[j-1]){
            dp[i][j]=max(dp[i-1][j-1]+1,max(dp[i-1][j],dp[i][j-1]));
        }else{
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
}
string c;
int i=x,j=y;
while(i>0&&j>0){
     if(dp[i][j]==dp[i][j-1]){
        j--;
    }else if(dp[i][j]==dp[i-1][j]){
        i--;
    }else{
      c+=b[j-1];
        i--;
        j--;
    }
}
reverse(c.begin(),c.end());
cout<<c;
     return 0;
}


Measured memory_bytes: 38560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  string S;
  cin >> S;
  int N=S.size();
  
  vi count(2019);
  int ten=1,sum=0;
  count[0]++;
  rep(i,N) {
    sum=(sum+(S[N-i-1]-'0')*ten)%2019;
    ten=ten*10%2019;
    count[sum]++;
  }
  
  ll ans=0;
  rep(i,2019) ans+=(ll)count[i]*(count[i]-1)/2;
  cout << ans << endl;
}


Measured memory_bytes: 3752
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

func main() {
	s, t := readString(), readString()

	fmt.Println(t + s)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


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

using namespace std;

typedef long long ll;

const ll MAX_N = 1e6;
const ll INF = (1LL<<31)-1;

ll dat[2*MAX_N],n;

void init(ll a){
  n = 1LL;
  
  while( n < a){ n *= 2;}
  
  for(ll i = 0; i < 2*MAX_N; i++){ dat[i] = INF;}
  
}

void update(ll k, ll a){ // kノードをaにupdateする
  
   k += n-1;
  dat[k] = a;
  
  while( k > 0){
    k = (k-1)/2;
    dat[k] = min(dat[2*k+1],dat[2*k+2]);
  }
}

ll find(ll a, ll b, ll k, ll l, ll r){
  if( r <= a || b <= l){ return INF;}
  if( a <= l && r <= b){ return dat[k];}
  
  else{
    ll v1 = find(a,b,2*k+1,l,(l+r)/2);
    ll v2 = find(a,b,2*k+2,(l+r)/2,r);
    
    return min(v1,v2);
  }
}

int main(){
  ll N,Q; cin >> N >> Q;
  
  init(N);
  
  for(ll i = 0; i < Q; i++){
    ll a,b,c; cin >> a >> b >> c;
    if( a == 0){ update(b,c);}
    else{ 
      cout << find(b,c+1,0,0,n) << endl;
    }
  }
  return 0;
}
                                  
     


Measured memory_bytes: 18748
N, M = map(int,input().split())
par = [i for i in range(N+1)]
size = [1 for _ in range(N+1)]
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x]) #経路圧縮
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
        return 0
    par[x] = y
    size[y] = size[x] + size[y]
    size[x] = 0
for i in range(M):
    x, y,  z= map(int,input().split())
    unite(x,y)
Ans =0
for j in size[1:]:
    if j != 0:
        Ans +=1
print(Ans)

Measured memory_bytes: 14544
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String t = scanner.nextLine();
        int n = s.length();
        int m = t.length();
        int[][] dp  = new int[n+1][m+1];

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                if(s.charAt(i-1)==t.charAt(j-1))
                    dp[i][j] = dp[i-1][j-1]+1;
                else
                    dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
            }
        }
        StringBuilder str = new StringBuilder();
        int i=n,j=m;
        while(i>0 && j>0){
            if(s.charAt(i-1)==t.charAt(j-1)) {
                str.append(s.charAt(i - 1));
                i--;
                j--;
            }
            else if(dp[i][j-1]<dp[i-1][j])
                i--;
            else
                j--;
        }
//        for(int[] o : dp){
//            for(int k : o)
//                System.out.print(k+" ");
//            System.out.println();
//        }
        if(str.length()==0)
            System.out.println("");
        else
            System.out.println(str.reverse().toString());
    }
}


Measured memory_bytes: 86680
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN (300006)
#define MAXK 26
#define MAXX 15000006
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, A[MAXN], dp[302*302], dp2[302*302];
const ll MOD=998244353;
ll qexp(ll x, ll e) {
	if(e==0) return 1;
	ll half = qexp(x,e/2);
	half *= half;
	half %= MOD;
	if(e%2) half *= x;
	half %= MOD;
	return half;
}
int main()
{
	cin>>n; FOR(i,0,n) cin>>A[i];
	ll sum=accumulate(A,A+n,0);
	dp[0]=1;dp2[0]=1;
	for(ll i=0;i<n;i++) {
		for(ll j=sum;j>=0;j--) {
			// dp[j] = dp[j] + (dp[j]*2)%MOD; dp[j] %= MOD;
			dp[j] *= 2; dp[j] %= MOD;
			if(j>=A[i])dp[j] += dp[j-A[i]]; dp[j] %= MOD;
			if(j>=A[i])dp2[j] += dp2[j-A[i]]; dp2[j] %= MOD;
		}
	}
	ll ans = qexp(3,n-1); 
	for(ll i=(sum+1)/2;i<=sum;++i) {
		ans -= (dp[i]);
		ans += MOD;
		ans %= MOD;
	}
	if(sum%2==0) {
		ans += dp2[sum/2];
		ans %= MOD;
	}
	cout<<(ans*3LL)%MOD<<'\n';
}


Measured memory_bytes: 1664
H,W = (int(x) for x in input().split())
s = []
for i in range(H):
    s += [ ['.'] + list(input()) + ['.'] ]
s = [['.' for i in range(W+2)]] + s + [['.' for i in range(W+2)]]

around = [[-1,0],[0,-1],[0,1],[1,0]]
clear = True
for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i][j] == '#':
            if all((s[i+k[0]][j+k[1]] == '.' for k in around)):
                clear = False
                break
    else:
        continue
    break

if clear:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt(), f = sc.nextInt(), r = sc.nextInt();
        while (!(m == -1 && f == -1 && r == -1)) {
            int sum = m + f;
            if (m == -1 || f == -1) System.out.println('F');
            else if(sum >= 80) System.out.println('A');
            else if(sum >= 65 && sum < 80) System.out.println('B');
            else if((sum >= 50 && sum < 65) || (sum >= 30 && sum < 50 && r >= 50)) System.out.println('C');
            else if(sum >= 30 && sum < 50) System.out.println('D');
            else System.out.println('F');
            m = sc.nextInt();
            f = sc.nextInt();
            r = sc.nextInt();
        }
    }
}



Measured memory_bytes: 26052
#include <bits/stdc++.h>
#define REP(i,n) for(i=0; i<n; i++)
#define IREP(i,n) for(i=n-1; i>=0; i--)
#define X first
#define Y second;
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	int i,j,p,N,M,K;
	bool find;
	vector<int>::iterator ite;
	vector<int> hannin; 
	while(cin >> N, N!=0) {
		vector<int> v[N];
		REP(i,N) {
			cin >> M;
			REP(j,M) {
				cin >> p;
				v[i].push_back(p);
			}
		}
		cin >> K;
		int l[K];
		REP(i,K) cin >> l[i];
		REP(i,N) {
			REP(j,K) {
				find = false;
				ite=v[i].begin();
				while(ite!=v[i].end()) {
					if(*ite==l[j]) find=true;
					ite++;
				}
				if(find==false) break;
			}
			if(find==true) hannin.push_back(i);
		}
		if(hannin.size()==1) cout << hannin[0]+1 << endl;
		else cout << -1 << endl;
		hannin.clear();
	}
	return 0;
}

Measured memory_bytes: 1280
use std::io;

fn main() {
    let n = parse_line::<usize>();
    let st = parse_line::<String>();
    solve(st, n);
}

fn parse_line<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn solve(st: String, n: usize) {
    let split: Vec<&str> = st.split_whitespace().collect();
    let mut s = split[0].chars();
    let mut t = split[1].chars();
    loop {
        let cs = s.next();
        if cs.is_none() {
            break;
        };
        let ts = t.next().unwrap();
        print!("{}", cs.unwrap());
        print!("{}", ts);
    }
    println!();
}

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

int main () {
  int N, K;
  cin >> N >> K;
  int ans = 1;
  for(int i = 0; i < N; i++) {
   if (ans*2 > ans+K) {
     ans += K;
   }
    else ans *= 2;
  }
  cout << ans << endl;
}

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

#define ul unsigned long int
#define ull unsigned long long
#define li long long int


int main()
{
  ul h,w;
  cin>>h>>w;

  while (h>0|w>0) {
    for (ul i = 0; i < h; i++)
    {
      for (ul j = 0; j < w; j++)
        cout << ((i % (h - 1)) && (j % (w - 1)) ? "." : "#");
      cout << endl;
    }
    cout << endl;

    cin >> h >> w;
  }

  return 0;
}



Measured memory_bytes: 3116
n = int(input())
sp = [0] * n
for i in range(n):
    sp[i] = list(map(str,input().split()))
    sp[i].append(i+1)
    sp[i][1] = int(sp[i][1])

sp.sort(key = lambda x: x[1],reverse = True)
sp.sort(key = lambda x: x[0])
for i in range(n):
    print(sp[i][2])



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	x=0;char c=getchar();bool f=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return  x;
}
template<class t> inline void write(t x){
	if(x<0){putchar('-'),write(-x);}
	else{if(x>9)write(x/10);putchar('0'+x%10);}
}

#define int long long

const int mod=1e9+7;
int ans,cnt[70],n;

signed main(){
	read(n);
	for(int i=1,x;i<=n;i++){
		read(x);
		for(int j=0;j<60;j++) if(x>>j&1ll) cnt[j]++;
	}
	for(int i=0;i<60;i++) (ans+=cnt[i]*(n-cnt[i])%mod*((1ll<<i)%mod)%mod)%=mod;
	write(ans);
}

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

using namespace std;
using ll = long long;
using pint = pair<int, int>;

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

	ll ans = 0;
	ll div = N / K;
	ll mod = N % K;

	if (mod == 0) {
		ans = 0;
	} else if (mod < (K / 2)) {
		ans = mod;
	}
	else {
		ans = K - mod;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3568
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef pair<int, int> pii;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

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

class D {
	int rows, cols;
	int d, q;
	vector<pii> pos;
	vector<ll> memo;
public:
	D()
	{
		cin >> rows >> cols;
		cin >> d;

		pos.resize(rows * cols + 1);
		memo.resize(rows * cols + 1);

		int v;
		REP(y, rows)
			REP(x, cols)
		{
			cin >> v;
			pos[v] = MP(y, x);
		}

		cin >> q;

	}

	inline ll diff(const int& s, const int& g)
	{
		return (ll)abs(pos[s].first - pos[g].first) + abs(pos[s].second - pos[g].second);
	}

	void memoize()
	{

		for (int s{ 1 }; s <= d; s++)
		{
			memo[s] = 0;

			for (int g{ s + d }; g <= rows * cols; g += d)
				memo[g] = memo[g - d] + diff(g, g - d);

		}

	}

	void solve()
	{
		memoize();

		int s, g;
		REP(_q, q)
		{
			ll ans{ 0 };
			cin >> s >> g;

			ans += memo[g] - memo[s];

			cout << ans << endl;
		}

	}

	void debug()
	{
		REPC(i, rows * cols)
		{
			cout << i << " is at (" << pos[i].first << ", " << pos[i].second << ")." << endl;
		}

		cout << endl << endl;

		REP1C(i, rows * cols)
		{
			cout << memo[i] << " ";
			if (!(i % d))
				cout << endl;
		}

		cout << endl << endl;

	}
};


int main()
{
	D solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 2560
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
                                                     
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 100005;
const ll mm = 1e+18;
void solve()
{
    int n,m,k;
    cin>>n>>m>>k;
    char c[n][m];
    rep0(i,n)rep0(j,m) cin>>c[i][j];
    int ans=0;
    rep0(i,1<<n){
        rep0(j,1<<m){
            vector<bool>f1(n,true);
            vector<bool>f2(m,true);
            rep0(k,n){
                if((i>>k)&1){
                    f1[k]=false;
                }
            }
            rep0(k,m){
                if((j>>k)&1){
                    f2[k]=false;
                }
            }
            int how=0;
            rep0(_i,n)rep0(_j,m){
                if(f1[_i]&&f2[_j]&&c[_i][_j]=='#'){
                    how++;
                }
            }
            if(how==k) ans++;
        }
    }
    cout<<ans;
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nx;
    }
    return 0;
}


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


class dice{
    public:
    int face[7];
    string name;
    
    dice(){
    }
    
    void north(){
        face[6] = face[0];
        face[0] = face[1];
        face[1] = face[5];
        face[5] = face[4];
        face[4] = face[6];
       
    }
    
    void south(){
        face[6] = face[0];
        face[0] = face[4];
        face[4] = face[5];
        face[5] = face[1];
        face[1] = face[6];
    }
    
    void east(){
        face[6] = face[0];
        face[0] = face[3];
        face[3] = face[5];
        face[5] = face[2];
        face[2] = face[6];
    }
    
     void west(){
        face[6] = face[0];
        face[0] = face[2];
        face[2] = face[5];
        face[5] = face[3];
        face[3] = face[6];
    }
    

};

bool eq(dice d1, dice d2){
    for(int j = 0; j < 6; j++){
        if(d1.face[j] != d2.face[j]){
            return false;
        }
    }
    return true;
}

bool equal(dice d1, dice d2){
    
    for(int j = 0; j < 4; j++){
        for(int k = 0; k<4; k++){
            if(d1.face[1] == d2.face[1]){
                break;
            }
            d1.south();
        }
        d1.east();
    }    
    for(int k = 0; k<4; k++){
        if(d1.face[0] == d2.face[0]){
            //if((d1.face[2] == d2.face[2]) && (d1.face[3] == d2.face[3]) && (d1.face[4] == d2.face[4]) && (d1.face[5] == d2.face[5])){
            if(eq(d1, d2)){
                return true;
            }
        }
        d1.east();
    }
    return false;        
            
}

int n;
dice d[100];

bool ans(){
    for(int j = 0; j < n - 1; j++){
        for(int i = j + 1; i < n; i++){
            if(equal(d[j], d[i])){
                return false;
            } 
        }
    }
    return true;
}


int main(){
    cin >> n;
    for(int j = 0; j < n; j++){
        for(int i = 0; i < 6; i++){
            cin >> d[j].face[i];
            //cout << d1.face[i] << endl;
        }
    }
    
    if(ans()){
        cout << "Yes" << endl;
    } else cout << "No" << endl;
    

    
    return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i, n) for(int i = 0; i < (n); ++i)
const ll mod = 1e9 + 7;

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

bool pairCompare(const P &firstElof, const P &secondElof) {
    return firstElof.second < secondElof.second;
}

int a[MAXN];

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

    rep(i, n) {
        cin >> d;
        d--;
        a[d] = i + 1;
    }
    rep(i, n) { cout << a[i] << " "; }
    cout << "\n";
}


Measured memory_bytes: 3980
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class A_166_AC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();

            if (s.Substring(1, 1) == "B")
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("ABC");
            }

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 25732
/*
 *  stay hungry, stay foolish, stay home.
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define ml cout<<"\n"
 
#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define in insert
#define ff first
#define ss second
#define mod 1000000007

#define yes cout<<"Yes"<<endl;
#define no cout<<"No"<<endl;
#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;

int main(){
	ios_base::sync_with_stdio(false);
     	cin.tie(NULL);
    	cout.tie(NULL);    
    ll n;cin>>n;
    ll ar[n];
    rep(i,0,n){
        cin>>ar[i];
    }
    // if(n>1 && ar[0]==ar[n-1] ){
    //     no; return 0;
    // }
    for(ll i=n-2;i>=0;--i){
        if(ar[i]>ar[i+1]){
            if(ar[i]-1 != ar[i+1]){
                
                no;return 0;
            }else{
                ar[i]=ar[i+1];
            }
        }
    }
    yes;
    return 0;

}







Measured memory_bytes: 1024
def euq(a, b):
  if b==0: return a
  else:
    tmp = b
    b = a%b
    a = tmp
    return euq(a, b)
  
A, B = map(int, input().split())
ma = euq(max(A, B), min(A, B))

ans = A*B//ma
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	long long sum;
	sum = 0;
	cin>>n;
	vector<int> vec(n, 0);
	for(int i = 0; i < n; ++i)cin>>vec[i];
	sort(vec.begin(), vec.end());
	for(auto x : vec)sum += x;
	sum -= vec[n - 1];
	if(vec[n - 1] < sum){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int n, m, x; cin >> n >> m >> x;
  vector<int> a(m);
  rep(i, m) cin >> a[i];

  int index = upper_bound(all(a), x) - a.begin();

  cout << min(index, m-index) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
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; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

//const int mod = 1000000007;
const int mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint& a) { if ((x += a.x) >= mod) x -= mod; return *this;}
    mint& operator++() { return *this += mint(1); }
    mint& operator-=(const mint& a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator--() { return *this -= mint(1); }
    mint& operator*=(const mint& a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint& a) const { mint res(*this); return res+=a; }
    mint operator-(const mint& a) const { mint res(*this); return res-=a; }
    mint operator*(const mint& a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const {
        mint res = mint(1),a(*this);
        while(t > 0) {
            if(t&1) res *= a;
            t >>= 1;
            a *= a;
        }
        return res;
    }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint& a) { return *this *= a.inv(); }
    mint operator/(const mint& a) const { mint res(*this); return res/=a; }
};
ostream& operator<<(ostream& os,const mint& m) { return os << m.x; }

mint dp[3100][3100];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,s;
    cin >> n >> s;
    vi a(n);
    cin >> a;
    mint ans;
    dp[0][0] = 1;
    rep(i,n) {
        rep(j,s+1) {
            if(j+a[i] <= s) dp[i+1][j+a[i]] += dp[i][j];
            dp[i+1][j] += dp[i][j];
        }
        dp[i+1][0] += 1;
        ans += dp[i+1][s];
    }
    cout << ans << endl;
}


Measured memory_bytes: 75392
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};

int main() {
  int x, a;
  cin >> x >> a;
  if(x < a) cout << 0 << endl;
  else cout << 10 << endl;
  return 0;
}


Measured memory_bytes: 256
import math
import itertools
k = int(input())
a = [i for i in range(1,k+1)]

two = list(itertools.product(a,a))

ans = 0
for x,y in two:
    gcd1 = math.gcd(x,y)
    for i in range(1,k+1):
        gcd2 = math.gcd(gcd1,i)
        ans += gcd2
        
print(ans)


Measured memory_bytes: 11868
#include <iostream>
#include <math.h>

using namespace std;

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

    int x[n], y[n];
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < n; i++) cin >> y[i];

    double p1, p2, p3, pInf;
    p1 = p2 = p3 = pInf = 0;
    for (int i = 0; i < n; i++) {
        p1 += fabs(x[i] - y[i]);
        p2 += pow(fabs(x[i] - y[i]), 2);
        p3 += pow(fabs(x[i] - y[i]), 3);
        pInf = max(pInf, fabs(x[i] - y[i]));
    }

    cout << fixed << p1 << endl << sqrt(p2) << endl << cbrt(p3) << endl << pInf << endl;
}


Measured memory_bytes: 3472