akhauriyash/Code-Regression huggingface dataset:
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std;
// dfmt on

void main()
{
    long N = lread();
    auto X = new real[](N);
    auto Y = new real[](N);
    foreach (i; 0 .. N)
    {
        scan(X[i], Y[i]);
    }
    auto d = new real[][](N, N);
    foreach (i; 0 .. N)
        foreach (j; i .. N)
        {
            d[i][j] = d[j][i] = sqrt((X[i] - X[j]) ^^ 2 + (Y[i] - Y[j]) ^^ 2);
        }
    auto route = iota(N).array;
    real s = 0;
    long c;
    dprint(d);
    do
    {
        c++;
        real tmp = 0;
        foreach (i; 0 .. N - 1)
        {
            tmp += d[route[i]][route[i + 1]];
        }
        dprint(route, tmp);
        s += tmp;
    }
    while (nextPermutation(route));
    writefln("%.10f", s / c);
}


Measured memory_bytes: 3820
input = list(map(int, input().split(' ')))
N = input[0]
L = input[1]
taste_list = [L + i -1 for i in range(1, N+1)]
abs_taste_list = [abs(t) for t in taste_list]
print(sum(taste_list) - taste_list[abs_taste_list.index(min(abs_taste_list))])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, M, a[50], b[50], c[50], d[50], cnt;
bool vis[50];
vector<int>v[50];

int dfs(int x, int from) {
	vis[x] = true;
	for (int i : v[x]) {
		if (!vis[i]) {
			c[i] = d[i] = c[x] + 1;
			d[x] = min(d[x], dfs(i, x));
		}
		else if (i != from) {
			d[x] = min(d[x], c[i]);
		}
	}
	return d[x];
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		cin >> a[i] >> b[i];
		--a[i];
		--b[i];
		v[a[i]].push_back(b[i]);
		v[b[i]].push_back(a[i]);
	}
	dfs(0, -1);
	for (int i = 0; i < M; ++i) {
		if (c[a[i]] > c[b[i]]) {
			swap(a[i], b[i]);
		}
		if (d[b[i]] > c[a[i]])++cnt;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<cstdio>

int main(){
	int count[123];
	for(int i = 0; i < 123; i++){
		count[i] = 0;
	}

	char c;
	while(scanf("%c", &c) != EOF){
		if(c > 96){
			count[c] += 1;
		}else{
			count[c + 32] += 1;
		}
	}

	for(int i = 97; i < 123; i++){
		printf("%c : %d\n", i, count[i]);
	}
	return 0;
}

Measured memory_bytes: 968
import bisect

S = list(input())

ninnzuu = [0 for _ in range(len(S))]

rl_left = []
for i in range(len(S)-1):
    if S[i] == "R" and S[i+1] == "L":
        rl_left.append(i)

for i in range(len(S)):
    if S[i] == "R":
        next_rl = rl_left[bisect.bisect_left(rl_left, i)]
        kyori = next_rl - i
        if kyori % 2 == 0:
            ninnzuu[next_rl] += 1
        else:
            ninnzuu[next_rl + 1] += 1

    else:
        prev_rl = rl_left[bisect.bisect_left(rl_left, i) - 1]
        kyori = i - prev_rl
        if kyori % 2 == 0:
            ninnzuu[next_rl] += 1
        else:
            ninnzuu[next_rl + 1] += 1

print(" ".join(str(i) for i in ninnzuu))


Measured memory_bytes: 13220
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String b = sc.next();
		if (b.equals("A")) {
			System.out.println("T");
		} else if (b.equals("T")) {
			System.out.println("A");
		} else if (b.equals("C")) {
			System.out.println("G");
		} else {
			System.out.println("C");
		}
	}
}

Measured memory_bytes: 21588
#include<iostream>
#define INF (1 << 30)
using namespace std;
typedef long long ll;

int main() {
    ll x, y;
    cin >> x >> y;
    ll ans = INF;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            ll n = x, m = y;
            if (i == 1) n = -n;
            if (j == 1) m = -m;
            if (n <= m) ans = min(ans, i + j + m - n);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == '?':
        break
    if op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    else:
        print(int(a / b))
        



Measured memory_bytes: 5592
#include <iostream>
#include <numeric>
#include <algorithm>
using namespace std;

long long n, m, a[100000], b[100000], p[100000], s[100000], rj[100000];

long long f(long long x) {
    if(p[x] == x)
        return x;
    return p[x] = f(p[x]);
}

void pov(long long a, long long b, int i) {
    long long x = f(a), y = f(b);
    if(x == y) {
        rj[i] = rj[i + 1];
        return;
    }
    p[x] = y;
    rj[i] = rj[i + 1] - (s[x] * s[y]);
    s[y] += s[x];
}

int main() {
    cin >> n >> m;
    for(int i = 0; i < m; ++i)
        cin >> a[i] >> b[i], (--a[i], --b[i]);
    iota(p, p + n, 0);
    fill(s, s + n, 1);
    rj[m - 1] = (n * (n - 1)) / 2;
    for(int i = m - 2; i >= 0; --i) {
        pov(a[i + 1], b[i + 1], i);
    }
    for(int i = 0; i < m; ++i)
        cout << rj[i] << endl;
    return 0;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
#define MN 200000
int a[MN+5];
int main()
{
	int n,i,j,x,y;long long ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",&a[i]);
	for(i=1,j=x=y=0;i<=n;++i)
	{
		while(j<=n&&x==y)x+=a[++j],y^=a[j];
		ans+=j-i;x-=a[i];y^=a[i];
	}
	printf("%lld",ans);
}

Measured memory_bytes: 1024
import java.math.*;
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int[][] ary = new int[3][3];
        boolean[][] c = new boolean[3][3];
        String ans = "No";
        for(int i=0;i<3;i++){
            for(int j =0;j<3;j++){
                ary[i][j] = sc.nextInt();
            }
        }
        int n = sc.nextInt();
        int[] b = new int[n];
        for(int i = 0;i<b.length;i++){
            b[i] = sc.nextInt();
        }
        for(int i = 0;i<3;i++){
            for(int j = 0; j<3; j++){
                for(int k =0 ;k<b.length;k++){
                    if(b[k]==ary[i][j]){
                        c[i][j] = true;
                    }
                }
                }
            }
            if(c[0][0]&&c[0][1]&&c[0][2]){
                ans = "Yes";
            } else if(c[1][0]&&c[1][1]&&c[1][2]){
                ans = "Yes";
            } else if(c[2][0]&&c[2][1]&&c[2][2]){
                ans = "Yes";
            } else if(c[0][0]&&c[1][0]&&c[2][0]){
                ans = "Yes";
            } else if(c[0][1]&&c[1][1]&&c[2][1]){
                ans = "Yes";
            } else if(c[0][2]&&c[1][2]&&c[2][2]){
                ans = "Yes";
            } else if(c[0][0]&&c[1][1]&&c[2][2]){
                ans = "Yes";
            } else if(c[2][0]&&c[1][1]&&c[0][2]){
                ans = "Yes";
            }
            System.out.println(ans);
        }
        }


Measured memory_bytes: 23764
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  double aa,bb,c,d,e,f;
  cin >> aa >> bb >> c >> d >> e >> f ;
  double a = 100*aa;
  double b = 100*bb;
  double noudo = 100*e / (100+e);
  double masternoudo=0;
  double satoumizu = 0;
  double satoushituryou = 0;
  int testcount =0;//test
  int ts=0;
//  cout << noudo << endl;
  for(int A = 1; A*a<=f; A++){
    for(int B=0; A*a+B*b <= f; B++){
      for(int C=0; (C*c*100/(A*a+B*b+C*c) <= noudo) && (A*a+B*b+C*c <= f) ;C++){
        for(int D=0; ((C*c+D*d)*100/(A*a+B*b+C*c+D*d) <= noudo) && (A*a+B*b+C*c+D*d <= f); D++){
          testcount++;
      			double checknoudo = (c*C + d*D)* 100 / (a*A + b*B + c*C + d*D);
      			if((a*A + b*B + c*C + d*D) <= f && checknoudo <= noudo){
           			if(masternoudo <= checknoudo){
            	    masternoudo = checknoudo;
             		satoumizu = a*A + b*B + c*C + d*D;
            		satoushituryou = c*C + d*D;
                    ts = testcount;
		        	   }
			      }	
        }
      }
    }
  }
  
  cout << satoumizu << " " << satoushituryou << endl;
//  cout << testcount << endl;
//  cout << ts << endl;
 

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define fillarray(array, value, begin, end) fill((array) + (begin), (array) + (end) + 1, value)
#define fillvector(v, value) fill((v).begin(), (v).end(), value)
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end()
{
#ifdef ONLINE
    printf("\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000);
    system("pause");
#endif
}
int h, w;
int m;
struct counts
{
    int id;
    int cnt;
    bool operator<(const counts &x) const
    {
        return cnt > x.cnt;
    }
} cntx[N], cnty[N];
ll ans;
set<pii> s;

inline void solve()
{
    cin >> h >> w >> m;
    for (int i = 1; i <= m; ++i)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        cntx[x].cnt++, cnty[y].cnt++;
        cntx[x].id = x, cnty[y].id = y;
        s.insert(mp(x, y));
    }
    sort(cntx + 1, cntx + h + 1);
    sort(cnty + 1, cnty + w + 1);
    ans = cntx[1].cnt + cnty[1].cnt - 1;
    int l1 = 1, l2 = 1;
    for (; l1 < h; ++l1)
        if (cntx[l1 + 1].cnt < cntx[l1].cnt)
            break;
    for (; l2 < w; ++l2)
        if (cnty[l2 + 1].cnt < cnty[l2].cnt)
            break;
    if (1ll * l1 * l2 > m)
        ans++;
    else
    {
        for (int i = 1; i <= l1; ++i)
            for (int j = 1; j <= l2; ++j)
            {
                if (s.find(mp(cntx[i].id, cnty[j].id)) != s.end())
                    continue;
                ans++;
                cout << ans << endl;
                return;
            }
    }
    cout << ans << endl;
}

int main()
{
    TIME__START = clock();
    int Test = 1;
    // scanf("%d", &Test);
    while (Test--)
        solve();
    TIME__END = clock();
    program_end();
    return 0;
}

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

int main(){
    int n; cin >> n;
    int l; cin >> l;
    int p[n];

    for(int i=0; i < n; i++){
        p[i]=l+i;
    }

    int sum =0;
    for(int i=0; i<n; i++){
        
        sum +=p[i];
    }

    int first=p[0];
    int last=p[n-1]; 

    for(int i=0; i < n; i++){
        p[i]=abs(l+i);
    }


    sort(p, p+n);

    int ans;
    if(p[0]==0){
        ans=0;
    
    }else if(abs(first) < abs(last)){
        ans=first;
    }else{
        ans=last;
    }



    cout << (sum-ans) << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
*s,=map(int,input()[::-1])
a=[]
i=0
while i<n:
  j=max(j for j in range(i,min(n,i+m)+1)if not s[j])
  if i==j:
    print(-1)
    exit()
  a+=j-i,
  i=j
print(*a[::-1])

Measured memory_bytes: 6992
from itertools import accumulate 

N, K = list(map(int, input().split()))
P = list(map(lambda x: int(x) - 1, input().split()))
C = list(map(int, input().split()))

ans = -10**18-1
seen = [False]*N
for i in range(N):
    if seen[i]:
        continue
    loop = []
    now = i
    while seen[now] == False:
        seen[now] = True
        loop.append(C[now])
        now = P[now]
    loop_size = len(loop)
    loop_score = sum(loop)
    cumsum = [0]+list(accumulate(loop+loop))
    for j in range(1, min(K, loop_size)+1):
        for l in range(loop_size+1):
            r = l+j
            subseq = cumsum[r] - cumsum[l]
            ans = max(ans, subseq, subseq+loop_score*((K-j)//loop_size))
print(ans)

Measured memory_bytes: 69328
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	LL n,a[222222]={};
	cin>>n;
	FORQ(i,1,n){
		cin>>a[i];
		a[i]+=a[i-1];
	}
	LL mn=1LL*mod*mod;
	LL all=a[n];
	FOR(i,1,n){
		mn=min(mn,abs(all-a[i]-a[i]));
	}
	cout<<mn<<endl;
    return 0;
}


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

int main(){
    string o;cin>>o;
    string e;cin>>e;
    int sz=o.size()+e.size();
    char ans[sz+2];
    for(int i=0;i<o.size();i++){
        ans[i*2]=o[i];
    }
    for(int i=0;i<e.size();i++){
        ans[i*2+1]=e[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

a = sorted(a)

if n == 2:
    print(a[1] - a[0])
    exit()

res1 = a[n - 1] + a[n - 2] - (a[0] * 2)
p = n - 3
q = 1
mode = 0
while 1:
    #print(p, q, res1)
    if p < q:
        break
    elif p == q:
        if mode == 0:
            res1 += a[p + 2] - a[p]
        else:
            res1 += a[p] - a[p - 2]
        break
    else:
        if mode == 0:
            res1 += a[p + 1] + a[p + 2] - a[q] - a[q + 1]
            mode = 1
            q += 2
        else:
            res1 += a[p] + a[p - 1] - a[q - 1] - a[q - 2]
            mode = 0
            p -= 2

res2 = a[n - 1] * 2 - a[0] - a[1]
p = n - 2
q = 2
mode = 1
while 1:
    #print(p, q, res2)
    if p < q:
        break
    elif p == q:
        if mode == 0:
            res2 += a[p + 2] - a[p]
        else:
            res2 += a[p] - a[p - 2]
        break
    else:
        if mode == 0:
            res2 += a[p + 1] + a[p + 2] - a[q] - a[q + 1]
            mode = 1
            q += 2
        else:
            res2 += a[p] + a[p - 1] - a[q - 1] - a[q - 2]
            mode = 0
            p -= 2

print(max(res1, res2))


Measured memory_bytes: 8308
n,m=map(int,input().split())

if n==1 and m==1:
  print("0")
if n==1 and not m==1:
  print(m*(m-1)//2)
if m==1 and not n==1:
  print(n*(n-1)//2)
if not m==1 and not n==1:
    print(n*(n-1)//2+m*(m-1)//2)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

#define ll long long

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

    ll a, b, c;
    cin >> a >> b >> c;
    if (c <= a + b) cout << "No\n";
    else if (4 * a * b < (c - a - b) * (c - a - b)) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

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

int	main() {
	int K, S;
	cin >>K >>S;
	int SS=0;
	for (int X=0; X<=K; X++) {
		if (S-X>2*K)
			continue;
		else
			for (int Y=0; Y<=K; Y++) {
				int Z=S-X-Y;
				if (Z>K)
					continue;
				if (Z<0)
					continue;
				SS++;
			}
	}
	cout <<SS <<endl;
	return 0;
};


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
#define EPS 1e-8
#define equals(a,b) fabs((a) - (b)) < EPS

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct Point {
	double x, y;

	Point(double x=0, double y=0) : x(x), y(y) {}

	Point operator+(const Point &o) const { return Point(x+o.x, y+o.y); }

	Point operator-(const Point &o) const { return Point(x-o.x, y-o.y); }

	Point operator*(const double m) const { return Point(x*m, y*m); }

	Point operator/(const double d) const { return Point(x/d, y/d); }

	bool operator<(const Point &o) const { return x != o.x ? x < o.x : y < o.y; }

	bool operator==(const Point &o) const { return fabs(x-o.x) < EPS && fabs(y-o.y) < EPS; }

	double cross(const Point &o) const { return x * o.y - y * o.x; }

	double dot(const Point &o) const { return x * o.x + y * o.y; }

	double atan() const { return atan2(y, x); }

	double norm() const { return sqrt(dot(*this)); }

	double distance(const Point &o) const { return (o - (*this)).norm(); }

	double area(const Point &a,const Point &b) {
		Point p = a - (*this), p2 = b - (*this); 
		return p.cross(p2);
	}

	double area_abs(const Point &a,const Point &b) const {
		Point p = a - (*this), p2 = b - (*this);
		return fabs(p.cross(p2)) / 2.0;
	}	

	//??????ab?????????????????????????????????????????????????????????
	int between(const Point &a,const Point &b) {
		if(area(a,b) != 0) return 0;

		if(a.x != b.x)  return ((a.x <= x) && (x <= b.x)) || ((a.x >= x) && (x >= b.x));
		else return ((a.y <= y) && (y <= b.y)) || ((a.y >= y) && (y >= b.y));
	}      

	double distance_seg(const Point& a,const Point& b) {
		if((b-a).dot(*this-a) < EPS) {
			return (*this-a).norm();
		}
		if((a-b).dot(*this-b) < EPS) {
			return (*this-b).norm();
		}
		return abs((b-a).cross(*this-a)) / (b-a).norm();
	}
};

ostream& operator << (ostream& os, const Point& p) {
	os << "(" << p.x << ", " << p.y << ")";
	return os;
}

int ccw(Point a, Point b, Point c) {
	b = b-a;
	c = c-a;

	if(b.cross(c) > 0.0) return +1;	//conter clockwise
	if(b.cross(c) < 0.0) return -1;	//clockwise
	if(b.dot(c) < 0.0) return +2;	//a on Seg(b,c)
	if(b.norm() < c.norm()) return -2;	//b on Seg(a,c)
	return 0;	//c on Seg(a,b)
}

int main() {
	Point a, b, c;
	cin >> a.x >> a.y >> b.x >> b.y;

	int q;
	cin >> q;

	rep(i, q) {
		cin >> c.x >> c.y;

		int d = ccw(a, b, c);
		if(d == +1) {
			cout << "COUNTER_CLOCKWISE" << endl;
		} else if(d == -1) {
			cout << "CLOCKWISE" << endl;
		} else if(d == +2) {
			cout << "ONLINE_BACK" << endl;
		} else if(d == -2) {
			cout << "ONLINE_FRONT" << endl;
		} else if(d == 0) {
			cout << "ON_SEGMENT" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1232
# sys.stdin.readline()
import sys
input = sys.stdin.readline

n, k = map(int, input().split())
h = [0]*n
for i in range(n):
    h[i] = int(input())
h.sort()
check = [0]*(n-k+1)
for i in range(n-k+1):
    check[i] = h[i+k-1]-h[i]
print(min(check))

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

int main() {
  int K;
  cin >> K;
  vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << vec.at(K-1) << endl;
}


Measured memory_bytes: 256
# coding: utf-8


def solve(*args: str) -> str:
    S = args[0]
    m = 2019
    dp = [0]*m
    dp[0] = 1

    acc, d = 0, 1
    for s in S[::-1]:
        acc = (acc+d*int(s)) % m
        dp[acc] += 1
        d = (d*10) % m
    return str(sum([n*(n-1)//2 for n in dp]))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 9272
n = gets.to_i
s = gets.chomp.chars

lw = []
re = []

n.times do |i|
  lw[i] = s[i] == 'W' ? (lw[i - 1] || 0) + 1 : (lw[i - 1] || 0)
  re[n - 1 - i] = s[n - 1 - i] == 'E' ? (re[n - i] || 0) + 1 : (re[n - i] || 0)
end

lw << 0
re << 0

min = 1000000
n.times do |i|
  min = [min, (lw[i-1] || 0) + (re[i+1] || 0)].min
end

puts min

Measured memory_bytes: 32132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    string s, t;
    cin >> s >> t;
    int ls, lt;
    ls = s.length();
    lt = t.length();
    int ans = lt;
    int tmp;
    for (int i = 0; i < ls - lt + 1; i++) {
        tmp = lt;
        for (int j = 0; j < lt; j++) {
            if(s[i + j] == t[j]){
                tmp--;
            }
        }
        ans = min(tmp, ans);
    }
    printf("%d\n", ans);

}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  int N;
  cin >> N;
  N %= 100;
  N %= 10;
  // printf("%d\n", N);
  if (N == 3) {
    printf("bon\n");
  }
  else if (N == 0 || N == 1 || N == 6 || N == 8) {
    printf("pon\n");
  } else {
    printf("hon\n");
  }
  return 0;
}

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

int main(){
	int n = 0;
	string s;
	string ss[] = {"dream", "dreamer", "erase" ,"eraser"};
	cin >> s;
	int l = s.length();
	s += ' ';
	s += ' ';
	while(n < l){
		bool flag = false;
		for(int i = 0;i < 4;i++){
			if(s.substr(n,ss[i].length()) == ss[i]){
				n += ss[i].length();
				flag = true;
				break;
			}
		}
		if(!flag) {
			if(s.substr(n,2) == "er" && n >= 5 && s.substr(n - 5,5) == "dream"){
				n += 2;
				continue;
			}
			if(n >= 5 && s.substr(n - 1,2) == "er" && s.substr(n - 5,5) == "erase") {
				n++;
				continue;
			}
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 512
import Control.Monad.Trans.State
 
main :: IO ()
main = do
  n <- readLn
  print $ evalState (step n) (2, 1)
 
step :: Int -> State (Int, Int) Int
step 0 = get >>= return . fst
step 1 = get >>= return . snd
step n = get >>= put . lucas >> step (n - 1)

lucas :: (Int, Int) -> (Int, Int)
lucas (x, y) = (y, x + y)

Measured memory_bytes: 508
import bisect

n = int(input())
list = list(map(int, input().split()))
sum = [0] * (n + 1)
for i in range(1, n+1):
    sum[i] = sum[i-1] + list[i-1]
result = []
for i in range(3, n):
    half1 = sum[i-1] // 2
    i1 = bisect.bisect_right(sum, half1)
    if (half1 - sum[i1 - 1]) < sum[i1] - half1:
        a1 = sum[i1 - 1]
        a2 = sum[i-1] - sum[i1 - 1]
    else:
        a1 = sum[i1]
        a2 = sum[i-1] - sum[i1]
    
    
    half2 = (sum[n] + sum[i-1]) // 2
    i2 = bisect.bisect_right(sum, half2)
    if (half2 - sum[i2 - 1]) < sum[i2] - half2:
        a3 = sum[i2 - 1] - sum[i-1]
        a4 = sum[n] - sum[i2 - 1]
    else:
        a3 = sum[i2] - sum[i-1]
        a4 = sum[n] - sum[i2]
    result.append(max(a1,a2,a3,a4) - min(a1,a2,a3,a4))
print(min(result))

Measured memory_bytes: 28044
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,s,l=0;
  cin>>n>>k>>s;
  int a[n]={0};
  for(int i=0;i<n;++i)
  {
    if(l<k)
    {
      a[i]=s;
      l++;
    }
    else
     if(s==1)
       a[i]=s+1;
     else 
      a[i]=s-1;  
    cout<<a[i]<<" ";
  }
}
  

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

int main() {

	int n,len;
	char c[100000];
	char ans[100000];

	while (cin >> n, n) {

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

		cin >> len;
		for (int i = 0; i < len; i++) {
			cin >> ans[i];
			for (int j = 0; j < 2 * n; j += 2) {
				if (ans[i] == c[j]) {
					ans[i] = c[j + 1];
					break;
				}
			}
		}
		for (int i = 0; i < len; i++) {
			cout << ans[i];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3204
using System;
using System.Collections.Generic;
using System.Linq;
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = Long() + add;
        }
        return Array;
    }
}
class Program {
    static Scanner cin = new Scanner();
    static void Main() {
        int N = cin.Int();
        int M = cin.Int();
        int Q = cin.Int();
        var L = new int[M];
        var R = new int[M];

        var sum = new int[510, 510];
        for (int i = 0; i < M; i++) {
            L[i] = cin.Int();
            R[i] = cin.Int();
            sum[L[i], R[i]]++;
        }
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                sum[i, j] += sum[i, j - 1];
            }
        }
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                sum[i, j] += sum[i - 1, j];
            }
        }

        var p = new int[Q];
        var q = new int[Q];
        for (int i = 0; i < Q; i++) {
            p[i] = cin.Int();
            q[i] = cin.Int();
        }

        for (int i = 0; i < Q; i++) {
            Console.WriteLine(sum[q[i], q[i]] + sum[p[i] - 1, p[i] - 1] - sum[p[i] - 1, q[i]] - sum[q[i], p[i] - 1]);
        }
        Console.ReadLine();
    }
}

Measured memory_bytes: 19108
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    int N = 0;
    cin >> N;
    string S;
    cin >> S;
    string first;
    string last;
    if (N % 2 == 1)
    {
        cout << "No" << endl;
    }
    else{
        first = S.substr(0, S.size() / 2);
        last = S.substr(S.size() /2,S.size());
        if (first == last)
        {
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 256
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))

# ===CODE===

eps = 10 ** (-9)


def main():
    n = ni()
    e = []
    for _ in range(n):
        xi, yi = ns()
        e.append([xi, yi])

    dp = [[INF for _ in range(n)] for _ in range(n)]

    dist = lambda p1, p2: math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)

    dp[0][0] = 0

    for i in range(n - 1):
        for j in range(n):
            if dp[i][j] != INF:
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + dist(e[i], e[i + 1]))
                dp[i + 1][i] = min(dp[i + 1][i], dp[i][j] + dist(e[j], e[i + 1]))

    for i in range(n):
        dp[n - 1][n - 1] = min(dp[n - 1][n - 1], dp[n - 1][i] + dist(e[n - 1], e[i]))

    print(dp[n - 1][n - 1])


if __name__ == '__main__':
    main()



Measured memory_bytes: 28320
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,k;
  cin >> n >> k;
  int64_t a[n];
  for(int64_t i=0;i<n;i++)cin >> a[i];
    int64_t ans=1000000000000000000;
  for(int64_t bit=0;bit<(1<<n);bit++){
    if(__builtin_popcount(bit)<k || bit%2==0)continue;
    vector<int64_t> s;
    for(int64_t i=0;i<n;i++){
      if(bit&(1<<i)){
          s.push_back(i);
      }
    }
    s.push_back(n);
    int64_t l=0,sum=0;
    for(int64_t j=0;j<s.size()-1;j++){
        l=max(l+1,*max_element(a+s[j],a+s[j+1]));
        sum+=l-a[s[j]];
    }
    ans=min(ans,sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3552
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


const int INF=1e9;


const int MAX_N = 1e6;

int par[MAX_N];
int ranks[MAX_N];

void init_uft(int n){
	for(int i = 0; i < n; i++){
		par[i] = i;
		ranks[i]=0;
	}
}

int find(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x]=find(par[x]);
	}
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x==y) return;

	if(ranks[x] < ranks[y]){
		par[x]=y;
	} else{
		par[y]=x;
		if(ranks[x]==ranks[y]) ranks[x]++;
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

struct edge{int u, v ,cost; edge(){}; edge(int u, int v, int cost):u(u),v(v),cost(cost){};};

bool comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

const int MAX_V = 1e6+10;

edge es[MAX_V];
int V, E;

int kruskal(){
	sort(es, es+E, comp);
	init_uft(V);
	int res = 0;
	for(int i = 0; i< E; i++){
		edge e = es[i];
		if(!same(e.u,e.v)){
			unite(e.u,e.v);
			res += e.cost;
		}
	}
	return res;
}

int main(){
	cin>>V>>E;
	int s, t, w;
	for(int i = 0 ; i < E; i++){
		cin>>s>>t>>w;
		es[i] = edge(s, t, w);
	}
	cout<<kruskal()<<endl;
}

Measured memory_bytes: 6432
import numpy as np

N = int(input())
a = list(map(int,input().split()))
MAX = max(a)
MIN = min(a)
if MIN >= 0:
    print(N-1)
    for i in range(N-1):
        print(i+1, i+2)
elif MAX <= 0:
    print(N-1)
    for i in range(N-1):
        print(N-i, N-i-1)
else:
    if abs(MAX) >= abs(MIN):
        print(2*N-1)
        for i in range(N):
            print(a.index(MAX)+1, i+1)
        for i in range(N-1):
            print(i+1, i+2)
    else:
        print(2*N-1)
        for i in range(N):
            print(a.index(MIN)+1, i+1)
        for i in range(N-1):
            print(N-i, N-i-1)


Measured memory_bytes: 12396
#include <iostream>
#define MAX_N 200
using namespace std;
int main(void){
  int n;
  int cn[MAX_N] = {0};
  int fc = 0;
  cin >> n;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    if(a >= 3200) fc++;
    else cn[a/400] = 1;
  }
  int mi = 0;
  for(int i = 0; i < 8; i++) mi += cn[i];
  if(mi == 0) cout << 1 << " ";
  else cout << mi << " ";
  cout << mi+fc << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip	;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
class TOPO{//out is tsort's return.
	public:
	vvi G;
	vi out;
	vector<bool>V;
	vi indeg;
	int n;
	TOPO(int size){
		n=size;
		G=vvi(n);
		out=vi(0);
		V=vector<bool>(n);
		indeg=vi(n);
	}
	void add_edge(int s,int t){
		G[s].pb(t);
	}
	void bfs(int s){
		queue<int>q;
		q.push(s);
		V[s]=true;
		while(!q.empty()){
			int u=q.front();q.pop();
			out.pb(u);
			rep(i,G[u].size()){
				int v=G[u][i];
				indeg[v]--;
				if(indeg[v]==0&&!V[v]){
					V[v]=true;
					q.push(v);
				}
			}
		}
	}
	void tsort(){
		rep(i,n)indeg[i]=0;
		rep(i,n)rep(j,G[i].size()){
			int v=G[i][j];
			indeg[v]++;
		}
		rep(i,n)if(indeg[i]==0&&!V[i])bfs(i);
//		rep(i,n)cout<<" "<<out[i];cout<<endl;
	}
};
struct edge{
	int to,cost;
};
int main(){
	int n,m;
	cin>>n>>m;
	TOPO tp(n);
	vector<vector<edge> > rG(n);
	while(m--){
		int a,b,c;
		cin>>a>>b>>c;
		tp.add_edge(a,b);
		edge e={a,c};
		rG[b].pb(e);
	}
	tp.tsort();
	vi out=tp.out;
	vi dp(n);
	loop(i,1,n){
		int ma=-1;
//		cout<<out[i]<<endl;
		rep(j,rG[out[i]].size())ma=max(ma,dp[rG[out[i]][j].to]+rG[out[i]][j].cost);
		dp[out[i]]=ma;
	}
//	rep(i,n)cout<<" "<<dp[out[i]];cout<<endl;
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1268
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
    cout << !in() << endl;
  return 0;
}


Measured memory_bytes: 3664
function Main(input) {
  input = input.split("\n");
  var a = input[0];
  var ans = "a";
  if(a==a.toUpperCase()){
    var ans = "A";
  }

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define rep(i,n) for (int i=0; i < (n); ++i)
using ll = long long ;
using namespace std;
const int INF = 1001001001;


int main() {

    int n ;
    cin >> n ;
    vector<pair<ll,ll>> a(n) ;

    rep(i,n){
        cin >> a[i].second >> a[i].first ;
    }
    sort(a.begin(),a.end()) ;

    ll sum = 0 ;
    rep(i,n){
        sum+=a[i].second ;
        if(sum>a[i].first){
            cout << "No" << endl ;
            return 0 ;
        }
        //cout << sum << endl ;
    }

    cout << "Yes" << endl ;
    return 0 ;
}


Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;


int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int x, y;
    cin >> x >> y;
    int ans = INF;
    
    int z = 0;
    while (max(x, y)>=0) {
        chmin(ans, a*max(x, 0)+b*max(y, 0)+c*z);
        x--; y--; z+=2;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
#define all(x) x.begin(), x.end()
#define fi first
#define se second
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

int main() {
    Int a, b, c;
    cin >> a >> b >> c;
    dump(a + b + c >= 22 ? "bust" : "win");
    return 0;
}

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

int main(){
    int W;
    int H;
    int x;
    int y;
    int r;
    cin>>W>>H>>x>>y>>r;
    if(x-r>=0 && r+x<=W && y-r>=0 && r+y<=H){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 3116
import itertools as it

N = int(input())
S = [input() for i in range(N)]

HeadCharCnt = [0 for i in range(5)]
MARCH = 'MARCH'

for i in range(N):
    whichChar = MARCH.find(S[i][0])
    if whichChar != -1:
        HeadCharCnt[whichChar] = HeadCharCnt[whichChar] + 1

HeadCharCntPos = []
for j in HeadCharCnt:
    if j > 0:
        HeadCharCntPos.append(j)
validComb = list(it.combinations(HeadCharCntPos, 3))
ans = 0
for v in validComb:
    ans = ans + v[0] * v[1] * v[2]

print(ans)


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

typedef long long int lli;
typedef long double lld;
typedef long long ll;
//Datatype
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define vvlli vector<vector<long long int>>
#define ppi pair<int, int>
#define rppi pair<int, pair<int, int>>
#define lppi pair<pair<int, int>, int>
#define vppi vector<pair<int, int>>
#define sppi stack<pair<int int>>
#define qppi queue<pair<int, int>>
//function
#define f first
#define s second
#define pb(x) push_back(x)
#define mkp(i, j) make_pair(i, j)
#define lmkp(i,j,k) make_pair(make_pair(i,j),k)
#define rmkp(i,j,k) make_pair(i,make_pair(j,k))
//loop
#define loop(i,n) for (i = 0; i < n; ++i)
#define loops(i,k,n) for (i = k; i <= n; ++i)
#define looprev(i,k,n) for (i = k; i >= n; --i)
//Const
#define inf (int)1e9
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
//Print
#define prd(n) printf("%d", n)
#define prl(n) printf("%lld", n)
#define prdn(n) printf("%d\n", n)
#define prln(n) printf("%lld\n", n)
#define prf(n) printf("%f", n)
//Scan
#define scd(n) scanf("%d", &n)
#define scd2(a, b) scanf("%d %d", &a, &b)
#define scd3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scl(n) scanf("%lld", &n)
#define scl2(a, b) scanf("%lld %lld", &a, &b)
#define scl3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define scf(n) scanf("%f", &n)

using namespace std;
class Solution{
  public:
    int frog2(int N, vector<int> vec, int k){
      if(vec.size() == 1){
          return 0;
      }
      else if(vec.size() == 2){
          return abs(vec[1]-vec[0]);
      }
      int i, j, A[N];
      loop(i, N){
          A[i] = INT_MAX;
      }
      A[0] = 0;
      A[1] = abs(vec[1]-vec[0]);
      loops(i, 2, N-1){
          if(i < k){
              loop(j, i){
                  A[i] = min(A[j] + abs(vec[i]-vec[j]), A[i]);
              }
          }
          else{
              loops(j, i-k, i){
                  A[i] = min(A[j] + abs(vec[i]-vec[j]), A[i]);

              }
          }
      }
      return A[N-1];
    }
};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli i, j, k, n;
    Solution s;
    cin>>n>>k;
    vector<int> vec(n, 0);
    loop(i, n){
        cin>>vec[i];
    }
    int res = s.frog2(n, vec, k);
    cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 4520
#include<stdio.h>

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dfs();
void dfs_visit(int);

int n, M[MAX][MAX];
int color[MAX],d[MAX],f[MAX];
int tt;


void dfs(){
  int u;

  for(u=0;u<n;u++){
    color[u] = WHITE;
  }
    tt = 0;

    for(u=0;u<n;u++){
      if( color[u] == WHITE ){
	dfs_visit(u);
      }}
      
      for(u=0;u<n;u++){
	printf("%d %d %d\n", u+1,d[u],f[u]);
      }
  
    
    }

    void dfs_visit(int u){
      int v;
      color[u] = GRAY;
      d[u] = ++tt;
      for(v=0;v<n;v++){
	if(M[u][v]==0){
	  continue;
	}
	if( color[v]== WHITE){
	  dfs_visit(v);
	}
      }
      color[u] = BLACK;
      f[u]= ++tt;
    }                       
  
int main(){
  int i,j;
  int u,k,v;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;     //  A[1][1] denaku A[0][0]dekanngaeteiru
    
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();


  return 0;

}




Measured memory_bytes: 2112
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

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

int return_min(vector<int> dp, vector<int> h, int K, int index) {
    int tmp;
    int min_val = 10001;
    for (int hohaba = 1; hohaba <= K; hohaba++) {
        if (hohaba > index) {
            tmp = 10001;
        } else {
            tmp = dp[index - hohaba] + abs(h[index] - h[index - hohaba]);
        }
        if (min_val > tmp) {
            min_val = tmp;
        }
    }
    return min_val;
}

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

    long long N, K;
    cin >> N >> K;
    vector<long long> h(N);
    for (long long i = 0; i < N; i++) {
        long long tmp;
        cin >> tmp;
        h[i] = tmp;
    }

    vector<long long> dp(N);
    for (long long i = 1; i < N; i++) {
        // dp[i] = return_min(dp, h, K, i);
        long long tmp;
        long long min_val = 1e9;
        for (long long hohaba = 1; hohaba <= K; hohaba++) {
            if (hohaba > i) {
                tmp = 1e9;
            } else {
                tmp = dp[i - hohaba] + abs(h[i] - h[i - hohaba]);
            }
            if (min_val > tmp) {
                min_val = tmp;
            }
            debug(tmp, hohaba, min_val);
        }
        dp[i] = min_val;
        debug(i, dp);
    }
    cout << dp[N - 1] << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;


int main(){
    int a,b,c,d,sum = 0;
    cin >> a >> b >> c >> d;
    if(a > b) sum += b;
    else sum += a;
    if(c > d) sum += d;
    else sum += c;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var s = arr[0] == arr[1] ? "==" : arr[0] > arr[1] ? ">" : "<";

            Console.WriteLine($"a {s} b");
        }
    }
}



Measured memory_bytes: 16396