akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
using ll = long long;
//#define int ll
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
signed main(){
    using piii = pair<int,pii>;
    vector<piii>v;
    int n; cin>>n;
    rep(i,n){
        piii hoge; cin>>hoge.first>>hoge.second.first>>hoge.second.second;
        v.push_back(hoge);
    }
    bool flag=true;
    piii now=make_pair(0,pii(0,0));
    rep(i,v.size()){
        piii res=v[i];
        int dif=res.first-now.first;
        int sum=abs(res.second.first-now.second.first)+abs(res.second.second-now.second.second);
        if((dif%2!=sum%2)||dif<sum)return puts("No")*0;
        now=res;
    }
    return puts("Yes")*0;
}


Measured memory_bytes: 1912
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
const int MAX_N = 150;
struct edge { int to, dist; };
vector<edge> G[MAX_N];
int solve(int n)
{
    int res = 0;
    bool used[MAX_N] = {};
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, 0));
    while(not que.empty())
    {
        P p = que.top(); que.pop();
        int v = p.second;
        if(used[v]) continue;
        used[v] = true;
        res += p.first;
        for(int u = 0; u < G[v].size(); u++)
        {
            edge e = G[v][u];
            if(used[e.to] == false) que.push(P(e.dist, e.to));
        }
    }
    res /= 100;
    res -= n - 1;
    return res;
}
int main()
{
    int n;
    while(cin >> n, n)
    {
        int m; cin >> m;
        for (int i = 0; i < m; i++)
        {
            int a, b, d;
            scanf("%d,%d,%d", &a, &b, &d);
            G[a].push_back({b, d});
            G[b].push_back({a, d});
        }
        cout << solve(n) << endl;
        for(int i = 0; i < MAX_N; i++) G[i].clear();
    }
    return 0;
}




Measured memory_bytes: 3288
def knapsack_rec(target, W, V): # target=knapsack weight
    P = {}
    P[0] = target
    max_ = 0

    for vi in range(len(V)):
        we, va = W[vi], V[vi]
        for i in range(max_, -1, -1):
            if i in P:
                piva = P.get(i + va, -1)
                if piva < P[i] - we:
                    P[i + va] = P[i] - we
                    if max_ < i + va:
                        max_ = i + va
    return max_

assert knapsack_rec(15, [6, 5, 6, 6, 3, 7], [5, 6, 4, 6, 5, 2]) == 17

if __name__ == "__main__":
    import sys
    n, w, *r = map(int, sys.stdin.read().split())
    W, V = r[::2], r[1::2]
    ans = knapsack_rec(w, W, V)
    print(ans)


Measured memory_bytes: 45148
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
#define pb push_back
#define PI 3.14159265
int M = 998244353;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  bool check = 0;
  int a[n];
  for (int i = 0; i < n; ++i)
  {
    cin >> a[i];
    if (a[i] == 0)
      check = 1;
  }
  if (check)
    cout << "0" ;
  else
  {
    int ans = 1e18;
    for (int i = 0; i < n; ++i)
    {
      ans /= a[i];
      if (ans < 1)
      {
        cout << "-1";
        exit(0);
      }
    }
    if (ans < 1)
    {
      cout << "-1";
      exit(0);
    }
    int x = 1;
    for (int i = 0; i < n; ++i)
    {
      x *= a[i];
    }
    cout << x;
  }
}

Measured memory_bytes: 4384
import sys
from collections import Counter

n = int(input())
aaa = [int(line) for line in sys.stdin.readlines()]
cnt = Counter(aaa)
nim = 0
mnt = 0
prev_i = 0
for i, c in sorted(cnt.items()):
    di = i - prev_i
    mnt += c
    if di % 2 == 1:
        nim ^= mnt
print('first' if nim > 0 else 'second')


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

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

  switch (N) {
    case 1:
      cout << "Hello World" << endl;
      break;

    default:
      int A, B;
      cin >> A >> B;
      cout << A + B << endl;
      break;
  }
}

Measured memory_bytes: 256
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
using namespace std;

#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        ll p=c*d/__gcd(c,d);
        ll s=b/c-(a-1)/c;
       // cout<<s;
        ll t=b/d-(a-1)/d;
        ll o=b/p-(a-1)/p;
        cout<<b-a+1-s-t+o;
    }
    return 0;
}

Measured memory_bytes: 256
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
A = get_ints

hash = Hash.new(0)

A.each do |a|
  hash[a] += 1
end
sum = 0
hash.each do |i, num|
  sum += (num * (num-1)) / 2
end

A.each do |a|
  if hash[a] == 1
    puts sum
  else
    cur = (hash[a] * (hash[a] - 1))/2
    xxx = ((hash[a] - 1) * (hash[a] - 2)) / 2
    puts sum - cur + xxx
  end
end


Measured memory_bytes: 37028
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;

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

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

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

int atoi(char a) {
    return a - '0';
}

int main(){
    char A, B, C, D;
    cin >> A >> B >> C >> D;
    if (atoi(A) + atoi(B) + atoi(C) + atoi(D) == 7) {
        cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;// +++
    } else if (atoi(A) - atoi(B) + atoi(C) + atoi(D) == 7) {
        cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;// -++
    } else if (atoi(A) - atoi(B) - atoi(C) + atoi(D) == 7) {
        cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;// --+
    } else if (atoi(A) - atoi(B) - atoi(C) - atoi(D) == 7) {
        cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;// ---
    } else if (atoi(A) + atoi(B) - atoi(C) - atoi(D) == 7) {
        cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;// +--
    } else if (atoi(A) + atoi(B) + atoi(C) - atoi(D) == 7) {
        cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;// ++-
    } else if (atoi(A) - atoi(B) + atoi(C) - atoi(D) == 7) {
        cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;// -+-
    } else if (atoi(A) + atoi(B) - atoi(C) + atoi(D) == 7) {
        cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;// +-+
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

const ll INF = 1000000000000000;

template <typename T>
struct Edge
{
    int to;
    T cost;
};

template <typename T>
struct WeightedGraph
{
    int n;
    vector<vector<Edge<T>>> g;
    
    WeightedGraph(int n) : n(n){
        g.resize(n);
    }
    
    void init(int n_){
        n = n_;
        g.resize(n_);
    }
    
    void add_edge(int from, int to, T cost){
        g[from].push_back((Edge<T>){to, cost});
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    WeightedGraph<ll> g(n);
    for(int i = 0; i < m; i++){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        g.add_edge(a, b, c);
    }
    ll d[1005];
    for(int i = 0; i < n; i++) d[i] = -INF;
    d[0] = 0;
    ll l;
    for(int i = 0; i < n * 2; i++){
        for(int u = 0; u < n; u++){
            for(Edge<ll> e : g.g[u]){
                int v = e.to;
                if(d[u] + e.cost > d[v]){
                    d[v] = d[u] + e.cost;
                }
            }
        }
        if(i == n) l = d[n - 1];
    }
    if(d[n - 1] > l) cout << "inf" << endl;
    else cout << l << endl;
}


Measured memory_bytes: 3636
#include <cstdlib>
#include <cstdio>

using namespace std;

int a,b;

int main()
{
	for(a=1;a<=9;a++)
	{
		for(b=1;b<=9;b++)
		printf("%dx%d=%d\n",a,b,a*b);
	}
	return 0;
}

Measured memory_bytes: 924
#include <iostream>

using namespace std;

int main(){
	int h,w;

	while(cin>>h>>w){
		if(h==0&&w==0)break;

		for(int i=0;i<w;i++){
			cout<<"#";
		}
		cout<<endl;


		for(int i=0;i<h-2;i++){
			cout<<"#";
			for(int j=0;j<w-2;j++){
				cout<<".";
			}
			cout<<"#";

			cout<<endl;
		}
		
		for(int i=0;i<w;i++){
			cout<<"#";
		}
		cout<<endl;

		cout<<endl;
	}

	return 0;
}

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

using namespace std;
typedef long long ll;

char GetNotUsed(char a, char b){
  if(a == 'R'){
    if(b == 'G') return 'B';
    if(b == 'B') return 'G';
  }else if(a == 'G'){
    if(b == 'R') return 'B';
    if(b == 'B') return 'R';    
  }else if(a == 'B'){
    if(b == 'R') return 'G';
    if(b == 'G') return 'R';    
  }
  return 'e';
}

int main(){
  ll N;
  string S;
  cin >> N >> S;
  
  vector<ll> acR(N,0);
  vector<ll> acG(N,0);
  vector<ll> acB(N,0);
  
  for(ll i=N-1; i>=0; i--){
    acR[i] = (i==N-1) ? 0 : acR[i+1];
    acG[i] = (i==N-1) ? 0 : acG[i+1];
    acB[i] = (i==N-1) ? 0 : acB[i+1];
    if(S[i] == 'R') ++acR[i];
    if(S[i] == 'G') ++acG[i];
    if(S[i] == 'B') ++acB[i];
  }
  
  unordered_map<char, vector<ll>*> acmap;
  acmap.emplace('R', &acR);
  acmap.emplace('G', &acG);
  acmap.emplace('B', &acB);
  
  ll count = 0;
  for(ll i=0; i<N-2; i++){
    for(ll j=i+1; j<N-1; j++){
      if(S[i] == S[j]) continue;
      char c = GetNotUsed(S[i],S[j]);
      vector<ll> *target = acmap[c];
      ll temp = (*target)[j+1];
      ll symIndex = 2*j-i;
      if(symIndex < N && S[2*j-i] == c) --temp;     
      count += temp;
    }
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3716
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int dp[20001];
int AB[10001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int H = getint(), N = getint();
	rep1(i, 20000) dp[i] = 1e9;
	rep1(i, 10000) AB[i] = 2e9;

	rep(i, N) {
		int a = getint(), b = getint();
		chmin(AB[a], b);
	}
	rep1(i, 10000) {
		int k = AB[i];
		if (k < 1e9) {
			int ima = k;
			for (int j = i + i; j <= 10000; j += i) {
				ima += k;
				if (AB[j] >= ima) AB[j] = 2e9;
			}
			auto dp2 = dp + i;
			rep(j, H) if (dp2[j] > dp[j] + k) dp2[j] = dp[j] + k;
		}
	}

	int kotae = *min_element(dp + H, dp + H + 10001);
	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	a := map[int]int{}
	cnt := 0

	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		if a[x] < x {
			a[x]++
		} else {
			cnt++
		}
	}

	for k, v := range a {
		if k != v {
			cnt += v
		}
	}

	fmt.Println(cnt)
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

ll ppow(ll a,ll b,ll MOD){
	a %= MOD;
	ll res = 1;
	while(b){
		if(b & 1) res = (res * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

int main(void){
    ll 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;
    }
    vector<ll> cum(n+1,0);
    map<ll,ll> dict;
    dict[0]++;
    for(ll i=n-1; i>=0; i--){
        cum[i] = (cum[i+1] + (s[i]-'0') * ppow(10,n-1-i, p)) % p;
        dict[cum[i]]++;
    }
    ll ans = 0;
    for(auto ob: dict){
        ll sec = ob.sc;
        ans += sec * (sec-1) /2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2564
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;

int main() {
	string s;
	cin >> s;
	if (s == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1 << endl;
		return 0;
	}

	int l = s.size();
	if (l < 26) {
		vi ex(26);
		REP(i, l) {
			ex[s[i] - 'a']++;
		}
		REP(i, 26) {
			if (!ex[i]) {
				char c = 'a' + i;
				cout << s + c << endl;
				return 0;
			}
		}
	}
	else {
		vi ex(26);
		for (int i = 25; i > 0; i--) {
			ex[s[i] - 'a']++;
			if (s[i - 1] < s[i]) {
				char c;
				REP(j, 26) {
					if (ex[j]) {
						c = 'a' + j;
						if(s[i-1] < c) {
							cout << s.substr(0, i - 1) + c << endl;
							return 0;
						}
					}
				}
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        for(int i = 1;i <= 10000;i++){
            int a = sc.nextInt();
            System.out.println("Case" + " " + i + ":" + " " + a);
        }
    }
}


Measured memory_bytes: 41820
package main

import (
	"bufio"
	"errors"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func create(size int, conds map[int]int) (int, error) {
	base := []rune(strings.Repeat("0", size))
	for k, v := range conds {
		base[k-1] = rune(v + 48)
	}
	if _, exist := conds[1]; size != 1 && !exist {
		base[0] = '1'
	}
	if base[0] != '0' || size == 1 {
		return strconv.Atoi(string(base))
	}
	return 0, errors.New("No")
}

func main() {
	n, m := nextInt(), nextInt()

	conds := map[int]int{}

	dup := false

	for i := 0; i < m; i++ {
		s := nextInt()
		c := nextInt()
		if v, exist := conds[s]; exist && c != v {
			dup = true
		}
		conds[s] = c
	}

	var r int
	if dup {
		r = -1
	} else {
		rr, err := create(n, conds)
		if err != nil {
			r = -1
		} else {
			r = rr
		}
	}
	fmt.Println(r)
}


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

int main() {
    string S;
    ll K;
    cin >> S;
    cin >> K;
    
    int ans = 1, mem;
    for (int i=0; i<S.size(); i++) {
        if (S[i] - '1' != 0) {
            ans = S[i] - '0';
            mem = i;
            break;
        }
    }
    
    if (mem + 1 > K) cout << 1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc097/tasks/abc097_b

int main() {
    int X; cin >> X;
    vector<int> exp(X+5);
    exp[1] = 1;

    for (int i = 2; i < X; i++) {
        int v = i*i;
        while(v <= X) {
            exp[v] = 1;
            v = v*i;
        }
    }

    for (int i = X; i >= 0; i--) if (exp[i]){
            cout << i << "\n";
            return 0;
    }



    return 0;
}

Measured memory_bytes: 256
#include <iostream>

class Dice {
    public:
        int* label;
        Dice() {
            label = new int[7];
        };
        ~Dice() {
            delete[] label;
        }
        void turn_dice(char c) {
           
            if(c == 'S') {
               int w = label[5];
               label[5] = label[6];
               label[6] = label[2];
               label[2] = label[1];
               label[1] = w;
            }
            else if(c == 'E') {
                int w = label[4];
                label[4] = label[6];
                label[6] = label[3];
                label[3] = label[1];
                label[1] = w;
            }
            else if(c == 'N') {
                int w = label[2];
                label[2] = label[6];
                label[6] = label[5];
                label[5] = label[1];
                label[1] = w;
            }
            else if(c == 'W') {
                int w = label[3];
                label[3] = label[6];
                label[6] = label[4];
                label[4] = label[1];
                label[1] = w;
            }
        };
};
void same(Dice& dice1, Dice& dice2) {
    for(int i = 1; i <= 6; i++) {
        dice1.turn_dice('S');
        for(int j = 1; j <= 4; j++) {
            dice1.turn_dice('E');
            if(dice1.label[1] == dice2.label[1]&&
               dice1.label[2] == dice2.label[2]&&
               dice1.label[3] == dice2.label[3]&&
               dice1.label[4] == dice2.label[4]&&
               dice1.label[5] == dice2.label[5]&&
               dice1.label[6] == dice2.label[6]) {
                std::cout << "Yes" << std::endl;
                return;
            }
        }
    }
    dice1.turn_dice('E');
    dice1.turn_dice('N');
    for (int k = 1; k <= 4; k++) {
        dice1.turn_dice('E');
        if(dice1.label[1] == dice2.label[1]&&
           dice1.label[2] == dice2.label[2]&&
           dice1.label[3] == dice2.label[3]&&
           dice1.label[4] == dice2.label[4]&&
           dice1.label[5] == dice2.label[5]&&
           dice1.label[6] == dice2.label[6]) {
            std::cout << "Yes" << std::endl;
            return;
        }
    }
    dice1.turn_dice('N');
    dice1.turn_dice('N');
    for (int k = 1; k <= 4; k++) {
        dice1.turn_dice('E');
        if(dice1.label[1] == dice2.label[1]&&
           dice1.label[2] == dice2.label[2]&&
           dice1.label[3] == dice2.label[3]&&
           dice1.label[4] == dice2.label[4]&&
           dice1.label[5] == dice2.label[5]&&
           dice1.label[6] == dice2.label[6]) {
            std::cout << "Yes" << std::endl;
            return;
        }
    }
    std::cout << "No" << std::endl;
}


int main() {
    Dice dice1;
    Dice dice2;
    for(int i = 1; i <= 6; i++) {
       std::cin >> dice1.label[i];
    }
    for(int j = 1; j <= 6; j++) {
        std::cin >> dice2.label[j];
    }
    same(dice1, dice2);
    return 0;
}



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

int disits(int x) {
  int ret = 0;
  while(x > 0) {
    ret += x%10;
    x /= 10;
  }
  return ret;
}

int main() {
  int n, ans = 100000;
  cin >> n;
  for(int i = 1; i < n; i++) {
    int a = i;
    int b = n-i;
    ans = min(ans, disits(a)+disits(b));
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
module Main where
 
import Control.Applicative
import Numeric
import Data.List
 
type House = [Floor]
type Floor = [Room]
type Room  = Int
 
officialHouseInit :: [House]
officialHouseInit = replicate 4 houseInit
 
houseInit :: House
houseInit = replicate 3 floorInit
 
floorInit :: Floor
floorInit = replicate 10 roomInit
 
roomInit :: Room
roomInit = 0
 
showOfficialHouse :: [House] -> String
showOfficialHouse = intercalate (replicate 20 '#' ++ "\n") . map showHouse
 
showHouse :: House -> String
showHouse = unlines . map showFloor
 
showFloor :: Floor -> String
showFloor = concatMap ((' ' :) . showRoom) 
 
showRoom :: Room -> String
showRoom = show
 
main :: IO ()
main = do
  { [n] <- getInts
  ; hs <- loop n officialHouseInit
  ; putStr $ showOfficialHouse hs
  }
 
loop :: Int -> [House] -> IO [House]
loop 0 hs = return hs
loop n hs = do
  { [b,f,r,v] <- getInts
  ; let (fronts, ho : ends) = splitAt (b - 1) hs
  ; let (lows, fl : ups)    = splitAt (f - 1) ho
  ; let (xs, rm : ys)       = splitAt (r - 1) fl
  ; let fl' = xs ++ (rm + v) : ys
  ; let ho' = lows ++ fl' : ups
  ; let hs' = fronts ++ ho' : ends
  ; loop (n-1) hs'
  }
   
--
 
getInts :: IO [Int]
getInts = map read . words <$> getLine
 
putInts :: [Int] -> IO ()
putInts = putStrLn . unwords . map show
 
getDoubles :: IO [Double]
getDoubles = map read . words <$> getLine
 
putDoubles :: [Double] -> IO ()
putDoubles = putStrLn . unwords . map showDouble
 
showDouble :: Double -> String
showDouble d = showFFloat Nothing d ""



Measured memory_bytes: 4624
def maxheapify(h,a,i):
    l=2*i+1
    r=2*i+2
    if l<h:
        if a[l]>a[i]:
            largest=l
        else:
            largest=i
        if r<h:
            if a[r]>a[largest]:
                largest=r
    
        if largest!=i:
            a[i],a[largest]=a[largest],a[i]
            maxheapify(h,a,largest)
    return a

def buildmaxheap(h,a):
    for i in range((h-1)//2,-1,-1):
        maxheapify(h,a,i)
    return a

h=int(input())
a=list(map(int,input().split()))
ans=buildmaxheap(h,a)
print("",end=" ")
for i in range(h-1):
    print(ans[i],end=" ")
print(ans[h-1])



Measured memory_bytes: 63700
#include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
int main() {
	int n;
	int cnt[2] = {0, 0};
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		cnt[a % 2]++;
	} 
	if (!cnt[0] || !cnt[1]) cout << 0 << endl;
	else {
		int dv = n - 1;
		if (cnt[1] % 2 == 0) dv--;
		cout << dv << endl;
	}
	return 0;
}



Measured memory_bytes: 3248
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws Exception {
        long[] arr = inputval();
        long X,Y;
        X = arr[0];
        Y = arr[1];
        int ans=0;
        while(X <= Y){
            X*=2;
            ans++;
        }
        System.out.println(ans);

        /*if(arr[0] > arr[1]) ans = 0;
        else ans = (int)(Math.log(Y/X)/Math.log(2)) + 1;
        System.out.println(ans);
        */
    }


    static long[] inputval() throws Exception {
        String[] strarray = br.readLine().trim().split(" ");
        long[] intarray = new long[strarray.length];
        for (int i = 0; i < intarray.length; i++) {
            intarray[i] = Long.parseLong(strarray[i]);
        }
        return intarray;
    }

    static void array_sout(int[][] array) {
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }

    static void array_sout(int[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();
    }
}

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

int main()
{
    int h,w;
    cin >> h >> w;
    string s[h];
    for(int i = 0; i < h; i++) cin >> s[i];

    int x[] = {1,1,1,0,-1,-1,-1,0},y[] = {1,0,-1,-1,-1,0,1,1}; //右上から時計回り
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] == '#') continue;
            int n = 0;
            for(int k = 0; k < 8; k++){
                int nx = j + x[k];
                int ny = i + y[k];
                if(nx < 0 || nx >= w) continue;
                if(ny < 0 || ny >= h) continue;
                if(s[ny][nx] == '#') n++;
            }
            s[i][j] = char(n + '0');
        }
    }

    for(int i = 0; i < h; i++) cout << s[i] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
int A, B, C;
int* l;
int dfs(int i, int a, int b, int c);

int main(int argc, char** argv){
  cin >> N >> A >> B >> C;
  l = (int *)malloc(sizeof(int)*N);
  for(int cnt0=0; cnt0<N; cnt0++){
    cin >> l[cnt0];
  }
  int a, b, c;
  a = b = c = 0;
  int ans = dfs(0, a, b, c);
  printf("%d", ans);
  return 0;
}

int dfs(int i, int a, int b, int c){
  if(i == N){
    int m = min(a, b);
    m = min(m, c);
    if(m > 0){
      return abs(a-A)+abs(b-B)+abs(c-C)-30;
    }else{
      return 1e9;
    }
  } 
  
  int r1 = dfs(i+1, a, b, c);
  int r2 = dfs(i+1, a+l[i], b, c) + 10;
  int r3 = dfs(i+1, a, b+l[i], c) + 10;
  int r4 = dfs(i+1, a, b, c+l[i]) + 10;

  int ret = min(r1, r2);
  ret = min(ret, r3);
  ret = min(ret, r4);

  return ret;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int counter[1000006];
bool divided[1000005];
int main(){
	int n;
	cin>>n;
	vector<int>arr(n);
	for(int i=0; i<n; i++) cin>>arr[i];
	sort(arr.begin(),arr.end());
	for(int i=0; i<n; i++){
		counter[arr[i]]++;
		if(!divided[arr[i]] && counter[arr[i]]==1){
			for(int j=2*arr[i]; j<=1000000; j+=arr[i]) divided[j] = true;
		}
	}
	int ret = 0;
	for(int i=0; i<n; i++){
		if(arr[i]==1){
			if(counter[1]==1) ret++;
		}
		else{
			if(counter[1]) continue;
			if(divided[arr[i]] || counter[arr[i]]>1) continue;
			ret++;
		}
	}
	cout<<ret;
}


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

int main()
{
    ll n;
    ll p[200000];
    cin >> n;
    for (ll i = 1; i <= n;i++)
        cin >> p[i];
    ll ans = 0,min = p[1];
    for (ll i = 1; i <= n;i++)
    {
        if(p[i] <= min)
        {
            ans++;
            min = p[i];
        }
    }
    cout << ans;
}

Measured memory_bytes: 1792
import math

n = int(input())
ans = {}

for i in range(n):
    ans[i+1] = 0

for x in range(1, int(math.sqrt(n))+1):
    for y in range(1, int(math.sqrt(n))+1):
        for z in range(1, int(math.sqrt(n))+1):
            a = x**2+y**2+z**2+x*y+y*z+z*x
            # print(x,y,z,a)
            if a in ans:
                ans[a] += 1

for a in ans.values():
    print(a)

Measured memory_bytes: 9684
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
  int x, y ,z;
  cin >> x >> y >> z;
  cout << x * y /2<< endl;
  return 0;
  // cout << fixed;//小数点を確実に10桁で表示するためのもの
  // cout << setprecision(10); 
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<int> a;
    a.resize(n);
    for (auto &x: a){
        cin >> x;
    }
    int res = 0;
    sort(a.begin(), a.end());
    for (int i=0;i<n-2;i++){
        for (int j=i+1;j<n-1;j++){
            int down = a[j] - a[i];
            int up = a[i] + a[j];
            
            auto posLower = lower_bound(a.begin() + j + 1, a.end(), down + 1);
            auto posUpper = upper_bound(a.begin() + j + 1, a.end(), up - 1);
            
            if (posLower != a.end()){
                int pL = posLower - a.begin();
                int pU = posUpper - a.begin() - 1;
                if (pU < pL) continue;
                
                res += (pU - pL + 1);
                
            }
        }
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define in        []{int n; cin>>n; return n;}()

int main() {
    int N = in;
    if( !N ) return 0;
    vector<int> A(N+1, 0);
    rep( i, N ) A[i+1] = in + A[i];
    int ans = INT_MIN;
    rep( r, N+1 ) rep( l, r ) ans = max( ans, A[r] - A[l] );
    cout << ans << "\n";
    main();
}



Measured memory_bytes: 3016
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  int n, h, w;
  cin >> n >> h >> w;
  cout << (n - h + 1) * (n - w + 1) << endl;
}


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

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin >> n ;
	string s;
	cin >> s;
	if(s.length()>n){
		for(int i(0);i<n;++i){
			cout << s[i];
		}
		cout << "...";
	}
	else{
		cout << s;
	}
}

Measured memory_bytes: 3648
n, m = map(int, input().split())
arr = []
for i in range(m):
    arr.append(list(map(int, input().split())))
arr = [[0] + list(map(int, input().split()))] + arr
ans = 0
for i in range(2**n):
    light = []
    for j in range(n):
        light.append(i >> j & 1)
    cnt = 0
    for k in range(1, m+1):
        judge = 0
        for s in range(1, len(arr[k])):
            judge += light[arr[k][s]-1]
        judge %= 2
        if judge == arr[0][k]:
            cnt += 1
    if cnt == m:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
typedef std::pair<int, int> P;
int INF = 1e9;
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int main(){
    while(1){
        int w, h;
        std::cin >> w >> h;
        if(w == 0 && h == 0) break;
        std::vector<std::vector<int>> hori(h, std::vector<int>(w -1));
        std::vector<std::vector<int>> ver(h - 1, std::vector<int> (w));
        std::vector<std::vector<int>> d(h, std::vector<int> (w, INF));
        std::vector<std::vector<int>> used(h, std::vector<int> (w, 0));
        for(int i = 0; i < 2* h - 1; i++){
            if(i % 2 == 0){
                for(int j = 0; j < w - 1; j++) std::cin >> hori[i / 2][j];
            }
            else for(int j = 0; j < w; j++) std::cin >> ver[i / 2][j];
        }
        std::queue<P> q;
        q.push(P(0, 0));
        used[0][0] = 1;
        d[0][0] = 1;
        while(!q.empty()){
            P t = q.front();
            q.pop();
            for(int i = 0; i < 4; i++){
                int x = t.first + dx[i], y = t.second + dy[i];
                if(i == 0 && 0 <= x && x < h && 0 <= y && y < w && used[x][y] == 0){
                    if(ver[x][y] == 0){
                        d[x][y] = std::min(d[x][y], d[t.first][t.second] + 1);
                        used[x][y] = 1;
                        q.push(P(x, y));
                    }
                }
                else if(i == 1 && 0 <= x && x < h && 0 <= y && y < w && used[x][y] == 0){
                    if(hori[x][y] == 0){
                        d[x][y] = std::min(d[x][y], d[t.first][t.second] + 1);
                        used[x][y] = 1;
                        q.push(P(x, y));
                    }
                }
                else if(i == 2 && 0 <= x && x < h && 0 <= y && y < w && used[x][y] == 0){
                    if(ver[x - 1][y] == 0){
                        d[x][y] = std::min(d[x][y], d[t.first][t.second] + 1);
                        used[x][y] = 1;
                        q.push(P(x, y));
                    }
                }
                else if(i == 3 && 0 <= x && x < h && 0 <= y && y < w && used[x][y] == 0){
                    if(hori[x][y - 1] == 0){
                        d[x][y] = std::min(d[x][y], d[t.first][t.second] + 1);
                        used[x][y] = 1;
                        q.push(P(x, y));
                    }
                }
            }
        }
        if(d[h- 1][w - 1] == INF){
            std::cout << 0 << std::endl;
        }
        else std::cout << d[h - 1][w - 1] << std::endl;
    }
}


Measured memory_bytes: 3124
N = int(input())
 
def dfs(s):
  if int(s) > N: 
    return 0
  ret = 1 if all(s.count(c) > 0 for c in '753') else 0
  for c in '753':
    ret += dfs(s+c)
  return ret
 
print(dfs('0'))

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

int x[102];
inline int d_sum(int p, int n) {
    int sum(0);
    rep(i, n) {
        sum += (x[i] - p) * (x[i] - p);
    }
    return sum;
}
int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    rep(i, n) cin >> x[i];
    int ans = INT_MAX;
    for(int p=1; p<=100; p++) {
        int cost = d_sum(p, n);
        ans = min(ans, cost);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/*input
5 2
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}



int main()
{
	//IOS;
	ll n,x;
	cin>>n>>x;
	ll ans=x;
	ll a=x,b=n; //a:short b:long

	while(a!=b){
		//cout<<a<<' '<<b<<endl;
		ll d=b-a;
		ll cnt=b/d+a/d;
		ans+=cnt*d;
		a%=d;
		b=d;
		ans+=a;
		a=d-a;
	}
	cout<<ans-a<<'\n';
	return 0;
}


Measured memory_bytes: 256
X, K, D = map(int, input().split())

if K*D<=abs(X):
    print(abs(X)-K*D)
else:
    Y = abs(X)//D
    Z = K - Y
    if Z%2==0:
        print(abs(X)-D*Y)
    else:
        print(abs(abs(X)-D*Y-D))

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


int main(void) {
  int n, m;
  cin >> n >> m;
  int l, r, maxL = 0, minR = 100005;
  rep(i, m) {
    cin >> l >> r;
    maxL = max(maxL, l);
    minR = min(minR, r);
  }

  int ans = minR - maxL + 1;
  ans = minR < maxL ? 0 : ans;

  cout << ans << endl;

  return 0;
}

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

main(){
	string s;
	cin >> s;
	int ans=0;
	for(int i=0;i<s.length();i++){
		int len=0;
		while( i+len<s.length() && (s[i+len]=='A'||s[i+len]=='T'||s[i+len]=='G'||s[i+len]=='C') ){
			len++;
		}
		if(ans<len){
			ans=len;
		}
	}
	cout << ans <<endl;
}


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

int main(){
	int n, sum, s1, s2, c;
	c = 0;
	while(1){
		cin >> n >> sum;
		if(n == 0 && sum == 0) break;
		for(int z = 1; z <= n - 2; z++){
			s1 = s2 = 0;
			for(int y = 1 + z + s1; y <= n - 1; y++){
				for(int x = 2 + z + s2; x <= n; x++){
					if((z + y + x) == sum) c++;
				}
			s2++;
			}
		s1++;
		}
		cout << c << endl;
		s1 = s2 = c = 0;
	}
	return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		char[] X = sc.next().toCharArray();
		char[] next = new char[N];
		int D = sc.nextInt();
		for(int i = 0; i < N; i++) {
			if(D != 0 && X[i] == '0') {
				next[i] = '1';
				D--;
			}
			else {
				next[i] = X[i];
			}
		}
		for(int i = N-1; i >= 0; i--) {
			if(D != 0 && X[i] == '1') {
				next[i] = '0';
				D--;
			}
			
		}
		
		System.out.println(String.valueOf(next));
	}
}
		
		
		
		

Measured memory_bytes: 26320
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long ll;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/***********************************************************************/


int mul(int a, int b){
  return 1LL * a * b % MOD;
}
int pow(int a, int b){
  int re = 1;
  while(b){
    if(b&1)re = mul(re , a);
    a = mul(a, a);
    b >>= 1;
  }
  return re;
}
int ncr(int n, int r){
  int ans = 1;
  for(int x = 0; x<r; x++){
    ans = mul(ans, n - x);
    ans = mul(ans, pow(r - x, MOD -2));
  }
 return ans;
}
int sub(int a, int b){
  if(a >= b)return a - b;
  return MOD +a - b;
}
void solve_case() {
  int ans;
  int n, a , b;
  cin >> n >> a >> b;
  (ans =  sub( pow(2, n) ,  1 ));
  // ans = (ans + MOD)% MOD;
  ans = sub(ans,  ncr(n , a));
  ans = sub(ans, ncr(n, b));
  cout << ans;

}

/**************/


int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
 
  int tt = 1;
  // cin >> tt;
  while (tt--) {
    solve_case();
  } 
}




Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

H, W = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(H)]
ans = []

for i in range(H):
    if i % 2 == 0:
        for j in range(W - 1):
            if X[i][j] % 2 == 1:
                X[i][j] -= 1
                X[i][j + 1] += 1
                ans.append((i + 1, j + 1, i + 1, j + 2))

        if X[i][-1] % 2 == 1 and i < H - 1:
            X[i][-1] -= 1
            X[i + 1][-1] += 1
            ans.append((i + 1, W, i + 2, W))
    else:
        for j in reversed(range(1, W)):
            if X[i][j] % 2 == 1:
                X[i][j] -= 1
                X[i][j - 1] += 1
                ans.append((i + 1, j + 1, i + 1, j))

        if X[i][0] % 2 == 1 and i < H - 1:
            X[i][0] -= 1
            X[i + 1][0] += 1
            ans.append((i + 1, 1, i + 2, 1))

print(len(ans))
for t in ans:
    print(*t)


Measured memory_bytes: 92948
#include <iostream>
#include <climits>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

int main() {
	int n, w;
	cin >> n >> w;
	vector<pair<long long, long long>> items(n);			// First Means Value Second Means Weight
	for (auto& item : items)
		cin >> item.first >> item.second;

	vector<vector<long long>> dp(n + 1, vector<long long>(w + 1));
	for (int i = 0; i <= n; i++) {				// Here i represents ith item To Consider
		for (int j = 0; j <= w; j++) {			// Here j means Value You Can Get In j Weight Bag
			if (i == 0 || j == 0) {
				dp[i][j] = 0;
			}
			else if (items[i - 1].first <= j)
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - items[i - 1].first] + items[i - 1].second);
			else
				dp[i][j] = dp[i - 1][j];
			// cout << dp[i][j] << " ";
		}
		// cout << endl;
	}
	cout << dp[n][w] << endl;
	return 0;
}

Measured memory_bytes: 80256
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{	
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String []s=br.readLine().split(" ");
		
		long N=Long.parseLong(s[0]);
		long K=Long.parseLong(s[1]);
		
		out.println(min(N%K, abs(K-(N%K))));
			
		
		
	}
	
	
}




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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d,e;
  string s,ss;
  cin>>a;
  bool used[1000100]={};
  used[a]=true;
  for(int i=1;i<=1000000;i++){
    if(a%2){
      a=3*a+1;
    }else{
      a/=2;
    }
    if(used[a]){cout<<i+1<<endl;break;}
    used[a]=true;
  }

  return 0;
}


Measured memory_bytes: 1280