akhauriyash/Code-Regression huggingface dataset:
S = input()
#  +のかず 0 - len(S) - 1

r = 0

s = len(S) - 1

for i in range(2 ** s):
    bit = []
    for j in range(s):
        if (i >> j) & 1:
            bit.append(j+1)

    for o in range(len(bit)):
        if o == 0:
            r += int(S[0: bit[o]])
        else:
            r += int(S[bit[o - 1] : bit[o]])
            
    if len(bit) == 0:
        r += int(S)
    else:
        r += int(S[bit[-1] :])
        
print(r)

Measured memory_bytes: 9200
n, k = gets.split.map(&:to_i)

if k == 0
    puts n ** 2
else
    ans = 0
    (k + 1).upto(n) do |b|
        x, y = n.divmod(b)
        ans += x * (b - k)
        ans += (y >= k ? y - k + 1 : 0)
    end
    puts ans
end


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

int main(){
  long long A,B,C,X,Y,ansA,ansB,ansC;
  cin >> A >> B >> C >> X >> Y;
  if(X>Y){
    ansA=2*C*X;
    ansB=2*C*Y+A*(X-Y);
    ansC=A*X+B*Y;
  }
  else{
    ansA=2*C*Y;
    ansB=2*C*X+B*(Y-X);
    ansC=A*X+B*Y;
  }
  cout << min(ansA,min(ansB,ansC)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	long long N;
	cin >> N;

	vector<long long> capa_list(5, 0);

	long long min_capa = 1e15 + 1;
	for (int i = 0; i < 5; i++)
	{
		cin >> capa_list[i];
		min_capa = min(min_capa, capa_list[i]);
	}

	N -= min_capa;
	long long result = 5;
	if (N > 0)
	{
		result += (N / min_capa);
		result += (N % min_capa) ? 1 : 0;
	}

	cout << result;
	
	return 0;
}


Measured memory_bytes: 3616
# coding: utf-8
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
heapq.heapify(A)
minus = 0
l = []
for i in range(M):
    b, c = map(int, input().split())
    l.append([b, c])
l.sort(key=lambda x: x[1], reverse=True)
A.sort(reverse=False)
idx = 0
i = 0
ans = 0
while i < N and idx < M:
    if l[idx][0] == 0:
        idx += 1
    if idx >= M:
        ans += A[i]
        i += 1
        continue
    if A[i] < l[idx][1]:
        ans += l[idx][1]
        l[idx][0] -= 1
        i += 1
    else:
        ans += A[i]
        i += 1
    # print("ans =", ans)
for j in range(i, N):
    ans += A[j]
print(ans)

Measured memory_bytes: 25656
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int h, w;
const int MAX_H = 500;
char a[MAX_H][MAX_H];

int main(){
  cin >> h >> w;
  REP(i, h) REP(j, w) cin >> a[i][j];
  char red[h][w], blue[h][w];
  REP(i, h) REP(j, w) {
    red[i][j] = a[i][j];
    blue[i][j] = a[i][j];
  }

  for(int i = 0; i < h; i += 2) {
    for(int j = 1; j < w; j++) {
      red[i][j] = '#';
    }
  }
  REP(i, h) red[i][w-1] = '#';

  for(int i = 1; i < h; i += 2) {
    for(int j = 0; j < w - 1; j++) {
      blue[i][j] = '#';
    }
  }
  REP(i, h) blue[i][0] = '#';

  REP(i, h) {
    REP(j, w) cout << red[i][j];
    cout << endl;
  }

  cout << endl;

  REP(i, h) {
    REP(j, w) cout << blue[i][j];
    cout << endl;
  }

  return 0;
}


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

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using ll=long long;
using pii=pair<int, int>;
//#define int ll
int MOD = 1000000007;

int mc[10004];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int N, P; cin >> N >> P;
    string S; cin >> S;
    if(P == 2 || P == 5) {
        ll ans = 0;
        rep(i, N) if((S[i]-'0')%P == 0) ans += (i+1);
        cout << ans << endl;
        return 0;
    } else {
        int ps=0,c=1;
        ll ans=0;
        mc[0]++;
        reverse(all(S));
        rep(i,N) {
            ps=(ps+c*(S[i]-'0'))%P,c=c*10%P;
            ans+=mc[ps];
            mc[ps]++;
        }
        cout << ans << endl;
    }
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    ll a,b;cin>>a>>b;
    vl c(41),d(41);
    c[0]=1;d[0]=0;
    for(int i=1;i<41;++i){
        c[i]=2*c[i-1];
        d[i]=c[i]-1;
    }
    if(a==b){
        cout<<a<<endl;
    }
    else{
        a--;
        int k=0,cnt=0;
        ll ans=0;
        while(b-d[k]>0){
            ll x=(b-d[k])/c[k+1]*c[k];
            ll y=(a-d[k])/c[k+1]*c[k];
            if((b-d[k])%c[k+1]>=c[k]){
                x+=c[k];
            }
            else{
                x+=(b-d[k])%c[k+1];
            }
            if((a-d[k])%c[k+1]>=c[k]){
                y+=c[k];
            }
            else{
                y+=(a-d[k])%c[k+1];
            }
            if(a-d[k]<=0)y=0;
            if((x-y)%2==1)ans+=c[k];
            k++;
            cnt++;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
	int a,b,c,k;
	cin >> a >> b >> c;
	cin >> k;
	while(k--){
		if(b<=a){
			b *= 2;
		}
		else{
			c *= 2;
		}
	}
	if(a<b&&b<c)
		printf("Yes");
	else
		printf("No");
}


Measured memory_bytes: 3636
n, m = map(int, input().split())
X = list(sorted([list(map(int, input().split())) for _ in range(m)], key=lambda x: x[1]))

elmd = -1
ans = 0
for a, b in X:
    if a <= elmd < b:
        pass
    else:
        elmd = b - 1
        ans += 1

print(ans)

Measured memory_bytes: 29848
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int a=0;
	for(int i=0;i<s.size();i++){
		if(i!=0&&i!=s.size()-1){
			a++;
		}
	}
	cout<<s[0];
	cout<<a;
	cout<<s[s.size()-1];
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
d = defaultdict(int)
n = int(input())

for i in range(1,n+1):
    a = str(i)[0]
    b = str(i)[-1]
    d[(a,b)] += 1

ans = 0
for i, j in list(d):
    c = d[(i,j)]
    f = d[(j,i)]
    ans += int(d[(i,j)]) * int(d[(j,i)])
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    vector<int> a(3);
    scan(a);
    int sum = accumulate(all(a), 0);
    if (22 <= sum) {
        print("bust");
    } else {
        print("win");
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	int N,K;
	scanf("%d %d",&N,&K);

	int table[K][N/2];

	for(int row = 0; row < K; row++){
		for(int col = 0; col < N/2; col++){
			scanf("%d",&table[row][col]);
			table[row][col]--;
		}
	}

	int ans[N];
	for(int i = 0; i < N/2; i++)ans[i] = 1;
	for(int i = N/2; i < N; i++)ans[i] = 0;

	bool FLG;
	int sum;

	while(true){
		FLG = true;
		for(int i = 0; i < K; i++){
			sum = 0;
			for(int a = 0; a < N/2; a++){
				sum += ans[table[i][a]];
			}
			if(sum < N/8 || sum > 3*N/8){
				FLG = false;
				break;
			}
		}

		if(FLG)break;

		random_shuffle(ans,ans+N);

	}

	for(int i = 0; i < N; i++)printf("%d",ans[i]);
	printf("\n");

	return 0;
}

Measured memory_bytes: 4212
package main

// Solution for https://atcoder.jp/contests/aising2020/tasks/aising2020_b

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var n int
	con.Scan(&n)
	c := 0
	for i := 1; i <= n; i++ {
		var a int
		con.Scan(&a)
		if i%2 == 1 && a%2 == 1 {
			c++
		}
	}
	con.Println(c)
	return nil
}


Measured memory_bytes: 1844
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
#include<iomanip>
#include<cctype>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

//mod計算用のクラス
class ModInt{
public:
    long long int x;
    long long int mod;
	ModInt(){}
    ModInt(long long int _x, long long int _mod = 1000000007){
        this->x = _x % _mod;
        this->mod = _mod;
    }
	ModInt operator+(ModInt other){
		return ModInt(this->x + (other.x % this->mod),this->mod);
	}
	ModInt operator-(ModInt other){
		long long int res = this->x - (other.x % this->mod);
		if (res < 0) return ModInt(res + this->mod, this->mod);
		return ModInt(res);
	}
	ModInt operator*(ModInt other){
		return ModInt(this->x * (other.x % this->mod),this->mod);
	}
	ModInt operator/(ModInt other){
		return ModInt(*this * other.inv());
	}
	ModInt pow(long long int n){
		ModInt res(1, this->mod), a(this->x, this->mod);
		while (n){
			if (n & 1){
				res = res * a;
			}
			n >>= 1;
			a = a * a;
		}
		return res;
	}
	ModInt inv(){
		return ModInt(this->pow(this->mod - 2));
	}
	void disp(){
		cout << this->x << endl;
	}
};
ostream& operator<<(ostream& stream, const ModInt m){
	stream << to_string(m.x);
	return stream;
}
//mod nCrを返す関数.ModIntが必要.
ModInt modcomb(long long int n, long long int r, long long int _mod = 1000000007){
	ModInt x(1, _mod), y(1, _mod);
	for (long long int i = 0; i < r; i++){
		x = x * ModInt(n - i);
		y = y * ModInt(i + 1);
	}
	return x / y;
}
int main(){
	int n, m;
	cin >> n >> m;
	cout << modcomb(n, 2) + modcomb(m, 2) << endl;


	return 0;
}

Measured memory_bytes: 256
using System;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var a = int.Parse(_[0]);
            var b = int.Parse(_[1]);
            var k = int.Parse(_[2]);

            for(var i = a; i <= b; i++){
                if(i < a + k || i > b - k){
                    Console.WriteLine(i);
                }
            }
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define pi 3.141592653897932384626
//freopen("std.in","r",stdin);freopen("std.out","w",stdout);
using namespace std;
int main()
{
    long a,b,c;
    cin>>a>>b>>c;
    long m=max(max(a,b),c);
    long sum,x,y,z;
    x=(m-a)%2;
    y=(m-b)%2;
    z=(m-c)%2;
    if(x+y+z==2)cout<<((m-a)/2+(m-b)/2+(m-c)/2)+1<<endl;
    if(x+y+z==1)cout<<((m-a)/2+(m-b)/2+(m-c)/2)+2<<endl;
    if(x+y+z==0)cout<<((m-a)/2+(m-b)/2+(m-c)/2)<<endl;
    return 0;
}


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

#define INF (INT64_MAX/2)
#define MAX 100
#define MOD (1000000000+7)

int main() {
	string S;

	cin >> S;

	int ans = 0;
	int flag = 0;
	int l = 0;
	for( int i = 0; i < S.size(); i++ ) {
		if( S[i] == 'A' || S[i] == 'G' || S[i] == 'C' || S[i] == 'T' ) {
			l++;
		}
		else {
			l = 0;
		}
		ans = max( ans, l );
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
 execution in cmd of windows:
 
 
  g++ p1.cpp -o p1
  
  
  p1
 
 */
typedef double dd;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl <<"\n"
#define con continue
#define br break
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
ll mx=INT_MAX;
ll mi=INT_MIN;
#define mem0(a)         memset(a,0,sizeof(a))
#define mem1(a)         memset(a,-1,sizeof(a))
#define all(v) v.begin(), v.end()
#define fsort(v) sort(all(v))  
#define rsort(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(all(v))
#define maxc(v) max_element(all(v))
#define minc(v) min_element(all(v))
#define sumv(v,x) accumulate(v.begin(),v.end(),x);
const ll mod = 1000000007;
const ll inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
#define io { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define cer cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
#define cs ll t;cin>>t;while(t--)



int main()
{
	#ifndef ONLINE_JUDGE
		ifstream cin("in.in");
		ofstream cout("out.out");
	#endif
	
        io;
        //////////////////////////////////
        
        	ll i,j,k,p=0,q=0,l,r,d,s=0,n;
        	cin>>n;
        	for(i=1;i<=n;i++)
        	{
        		ll x;
        		cin>>x;
        		if(i%2==1 && x%2==1) s++;
        	}
        cout<<s;
    	//////////////////////////////////
        cer;
}


Measured memory_bytes: 3768
fun main(args: Array<String>) {
  val (Ns, Ks) = readStrings()
  val N = Ns.toInt()
  var K = Ks.toLong()
  val AN = readInts()

  val map = hashMapOf<Int, Int>()
  val array = Array(N + 1) { 0 } // i 回目に到着する町がどこか
  array[0] = 1 // 始めは町１
  map[1] = 0

  var loopBegin = -1
  var loopEnd = -1

  for (i in 1..N) {
    val prev = array[i - 1]
    val current = AN[prev - 1]
    array[i] = current
    if (map.contains(array[i])) { // ループしたら終了
      loopBegin = current
      loopEnd = prev
      break
    }
    map[current] = i
  }

//  println(array.joinToString())
//  println(map)
//  println("$loopBegin $loopEnd")

  if (K <= map.size) {
    println(array[K.toInt()])
  } else {
    val begin = map[loopBegin]!!
    val end = map[loopEnd]!!
    val loopSize = end - begin + 1
    K -= begin
    println(array[begin + (K % loopSize).toInt()])
  }
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


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

int main () {
	int n, sum = 0;
	cin >> n;

  	int num = n;
	while (num != 0) {
		sum += num % 10;
		num /= 10;
	}

	if (n % sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

const int mod=1000000007;
map<vector<char>,int> ma;
vector<char> V,v[420010];
int cnt,t[420010][36],n,m,f[71][420010],g[71][36][2],sum[71][36],ans,h[420010];
char s[110];

void dfs(int nw)
{
	ma[V]=(++cnt),v[cnt]=V;
	for (int i=(V.empty()?0:V[V.size()-1]); (i==0)+i+nw<=35; i++)
		V.push_back(i),dfs(i+nw+(i==0)),V.pop_back();
}

int main()
{
	V.clear(),cnt=0,dfs(0);
	for (int i=1,nw; i<=cnt; i++)
	{
		nw=0;
		for (int j=0,sz=v[i].size(); j<sz; j++) nw+=(v[i][j]==0)+v[i][j];
		for (int j=0; (j==0)+j+nw<=35; j++) 
		{
			V=v[i],V.push_back(j),sort(V.begin(),V.end());
			t[i][j]=ma[V];
		}
	}
	scanf("%d%d%s",&n,&m,s);
	f[0][1]=1,g[0][0][0]=1;
	for (int i=1; i<=n; i++)
	{
		g[i][0][0]=g[i-1][0][0],g[i][0][1]=0;
		for (int j=1; j<=(i+1>>1); j++)
			g[i][j][0]=(g[i-1][j][0]+g[i-1][j][1])%mod,
			g[i][j][1]=(g[i-1][j][1]+g[i-1][j-1][0])%mod;
	}
	for (int j=0; j<=(n+1>>1); j++)
	{
		sum[0][j]=0;
		for (int i=1; i<=n; i++) sum[i][j]=(sum[i-1][j]+1ll*g[i][j][0]+g[i][j][1])%mod;
	}
	for (int i=0; i<n; i++)
		for (int k=1; k<=cnt; k++) if (f[i][k])
			for (int nxt=(i==0?1:i+2),j=nxt; j<=n; j++)
				for (int l=0; l<=(j-nxt+2>>1); l++)
					f[j][t[k][l]]=(f[j][t[k][l]]+1ll*f[i][k]*sum[j-nxt+1][l])%mod;
	for (int j=1; j<=cnt; j++)
		for (int i=0; i<=n; i++) h[j]=(h[j]+f[i][j]>=mod?h[j]+f[i][j]-mod:h[j]+f[i][j]);
	ans=0;
	for (int nw,p,i=1,nww,pp; i<=cnt; i++) if (h[i])
	{
		nw=0,p=v[i].size(),nww=0,pp=v[i].size();
		for (int j=0; (p||nw)&&j<m; j++)
			if (s[j]=='r') 
			{
				if (p) nw+=v[i][--p];
				else if (nww&&nw) nw--,nww--;
			}
			else 
			{
				if (nw) 
				{
					nw--;
					if (p<pp) nww+=max(v[i][--pp]-1,0); else nww--;
				}
			}
		if (!p&&!nw) ans=(ans+h[i])%mod;
	}
	return printf("%d\n",ans),0;
}

Measured memory_bytes: 246144
n,m=map(int,input().split())
hoge=[]
for i in range(n):
  huga=list(map(int,input().split()))
  huga=huga[1:]
  for j in range(len(huga)):
    hoge.append(huga[j])
ans=0
for i in range(m):
  if(hoge.count(i+1)==n):
    ans+=1

print(ans)

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

using namespace std;

int main() {
    int n, m; cin >> n >> m;
    vector <string> v (n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        cout << v[i] << "\n" << v[i] << "\n";
    }
}

Measured memory_bytes: 3640
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)

	ss := strings.Split(s, "")

	moji1 := ""
	moji2 := ""
	cnt := 0
	cnt2 := 0
	cnt3 := 0
	for _, s := range ss {
		if moji1 != s && moji2 != s {
			cnt++

			if moji1 == "" {
				moji1 = s
				continue
			}

			if moji2 == "" {
				moji2 = s
				continue
			}
		}

		if cnt > 2 {
			fmt.Print("No")
			return
		}

		if moji1 == s {
			cnt2++
			if cnt2 > 2 {
				fmt.Print("No")
				return
			}
		}

		if moji2 == s {
			cnt3++
			if cnt3 > 2 {
				fmt.Print("No")
				return
			}

		}

	}
	fmt.Print("Yes")
}


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


#define int long long

bool ok[11][11][11] = {};

int a[100010];
int l[100010] = {};
int r[100010] = {};

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

    for(int i = 0;i < n;i++){
        a[i] = s[i] - '0';
    }

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

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

    for(int x = 1;x < n-1;x++){
        for(int i = 0;i < 10;i++){
            for(int j = 0;j < 10;j++){
                if(((l[x-1] & (1 << i)) != 0) && ((r[x+1] & (1 << j)) != 0)){
                    ok[i][a[x]][j] = true;
                }
            }
        }
    }

    int ans = 0;

    for(int i = 0;i < 10;i++){
        for(int j = 0;j < 10;j++){
            for(int k = 0;k < 10;k++){
                if(ok[i][j][k]) ans++;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <cmath>
#include <map>
#include <climits>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
int main()
{
    int N, M; cin >> N >> M;
    cout << (1800 * M + 100 * N) * (1 << M) << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input(""))
data = [0]*n
t = [0]*n
x = [0]*n
y = [0]*n
flag = 0

for i in range(n):
    data[i] = input("")
    t[i] = int(data[i].split(" ")[0])
    x[i] = int(data[i].split(" ")[1])
    y[i] = int(data[i].split(" ")[2])

for i in range(n):
    if i == 0:
        if x[i]+y[i] > t[i] or (x[i]+y[i]-t[i])%2 != 0:
            print("No")
            flag = 1
            break
    else:
        if abs(x[i]-x[i-1])+abs(y[i]-y[i-1]) > t[i] or (x[i]+y[i]-t[i])%2 != 0:
            print("No")
            flag = 1
            break
if flag == 0:print("Yes")

Measured memory_bytes: 18804
import bisect


def main():
    n = int(input())
    a = list(map(int, input().split()))

    a.sort()
    a2 = a[::-1]

    sa = [0 for i in range(n+1)]
    for i in range(1, n+1):
        sa[i] = sa[i-1] + a[i-1]

    ans, max_s = 0, a2[0]
    for i in range(n):
        t = sa[bisect.bisect_right(a, 2*a2[i])]
        if max_s <= 2 * t:
            ans += 1
            max_s = a2[i]
        else:
            break

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14480
class String
  def mirror?
    (1 .. size / 2).all?{|i| self[i - 1] == self[size - i]}
  end
end
N = gets.to_i
S = (1 .. N).map do
  s,c = gets.split
  [s.chomp, c.to_i]
end

used_suffix = {}
used_prefix = {}

q = []
S.each do |s,c|
  q << [s, "", c]
  q << ["", s, c]
end
until q.empty?
  status = q.min_by(&:last)
  q.delete(status)
  l,r,t = *status
  lr = l + r
  if lr.size > 0 && lr.mirror?
    puts t
    exit
  end
  
  if l.size > r.size
    suffix = l[r.size, l.size - r.size].reverse
    next if used_suffix[suffix]
    used_suffix[suffix] = true
    S.select{|s,c| s.size >= suffix.size ? s.end_with?(suffix) : suffix.end_with?(s) }
      .each{|s,c| q.push([l, s + r, t + c]) }
  elsif l.size < r.size
    prefix = r[0, r.size - l.size].reverse
    next if used_prefix[prefix]
    used_prefix[prefix] = true
    S.select{|s,c| s.size >= prefix.size ? s.start_with?(prefix) : prefix.start_with?(s) }
      .each{|s,c| q.push([l + s, r, t + c]) }
  else
    raise "unreachable"
  end
end
puts -1


Measured memory_bytes: 14364
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD = pow(10,9)+7;
int N; //文字列の長さ
vector<map<string , ll>> memo(N+1);

//4文字が条件を満たしているかどうか
bool ok(string last4){
    for(int i=0; i<4; i++){
        string t = last4;
        if(i>0){
            char ti_1 = t[i-1];
            char ti = t[i];
            t[i] = ti_1;
            t[i-1]= ti;
        }

        if(t.find("AGC") != std::string::npos) return false;
    }

    return true;
}

ll dfs(int cur , string last3){

    if(memo[cur].find(last3) != memo[cur].end()) return memo[cur][last3];
    if(cur == N) return 1;

    ll ret = 0;
    string t = "ACGT";
    for(auto c : t){
        if(ok(last3+c)){
            string str = "";
            str.append(1,last3[1]);
            str.append(1,last3[2]);
            str.append(1,c);
            ret = (ret + dfs(cur+1 ,str)) % MOD;
        }
    }
    memo[cur][last3] = ret;
    return ret;
}

int main(){
    cin >> N;
    memo.assign(N+1,map<string,ll>());
    ll ans = dfs(0,"TTT");
    cout << ans << endl;
}

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

using namespace std;

const int MN = 50+10;
typedef long long ll;
typedef pair<int,int> ii;

long long N; int A, B;
long long V[MN];
long long C[MN][MN];

int main()
{
    #ifdef ACMTUYO
    freopen("a.in","r",stdin);
    #else
    cin.tie(0); ios_base::sync_with_stdio(0);
    #endif

    for (int i=0; i < MN; i++) C[i][0] = C[i][i] = 1;
    for (int i=2; i < MN; i++) for (int j=1; j < i; j++) C[i][j] = C[i-1][j-1] + C[i-1][j];

    cin >> N >> A >> B;
    for (int i=1; i <= N; i++){
        cin >> V[i];
    }

    sort(V+1,V+N+1);
    reverse(V+1,V+N+1);

    /*Big PARCHE, all are the same*/
    if (V[1] == V[N]){
        ll cant=0;
        for (int i=A; i <= B; i++){
            cant += C[N][i];
        }
        cout << fixed << setprecision(7);
        cout << V[1] << endl;
        cout << cant << endl;
        return 0;
    }

    ll sum=0;
    for (int i=1; i <= A; i++){
        sum += V[i];
    }

    cout << fixed << setprecision(7);
    cout << (double)sum/A << endl;

    int cantPivotValue=0, pivotValuesUsed=0;
    for (int i=1; i <= N; i++){
        if (V[i] == V[A])
            cantPivotValue++;
        if (V[i] == V[A] && i <= A)
            pivotValuesUsed++;
    }

    if (V[A] != V[1])
        cout << C[cantPivotValue][pivotValuesUsed] << "\n";
    else {
        ll ans = 0;
        for (int i=A; i <= min(cantPivotValue,B); i++){
            ans += C[cantPivotValue][i];
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;

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

    if(n%500 <= a) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

typedef long long cat;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int gcd(int a, int b) {
	if(a > b) swap(a, b);
	return (a == 0) ? b : gcd(b%a, a);
}

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	if(N == 3) {
		cout << "2 3 25\n";
		return 0;
	}
	vector<int> ans;
	int sum = 0;
	for(int i = 30000; i > 0; i--) {
		if(i%2 != 0 && i%3 != 0) continue;
		if((int)ans.size()+1 == N) {
			if((sum+i)%2 != 0) continue;
			if((sum+i)%3 != 0) continue;
		}
		ans.push_back(i);
		sum += i;
		if((int)ans.size() == N) break;
	}
	int g = 0;
	for(int i = 0; i < (int)ans.size(); i++) g = gcd(g, ans[i]);
	if((int)ans.size() == N && g == 1) {
		for(int i = 0; i < N; i++) cout << ans[i] << ((i == N-1)?"\n":" ");
		return 0;
	}
	ans.clear();
	sum = 0;
	for(int i = 2; i <= 30000; i++) {
		if(i%2 != 0 && i%3 != 0) continue;
		if((int)ans.size()+1 == N) {
			if((sum+i)%2 != 0) continue;
			if((sum+i)%3 != 0) continue;
		}
		ans.push_back(i);
		sum += i;
		if((int)ans.size() == N) break;
	}
	g = 0;
	for(int i = 0; i < (int)ans.size(); i++) g = gcd(g, ans[i]);
	if((int)ans.size() == N && g == 1) {
		for(int i = 0; i < N; i++) cout << ans[i] << ((i == N-1)?"\n":" ");
		return 0;
	}
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 640
n = int(input())
a = [int(i) for i in input().split()]
if sum(a) % (n * (n + 1) // 2) != 0:
    print("NO")
    exit()

k = sum(a) // (n * (n + 1) // 2)

l = 0
for i in range(n):
    j = (i + 1) % n
    m = a[i]-a[j]
    if (m + k) % n != 0 or (m + k) // n < 0:
        print("NO")
        exit()
    l += (m + k) // n
if k == l:
    print("YES")
else:
    print("NO")


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<ll,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int k, n;
	cin >>k >>n;
	VI a(2*n);
	rep(i, n){ cin >> a[i]; a[i+n]=a[i]+k;}
	int mx = 0;
	rep(i, 2*n-1){
		mx = max(mx, a[i+1] - a[i]);
	}
	cout << k - mx <<"\n";
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main() {
	int input[10], tmp, i = 0;
	cin >> input[0] >> input[1] >> input[2] >> input[3];

	int w = input[0];
	int h = input[1];
	int array[w][h];
	int count = 0;

	for (int x = 0; x < w; x++) {
		for (int y = 0; y < h; y++) {
			array[x][y] = 0;
			if (x >= input[2] && y >= input[3]) {
				array[x][y] = 1;
				count++;
			}
		}
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795L
#ifndef DEBUG
#define debug(args...)
#else
#include "debug.h"
#endif
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
#ifdef DEBUG
  freopen("inp.txt", "r", stdin);
#endif
  int k; string s;
  cin>>k>>s;
  if (s.size()<=k) {
    cout<<s<<'\n';
  } else {
    cout<<s.substr(0, k)<<"...\n";
  }
  return 0;
}


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

#define      pb    push_back
#define      ff    first
#define      ss    second
#define      ll    long long int
#define      endl  "\n"
#define      FASTIO        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


#define      TEST    int t ; cin >> t ; while( t -- )

const ll big = 10e7 + 11 ;

int  main (  ) {

    FASTIO ;

    int n , m ;
    cin >> n >> m ;

    int ans = 0 ;

    ans = n * ( n - 1 ) / 2 ;

    ans += m * (m - 1 ) / 2 ;

    cout <<   ans  ;


    return  0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep( i, n ) for (long long i = 0; i < ( long long )(n); i++)

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

int main(){
    ll n;
    cin>>n;
    ll sum= 0;

    rep(i,n+1){
        if(i%3==0||i%5==0) continue;
        else sum+=i;
    }
    cout<<sum;
} 


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD=1000000007;

int main() {
    string S; cin>>S;
    for(int bit=0;bit<(1<<3);bit++){
        int ans=S[0]-'0';
        for(int i=0;i<3;i++){
            if(bit & 1<<(2-i)){
                ans+=S[i+1]-'0';
            }
            else{
                ans-=S[i+1]-'0';
            }
        }
        if(ans==7){
            cout<<S[0];
            for(int i=0;i<3;i++){
                if(bit & 1<<(2-i)){
                    cout<<"+"<<S[i+1];
                }
                else{
                    cout<<"-"<<S[i+1];
                }
            }
            cout<<"=7";
            return 0;
        }
    }
    return 0;
}

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

int main() {
  int A, B, C, D;

  cin >> A >> B >> C >> D;

  
  if (A + B > C + D ) {
    cout << "Left" << endl;
  }
  else if(A + B < C + D ){
    cout << "Right" << endl;
  }
  else{
    cout << "Balanced" << endl;
  }
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

int a[111111],n,minV;
unordered_map <int,bool> cache;
void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

bool solve(int s)
{
	if(s < 0)
	{
		return false;
	}
	if(s == 0)
	{
		return false;
	}
	if(s < minV)
	{
		return false;
	}
	if(cache.find(s) != cache.end())
	{
		return cache[s];
	}
	
		int flag = 0;
		for(int i=0;i<n;i++)
		{
			if(s-a[i] < 0)
			{
				continue;
			}
			bool p = solve(s-a[i]);
			if(p == false)
			{
				flag = 1;
				break;
			}
		}
		if(flag == 1)
		{
			return cache[s] = true;
		}
		else
		{
			return cache[s] = false;
		}
}

int32_t main()
{
 // c_p_c();
  int x;
  cin >> n >> x;
  minV = INT_MAX;
  for(int i=0;i<n;i++)
  {
  	cin >> a[i];
  	minV = min(minV,a[i]);
  }
  // cout<<minV<<endl;
  bool res = solve(x);
  if(res == true)
  {
  	cout<<"First"<<endl;
  }
  else
  {
  	cout<<"Second"<<endl;
  }
  return 0;
}



Measured memory_bytes: 7588
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fin(x) freopen(x,"r",stdin)
#define fout(x) freopen(x,"w",stdout)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll inf=0xc0c0c0c0c0c0c0c0;
const double pi=acos(-1);
const int MAXM=1e5+7;
int N,M;
int fa[MAXM],used[MAXM],L[MAXM];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
	scanf("%d%d",&N,&M);
	for(int i=0;i<=M;i++)
		fa[i]=i;
	for(int i=0;i<N;i++)
	{
		int K;
		scanf("%d",&K);
		for(int j=0;j<K;j++)
		{
			int x;
			scanf("%d",&x);
			L[j]=find(x);
			used[x]=1;
		}
		for(int j=1;j<K;j++)
		{
			fa[L[j]]=L[0];
		}
	}
	int last=-1;
	int err=0;
	for(int i=0;i<=M;i++)
		if(used[i])
		{
			if(last==-1)last=find(i);
			else if(last!=find(i)){err=1;break;} 
		}
	if(err)puts("NO");
	else puts("YES");
	return 0;
}

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

void GetList(int Num, vector<int>& List);
bool Check(int Question, vector<int>& List, int Start, int Sum);

void GetList(int Num, vector<int>& List)
{
    List.clear();
    int Temp;
    
    for(int i = 0; i < Num; i++){
        std::cin >> Temp;
        List.push_back(Temp);
    }
}

bool Check(int Question, vector<int>& List, int Start, int Sum)
{
     if(Sum == Question){
            return true;
    } else if(Sum > Question){
            return false;
    }
    
    for(int i = Start; i < List.size(); i++){
        if(Check(Question, List, i+1, Sum+List[i]) == true) return true;
    }
    return false;
}

int main(void){
    int Num, QuestionNum;
    vector<int> List;
    vector<int> QuestionList;
    
    std::cin >> Num;
    GetList(Num, List);
    std::cin >> QuestionNum;
    GetList(QuestionNum, QuestionList);
    
    for(int i = 0; i < QuestionList.size(); i++){
        if(Check(QuestionList[i], List, 0, 0))   std::cout << "yes" << std::endl;
        else        std::cout << "no" << std::endl;
    }
}

Measured memory_bytes: 1216
N = int(input())

if N <= 1000:
  print(1000 - N)
elif N <= 2000:
  print(2000 - N)
elif N <= 3000:
  print(3000 - N)
elif N <= 4000:
  print(4000 - N)
elif N <= 5000:
  print(5000 - N)
elif N <= 6000:
  print(6000 - N)
elif N <= 7000:
  print(7000 - N)
elif N <= 8000:
  print(8000 - N)
elif N <= 9000:
  print(9000 - N)
else:
  print(10000 - N)

Measured memory_bytes: 9184
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
int p(int A,int B){
  if(!B)return 1;
  if(B%2)return p(A,B-1)*A%mod;
  int C=p(A,B/2);
  return C*C%mod;
}
signed main(){
  int N,K;
  cin>>N>>K;
  vector<int> A(K+1);
  int ans=0;
  for(int i=K;i>0;i--){
    A[i]=p(K/i,N);
    for(int j=i*2;j<=K;j+=i)A[i]=(A[i]-A[j]+mod)%mod;
    ans=(ans+A[i]*i%mod)%mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4012
#include<bits/stdc++.h>
using namespace std;
long long x,k,d; 
int main(){
	cin>>x>>k>>d;
	long long t=x/d;
	x=abs(x);
	if(x/d>=k){
		cout<<abs(x-k*d);
		return 0;
	}else{
		if((k-x/d)%2==0){
			cout<<abs(x-(x/d)*d);
			return 0;
		}else{
			cout<<abs(x-(x/d+1)*d);
		}
	}
	return 0;
} 

Measured memory_bytes: 3596
// failed to generate code

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

int dp[100010];
int a[101];
int N, K;

int dfs(int k){
    if( dp[k] != -1 )
        return dp[k];
    int ans = 0;
    for(int i = 0 ; i < N ; i++){
        if( k >= a[i] ) if( !dfs(k-a[i]) ){
            ans = 1;
            break;
        }
    }
    return dp[k] = ans;
}

int main(){
    memset(dp, -1, sizeof(dp));
    cin >> N >> K;
    for(int i = 0 ; i < N ; i++){
        cin >> a[i];
    }
    cout << (dfs(K)?"First":"Second") << endl;

}


Measured memory_bytes: 3712
from collections import Counter
N, *a = map(int, open(0).read().split())

c = Counter(a).most_common()
c = sorted([[i, j // 2] for i, j in c], reverse=True)
ans = 1
cnt = 0
for i in range(len(c)):
    a, v = c[i]
    while v > 0:
        ans *= a
        cnt += 1
        v -= 1
        if cnt == 2:
            break
    if cnt == 2:
      break
            
print(ans if cnt == 2 else 0)


Measured memory_bytes: 25816
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const int INF=1e9;
    
int main(){
  int n;
  cin>>n;
  vector<int> x(n);
  rep(i,n) cin>>x[i];
  
  int ans=INF;
  rep(p,100){
    int now=0;
    
    rep(i,n){
      now+=(x[i]-p)*(x[i]-p);
    }
    ans=min(ans,now);
  }
  
  cout<<ans<<endl;
  return 0;

  

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr int MOD = 1000000007;
constexpr int INF = 1e18;

using namespace std;

bool bellmanford(int N, vector<vector<pair<int, int>>>& graph, vector<int>& d){
  for(int i = 0; i < N; i++){
    for(int v = 0; v < N; v++){
      for(int k = 0; k < (int)graph[v].size(); k++){
        pair<int, int> e = graph[v][k];
        if(d[v] != INF && d[e.first] > d[v] + e.second){
          d[e.first] = d[v] + e.second;
        }
      }
    }
  }
  return false;
}

signed main() {
  int N, M;
  cin >> N >> M;

  vector<vector<pair<int, int>>> graph(N);
  vector<int> score(N, INF);
  score[0] = 0;

  int a, b, c;
  REP(i, M){
    cin >> a >> b >> c;
    a--; b--; c *= -1;
    graph[a].push_back(make_pair(b, c));
  }

  bellmanford(N, graph, score);

  vector<bool> negative(N, false);
  REP(_, N) REP(i, N) REP(j, (int)graph[i].size()){
    if(score[i] == INF) continue;
    pair<int, int> p = graph[i][j];
    if(score[p.first] > score[i]+p.second){
      score[p.first] = score[i]+p.second;
      negative[p.first] = true;
    }
    if(negative[i] == true) negative[p.first] = true;
  }

  if(negative[N-1]) cout << "inf" << endl;
  else cout << -score[N-1] << endl;

  return 0;
}

Measured memory_bytes: 384
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int a, b, c;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a>>b>>c;
    if(a+b+c-22<0)
    return cout<<"win"<<"\n",0;
    cout<<"bust"<<"\n";
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
main()
{
	int N;
	int k;
	cin>>N;
	if(N<=999)
	{
	 k=N%10;
}
else
{
	return 0;
}
	if(k==2|k==4|k==5|k==7|k==9)
	{
	cout<<"hon";
	}
	 if(k==0|k==1|k==6|k==8)
	{
		cout<<"pon";
	}
	if(k==3)
	{
		cout<<"bon";
	}
}

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

using i64 = long long;
using P = pair<i64, i64>;
const i64 INF = numeric_limits<i64>::max();

struct edge{
    i64 src, to, cost;
    edge(i64 to, i64 cost) : src(-1), to(to), cost(cost) {}
    edge(i64 src, i64 to, i64 cost) : src(src), to(to), cost(cost) {}
    bool operator <(const edge &u){
        return this->cost < u.cost;
    };
};

using Graph = vector<vector<edge>>;

vector<i64> dijkstra(Graph G, i64 s){
    //
    // Dijkstra 法 O(ElogV)
    // Graph G : 有向グラフ
    // i64 s : 始点の番号
    //
    i64 n = G.size();
    vector<i64> dist(n, INF);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(0, s);
    while(!que.empty()){
        P t = que.top(); que.pop();
        i64 cost = t.first, u = t.second;
        if(cost > dist[u]) continue;
        for(auto e : G[u]){
            i64 v = e.to;
            if(cost + e.cost < dist[v]){
                dist[v] = cost + e.cost;
                que.emplace(dist[v], v);
            }
        }
    }
    return dist;
}

void solve(long long N, long long u, long long v, std::vector<long long> A, std::vector<long long> B){
    Graph G(N);
    --u; --v;
    for(int i = 0; i < N - 1; ++i){
        --A[i]; --B[i];
        G[A[i]].push_back(edge(A[i], B[i], 1));
        G[B[i]].push_back(edge(B[i], A[i], 1));
    }
    vector<i64> da = dijkstra(G, u);
    vector<i64> db = dijkstra(G, v);
    queue<i64> que;
    que.push(u);
    vector<i64> d(N, INF);
    d[u] = 0;
    i64 ans = 0;
    while(!que.empty()){
        i64 t = que.front(); que.pop();
        if(d[t] >= db[t]) continue;
        for(auto e : G[t]){
            i64 x = e.to;
            if(d[x] == INF){
                if(d[t] + 1 < db[x]){
                    d[x] = d[t] + 1;
                    que.push(x);
                }else if(d[t] + 1 == db[x]){
                    ans = max(ans, db[x]);
                }
            }
        }
    }
    for(int i = 0; i < N; ++i){
        if(d[i] != INF) ans = max(ans, db[i] - 1);
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long u;
    scanf("%lld",&u);
    long long v;
    scanf("%lld",&v);
    std::vector<long long> A(N-1);
    std::vector<long long> B(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, u, v, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 20796