akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <tuple>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
typedef long long int64;
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;

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

//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

void solve() {
		int  n; cin >> n;
		vector<int> ans(n + 1);
		for (int i = 1; i <= n; ++i) {
			int num; cin >> num;
			ans[n - (n - num)] = i;
		}
		for (int i = 1; i <= n; ++i) {
			cout << ans[i] << endl;
		}
    return;
}

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



Measured memory_bytes: 1152
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val (N,M) = rd.readIntArray()
    val S = rd.readString()

    var len = 0
    var i = 0
    while (i < N) {
        var j = i+1
        var ln = 0
        while (S[j+ln] == '1') {
            ln++
        }
        i = j+ln
        len = max(len, ln)
    }
    if (len >= M) {
        println(-1)
        return
    }

    var goal = false
    val ans = ArrayList<Int>()
    var n = N
    while (true) {
        if (n <= M) {
            if (n>0) ans.add(n)
            goal = true
        }

        if (goal) break

        for (i in M downTo 1) {
            if (S[n-i] == '1') continue
            n -= i
            ans.add(i)
            break
        }
    }

    if (goal) println(ans.reversed().joinToString(" "))
    else println(-1)

    return
}


//val rd = debug.Reader("abc", "146", "f", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long, val col: Int)
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 46080
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vl a(n);
  rep(i,n)cin >> a[i];
  for(int i = n-2;i>=0;i--){
    if(a[i]>a[i+1])a[i]--;
    if(a[i]>a[i+1]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 3992
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
int s[100010];
int main(){
    int n,i,tmp,ans=0,x;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&x),s[x]++;
    for(i=0;i<=100000;i++){
        tmp=s[i]+s[i+1];
        if(i>0) tmp+=s[i-1];
        ans=max(ans,tmp);
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main(void){
  string S;
  cin >> S;
  int i;
  bool flug = true;
  for(i=0;i<(int)S.length();i++){
   if((i%2 == 0) && (S[i] == 'L')){
     flug = false;
   }else if((i%2 == 1) && (S[i] == 'R')){
    flug = false; 
   }else{
     
   }
  }
  
  if(flug == true){
   cout << "Yes" << endl; 
  }else{
   cout << "No" << endl;
  }
  
return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//以上テンプレ
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}


int main(){
    ll N,X;
    cin>>N>>X;
    vl x(N);
    rep(i,N) cin>>x.at(i);
    if(N==1){
        cout<<abs(x.at(0)-X)<<endl;;
        return 0;
    }
    sort(all(x));
    vl dis(N-1);
    rep(i,N-1) dis.at(i)=x.at(i+1)-x.at(i);
    ll a=dis.at(0);
    rep(i,N-1){
        a=__gcd(a,dis.at(i));
    }
    ll b=INF;
    rep(i,N){
        chmin(b,abs(x.at(i)-X));
    }
    a=__gcd(a,b);
    cout<<a<<endl;
    }


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    if (n == 3 || n == 5 || n == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
}



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

#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef vector<int> vi;
typedef long long int ll;
vector<vector<int>> adj;

class C {
public:
	void solve(std::istream& in, std::ostream& out) {
		ll n, y; in>>n>>y;
        ll a, b, c;
        for(a = 0; a<=2000; ++a){
            for(int b=0; b<=2000; ++b){
                ll remain = y-a*10000-b*5000;
                if(remain<0) break;
                if(remain>=0 and remain%1000==0){
                    if(a+b+(remain)/1000!=n) continue;
                    out<<a<<" "<<b<<" "<<(remain/1000);
                    return;
                }
            }
        }
        out<<"-1 -1 -1";

	}
    void inG(int m, istream& in){ int u,v; adj = vector<vi>(200005);f(i, m){ in>>u>>v; adj[u].push_back(v); adj[v].push_back(u); }}
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	C solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main()
{
  string s;
  cin >> s;
  vector<int> m(s.size(),0);
  s+='R';
  
  int gr=0;
  int gl=0;
  int sr=0;
  int sl=0;
  int si=0;
  for(int i=0;i<s.size();++i){
    if(sl>0&&s.at(i)=='R'){//清算
      if(si%2==0){
        m.at(gr)=si/2;
        m.at(gl)=si/2;
      }else if(sr%2==0){
        m.at(gr)=si/2;
        m.at(gl)=si/2+1;
      }else{
        m.at(gr)=si/2+1;
        m.at(gl)=si/2;
      }
      sr=0;
      sl=0;
      si=0;
    }else if(sl==0&&s.at(i)=='L'){
      gr=i-1;
      gl=i;
    }
    if(s.at(i)=='R'){
      ++sr;
    }else{
      ++sl;
    }
    ++si;
  }
  
  for(auto x:m){
    cout << x << " ";
  }
  return 0;
}

Measured memory_bytes: 1024
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
#define ll long long
#define M 1000000007LL
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) ((ll)v.size())
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pii pair<ll,ll> 
#define mod 1000000007
#define MAXN 300002
ll dp[MAXN][2];
int main() {
       ll t;
       ios::sync_with_stdio(0);
       cin.tie(0);
       cout.tie(0);
        ll i,n,k;
        cin>>n>>k;
       string s;
       cin>>s;
       ll j=0;
       ll ans=0;
         deque<pii>v;
         ll res=0;
        for(i=0;i<n;i++)
         {
            if(i and s[i]!=s[i-1]) {v.pb({res,res});res=0;}
            res++;
         }
         v.pb({res,res});
        // cout<<"gg"<<endl;
         if(s[0]=='0') v.push_front({0,0});

         for(i=0;i<v.size();i++)
         {
             if(i)
             v[i].S+=v[i-1].S;
              if(i%2==0)
              {
               if(i-2*k-1>0)
                ans=max(ans,v[i].S-v[i-2*k-1].S);
               else ans=max(ans,v[i].S);
              }
              else
              {
                if(i-2*k>0)
                ans=max(ans,v[i].S-v[i-2*k].S);
               else ans=max(ans,v[i].S);
              }
         }
         cout<<ans;
       return 0;
}

Measured memory_bytes: 2000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int ans;
int main(void){
    int n; cin>>n;
    string s; cin>>s;
    ans=n;
    for(int i=1;i<n;i++){
        if(s[i]==s[i-1]) ans--;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 512
n = int(input())
x = [input() for i in range(n)]

flag = True
mem = [x[0]]
for i in range(1, n):
  if x[i-1][-1] != x[i][0] or x[i] in mem:
    flag = False
    break
    
  mem.append(x[i])
      
print("Yes" if flag else "No")

Measured memory_bytes: 3060
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n,k;
	cin>>n>>k;
	int ans = 0;
	while(n > 0){
		n /= k;
		ans++;
	}			
	cout<<ans;
	return 0;	
}

Measured memory_bytes: 256
N =int(input())
txy = list(list(map(int,input().split())) for i in range(N))

t =[i[0] for i in txy]
x =[i[1] for i in txy]
y =[i[2] for i in txy]

t.insert(0,0)
x.insert(0,0)
y.insert(0,0)

ans ="Yes"
for i in range(N):
    dt = t[i+1] -t[i]

    dist =abs(x[i+1]-x[i])+abs(y[i+1] -y[i])

    if dt >= dist and dt%2 ==dist%2:
        continue
    else :
        ans ="No"
        break

print(ans)


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

vector<bool> ans;
int main(){
  int r,c;
  while(cin >> r >> c,r){
    int t_c,t_r;
    t_c = c % 2;
    t_r = r % 2;
    if(t_c && t_r){
      ans.push_back(false);
    }else{
      ans.push_back(true);
    }
  }
  
  for(auto i:ans){
    if(i){
      cout << "yes" << endl;
    }else{
      cout << "no" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3056
def napzak(w,v,limit):
    dp = [0]*(limit+1)
    wv = [(weight,value) for weight,value in zip(w,v) if value>weight]
    if wv == []:
        return limit
    for i in range(1,limit+1):
        for j,value in wv:
            if (i-j)>=0 and dp[i]<(dp[i-j]+value-j):
                dp[i] = dp[i-j]+value-j
    return dp[limit]+limit

n = int(input())
wa = list(map(int,input().split()))
wb = list(map(int,input().split()))

m = napzak(wa,wb,n)
ans = napzak(wb,wa,m)

print(ans)

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


int main() {
  int n;
  cin >> n;
  vector<int>a(100100);
  rep(i,6){
    a[i]=i;
  }
  rep2(i,6,9){
    a[i]=i-5;
  }
  rep2(i,9,100100){
    int d=1;
    while(d*6<=i){
      d*=6;
    }
    int b=1;
    while(b*9<=i){
      b*=9;
    }
    a[i]=min({a[i-1]+1,a[i-d]+1,a[i-b]+1});
  }
  
  cout<<a[n]<<endl;
}

Measured memory_bytes: 640
N, *A = map(int, open(0).read().split())

A.sort()
lim = A[-1] + 1

dp = [0] * lim
for a in A:
    dp[a] += 1
    if dp[a] == 1:
        for j in range(2 * a, lim, a):
            dp[j] += 2

print(dp.count(1))

Measured memory_bytes: 33032
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextInt

  println(
    if ((0 to 100 by 4).exists(d4 => (0 to 100 by 7).exists(d7 => d4 + d7 == N))) "Yes"
    else "No"
  )
}

Measured memory_bytes: 27324
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    x,n = map(int, input().split())
    p = list(map(int, input().split()))
    l = [abs(i-x) if i not in p else 103 for i in range(102)]

    ans = l.index(min(l))
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 9148
#include <stdio.h>
#define min(a, b) ((a)>(b) ? (b) : (a))

int main(){
  long a, b, c;  scanf("%ld %ld %ld", &a, &b, &c);
  long ans;
  if(!(a%2 && b%2 && c%2))
    ans = 0;
  else
    ans = min(a*b, min(b*c, c*a));
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 128
def main(N, A):
    count = 0
    flag = True
    i = 0
    while flag:
        flag = False
        for j in list(reversed(list(range(i + 1, N)))):
            a = A[j-1]
            b = A[j]
            if a > b:
                A[j-1] = b
                A[j] = a
                count += 1
                flag = True
        i += 1
    print(' '.join(map(str, A)))
    print(count)
    return (A, count)


if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    main(N, A)



Measured memory_bytes: 5604
import java.util.Scanner;

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

		double area = r * r * Math.PI;
		double length = 2 * r * Math.PI;

		System.out.printf(String.format("%.6f %.6f",area, length));
	}

}

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

using namespace std;
const int INF = INT_MAX;
const int MOD = 1000000007;

bool cmp(pair<int, int> a, int b){
    return a.second < b;
}

int main() {
    ios::sync_with_stdio(false);
    int n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;
    int ans = 0;
    for (int i = 0; i < k; i++){
        if (t[i] == 'r')
            ans += p;
        if (t[i] == 'p')
            ans += s;
        if (t[i] == 's')
            ans += r;
        bool f = false;
        for (int j = i + k; j < n; j += k){
            if (t[j] != t[j-k] || f) {
                if (t[j] == 'r')
                    ans += p;
                if (t[j] == 'p')
                    ans += s;
                if (t[j] == 's')
                    ans += r;
            }
            if (t[j] == t[j-k]){
                f ^= 1;
            }
            else {
                f = false;
            }
        }
    }
    cout << ans;
}


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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main()
{
	int t;
	cin >> t;
	if(t ==  25)
		cout << "Christmas";
	else if(t == 24)
		cout << "Christmas Eve";
	else if(t == 23)
		cout << "Christmas Eve Eve";
	else
		cout << "Christmas Eve Eve Eve";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){

    int a,b;

    scanf("%d %d",&a,&b);
        if(a<b){
            printf("a < b\n");
        }
        else if(a>b){
            printf("a > b\n");
        }
        else{
            printf("a == b\n");
        }
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;

int main()
{
  int a, b, c, x, cnt = 0;
  cin >> a >> b >> c >> x;
  rep(i, a + 1) rep(j, b + 1) rep(k, c + 1) if (500 * i + 100 * j + 50 * k == x) cnt++;
  cout << cnt << endl;
}

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

int main(void){
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    for (int i=0; i<n; i++) cin >> s[i];
    sort(s.begin(), s.end());
    for (auto x : s) cout << x;
    cout << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>

using namespace std;

int fe(int W) {
    for(int l = 0; l < W; l++) {
        cout << '#';
    }
    cout << endl;
    return 0;
}

int pr(int W) {
    cout << '#';
    for(int l = 1; l < W - 1; l++) {
        cout << '.';
    }
    cout << '#' << endl;
    return 0;
}

int main(){
    int i, l, H=0, W=0;
    while(1){
        cin >> H >>  W;
        if(H == 0 && W == 0) {
            return 0;
        } else {
            fe(W);
            for(i = 1; i < H - 1; i++) {
                pr(W);
            }
            fe(W);
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[100000][2];
ll solve(ll a[], int s, int e, int f){
    if(s > e)
    return 0;
    if(dp[s][f] != INT_MIN){
    return dp[s][f];
    }
    ll so = INT_MIN;
    if(f == 0)
    so = a[s] + solve(a, s + 1, e, 0);
    else
    so = -a[s] + solve(a, s + 1, e, 0);
    //cout << s << " " << f << " " << so << endl;
    if(s < e){
        if(f == 0)
        so = std::max(so, -a[s] + solve(a, s + 1, e, 1));
        else
        so = std::max(so, a[s] + solve(a, s + 1, e, 1));
    }
    //cout << s << " " << f << " " << so << endl;
    return dp[s][f] = so;
}
int main() {
    int n;
    cin >> n;
    ll a[n];
    for(int i = 0; i < n; i++)
    cin >> a[i];
    for(int i = 0; i < 100000; i++){
        for(int j = 0; j < 2; j++)
            dp[i][j] = INT_MIN;
    }
    cout << solve(a, 0, n-1, 0); 
    return 0;
}

Measured memory_bytes: 10368
#include <stdio.h>
#include <string.h>

int main()
{
    char s[11],print[11];

    memset(print,'\0',11);
    scanf("%s",s);

    int len = strlen(s),i;
    int char_num = 0;

    for (i = 0; i < len; i++)
    {
        if(s[i] != 'B')
        {
            print[char_num] = s[i];
            char_num++;
        }
        else
        {
            if(char_num != 0)
            {
                char_num--;
                print[char_num] = '\0';
            }
        }
    }
    printf("%s",print);
}

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

#define int long long int
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define lb lower_bound
#define ub upper_bound
#define srt(a) sort(a.begin(),a.end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
#define mxe(a) *max_element(a.begin(),a.end())
#define mne(a) *min_element(a.begin(),a.end())
#define endl '\n'
#define mod 1000000007
#define INF64 1e18
const int N=105;
const int K=100005;
int dp[N][K];
void solve(){
  int n,k;cin>>n>>k;
  vi a(n+1);
  for(int i=1;i<=n;i++)
    cin>>a[i];
  for(int i=0;i<=n;i++)dp[i][0]=1;
  vi pref(k+1,1);
  for(int i=1;i<=n;i++){
    vi p(k+1);
    p[0]=1;
    for(int j=1;j<=k;j++){
      dp[i][j]=(mod+pref[j]-(j-a[i]-1>=0?pref[j-a[i]-1]:0))%mod;
      p[j]=(p[j-1]+dp[i][j])%mod;
    }
    pref=p;
  }
  cout<<dp[n][k];
}

int32_t main(){
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int T=1;
  //cin>>T;
  for(int TT=1;TT<=T;TT++){
    solve();
  }
}


Measured memory_bytes: 82840
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

fn main() {
    input! {
    h: usize,
    w: usize,
    t: Usize1
    }
    let m = 1_000_000_007;
    let mut dp = vec![vec![0; w]; h + 1];
    dp[0][0] = 1;
    let p: Vec<usize> = (0..w).collect();
    let mut ps = vec![];
    for i in 0..1 << (w - 1) {
        let mut np = p.clone();
        let mut flag = true;
        for j in 0..(w - 1) {
            if i & 1 << j > 0 && i & 2 << j > 0 {
                flag = false;
                break;
            }
        }
        if flag {
            for j in 0..(w - 1) {
                if i & 1 << j > 0 {
                    np.swap(j, j + 1);
                }
            }
            ps.push(np);
        }
    }
    for i in 0..h {
        for j in 0..ps.len() {
            for k in 0..w {
                dp[i + 1][k] += dp[i][ps[j][k]];
                dp[i + 1][k] %= m;
            }
        }
    }
    let ans = dp[h][t];
    println!("{}", ans);
}



Measured memory_bytes: 2168
using System;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine();
        var str = input.Split(' ');
        var ans1 = int.Parse(str[0]) * int.Parse(str[1]);           // ??¢???
        var ans2 = (int.Parse(str[0]) + int.Parse(str[1])) * 2;     // ??¨?????????
        Console.WriteLine(ans1 + " " + ans2);
    }
}

Measured memory_bytes: 9156
#include <stdio.h>

int main(void) {
  int i, j, k, n, m, x, a, b;
  scanf("%d%d%d", &n, &m, &k);
  int uf[n], c[n];
  for(i = 0; i < n; ++i) uf[i] = i, c[i] = 0;
  for(i = 1; i <= k; ++i) {
    scanf("%d%d%d", &x, &a, &b);
    if(x == 1) {
      a--, b--;
      int ra = 0, rb = 0, na = a, nb = b;
      while(uf[na] != na) na = uf[na], ra++;
      while(uf[nb] != nb) nb = uf[nb], rb++;
      uf[a] = na, uf[b] = nb;
      if(c[na] && c[nb] && c[na] != c[nb]) {
        printf("%d\n", i);
        return 0;
      }
      if(c[na]) {
        if(ra > rb) uf[nb] = na;
        else uf[na] = nb, c[nb] = c[na];
      } else {
        if(ra > rb) uf[nb] = na, c[na] = c[nb];
        else uf[na] = nb;
      }
    } else {
      a--;
      int na = a;
      while(na != uf[na]) na = uf[na];
      if(c[na] && c[na] != b) {
        printf("%d\n", i);
        return 0;
      }
      uf[a] = na;
      c[na] = b;
    }
  }
  printf("0\n");
  return 0;
}


Measured memory_bytes: 3488
from collections import defaultdict as dd
from bisect import bisect_right
s = input()
t = input()
n = len(s)
cmap = dd(list)
for i, c in enumerate(s):
    cmap[c].append(i)
for i, c in enumerate(s):
    cmap[c].append(i+n)
cmap = dict(cmap)
a = 0
pos = -1
for c in t:
    try:
        i = bisect_right(cmap[c], pos)
        ind = cmap[c][i]
    except:
        print(-1)
        exit()
    if ind >= n:
        a += n
        pos = ind - n
    else:
        pos = ind
print(a + pos + 1)


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

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

  vector<int> d(n);
  rep(i,n-1) {
    if     (a[i] < a[i+1]) d[i] = 1;
    else if(a[i] > a[i+1]) d[i] = -1;
    else d[i] = 0;
  }

  ll money = 1000;
  ll kabu = 0;
  rep(i, n-1) {
    if(d[i] == -1) {
      if(kabu) {
        //売る
        money += a[i] * kabu;
        kabu = 0;
      }
    }
    else if(d[i] == 1) {
      //買う
      kabu += money / a[i];
      money %= a[i];
    }
  }

  if(kabu) {
    money += a[n-1] * kabu;
    kabu = 0;
  }
  cout<< money << endl;
}


Measured memory_bytes: 3632
#include <algorithm>

#include <bitset>

#include <tuple>

#include <cstdint>

#include <cstdio>

#include <cctype>

#include <assert.h>

#include <stdlib.h>

#include <stdio.h>

#include <cassert>

#include <cfloat>

#include <climits>

#include <cmath>

#include <complex>

#include <ctime>

#include <deque>

#include <fstream>

#include <functional>

#include <iomanip>

#include <iostream>

#include <iterator>

#include <list>

#include <limits>

#include <map>

#include <memory>

#include <queue>

#include <random>

#include <set>

#include <stack>

#include <string>

#include <unordered_map>

#include <unordered_set>

#include <utility>

#include <vector>

#include <math.h>
#define int long long
using namespace std;
signed main() {
    int N;
    cin >> N;
    vector<string>vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    int AC = 0;
    int WA = 0;
    int TLE = 0;
    int RE = 0;
    for (int i = 0; i < N; i++) {
        if (vec.at(i) == "AC") {
            AC++;
        }
        else if (vec.at(i) == "WA") {
            WA++;
        }
        else if (vec.at(i) == "TLE") {
            TLE++;
        }
        else {
            RE++;
        }
    }
    cout << "AC" << " " << "x" << " " << AC << endl;
    cout << "WA" << " " << "x" << " " << WA << endl;
    cout << "TLE" << " " << "x" << " " << TLE << endl;
    cout << "RE" << " " << "x" << " " << RE << endl;
}


Measured memory_bytes: 6404
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int a, b, c; cin >> a >> b >> c;
  int ans = min(a+b, min(a+c, b+c));
  cout << ans << endl;
  return 0;
}


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

int main() {
	int A,B;
	cin>>A>>B;
    int count=0;
    int reduce=-1;
    while(A*count-reduce<B){ 
    	count++;
        reduce++;
    }
    cout<<count<<endl;
    
    
    
    
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char *argv[]){
  int a[3];
  a[0] = 1,a[1] = a[2] = 0;
  char f,t;
  int to,from,tmp,i;
  
  while(scanf("%c,%c%*c",&f,&t) != EOF){
    to = t - 'A';
    from = f - 'A';

    tmp = a[from];
    a[from] = a[to];
    a[to]  = tmp;
  }

  for(i = 0;i < 3;++i){
    if(a[i] == 1){
      printf("%c\n",(char)(i + 'A'));
      break;
    }
  }
  
  
  return 0;    
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int q,a,b,dp[1001][1001],ok;
string s,t;
int main(void){
    cin>>q;
    while(q--){
        cin>>s>>t;
        a=s.size();
        b=t.size();
        for(int i=1;i<=a;i++){
            for(int j=1;j<=b;j++){
                //if(i==3)cout<<s[i-1]<<" "<<t[j-1]<<endl;
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                if(s[i-1]==t[j-1])dp[i][j]=max(dp[i-1][j-1]+1,dp[i][j]);
            }
        }
        cout<<dp[a][b]<<endl;
        for(int j=0;j<=a;j++){
            for(int k=0;k<=b;k++){
                //cout<<dp[j][k]<<" ";
                dp[j][k]=0;
            }
            //cout<<endl;
        }
    }
}



Measured memory_bytes: 7076
n = int(input())
xy = [[] for i in range(n)]
maxh = 0
for i in range(n):
  a = int(input())
  for j in range(a):
    xy[i].append(list(map(int, input().split())))
for i in range(1<<n):
  tmp = [-1] * n
  try:
    for j in range(n):
      if i & (1<<j):
        if tmp[j] == -1:
          tmp[j] = 1
        elif tmp[j] == 0:
          raise
        for k, l in xy[j]:
          if tmp[k-1] == -1:
            tmp[k-1] = l
          elif tmp[k-1] != l:
            raise
      else:
        if tmp[j] == -1:
          tmp[j] = 0
        elif tmp[j] == 1:
          raise
  except:
    pass
  else:
    hoge = tmp.count(1)
    if hoge > maxh:
      maxh = hoge
print(maxh)


Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){

  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  long long ans = 0;
  long long N = A+B+C;

  long long KA = K - A;
  long long KAB = K - A - B;
  if( KA < 0 ) KA = 0;
  if( KAB < 0 ) KAB = 0;

  ans = 1*min(A, K) + 0*min(B, KA) + -1*min(C, KAB);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3576
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
    	ni();
    	String q1 = "";
    	String q2 = "";

    	int state = 0;
    	int mode = 1;

    	for (int i=0; i<420; i++) {
    		int x = state / 2;
    		int y = state % 2;

    		out.println(mode == 1 ? q1 + (x == 0 ? "." : "#") : (x == 0 ? "." : "#") + q1);
    		out.println(mode == 1 ? q2 + (y == 0 ? "." : "#") : (y == 0 ? "." : "#") + q2);
    		out.flush();

    		String s = ns();

    		if (s.equals("end")) {
    			return;
    		} else if (s.equals("T")) {
    			q1 = mode == 1 ? q1 + (x == 0 ? "." : "#") : (x == 0 ? "." : "#") + q1;
    			q2 = mode == 1 ? q2 + (y == 0 ? "." : "#") : (y == 0 ? "." : "#") + q2;
    			state = 0;
    		} else {
    			state++;
    			if (state == 4) {
    				mode = 2;
    				state = 0;
    			}
    		}
    	}
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}


Measured memory_bytes: 10920
iN ,iX  = [int(x) for x in input().split()]
aX = [int(x) for x in input().split()]

aCum = [0]*(iN)
aCum[0] = aX[0]
for i in range(1,iN):
    aCum[i]=aCum[i-1]+aX[i]

def fCeil(iT,iR):
    return -1 * iT // iR * -1

def fCalcCost(iN,iX,aCum,iK):
    iCost = (iN + iK ) * iX + 5 * aCum[-1]
    for i in range(2,fCeil(iN,iK) ):
        iCost += 2 * aCum[-1 * i * iK -1]
    return iCost

iTotalCost = fCalcCost(iN,iX,aCum,1)
for iK in range(2,fCeil(iN,2) + 1):
    iTotalCost = min(iTotalCost,fCalcCost(iN,iX,aCum,iK))
print(iTotalCost)


Measured memory_bytes: 25836
#include<bits/stdc++.h>
using namespace std;
long long f[3001][3001];
int a[3001];
int main()
{
	int n,i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(n%2==0)
			f[i][i]=-a[i];
		else
			f[i][i]=a[i];
	}
	for(j=1;j<n;j++)
	{
		for(i=1;i<n&&i+j<=n;i++)
		{
			if(j%2!=n%2)
				f[i][i+j]=max(f[i+1][i+j]+a[i],f[i][i+j-1]+a[i+j]);
			else
				f[i][i+j]=min(f[i+1][i+j]-a[i],f[i][i+j-1]-a[i+j]);	
		}
	}
	printf("%lld",f[1][n]);
	return 0;
}

Measured memory_bytes: 70016
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define forn(a,b,c) for(int a=b;a<=c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
#define f first
#define s second
typedef pair<int,int> pii;
const int N=3e2+5;
const int mod=998244353;
const ll inf=1e18+7;
int n,x,cnt[4];double dp[N][N][N];
double solve(int a,int b,int c){
    if(a<0||b<0||c<0){
        return 0;
    }
    if(dp[a][b][c]!=-1){
        return dp[a][b][c];
    }
    if(a==0&&b==0&&c==0){
        return 0;
    }
    double ans=a*solve(a-1,b,c)+b*solve(a+1,b-1,c)+c*solve(a,b+1,c-1)+n;
    ans/=(a+b+c);
    return dp[a][b][c]=ans;
}
int main()
{
    cin>>n;
    fill(&dp[0][0][0], &dp[0][0][0] + N*N*N, -1);
    forn(i,1,n){
        cin>>x;
        cnt[x]++;
    }
    printf("%.14f\n",solve(cnt[1],cnt[2],cnt[3]));
    return 0;
}


Measured memory_bytes: 221952
using System;
using System.Collections.Generic;

public class Hello{
    public static void Main(){
        Console.ReadLine();
        
        var dic = new Dictionary<string, bool>();
        string line = Console.ReadLine();
        while(line != null){
            var xs = line.Split(' ');
            if(xs[0] == "insert"){
                dic[xs[1]] = true;
            }else if(xs[0] == "find"){
                Console.WriteLine(dic.ContainsKey(xs[1]) ? "yes" : "no");
            }
            line = Console.ReadLine();
        }
    }
}


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

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

fn main() {
    let n: usize = read();
    let s: String = read();
    let ci: Vec<char> = s.chars().collect();

    let mut r_cnt: u64 = 0;
    let mut g_cnt: u64 = 0;
    let mut b_cnt: u64 = 0;

    for i in 0..n {
        if ci[i] == 'R' {
            r_cnt += 1;
        } else if ci[i] == 'G' {
            g_cnt += 1;
        } else {
            b_cnt += 1;
        }
    }

    let mut ans: u64 = r_cnt * g_cnt * b_cnt;
    for i in 0..n {
        for j in i+1..n {
            let k = 2 * j - i;
            if k >= n {
                break;
            }
            if ci[i] != ci[j] && ci[j] != ci[k] && ci[k] != ci[i] {
                ans -= 1;
            }
        }
    }

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


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

int main(){
    int n;
    cin >> n;
    vector<vector<int>> d(10,vector<int>(10,0));
    ll ans = 0;
    for (int i = 1; i < n + 1; i++){
        int a=0,b=0;
        a = i%10;
        int x = i;
        while(x){
            b = x;
            x = x / 10;
        }
        d[a][b]++;
    }
    rep(i,10){
        rep(j,10){
            ans += d[i][j] * d[j][i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e8;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	string s;
	while(cin >> s) {
		int n = s.size();
		map<int,int> dp;
		dp[0] = 0;
		using bs = bitset<26>;
		bs tmp = 0;
		int ans;
		REP(i,n){
			int c = s[i]-'a';
			tmp[c] = !tmp[c];
			int mi = INF;
			REP(j,26){
				auto t = tmp;
				t[j] = !t[j];
				if(dp.find(t.to_ulong()) != dp.end()) {
					chmin(mi, dp[t.to_ulong()]+1);
				}
			}
			if(dp.find(tmp.to_ulong()) != dp.end()) chmin(mi,dp[tmp.to_ulong()]+1);
			ans = mi;
			if(dp.find(tmp.to_ulong()) == dp.end()) {
				dp[tmp.to_ulong()] = INF;
			}
			chmin(dp[tmp.to_ulong()], mi);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 9876
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		int N = fs.nextInt();

		int[] res = new int[N + 1];
		for (int i = 1; i <= N; i++) {
			int A = fs.nextInt();
			res[A] = i;
		}

		for (int i = 1; i <= N; i++) {
			System.out.print(res[i] + " ");
		}
		System.out.println();

	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 43520
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;
 

int main() {
    ios_base::sync_with_stdio(false);

    int n,m;
    cin >> n >> m;
    vector<vector<int>> r(m,vector<int>(n));
    rep(i,m) {
        int k;
        cin >> k;
        rep(j,k) {
            int ss;
            cin >> ss;
            r[i][ss-1]=1;
        }
    }
    vector<int> p(m);
    rep(i,m) cin >> p[i];
    int ans=0;
    rep(bit,(1<<n)) {
        vector<int> cnt(n);
        rep(i,n) {
            if (bit & (1<<i)) {
                rep(j,m) {
                    if (r[j][i]) ++cnt[j];
                }
            }
        }
        bool flag=1;
        rep(i,m) {
            if (cnt[i]%2!=p[i]) flag=0;
        }
        if (flag) ++ans;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string S;
    cin >> S;
    int size = S.size();
    vector<int> ans(size, 0);
    int r_count = 0;
    int l_count = 0;
    int label = 0;
    rep(i, 0, size)
    {
        if (i != 0)
        {
            if ((S.at(i - 1) == 'R') && (S.at(i) == 'L'))
            {
                label = i - 1;
            }
            else if ((S.at(i - 1) == 'L') && (S.at(i) == 'R'))
            {
                if ((r_count + l_count) % 2 == 0)
                {
                    ans.at(label) = (r_count + l_count) / 2;
                    ans.at(label + 1) = (r_count + l_count) / 2;
                }
                else if (r_count % 2 != 0)
                {
                    ans.at(label) = (r_count + l_count) / 2 + 1;
                    ans.at(label + 1) = (r_count + l_count) / 2;
                }
                else
                {
                    ans.at(label) = (r_count + l_count) / 2;
                    ans.at(label + 1) = (r_count + l_count) / 2 + 1;
                }
                r_count = 0;
                l_count = 0;
            }
        }
        if (S.at(i) == 'R')
        {
            r_count++;
        }
        else
        {
            l_count++;
        }
    }
    if ((r_count + l_count) % 2 == 0)
    {
        ans.at(label) = (r_count + l_count) / 2;
        ans.at(label + 1) = (r_count + l_count) / 2;
    }
    else if (r_count % 2 != 0)
    {
        ans.at(label) = (r_count + l_count) / 2 + 1;
        ans.at(label + 1) = (r_count + l_count) / 2;
    }
    else
    {
        ans.at(label) = (r_count + l_count) / 2;
        ans.at(label + 1) = (r_count + l_count) / 2 + 1;
    }
    rep(i, 0, size)
    {
        cout << ans.at(i) << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=2500;
int cha[maxn][maxn];
int n,k;
inline int calc(int x1,int y1,int x2,int y2){
    return cha[x2][y2]+cha[x1-1][y1-1]-cha[x2][y1-1]-cha[x1-1][y2];
}
int main(){
    scanf("%d%d",&n,&k);
    for(register int i=1,x,y,c;i<=n;i++){
        char s[10];
        scanf("%d%d",&x,&y);
        scanf("%s",s);
        x%=2*k,y%=2*k;
        if(s[0]=='B')y+=k;
        cha[x%(k<<1)+1][y%(k<<1)+1]++;
    }
    int ans=0;
    for(register int i=1;i<=(k<<1);i++){
        for(register int j=1;j<=(k<<1);j++){
            cha[i][j]=cha[i][j]+cha[i][j-1]+cha[i-1][j]-cha[i-1][j-1];
        }
    }
    for(register int i=1;i<=k;i++){
        for(register int j=1;j<=k;j++){
            int tot=calc(1,1,i,j);
            tot+=calc(i+1,j+1,k+i,k+j);
            tot+=calc(k+i+1,k+j+1,k<<1,k<<1);
            tot+=calc(k+i+1,1,k<<1,j);
            tot+=calc(1,k+j+1,i,k<<1);
            ans=max(ans,max(tot,n-tot));
        }
    }
    cout<<ans<<endl;
}

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

int main(){
	int n, m;
	cin >> n >> m;
	while( n | m){
		int tsum, hsum;
		tsum = hsum = 0;
		vector<int> tcard, hcard;
		tcard.clear();
		hcard.clear();
		for(int i = 0; i < n; i++){
			int a;
			cin >> a;
			tsum += a;
			tcard.push_back(a);
		}
		for(int i = 0; i < m; i++){
			int a;
			cin >> a;
			hsum += a;
			hcard.push_back(a);
		}
		
		bool flag = false;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				if(tsum - tcard[i] + hcard[j] == hsum - hcard[j] + tcard[i]){
					cout << tcard[i] << ' ' << hcard[j] << endl;
					flag = true;
					break;
				}
			}
			if(flag){
				break;
			}
		}
		
		if(!flag){
			cout << -1 << endl;
		}
	cin >> n >> m;
	}
	
	return 0;
}

Measured memory_bytes: 1220