akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int a,b,c,n,d=0;
  cin>>a>>b>>c>>n;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      if(n-(a*i+b*j)>=0&&(n-(a*i+b*j))%c==0)d++;
    }
  }
  cout<<d;
}

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

namespace ABC093
{
    class C
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int[] ABC = new int[3] { int.Parse(input[0]), int.Parse(input[1]), int.Parse(input[2]) };

            int max = ABC.Max();
            if ((3 * max) % 2 != (ABC[0] + ABC[1] + ABC[2]) % 2) { max = ABC.Max() + 1; }

            Console.WriteLine(((3 * max) - (ABC[0] + ABC[1] + ABC[2])) / 2);
        }
    }
}


Measured memory_bytes: 13268
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main(){
	int a,b,c,d,ans,keta=1;
	cin>>a;
		b=(a/100);
//		cout<<"b="<<b<<endl;
		a=a%100;
		keta++;

		c=(a/10);
	//	cout<<"c="<<c<<endl;
		a=a%10;
		keta++;

	d=a;
//	cout<<d<<endl;
	if(keta==1)
		cout<<"Yes"<<endl;
	else if(keta==2){
		if(c==d)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	else{
		if(b==d)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;

	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void)
{
  int a,b;
  
  cin>>a;
  cin>>b;
  
  if(a==1 && b==2 || a==2 && b==1)
    cout<<3<<endl;
  else if(a==1 && b==3 || a==3 && b==1)
    cout<<2<<endl;
  else
    cout<<1<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int last(int d,int i){
  
  return ;
}

int main(){
  int d=0;
  int c=0;
  int s[365][26]={0};
  
  int lastDay[27]={0};
  int tmp=0;
  int i,j;
  
  scanf("%d",&d);

  for(i=0;i<26;i++){
    scanf("%d",&tmp);
    c+=tmp;
  }
  
  for(i=0;i<365;i++){
    for(j=0;j<26;j++){
      scanf("%d",&s[i][j]);
    }
  }

  for(i=0;i<365;i++){
    int max=s[i][0];
    int max_t=1;
    for(j=1;j<26;j++){
      if(s[i][j]>max){
	max=s[i][j];
	max_t=j+1;
      }
    }
    printf("%d\n",max_t);
  }

  return 0;
}


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

using namespace std;

typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
const ll mod = 1e9 + 7;

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> s(n), t(m);
    rep(i, n) cin >> s[i];
    rep(i, m) cin >> t[i];

    vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
    vector<vector<ll>> sum(n + 1, vector<ll>(m + 1, 0));
    rep(i, n) {
        rep(j, m) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = sum[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = 0;
            }
            dp[i + 1][j + 1] %= mod;
            sum[i + 1][j + 1] = sum[i][j + 1] + sum[i + 1][j] + dp[i + 1][j + 1];
            sum[i + 1][j + 1] %= mod;
            sum[i + 1][j + 1] = (sum[i + 1][j + 1] + mod - sum[i][j]) % mod;
        }
    }

    ll ans = 1;
    rep(i, n + 1) rep(j, m + 1) ans += dp[i][j], ans %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 62976
#include <iostream>

using namespace std;

int main()
{
  int a, b;

  while (cin >> a, cin >> b, a or b) {
    for (int i=0; i<a; ++i) {
      for (int j=0; j<b; ++j)
        cout << "#";
      cout << endl;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> B(N - 1);
    REP(i, 0, N - 1) cin >> B[i];

    int ans = B[0];
    REP(i, 0, N - 1) {
        if (i == N - 2) ans += B[i];
        else ans += min(B[i], B[i + 1]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <complex>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>

using namespace std;
typedef long long ll;


int main()
{

	int n;
	string s;
	std::cin >> n;
	std::cin >> s;

	int r = 0, l = 0;

	for (int i = 0; i < n; ++i)
	{
		if (s.substr(i, 1) == ".") ++r;
	}

	int val = r + l;
	
	for (int i = 0; i < n; ++i)
	{
		if (s.substr(i, 1) == "#")
		{
			++l;
		}
		else
		{
			--r;
		}

		int comp = r + l;
		if (comp < val) val = comp;
	}

	cout << val << endl;

	return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
)

func main() {
	var n, k, r, s, p, result int
	var t string
	fmt.Scanf("%d %d", &n, &k)
	fmt.Scanf("%d %d %d",&r, &s, &p)
	fmt.Scanf("%s", &t)

	// 各出し手に対する勝ち点
	score := map[rune]int {
		's': r,
		'p': s,
		'r': p,
	}

	// 勝利した場合のフラグ
	winFlg := make(map[int]bool, len(t))

	for i, ru := range t[:n] {
		// k回目までは必ず勝つ
		if i < k {
			result += score[ru]
			winFlg[i] = true
		} else {
			// 以下のいずれかに当てはまる場合勝つ
			// 前回同じ手でない
			// 前回負けている
			if t[i] != t[i - k] || winFlg[i - k] == false {
				result += score[ru]
				winFlg[i] = true
			}
		}
	}

	fmt.Printf("%d", result)
}

Measured memory_bytes: 3072
PROGRAM ATCODER

implicit none
integer(16) :: n,x,i,ans=0
integer(16),allocatable :: a(:),b(:)

read(*,*) n,x
allocate(a(n),b(n-1))
read(*,*) (a(i), i=1,n)

do i = 1, n
  if ( a(i) >x ) then
    ans = ans + a(i) - x
    a(i) = x
  end if
end do

do i = 2,n
  b(i-1) = a(i) + a(i-1)
end do

do i = 1,n-2
  if ( b(i) > x ) then
    ans = ans + b(i) - x
    b(i+1) = b(i+1) - (b(i) - x)
  end if
end do

if ( b(n-1) > x ) then
  ans = ans + b(n-1) - x  
end if

write(*,'(i0)') ans

contains
!!!!!! サブルーチンは↓
!!!!!!

END PROGRAM ATCODER


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

int main (){
    string steps;
    cin >> steps;
    int i;
    bool right = true;
    bool left = true;
    for(i= 0; i <steps.size(); i++){
        if( (steps[i] != 'U') && steps[i] != 'D' && steps[i] != 'R' && steps[i] != 'L'){
            cout << "No" << endl;
            return 0;
        }
        if(steps[i] != 'U' && steps[i] != 'D' ){
            if( i % 2 == 0){ // Right
                right &= (steps[i] == 'R');
            } else { // Left
                left &= (steps[i] == 'L');
            }
        }
    }
    if(right && left){
        cout << "Yes" << endl;;
        return 0;
    }
    cout << "No" << endl;;
    return 0;
}

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

int main() {
	int N, ans = 0;
	cin >> N;
	vector<int> L(N);
	for (int& i : L) cin >> i;
	sort(L.begin(), L.end());
	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			int a = max(upper_bound(L.begin(), L.end(), L[i] - L[j]), upper_bound(L.begin(), L.end(), L[j] - L[i])) - L.begin();
			a = max(a, j + 1);
			int b = lower_bound(L.begin(), L.end(), L[i] + L[j]) - L.begin();
			b = max(b, j + 1);
			ans += b - a;
		}
	}
	cout << ans;
}

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

using namespace std;

const int MaxN = 2e5 + 25;
const int MOD = 1e9 + 7;


int main()
{
//    freopen("input.txt", "r", stdin);

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

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

    if(k == 0)
    {
        cout << n * 1ll * n << '\n';
        return 0;
    }

    long long ans = 0;

    for(int a = max(k, 1); a <= n; ++a)
    {
        for(int l = 0; l <= n; l += a)
        {
            int r = l + a - 1;
            if(r <= n)
                ans += (a - k);
            else
            {
                int len = n - l + 1;
                if(len >= k)
                    ans += len - k;
            }
        }
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
from fractions import gcd
from itertools import accumulate

N = int(input())
a = list(map(int, input().split()))

b = list(accumulate([0] + a, gcd))
c = list(accumulate([0] + a[::-1], gcd))
l = list(gcd(s, t) for s, t in zip(b[:-1], c[::-1][1:]))
print(max(l))


Measured memory_bytes: 16152
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n);++i)
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    vector<int> ans(N);
    rep(i, N) ans[a[i] - 1] = i + 1;
    rep(i, N) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 1664
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	fmt.Println(lcm(2, N))
}
func lcm(a, b int) int {
	return a * b / gcd(a, b)
	// return a / gcd(a, b) * b   桁あふれ対策
}
func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

ll euclid(ll a, ll b){
    if(a < b) return euclid(b, a);
    
    if(a % b == 0) return b;
    else return euclid(b, a % b);

}

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

    //A-1，B以下のそれぞれで割り切れない個数(とりあえず重複無視)
    ll div_underB = b - (b / c + b / d);
    ll div_underA = (a - 1) - ((a - 1) / c + (a - 1) / d);

    ll l = c * d / euclid(c, d);//最小公倍数

    //重複して引いた個数を足し戻す
    div_underB += b / l;
    div_underA += (a - 1) / l;

    cout << div_underB - div_underA << endl;
}


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

using namespace std;

const double pi=acos(-1.0);
const double eps=1e-11;

#define size(A) ((int)A.size())
#define length(A) ((int)A.length())
#define all(A) A.begin(),A.end()
#define mp(A,B) make_pair(A,B)
#define pb(x) push_back(X);

using int64=long long int;
using ipair=pair<int,int>;
using vi=vector<int>;
using vd=vector<double>;

int n,l;

bool cmp(const string& lhs,const string& rhs){
	return lhs+rhs<rhs+lhs;
}

int main(){
	cin>>n>>l;
	vector<string> a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(all(a),cmp);
	for(auto& str:a)
		cout<<str;
	cout<<endl;
}

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

//#include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// using cint = cpp_int;

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ull MAX = ULONG_MAX;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)
#define input(a) scanf("%lld", &(a))
#define print(a) printf("%lld\n", (a))

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

#define dump(a, h, w)                                                          \
    rep(i, h) {                                                                \
        rep(j, w) cerr << a[i][j] << space;                                    \
        cerr << endl;                                                          \
    }
#define lldump(a, n) dump(vector<vector<ll>>{a}, 1, n)

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define each(i, a) for (auto &&i : a)
#define rep(i, n) inc(i, 0, n - 1)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC optimization_level 3
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }
func sign(ll a) { return a ? abs(a) / a : 0; }

def in() {
    ll A;
    cin >> A;
    return A;
}

ll x, y, res;
signed main() {
    cin >> x >> y;
    if (x < y) {
        res = y - x;
        if (x <= 0 && 0 <= y) res = min(res, abs(abs(y) - abs(x)) + 1);
    } else {
        if (x >= 0 && y <= 0)
            res = abs(abs(y) - abs(x)) + 1;
        else
            res = x - y + 2;
    }
    cout << res << endl;
}

// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++17


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

using lint = int64_t;
#define bit(n) ((lint)1 << n);
const int INF = 1e9;
const lint LINF = 1e18;

const lint MOD = 1e9 + 7;
// const lint MOD = 998244353;

class IoSetup {
    public:
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(12);
        cerr << fixed << setprecision(12);
    }
} iosetup;

int main() {
    int n, k;
    cin >> n >> k;
    if (k == 1) {
        cout << 0 << endl;
    } else {
        cout << n - k << endl;
    }

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var L, R int
	fmt.Scan(&L, &R)

	ret := 2018
	for i := L; i <= R-1; i++ {
		I := i % 2019
		if I == 0 {
			ret = 0
			break
		}
		for j := i + 1; j <= R; j++ {
			J := j % 2019
			if J == 0 {
				ret = 0
				break
			}
			r := I * J % 2019
			if r < ret {
				ret = r
			}
		}
	}
	fmt.Println(ret)
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

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

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};


/////////////////////////////////////////////////////////////////////////////////////////

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

    int n,m;
    cin >> n >> m;
    vector<vector<int>> p(1e5+1);
    for (int i = 0;i < n;i++){
        int a,b;
        cin >> a >> b;
        p[a].push_back(b);
    }

    long long ans = 0;

    priority_queue<int> que;

    for (int i = 1;i <= m;i++){
        for (int j = 0;j < p[i].size();j++){
            que.push(p[i][j]);
        }

        if (!que.empty()){
            ans += que.top();
            que.pop();
        }
    }

    cout << ans << endl;

    return 0;

}

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

#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 EPS (1e-7)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

int vx[]={0,1,0,-1};
int vy[]={1,0,-1,0};

int dx[]={1,0,-1,1,-1,1,0,-1};
int dy[]={1,1,1,0,0,-1,-1,-1};

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int MAX=1e9;

const int MAX_N=100001;

int main(){
	int n,C;
	cin>>n>>C;
	int t[n];
	int s[n];
	int c[n];
	int cnt[2*MAX_N];
	fill(cnt,cnt+2*MAX_N,0);
	vector<pii> cha[C];
	REP(i,n){
		cin>>s[i]>>t[i]>>c[i];
		c[i]--;
		cha[c[i]].push_back(pii(s[i],t[i]));
	}
	REP(i,C){
		bool count[2*MAX_N];
		fill(count,count+2*MAX_N,false);
		REP(j,(int)cha[i].size()){
			int start=cha[i][j].first*2-1;
			int end=cha[i][j].second*2-1;
			for(int k=start;k<=end;k++){
				if(!count[k]){
					cnt[k]++;
					count[k]=true;
				}
			}
		}
	}
	int ans=0;
	REP(i,2*MAX_N){
		ans=max(ans,cnt[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3584
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

P p[510000];
long long int S[510000] = {}, DP[510000] = {};

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> p[i].first >> p[i].second;
    }
    sort(p, p + N);
    long long int SS = 0;
    for(int i = 0; i < N; i++){
        SS += p[i].second;
        S[i] = SS - p[i].first;
    }
    DP[N] = -INF;
    for(int i = N - 1; i >= 0; i--){
        DP[i] = max(S[i], DP[i + 1]);
    }
    SS = -p[0].first;
    long long int ans = DP[0] - SS;
    for(int i = 0; i < N - 1; i++){
        SS = min(SS, S[i] + p[i].first - p[i + 1].first);
        ans = max(ans, DP[i + 1] - SS);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 18892
//#include <bits/stdc++.h>
#include <iostream>
#include <string>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  string s;
  cin >> s;
  if (s[0] != s[1] && s[1] != s[2] && s[0] != s[2]) cout << "Yes";
  else cout << "No";
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3596
package main

import "fmt"

func last(s string) byte {
	return s[len(s)-1]
}

func main() {
	var a, b, c string
	fmt.Scan(&a, &b, &c)
	if last(a) == b[0] && last(b) == c[0] {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n, a, b;
  cin >> n >> a >> b;
  if (a % 2 == b % 2)
    cout << (b - a) / 2 << endl;
  else
    cout << min(a - 1, n - b) + 1 + (b - a - 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    while (sc.hasNext()) {
      int a = sc.nextInt();
      int b = sc.nextInt();

      System.out.println(gcd(a, b) + " " + lcm(a, b));
    }
  }

  static void swap(int a, int b) {
    int temp = a;
    a = b;
    b = temp;
  }

  static int gcd(int a, int b) {
    if (a < b) swap(a, b);

    while (b != 0) {
      int temp = b;
      b = a % b;
      a = temp;
    }

    return a;
  }

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

Measured memory_bytes: 17372
#include <algorithm>
#include <cstdio>

using namespace std ;

const int N=1<<12 ;

int s[20][20] ;
int p[20] ;
int n , m ;

int t[20] ;
inline int check ( int S )
{
	int i , j ;
	for ( i=1 ; i<=m ; i++ ) 
	{
		int flag=0 ;
		for ( j=1 ; j<=s[i][0] ; j++ ) flag^=((S>>(s[i][j]-1))&1);
		if ( (flag^p[i])==1 ) return 0 ;
	}
	return 1 ;
}

int main ()
{
	int i , j , res=0 ;
	scanf("%d%d",&n,&m);
	for ( i=1 ; i<=m ; i++ ) 
	{
		scanf("%d",s[i]);
		for ( j=1 ; j<=s[i][0] ; j++ ) scanf("%d",s[i]+j);
	}
	for ( i=1 ; i<=m ; i++ ) scanf("%d",p+i);
	for ( i=0 ; i<(1<<n) ; i++ ) res+=check(i);
	printf("%d\n",res);
	return 0 ;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <cstring>
#include <sstream>
#include <stdlib.h>

using namespace std;

int main (void)
{
	int n,a[20],b[20];
	cin >> n;

	long gg = 1000;

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

	int co = 0;

	for (int i = 0; i < n; i++)
	{
		if (co < b[i])
		{
			co = 0;
			co = b[i];
			gg = 0;
			gg = a[i];
		}
		if (co == b[i])
		{
			if (a[i] < gg)
			{
				gg = 0;
				gg = a[i];
			}
		}
	}

	cout << gg << " " << co << endl;
}




Measured memory_bytes: 3104
import java.util.*;
import java.io.*;

/**
 * Made by egor https://github.com/chermehdi/egor.
 * 
 * @author Azuz
 * 
 */
public class Main {

    private static final long MOD = (long) 1e9 + 7l;

    void solve(Scanner in, PrintWriter out) {
      int n = in.nextInt();
      long[] arr = new long[n];

      long sum = 0;
      for (int i = 0; i < n; ++i) {
        arr[i] = in.nextInt();
        sum = (sum + arr[i]) % MOD;
      }

      long ans = 0;
      for (int i = 0; i < n; ++i) {
        sum = (((sum - arr[i]) % MOD) + MOD) % MOD;
        long tmp = ((arr[i] % MOD)  * sum) % MOD;
        ans = (ans + tmp) % MOD;
      }
    
      out.println(ans);

    }

    public static void main(String[] args) {
        try(Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
        }
    }
}


Measured memory_bytes: 59752
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define endl "\n"

using namespace std;

struct obj
{
    int v, w;
};

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

    obj arr[n];

    for (int i = 0; i < n; i++)
    {
        int v, w;
        cin >> w >> v;
        arr[i].v = v;
        arr[i].w = w;
    }

    ll dp[n][m + 1] = {0};

    for (int i = 0; i < n; i++)
    {
        dp[i][0] = 0;
    }
    for (int i = 1; i <= m; i++)
    {
        if (arr[0].w <= i)
        {
            dp[0][i] = arr[0].v;
        }
        else
        {
            dp[0][i] = 0;
        }
    }

    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            if (arr[i].w <= j)
            {
                dp[i][j] = max(arr[i].v + dp[i - 1][j - arr[i].w], dp[i - 1][j]);
            }
            else
            {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }

    cout << dp[n - 1][m] << endl;
}


Measured memory_bytes: 78336
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

ll PowMod(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = PowMod(N, P/2, M);
        return t*t % M;
    }
    return N * PowMod(N, P-1, M);
}
const int MAX = 200005;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    COMinit();
    int n,a,b;
    cin >> n >> a >> b;
    ll ans = 1;
    ans = PowMod(2,n,mod);
    ans--;

    ll na = 1 , nb = 1;

    rep(i,a){
        na *= (n-i);
        na %= mod;
    }
    rep(i,a){
        na *= inv[i+1];
        na %= mod;
    }
    rep(i,b){
        nb *= (n-i);
        nb %= mod;
    }
    rep(i,b){
        nb *= inv[i+1];
        nb %= mod;
    }
    cout << (ans - na - nb + mod*2)%mod << endl;
}

Measured memory_bytes: 4992
n,m=gets.chomp.split.map(&:to_i)

sa=(n-m).abs
if sa > 1
    puts 0
    exit
end

ans = 1
max = 1000000000 + 7

ans = 2 if sa == 0

n.times do |i|
    ans *= (i+1)
    ans = ans % max if ans >= max
end

m.times do |i|
    ans *= (i+1)
    ans = ans % max if ans >= max
end


puts ans

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll MAX = pow(10, 18) + 5;

ll search(vector<ll> &A, ll x) {
    ll cnt = 0;
    for(int i = 0; i < A.size(); i++) {
        int l = -1;
        int r = A.size();
        int mid;
        if(A.at(i) < 0) {
            while(l + 1 != r) {
                mid = (l + r) / 2;
                if(A.at(i) * A.at(mid) < x) {
                    r = mid;
                } else {
                    l = mid;
                }
            }
            cnt += A.size() - r;
        } else {
            while(l + 1 != r) {
                mid = (l + r) / 2;
                if(A.at(i) * A.at(mid) < x) {
                    l = mid;
                } else {
                    r = mid;
                }
            }
            cnt += r;
        }
        if(A.at(i) * A.at(i) < x) {
            cnt--;
        }
    }
    return cnt / 2;
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());

    ll l = -MAX;
    ll r = MAX;
    ll mid;
    ll n;
    while(l + 1 != r) {
        mid = (l + r) / 2;
        n = search(A, mid);
        if(n < K) {
            l = mid;
        } else {
            r = mid;
        }
    }
    cout << l << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    string S;
    cin >> S;
    bool ans = false;
    for ( int i = 0; i < S.length()-1; i++ ) {
        if ( S[i] == 'A' && S[i+1] == 'C' ) { ans = true; }
    }
    
    cout << (ans ? "Yes" : "No" ) << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n,k; cin>>n>>k;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    vector<vector<ll>> dp(100,vector<ll>(2,-1));
    // dp[i][smaller]:上からi桁使う
    dp[0][0]=0;
    for(ll digit=0; digit<50; digit++){
        ll mask=(1LL<<(49-digit));
        ll num=0; //この桁が立っている数
        rep(i,n) if(a[i] & mask) num++;
        ll score0=num*mask;
        ll score1=(n-num)*mask;
        if(dp[digit][1]!=-1) chmax(dp[digit+1][1],dp[digit][1]+max(score0,score1));
        if(dp[digit][0]!=-1){
            if(k & mask) chmax(dp[digit+1][1],dp[digit][0]+score0);
        }
        if(dp[digit][0]!=-1){
            if(k & mask) chmax(dp[digit+1][0],dp[digit][0]+score1);
            else chmax(dp[digit+1][0],dp[digit][0]+score0);
        }
    }
    cout<<max(dp[50][0],dp[50][1])<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<utility>
#define ul unsigned long long int
#define ll long long int
#define MAX 1000000+1
using namespace std;
#define F first
#define S second
#define pi 2*acos(0.0)
#define PB push_back
#define CL clear()







int main()
{
  ll n, t, r = 0;
  cin >> n;
  while(n--)
  {
      cin >> t;
      r+=(t-1);
  }
 cout << r;



    return 0;
}



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

using i64 = int64_t;

struct Box{
    i64 c, e;
};

i64 dp[502][10004]={0}, cumsum[10004]={0};

int main(){
    int m, n;
    cin >> m >> n;
    vector<i64> p;
    for(int i=0;i<m;++i){
        i64 tmp;
        cin >> tmp;
        p.push_back(tmp);
    }
    vector<Box> b;
    for(int i=0;i<n;++i){
        i64 c, e;
        cin >> c >> e;
        b.push_back((Box){c, e});
    }

    sort(p.begin(), p.end(), greater<i64>());
    for(int i=1;i<=m;++i)cumsum[i] = cumsum[i-1] + p[i-1];
    for(i64 i=0;i<n;++i){
        for(i64 j=0;j<=m;++j){
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            i64 cnt = min(b[i].c, m-j);
            i64 price = cumsum[j+cnt] - cumsum[j];
            i64 benefit = price - b[i].e;
            dp[i+1][j+cnt] = max(dp[i+1][j+cnt], dp[i][j] + benefit);
        }
    }

    i64 ans = 0;
    for(int i=0;i<=m;++i)ans = max(ans, dp[n][i]);

    cout << ans << endl;

    return 0;
}



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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
    int x(0), sgn(1); char ch(getchar());
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
    for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
    return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("C.in", "r", stdin);
	freopen ("C.out", "w", stdout);
#endif
}

const int N = 1e5 + 1e3;

int n, x[N], suf[N];

int nxt[N][20], log2n;

inline int Calc(int a, int b) {
	int res = 0;
	Fordown (i, log2n, 0)
		if (nxt[a][i] < b) a = nxt[a][i], res |= 1 << i;
	return res + 1;
}

int main() {

	File();

	n = read();
	For (i, 1, n)
		x[i] = read();

	int L = read();

	suf[1] = 1;
	for (int i = 1; i <= n; ++ i, suf[i] = suf[i - 1])
		while (suf[i] < n && abs(x[suf[i] + 1] - x[i]) <= L) ++ suf[i];

	For (i, 1, n)
		nxt[i][0] = suf[i];

	log2n = ceil(log2(n));
	For (j, 1, log2n) For (i, 1, n)
		nxt[i][j] = nxt[nxt[i][j - 1]][j - 1];

	int q = read();
	For (i, 1, q) {
		int a = read(), b = read();
		if (a > b) swap(a, b);
		printf ("%d\n", Calc(a, b));
	}

    return 0;

}


Measured memory_bytes: 9472
n = gets.to_i
h = gets.split.map(&:to_i)

prev = 10**9 + 1
cnt = 0
ans = 0
for i in 0...n
    cur = h[n-1-i]
    
    if cur >= prev
        cnt += 1
        ans = [ans, cnt].max
    else
        cnt = 0
    end

    # p "#{cur} #{prev} #{cnt} #{ans}" 

    prev = cur
end

puts ans

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int ans = 1e9;
  for (int k = 0; k <= max(x, y); k++) {
    ans = min(ans, k * 2 * c + max(0, x - k) * a + max(0, y - k) * b);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/*
 *  Created on: 19 / 9 / 2020
 *  Author:     Eslam Waheed
 */

#define _CRT_SECURE_NO_WARNINGS
//#define __USE_MINGW_ANSI_STDIO

#include<bits/stdc++.h>
//#include <bits/BIGINT.h>
//#include <bits/Int128.h>
using namespace std;

#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define ld   long double

#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   s.size()
#define endl    '\n'

//ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }

//const ld PI = acos(-1);
//const ll mod = 1e9 + 7;
//const ld EPS = 1e-8;
/*
 you can ^_^ (•‿•)

( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )
*/
int main()
{
    //stp(0)
    Eslam__Waheed;
    ll n; cin >> n;
    ll ans = 0;
    for (int i = 1;; i++)
    {
        bool f = 1;
        for (int j = 1;; j++)
        {
            if (f && i * j > n)
            {
                cout << ans;
                return 0;
            }
            if (i * j < n)
            {
                ans++;
                f = 0;
            }
            else
                break;

           // cout << i << ' ' << j << endl;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3648
K, N = map(int,input().split())
A = list(map(int, input().split()))
l = 0
L = []
for i in range(N-1):
  l = A[i+1] - A[i]
  L.append(l)
L.append(K-A[N-1]+A[0])
print(sum(L)-max(L))

Measured memory_bytes: 26444
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			long x = sc.nextLong();
			long k = sc.nextLong();
			long d = sc.nextLong();
			
			
			long ans = 0;
			long step = Math.abs(x) / d;
			x = Math.abs(x);

			if ( k <= step ) {
				ans = x - k * d;
			}
			else {
				long additionalStep = k - step;
				if ( additionalStep % 2 == 0 ) {
					//can go minimum
					ans = x % d;
				}
				else {
					//should go opposite side
					ans = d - x % d;
				}
				
			}
			
			System.out.println(ans);
		}
	}

}

Measured memory_bytes: 35756
N = int(input())
A = list(map(int,input().split()))
ans = 0
i = 0
while True:
	if A[i] % 2 == 0:
		A[i] /= 2
	else:
		break
	if i == N-1:
		i = 0
		ans += 1
	else:
		i += 1
print(ans)
	


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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
	string s;
	cin >> s;

	reverse(s.begin(), s.end());
	for (int i = 0; i < 4; i++) reverse(divide[i].begin(), divide[i].end());

	bool can = 1;
	for (int i = 0; i < s.size();) {
		bool can2 = 0;
		for (int j = 0; j < 4; j++) {
			string d = divide[j];
			if (s.substr(i, d.size()) == d) {
				can2 = 1;
				i += d.size();
			}
		}
		if (!can2) {
			can = 0;
			break;
		}
	}

	if (can) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 512
n, q = map(int, input().split())
s = input()
query = [tuple(map(int, input().split())) for _ in range(q)]
cum = [0] * n
for i in range(n-1):
    cum[i+1] = cum[i] + int(s[i:i+2] == 'AC')

for l, r in query:
    print(cum[r-1] - cum[l-1])

Measured memory_bytes: 21348
#include <iostream>
#include <queue>
using namespace std;
int main(){
    queue<char> a;
    queue<char> b;
    queue<char> c;
    string s;
    cin >> s;
    for(char ch : s) {
        a.push( ch );
    }
    cin >> s;
    for(char ch : s) {
        b.push( ch );
    }
    cin >> s;
    for(char ch : s) {
        c.push( ch );
    }
    
    int u = 0;
    while(1) {
        if(u == 0) {
            if(a.empty()) {
                break;
            }
            u = (a.front() - 'a');
            a.pop();
        }
        if(u == 1) {
            if(b.empty()) {
                break;
            }
            u = (b.front() - 'a');
            b.pop();
        }
        if(u == 2) {
            if(c.empty()) {
                break;
            }
            u = (c.front() - 'a');
            c.pop();
        }
    }
    cout << (char)('A' + u) << endl;
}


Measured memory_bytes: 256
from collections import deque
class Dinic:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def bfs(self, s, t):
        self.level = level = [None]*self.N
        deq = deque([s])
        level[s] = 0
        G = self.G
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] is None:
                    level[w] = lv
                    deq.append(w)
        return level[t] is not None

    def dfs(self, v, t, f):
        if v == t:
            return f
        level = self.level
        for e in self.it[v]:
            w, cap, rev = e
            if cap and level[v] < level[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        INF = 10**9 + 7
        G = self.G
        while self.bfs(s, t):
            *self.it, = map(iter, self.G)
            f = INF
            while f:
                f = self.dfs(s, t, INF)
                flow += f
        return flow

n = int(input())
ab = []
cd = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append([i+1, a, b])

for i in range(n):
    c, d = map(int, input().split())
    cd.append([n+1+i, c, d])

s = 0
g = 2 * n + 1
edge = []
for i in range(1, n + 1):
    edge.append([0, i])
for i in range(n + 1, g):
    edge.append([i, g])


for i in range(len(ab)):
    i_idx, a, b = ab[i]
    for j in range(len(cd)):
        j_idx, c, d = cd[j]
        if a < c and b < d:
            edge.append([i_idx, j_idx])

try:
    dinic = Dinic(len(edge))

    for i in range(len(edge)):
        dinic.add_edge(edge[i][0], edge[i][1], 1)
    ans = dinic.flow(s, g)

    print(ans)
except:
    print(0)


Measured memory_bytes: 5108
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tommy6073
 */

#include <iostream>
#include <string>

using namespace std;

class AGrouping2 {
public:
    void solve(std::istream& in, std::ostream& out) {
        int N;
        in >> N;

        out << N / 3;
    }
};


int main() {
	AGrouping2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
using namespace std;
int n, w[101000];
long long res = 1, Mod = 1000000007;
int main(){
    int i, pv = 0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&w[i]);
    }
    
    for(i=1;i<=n;i++){
        if(pv<i)pv=i;
        while(pv < n && w[pv+1] >= (pv+1-i)*2 && w[pv] >= (pv+1-i)*2-1)pv++;
        res=res*(pv-i+1)%Mod;
    }
    printf("%lld\n",res);
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>


using namespace std;
const int MaxStringSize = 1000;
const int NullMemo = -1;

int calc_LCS(string str1, string str2) {
  // Memo[n][m] は str1.sub(0, n) と str2.sub(0, m)のLCSをmemoする。
  int memoLCS[str1.size() + 1][str2.size() + 1];

  for(int i = 0; i <= str1.size(); i++) {
    memoLCS[i][0] = 0;
  }
  for(int i = 0; i <= str2.size(); i++) {
    memoLCS[0][i] = 0;
  }

  for(int i = 1; i <= str1.size(); i++) {
    for(int j = 1; j <= str2.size(); j++) {
      if(str1[i - 1] == str2[j - 1]) {
        memoLCS[i][j] = memoLCS[i - 1][j - 1] + 1;
      } else {
        memoLCS[i][j] = max(memoLCS[i][j - 1], memoLCS[i - 1][j]);
      }
    }
  }

  return memoLCS[str1.size()][str2.size()];
}

int main() {
  int datasets_num;
  string str1;
  string str2;

  cin >> datasets_num;

  for(int i = 0; i < datasets_num; i++) {
    cin >> str1 >> str2;

    cout << calc_LCS(str1, str2) << endl;
  }
}



Measured memory_bytes: 7068
#include<bits/stdc++.h>
using namespace std;
 
#define int             long long
#define ld              long double
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int, int>
#define mk(arr,n,type)  type *arr=new type[n];
#define vi              vector<int>
#define si              set<int>
#define usi             unordered_set<int>
#define mii             map<int, int>
#define umii            unordered_map<int, int>
#define pqmax           priority_queue<int>
#define pqmin           priority_queue<int, vi, greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define trailzrobits(x) __builtin_ctzll(x)
#define leadzrobits(x)  __builtin_clzll(x)
#define paritybits(x)   __builtin_parityll(x)
#define gcd             __gcd
#define lcm(x, y)       (x * y) / gcd(x, y)
#define mod             1000000007
#define endl            '\n'
#define PI              3.14159265358979323846
#define inf             1e18
#define sp(x,y)         fixed<<setprecision(y)<<x

void __print(int x) {cout<<x;}
void __print(float x){cout<<x;}
void __print(double x){cout<<x;}
void __print(ld x) {cout<<x;}
void __print(char x){cout <<'\''<<x<<'\'';}
void __print(const char *x){cout <<'\"' <<x<<'\"';}
void __print(const string &x) {cout<<'\"'<<x<<'\"';}
void __print(bool x) {cout<<(x?"true":"false");}
template<typename T,typename V>     void __print(const pair<T,V> &x) {cout<<'{';__print(x.first);cout<<',';__print(x.second);cout<<'}';}
template<typename T>                void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}void _print() {cout << "]\n";}
template <typename T,typename... V> void _print(T t, V... v) {__print(t);if(sizeof...(v))cout<<", ";_print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_print(x)
#else 
#define dbg(x...)
#endif

int power(int x, int y, int p = mod){
    int res = 1;
    x %= p;
    while(y > 0){
        if(y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res; 
}

int inv(int x, int p = mod){
    return power(x, p - 2) % p;
}

const int N = 1e6 + 6;
 
int32_t main(){

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int t = 1;
    // cin >> t;
    while(t--){
        
        int n, k; cin>>n>>k;
        mk(a, n+1, int);
        for(int i=1; i<=n; i++)
            cin>>a[i];
        
        mk(dp, n+1, int);
        dp[1] = 0;

        for(int i=2; i<=n; i++){
            dp[i] = inf;
            for(int j=i-1; j>=i-k; j--){
                if(j>=1)
                    dp[i] = min(dp[i], abs(a[i] - a[j]) + dp[j]);
            }
        }

        cout<<dp[n];
    }

    return 0;

}

Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


void solve() {
    long long N; cin >> N;

    long long ans = 0;

    for (int i = 1; i <= N; i++) {
        for (int j = i; j <= N; j+=i) {
            ans += j;
        }
    }

    cout << ans << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3580
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = Console.ReadLine();
            string str2 = Console.ReadLine();
            int ans = 0;
            for(int i = 0; i < 3; i++)
            {
                if (str[i] == str2[i]) ans += 1;
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[3];
  for(int i=0;i<3;i++)
  {
    a[i]=n%10;
    n/=10;
  }
  if(a[0]==a[2])
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)
"""
#memo化再帰
memo = [-1]*(110000)
def rec(n):
    if n==0:
        return 0
    if memo[n] != -1:
        return memo[n]
    res = n
    pow6,pow9 = 1,1
    while pow6 <=n:
        res = min(res,rec(n-pow6)+1)
        pow6 *= 6
    while pow9 <= n:
        res = min(res,rec(n-pow9)+1)
        pow9 *= 9
    memo[n] = res
    return memo[n]
N = int(input())
print(rec(N))
"""
"""
#もらうDP
N = int(input())
dp=[inf]*110000
dp[0] = 0
for n in range(1,N+1):
    pow6,pow9 = 1,1
    while pow6<=n:
        dp[n] = min(dp[n],dp[n-pow6]+1)
        pow6 *= 6
    while pow9 <= n:
        dp[n] = min(dp[n],dp[n-pow9]+1)
        pow9 *= 9
print(dp[N])
"""
#配るDP
N = int(input())
dp=[inf]*(110000)
for i in range(110000):
    dp[i] = N 
dp[0]=0
for n in range(N):
    pow6,pow9 = 1,1
    while n+pow6<=N:
        dp[n+pow6] = min(dp[n+pow6],dp[n]+1)
        pow6 *= 6
    while n+pow9 <=N:
        dp[n+pow9] = min(dp[n+pow9],dp[n]+1)
        pow9 *= 9
print(dp[N])

Measured memory_bytes: 4432
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

I dp[1000];
I dp2[10];
I dp3[100];

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  I n;
  string s;
  cin >> n >> s;
  REP(i,s.size()){
    I b = ctoi(s.at(i));
    if (dp2[b] == 1){
      continue;
    }else{
      dp2[b] = 1;
    }
    for (I j=i+1;j<s.size();j++){
      I c = b * 10 + ctoi(s.at(j));
      if (dp3[c] == 1){
        continue;
      }else{
        dp3[c] = 1;
      }
      for (I k=j+1;k<s.size();k++){
        I a = ctoi(s.at(i)) * 100 + ctoi(s.at(j)) * 10 + ctoi(s.at(k));
        dp[a] = 1;
      }
    }
  }
  I t=0;
  REP(i,1000){
    if (dp[i] == 1){
      t++;
    }
  }
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 384
//14-2 ????\¨
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main(){
    int N,M;
    cin >> N >> M;
    int A[1000];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    int tohyo[1000] = {};
    for(int i=0; i<M; i++){
        int B;
        cin >> B;
        bool flg = true;
        int l = 0;
        while(flg){
            if(A[l]<=B){
                tohyo[l]++;
                flg = false;
            }
            else{
                l++;
            }
        }
    }
    int max_num = 0;
    for(int i=0; i<N; i++){
        if(tohyo[max_num] < tohyo[i]){
            max_num = i;
        }
    }
    cout << max_num+1 << endl;
    return 0;
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		sum += a-1;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
<?php
// Your code here!
$count = fgets(STDIN);//7
$num = 10000;
$sum = 0;

for($i=0; $i<=(int)($count)-(int)(1);$i++){
    $total[] = trim(fgets(STDIN)); 
}
// var_dump($total);
rsort($total);
// var_dump($total);

foreach($total as $value){
    // var_dump($value);
    if($value < $num){
        $sum++;
        $num = $value;
    }else{
        continue;
    }
}

echo $sum;

Measured memory_bytes: 3828
import sys
def main():
    s=list(sys.stdin.readline().strip())
    t=0
    while len(s)>2:
        ps,cs,i,f=s[0],s[1],1,False
        for ns in s[2:]:
            if ps!=ns:
                cs,f,t=ns,True,t^1
                s.pop(i)
            else:ps,cs,i=cs,ns,i+1
        if f is False:break
    print('First') if t==1 else print('Second')
if __name__=='__main__':main()

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

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  int t = n * a;
  cout << min(t,b) << endl;
  
  return 0;
}


Measured memory_bytes: 256