akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end());
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 2e5;
ll DP[2][3][3], DP2[2][3][3];
string s;
ll p, d = 1;
bool y[3];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;
  int n = sz(s);
  {
    FOR(i, 0, n){
      y[(s[i]-'a')] = true;
      p += (s[i]-'a');
      if(i && (s[i]==s[i-1])) d = 0;
    }
    p %= 3;
    sort(y, y+3);
    if(!y[1]){
      cout << 1 << endl;
      return 0;
    }
    if(n==3){
      cout << ((p) ? (6+d) : (3)) << endl;
      return 0;
    }
  }
  DP[0][0][0] = 1;
  DP[0][1][1] = 1;
  DP[0][2][2] = 1;
  FOR(t, 1, n){
    Fill(DP2, 0ll);
    FOR(i, 0, 3)FOR(j, 0, 3)FOR(k, 0, 3){
      DP2[j==k][(i+k)%3][k] += DP[0][i][j];
      DP2[1][(i+k)%3][k] += DP[1][i][j];
    }
    swap(DP, DP2);
    FOR(i, 0, 2)FOR(j, 0, 3)FOR(k, 0, 3) DP[i][j][k] %= MOD;
  }
  ll ans = d;
  FOR(i, 0, 3) ans += DP[1][p][i];
  cout << ans % MOD << endl;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e5 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int a[maxn];
int cnt[maxn];

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	int k;
	cin >> k;
	string s;
	cin >> s;
	int n = s.size();
	if(n>k){
		s=s.substr(0,k)+"...";
	}
	cout << s << "\n";
}


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

int main() {
	int n,m; cin >> n>>m;
	vector<pair<int, int>> vpos;
	for(int i=0;i<n;++i){
		int a,b;cin >> a >> b;
		vpos.push_back(make_pair(a,b));
	}
	vector<pair<int, int>> vchk;
	for(int j=0;j<m;++j){
		int c,d;cin >> c >> d;
		vchk.push_back(make_pair(c,d));
	}
	for(int k=0;k<n;++k){
		int min_d =1000000000;
		int min_id = 1;
		for(int l=0;l<m;++l){
			int id = l+1;
			int tmp_d = abs(vpos[k].first - vchk[l].first ) + abs(vpos[k].second - vchk[l].second );
			if(tmp_d< min_d) {
				min_d = tmp_d;
				min_id = id;
			}
		}
		cout << min_id << endl;
	}
	return 0;
}

Measured memory_bytes: 256
a = [0,0,0,0,0,0,0,0,0,0]
 
for num in 0..9 do
 
	a[num] = gets.to_i
 
end

	n = a.size - 1
	for i in 0..n
		for j in 0..n - i - 1
			if a[j] > a[j + 1]
				tmp = a[j]
				a[j] = a[j + 1]
				a[j + 1] = tmp
			end
		end
	 end
	 
puts a[9]
puts a[8]
puts a[7]

Measured memory_bytes: 6096
using System;

namespace Beginer081_A

{
    class Program
    {
        static void Main(string[] args)
        {
            string hoge = Console.ReadLine();
            int cnt = 0;
            if (hoge.Substring(0, 1) == "1") cnt++;
            if (hoge.Substring(1, 1) == "1") cnt++;
            if (hoge.Substring(2, 1) == "1") cnt++;
            Console.WriteLine(cnt);

        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<math.h>

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

int main() {
	int n, k; cin >> n >> k;
	vector<int> h(n);
	rep(i, n)cin >> h[i];

	int ans = 0;
	rep(i, n) {
		if (h[i] >= k)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
int main(){
	int i,n;
	scanf("%d",&n);
	int a[100];
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=n-1;i>=0;i--){
		if(i!=n-1) printf(" ");
		printf("%d",a[i]);
	}
	printf("\n");
	return 0;
}

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

int main(int argc, char const *argv[])
{
	// freopen("in", "r", stdin);
	string s, t;
	cin >> s >> t;
	int cnt = 0;
	for(int i = 0; i < 3; i++) {
		cnt += (s[i] == t[i]);
	} cout << cnt << endl;
	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    string origin = "CODEFESTIVAL2016";
    int ans = 0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] != origin[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i = 0; i < (n); ++i )
#define rep_rev(n,i) for(ll i = n; i >= 0; --i )
using namespace std;
using P = pair<int, int>;
const long long INF = 1LL << 60;

int main(){
  string S; cin >> S;
  if(S[0] == S[1] && S[1] == S[2]) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    int X;
    std::cin >> X;

    int ureshisa = 0;
    ureshisa += (X / 500) * 1000;
    X %= 500;
    ureshisa += (X / 5) * 5;

    std::cout << ureshisa;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>

int n, m;
int c[100];
int N[100];

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

int main()
{
	while( std::cin >> n >> m, n | m ){
		memset( c, 0, sizeof( c ) );
		
		for( int i = 0; i < m; i++ ){
			N[i] = i + 1;
		}
		
		for( int i = 0; i < n; i++ ){
			for( int j = 0; j < m; j++ ){
				int a;
				std::cin >> a;
				if( a ) c[j]++;
			}
		}
		
		for( int i = 0; i < m; i++ ){
			for( int j = 1; i + j < m; j++ ){
				if( c[i] < c[i+j] ){
				 	swap( c[i], c[i+j] );
					swap( N[i], N[i+j] );
				}
			}
		}
		
		for( int i = 0; i < m; i++ ){
			for( int j = 1; i + j < m; j++ ){
				if( c[i] == c[i+j] && N[i] > N[i+j] ){
					swap( N[i], N[i+j] );
				}
			}
		}
		
		for( int i = 0; i < m; i++ ){
			std::cout << N[i] << ( i != m - 1 ? " " : "" );
		}
		std::cout << std::endl;
	}

 	return 0;
}

Measured memory_bytes: 1164
let ss = Array.init 3 @@ fun _ -> read_line ()
let i_s = Array.make 3 0
let rec f c = String.(let j = index "abc" c in if i_s.(j) >= length ss.(j) then Printf.printf "%c\n" "ABC".[j] else (i_s.(j) <- i_s.(j) + 1; f ss.(j).[i_s.(j) - 1]))
let _ = i_s.(0) <- 1; f ss.(0).[0]

Measured memory_bytes: 384
import sys

class alphabet: #Trueなら大文字
    def __init__(self, capitalize):
        self.num = dict() #アルファベットを数字に変換
        self.abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"\
            ,"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
        if capitalize: 
            for i in range(26): self.abc[i] = self.abc[i].upper()
        for i, a in enumerate(self.abc): self.num[a] = i


def solve():
    input = sys.stdin.readline
    N = int(input())
    S = input().strip("\n")
    Ans = ""
    Alphabet = alphabet(True)
    for i in range(len(S)):
        sNum = Alphabet.num[S[i]]
        rotateNum = (sNum + N) % 26
        Ans += Alphabet.abc[rotateNum]
    print(Ans)

    return 0

if __name__ == "__main__":
    solve()

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

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


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  int N;
  cin >> N;
  vector< int > g[10000];
  for(int i = 1; i < N; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
  }
  vector< int > A(N);
  cin >> A;
  sort(begin(A), end(A));


  vector< int > deg(N);
  queue< int > que;
  for(int i = 0; i < N; i++) {
    deg[i] = g[i].size();
    if(deg[i] == 1) {
      que.emplace(i);
      --deg[i];
    }
  }
  vector< int > ans(N, N - 1);
  int ptr = 0;
  int64 ret = 0;
  while(que.size()) {
    auto p = que.front();
    que.pop();
    if(ptr + 1 < N) ret += A[ptr];
    ans[p] = ptr++;
    for(auto &t : g[p]) {
      --deg[t];
      if(deg[t] == 1) {
        que.emplace(t);
      }
    }
  }
  cout << ret << endl;
  for(int i = 0; i < N; i++) {
    cout << A[ans[i]] << " ";
  }
  cout << endl;
}








Measured memory_bytes: 1024
n = int(input())
s = input()

left = [0]*(n+1)
right = [0]*(n+1)
for i in range(n):
    left[i+1] = left[i] + (s[i] == "#")
    right[n-i-1] = right[n-i] + (s[n-i-1] == ".")
v_min = n + 1
for i in range(n+1):
    v = left[i] + right[i]
    if v_min > v:
        v_min = v
print(v_min)

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

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

    string winner;
    if ((b - a) % 2 == 1) {
        winner = "Borys";
    } else {
        winner = "Alice";
    }

    cout << winner << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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



int main() {
	ll N;
	cin >> N;
	vector<vector<ll>> b(N + 1, vector<ll>(N + 1, 0));

	vector<ll> ans(N + 1);

	repn(i, N) {
		cin >> b[0][i];
	}

	rep(i,N) {
		ll M = N - i;
		for (ll j = M; j >= 1; j--) {
			if (b[i][j] > j) { b[N][0] = -1; break; }
			if (b[i][j] == j) { ans[M] = j; break; }
			if (j == 1) { b[N][0] == -1; break; }
		}

		if (b[N][0] == -1) { break; }

		repn(j, M) {
			if (j < ans[M]) { b[i + 1][j] = b[i][j]; }
			if (j > ans[M]) { b[i + 1][j - 1] = b[i][j]; }
		}
	}

	if (b[N][0] == -1) { cout << -1; }
	else {
		repn(i, N) {
			cout << ans[i] << endl;
		}
	}
	
	
	system("PAUSE");
}


Measured memory_bytes: 512
# AOJ ITP2_3_D: Lexicographical Comparison
# Python3 2018.6.24 bal4u

n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = list(map(int, input().split()))
k = min(n, m)
f = 2
for i in range(k):
	if a[i] < b[i]:
		f = 1
		break
	if a[i] > b[i]:
		f = 0
		break
if f == 2: f = 1 if n < m else 0
print(f)


Measured memory_bytes: 5624
package main

import "fmt"

func main(){
	var n,ans,g int
	var s string
	fmt.Scan(&n)
	fmt.Scan(&s)
	for i:=0 ; i<n ;i++ {
		if s[i:i+1] == "G" {
			g++
		}
	}
//fmt.Println(r,g,b)
	for i:=0 ; i<n ;i++ {
		if s[i:i+1] == "B" {
			for j:=0 ; j<i; j++ {
				if s[j:j+1] == "R" {
//fmt.Println(i,j)
					if 2*j-i >= 0 && s[2*j-i:2*j-i+1] == "G" {
							ans -= 1
					}
					if (i-j)%2 == 0 {
						if s[int((i+j)/2):int((i+j))/2+1] == "G" {
//fmt.Println("minus")
							ans -= 1
						}
					}
					if 2*i-j < n && s[2*i-j:2*i-j+1] == "G" {
							ans -= 1
					}
					ans += g
				}
			}
			for j:=i+1 ; j<n ; j++ {
				if s[j:j+1] == "R" {
					if 2*i-j >= 0 && s[2*i-j:2*i-j+1] == "G" {
						ans -= 1
					}
                                        if (j-i)%2 == 0 && s[(j+i)/2:(j+i)/2+1] == "G" {
						ans -= 1
					}
                                        if 2*j-i < n && s[2*j-i:2*j-i+1] == "G" {
						ans -= 1
					}
					ans += g
				}
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1812
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  if(N < K){
    cout << min(K - N, N) << endl;
  } else if(N == K){
    cout << 0 << endl;
  } else{
    ll m = N % K;
    cout << min(K - m, m) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
robots, count = [], 0
for x in range(N):
    X, L = map(int, input().split())
    robots.append((X+L, X-L))
robots.sort()
node = -10**12
for end, start in robots:
    if start >= node:
        node = end
        count += 1
print(count)


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

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

vector<vector<ll>> G;
ll N;
ll par[100000];
ll d[100000];
ll chs[100000];

void bfs(ll n){
    for(auto &e : G[n]){
        if(e == par[n]) continue;
        par[e] = n;
        d[e] = d[n] + 1;
        bfs(e);
        chs[n] += chs[e];
    }
    chs[n]++;
}

int main(){
    cin >> N;
    G.resize(N);
    for(int i=0;i<N-1;i++){
        ll a,b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    par[0] = -1;
    d[0] = 1;
    bfs(0);
    ll D = d[N-1];
    ll p = N-1;
    for(int i=0;i<(D/2)-1;i++) p = par[p];
    ll s = chs[p];
    ll f = N - s;
    if(f > s) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
    return 0;
}

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

int main(){
	int width,height;
  	int N,answer;
  	scanf("%d",&height);
    scanf("%d",&width);
  	scanf("%d",&N);
  	if(width<height){
      for(int i=1;i<=width;i++){
      	if(height*i>=N){
			answer=i;
          	break;
        }
      }
    }else{
        for(int i=1;i<=height;i++){
			if(width*i>=N){
              	answer=i;
              	break;
            }
        }
      }
  printf("%d",answer);
  return 0;
}


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

int main() {
  int n, a, j = 0, min = 100000;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    while (a % 2 == 0) {
      a /= 2;
      j++;
    }
    if (min > i) min = j;
    j = 0;
  }
  cout << min << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[][] b = new int[n][n];
        for (int i = 0 ; i < n ; i++) {
            for (int j = 0 ; j < n ; j++) {
                b[i][j] = -1;
            }
        }
        for (int i = 0 ; i < n; i++) {
            a[i] = sc.nextInt();
            for (int j = 0 ; j < a[i] ; j++) {
                int x = sc.nextInt() - 1;
                int y = sc.nextInt();
                b[i][x] = y;
            }
        }
        int c = 0;
        for (int i = 0 ; i < Math.pow(2, n) ; i++) {
            int[] d = new int[n];
            for (int j = 0 ; j < n ; j++) {
                if ((1 & i >> j) == 1) {
                    d[j] = 1;
                }
            }
            //正直ものとかていして、矛盾が生じないか確認する。
            boolean flg = true;
            for (int j = 0 ; j < n ; j++) {
                for (int k = 0 ; k < n ; k++) {
                    if (b[j][k] != -1) {
                        if (d[j] == 1) {
                            if (b[j][k] != d[k]) {
                                flg = false;
                            }
                        }
                    }
                }
            }
            int e = 0;
            if (flg) {
                for (int j = 0 ; j < n ; j++) {
                    e += d[j];
                }
            }
            c = Math.max(c, e);

  //          System.out.println(d[0] + " " + d[1] + " " + d[2]);
        }


        System.out.println(c);

    }

}

Measured memory_bytes: 26880
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  string a,b;
  cin >> a >> b;
  a += b;


  int num;
  num = atoi(a.c_str());
    
  bool can = false;
  REP(i,1000){
    if(num == i*i){
      can = true;
    }
  }
  
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}


Measured memory_bytes: 3604
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let x: u64 = read();
    let a = x / 500 * 1000;
    let b = (x % 500) / 5 * 5;
    println!("{}", a + b);
}



Measured memory_bytes: 4352
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;
using P = pair<int,int>;

int main(){

  int N, a;
  cin >> N;
  int ans = 0;

  vector<vector<int>> vec(2, vector<int>(N));

  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++) {
      cin >> a;
      vec.at(i).at(j) = a;
    }
  }

  int x = N;
  for (int i = 0; i < N; i++) {
    int j = 0;
    int sum = 0;
    int k;
    for (k = 0; k < x; k++) {
      sum += vec.at(j).at(k);
    }
    j = 1;
    for (int l = k-1; l < N; l++) {
      sum += vec.at(j).at(l);
    }
    ans = max(ans, sum);
    x--;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3544
use std::io::Read;
use std::collections::HashMap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut a: Vec<usize> = Vec::new();
    let mut counts: HashMap<usize, usize> = HashMap::new();
    for _ in 0..n {
        let ai: usize = iterator.next().unwrap().parse().unwrap();
        a.push(ai);
        *counts.entry(ai).or_insert(0) += 1;
    }

    let mut total = 0;
    for (_, &v) in &counts {
        if v >= 2 {
            total += comb(v, 2);
        }
    }

    let mut result = String::new();

    for ai in a {
        let mut ans = total;
        let count = *counts.get(&ai).unwrap();
        if count >= 2 {
            ans -= comb(count, 2);
        }
        if count >= 3 {
            ans += comb(count - 1, 2);
        }
        result.push_str(&format!("{}\n", ans));
    }

    return result.trim().to_string();
}

fn comb(n: usize, r: usize) -> usize {
    let mut n = n;
    let mut r = if r > n / 2 { n - r } else { r };

    let mut numerator = 1;
    let mut denominator = 1;
    while r > 0 {
        numerator *= n;
        denominator *= r;

        n -= 1;
        r -= 1;
    }
    numerator / denominator
}


Measured memory_bytes: 19324
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b;cin>>n>>a>>b;
  int ans=0;
  for(int i=1;i<=n;i++){
    int sum=0;
    int m=i;
    for(int j=0;j<5;j++){
      sum+=m%10;
      m/=10;
    }
    if(sum>=a&&sum<=b)ans+=i;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    string s;
    cin>>N>>s;
    s = "0"+s+"0";
    vector<int> dp(N+2);
    for(int i=1;i<=N;++i){
        dp[i+1] = max(dp[i+1],dp[i]);
        if(s.substr(i-1,3)!="101") continue;
        for(int l=i-1; s[l]!='0'; l--){
            dp[i+1] = max(dp[i+1],dp[l-1]+(i-l));
        }
        for(int r=i+1; s[r]!='0'; r++){
            dp[r] = max(dp[r],dp[i-2]+(r-i));
        }
    }
    cout<<dp[N+1]<<endl;
}


Measured memory_bytes: 2840
use std::cmp::max;
use std::collections::BTreeMap;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut xy = vec![];
    for _ in 0..n {
        let x: i64 = sc.read();
        let y: i64 = sc.read();
        xy.push((x, y));
    }

    xy.sort_by(|&(x1, y1), &(x2, y2)| {
        let t1 = (y1 as f64).atan2(x1 as f64);
        let t2 = (y2 as f64).atan2(x2 as f64);
        t1.partial_cmp(&t2).unwrap()
    });

    let tmp = xy.clone();
    xy.extend(tmp);

    let mut ans = 0;
    for head in 0..n {
        for tail in head..(head + n) {
            let mut cur = (0, 0);
            for i in head..(tail + 1) {
                cur.0 += xy[i].0;
                cur.1 += xy[i].1;
            }
            let (x, y) = cur;
            ans = max(ans, x * x + y * y);
        }
    }
    println!("{}", (ans as f64).sqrt());
}

fn update_max<T: PartialOrd>(a: &mut T, b: T) {
    if *a < b {
        *a = b;
    }
}

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a.abs()
    } else {
        gcd(b.abs(), a.abs() % b.abs())
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define PP pair<int,P>
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


main(){
  int n,q;
  cin>>n>>q;
  vector<PP> v;
  rep(i,n){
    int a,b,c;
    cin>>a>>b>>c;
    v.PB(PP(c,P(a-c,b-c-1)));
  }
  sort(all(v));

  int i=0;
  vector<P> a;
  rep(_,q){
    int d;
    cin>>d;
    a.PB(P(d,i));
  }
  int ans[300000]={};
  int b[300000]={};
  rep(i,n){
    auto l=lower_bound(all(a),P(v[i].S.F,0));
    auto r=upper_bound(all(a),P(v[i].S.S,inf));
    int la=l-a.begin(),ra=r-a.begin();
//    cout<<la<<' '<<ra<<endl;
    FOR(j,la,ra){
      if(b[j]) j=b[j]-1;
      if(ans[j]) continue;
      ans[j]=v[i].F;
      b[j]=ra;
    }
    
  }

  rep(i,q){
    cout<<((!ans[i])?-1:ans[i])<<endl;
  }


}


Measured memory_bytes: 18924
import math
def g(a, b):
    if b == 0:
        return a
    else:
        if a < b:
            a, b = b, a
        return g(b, a % b)


A, B = map(int, input().split())

t = g(A, B)

k = 2
cnt = 0
while t > 1:
    limit = int(math.sqrt(t))
    if k > limit + 1:
        break
    if t % k == 0:
        cnt += 1
        while t % k == 0:
            t //= k
    k += 1
if not t == 1:
    cnt += 1
print(cnt + 1)

Measured memory_bytes: 40300
#include<bits/stdc++.h>
#define ll long long

const int N = 200010;

std::pair <int, int> p[N];
int sufmax[N], sufmin[N];
int n;

ll calc(){
	int max = 0, max1 = 0, min = INT_MAX, min1 = INT_MAX;
	for (int i = 0; i < n; ++ i){
		max = std::max(max, p[i].first);
		max1 = std::max(max1, p[i].second);
		min = std::min(min, p[i].first);
		min1 = std::min(min1, p[i].second);
	}
	return 1ll * (max - min) * (max1 - min1);
}

int main(){
	scanf("%d", &n);
	int max = 0, min = INT_MAX, sit1, sit2;
	for (int i = 0; i < n; ++ i){
		scanf("%d%d", &p[i].second, &p[i].first);
		if (p[i].first > p[i].second){
			std::swap(p[i].first, p[i].second);
		}
	}
	if (n == 1){
		return printf("0\n"), 0;
	}
	ll ans = calc();
	std::sort(p, p + n);
	sufmin[n] = INT_MAX;
	for (int i = n - 1; i >= 0; -- i){
		sufmax[i] = std::max(sufmax[i + 1], p[i].first);
		sufmin[i] = std::min(sufmin[i + 1], p[i].first);
	}
	int nowmax = 0, nowmin = INT_MAX;
	for (int i = 0; i < n; ++ i){
		int x = std::max(nowmax, sufmax[i]), y = std::min(nowmin, sufmin[i]);
		int _x = std::max(std::max(nowmax, p[i].second), sufmax[i + 1]), _y = std::min(std::min(nowmin, p[i].second), sufmin[i + 1]);
		if (_x - _y <= x - y){
			std::swap(p[i].first, p[i].second);
		}
		nowmax = std::max(nowmax, p[i].first);
		nowmin = std::min(nowmin, p[i].first);
	}
	return printf("%lld\n", std::min(calc(), ans)), 0;
}

Measured memory_bytes: 3456
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    String ans = "NO";
    if((b - a) == (c - b)) ans = "YES";
    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

const ll mod = 1e9+7;
ll power(ll x, ll y, ll m=mod) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2ll, m) % m; 
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
} 

ll modInverse(ll a, ll m = mod) 
{ 
    return power(a, m-2ll, m); 
} 

void solve() {
    ll n, k, i, j, p, q, ans = 0;
    cin>>n>>k;
    ll a[k+1];
    Fo(i,1,k+1) {
        a[i] = power(k/i, n);
    }
    for(i=k;i>0;i--) {
        j = 2*i;
        while(j<=k) {
            a[i] = ( a[i] - a[j] + mod ) % mod;
            j += i;
        }
        ans = ( ans + a[i] * i ) % mod;
        // debug2(i,a[i]);
    }
    ans = (ans+mod)%mod;
    cout<<ans;
}

int main()
{
    fastIO;ll t=1;
    // cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 4384
#!/usr/bin/env python3
s = input()
n = len(s)-1

def calc(s, op):
    ret = int(s[0])
    for i in range(len(op)):
        if op[i] == '+':
            ret += int(s[i+1])
        else:
            ret -= int(s[i+1])
    
    return ret

for i in range(2**n):
    op =''
    for j in range(n):
        if (i >> j)&1:
            op += '+'
        else:
            op += '-'
    
    if calc(s,op) == 7:
        #print(op)
        ans = ''
        for a in range(len(op)):
            ans += s[a]
            ans += op[a]
        ans += s[-1]
        ans += '=7'
        print(ans)
        exit(0)








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

using namespace std;

int main()
{
    long long n;
    cin >> n;
    long long mn = 1e18;
    for(long long i = 2; i * i <= n; i ++){
        if(n % i == 0){
            mn = min(mn, i + (n / i));
        }
    }
    if(mn == 1e18){
        cout << n - 1 << "\n";
    }
    else{
        cout << mn - 2 << "\n";
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
#define ll long long int
#define m 1000000007
using namespace std;
int main()
{
    int t;
    t=1;
    while(t--)
    {
        int n,count=0,flag=0;
        cin >> n;
        while(n--)
        {
            int d1,d2;
            cin >> d1 >> d2;
            if(d1==d2)
            {
                count++;
            }
            else
            {
                count=0;
            }
            if(count==3)
            {
                flag=1;
            }
        }
        if(flag==1)
        {
            cout << "Yes";
        }
        else
        {
            cout << "No";
        }
    }
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	int a[n+1];
	for(int i=1; i<=n; ++i){
		cin >> a[i];
	}
	int next=1;
	int cnt=0;
	while(next!=2){
		next = a[next];
		++cnt;
		if(cnt > n) {
			cnt = -1;
			break;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, h, w);
    For(i, h) For(j, w){
        Cin(string, s);
        if(s == "snuke"){
            Cout((char)('A'+j), i+1);
            return 0;
        }
    }
}





Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll 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; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}
ll dp[20500];
int main() {
	ll a, b;
	cin >> n >> a >> b;
	if (b % 2 == a % 2) {
		cout << (b - a) / 2 << endl;
	}
	else {
		cout << min(a - 1, n - b) + 1 + (b - a - 1) / 2 << endl;
	}
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD ((ll)1e9+7)

ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}

ll powl(ll a,ll b){
    if(b==0)
        return 1;
    return powl(a * a % MOD, b / 2) * (b & 1 ? a : 1) % MOD;
}
struct UnionFind{
    vector<int> nxt;
    UnionFind(int x){
        nxt.resize(x);
        for (int i = 0; i < x;i++){
            nxt[i] = i;
        }
    }
    int find(int x){
        if(nxt[x]==x)
            return x;
        return nxt[x] = find(nxt[x]);
    }
    inline void unite(int x,int y){
        nxt[find(y)] = find(x);
    }
};


ll N,Q;
ll l[33],r[33];
vector<ll> aiv[33];
vector<vector<ll>> dp;
vector<pll> av;
vector<ll> nv;
vector<ll> As;
ll i,j,k;
int main(){
    scanf("%lld%lld", &N,&Q);
    fornum(i,0,Q){
        scanf("%lld%lld",&l[i],&r[i]);
        --l[i];
        av.push_back({l[i], i});
        av.push_back({r[i], i});
    }
    
    sort(av.begin(), av.end());

    UnionFind uf(Q+1);
    aiv[av[0].second].push_back(0);
    fornum(i,1,av.size()){
        if(av[i].first != av[i - 1].first){
            As.push_back(moddiv(powl(10, av[i].first - av[i - 1].first) - 1 + MOD, 9));
        }else{
            uf.unite(av[i].second, av[i - 1].second);
        }
        aiv[av[i].second].push_back(As.size());
    }

    nv.assign(1 << Q, 1);
    fornum(i, 0, 1 << Q)
    {
        ll a = 0;
        fornum(j,0,Q){
            if(i&(1<<j)){
                fornum(k,0,2){
                    ll ii = aiv[j][k];
                    if(a&(1ll<<ii))
                        continue;
                    if(ii>0&&(a&(1ll<<(ii-1)))){
                        nv[i] = moddiv(nv[i] * (As[ii - 1] + 1), As[ii - 1]);
                    }
                    if(ii<As.size()&&(a&(1ll<<(ii+1)))){
                        nv[i] = moddiv(nv[i] * (As[ii] + 1), As[ii]);
                    }
                    a |= (1ll << ii);
                }
            }
        }
    }

    dp.assign(10, vector<ll>(1 << Q, 0));
    dp[0][0] = powl(10, av[0].first) * powl(10, N - av[av.size() - 1].first) % MOD;
    fornum(i,0,As.size()){
        dp[0][0] = dp[0][0] * As[i] % MOD;
    }
    fornum(i,0,9){
        fornum(j,0,(1<<Q)){
            fornum(k,0,Q){
                bool a = j & (1ll << k);
                bool b = j & (1ll << uf.find(k));
                if(a!=b)
                    break;
                if(i==0){
                    if(l[k]==av[0].first&&!a){
                        break;
                    }
                }
            }
            if(k<Q){
                continue;
            }
            
            dp[i + 1][j] += dp[i][j];
            for (k = j; k > 0;k=(k-1)&j){
                dp[i + 1][j] += dp[i][j ^ k] * nv[k];
                dp[i + 1][j] %= MOD;
            }
        }
    }

    printf("%lld", dp[9][(1 << Q) - 1]);
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<string>

using namespace std;
void solve(string,int);
int main(){
  string S;
  int K;

  cin >> S;
  cin >> K;
  solve(S,K);

  return 0;
}

void solve(string S,int K){
  if(S[0]=='1'){
    if(K==1){
      cout << 1;
    }else{
      solve(S.substr(1),K-1);
    }
  }
  else{
    cout << S[0];
  }
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){

  int n;
  cin >> n;
  int k = 0;
  rep(i,1000)if((i*i == 1+8*n) && (i & 1))k = (i+1)/2;
  if(k == 0){
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
  cout << k << endl;
  vector<int> cnt(n+100,0);
  vector<vector<int>> v(k);
  rep(i,k){
    int cn = k-1;
    rep(j,i){
      rep(l,k-1){
        if(cnt[v[j][l]] != 2){
          v[i].push_back(v[j][l]);
          cn--;
          cnt[v[j][l]]++;
          break;
        }
      }
    }
    int left = 0,right = n;
    while(right-left > 1){
      int mid = (right+left)/2;
      if(cnt[mid] == 0)right = mid;
      else left = mid;
    }
    for(int j = right;j <= n && cn;j++,cn--)cnt[j]++,v[i].push_back(j);
  }
  rep(i,k){
    printf("%d ",k-1);
    rep(j,k-1)printf("%d ",v[i][j]);
    printf("\n");
  }




  



  return 0;
}

Measured memory_bytes: 2688
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    s = list(input().rstrip())
    k = int(input())
    a = s[k-1]
    for i in range(n):
        if s[i] == a:
            continue
        s[i] = '*'
    print(*s, sep='')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String code_st =scan.next();
		int[] code = new int[4];
		code[0] = Integer.parseInt(code_st.substring(0, 1));
		for (int i = 1; i < 4; i++) {
			code[i] = Integer.parseInt(code_st.substring(i, i + 1));
			if (code[i - 1] == code[i]) {
				System.out.println("Bad");
				return;
			}
		}
		System.out.println("Good");
		return;
	}
}


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

int main(){
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int ans = 0;
    for (int i = 0; i <= 3000; i++){
        for (int j = 0; j <= 3000; j++) {
            int v = i * R + j * G;
            if (N >= v && (N - v) % B == 0){ 
                ans++;
            }
        }
    }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long n, a[102000], b[102000], c[102000];
vector<pair<long long, long long>>x, P;
int main() {
	cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; x.push_back(make_pair(a[i], i)); }
	sort(x.begin(), x.end());
	long long pos1 = n + 1, mn = 1LL << 62;
	for (int i = x.size() - 1; i >= 0; i--) {
		if (i >= 1 && x[i].first == x[i - 1].first)continue;
		if (mn <= x[i].first || pos1 < x[i].second)continue;
		mn = x[i].first;
		pos1 = x[i].second;
		P.push_back(make_pair(mn, pos1));
	}
	for (int i = 0; i < x.size(); i++)c[i] = x[i].first;
	for (int i = 1; i <= x.size(); i++)c[i] += c[i - 1];
	reverse(P.begin(), P.end());
	long long ret = 0;
	for (int i = P.size() - 1; i >= 0; i--) {
		long long Target = 0; if (i >= 1)Target = P[i - 1].first;

		int pos2 = lower_bound(x.begin(), x.end(), make_pair(Target, -1LL)) - x.begin();
		long long Y = c[n]; if (pos2 >= 1)Y -= c[pos2 - 1];
		Y -= Target*(n - pos2);
		b[P[i].second] = (Y - ret);
		ret = Y;
	}
	for (int i = 1; i <= n; i++) { cout << b[i] << endl; }
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define mod 1000000007
#define PI 3.14159265
#define endl '\n'
#define MAX 200001

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

    int n;
    cin >> n;
    vector <ll> vec1, vec2;
    ll v;
    ll s1 = 0, s2 = 0;
    for (int i = 0; i < n; i++) {
        cin >> v;
        vec1.pb(v);
        s1 += v;
    }
    for (int i = 0; i < n; i++) {
        cin >> v;
        vec2.pb(v);
        s2 += v;
    }
    if (s1 < s2) {
        cout << "-1" << endl;
        return 0;
    }
    vector <ll> dif;
    for (int i = 0; i < n; i++) {
        dif.pb(vec1[i] - vec2[i]);
        s1 -= vec2[i];
    }
    sort(all(dif));
    int ans = 0;
    for (auto it : dif) {
        if (it >= 0) {
            s1 -= it;
            ans += (s1 >= 0);
        }
    }
    cout << n - ans << endl;


    return 0;
}


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

int hyoka(string);
int isNum(int);

int main(){
	int n,i;
	string s;
	
	cin>>n;
	for(i=0;i<n;i++){
	 cin>>s;
	 cout<<hyoka(s)<<endl;
	}
			
	return 0;
}


int hyoka(string s){
	int total=0,work=0;
	int tmp1,tmp2;
	int oi=0;
	char oc;
	int n;
	string cs;
	
	if(s[oi]=='(' || isNum(s[oi])!=-1){s='+'+s;}
	//cout<<s<<endl;

	while(1){
	 oc=s[oi];if(oc=='='){total+=work;break;}
	 
	 if(s[oi+1]!='('){	//??°???????????????
	  tmp1=0;
	  while(1){
	   oi++;
	   tmp2=isNum(s[oi]);
	   if(tmp2!=-1){tmp1=tmp1*10+tmp2;}else{break;}
	  }
	 }else{	//??????????????°
	  cs="";n=1;oi++;
	  while(1){
	   oi++;
	   switch(s[oi]){
		case '(':n++;break;
		case ')':n--;break;
	   }
	   if(n!=0){cs+=s[oi];}else{break;}
	  }
	  cs+='=';
	  //cout<<cs<<endl;
	  tmp1=hyoka(cs);
	 }
	
	 switch(oc){
	  case '+':total+=work;work=tmp1;break;
	  case '-':total+=work;work=-tmp1;break;
	  case '*':work*=tmp1;break;
	  case '/':work/=tmp1;break;
	 }
	}
	
	return total;
}

int isNum(int c){
	if(48<=c && c<=57){
	 return c-48;
	}
	return -1;
}

Measured memory_bytes: 1216