akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w, k, ans = 0, ct = 0;
  cin >> h >> w >> k;
  char c[h][w];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      cin >> c[i][j];

  for (int tmp = 0; tmp < (1 << (h + w)); tmp++) {
    bitset<12> s(tmp);
    ct = 0;
    int a[h][w];
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        a[i][j] = c[i][j];

    for (int i = 0; i < h; i++)
      if (s[i] == 1)
        for (int j = 0; j < w; j++)
          a[i][j] = 'r';
    for (int i = h; i < (h + w); i++)
      if (s[i] == 1)
        for (int j = 0; j < h; j++)
          a[j][i-h] = 'r';
    for (int i = 0; i < h; i++)
      for (int j = 0; j < w; j++)
        if (a[i][j] == '#')
          ct++;
    if (ct == k)
      ans++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>

using namespace std;

int main(){

	map<string,set<int> > ls;
	string s;
	int num;
	while(cin>>s>>num){
		ls[s].insert(num);
	}
	for(map<string,set<int> >::iterator it = ls.begin(); it != ls.end(); it++){
		cout<<it->first<<endl;
		for(set<int>::iterator iit = (it->second).begin(); iit != (it->second).end();){
			cout<<*iit;
			if(++iit==(it->second.end())){
				cout<<endl;
			}
			else
				cout<<" ";
		}
	}

	return 0;
}

Measured memory_bytes: 0
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	ll MOD = 1e9 + 7;
	int n; cin >> n;
	string u, d; cin >> u >> d;
	int now;
	ll res;
	bool tate;
	if (u[0] == d[0])
	{
		res = 3;
		now = 1;
		tate = true;
	}
	else
	{
		res = 6;
		now = 2;
		tate = false;
	}
	while (now < n)
	{
		if (tate)
		{
			res *= 2;
			res %= MOD;
			if (u[now] == d[now])++now;
			else
			{
				now += 2;
				tate = false;
			}
		}
		else
		{
			if (u[now] == d[now])
			{
				++now;
				tate = true;
			}
			else
			{
				now += 2;
				res *= 3;
				res %= MOD;
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll n, m;
vector<vector<ll>> g;
void bfs(ll s, vector<ll> &loop, ll & mi){

    queue<ll> q;
    q.push(s);

    vector<int> visited(n, 0);
    vector<ll> prev(n, 0);
    prev[s] = -1;
    bool fin = false;
    while(!q.empty()){
        ll now = q.front();
        q.pop();
        visited[now] = 1;
        rep(i, g[now].size()){
            ll next = g[now][i];
            if(next == s){
                prev[next] = now;
                fin = true;
                break;
            }
            if(visited[next]) continue;
            prev[next] = now;
            visited[next] = 1;
            q.push(next);
        }
        if(fin) break;
    }

    if(!fin){
        return;
    }

    vector<ll> tmp;
    ll now = s;
    while(true){
        now = prev[now];
        tmp.push_back(now);
        if(now == s) break;
    }

    if(tmp.size() < mi){
        loop = tmp;
        mi = tmp.size();
    }

    return;
}
int main(void){
    cin >> n >> m;
    g.resize(n);
    rep(i, m){
        ll a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
    }

    vector<ll> loop;
    ll mi = INF;

    rep(i, n){
        bfs(i, loop, mi);
    }
    if(mi >= INF){
        cout << -1 << endl;
        return 0;
    }
    cout << mi << endl;
    rep(i, loop.size()){
        cout << loop[i] + 1 << endl;
    }
}



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

using namespace std;

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

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

    int ans = 0;
    rep(i,n){
        int h;
        cin >> h;
        if( h >= k ) ans++;
    }

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

Measured memory_bytes: 256
using System;

public class Test
{
	public static void Main()
	{
		// your code goes here
		while(true) {
			string[] s = Console.ReadLine().Split(' ');
			var H = int.Parse(s[0]);
			var W = int.Parse(s[1]);
			
			if( (H == 0) && (W == 0) )	break;
			
			string line1 = new string('#', W);
			string line2 = "#" + new string('.', W-2) + "#";
			
			Console.WriteLine(line1);
			for(int i = 0; i < H-2; i++) {
				Console.WriteLine(line2);
			}
			Console.WriteLine(line1);
			
			Console.WriteLine();
		}
	}
}

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

int main() {
  int a,b;
  int ans;
  cin >> a >> b;
  int sum = a+b;
  int mul = a*b;
  int sub = a-b;
  if(sum >= mul){
    ans = sum;
  }else{
    ans = mul;
  }
  if(ans >= sub){
    cout << ans << endl;
  }else{
    cout << sub << endl;
  }

}


Measured memory_bytes: 256
unittest
{
	assert( [ "3", "1 2 3" ].solve == 6 );
	assert( [ "10", "3 1 4 1 5 9 2 6 5 3" ].solve == 237 );
	assert( [ "10", "3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820" ].solve == 103715602 );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	
	auto bs = new long[ 60 ];
	foreach( a; as )
	{
		foreach( i, ref b; bs )
		{
			if( a & ( 1L << i ) ) b++;
		}
	}
	
	const M = 10L ^^ 9 + 7;
	auto ans = ModWorld!M( 0L );
	foreach( k, a; as )
	{
		n--;
		foreach( i, ref b; bs )
		{
			auto j = 1L << i;
			if( a & j )
			{
				b--;
				ans += j * ModWorld!M( n - b );
			}
			else
			{
				ans += j * ModWorld!M( b );
			}
		}
	}
	return ans;
}

// モジュラ整数型（n mod M）
struct ModWorld( long M )
{
	long n;
	
	this( long n ){ this.n = n % M; }
	void opUnary( string OP )() if( OP == "++" ){ this.n = ( this.n + 1 ) % M; }
	void opUnary( string OP )() if( OP == "--" ){ this.n = ( this.n + M - 1 ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "+"  ){ this.n = ( this.n + r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "-"  ){ this.n = ( this.n + M - r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "*"  ){ this.n = ( this.n * r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "/"  ){ this *= r ^^ ModWorld( M - 2 ); }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "^^" )
	{
		auto a = this.n;
		this.n = 1L;
		for( auto i = r.n; 0 < i; i >>= 1 )
		{
			if( i & 1 ) this.n = ( this.n * a ) % M;
			a = ( a * a ) % M;
		}
	}
	auto opBinary( string OP )( ModWorld r ){ auto l = this; l.opOpAssign!OP( r ); return l; }
	auto opEquals( ModWorld r ){ return this.n == r.n; }
	
	void opAssign( long r ){ this.n = r % M; }
	void opOpAssign( string OP )( long r ){ this.opOpAssign!OP( ModWorld( r ) ); }
	auto opBinary( string OP )( long r ){ return this.opBinary!OP( ModWorld( r ) ); }
	auto opBinaryRight( string OP )( long l ){ return ModWorld( l ).opBinary!OP( this ); }
	auto opEquals( long r ){ return this.n == r; }
	
	auto toString(){ return this.n.to!string; }
}


Measured memory_bytes: 23972
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;
typedef string tring;

lint N, M, V, P, arr[100000];
map<lint, lint> st;
map<lint, lint> ed;
bool check(lint i) {
	if (P >= st[i] + 1) return false;
	else if (arr[P - 1] > i + M) return true;
	lint safe = (P - 1 + N - st[i]) * M;
	for (int j = P - 1; j < st[i]; j++) {
		safe += min(M, i + M - arr[j]);
	}
	return safe < M * V;
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> M >> V >> P;
	lint maxv = 0;
	REP(i, N) {
		cin >> arr[i];
		chmax(maxv, arr[i]);
	}
	sort(arr, arr + N, greater<lint>());
	REP(i, N) {
		if (st.find(arr[i]) == st.end()) st[arr[i]] = i;
		chmax(ed[arr[i]], i);
	}
	st[0] = N - 1;
	ed[0] = N - 1;

	lint lb = -1, ub = N;
	while (ub - lb > 1) {
		lint mid = (lb + ub) / 2;
		if (!check(arr[mid])) lb = mid;
		else ub = mid;
	}
	cout << ed[arr[lb]] + 1 << endl;
}


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

int main(){
	int m1,d1,m2,d2;
	cin >> m1 >> d1;
	cin >> m2 >> d2;
	int ans = 1;
	
	if(m1==12){
		if(m2!=1) ans = 0;
	}else{
		if(m1+1!=m2) ans = 0;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef string::const_iterator State;

int number(State &begin);
int factor(State &begin);
int term(State &begin);
int expression(State &begin);

int expression(State &begin) {
  int ret = term(begin);
  for (;;) {
    if (*begin == '+') {
      begin++;
      ret += term(begin);
    } else if (*begin == '-') {
      begin++;
      ret -= term(begin);
    } else {
      break;
    }
  }
  return ret;
}

int term(State &begin) {
  int ret = factor(begin);
  for (;;) {
    if (*begin == '*') {
      begin++;
      ret *= factor(begin);
    } else if (*begin == '/') {
      begin++;
      ret /= factor(begin);
    } else {
      break;
    }
  }
  return ret;
}

int factor(State &begin) {
  int ret = 0;
  if (*begin == '(') {
    begin++;
    ret = expression(begin);
    begin++;
    return ret;
  } else {
    ret = number(begin);
  }
  return ret;
}

int number(State &begin) {
  int ret = 0;
  while (isdigit(*begin)) {
    ret *= 10;
    ret += *begin - '0';
    begin++;
  }
  return ret;
}

int main() {
  int N;
  cin >> N;
  cin.ignore();
  for (int i = 0; i < N; i++) {
    string s;
    getline(cin, s);
    State begin = s.begin();
    int ans = expression(begin);
    cout << ans << endl;
  }
}


Measured memory_bytes: 3104
S = input()
X,Y = map(int,input().split())

S = S+"T"
d,cnt = 0,0
pos = [set([0]),set([0])]
init = False
for s in S:
    # 前進
    if s=="F":
        cnt += 1
    # 方向転換
    else:
        # 移動先を全列挙
        if cnt>0:
            temp = set([])
            for p in pos[d]:
                temp.add(p+cnt)
                if init:
                    temp.add(p-cnt)
            pos[d] = temp
        # 方向転換
        d = (d+1)%2
        cnt = 0
        # 初回の方向転換を終えたかどうか
        init = True

print("Yes" if X in pos[0] and Y in pos[1] else "No")

Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int n=s.length();
  if(s[n-1]=='s')
  {
    cout<<s<<"es"<<endl;
  }
  else
  {
   	cout<<s<<"s"<<endl;
  } 
  return 0;
}


Measured memory_bytes: 3624
fun gcd2(a:Int, b:Int):Int {
    if (a < b) {
        return gcd2(b,a)
    }
    if (b == 0) {
        return a
    }
    return gcd2(b, a % b)
}

fun gcd(a:Int, b:Int, c:Int):Int {
    return gcd2(gcd2(a,b), c)
}

fun main() {
    val K:Int = readLine()!!.toInt()
    var ans:Int = 0
    for (a in 1..K) {
        for (b in 1..K) {
            for (c in 1..K) {
                ans += gcd(a,b,c)
            }
        }
    }
    println(ans)
}

Measured memory_bytes: 36136
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

const int INF = 1e9+5;
const ll LINF = 1e18;

int main(){
 ll n;
 ll res=0;
 cin >> n;
 for(int i=1;i*i<=n;i++){
   chmax(res,i*i);
 }
 cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
     
     
    int main(){
    	long long n,sum=0;
    	cin >> n;
    	vector<long long> v(n+3,0);
    	for(int i=0;i<n;i++){
    		cin >> v[i+1];
    	}
    	
    	for(int i=1;i<v.size()-1;i++){
    		sum+=v[i-1]/2;
    		v[i-1]%=2;
    		if(v[i-1]&&v[i]){
    			v[i-1]--;
    			v[i]--;
    			sum++;
    		}
    	}
    	cout << sum << endl;
    	return 0;
    }

Measured memory_bytes: 1024
def gi() gets.to_i end
def gs() gets.chomp end
def gim() gets.split.map(&:to_i) end
def gsm() gets.split.map(&:chomp) end
def YesNo1(bool, yes="Yes", no="No") puts (bool ? yes : no) end
def YESNO2(bool, yes="YES", no="NO") puts (bool ? yes : no) end
def sqrt(i) i ** (1.0/2) end

require "bigdecimal"
#####

a,b,c = gets.split.map{|str| BigDecimal(str)}
YesNo1(a.sqrt(200) + b.sqrt(200) + BigDecimal("0.0000000000000000000000001") < c.sqrt(200))

Measured memory_bytes: 1916
#include<iostream>
#include<vector>
#include<iomanip>

using namespace std;

int main(){
  int n;
  cin>>n;
  double sum=0;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    sum+=1.0/(double)a;
  }
  cout<<fixed<<setprecision(10)<<1.0/sum<<endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class _C
{
	void _()
	{

		var n = _Ns();

		int N = n[0];

	

		Console.WriteLine(N*(N+1)/2);
		
	}

	static void Main(string[] args)
  {
    new _C()._();
  }

  #region

  string _S()
  {
    return Console.ReadLine();
  }

  string[] _Ss()
  {
    return Console.ReadLine().Split();
  }

  int[] _N(int n)
  {
    var x = new int[n];
    for (var i = 0; i < n; i++)
    {
      x[i] = int.Parse(Console.ReadLine());
    }
    return x;
  }

  int[] _Ns()
  {
    var ss = Console.ReadLine().Split();

    var x = new int[ss.Length];
    for (var i = 0; i < ss.Length; i++)
      x[i] = int.Parse(ss[i]);

    return x;
  }
  #endregion
}


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

using namespace std;

void test_case()
{
    int n;
    cin>>n;
    map<string,int>mp;
    string s;
    int ans=0;
    while(n--)
    {
        cin>>s;
        if(mp.count(s)==0){
            ans++;
            mp[s]=1;
        }
    }
    printf("%d\n",ans);
}

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


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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pii pair<ll, ll>
#define sz size()

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>void __f(const char* name, Arg1&& arg1){cout<<name<<" : "<<arg1<<"\n";}
template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args)
{const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" , ";__f(comma+1, args...);} 
#define traceloop(x,a) { cerr<<#a<<": "; for(ll ix=0;ix<x;ix++) cerr<<a[ix]<<" "; cerr<<endl; }

int main()
{
	ios::sync_with_stdio(0);
	int i, n, j, k;
	cin>>n;
	int a[n+5][3];
	int dp[n+5][3];

	memset(dp, 0, sizeof dp);
	memset(a, 0, sizeof a);

	for(i=1;i<n+1;++i)
		cin>>a[i][0]>>a[i][1]>>a[i][2];

	for(i=1;i<n+1;++i)
	{
		for(j=0;j<3;++j)
		{
			for(k=0;k<3;++k)
			{
				if(k != j)
					dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i][j]);
			}
		}
	}

	cout << max(max(dp[n][0], dp[n][1]), dp[n][2])<<"\n";

	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 5e+5+5;

int n,q,D;
int d[N];
int A[N],B[N];

int main(){
	n=get();D=get();
	fo(i,0,n-1)d[i]=get();
	A[0]=D;
	fo(i,1,n)A[i]=min(abs(A[i-1]-d[i-1]),A[i-1]);
	B[n]=1;
	fd(i,n-1,0){
		if (B[i+1]<=d[i]/2)B[i]=B[i+1];
		else B[i]=B[i+1]+d[i];
	}
	q=get();
	fo(i,1,q){
		int x=get();
		if (A[x-1]>=B[x])printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

int N;
double p, dp[2][3000], ans;

int main()
{
    scanf("%d", &N);
    dp[0][0] = dp[1][0] = 1.0;
    for (int i = 1; i <= N; i++)
    {
        scanf("%lf", &p);
        dp[i%2][0] = (1-p)*dp[(i+1)%2][0];
        for (int j = 1; j <= N; j++)
        {
            dp[i%2][j] = p*dp[(i+1)%2][j-1] + (1-p)*dp[(i+1)%2][j];
        }
    }
    for (int i = N/2 + 1; i <= N; i++)
    {
        ans += dp[N%2][i];
    }
    printf("%.9lf\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int dig_sum(int num){
  int ans=0;
  while(num >0){
    ans+=(num%10);
    num /=10;
  }
  return ans;
}

int main(){
  int N,A,B;
  
  int ans=0;

  cin >> N >> A >>B;

  for(int i=1;i<=N;i++){
    int temp=dig_sum(i);
    //cout << temp<<endl; 
    if(temp>=A&&temp<=B){
      ans+=i;
      //cout<<temp<<endl;
    }
  }

  cout<<ans<<endl;

  return 0;

}


Measured memory_bytes: 256
S = input()
T = input()

length = len(S)

ans = 0
pre = -1

for t in T:
    x = S.find(t, pre+1, length)
    if x != -1:
        ans += x - pre
        pre = x
    else:
        x = S.find(t, 0, pre+1)
        if x != -1:
            ans += length + x - pre
            pre = x
        else:
            ans = -1
            break

print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int L;
	cin >> L;
	double base = (double)L / 3.0;
	cout << fixed << setprecision(7) << base*base*base << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    vector<int> a, ans(n+1, 0);
    a.push_back(0);
    rep(i, n){
        int x;
        cin >> x;
        a.push_back(x);
    }
    for(int i=n;i>=1;i--){
        ans[i] ^= a[i];
        if(i!=1&&ans[i]){
          for (int j = 1; j * j <= i; j++) {
              if(i%j==0){
                if (j != 1 && j * j != i) {
                  ans[j] ^= 1;
                  ans[i / j] ^= 1;
                } else {
                  ans[j] ^= 1;
                }
              }
          }
        }
    }
    int m=0;
    vector<int> res;
    rep2(i, 1, n+1){
        if(ans[i]){
            m++;
            res.push_back(i);
        }
    }
    cout << m << endl;
    int len = res.size();
    rep(i, len){
        cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define mem(s,t) memset(s,t,sizeof(s))
#define pb(s) push_back(s)
#define inf 0x3f3f3f3f
#define mn 100010
typedef long long ll;
using namespace std;

int a[510][510];

void work(int l,int r,int k)
{
    if (l>=r) return;
    int i,j,mid=(l+r)/2;
    for (i=l;i<=mid;i++)
    for (j=mid+1;j<=r;j++)
        a[i][j]=a[j][i]=k;
    work(l,mid,k+1);
    work(mid+1,r,k+1);
}

int main()
{
    int n,i,j;
    cin>>n;
    work(1,n,1);
    for (i=1;i<n;i++)
    {
        for (j=i+1;j<n;j++)
            printf("%d ",a[i][j]);
        printf("%d\n",a[i][n]);
    }
    return 0;
}



Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

int main() {
    int n,k;
    cin >> n >> k;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    rep(j,k) {
        vector<int>b(n+1);
        rep(i,n) {
            int l = max(0,i-a[i]);
            int r = min(n,i+a[i]+1);
            b[l]++;b[r]--;
        }
        rep(i,n) {
            b[i+1] += b[i];
        }
        b.pop_back();
        if(a==b) break;
        a = b;
    }    
    rep(i,n) cout << a[i] << " ";
    cout << endl;
    
}

Measured memory_bytes: 4824
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <bitset>
using namespace std;

long long calc(long long a){
	long long cnt = (a + 1) / 2;
	long long ans = cnt % 2;
	if(a % 2 == 0) ans ^= a;
	return ans;
}

int main() {
	long long A, B;
	cin >> A >> B;
	long long ans = calc(B) ^ calc(A-1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{
  ll n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  string s;cin >> s;
  a--;
  b--;
  c--;
  d--;

  bool flg_cont = false;  //連続
  bool flg_chg = c > d;
  bool flg_tri = false;

  // 2連続いわのばしょがあるかチェック
  ll cnt_rock = 0;
  for(ll i = a; i <= max(c,d); ++i)
  {
    if(s[i] == '#')
    {
      cnt_rock++;
    }
    else
    {
      cnt_rock = 0;
    }
    
    if(cnt_rock == 2)
    {
      flg_cont = true;
      break;
    }
  }

  // 3連続の場所があるかチェック
  ll cnt_agola = 0;
  for(ll i = b-1; i <= d + 1; ++i)
  {
    if(s[i] == '.')
    {
      cnt_agola++;
    }
    else
    {
      cnt_agola = 0;
    }

    if(cnt_agola > 2)
    {
      flg_tri = true;
      break;
    }
  }

  bool ans = false;
  if(!flg_chg)
  {
    ans = true;
  }
  else
  {
    if(flg_tri)
    {
      ans = true;
    }
  }

  if(flg_cont) ans = false;

  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  

  

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
 
using namespace std;
 
int main(){
  int n, i;
	cin >> n;
  int a[n-1];

  int order;

  for (i=0; i<n; i++){
    cin >> order;
    a[order-1] = i+1;
  }

  for (i=0; i<n; i++){
    printf("%d ", a[i]);
  }

	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long int sum = 0;
	for(int i=1;i<=n;i++)
	{
		long long int y = floor(n/i);
		long long int p = (y*(y+1));
		long long int x = (p/2)*i;
		sum+=x;
	}
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
#define mod 1e9+7

int main(){
      ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0);    
    
     int x,y;
        cin>>x>>y;
        int i=1;
        while(i<10009 )
        {  //cout<<i<<endl;
             if( ((int)((i*8)/100) )==x  &&  ((int)((i*10)/100))==y  ){
                cout<<i<<endl;
                return 0;
             
             }
             i++;
        }
        cout<<-1<<endl;
        return 0;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define all(x) x.begin(), x.end()
using ll = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> l(m), r(m);
    vector<ll> c(m);
    rep(i,0,m) {
        cin >> l[i] >> r[i] >> c[i];
        --l[i];
        --r[i];
    }
    vector<vector<pair<int,ll>>> g(n);
    rep(i,1,n) g[i].emplace_back(i-1,0);
    rep(i,0,m) g[l[i]].emplace_back(r[i],c[i]);
    const ll INFTY = LLONG_MAX;
    vector<ll> dist(n,INFTY);
    using T = pair<ll,int>;
    priority_queue<T,vector<T>,greater<T>> pq;
    pq.emplace(0,0);
    while(!pq.empty()) {
        ll d;
        int u;
        tie(d,u) = pq.top();
        pq.pop();
        if(d<dist[u]) {
            dist[u] = d;
            for(const auto &e:g[u]) {
                pq.emplace(d+e.second, e.first);
            }
        }
    }
    ll ans = dist[n-1];
    if(ans==INFTY) ans = -1;
    cout<<ans<<endl;
}


Measured memory_bytes: 12280
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
d = [[0]*3 for _ in range(3)]

for  _ in range(N):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if A[i][j] == b:
        d[i][j] = 1
        
ans = "No"
 
for i in range(3):
  if sum(d[i]) == 3:
    ans = "Yes"
    break
  if sum([D[i] for D in d]) == 3:
    ans = "Yes"
    break
if sum([d[i][i] for i in range(3)]) == 3:
  ans = "Yes"
 
if sum([d[i][2 - i] for i in range(3)]) == 3:
  ans = "Yes"
  
print(ans)
 

Measured memory_bytes: 3064
n=gets.to_i
as=n.times.map{gets.to_i}.sort
ans=0
cur=1
(n-1).times do |i|
  if as[i]==as[i+1]
    cur+=1
  else
    ans+=1 if cur.odd?
    cur=1
  end
end
ans+=1 if cur.odd?
puts ans


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

int main(){
  ll D, G;
  cin >> D >> G;
  vector<pair<ll, ll>> pc(D);
  rep(i, D){
    cin >> pc[i].first >> pc[i].second;
  }

  ll sum, solve;
  ll ans = pow(10, 9);
  for(int bit = 0; bit < (1 << D); bit++){
    sum = 0;
    solve = 0;
    for(int i = 0; i < D; i++){
      if(bit & (1 << i)){
        //フラグが立っている場合
        sum += 100 * (i + 1) * pc[i].first + pc[i].second;
        solve += pc[i].first;
      }
    }
    if(sum >= G){
      ans = min(ans, solve);
    }else{
      for(int i = D-1; i >= 0; i--){
        if(bit & (1 << i)){
          //足し合わせをした場合
          continue;
        }else{
          for(int j = 0; j < pc[i].first; j++){
            if(sum >= G) break;
            //配点の高い問題をたす
            sum += 100 * (i+1);
            solve++;
          }
        }
      }
    }
    ans = min(ans, solve);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	ll a1,a2,b1,b2;
	cin>>a1>>a2>>b1>>b2;
	ll ans=-1e18;
	ans=max(ans,a1*b1);
	ans=max(ans,a1*b2);
	ans=max(ans,a2*b1);
	ans=max(ans,a2*b2);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3640
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

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

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

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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

long long  n, k;
string s;
vector<vector<vector<long long >>> memo;

long long  func(long long  i, long long  j, bool flg) {
	if (i == n) {
		if (j == k) return 1;
		return 0;
	}

	if (j > k) return 0;

	if (memo[i][j][flg] != -1) return memo[i][j][flg];

	long long  res = 0;
	if (flg == false) {
		for (long long  dig = 0; dig <= 9; dig++) res += func(i + 1, j + (dig != 0), false);
	}
	else {
		res = func(i + 1, j + ((s[i] - '0') != 0), true);
		for (long long  dig = 0; dig < (s[i] - '0'); dig++) res += func(i + 1, j + (dig != 0), false);
	}

	return memo[i][j][flg] = res;
}

int main() {

	cin >> s;
	n = s.length();
	cin >> k;
	memo.resize(n, vector<vector<long long >>(k + 1, vector<long long >(2, -1)));

	cout << func(0, 0, true);
	return 0;
}

Measured memory_bytes: 3172
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    };

    let a_i_max = 1_000_000;
    let mut map = std::collections::BTreeMap::new();
    for &a_i in a.iter() {
        *map.entry(a_i).or_insert(0) += 1;
    }

    let mut b = vec![true; a_i_max + 1];
    let mut x = vec![];
    for (&a_i, &count) in map.iter() {
        if b[a_i] {
            x.push((a_i, count));
            for j in (a_i + a_i..=a_i_max).step_by(a_i) {
                b[j] = false;
            }
        }
    }

    let ans = x.iter().filter(|&&(_, count)| count == 1).count();
    println!("{}", ans);
}


Measured memory_bytes: 13760
namespace Coder {
  class Scanner {
    private buffer: string = '';
    private stdinQueue: any = [];

    constructor() {
      process.stdin.resume();
      process.stdin.setEncoding('utf8');
      process.stdin.on(
        'data',
        (chunk): void => {
          this.buffer += chunk;
          while (this.stdinQueue.length > 0) {
            const i = this.buffer.indexOf('\n');
            if (i < 0) {
              break;
            }
            let line = this.buffer.substr(0, i);
            if (line.endsWith('\r')) {
              line = line.slice(0, -1);
            }
            this.buffer = this.buffer.substr(i + 1);
            this.stdinQueue.shift()(line);
          }
        },
      );
    }
    public getLine(): Promise<string> {
      return new Promise((resolve, reject) => {
        const i = this.buffer.indexOf('\n');
        if (i >= 0 && this.stdinQueue.length === 0) {
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          resolve(line);
        } else {
          this.stdinQueue.push(resolve);
        }
      });
    }

    public close(): void {
      process.stdin.pause();
    }
  }

  async function solve() {
    const sc = new Scanner();
    const S = await sc.getLine();
    let ans = 0;
    for (let i = 0; i < S.length; i += 1) {
      for (let j = i; j < S.length; j += 1) {
        const t = S.substr(i, S.length - j);
        if (t.match(/[^AGCT]/) === null) {
          ans = Math.max(ans, t.length);
        }
      }
    }
    console.log(ans);
    sc.close();
  }

  solve();
}


Measured memory_bytes: 7628
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>
#include <time.h>
#include <random>

using namespace std;

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

long long int INF = 3e18;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←


#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pd(x) cerr<<"//"<<(x)<<endl;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl


ll mod = 998244353;
ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}

ll n,m,num,sum,ans,a,b,c,d,e,g,h,w,i,j,k,q,l,r;
ll x[500005],y[500005],z[500005];
//bool check[5005];
char s[500005],t[500005];
bool flag,dame;

ll  fact[400005];
ll rfact[400005];
ll dp1[305][90005],dp2[305][90005];
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<400000; i++){
        fact[i] = (fact[i-1]*i) % mod;
        rfact[i] = rui(fact[i],mod - 2);
    }
}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod) * rfact[n-r]) % mod;
}

int main(){
	cin >> n;
	for(i=1;i<=n;i++){
		cin >> x[i];
		sum += x[i];
	}
	//sort(x,x+n);
	dp1[0][0] = 1;
	dp2[0][0] = 1;
	for(i=1;i<=n;i++){
		for(j=0;j<=sum;j++){
			dp1[i][j] += dp1[i-1][j] * 2;
			dp2[i][j] += dp2[i-1][j];
			if(j-x[i] >= 0){
				dp1[i][j] += dp1[i-1][j-x[i]];
				dp2[i][j] += dp2[i-1][j-x[i]];
			}
			dp1[i][j] %= mod;
			dp2[i][j] %= mod;
		}
	}
	//p(sum);
	for(i=1;i<=n;i++){
		for(j=0;j<=sum;j++){
		//	pe(dp1[i][j]);
		}
		//el;
	}
	ans = 0;
	for(i=sum;;i--){
		if(i * 2 < sum)break;
		ans += dp1[n][i];
		ans %= mod;
	}
	if(sum % 2 == 0){
		ans += (mod - dp2[n][sum/2]);
	}
	//p(ans);
	ans = rui(3,n) + 3 * (mod - ans);
	//p(rui(3,n));
	ans %= mod;
	p(ans);
	return 0;
}


Measured memory_bytes: 454528
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int main(void){
	std::string s,c1,c2,c3;
  	cin >> s;
  	int a,b,c,d,i,sum;
  	a = stoi(s.substr(0,1));
  	b = stoi(s.substr(1,1));
  	c = stoi(s.substr(2,1));
  	d = stoi(s.substr(3,1));
  	for (i=1;i<100;i++){
    	sum = a + ((int)(pow(-1,i)))*b + ((int)(pow(-1,i/2)))*c + ((int)(pow(-1,i/3)))*d;
        if (sum==7){
        	if((int)(pow(-1,i)) == 1){
            	c1 = "+";
            }else{
            	c1 = "-";
            }
          	if((int)(pow(-1,i/2)) == 1){
            	c2 = "+";
            }else{
            	c2 = "-";
            }
          	if((int)(pow(-1,i/3)) == 1){
            	c3 = "+";
            }else{
            	c3 = "-";
            }
          	cout << a << c1 << b << c2 << c << c3 << d << "=" << 7;
          	return 0;
        }
    }
}

Measured memory_bytes: 256
def check(A, mid, K):
    return A[mid] <= K


def binMax(A, K):
    ok = -1  # maxVal when minimize
    ng = len(A)  # maxVal when maximize
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(A, mid, K):
            ok = mid
        else:
            ng = mid
    return ok


def resolve():
    N, M, K = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    presumA = [0 for _ in range(N + 1)]
    for i in range(N):
        presumA[i + 1] = presumA[i] + A[i]
    presumB = [0 for _ in range(M + 1)]
    for i in range(M):
        presumB[i + 1] = presumB[i] + B[i]
    startA = binMax(presumA, K)
    maxA = 0
    for ai in range(startA, -1, -1):
        maxA = max(maxA, ai + binMax(presumB, K - presumA[ai]))
    print(maxA)

resolve()


Measured memory_bytes: 48436
program ccc
implicit none

integer :: n, m, i, j, k, l, sw, res
integer,dimension(10) ::  kk, p, switch, counter
integer,dimension(10,10) :: s
logical :: ch

kk=0
p=0
s=0
res=0

read*, n, m
do i=1,m
read*, kk(i), s(1:kk(i),i)
end do
read*, p(1:m)

do i=0,2**n-1
switch=0
sw=0
 
 do j=0,n-1
  if(btest(i,j)) then
  sw=sw+1
  switch(sw)=j+1
  end if
 end do
  
 counter=0
 
 do j=1,m
  do k=1,10
  if(s(k,j)==0) exit 
   do l=1,sw
    if(s(k,j)==switch(l)) then
    counter(j)=counter(j)+1
    exit
    end if
   end do
  end do
 end do

 ch=.True.

 do j=1,m
  if(mod(counter(j),2)/=p(j)) then
  ch=.False.
  exit
  end if
 end do
 if (ch) res=res+1
end do

write(*,'(i0)') res

end program

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define INF (500000)
using namespace std;

int array[20000];

int main()
{
	int N;
	while (scanf("%d", &N), N){
		memset(array, 0, sizeof(array));
		
		for (int i = 1; i <= N; i++){
			scanf("%d", &array[i]);
		}
		
		int mini = INF;
		
		for (int i = 1; i <= N; i++){
			for (int j = 0; j < 2; j++){
				array[i] = array[i] % 3 + 1;
				
				int u = i;
				int d = i;
				int color;
				int cnt = 4;
				int sum = 0;
				
				while (cnt >= 4) {
					if (sum == 0){
						cnt = 1;
					}
					else {
						cnt = 0;
					}
					
					if (array[d + 1] == 0){
						break;
					}
					
					color = array[d + 1];
					
					while (array[u - 1] == color){
						u--;
						cnt++;
					}
					while (array[d + 1] == color){
						d++;
						cnt++;
					}
					
					if (cnt >= 4){
						sum += cnt;
					}
					else {
						break;
					}
				}
				
				mini = min(mini, N - sum);
			}
			
			array[i] = array[i] % 3 + 1;
		}
		
		printf("%d\n", mini);
	}
	
	return 0;
}

Measured memory_bytes: 1112
N, M = map(int, input().split())
ans = []
jdg = True
cnt = 0

for i in range(N):
    ans.append("#")

for i in range(M):
    s, c = map(int, input().split())
    if ans[s-1] != "#" and ans[s-1] !=c:
        jdg = False
    elif s == 1 and c ==0 and N != 1:
        jdg = False
    else:
        ans[s-1] = c

if ans[0] == "#":
    ans[0] = 1
for i in range(N):
    if ans[i] == "#":
        ans[i] = 0

for i in range(N):
    cnt += ans[i] *10**(N-1-i)
if N ==1 and M==0:
  print(0)

elif jdg: 
    print(cnt)
elif jdg == False:
    print(-1)

Measured memory_bytes: 38552
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	i64 a, b, k; scanf("%lld%lld%lld", &a, &b, &k);

	i64 tmp = std::min(a, k);
	a -= tmp;
	k -= tmp;
	b = std::max<i64>(0LL, b - k);

	printf("%lld %lld\n", a, b);
	return 0;
}


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

int main() {
    string s;
    long k;

    cin >> s >> k;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] != '1' && i + 1 <= k) {
            cout << s[i] << endl;
            return 0;
        }
    }

    cout << 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	while(true){
		scanf("%d %d",&a,&b);
		if(a == 0 && b == 0) break;
		if(a > b) printf("%d %d\n",b,a);
		else{
			printf("%d %d\n",a,b);
		}
	}
}



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

using namespace std;

using ll = long long;
using vi = vector <int>;
using vll = vector <ll>;
using vvi = vector <vi >;
using pii = pair <int, int>;
using pll = pair <long, long>;
using vpi = vector <pii >;

#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define dg(x) cout << #x << " = " << x << endl

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

    int n, d, cnt = 0;
    cin >> n >> d;
    while(n--)
    {
        ll x, y;
        cin >> x >> y;
        double a = sqrt((x * x) + (y * y));
        if (a <= d)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <vector>
#include <stack>
#include <cstring>

#define MAXN 20010
using namespace std;


int main() {
    int k, s;
    int a1, a2, cnt = 0;
    cin >> k >> s;
    {
        for (int i = 0; i <= k; i++) {
            int z = s - i;
            a1 = max(0, z - k);
            a2 = min(k, z);
            //cout<<a1<<" "<<a2<<"   ";
            if(a2-a1<0)
                continue;
            cnt += (a2-a1+1);
        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;
use std::f64::consts::PI;

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 r: usize = iterator.next().unwrap().parse().unwrap();

    let ans: f64 = 2_f64 * (r as f64) * PI;

    return ans.to_string();
}


Measured memory_bytes: 2152
#include <stdio.h> 

int main(void){ 
    int A;
    int B; 
     
    scanf("%d", &A); 
    scanf("%d", &B); 

    if(A%3 == 0 || B%3 == 0 || (A+B)%3 == 0 ){

          printf("Possible");

    }else{
    
        printf("Impossible");
  
   }

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    int count=0,count2=0,count4=0;
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        if((k&3)==0){
            count4+=1;
        }
        else if((k&1)==0){
            count2+=1;
        }
        else{
            count+=1;
        }
    }
    int ans=0;
    if(count2==n){
        ans=1;
    }
    else if(count2==0 && count4-count>=-1){
        ans=1;
    }
    else if(count2>0 && count4-count>=0){
        ans=1;
    }
    if(ans==1){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256